Move SportsPress to top-level page
This commit is contained in:
@@ -21,16 +21,22 @@ class SP_Admin_Menus {
|
||||
* Hook in tabs.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'admin_menu', array( $this, 'menu_clean' ) );
|
||||
add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
|
||||
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
|
||||
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
|
||||
add_filter( 'menu_order', array( $this, 'menu_order' ) );
|
||||
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
*/
|
||||
public function settings_menu() {
|
||||
$settings_page = add_options_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_options', 'sportspress', array( $this, 'settings_page' ) );
|
||||
public function admin_menu() {
|
||||
global $menu;
|
||||
|
||||
if ( current_user_can( 'manage_sportspress' ) )
|
||||
$menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
|
||||
|
||||
$main_page = add_menu_page( __( 'SportsPress Settings', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), null, '51.5' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,17 +46,75 @@ class SP_Admin_Menus {
|
||||
* @return void
|
||||
*/
|
||||
public function menu_highlight() {
|
||||
global $typenow;
|
||||
global $typenow, $submenu;
|
||||
if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_performance', 'sp_metric' ) ) )
|
||||
sp_highlight_admin_menu();
|
||||
$this->highlight_admin_menu( 'sportspress', 'edit.php?post_type=' . $typenow );
|
||||
elseif ( $typenow == 'sp_calendar' )
|
||||
sp_highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
|
||||
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
|
||||
elseif ( $typenow == 'sp_table' )
|
||||
sp_highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
|
||||
$this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
|
||||
elseif ( $typenow == 'sp_list' )
|
||||
sp_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
|
||||
$this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
|
||||
elseif ( $typenow == 'sp_directory' )
|
||||
sp_highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit.php?post_type=sp_directory' );
|
||||
$this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit.php?post_type=sp_directory' );
|
||||
|
||||
if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) ) {
|
||||
$submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder the SP menu items in admin.
|
||||
*
|
||||
* @param mixed $menu_order
|
||||
* @return array
|
||||
*/
|
||||
public function menu_order( $menu_order ) {
|
||||
// Initialize our custom order array
|
||||
$sportspress_menu_order = array();
|
||||
|
||||
// Get the index of our custom separator
|
||||
$sportspress_separator = array_search( 'separator-sportspress', $menu_order );
|
||||
|
||||
// Get index of menu items
|
||||
$sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order );
|
||||
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
|
||||
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
|
||||
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
|
||||
|
||||
// Loop through menu order and do some rearranging
|
||||
foreach ( $menu_order as $index => $item ) :
|
||||
|
||||
if ( ( ( 'sportspress' ) == $item ) ) :
|
||||
$sportspress_menu_order[] = 'separator-sportspress';
|
||||
$sportspress_menu_order[] = $item;
|
||||
$sportspress_menu_order[] = 'edit.php?post_type=sp_event';
|
||||
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
|
||||
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
|
||||
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
|
||||
unset( $menu_order[$sportspress_separator] );
|
||||
unset( $menu_order[$sportspress_event] );
|
||||
unset( $menu_order[$sportspress_team] );
|
||||
unset( $menu_order[$sportspress_player] );
|
||||
unset( $menu_order[$sportspress_staff] );
|
||||
elseif ( !in_array( $item, array( 'separator-sportspress' ) ) ) :
|
||||
$sportspress_menu_order[] = $item;
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
|
||||
// Return order
|
||||
return $sportspress_menu_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* custom_menu_order
|
||||
* @return bool
|
||||
*/
|
||||
public function custom_menu_order() {
|
||||
if ( ! current_user_can( 'manage_sportspress' ) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,6 +186,12 @@ class SP_Admin_Menus {
|
||||
public function remove_venues( $arr = array() ) {
|
||||
return $arr[0] != __( 'Venues', 'sportspress' );
|
||||
}
|
||||
|
||||
public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) {
|
||||
global $parent_file, $submenu_file;
|
||||
$parent_file = $p;
|
||||
$submenu_file = $s;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -76,7 +76,7 @@ class SP_Admin_Notices {
|
||||
$screen = get_current_screen();
|
||||
|
||||
// If we have just installed, show a message with the install pages button
|
||||
if ( get_option( '_sp_needs_welcome' ) == 1 && $screen->id != 'settings_page_sportspress' ) {
|
||||
if ( get_option( '_sp_needs_welcome' ) == 1 && $screen->id != 'toplevel_page_sportspress' ) {
|
||||
include( 'views/html-notice-install.php' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class SP_Admin_Welcome {
|
||||
<div class="sp-badge"><?php printf( __( 'Version %s', 'sportspress' ), SP()->version ); ?></div>
|
||||
|
||||
<p class="sportspress-actions">
|
||||
<?php if ( false ): ?><a href="<?php echo admin_url( add_query_arg( array( 'page' => 'sportspress' ), 'options-general.php' ) ); ?>" class="button button-primary"><?php _e( 'Settings', 'sportspress' ); ?></a><?php endif; ?>
|
||||
<?php if ( false ): ?><a href="<?php echo admin_url( add_query_arg( array( 'page' => 'sportspress' ), 'admin.php' ) ); ?>" class="button button-primary"><?php _e( 'Settings', 'sportspress' ); ?></a><?php endif; ?>
|
||||
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://ow.ly/vaGUv" data-text="An open-source (free) #WordPress plugin that helps you build professional league websites." data-via="ThemeBoy" data-size="large" data-hashtags="SportsPress">Tweet</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
||||
</p>
|
||||
@@ -266,7 +266,7 @@ class SP_Admin_Welcome {
|
||||
</div>
|
||||
|
||||
<div class="return-to-dashboard">
|
||||
<a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress' ), 'options-general.php' ) ) ); ?>"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress' ), 'admin.php' ) ) ); ?>"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
@@ -125,8 +125,6 @@ class SP_Admin_CPT_Calendar extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_calendar' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
|
||||
|
||||
@@ -180,8 +180,6 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_event' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
|
||||
@@ -114,8 +114,6 @@ class SP_Admin_CPT_List extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_list' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
|
||||
|
||||
@@ -163,8 +163,6 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_player' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
|
||||
@@ -138,8 +138,6 @@ class SP_Admin_CPT_Staff extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_staff' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
|
||||
@@ -100,8 +100,6 @@ class SP_Admin_CPT_Table extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_table' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
|
||||
|
||||
@@ -112,8 +112,6 @@ class SP_Admin_CPT_Team extends SP_Admin_CPT {
|
||||
if ( $typenow != 'sp_team' )
|
||||
return;
|
||||
|
||||
sp_highlight_admin_menu();
|
||||
|
||||
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
|
||||
|
||||
@@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
function sp_get_screen_ids() {
|
||||
return apply_filters( 'sportspress_screen_ids', array(
|
||||
'dashboard_page_sp-about',
|
||||
'settings_page_sportspress',
|
||||
'toplevel_page_sportspress',
|
||||
'edit-sp_result',
|
||||
'sp_result',
|
||||
'edit-sp_outcome',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="icon32 icon32-sportspress-settings" id="icon-sportspress"><br /></div><h2 class="nav-tab-wrapper sp-nav-tab-wrapper">
|
||||
<?php
|
||||
foreach ( $tabs as $name => $label )
|
||||
echo '<a href="' . admin_url( 'options-general.php?page=sportspress&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>';
|
||||
echo '<a href="' . admin_url( 'admin.php?page=sportspress&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>';
|
||||
|
||||
do_action( 'sportspress_settings_tabs' );
|
||||
?>
|
||||
|
||||
@@ -152,18 +152,6 @@ class SP_Post_types {
|
||||
* Register core post types
|
||||
*/
|
||||
public static function register_post_types() {
|
||||
|
||||
register_post_type( 'sp_separator',
|
||||
array(
|
||||
'label' => '',
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
'show_in_admin_bar' => false,
|
||||
'can_export' => false,
|
||||
)
|
||||
);
|
||||
|
||||
do_action( 'sportspress_register_post_type' );
|
||||
|
||||
register_post_type( 'sp_result',
|
||||
@@ -189,9 +177,9 @@ class SP_Post_types {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => 'sportspress',
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -219,39 +207,9 @@ class SP_Post_types {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
register_post_type( 'sp_performance',
|
||||
apply_filters( 'sportspress_register_post_type_performance',
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Performance', 'sportspress' ),
|
||||
'singular_name' => __( 'Performance', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New Performance', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Performance', 'sportspress' ),
|
||||
'new_item' => __( 'New', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'search_items' => __( 'Search', 'sportspress' ),
|
||||
'not_found' => __( 'No results found.', 'sportspress' ),
|
||||
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
|
||||
),
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'capability_type' => 'sp_config',
|
||||
'map_meta_cap' => true,
|
||||
'publicly_queryable' => false,
|
||||
'exclude_from_search' => true,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => 'sportspress',
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -279,9 +237,39 @@ class SP_Post_types {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => 'sportspress',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
register_post_type( 'sp_performance',
|
||||
apply_filters( 'sportspress_register_post_type_performance',
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Performance', 'sportspress' ),
|
||||
'singular_name' => __( 'Performance', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New Performance', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Performance', 'sportspress' ),
|
||||
'new_item' => __( 'New', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'search_items' => __( 'Search', 'sportspress' ),
|
||||
'not_found' => __( 'No results found.', 'sportspress' ),
|
||||
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
|
||||
),
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'capability_type' => 'sp_config',
|
||||
'map_meta_cap' => true,
|
||||
'publicly_queryable' => false,
|
||||
'exclude_from_search' => true,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => 'sportspress',
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -309,9 +297,9 @@ class SP_Post_types {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => 'sportspress',
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -339,9 +327,9 @@ class SP_Post_types {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'has_archive' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => 'sportspress',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -2986,14 +2986,6 @@ if ( !function_exists( 'sp_delete_duplicate_post' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_highlight_admin_menu' ) ) {
|
||||
function sp_highlight_admin_menu( $p = 'options-general.php', $s = 'sportspress' ) {
|
||||
global $parent_file, $submenu_file;
|
||||
$parent_file = $p;
|
||||
$submenu_file = $s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of sport options and settings.
|
||||
* @return array
|
||||
|
||||
Reference in New Issue
Block a user