自定义管理页面分页权限错误

时间:2016-08-10 作者:Lucy Brown

我有一个自定义页面,可以拉入用户,我正在使用一些分页。

如果我查看网站前端的页面,效果很好,但当我查看我制作的基本插件中管理区域内的网站时,它不起作用,我会收到一个权限错误“您没有足够的权限访问此页面”

这是下面的代码,我不知道为什么它不起作用,但如果有人有任何线索,我会非常感激,

谢谢

    <?php 
       $total_users = count_users();
       $total_users = $total_users[\'total_users\'];
       $paged = get_query_var(\'paged\');
       $number = 50;
    ?>

    <?php 
        $args = array(
            \'order\' => \'ASC\',
            \'orderby\' => \'display_name\',
            \'count_total\' => \'true\',
            \'role\' => \'subscriber\',
            \'offset\' => $paged ? ($paged) * $number : 0,
            \'number\' => $number,
        );?>



        <?php
            $blogusers = get_users($args);?>

        <?php // Array of WP_User objects.
            foreach ( $blogusers as $user ) {?>

            <?php $userId = $user->ID;?>

            <?php  echo \'<input type="text" value="\' . esc_html( $user->display_name ) . \'">\';?>



            <div id="content">

            <h2>Completed Courses</h2>


                    <!-- COMPLIANCE-->



                        <?php
                            $post_args = array(
                                \'post_type\' => \'tribe_events\',
                                \'eventDisplay\'=>\'custom\',
                                \'start_date\'     => date( \'Y-m-d H:i:s\', strtotime( \'-365 days\' ) ),
                                \'tax_query\' => array(

                                    array(
                                        \'taxonomy\' => \'tribe_events_cat\',
                                        \'field\'    => \'slug\',
                                        \'terms\'    => \'compliance\',
                                        ),
                                            ),

                                            \'meta_query\' => array(
                                                array(
                                                    \'key\' => \'associated_people\',
                                                    \'value\' => \'"\' . $userid . \'"\', // matches exaclty "123", not just 123. This prevents a match for "1234"
                                                    \'compare\' => \'LIKE\'
                                            )
                                        )
                                    ); ?>

                        <!-- MEMBERSHIP A -->                       

                        <?php if( rcp_is_active() && 2 == rcp_get_subscription_id() ) : ?>

                            <?php
                            $post_list = new wp_query( $post_args ); ?>

                                <table style="width:100%">      
                                    <tr>
                                        <td>Compliance</td>
                                    </tr>

                                    <?php
                                        if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                    ?>

                                        <tr>
                                            <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td>
                                            <td><?php the_field(\'cpd_credits\'); ?></td>
                                        </tr>

                        <?php endwhile; else : ?>
                        <?php endif; wp_reset_query(); ?>


                        <?php

                        $total_credit = 0;

                        $post_list = new wp_query( $post_args ); ?>

                        <table style="width:100%">      

                            <?php
                                if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
                                    $cur_credit = get_field(\'cpd_credits\');
                                    $total_credit += $cur_credit;
                            ?>


                            <?php endwhile; else : ?>
                            <?php endif; wp_reset_query(); ?>

                            <tr>
                                <td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
                                    Total: <?php echo $total_credit;?> of 2 in the last 12 months
                                </td>
                            </tr>

                            </table>

                            <?php endif; ?>

                            <!-- END OF MEMBERSHIP A -->

 <?php $pl_args = array(
     \'base\'     => add_query_arg(\'paged\',\'%#%\'),
     \'format\'   => \'\',
     \'total\'    => floor($total_users / $number),
     \'current\'  => max(1, $paged),
  );

  // for ".../page/n"
  if($GLOBALS[\'wp_rewrite\']->using_permalinks())
    $pl_args[\'base\'] = user_trailingslashit(trailingslashit(get_pagenum_link(1)).\'page/%#%/\', \'paged\');


  echo paginate_links($pl_args);?>

1 个回复
SO网友:Lucy Brown

我用另一个帖子解决了这个问题-Pagination Error on Admin (You do not have sufficient permissions)

基本上,我需要将$paged参数更改为$paged=isset($\\u请求[\'paged\')?最大值(1,(int)$\\u请求[\'paged]):1;

以及$pl\\u args[\'base\']=admin\\u url(\'admin.php?page=cpd admin page&paged=%\\u%\')的$pl\\u args参数;

相关推荐

change pagination url

目前,我的分页页面URL为:http://www.example.com/category_name/page/2但我需要将此URL结构更改为:http://www.example.com/category_name/?page=2等有什么解决方案吗?