set_screen_options

Saves option for number of rows when listing posts, pages, comments, etc.

Description

set_screen_options(); 

Usage

  1. if ( !function_exists( 'set_screen_options' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = set_screen_options(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/misc.php  
  1. function set_screen_options() { 
  2.  
  3. if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) { 
  4. check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); 
  5.  
  6. if ( !$user = wp_get_current_user() ) 
  7. return; 
  8. $option = $_POST['wp_screen_options']['option']; 
  9. $value = $_POST['wp_screen_options']['value']; 
  10.  
  11. if ( $option != sanitize_key( $option ) ) 
  12. return; 
  13.  
  14. $map_option = $option; 
  15. $type = str_replace('edit_', '', $map_option); 
  16. $type = str_replace('_per_page', '', $type); 
  17. if ( in_array( $type, get_taxonomies() ) ) 
  18. $map_option = 'edit_tags_per_page'; 
  19. elseif ( in_array( $type, get_post_types() ) ) 
  20. $map_option = 'edit_per_page'; 
  21. else 
  22. $option = str_replace('-', '_', $option); 
  23.  
  24. switch ( $map_option ) { 
  25. case 'edit_per_page': 
  26. case 'users_per_page': 
  27. case 'edit_comments_per_page': 
  28. case 'upload_per_page': 
  29. case 'edit_tags_per_page': 
  30. case 'plugins_per_page': 
  31. // Network admin 
  32. case 'sites_network_per_page': 
  33. case 'users_network_per_page': 
  34. case 'site_users_network_per_page': 
  35. case 'plugins_network_per_page': 
  36. case 'themes_network_per_page': 
  37. case 'site_themes_network_per_page': 
  38. $value = (int) $value; 
  39. if ( $value < 1 || $value > 999 ) 
  40. return; 
  41. break; 
  42. default: 
  43.  
  44. /** 
  45. * Filters a screen option value before it is set. 
  46. * The filter can also be used to modify non-standard [items]_per_page 
  47. * settings. See the parent function for a full list of standard options. 
  48. * Returning false to the filter will skip saving the current option. 
  49. * @since 2.8.0 
  50. * @see set_screen_options() 
  51. * @param bool|int $value Screen option value. Default false to skip. 
  52. * @param string $option The option name. 
  53. * @param int $value The number of rows to use. 
  54. */ 
  55. $value = apply_filters( 'set-screen-option', false, $option, $value ); 
  56.  
  57. if ( false === $value ) 
  58. return; 
  59. break; 
  60.  
  61. update_user_meta($user->ID, $option, $value); 
  62.  
  63. $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); 
  64. if ( isset( $_POST['mode'] ) ) { 
  65. $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); 
  66.  
  67. wp_safe_redirect( $url ); 
  68. exit;