文章最后更新时间:
本代码在子比主题8.0版本下能正常使用,暂无bug。免费的就不要拿到自己网站上卖钱了,代码被别人改良了,我直接拿过来了。
效果预览
![图片[1]-子比主题功能 – 购买文章自动认证教程-九二分享](https://www.xzma.cn/wp-content/uploads//13a55c6af47115417ba351a48b63d4d4.jpeg)
功能
自动启用功能:在文章发布的侧边栏中直接启用认证功能,无需额外操作。
独立设置认证名称:允许为每篇文章设置自定义认证名称,使认证信息更加灵活。
认证描述可自定义:可以在文章编辑页面侧边栏中输入自定义的认证名称和描述,而无需固定某个值。
支持新文章:新发布的文章也可以直接使用此功能,大大减少了重复劳动。
代码部署:此代码添加至子比主题 func.php 文件内。
// 购买文章自动认证
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);
?>
/>
启用认证用户功能
认证名称:
<?php echo esc_attr($name); ?>
认证描述:
<?php echo esc_attr($desc); ?>
启用后请确保已打开付费下载
购买后将会自动认证,无需审核
留空认证名称或描述则使用默认值
}
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');
© 版权声明
© 版权声明 All Rights Reserved
THE END








暂无评论内容