0 0 0

子比主题功能 – 购买文章自动认证教程

颜诗雅 (UID:1002) 管理员 赞助商 V
2025-05-12 196

本代码在子比主题8.0版本下能正常使用,暂无bug。免费的就不要拿到自己网站上卖钱了,代码被别人改良了,我直接搬运过来了。

功能详情

自动启用功能:在文章发布的侧边栏中直接启用认证功能,无需额外操作。

独立设置认证名称:允许为每篇文章设置自定义认证名称,使认证信息更加灵活。

认证描述可自定义:可以在文章编辑页面侧边栏中输入自定义的认证名称和描述,而无需固定某个值。

教程开始

进入网站根目录 找到wp-content/themes/zibll/func.php文件 如果没有func.php就新建一个,functions.php也可以 放functions.php更新主题会覆盖掉 还需要重新添加代码 建议放func.php 更新主题不会覆盖

进入文件后放入下面代码 如果没有<?php就添加上

[reply]

// 购买文章自动认证
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');
 

 

[/reply]

支持新文章:新发布的文章也可以直接使用此功能,大大减少了重复劳动。

 

 

 


下载声明

每次下载将扣除 1个元宝,VIP会员免费下载,元宝可通过 /发布主题/签到/回帖/获得!
拥有真气  :排行
拥有元宝  :
兑换
拥有灵石  :  0枚充值
关闭
最新回复 (0)

    暂无评论

请先登录后发表评论!

返回
请先登录后发表评论!