Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

Custom 'per_page' screen option not updating in Wordpress admin area

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!


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

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...