Making WordPress.org

Changeset 2001


Ignore:
Timestamp:
10/20/2015 09:47:41 AM (9 years ago)
Author:
ocean90
Message:

Rosetta Roles: Add a 'per_page' screen option for the list table.

Location:
sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/class-translation-editors-list-table.php

    r1792 r2001  
    6767     */
    6868    public function prepare_items() {
    69         $search = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
    70         $per_page = 10;
    71         $paged = $this->get_pagenum();
     69        $search =   isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
     70        $per_page = $this->get_items_per_page( 'translation_editors_per_page', 10 );
     71        $paged =    $this->get_pagenum();
    7272
    7373        $args = array(
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r1944 r2001  
    4747        add_action( 'admin_menu', array( $this, 'register_translation_editors_page' ) );
    4848        add_filter( 'user_row_actions', array( $this, 'promote_user_to_translation_editor' ), 10, 2 );
     49        add_filter( 'set-screen-option', array( $this, 'save_custom_screen_options' ), 10, 3 );
    4950    }
    5051
     
    210211
    211212        add_action( 'load-' . $this->translation_editors_page, array( $this, 'load_translation_editors_page' ) );
     213        add_action( 'load-' . $this->translation_editors_page, array( $this, 'register_screen_options' ) );
    212214        add_action( 'admin_print_scripts-' . $this->translation_editors_page, array( $this, 'enqueue_scripts' ) );
    213215        add_action( 'admin_footer-' . $this->translation_editors_page, array( $this, 'print_js_templates' ) );
     
    258260
    259261    /**
     262     * Registers a 'per_page' screen option for the list table.
     263     */
     264    public function register_screen_options() {
     265        $option = 'per_page';
     266        $args   = array(
     267            'default' => 10,
     268            'option'  => 'translation_editors_per_page'
     269        );
     270        add_screen_option( $option, $args );
     271    }
     272
     273    /**
     274     * Adds the 'per_page' screen option to the whitelist so it gets saved.
     275     *
     276     * @param bool|int $new_value Screen option value. Default false to skip.
     277     * @param string   $option    The option name.
     278     * @param int      $value     The number of rows to use.
     279     * @return bool|int New screen option value.
     280     */
     281    public function save_custom_screen_options( $new_value, $option, $value ) {
     282        if ( 'translation_editors_per_page' !== $option ) {
     283            return $new_value;
     284        }
     285
     286        $value = (int) $value;
     287        if ( $value < 1 || $value > 999 ) {
     288            return $new_value;
     289        }
     290
     291        return $value;
     292    }
     293
     294    /**
    260295     * Loads either the overview or the edit handler.
    261296     */
Note: See TracChangeset for help on using the changeset viewer.