wordpress - Possible to use add_screen_option to save CPT edit page custom screen option? -


i need add custom screen option admin posts list edit page. can option added. renders fine , saves correctly, per_page screen option no longer gets saved when changed. i've been through following code on , over. traced through wp core set_screen_options(), don't see i'm doing wrong. else see problem?

the code:

add_filter( 'screen_settings',   array( $this, 'show_screen_options' ), 10, 2 ); add_filter( 'set-screen-option', array( $this, 'set_screen_options' ), 11, 3 ); add_action( 'load-edit.php',     array( $this, 'load_edit_php' ), 10, 0 );   /**  * display custom screen options  *  * @param $status  * @param $args  *  * @return string  */ function show_screen_options( $status, $args ) {      $return = $status;      if ( $args->base == 'edit' ) {          $current_val = $this->get_user_meta_current_val( 'edit_ticket_in_new_window' );         $selected    = isset( $current_val ) && $current_val === 'yes' ? 'checked' : '';          $return .= "         <fieldset>         <legend>" . __( 'miscellaneous', 'awesome-support' ) . "</legend>         <div class='metabox-prefs'>         <div class='edit_ticket_in_new_window'>             <label for='edit_ticket_in_new_window'>             <input type='checkbox' value='yes' name='edit_ticket_in_new_window' id='edit_ticket_in_new_window' " . $selected . " /> "                    . __( 'edit tickets in new window/tab', 'awesome-support' ) . "</label><br />             <input type='hidden' name='edit_ticket_in_new_window' value='edit_ticket_in_new_window' />         </div>         </div>         </fieldset>         <br class='clear'>";     }      return $return; }  /**  * filter screen option values before setting.  *  * @param $status  * @param $option  * @param $value  *  * @return mixed  */ function set_screen_options( $status, $option, $value ) {      if ( 'edit_ticket_in_new_window' === $option ) {         $value = $_post[ 'edit_ticket_in_new_window' ];     }      return $value; }  /**  * screen options edit.php  */ public function load_edit_php() {      add_screen_option( 'edit_ticket_in_new_window',                        array(                            'label'   => 'open tickets/replies in new window',                            'default' => 'no',                            'option'  => 'edit_ticket_in_new_window',                        )     );  }  /**  * screen option current user else return default.  *  * @param $option  *  * @return mixed|string  */ public function get_user_meta_current_val( $option ) {      $user        = get_current_user_id();     $screen      = get_current_screen();     $option      = $screen->get_option( $option, 'option' );     $current_val = get_user_meta( $user, $option, true );      if ( empty( $current_val ) ) {         $current_val = $screen->get_option( $option, 'default' );     }      return $current_val; } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -