WordPress.org

Ready to get started?Download WordPress

Forums

How to save options on paginated pages without resetting the options (1 post)

  1. Usman Ali
    Member
    Posted 4 months ago #

    I have developed a WordPress plugin with some options which are working fine without pagination. I am kind of new to WordPress plugin development. The problem is I added pagination to the plugin's options page but the problem is when I click on save changes and if for example I am on page 2 then the changes are reset on the options which are on page 1 and all other pages. It looks something like this:

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

    How can I fix it? I mean how can make the changes save only for the options displaying on that specific page and not on the other page of the pagination?

    This is the code:

    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(<code>id</code>) 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>';
    			}
    
    		}

Reply

You must log in to post.

About this Topic