Advertisements

set_screen_options

Definition:
function set_screen_options() {}

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

Defined filters

  • set-screen-option
    apply_filters('set-screen-option', false, $option, $value)

Source code

function set_screen_options() {



	if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {

		check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );



		if ( !$user = wp_get_current_user() )

			return;

		$option = $_POST['wp_screen_options']['option'];

		$value = $_POST['wp_screen_options']['value'];



		if ( !preg_match( '/^[a-z_-]+$/', $option ) )

			return;



		$option = str_replace('-', '_', $option);



		$map_option = $option;

		$type = str_replace('edit_', '', $map_option);

		$type = str_replace('_per_page', '', $type);

		if ( in_array($type, get_post_types()) )

			$map_option = 'edit_per_page';

		if ( in_array( $type, get_taxonomies()) )

			$map_option = 'edit_tags_per_page';





		switch ( $map_option ) {

			case 'edit_per_page':

			case 'users_per_page':

			case 'edit_comments_per_page':

			case 'upload_per_page':

			case 'edit_tags_per_page':

			case 'plugins_per_page':

			// Network admin

			case 'sites_network_per_page':

			case 'users_network_per_page':

			case 'site_users_network_per_page':

			case 'plugins_network_per_page':

			case 'themes_network_per_page':

			case 'site_themes_network_per_page':

				$value = (int) $value;

				if ( $value < 1 || $value > 999 )

					return;

				break;

			default:

				$value = apply_filters('set-screen-option', false, $option, $value);

				if ( false === $value )

					return;

				break;

		}



		update_user_meta($user->ID, $option, $value);

		wp_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );

		exit;

	}

}

2851

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: