Controling Admin Access

New in version 4.0 is the ability for developers to control admin user access to the plugin’s admin menus via a WordPress Filter. The default capability is ‘edit_others_posts’, a capability of Editors, Admins, and Super Admins. Only those roles can access the plugin’s admin menus by default. To change that capability, in your functions.php file (or wherever) add a hook to the mstw_gs_user_capability filter as follows:

add_filter( ‘mstw_gs_user_capability’, ‘my_user_capability_callback’, 10, 2 );

where 10 is the priority of the filter call to my_user_capability_callback and 2 is the number of arguments the callback will receive (see below). PLEASE DO NOT SET THE PRIORITY HIGHER THAN 10, which is the default. That is, use 10 and above, 1-9 are reserved for the MSTW Framework and your code may produce unexpected results if you use them.

Your callback will look something like this:

	function my_user_capability_callback( $capability, $filter4 ) {
		// Only allow the admin role to access the display settings menu 
		if ( $filter4 == 'display_settings_menu_item' )
			return 'manage_options';
		// For everything else, just pass the $capability back unchanged
		else 	
			return $capability;  
	}

The ‘filter for’ values for the `mstw_gs_user_capability` hook (as of version 4.0 ) are:

  • scheduled_games_menu_item – called before registering the games, schedules, and teams custom post types
  • display_settings_menu_item – called before displaying the Display Settings submenu
  • csv_import_menu_item – called before displaying the CSV Import submenu

scheduled_games_menu_item controls the display of the entire MSTW Game Schedules menu and all submenus. display_settings_menu_item controls the display of the Display Settings submenu, and csv_import_menu_item controls the display of the CSV Import submenu.