/** * 子比主题多导航小工具 */ $widgets_files = array( 'tengfei_more_navigation.php', /*小工具文件名*/ ); foreach ($widgets_files as $file) { require get_template_directory() . '/tengfei/widgets/' . $file; /** * 面包屑修改 */ add_action('wp', function() { if (is_single() || is_singular('forum_post')) { ob_start(); } }); add_action('shutdown', function() { $buffer = ob_get_clean(); if ($buffer) { echo preg_replace('/
  • \s*正文\s*<\/li>/', '
  • ' . get_the_title() . '
  • ', $buffer); } }, 0); } // 子比小黑屋 if (file_exists(get_theme_file_path('/xy_block.php'))) { require_once get_theme_file_path('/xy_block.php'); } /** * 新用户注册时自动用id为1的用户发送私信 */ function auto_send_private($new_user_id) { // 检查是否是新用户,并确保用户ID为1存在 $send_user_id = 1; // 假设用户1存在 // 获取私信内容 $msg_content = '欢迎加入52纸模网!52纸模网提供海量的纸模型资源高速下载服务,站内资源下载需消耗积分,您可以通过投稿发布纸模型资源赚取积分,也可以通过赞助充值的方式直接购买积分,注意哦,开通VIP会员赠送海量积分还可享受折扣下载哦!'; // 定义私信参数 $msg_args = array( 'send_user' => $send_user_id, 'receive_user' => $new_user_id, // 新用户ID 'content' => $msg_content, 'parent' => '', 'status' => '', 'meta' => '', 'other' => '', ); // 发送私信 $msg = Zib_Private::add($msg_args); } add_action('user_register', 'auto_send_private'); /** * 面包屑修改 */ add_action('wp', function() { if (is_single() || is_singular('forum_post')) { ob_start(); } }); add_action('shutdown', function() { $buffer = ob_get_clean(); if ($buffer) { echo preg_replace('/
  • \s*正文\s*<\/li>/', '
  • ' . get_the_title() . '
  • ', $buffer); } }, 0); /* * 用户中心添加UID、注册时间、消费金额 * 定义用于显示用户ID的函数 * 'but'是配合函数赋予class样式'but'在子比主题内通常是按钮样式可配合c-blue或jb-pink赋予色彩 * c系列为透明背景,颜色有c-blue、c-blue-2、c-cyan、c-gray、c-green、c-green-2、c-purple、c-purple-2、c-red、c-red-2、c-theme、c-white、c-yellow、c-yellow-2 * jb系列为非透明渐变色背景,颜色有pay-tag、jb-red、jb-pink、jb-yellow、jb-blue、jb-cyan、jb-green、jb-purple、jb-vip1、jb-vip2 */ function ZbTool_user_id_to_desc($desc, $user_id) { // 初始化变量 $day = true; // 可以根据需要进行动态设置 $uid = true; // 可以根据需要进行动态设置 $pay_price = true; // 可以根据需要进行动态设置 $demo = false; // 可以根据需要进行动态设置 // 初始化输出变量 $output = []; // 判断 uid 为 true if ($uid) { $icon = ''; // 图标 可自行更换 $but = 'UID:' . esc_html($user_id); $class = 'c-red'; $output[] = '' . $icon . $but . ''; } // 判断 day 为 true if ($day) { $icon = ''; // 图标 如果有需要的话 $but = zib_get_user_join_day_desc($user_id, 'but c-cyan'); // 获取用户加入天数描述 $class = ''; $output[] = $but; } // 判断 pay_price 为 true if ($pay_price) { $icon = ''; // 图标 可自行更换 $but = zibpay_get_user_pay_price($user_id, 'pay_price'); $class = 'jb-vip2'; $output[] = '总消费:' . esc_html($but) . ''; } // 判断 demo 为 true if ($demo) { $icon = ''; // 图标 可自行更换 $but = '我是添加样式的演示~'; $class = 'c-purple'; $output[] = '' . esc_html($but) . ''; } // 将生成的内容添加到原始描述 $desc = implode(' ', $output) . ' ' . $desc; return $desc; } // 添加过滤器 add_filter('user_page_header_desc', 'ZbTool_user_id_to_desc', 10, 2); add_filter('author_header_identity', 'ZbTool_user_id_to_desc', 10, 2); /** * 文章更新日期提示 */ function article_time_update() { date_default_timezone_set('PRC'); $newdate = time(); $updated_date = get_the_modified_time('Y-m-d H:i:s'); $updatetime = strtotime($updated_date); $custom_content = ''; if ($newdate > $updatetime + 86400) { $custom_content = '

    文章最后更新时间:' . $updated_date . '

    '; } echo $custom_content; } add_action('zib_posts_content_before', 'article_time_update'); /** * 会员开通/续费送积分功能 */ // 监听支付成功事件 add_action('payment_order_success', 'zib_vip_payment_give_points', 15); /** * 会员开通/续费送积分 * @param object $pay_order 订单对象 */ function zib_vip_payment_give_points($pay_order) { // 检查是否是会员订单 if (empty($pay_order->user_id) || empty($pay_order->product_id) || 4 != $pay_order->order_type) { return; } // 解析产品ID $vip_product_id = explode('_', $pay_order->product_id); if (!isset($vip_product_id[0]) || !isset($vip_product_id[1]) || !isset($vip_product_id[2]) || !isset($vip_product_id[3]) || 'vip' != $vip_product_id[0]) { return; } $pay_vip_level = (int) $vip_product_id[1]; $pay_vip_product = (int) $vip_product_id[2]; $pay_vip_action = $vip_product_id[3]; $user_id = $pay_order->user_id; // 获取产品信息 if ('renew' == $pay_vip_action) { // 续费 $product_args = zibpay_get_vip_renew_product($pay_vip_level); } else if ('pay' == $pay_vip_action) { // 开通 $product_args = (array) _pz('vip_opt', '', 'vip_' . $pay_vip_level . '_product'); } else { // 其他操作(如升级)不赠送积分 return; } // 检查产品是否存在 if (!isset($product_args[$pay_vip_product])) { return; } $product = $product_args[$pay_vip_product]; $time = isset($product['time']) ? $product['time'] : 0; $unit = isset($product['unit']) ? $product['unit'] : 'month'; // 处理月付和年付产品 if (!in_array($unit, array('month', 'year'))) { return; } // 统一转换为月数进行计算 $months = $time; if ('year' == $unit) { $months = $time * 12; } // 根据时长和操作类型计算积分 $points = 0; if (1 == $months) { // 1个月 if ('pay' == $pay_vip_action) { $points = 600; // 开通1个月赠送600积分 } else if ('renew' == $pay_vip_action) { $points = 600; // 续费1个月赠送600积分 } } else if (3 == $months) { // 3个月 if ('pay' == $pay_vip_action) { $points = 2000; // 开通3个月赠送2000积分 } else if ('renew' == $pay_vip_action) { $points = 2000; // 续费3个月赠送2000积分 } } else if (6 == $months) { // 6个月 if ('pay' == $pay_vip_action) { $points = 4500; // 开通6个月赠送4500积分 } else if ('renew' == $pay_vip_action) { $points = 4500; // 续费6个月赠送4500积分 } } else if (12 == $months) { // 12个月(年付) if ('pay' == $pay_vip_action) { $points = 10000; // 开通1年赠送10000积分 } else if ('renew' == $pay_vip_action) { $points = 10000; // 续费1年赠送10000积分 } } // 赠送积分 if ($points > 0) { $unit_text = 'month' == $unit ? '个月' : '年'; $data = array( 'value' => $points, 'type' => '会员赠送', 'desc' => ($pay_vip_action == 'pay' ? '开通' : '续费') . $time . $unit_text . '会员赠送', 'order_num' => $pay_order->order_num, ); zibpay_update_user_points($user_id, $data); } } /** * 信息编辑页修改 */ remove_filter('main_user_tab_content_data', 'zib_main_user_tab_content_data'); add_filter('main_user_tab_content_data', 'wxs_zib_main_user_tab_content_data'); function wxs_zib_main_user_tab_content_data() { $user = wp_get_current_user(); $user_id = isset($user->ID) ? (int) $user->ID : 0; if (!$user_id) { return; } $privacy = zib_get_user_meta($user_id, 'privacy', true); $gender = get_user_meta($user_id, 'gender', true); $html = ''; $avatar = zib_get_avatar_box($user_id, 'avatar-img avatar-lg', false, false); $avatar_set_link = zib_get_user_avatar_set_link('but c-blue p2-10 em09 ml6 hollow shrink0', '修改头像'); $html .= '
    ' . $avatar . '
    ' . esc_attr($user->display_name) . '填写QQ更改头像
    注册时间:' . get_date_from_gmt($user->user_registered) . '
    最后登录:' . get_user_meta($user_id, 'last_login', true) . '
    '; $html .= '
    昵称
    个人签名
    隐私设置
    性别
    居住地
    QQ
    微信
    '; $html = '
    ' . $html . '
    '; return zib_get_ajax_ajaxpager_one_centent($html); } /** * 记录文章最近访客 */ add_action('wp_head', 'dahai_record_visitor'); function dahai_record_visitor() { if (!is_singular('post') || !is_user_logged_in()) return; global $post; $visitors = get_post_meta($post->ID, 'dahai_visitors', true) ?: []; $uid = get_current_user_id(); $visitors = array_filter($visitors, fn($v) => $v != $uid); array_unshift($visitors, $uid); update_post_meta($post->ID, 'dahai_visitors', array_slice($visitors, 0, 50)); } // 注册小工具 - dahai add_action('widgets_init', fn() => register_widget('Dahai_Visitor_Widget')); class Dahai_Visitor_Widget extends WP_Widget { function __construct() { parent::__construct('dahai_visitor_widget', '文章访客 - Dahai', ['description' => '显示文章访客 by Dahai']); } function widget($args, $instance) { if (!is_singular('post')) return; global $post; $visitors = get_post_meta($post->ID, 'dahai_visitors', true); if (empty($visitors)) return; $num = $instance['num'] ?? 12; $badge = $instance['badge'] ?? '最近访客'; $pos = $instance['pos'] ?? 'right'; $size = $instance['size'] ?? 50; $fontSize = $instance['fontSize'] ?? 0.9; $pStyle = $pos == 'left' ? 'left:-50px;transform:rotate(-45deg);' : 'right:-50px;transform:rotate(45deg);'; echo '
    '; echo '' . esc_html($badge) . ''; echo '
    '; foreach (array_slice($visitors, 0, $num) as $uid) { $user = get_userdata($uid); if (!$user) continue; // 获取头像 $avatar_img = zib_get_data_avatar($uid, $size); // 获取会员徽章并根据头像尺寸调整大小 $vip_level = zib_get_user_vip_level($uid); $vip_badge = ''; if ($vip_level) { $vip_img_src = zibpay_get_vip_icon_img_url($vip_level); $badge_size = round($size * 0.35); // 徽章尺寸为头像的35% $vip_badge = ''; } echo ''; } echo '
    '; } function form($instance) { $badge = $instance['badge'] ?? '最近访客'; $pos = $instance['pos'] ?? 'right'; $num = $instance['num'] ?? 12; $size = $instance['size'] ?? 50; $fontSize = $instance['fontSize'] ?? 0.9; ?>