会员仅38元起,全站资源无限制ALL免费下载!

子比主题美化-购买文章自动认证代码

文章最后更新时间:2025-03-09 18:27:19

图片[1]-子比主题美化-购买文章自动认证代码-墨非网文章源自墨非网-https://www.mf8.site/3826.html

图片[2]-子比主题美化-购买文章自动认证代码-墨非网文章源自墨非网-https://www.mf8.site/3826.html

将下面的代码放到:/wp-content/themes/zibll/func.php文件里面,没有这个文件的自己创一个,记得创之后别忘了加php头,要不然不生效,话不多说直接代码!文章源自墨非网-https://www.mf8.site/3826.html

[wxgzh key=1718 reply=验证码]文章源自墨非网-https://www.mf8.site/3826.html

// 购买文章自动认证
function zibll_add_meta_box() {
    add_meta_box(
        'zibll_auth_meta_box',           
        '认证用户设置',
        'zibll_auth_meta_box_callback',
        'post',
        'side'
    );
}
add_action('add_meta_boxes', 'zibll_add_meta_box');

function zibll_auth_meta_box_callback($post) {
    // 获取元数据
    $is_enabled = get_post_meta($post->ID, '_zibll_auth_enabled', true);
    $name = get_post_meta($post->ID, '_zibll_auth_name', true);
    $desc = get_post_meta($post->ID, '_zibll_auth_desc', true);

    ?>
    <p>
        <label for="zibll_auth_enabled">
            <input type="checkbox" name="zibll_auth_enabled" id="zibll_auth_enabled" value="1" <?php checked($is_enabled, 1); ?> />
            启用认证用户功能
        </label>
    </p>
    <p>
        <label for="zibll_auth_name">认证名称:</label>
        <input type="text" name="zibll_auth_name" id="zibll_auth_name" value="<?php echo esc_attr($name); ?>" placeholder="默认:认证用户" />
    </p>
    <p>
        <label for="zibll_auth_desc">认证描述:</label>
        <input type="text" name="zibll_auth_desc" id="zibll_auth_desc" value="<?php echo esc_attr($desc); ?>" placeholder="默认:赞助会员" />
    </p>
    <p>
        <ul>
            <li>启用后请确保已打开付费下载</li>
            <li>购买后将会自动认证,无需审核</li>
            <li>留空认证名称或描述则使用默认值</li>
        </ul>
    </p>
    <?php
}

function zibll_save_post_meta($post_id) {

    if (!current_user_can('edit_post', $post_id)) {
        return;
    }

    if (isset($_POST['zibll_auth_enabled'])) {
        update_post_meta($post_id, '_zibll_auth_enabled', 1);
    } else {
        delete_post_meta($post_id, '_zibll_auth_enabled');
    }

    if (isset($_POST['zibll_auth_name'])) {
        update_post_meta($post_id, '_zibll_auth_name', sanitize_text_field($_POST['zibll_auth_name']));
    } else {
        delete_post_meta($post_id, '_zibll_auth_name');
    }

    if (isset($_POST['zibll_auth_desc'])) {
        update_post_meta($post_id, '_zibll_auth_desc', sanitize_text_field($_POST['zibll_auth_desc']));
    } else {
        delete_post_meta($post_id, '_zibll_auth_desc');
    }
}
add_action('save_post', 'zibll_save_post_meta');

function zibll_users_zidongrenzheng($pay_order) {
    $pay_order = (array) $pay_order;
    $post_id   = $pay_order['post_id'];
    $user_id   = $pay_order['user_id'];

    $is_enabled = get_post_meta($post_id, '_zibll_auth_enabled', true);
    if ($is_enabled) {
        $name = get_post_meta($post_id, '_zibll_auth_name', true);
        $desc = get_post_meta($post_id, '_zibll_auth_desc', true);

        // 设置默认值
        if (empty($name)) {
            $name = '认证用户';
        }
        if (empty($desc)) {
            $desc = '赞助会员';
        }

        // 添加认证操作
        zib_add_user_auth($user_id, array(
            'name' => $name,
            'desc' => $desc,
        ));
    }
}
add_action('payment_order_success', 'zibll_users_zidongrenzheng');

[/wxgzh]文章源自墨非网-https://www.mf8.site/3826.html

温馨提示:若内容/图片/下载链接失效,请在下方留言或登录后私信站长
© 版权声明
THE END
点赞14赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容