-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin-submenu-mover.php
382 lines (323 loc) · 12.9 KB
/
plugin-submenu-mover.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php # -*- coding: utf-8 -*-
/*
Plugin Name: Plugin Submenu Mover
Plugin URI: https://github.com/deckerweb/plugin-submenu-mover
Description: Move some plugin's single settings pages from top-level position to submenu under Tools, Settings or were appropriate. Result: cleaner admin screen, less confusing.
Project: Code Snippet: DDW Plugin Submenu Mover
Version: 1.4.0
Author: David Decker - DECKERWEB
Author URI: https://deckerweb.de/
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: plugin-submenu-mover
Domain Path: /languages/
Requires WP: 6.7
Requires PHP: 7.4
GitHub Plugin URI: https://github.com/deckerweb/plugin-submenu-mover
Primary Branch: main
Copyright: © 2022-2025, David Decker - DECKERWEB
TESTED WITH:
Product Versions
--------------------------------------------------------------------------------------------------------------
PHP 8.0, 8.3
WordPress 6.7.2 ... 6.8 Beta (used in production since 2022!)
--------------------------------------------------------------------------------------------------------------
VERSION HISTORY:
Date Version Description
--------------------------------------------------------------------------------------------------------------
2025-04-?? 1.5.0 New: Installable and updateable via Git Updater plugin
2025-03-28 1.4.0 Initial public release
- Now with class-based approach
- Battle tested for 3 years already
. . .
2022-07 1.0.0 Initial private release
2022-06 0.5.0 Private test version
2022-06 0.0.0 Development start
--------------------------------------------------------------------------------------------------------------
*/
/** Prevent direct access */
if ( ! defined( 'ABSPATH' ) ) exit( 'Sorry, you are not allowed to access this file directly.' );
if ( ! class_exists( 'DDW_Plugin_Submenu_Mover' ) ) :
class DDW_Plugin_Submenu_Mover {
/** Class constants & variables */
private const VERSION = '1.4.0';
/**
* Constructor
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'move_toplevel_to_submenu' ), 999 );
}
private function get_plugins() {
/** Slugs for admin pages */
$tools = 'tools.php';
$settings = 'options-general.php';
$plugins = 'plugins.php';
$themes = 'themes.php';
/** Builder checks */
$is_builder = 'none_yet';
$builder_menu = 'none_yet';
$oxyprops_label = 'OxyProps';
if ( defined( 'CT_VERSION' ) ) {
$is_builder = 'Oxygen';
$builder_menu = 'ct_dashboard_page';
} elseif ( defined( 'BRICKS_VERSION' ) ) {
$is_builder = 'Bricks';
$builder_menu = 'bricks';
$oxyprops_label = 'BricksProps';
}
/** DevKit Plugin check for Admin slug */
$devkit_admin = defined( 'DPDEV_ADMIN_SLUG' ) ? DPDEV_ADMIN_SLUG : 'devkit';
/** Collecting the plugin data */
$do_plugins = [
/** Plugin: The SEO Framework (free - wordpress.org) */
'the-seo-framework' => [
'is-active' => defined( 'THE_SEO_FRAMEWORK_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'theseoframework-settings',
'move-to-menu' => $settings,
'label' => 'The SEO Framework',
],
/** Plugin: Limit Login Attempts Reloaded (free - wordpress.org) */
'limit-login-attempts-reloaded' => [
'is-active' => defined( 'LLA_PLUGIN_URL' ),
'capability' => 'manage_options',
'admin-slug' => 'limit-login-attempts',
'move-to-menu' => $settings,
'label' => 'Limit Login Attempts',
],
/** Plugin: PublishPress Future (free - wordpress.org) (formerly: Post Expirator) */
'publishpress-future' => [
'is-active' => defined( 'POSTEXPIRATOR_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'publishpress-future',
'move-to-menu' => $settings,
'label' => 'PublishPress Future',
],
/** Plugin: Labinator Minimal Maintenance Mode (free - wordpress.org) */
'labinator-minimal-maintenance-mode' => [
'is-active' => defined( 'LMM_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'lmm-maintenance',
'move-to-menu' => $tools,
'label' => 'Labinator Minimal Maintenance Mode',
],
/** Plugin: WP Toolbelt (free - wordpress.org) */
'wp-toolbelt' => [
'is-active' => defined( 'TOOLBELT_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'toolbelt-modules',
'move-to-menu' => $tools,
'label' => 'Toolbelt Modules',
],
/** Plugin: DevKit Pro/free (by DPlugins.com) */
'devkit-pro' => [
'is-active' => defined( 'DPDEVKIT_URL' ),
'capability' => 'activate_plugins',
'admin-slug' => $devkit_admin,
'move-to-menu' => $tools,
'label' => 'DevKit',
],
/** Plugin: WPCodeBox (Premium) */
'wpcodebox' => [
'is-active' => defined( 'WPCODEBOX_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'wpcb_menu_page_php',
'move-to-menu' => $tools,
'label' => 'WPCodeBox',
],
/** Plugin: FluentSnippets (free - wordpress.org) */
'fluentsnippets' => [
'is-active' => defined( 'FLUENT_SNIPPETS_PLUGIN_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'fluent-snippets',
'move-to-menu' => $tools,
'label' => 'FluentSnippets',
],
/** Plugin: OxyProps / BricksProps (Premium) */
'obprops-plugin' => [
'is-active' => defined( 'OXYPROPS_AUTOLOAD_VERSION' ),
'capability' => 'manage_options',
'admin-slug' => 'oxyprops',
'move-to-menu' => $tools,
'label' => $oxyprops_label,
],
/** Plugin: Real Cookie Banner (free - wordpress.org) */
'real-cookie-banner' => [
'is-active' => class_exists( '\DevOwl\RealCookieBanner\lite\FomoCoupon' ),
'capability' => 'manage_options',
'admin-slug' => 'real-cookie-banner-component',
'move-to-menu' => $settings,
'label' => 'Cookies (RCB free)',
],
/** Plugin: Real Cookie Banner Pro (Premium) */
'real-cookie-banner-pro' => [
'is-active' => class_exists( '\DevOwl\RealCookieBanner\Vendor\DevOwl\Freemium\CorePro' ),
'capability' => 'manage_options',
'admin-slug' => 'real-cookie-banner-pro-component',
'move-to-menu' => $settings,
'label' => 'Cookies (RCB Pro)',
],
/** Plugin: Cookie Notice (free - wordpress.org) */
'cookie-notice' => [
'is-active' => class_exists( 'Cookie_Notice' ),
'capability' => 'manage_options',
'admin-slug' => 'cookie-notice',
'move-to-menu' => $settings,
'label' => 'Cookies',
],
/** Plugin: Maintenance (free - wordpress.org) */
'maintenance' => [
'is-active' => class_exists( 'MTNC' ),
'capability' => 'manage_options',
'admin-slug' => 'maintenance',
'move-to-menu' => $tools,
'label' => 'Maintenance',
],
/** Plugin: Envato Market (API Plugin Envato Marketplaces like themeforest and codecanyon) */
'envato-market' => [
'is-active' => defined( 'ENVATO_MARKET_VERSION' ),
'capability' => 'activate_plugins',
'admin-slug' => 'envato-market',
'move-to-menu' => $tools,
'label' => 'Envato Market',
],
/** Plugin: Related Posts Thumbnails (free - wordpress.org) */
'related-posts-thumbnails' => [
'is-active' => class_exists( 'RelatedPostsThumbnails' ),
'capability' => 'edit_theme_options',
'admin-slug' => 'related-posts-thumbnails',
'move-to-menu' => $themes,
'label' => 'Related Posts',
],
/** Plugin: Revolution Slider (Premium) */
'revolution-slider' => [
'is-active' => defined( 'RS_REVISION' ),
'capability' => 'edit_theme_options',
'admin-slug' => 'revslider',
'move-to-menu' => $themes,
'label' => 'Slider Revolution',
],
/** Plugin: Instant IDE (Premium) */
'instant-ide-manager' => [
'is-active' => defined( 'IIDEM_VERSION' ),
'capability' => 'activate_plugins',
'admin-slug' => 'instant-ide-manager-dashboard',
'move-to-menu' => $tools,
'label' => 'Instant IDE',
],
/** Plugin: Schema Pro (Premium) */
'instant-ide-manager' => [
'is-active' => defined( 'BSF_AIOSRS_PRO_VER' ),
'capability' => 'manage_options',
'admin-slug' => 'aiosrs_pro_admin_menu_page',
'move-to-menu' => $settings,
'label' => 'Schema Pro',
],
/** Plugin: SearchWP Live Search (free - wordpress.org) */
'searchwp-live-search' => [
'is-active' => defined( 'SEARCHWP_LIVE_SEARCH_VERSION' ),
'capability' => 'edit_theme_options',
'admin-slug' => 'searchwp-live-search',
'move-to-menu' => $settings,
'label' => 'SearchWP Live Search',
],
/** Plugin: Elements Hive Pro (Premium) */
'elements-hive-pro' => [
'is-active' => class_exists( 'ElementsHivePro' ),
'capability' => 'manage_options',
'admin-slug' => 'elements-hive-pro',
'move-to-menu' => 'breakdance',
'label' => 'Elements Hive Pro',
],
/** Plugin: Breakdance Reading Time Calculator (free - wordpress.org) */
'bd-reading-time-calculator' => [
'is-active' => function_exists( 'bd_reading_time_menu' ),
'capability' => 'manage_options',
'admin-slug' => 'bd-reading-time',
'move-to-menu' => 'breakdance',
'label' => 'Reading Time Calculator',
],
]; // end array
/** Return the array, filterable */
return apply_filters( 'ddw-psm/plugins', $do_plugins );
}
/**
* Move Admin Menu item from top-level menu to a defined submenu page under
* any top-level page, for example "Tools".
*
* @link https://njengah.com/remove-wordpress-admin-menu-items/
* @link https://developer.wordpress.org/reference/functions/add_submenu_page/
*/
public function move_toplevel_to_submenu() {
/** Get the plugin's array with those that should be moved */
$plugins = $this->get_plugins();
/**
* Necessary in-between-step for "Limit Login Attempts"
* plugin to avoid double submenu items
*/
if ( array_key_exists( 'limit-login-attempts-reloaded', $plugins ) && defined( 'LLA_PLUGIN_URL' ) ) {
remove_submenu_page( 'options-general.php', 'limit-login-attempts' );
}
/**
* Necessary in-between-step for "SearchWP Live Search"
* plugin to avoid double submenu items
*/
if ( array_key_exists( 'searchwp-live-search', $plugins ) && defined( 'SEARCHWP_LIVE_SEARCH_VERSION' ) ) {
remove_submenu_page( 'searchwp-live-search', esc_url( 'https://searchwp.com/?utm_source=WordPress&utm_medium=Admin+Menu+Upgrade+Link&utm_campaign=Live+Ajax+Search&utm_content=Upgrade+to+Pro' ) );
}
/** Iterating through all the plugins moving the menu item */
foreach ( $plugins as $plugin ) {
if ( $plugin[ 'is-active' ] ) {
/** Remove Top-Level */
remove_menu_page( $plugin[ 'admin-slug' ] );
/** Add the newly "generated" submenu under the preferred top-level item */
add_submenu_page(
esc_attr( $plugin[ 'move-to-menu' ] ),
esc_attr( $plugin[ 'label' ] ),
esc_attr( $plugin[ 'label' ] ),
sanitize_key( $plugin[ 'capability' ] ),
esc_attr( $plugin[ 'admin-slug' ] )
);
} // end if
} // end foreach
}
} // end of class
/** Start instance of Class */
new DDW_Plugin_Submenu_Mover();
endif;
if ( ! function_exists( 'ddw_psm_pluginrow_meta' ) ) :
add_filter( 'plugin_row_meta', 'ddw_psm_pluginrow_meta', 10, 2 );
/**
* Add plugin related links to plugin page.
*
* @since 1.3.0
*
* @param array $ddwp_meta (Default) Array of plugin meta links.
* @param string $ddwp_file File location of plugin.
* @return array $ddwp_meta (Modified) Array of plugin links/ meta.
*/
function ddw_psm_pluginrow_meta( $ddwp_meta, $ddwp_file ) {
if ( ! current_user_can( 'install_plugins' ) ) return $ddwp_meta;
/** Get current user */
$user = wp_get_current_user();
/** Build Newsletter URL */
$url_nl = sprintf(
'https://deckerweb.us2.list-manage.com/subscribe?u=e09bef034abf80704e5ff9809&id=380976af88&MERGE0=%1$s&MERGE1=%2$s',
esc_attr( $user->user_email ),
esc_attr( $user->user_firstname )
);
/** List additional links only for this plugin */
if ( $ddwp_file === trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) . basename( __FILE__ ) ) {
$ddwp_meta[] = sprintf(
'<a class="button button-inline" href="https://ko-fi.com/deckerweb" target="_blank" rel="nofollow noopener noreferrer" title="%1$s">❤ <b>%1$s</b></a>',
esc_html_x( 'Donate', 'Plugins page listing', 'plugin-submenu-mover' )
);
$ddwp_meta[] = sprintf(
'<a class="button-primary" href="%1$s" target="_blank" rel="nofollow noopener noreferrer" title="%2$s">⚡ <b>%2$s</b></a>',
$url_nl,
esc_html_x( 'Join our Newsletter', 'Plugins page listing', 'plugin-submenu-mover' )
);
} // end if
return apply_filters( 'ddw/admin_extras/pluginrow_meta', $ddwp_meta );
} // end function
endif;