From 7e6e0bfa9b1f9ca431d8d33133bb10b648281fe8 Mon Sep 17 00:00:00 2001 From: yeneastgate <104892108+yeneastgate@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:21:35 +0700 Subject: [PATCH] 45733 fix menu item disappears in the wp backend (#771) --- plugin.php | 148 ++++++++++++++++++++++++++++------------------------- 1 file changed, 77 insertions(+), 71 deletions(-) diff --git a/plugin.php b/plugin.php index 54f71e016..51226f5ac 100644 --- a/plugin.php +++ b/plugin.php @@ -80,8 +80,84 @@ add_action('save_post', [$pDetailViewPostSaveController, 'onSavePost']); add_action('wp_trash_post', [$pDetailViewPostSaveController, 'onMoveTrash']); + +add_action('admin_menu', [$pAdminViewController, 'register_menu']); +add_action('admin_enqueue_scripts', [$pAdminViewController, 'enqueue_css']); +add_action('init', [$pAdminViewController, 'onInit']); + +add_action('admin_bar_menu', function ( $wp_admin_bar ) { + if (is_network_admin()) { + return; + } + $user = wp_get_current_user(); + $allowed_roles = array('editor', 'administrator'); + if( array_intersect($allowed_roles, $user->roles ) ){ + $toolBarConfig = [ + [ + 'id' => 'onoffice', + 'title' => __('onOffice', 'onoffice-for-wp-websites'), + 'href' => admin_url('admin.php?page=onoffice'), + 'meta' => [ 'class' => 'onoffice' ] + ], + [ + 'id' => 'onoffice-clear-cache', + 'title' => __('Clear onOffice cache', 'onoffice-for-wp-websites'), + 'href' => admin_url('admin.php?action=onoffice-clear-cache'), + 'parent' => 'onoffice', + 'meta' => [ 'class' => 'onoffice-clear-cache' ] + ], + [ + 'id' => 'addresses', + 'title' => __('Addresses', 'onoffice-for-wp-websites'), + 'href' => admin_url('admin.php?page=onoffice-addresses'), + 'parent' => 'onoffice', + 'meta' => [ 'class' => 'addresses' ] + ], + [ + 'id' => 'estates', + 'title' => __('Estates', 'onoffice-for-wp-websites'), + 'href' => admin_url('admin.php?page=onoffice-estates'), + 'parent' => 'onoffice', + 'meta' => [ 'class' => 'estates' ] + ], + [ + 'id' => 'forms', + 'title' => __('Forms', 'onoffice-for-wp-websites'), + 'href' => admin_url('admin.php?page=onoffice-forms'), + 'parent' => 'onoffice', + 'meta' => [ 'class' => 'forms' ] + ], + [ + 'id' => 'settings', + 'title' => __('Settings', 'onoffice-for-wp-websites'), + 'href' => admin_url('admin.php?page=onoffice-settings'), + 'parent' => 'onoffice', + 'meta' => [ 'class' => 'settings' ] + ] + ]; + + foreach ( $toolBarConfig as $e ) { + $wp_admin_bar->add_node($e); + } + }; +}, 500); + +add_action('admin_init', function () use ( $pDI ) { + if ( strpos($_SERVER["REQUEST_URI"], "action=onoffice-clear-cache") !== false ) { + $pDI->get(CacheHandler::class)->clear(); + $location = ! empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('admin.php?page=onoffice-settings'); + update_option('onoffice-notice-cache-was-cleared', true); + wp_safe_redirect($location); + exit(); + } +}); + if (is_admin() && isset($_GET['post']) && isset($_GET['action']) && $_GET['action'] === 'edit') { - return $pDI; + $post_id = $_GET['post']; + $post_type = get_post_type($post_id); + if ($post_type === 'page') { + return $pDI; + } } $pDI->get(ScriptLoaderRegistrator::class)->generate(); @@ -102,15 +178,12 @@ // https://codex.wordpress.org/Plugin_API/Action_Reference/wp add_action('wp', [FormPostHandler::class, 'initialCheck']); -add_action('admin_menu', [$pAdminViewController, 'register_menu']); add_action('admin_enqueue_scripts', [$pAdminViewController, 'enqueue_ajax']); -add_action('admin_enqueue_scripts', [$pAdminViewController, 'enqueue_css']); add_action('admin_enqueue_scripts', [$pAdminViewController, 'enqueueExtraJs']); add_action('oo_cache_cleanup', function() use ($pDI) { $pDI->get(CacheHandler::class)->clean(); }); add_action('admin_notices', [$pAdminViewController, 'generalAdminNoticeSEO']); -add_action('init', [$pAdminViewController, 'onInit']); add_action('init', function() use ($pAdminViewController) { $pAdminViewController->disableHideMetaboxes(); }, 11); @@ -348,16 +421,6 @@ function update_status_close_action_button_option() } }); -add_action('admin_init', function () use ( $pDI ) { - if ( strpos($_SERVER["REQUEST_URI"], "action=onoffice-clear-cache") !== false ) { - $pDI->get(CacheHandler::class)->clear(); - $location = ! empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('admin.php?page=onoffice-settings'); - update_option('onoffice-notice-cache-was-cleared', true); - wp_safe_redirect($location); - exit(); - } -}); - add_action('admin_notices', function () { if (get_option('onoffice-notice-cache-was-cleared') == true) { $class = 'notice notice-success is-dismissible'; @@ -367,63 +430,6 @@ function update_status_close_action_button_option() } }); -add_action('admin_bar_menu', function ( $wp_admin_bar ) { - if (is_network_admin()) { - return; - } - $user = wp_get_current_user(); - $allowed_roles = array('editor', 'administrator'); - if( array_intersect($allowed_roles, $user->roles ) ){ - $toolBarConfig = [ - [ - 'id' => 'onoffice', - 'title' => __('onOffice', 'onoffice-for-wp-websites'), - 'href' => admin_url('admin.php?page=onoffice'), - 'meta' => [ 'class' => 'onoffice' ] - ], - [ - 'id' => 'onoffice-clear-cache', - 'title' => __('Clear onOffice cache', 'onoffice-for-wp-websites'), - 'href' => admin_url('admin.php?action=onoffice-clear-cache'), - 'parent' => 'onoffice', - 'meta' => [ 'class' => 'onoffice-clear-cache' ] - ], - [ - 'id' => 'addresses', - 'title' => __('Addresses', 'onoffice-for-wp-websites'), - 'href' => admin_url('admin.php?page=onoffice-addresses'), - 'parent' => 'onoffice', - 'meta' => [ 'class' => 'addresses' ] - ], - [ - 'id' => 'estates', - 'title' => __('Estates', 'onoffice-for-wp-websites'), - 'href' => admin_url('admin.php?page=onoffice-estates'), - 'parent' => 'onoffice', - 'meta' => [ 'class' => 'estates' ] - ], - [ - 'id' => 'forms', - 'title' => __('Forms', 'onoffice-for-wp-websites'), - 'href' => admin_url('admin.php?page=onoffice-forms'), - 'parent' => 'onoffice', - 'meta' => [ 'class' => 'forms' ] - ], - [ - 'id' => 'settings', - 'title' => __('Settings', 'onoffice-for-wp-websites'), - 'href' => admin_url('admin.php?page=onoffice-settings'), - 'parent' => 'onoffice', - 'meta' => [ 'class' => 'settings' ] - ] - ]; - - foreach ( $toolBarConfig as $e ) { - $wp_admin_bar->add_node($e); - } - }; -}, 500); - add_filter('script_loader_tag', 'filter_script_loader_tag', 10, 2); function filter_script_loader_tag($tag, $handle) { $attributes = [IncludeFileModel::LOAD_DEFER, IncludeFileModel::LOAD_ASYNC];