Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a custom page in my admin area which has a custom table. But the per_page screen option isn't working! I checked the database and noticed that the option isn't being saved at the wp_usermeta table when I click 'Apply' on the screen options dropdown! But if I insert the option manually on the database, then it works fine; the table shows the correct amount of lines and the per_page option will show the value I set on the database. Here's the plugin code that handles the screen option:

private function __construct() {
    {...}
    add_filter( 'set-screen-option', [ $this, 'set_screen' ], 10, 3 );
    add_action( 'admin_menu', [ $this, 'initialize' ] );
    {...}
}

public function set_screen( $status, $option, $value ) {
    return $value;
}

public function initialize(){

    $products_hook = add_menu_page(
        'Products',
        'Products',
        'manage_options',
        'products',
        [ $this, 'show_products_page' ],
        'dashicons-admin-generic',
        30
    );
    
    add_action( "load-$products_hook", [ $this, 'products_option' ] );
}

public function products_option() {

    $args   = [
        'label'   => 'Products',
        'default' => 20,
        'option'  => 'products_per_page'
    ];

    add_screen_option( 'per_page', $args );
}

Perhaps another plugin is messing up with mine?
Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
417 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...