PluginProbe
Faust.js / 1.0.2
Faust.js v1.0.2
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / admin-menus / callbacks.php

callbacks.php in Faust.js 1.0.2, at includes/admin-menus/callbacks.php

112 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Disables wp-admin menu items that aren't supported in a headless environment.
4 *
5 * @package FaustWP
6 */
7
8 namespace WPE\FaustWP\Admin_Menus;
9
10 use function WPE\FaustWP\Settings\is_themes_disabled;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 add_action( 'admin_menu', __NAMESPACE__ . '\\remove_admin_menu_pages', 1000 );
17 /**
18 * Remove wp-admin menu items not needed in a headless environment.
19 *
20 * @global $submenu
21 *
22 * @return void
23 */
24 function remove_admin_menu_pages() {
25 /**
26 * Global submenu data
27 *
28 * @var array
29 */
30 global $submenu;
31
32 if ( ! is_themes_disabled() ) {
33 return;
34 }
35
36 // Remove Appearance > Themes.
37 remove_submenu_page( 'themes.php', 'themes.php' );
38
39 // Remove Appearance > Theme Editor.
40 remove_submenu_page( 'themes.php', 'theme-editor.php' );
41
42 // Remove Appearance > Editor.
43 remove_submenu_page( 'themes.php', 'site-editor.php' );
44
45 // Remove Appearance > Widgets.
46 remove_submenu_page( 'themes.php', 'widgets.php' );
47
48 /**
49 * Remove features that require the Customizer.
50 * Loop through the themes.php submenu to remove features in Customizer
51 * since there's no direct way to remove them via the submenu_slug.
52 * Targeting 'hide-if-no-customize' removes all the features that
53 * rely on the Customizer. Otherwise you must target each one
54 * specifically by name (which might be a good idea?).
55 */
56 if ( isset( $submenu['themes.php'] ) ) {
57 foreach ( $submenu['themes.php'] as $key => $item ) {
58 if ( in_array( 'hide-if-no-customize', $item, true ) ) {
59 unset( $submenu['themes.php'][ $key ] );
60 }
61 }
62 }
63 }
64
65 add_action( 'wp_before_admin_bar_render', __NAMESPACE__ . '\\remove_admin_bar_items' );
66 /**
67 * Removes admin bar items not needed in a headless environment.
68 *
69 * @return void
70 */
71 function remove_admin_bar_items() {
72 /**
73 * WP Admin Bar global
74 *
75 * @var WP_Admin_Bar $wp_admin_bar
76 */
77 global $wp_admin_bar;
78
79 if ( ! is_themes_disabled() ) {
80 return;
81 }
82
83 $wp_admin_bar->remove_menu( 'customize' );
84 $wp_admin_bar->remove_node( 'themes' );
85 $wp_admin_bar->remove_node( 'site-editor' );
86 $wp_admin_bar->remove_node( 'widgets' );
87 }
88
89 add_action( 'current_screen', __NAMESPACE__ . '\\prevent_admin_page_access' );
90 /**
91 * Prevents access to named pages by redirecting to the admin root.
92 *
93 * @return void
94 */
95 function prevent_admin_page_access() {
96 if ( ! is_themes_disabled() ) {
97 return;
98 }
99
100 $disabled_screens = array(
101 'site-editor',
102 'themes',
103 );
104
105 $screen = get_current_screen();
106
107 if ( is_object( $screen ) && in_array( $screen->id, $disabled_screens, true ) ) {
108 wp_safe_redirect( admin_url() );
109 exit;
110 }
111 }
112