Skip to content

Commit

Permalink
45733 fix menu item disappears in the wp backend (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeneastgate authored Apr 9, 2024
1 parent 2722254 commit 7e6e0bf
Showing 1 changed file with 77 additions and 71 deletions.
148 changes: 77 additions & 71 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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';
Expand All @@ -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];
Expand Down

0 comments on commit 7e6e0bf

Please sign in to comment.