Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Custom admin menus #5757

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sync/class.jetpack-sync-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Jetpack_Sync_Defaults {
'hosting_provider' => array( 'Jetpack_Sync_Functions', 'get_hosting_provider' ),
'locale' => 'get_locale',
'site_icon_url' => array( 'Jetpack_Sync_Functions', 'site_icon_url' ),
'admin_menu_items' => array( 'Jetpack_Sync_Functions', 'get_custom_admin_menu_items' ),
);

static $blacklisted_post_types = array(
Expand Down
24 changes: 22 additions & 2 deletions sync/class.jetpack-sync-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public static function get_hosting_provider() {
}
if ( defined( 'MM_BASE_DIR' ) ) {
return 'bh';
}
}
if ( defined( 'IS_PRESSABLE' ) ) {
return 'pressable';
}
}
if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) {
return 'wpe';
}
Expand Down Expand Up @@ -176,6 +176,26 @@ public static function get_plugins() {
return apply_filters( 'all_plugins', get_plugins() );
}

/**
* Returns items inserted to wp-admin admin page menu by custom plugins and themes.
* They usually do that bu hooking in admin_menu and calling add_menu_page and add_submenu_page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bu -> by

* @return array
**/
public static function get_custom_admin_menu_items() {
global $menu, $submenu;

// Since some of the menu items are displayed only for certain capability, we need user switcharoo
$current_user_id = get_current_user_id();
wp_set_current_user( Jetpack_Options::get_option( 'master_user' ) );

// add_menu_page and add_submenu_page hook into admin_menu. Documented in wp-admin/includes/menu.php
do_action( 'admin_menu', '' );

// Lets clean up user switch
wp_set_current_user( $current_user_id );
return array( 'menu' => $menu, 'submenu' => $submenu );
}

public static function wp_version() {
global $wp_version;

Expand Down