在分页页面上保存选项

时间:2014-03-02 20:24:40

标签: php wordpress pagination options

我开发了一个WordPress插件,其中包含一些选项,这些选项在没有分页的情况下工作正常。我是WordPress插件开发的新手。问题是我在插件的选项页面添加了分页,但问题是当我点击保存更改时,如果我在第2页,那么更改将重置在第1页上的选项和所有其他页面上。它看起来像这样:

http://usmanali.net/plugin-page.png

我该如何解决?我的意思是如何才能使更改仅保存在特定页面上显示的选项而不是分页的其他页面上?

这是代码:

public function register_settings_and_fields()
    {

        global $wpdb;

        register_setting('par_plugin_options', 'par_plugin_options'); // 3rd param required for cb

        add_settings_section('par_main_section', 'Check / Uncheck the pages against each user', array($this, 'par_main_section_cb'), 'ua_par_settings'); //id, title of section, cb, page

        $users = get_users();

        $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;

        $limit = 2;

        $offset = ( $pagenum - 1 ) * $limit;

            $args = array(
                'blog_id'      => $GLOBALS['blog_id'],
                'role'         => '',
                'meta_key'     => '',
                'meta_value'   => '',
                'meta_compare' => '',
                'meta_query'   => array(),
                'include'      => array(),
                'exclude'      => array(),
                'orderby'      => 'login',
                'order'        => 'ASC',
                'offset'       => '',
                'search'       => '',
                'number'       => $limit,
                'count_total'  => false,
                'fields'       => 'all',
                'who'          => ''
             );

        $entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}users LIMIT $offset, $limit" );

        if( $entries ) {

        $count = 1;

            foreach ( $entries as $user ) {

            add_settings_field($user->user_login, '<center>' . $user->user_nicename . '<br />(' . $user->user_email . ')</center>', array($this, 'process_callback'), 'ua_par_settings', 'par_main_section', array( 'value' => $user->user_login, ));

            $count++;

            };

        }

        $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM {$wpdb->users}" );

        $num_of_pages = ceil( $total / $limit );
        $page_links = paginate_links( array(
            'base' => add_query_arg( 'pagenum', '%#%' ),
            'format' => '',
            'prev_text' => __( '&laquo;', 'aag' ),
            'next_text' => __( '&raquo;', 'aag' ),
            'total' => $num_of_pages,
            'current' => $pagenum
        ) );

        if ( $page_links ) {
            echo '<div class="tablenav" style="float: right !importnat;"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div></div>';
        }

    }

0 个答案:

没有答案