注册时间2024-11-22
最后登录2026-7-21
在线时间1918 小时
UID1
买家信用
卖家信用
送礼物:3 个
收礼物:1 个
|
交易无需等待,成交就是现在,全面资源整合网络大咖云集,让你轻松玩转互联网!
您需要 登录 才可以下载或查看,没有账号?立即注册
×
给子比主题购买的文章加上一个文章自动认证教程,这个功能还是比较实用的,当用户买了本篇文章之后那么将会自动认证,非常的实用,话不多说直接开始!
[h1]代码部署[/h1]
将下面的代码放到:/wp-content/themes/zibll/func.php文件,没有这个文件自己创建一个,记得加上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);
- ?>
- <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');
复制代码
|
|