0

I have a custom page pulling in users and I'm using some pagination.

It works fine if I look at the page on the front end of the site but when I look at the site within the admin area within a basic plugin I've made, it doesn't work and I get a permissions error "You do not have sufficient permissions to access this page."

This is the code below, I have no idea why it's not working, but if anyone has any clues I'd really appreciate it,

Thanks!

    <?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 Answer 1

1

I fixed this using another post - Pagination Error on Admin (You do not have sufficient permissions)

Basically I needed to changed the $paged argument to $paged = isset( $_REQUEST['paged']) ? max( 1, ( int ) $_REQUEST['paged'] ) : 1;

and the $pl_args argument to $pl_args['base'] = admin_url( 'admin.php?page=cpd-admin-page&paged=%_%' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.