/** * 核心业务逻辑 */ class Zibll_Vip2_Expire_Core { public function __construct() { // 拦截 [hidecontent] 短代码的渲染输出 add_filter('do_shortcode_tag', [$this, 'intercept_hidecontent_shortcode'], 10, 4); // 记录重新购买的时间 add_action('zibpay_order_success', [$this, 'record_buy_time'], 10, 2); } /** * 获取永久会员的开通/最后购买时间 * @param int $user_id 用户ID * @return string 时间字符串(Y-m-d H:i:s)|false */ private function get_vip2_start_time($user_id) { global $wpdb; $order_table = $wpdb->prefix . 'zibpay_order'; // 查永久会员开通订单 $vip2_order = $wpdb->get_row($wpdb->prepare( "SELECT pay_time FROM {$order_table} WHERE user_id = %d AND product_id = %s AND `status` = 1 ORDER BY pay_time ASC LIMIT 1", $user_id, 'vip_2_0_pay' )); if ($vip2_order) { return $vip2_order->pay_time; } // 兼容旧版永久会员(product_id=vip_1_0_pay 且 vip_exp_date=Permanent) $old_vip2_order = $wpdb->get_row($wpdb->prepare( "SELECT pay_time FROM {$order_table} WHERE user_id = %d AND product_id = %s AND `status` = 1 ORDER BY pay_time ASC LIMIT 1", $user_id, 'vip_1_0_pay' )); if ($old_vip2_order) { $user_vip_meta = get_user_meta($user_id, 'user_vip', true); if ($user_vip_meta['vip_exp_date'] === 'Permanent') { return $old_vip2_order->pay_time; } } return false; } /** * 判断用户是否超期 * @param int $user_id 用户ID * @param int $post_id 文章ID * @return bool */ private function is_expired($user_id, $post_id) { // 1. 校验插件配置的指定文章 $target_posts = get_option('zibll_vip2_expire_posts', ''); $target_posts = $target_posts ? explode(',', $target_posts) : []; if (!in_array((string)$post_id, $target_posts)) { return false; } // 2. 校验会员身份(仅永久会员) $user_vip_meta = get_user_meta($user_id, 'user_vip', true); if (empty($user_vip_meta) || $user_vip_meta['vip_level'] != 2 || $user_vip_meta['vip_exp_date'] !== 'Permanent') { return false; } // 3. 获取超期天数 $expire_days = get_option('zibll_vip2_expire_days', 365); // 4. 获取基准时间(重新购买时间 > 会员开通时间) $re_buy_time = get_user_meta($user_id, "zibll_vip2_post_buy_{$post_id}", true); $start_time = $re_buy_time ?: $this->get_vip2_start_time($user_id); if (!$start_time) { return false; } // 5. 计算时间差 $start_time = strtotime($start_time); $current_time = time(); $diff_days = floor(($current_time - $start_time) / 86400); return $diff_days > $expire_days; } /** * 拦截 [hidecontent] 短代码的渲染输出 * @param string $output 短代码输出的HTML * @param string $shortcode 短代码名称 * @param array $attributes 短代码属性 * @param string $content 短代码包裹的内容 * @return string */ public function intercept_hidecontent_shortcode($output, $shortcode, $attributes, $content) { // 只拦截我们关心的付费隐藏短代码 if ($shortcode !== 'hidecontent' || $attributes['type'] !== 'payshow') { return $output; } $user_id = get_current_user_id(); $post_id = get_the_ID(); // 如果用户未登录或不是超期的永久会员,直接返回原输出 if (!$user_id || !$this->is_expired($user_id, $post_id)) { return $output; } // 获取文章付费配置 $pay_mate = get_post_meta($post_id, 'posts_zibpay', true); if (empty($pay_mate) || $pay_mate['pay_type'] === 'no') { return $output; } $pay_price = !empty($pay_mate['pay_price']) ? round((float)$pay_mate['pay_price'], 2) : 0; $tips = get_option('zibll_vip2_expire_tips', '您的永久会员访问权限已超期,请重新购买该文章以继续访问!'); // 构建新的付费提示HTML,包含提示文案和付费链接 $new_output = '
' . $tips . '
  此处内容已隐藏,您的永久会员权限已超期,需付费 ' . $pay_price . ' 元后查看
'; // 临时修改文章的VIP价格,确保付费逻辑正确 $pay_mate['vip_2_price'] = $pay_price; update_post_meta($post_id, 'posts_zibpay', $pay_mate); return $new_output; } /** * 记录重新购买文章的时间 * @param array $order 订单数据 * @param int $post_id 文章ID */ public function record_buy_time($order, $post_id) { $user_id = $order['user_id']; if (!$user_id || !$post_id) { return; } // 仅记录指定文章的购买 $target_posts = get_option('zibll_vip2_expire_posts', ''); $target_posts = $target_posts ? explode(',', $target_posts) : []; if (!in_array((string)$post_id, $target_posts)) { return; } // 记录本次购买时间 update_user_meta($user_id, "zibll_vip2_post_buy_{$post_id}", current_time('Y-m-d H:i:s')); } } new Zibll_Vip2_Expire_Core();
Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/iaaaxyz/wp-content/plugins/svipxufeipost/svippost.php:1) in /www/wwwroot/iaaaxyz/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 1563
2045381367 qq-VAM资源站
2045381367 qq-VAM资源站
2045381367 qq的头像-VAM资源站
UID:7697 已加入本站3天 总消费:0
这家伙很懒,什么都没有写...
随便看看

发布页:VAMW.XYZ