关于给子比主题的个人中心页面添加投诉页面协议页面实名认证页面入口功能的详细教程记录

懒得说废话了,暂时不出售该功能

懒人包专用下载覆盖即可,路径定位\zibll\inc\functions\user\page.php文件

代码修改方式如下

156行左右

if (_pz('user_auth_s', true)) {
        $tabs_array['auth'] = array(
            'title'    => '官方认证',
            'nav_attr' => 'drawer-title="官方认证"',
            'loader'   => '<div style="padding: 40px 20px;" class="colorful-bg c-blue flex jc zib-widget"><div class="colorful-make"></div><div class="text-center"><div class="em4x"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-user-auth"></use></svg></div><div class="mt10 em14 padding-w10 font-bold mb40">官方认证</div><div class="placeholder" style="width: 120px;height: 30px;">  </div></div></div>',
        );
    }

163行左右添加

$tabs_array['security'] = array(
        'title'         => '我的协议',
        'nav_attr'      => 'drawer-title="我的协议"',
        'content_class' => 'security-settings',
        'loader'        => '<div class="zib-widget">
                                <div class="placeholder k1 mb10"></div>
                                <div class="placeholder k1 mb10"></div>
                                <div class="placeholder s1"></div>
                                <div class="placeholder t1 mt20"></div>
                                <div class="placeholder s2"></div>
                                <div class="placeholder k1 mb10"></div>
                                <div class="placeholder k1 mb10"></div>
                                <div class="placeholder s1"></div>
                                <div class="placeholder t1 mt20"></div>
                                <div class="placeholder s2"></div>
                            </div>',
        'content_func'  => 'zib_main_user_tab_content_security', // 添加此行
        );
    
    
        $tabs_array['complaint'] = array(
        'title'         => '我的投诉',
        'nav_attr'      => 'drawer-title="我的投诉"',
        'content_class' => 'complaint-settings',
         'loader'        => '<div class="zib-widget">
                          <div class="placeholder k1 mb10"></div>
                            <div class="placeholder k1 mb10"></div>
                            <div class="placeholder s1"></div>
                            <div class="placeholder t1 mt20"></div>
                            <div class="placeholder s2"></div>
                            <div class="placeholder k1 mb10"></div>
                            <div class="placeholder k1 mb10"></div>
                            <div class="placeholder s1"></div>
                            <div class="placeholder t1 mt20"></div>
                            <div class="placeholder s2"></div>
                        </div>',
    'content_func'  => 'zib_main_user_tab_content_complaint', // 添加此行
    );
    
                $tabs_array['authentication'] = array(
            'title'         => '实名认证',
            'nav_attr'      => 'drawer-title="实名认证"',
            'content_class' => 'sm_authentication-settings',
            'loader'        => '<div class="zib-widget">
                                    <div class="placeholder k1 mb10"></div>
                                    <div class="placeholder k1 mb10"></div>
                                    <div class="placeholder s1"></div>
                                    <div class="placeholder t1 mt20"></div>
                                    <div class="placeholder s2"></div>
                                    <div class="placeholder k1 mb10"></div>
                                    <div class="placeholder k1 mb10"></div>
                                    <div class="placeholder s1"></div>
                                    <div class="placeholder t1 mt20"></div>
                                    <div class="placeholder s2"></div>
                                </div>',
            'content_func'  => 'zib_main_user_tab_content_authentication', // 添加此行
        );

319行左右

if (_pz('user_auth_s', true)) {
        $buttons[] = array(
            'html' => '',
            'icon' => zib_get_svg('user-auth'),
            'name' => '官方认证',
            'tab'  => 'auth',
        );
    }

327左右添加

$buttons[] = array(
            'html' => '',
            'icon' => '<svg t="1688630862278" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6861" width="200" height="200"><path d="M341.333333 0h398.222223a227.555556 227.555556 0 0 1 227.555555 227.555556v568.888888a227.555556 227.555556 0 0 1-227.555555 227.555556H341.333333a227.555556 227.555556 0 0 1-227.555555-227.555556V227.555556a227.555556 227.555556 0 0 1 227.555555-227.555556z" fill="#4C7BF6" p-id="6862"></path><path d="M682.666667 824.604444l-100.295111 53.020445 19.342222-111.786667-81.351111-79.075555 112.298666-16.042667L682.666667 568.888889l50.005333 101.831111 112.298667 16.099556-81.351111 79.075555 19.342222 111.729778z" fill="#FFFFFF" p-id="6863"></path><path d="M56.888889 227.555556m56.888889 0l0 0q56.888889 0 56.888889 56.888888l0 455.111112q0 56.888889-56.888889 56.888888l0 0q-56.888889 0-56.888889-56.888888l0-455.111112q0-56.888889 56.888889-56.888888Z" fill="#DBE5FD" p-id="6864"></path></svg>',
            'name' => '我的协议',
            'tab'  => 'security',
        );
    
    
            $buttons[] = array(
            'html' => '',
            'icon' => '<svg t="1688968573785" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5245" width="200" height="200"><path d="M232.727273 117.410909m93.090909 0l372.363636 0q93.090909 0 93.090909 93.090909l0 512q0 93.090909-93.090909 93.090909l-372.363636 0q-93.090909 0-93.090909-93.090909l0-512q0-93.090909 93.090909-93.090909Z" fill="#B177ED" opacity=".8" p-id="5246"></path><path d="M337.454545 233.774545m23.272728 0l302.545454 0q23.272727 0 23.272728 23.272728l0 0q0 23.272727-23.272728 23.272727l-302.545454 0q-23.272727 0-23.272728-23.272727l0 0q0-23.272727 23.272728-23.272728Z" fill="#FFFFFF" p-id="5247"></path><path d="M337.454545 373.387636m23.272728 0l186.181818 0q23.272727 0 23.272727 23.272728l0 0q0 23.272727-23.272727 23.272727l-186.181818 0q-23.272727 0-23.272728-23.272727l0 0q0-23.272727 23.272728-23.272728Z" fill="#FFFFFF" p-id="5248"></path><path d="M814.568727 907.636364h-605.090909a93.090909 93.090909 0 0 1-93.090909-93.090909v-334.289455a93.090909 93.090909 0 0 1 130.653091-85.154909l227.397818 100.305454a93.090909 93.090909 0 0 0 75.147637 0l227.397818-100.305454a93.090909 93.090909 0 0 1 130.676363 85.154909v334.289455a93.090909 93.090909 0 0 1-93.090909 93.090909z" fill="#8D1DEF" opacity=".8" p-id="5249"></path></svg>',
            'name' => '我的投诉',
            'tab'  => 'complaint',
        );
    
    $buttons[] = array(
            'html' => '',
            'icon' => '<svg t="1690081867544" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4470" width="200" height="200"><path d="M798.378667 620.544c-84.309333 0.341333-157.013333 69.632-156.672 158.037333 0.341333 80.554667 65.877333 149.162667 146.432 156.672h22.869333c80.554667-7.850667 141.653333-73.386667 141.312-158.037333-0.341333-88.064-69.632-157.013333-153.941333-156.672zM190.122667 987.818667s60.074667-303.445333 339.968-327.338667c0 0-118.784 42.666667 20.138666 210.944l107.861334 118.442667-467.968 2.048v-4.096zM527.36 58.026667c-141.994667 0.682667-256.341333 116.053333-256 258.048 0.682667 134.144 104.789333 245.077333 238.933333 256h38.229334c130.389333-11.946667 237.226667-119.808 236.544-258.048-0.341333-141.994667-115.712-256.682667-257.706667-256z" fill="#FFDFD2" p-id="4471"></path><path d="M579.242667 957.098667c-16.725333 0-29.013333 15.36-29.013334 29.013333 0 16.725333 12.288 29.013333 29.013334 29.013333s29.013333-12.288 29.013333-29.013333c0-17.066667-12.288-29.013333-29.013333-29.013333zM700.416 100.352c-59.733333-61.098667-139.605333-94.549333-224.938667-94.549333-83.968 0-162.816 33.109333-221.866666 93.184-58.709333 59.733333-90.794667 138.922667-90.794667 223.573333 0 119.466667 66.901333 228.010667 169.301333 278.528-66.901333 22.869333-126.634667 62.464-174.08 114.688-53.589333 59.050667-89.088 132.096-102.741333 211.285333v1.706667c0 47.786667 38.912 86.698667 86.698667 86.698667H464.213333c17.408 0 29.013333-19.797333 29.013334-33.109334 0-16.725333-12.288-29.013333-29.013334-29.013333H153.6c-8.192 0-18.090667-5.12-23.893333-12.288-2.389333-2.730667-5.802667-8.192-4.778667-14.336 26.282667-149.845333 168.618667-275.797333 324.266667-287.061333 4.778667 0 9.898667-1.024 15.018666-2.048 4.096-0.682667 8.533333-1.706667 11.605334-1.706667h19.797333c2.730667 0 63.488-4.096 99.669333-23.893333 117.76-48.810667 193.536-162.133333 193.536-288.768 1.706667-83.968-29.696-162.816-88.405333-222.890667z m22.186667 218.453333c0 64.170667-23.552 124.928-65.877334 170.666667-42.325333 45.738667-100.010667 72.704-162.133333 76.458667h-37.546667c-62.805333-5.461333-120.490667-33.109333-162.474666-77.824C251.904 442.368 228.693333 382.293333 228.693333 318.805333c0-136.533333 110.592-247.125333 246.784-247.125333s247.125333 110.592 247.125334 247.125333z" fill="#F96D28" p-id="4472"></path><path d="M907.605333 642.389333c-39.936-39.936-92.501333-61.781333-148.138666-61.781333s-108.202667 21.845333-148.138667 61.781333c-39.936 39.936-61.781333 92.501333-61.781333 148.138667s21.845333 108.202667 61.781333 148.138667c39.936 39.936 92.501333 61.781333 148.138667 61.781333s108.202667-21.845333 148.138666-61.781333c39.936-39.936 61.781333-92.501333 61.781334-148.138667s-21.845333-108.202667-61.781334-148.138667z m2.389334 148.138667c0 84.309333-66.218667 150.528-150.528 150.528s-150.528-66.218667-150.528-150.528 66.218667-150.528 150.528-150.528 150.528 65.877333 150.528 150.528z" fill="#F96D28" p-id="4473"></path><path d="M836.266667 759.808L763.221333 832.853333c0 3.754667-3.754667 3.754667-3.754666 7.509334-3.754667 3.754667-7.509333 7.509333-11.605334 7.509333-7.509333 3.754667-11.605333 3.754667-15.36 0-3.754667 0-3.754667-3.754667-7.509333-7.509333l-46.08-46.08c-15.36-15.36-7.509333-19.114667 0-26.965334 15.36-15.36 19.114667-3.754667 26.965333 3.754667l26.965334 26.965333c30.72-30.72 38.229333-42.325333 73.045333-73.045333 15.36-15.36 22.869333-7.509333 26.965333-3.754667 7.168 11.605333 18.773333 23.210667 3.413334 38.570667z" fill="#F96D28" p-id="4474"></path></svg>',
            'name' => '实名认证',
            'tab'  => 'authentication',
        );

600行左右

//获取用户中心绑定邮箱等功能的按钮
function zib_get_user_set_link($class = '', $tab = '', $text = '')
{
    $user_id = get_current_user_id();
    if (!$user_id) {
        return;
    }

    $args = array(
        'tag'           => 'a',
        'class'         => 'collection-set-link ' . $class,
        'mobile_bottom' => true,
        'height'        => 220,
        'data_class'    => 'modal-mini',
        'text'          => $text,
        'query_arg'     => array(
            'tab'    => $tab,
            'action' => 'user_set_modal',
        ),
    );

    //每次都刷新的modal
    return zib_get_refresh_modal_link($args);
}

629行左右添加

//ZYX-我的协议页面

    function zib_main_user_tab_content_security()
    {
        $user_id = get_current_user_id();
      $mybankuai = 'style="clear: both;background: var(--main-bg-color);padding: 15px;box-shadow: 0 0 10px var(--main-shadow);border-radius: var(--main-radius);"';
      $myli ='style="padding: 10px;background: rgb(243, 243, 243);margin-bottom: 10px;border-radius: 5px;"';
      $myshuliang ='style="padding: 5px;margin-bottom: 5px;"';
      $icon = '<svg t="1688652517567" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4640" width="200" height="200" style="margin-right: 5px;"><path d="M512 512m-512 0a512 512 0 1 0 1024 0 512 512 0 1 0-1024 0Z" fill="#44CB5C" opacity=".15" p-id="4641"></path><path d="M432.049231 618.732308a402.628923 402.628923 0 0 0-118.547693-143.36L236.307692 549.809231a555.992615 555.992615 0 0 1 206.769231 200.861538 1145.107692 1145.107692 0 0 1 154.387692-223.704615A503.256615 503.256615 0 0 1 787.692308 372.184615V320.590769a819.2 819.2 0 0 0-355.643077 298.141539z" fill="#44CB5C" p-id="4642"></path></svg>';
      $my_prompt = 'style="margin-bottom: 10px;padding: 15px;color: #04b97e;background: rgba(8, 196, 37, 0.1);"';
      
        // 获取当前用户已签订协议的页面ID及标题
        global $wpdb;
        $results = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT meta_key 
                 FROM {$wpdb->prefix}usermeta 
                 WHERE user_id = %d AND meta_key LIKE 'agreement_checked_%%'",
                $user_id
            )
        );
        // 统计已签订协议数量
        $agreement_count = count($results);
        // 初始化协议内容
        $agreement_content = '';
        foreach ($results as $result) {
            $page_id = str_replace('agreement_checked_', '', $result->meta_key);
            $page_title = get_the_title($page_id);
            $page_link = get_permalink($page_id);
            $agreement_content .= '<p ' . $myli . '><a href="' . $page_link . '">' . $page_title . '</a></p>';
        }
      
      $html .= "<div $my_prompt>为了确保您的权益和安全,我们诚挚邀请您积极参与,共同签署协议,共创一个更加可靠和互信的网络环境。</div>";
        $inner_div = "<div $myshuliang>" . $icon . "当前已签署:" . $agreement_count . " 份协议</div>";
        $html = "<div class='myxieyi' $mybankuai>" .$html . $inner_div . $agreement_content . '</div>';
        return zib_get_ajax_ajaxpager_one_centent($html);
    }
    add_filter('main_user_tab_content_security', 'zib_main_user_tab_content_security');

// ZYX-我的投诉页面

function zib_main_user_tab_content_complaint()
{
    $current_user_id = get_current_user_id();
    $my_complaint_style = '<div style="margin-bottom: 10px;padding: 15px;color: #0986f5;background: #337ab71c;">加入网络监督员维护网络网络环境,举报不良信息,共建和谐绿色网络环境</div>';
    $my_complaint_div ='style="background: #eeeeee57;padding: 15px;margin-bottom: 15px;"';
    $my_complaint_time ='style="background: rgb(239, 243, 245);padding: 10px;color: #55798a;margin-bottom: auto;"';

    global $wpdb;
    $table_name = $wpdb->prefix . 'zib_message';

    $query = $wpdb->prepare(
        "SELECT * FROM $table_name WHERE send_user = %d AND type = %s ORDER BY status ASC, content ASC",
        $current_user_id,
        'user_report'
    );
    $results = $wpdb->get_results($query);

    //如果查询记录为空则显示
    if (empty($results)) {
        $html = '<form class="zib-widget">' . $my_complaint_style . '<div ' . $my_complaint_div . '>您当前没有举报记录</div></form>';
    } else {
        $html = '<form class="zib-widget">' . $my_complaint_style;
        foreach ($results as $result) {
            // 提取提交举报的时间
            preg_match('/提交时间:(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/', $result->content, $matches);
            if (isset($matches[1])) {
                $submission_time = $matches[1];
                $html .= "<p $my_complaint_time>提交时间:$submission_time</p>";
            }

            // 提取被举报用户到提交时间之间举报信息
            $start_pos = strpos($result->content, '被举报用户:');
            $end_pos = strpos($result->content, '提交时间:');
            $filtered_content = substr($result->content, $start_pos, $end_pos - $start_pos);
            $filtered_content = str_replace('<br>', '<br class="complaint-br">', $filtered_content);

            $html .= "<div $my_complaint_div>" . $filtered_content;

            // 判断处理进度并添加相应的样式和文字
            if ($result->status == 1) {
                // 处理完成
                $html .= '<div class="progress-bar">';
                $html .= '<div class="progress-bg progress-completed"></div>';
                $html .= '</div>';
                $html .= '<p style="margin-bottom: 5px;">投诉已经处理</p>';
            } else {
                // 正在处理
                $html .= '<div class="progress-bar">';
                $html .= '<div class="progress-bg progress-processing"></div>';
                $html .= '</div>';
                $html .= '<p style="margin-bottom: 5px;">正在处理中...</p>';
            }

            $html .= '</div>';
        }
        $html .= '</form>';
    }

    return zib_get_ajax_ajaxpager_one_centent($html);
}

add_filter('main_user_tab_content_complaint', 'zib_main_user_tab_content_complaint');

// 添加CSS样式
function add_custom_styles() {
    echo '
    <style>
    .progress-bar{
      width: 100%;
      height: 10px;
      overflow: hidden;
      box-sizing: border-box;
      border-radius: 24px;
      background-color: rgba(180, 160, 120, .2);
      position: relative;
    box-shadow: unset;
    margin-bottom: 5px;
    }

    .progress-bg{
      width: 10%;
      height: 100%;
      overflow: hidden;
      box-sizing: border-box;
      background-image: linear-gradient(135deg, #00BFFF 25%,#FA8072 0,#FA8072 50%,#00BFFF 0,#00BFFF 75%, #FA8072 0);
      border-radius: 24px;
      animation: panoramic 20s linear infinite;
      background-size: 32px 100%;
    }

    @keyframes panoramic{
      to {
        background-position: 200% 0;
      }
    }

    .progress-completed {
      width: 100%;
      background-image: linear-gradient(135deg, #4abd15bd 25%,#4abd15bd 0,#4abd15bd 50%,#4abd15bd 0,#4abd15bd 75%, #4abd15bd 0);
      animation: none;
    }

    .progress-processing {
      width: 50%;
      background-image: linear-gradient(135deg, #ffe8a4 25%,#ffd353 0,#ffd353 50%,#ffe8a4 0,#ffe8a4 75%, #ffd353 0);
      animation: none;
    }
    
    .complaint-br {
        display: block;
        margin-bottom: 5px;
    }
    </style>
    ';
}

add_action('wp_head', 'add_custom_styles');

    // ZYX-实名认证页面
function zib_main_user_tab_content_authentication()
{
    // 获取当前用户ID
    $current_user_id = get_current_user_id();
    // 检查是否提交了表单
    if (isset($_POST['submit'])) {
        $name = sanitize_text_field($_POST['name']);
        $sfz = sanitize_text_field($_POST['sfz']);

        // 检查身份证号码是否已存在于数据库中
        $existing_user = get_users(array('meta_key' => 'user_sfz', 'meta_value' => $sfz));
        if (!empty($existing_user)) {
            // 身份证号码已存在,实名认证失败
            $html = '<div>实名认证失败,该身份证号码已被使用。</div>';
        } else {
            // 使用API接口验证身份证号码
            $url = 'https://zj.v.api.aa1.cn/api/sfz/?sfz=' . $sfz;
            $response = wp_remote_get($url);

            // 检查API请求是否成功
            if (is_wp_error($response)) {
                // 处理API请求失败的情况
                $html = '<div>实名认证失败,请稍后再试。</div>';
            } else {
                $body = wp_remote_retrieve_body($response);
                $data = json_decode($body, true);
    
                // 根据API响应结果显示实名认证成功或失败的信息
                if (isset($data['code']) && isset($data['msg'])) {
                    // 根据API响应中的msg判断实名认证成功或失败
                    if ($data['msg'] === '身份证校验正确') {
                        // 实名认证成功
                        $html = '<div style="padding: 40px 20px;">实名认证成功</div>';
                        // 将实名认证成功的状态和当前用户ID保存到数据库
                        update_user_meta($current_user_id, 'user_authentication', 'completed');
                        update_user_meta($current_user_id, 'user_sfz', $sfz);
                    } elseif ($data['msg'] === '身份证校验错误') {
                        // 实名认证失败
                        $html = '<div>实名认证失败,请稍后再尝试!</div>';
                    } else {
                        // 其他情况,显示无效的API响应信息
                        $html = '<div>无效的API响应。</div>';
                    }
                } else {
                    // API响应缺少必要的数据
                    $html = '<div>无效的API响应。</div>';
                }
            }
        }
    } else {
            // 查询当前用户的实名认证状态(假设保存在 user_authentication 表中)
            $authentication_status = get_user_meta($current_user_id, 'user_authentication', true);
            // 判断实名认证状态
            if ($authentication_status === 'completed') {
                // 实名认证已完成,直接显示成功信息
                $html = '<div class="text-center">
                <div class="em4x"><svg t="1690084687298" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4614" width="200" height="200"><path d="M911.872 928.256H112.128C50.176 928.256 0 878.08 0 816.128V178.688C0 116.736 50.176 66.56 112.128 66.56H911.36c61.952 0 112.128 50.176 112.128 112.128v637.44c0.512 61.952-49.664 112.128-111.616 112.128z" fill="#577AF6" p-id="4615"></path><path d="M430.08 492.544c28.672-23.552 47.104-59.392 47.104-99.328 0-71.168-57.856-129.024-129.536-129.024S218.624 321.536 218.624 392.704c0 39.936 18.432 75.776 47.104 99.328-89.088 33.28-152.064 118.784-152.064 219.648v14.336c0 3.072 2.56 5.632 5.632 5.632h458.24c3.072 0 5.632-2.56 5.632-5.632V711.68c-0.512-100.352-64-185.856-153.088-219.136zM644.096 442.368H829.44c6.656 0 11.776-5.12 11.776-11.776v-25.6c0-6.656-5.12-11.776-11.776-11.776h-185.344c-6.656 0-11.776 5.12-11.776 11.776v25.6c0 6.144 5.12 11.776 11.776 11.776zM644.096 573.44H829.44c6.656 0 11.776-5.12 11.776-11.776v-25.6c0-6.656-5.12-11.776-11.776-11.776h-185.344c-6.656 0-11.776 5.12-11.776 11.776v25.6c0 6.656 5.12 11.776 11.776 11.776zM899.072 655.36h-254.976c-6.656 0-11.776 5.12-11.776 11.776v25.6c0 6.656 5.12 11.776 11.776 11.776h254.976c6.656 0 11.776-5.12 11.776-11.776v-25.6c0-6.656-5.12-11.776-11.776-11.776z" fill="#FFFFFF" p-id="4616"></path></svg></div>
                <div class="mt10 em14 padding-w10 font-bold mb40">实名认证</div>
                <div class="em12 mb10" style="text-align: left;"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-user-auth"></use></svg><b class="ml6">该用户已实名</b></div>
                <div>实名状态:实名认证成功</div></div>';
            } else {
            // 显示输入框和提交按钮
            $html = '<div class="text-center">
              <div class="em4x"><svg t="1690084687298" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4614" width="200" height="200"><path d="M911.872 928.256H112.128C50.176 928.256 0 878.08 0 816.128V178.688C0 116.736 50.176 66.56 112.128 66.56H911.36c61.952 0 112.128 50.176 112.128 112.128v637.44c0.512 61.952-49.664 112.128-111.616 112.128z" fill="#577AF6" p-id="4615"></path><path d="M430.08 492.544c28.672-23.552 47.104-59.392 47.104-99.328 0-71.168-57.856-129.024-129.536-129.024S218.624 321.536 218.624 392.704c0 39.936 18.432 75.776 47.104 99.328-89.088 33.28-152.064 118.784-152.064 219.648v14.336c0 3.072 2.56 5.632 5.632 5.632h458.24c3.072 0 5.632-2.56 5.632-5.632V711.68c-0.512-100.352-64-185.856-153.088-219.136zM644.096 442.368H829.44c6.656 0 11.776-5.12 11.776-11.776v-25.6c0-6.656-5.12-11.776-11.776-11.776h-185.344c-6.656 0-11.776 5.12-11.776 11.776v25.6c0 6.144 5.12 11.776 11.776 11.776zM644.096 573.44H829.44c6.656 0 11.776-5.12 11.776-11.776v-25.6c0-6.656-5.12-11.776-11.776-11.776h-185.344c-6.656 0-11.776 5.12-11.776 11.776v25.6c0 6.656 5.12 11.776 11.776 11.776zM899.072 655.36h-254.976c-6.656 0-11.776 5.12-11.776 11.776v25.6c0 6.656 5.12 11.776 11.776 11.776h254.976c6.656 0 11.776-5.12 11.776-11.776v-25.6c0-6.656-5.12-11.776-11.776-11.776z" fill="#FFFFFF" p-id="4616"></path></svg></div>
              <div class="mt10 em14 padding-w10 font-bold mb40">实名认证</div>
              <div class="em12 mb10" style="text-align: left;"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-user-auth"></use></svg><b class="ml6">申请认证</b></div>
              <div class="muted-color mb20" style="text-align: left;"><div class="ml10">
              <li>成功完成实名认证的用户可以同时享受多种优先待遇</li>
                <li>申请认证请确保信息属实,提交申请后一般2-3个工作日处理完成</li>
                <li>处理完成后会有消息及邮件通知,请注意查看</li>
              </div></div>
                        <div class="mb30" style="margin-bottom: auto;"><label class="author-set-left" for="name">姓名:</label> <div class="author-set-right"><input class="form-control" type="text" name="name" id="name" required><br></div></div>
                        <div class="mb30"><label class="author-set-left" style="width: auto;" for="sfz">身份证号码:</label><div class="author-set-right"><input class="form-control" type="text" name="sfz" id="sfz" required><br></div></div>
                        <input class="user-auth-apply but jb-blue padding-lg btn-block mt20" type="submit" name="submit" value="提交认证">
                    </div>';
        }
      }
        $html = '<form class="colorful-bg c-blue flex jc zib-widget" style="padding: 40px 20px;" method="POST">' . $html . '</form>';
        return zib_get_ajax_ajaxpager_one_centent($html);
    }
    add_filter('main_user_tab_content_authentication', 'zib_main_user_tab_content_authentication');

func.php文件里添加这段代码

// 引入SweetAlert2 插件的样式
function load_sweetalert_scripts() {
    wp_enqueue_style( 'sweetalert2', 'https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18/dist/sweetalert2.min.css' );
    wp_enqueue_script( 'sweetalert2', 'https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18/dist/sweetalert2.min.js', array(), '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'load_sweetalert_scripts' );

// 在后台创建插件页面
function agreement_plugin_page() {
    global $post; // 添加全局变量$post,用于获取当前页面的ID

    // 设置一个签署成功的变量名
    $success = '<p style="color:green;text-align: center;background: rgba(136, 136, 136, .1);padding: 5px;">您已经成功签署本内容!</p>';

    // 检查当前用户是否已登录
    $is_logged_in = is_user_logged_in();

    $current_user_id = get_current_user_id();

    // 获取当前页面的ID
    $page_id = isset($post->ID) ? $post->ID : '';

    // 检查当前用户是否已签订协议
    $agreement_checked = get_user_meta($current_user_id, 'agreement_checked_' . $page_id, true);

    // 如果用户点击提交按钮且勾选了同意协议复选框,则更新用户元数据,并显示成功签署提示信息
    if (isset($_POST['submit']) && isset($_POST['agreement_checkbox'])) {
        update_user_meta($current_user_id, 'agreement_checked_' . $page_id, true);
        $agreement_checked = true; // 更新变量的值为true
    }
    
    if ($agreement_checked || (isset($_POST['submit']) && isset($_POST['agreement_checkbox']))) {
        echo $success;
        return; // 在签署成功后直接返回,无需执行下面的代码
    }
    

    echo '<form method="post" id="agreement-form" style="text-align: center;background: rgba(136, 136, 136, .1);padding: 5px;">';
    echo '<div style="display: inline-flex;">';

    // 如果当前用户未登录则调用登录框到按钮上
    if (!$is_logged_in) {
        echo '<button class="newadd-btns hover-show but nowave jb-blue radius" style="border-radius: 5px"><a href="javascript:;" class="signin-loader">登录</a></button>';
    } else {
        echo '<input type="checkbox" style="height: 20px;width: 20px;margin-right: 5px;" name="agreement_checkbox" id="agreement_checkbox"> 我已阅读并同意上述内容<br>';
        echo '<input type="hidden" name="page_id" value="' . $page_id . '">'; // 添加一个隐藏字段保存当前页面的ID
        echo '<input type="submit" class="newadd-btns hover-show but nowave jb-blue radius" style="border-radius: 5px;line-height: 0.5;margin-left: 5px;" name="submit" value="确认">';
    }

    echo '</div>';
    echo '</form>';

    // 添加 JavaScript 来进行表单验证
    echo '<script>
        document.getElementById("agreement-form").addEventListener("submit", function(event) {
            if (!document.getElementById("agreement_checkbox").checked) {
                event.preventDefault();
                Swal.fire({
                    icon: "error",
                    title: "提交失败",
                    text: "请您先勾选本内容后再提交!",
                    confirmButtonText: "确定"
                });
            }
        });
    </script>';
}

// 注册短代码
function agreement_shortcode() {
    ob_start();
    agreement_plugin_page(); // 调用<a href="https://www.godoublog.com/tag/%e6%8f%92%e4%bb%b6" title="更多关于 插件 的文章-GOdou社区" target="_blank">插件</a>页面
    return ob_get_clean();
}
add_shortcode('agreement', 'agreement_shortcode');

© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
评论 共3条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复
    • 的头像-知新网w6900565120
    • 的头像-知新网Xiumiao0