summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php')
-rw-r--r--plugins/jetpack/jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php b/plugins/jetpack/jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php
index 140b40f6..fd54f4ab 100644
--- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php
+++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php
@@ -13,7 +13,7 @@ namespace Automattic\Jetpack\Admin_UI;
*/
class Admin_Menu {
- const PACKAGE_VERSION = '0.2.1';
+ const PACKAGE_VERSION = '0.2.7';
/**
* Whether this class has been initialized
@@ -37,11 +37,35 @@ class Admin_Menu {
public static function init() {
if ( ! self::$initialized ) {
self::$initialized = true;
+ self::handle_akismet_menu();
add_action( 'admin_menu', array( __CLASS__, 'admin_menu_hook_callback' ), 1000 ); // Jetpack uses 998.
}
}
/**
+ * Handles the Akismet menu item when used alongside other stand-alone plugins
+ *
+ * When Jetpack plugin is present, Akismet menu item is moved under the Jetpack top level menu, but if Akismet is active alongside other stand-alone plugins,
+ * we use this method to move the menu item.
+ */
+ private static function handle_akismet_menu() {
+ if ( ! class_exists( 'Jetpack' ) && class_exists( 'Akismet_Admin' ) ) {
+ // Prevent Akismet from adding a menu item.
+ add_action(
+ 'admin_menu',
+ function () {
+ remove_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 );
+ },
+ 4
+ );
+
+ // Add an Anti-spam menu item for Jetpack.
+ self::add_menu( __( 'Anti-Spam', 'jetpack-admin-ui' ), __( 'Anti-Spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
+
+ }
+ }
+
+ /**
* Enqueue styles for the top level menu
*
* @return void
@@ -80,6 +104,22 @@ class Admin_Menu {
$can_see_toplevel_menu = false;
}
+ /**
+ * The add_sub_menu function has a bug and will not keep the right order of menu items.
+ *
+ * @see https://core.trac.wordpress.org/ticket/52035
+ * Let's order the items before registering them.
+ * Since this all happens after the Jetpack plugin menu items were added, all items will be added after Jetpack plugin items - unless position is very low number (smaller than the number of menu items present in Jetpack plugin).
+ */
+ usort(
+ self::$menu_items,
+ function ( $a, $b ) {
+ $position_a = empty( $a['position'] ) ? 0 : $a['position'];
+ $position_b = empty( $b['position'] ) ? 0 : $b['position'];
+ return $position_a - $position_b;
+ }
+ );
+
foreach ( self::$menu_items as $menu_item ) {
if ( ! current_user_can( $menu_item['capability'] ) ) {
continue;