Title: filter set-screen-option not triggering
Last modified: August 21, 2016

---

# filter set-screen-option not triggering

 *  [Robb Caldwell](https://wordpress.org/support/users/robbcaldwell/)
 * (@robbcaldwell)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/filter-set-screen-option-not-triggering/)
 * Displaying my own table of records, I want to have a “Per Page” option in the
   Screen Options pull down. So I setup my option:
 *     ```
       function add_options()
       {
           $option = 'per_page';
   
           $args = array(
               'label' => 'Properties',
               'default' => 20,
               'option' => 'my_custom_per_page'
           );
   
           add_screen_option( $option, $args );
           add_filter('set-screen-option', 'my_custom_set_option', 10, 3);
       }
   
       function my_custom_set_option($status, $option, $value)
       {
           return $value;
       }
       ```
   
 * This works fine, the option is created and displayed in the _Screen Options_ 
   pull down. However, my_custom_set_option is NEVER called and when you change 
   the value of my_custom_per_page in the Screen Options, it will revert back to
   its original value and never save.
 * Furthermore, looking at the core code, wp-admin/includes/misc.php, line 361, 
   version 3.5.2
 * `$value = apply_filters('set-screen-option', false, $option, $value);`
 * $value is always returned as false.
 * Looking up the apply_filters function, wp-includes/plugin.php, line 137
 * `function apply_filters($tag, $value)`
 * The second parameter of apply_filters is $value, but passed ‘false’
 * If I comment out this line it saves fine.
 * So is this a bug?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [AntoineH](https://wordpress.org/support/users/antoineh/)
 * (@antoineh)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/filter-set-screen-option-not-triggering/#post-3931379)
 * Any new thoughts on this?
 * I am having the same problem as described above. My callback for the set-screen-
   option filter is never called.
 * When commenting out line 360 in misc.php (v3.6)
 * `// $value = apply_filters('set-screen-option', false, $option, $value);`
 * the value is saved and I can change the items per page on my plugin’s page. But
   that’s not the way to go.
 * If I change my option name to one of the default ones from WordPress (e.g. ‘users_per_page’)
   it’s also working.
    At the moment I’m using this solution, as I am also showing
   users in my table. But I am still curious if this is a bug or if I am doing something
   wrong.
 *  Thread Starter [Robb Caldwell](https://wordpress.org/support/users/robbcaldwell/)
 * (@robbcaldwell)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/filter-set-screen-option-not-triggering/#post-3931380)
 * Pretty sure it’s a bug. I have already started a bug report for it, no response
   yet.
 * [http://core.trac.wordpress.org/ticket/24786](http://core.trac.wordpress.org/ticket/24786)
 *  [Ken Brucker](https://wordpress.org/support/users/draca/)
 * (@draca)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/filter-set-screen-option-not-triggering/#post-3931417)
 * It’s not a bug. The ‘set-screen-filter’ is applied very early, even before the
   admin_init action. When I setup the filter as my plugin loaded I was able to 
   get this to work properly.
 *  [Tijmen Smit](https://wordpress.org/support/users/tijmensmit/)
 * (@tijmensmit)
 * [12 years ago](https://wordpress.org/support/topic/filter-set-screen-option-not-triggering/#post-3931420)
 * I also have a problem with the ‘set-screen-option’ filter.
 * If I try this code ( [https://core.trac.wordpress.org/ticket/24786#comment:2](https://core.trac.wordpress.org/ticket/24786#comment:2))
   it works just fine, but I when I try to move it into a class it always fails.
   And I have no idea what I’m doing wrong 🙁
 * [@robb](https://wordpress.org/support/users/robb/) Caldwell did you manage to
   get it working in a class? Could you share the code here?
 * This is what I have now. No matter what I change the ‘plugins_loaded’ to, it 
   never saves the value. The ‘my_custom_per_page’ is created in the db though.
 *     ```
       class Screen_Option_Test {
   
           function __construct() {
               add_action( 'admin_menu', array( $this, 'create_admin_menu' ) );
               add_action( 'plugins_loaded', array( $this, 'screen_options' ) );
               add_action( 'in_admin_header', array( $this, 'add_options' ) );
           }
   
           function screen_options() {
               add_filter( 'set-screen-option', array( $this, 'my_custom_set_option', 10, 3 ) );
           }
   
            function create_admin_menu() {
               add_menu_page( 'Screen Test', 'Screen Test', 'manage_options', 'screen_test_menu', array( $this, 'screen_test' ) );
           }
   
           function screen_test() {
               echo 'screen test';
           }
   
           function add_options() {
               $option = 'per_page';
   
               $args = array(
                       'label' => 'Properties',
                       'default' => 20,
                       'option' => 'my_custom_per_page'
               );
   
               add_screen_option( $option, $args );
           }
   
           function my_custom_set_option( $status, $option, $value ) {
                   return $value;
           }
       }
   
       new Screen_Option_Test();
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘filter set-screen-option not triggering’ is closed to new replies.

## Tags

 * [apply_filters()](https://wordpress.org/support/topic-tag/apply_filters/)
 * [per_page](https://wordpress.org/support/topic-tag/per_page/)
 * [screen options](https://wordpress.org/support/topic-tag/screen-options/)

 * 4 replies
 * 4 participants
 * Last reply from: [Tijmen Smit](https://wordpress.org/support/users/tijmensmit/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/filter-set-screen-option-not-triggering/#post-3931420)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
