Last active
April 19, 2023 02:46
-
-
Save brasofilo/4a8c1910a51bf4a06f7cd3e6087abe12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Move Accessibility plugins into a single menu | |
* Plugin URI: https://gist.github.com/brasofilo/4a8c1910a51bf4a06f7cd3e6087abe12 | |
* Gist Plugin URI: brasofilo/4a8c1910a51bf4a06f7cd3e6087abe12 | |
* Gist Plugin URI: https://gist.github.com/brasofilo/4a8c1910a51bf4a06f7cd3e6087abe12 | |
* Description: Moves these 3 plugins: Accessibility Checker, One Click Accessibility, WP Accessibility | |
* Version: 2023-04-15 | |
* Author: brasofilo | |
* Author URI: http://wordpress.stackexchange.com/users/12615 | |
*/ | |
# v 2023-04-13 | |
B5F_MoveAccessibility::init(); | |
/** | |
* https://wordpress.stackexchange.com/questions/55724/plugin-menu-addition-in-multisite | |
*/ | |
class B5F_MoveAccessibility | |
{ | |
private static $ins = null; | |
private $_plugin_check; | |
private $_plugin_wpacc; | |
private $_plugin_setts; | |
private $_look = [ 'accessibility_checker', 'wp-accessibility', 'accessibility-settings' ]; | |
private $_allpages = [ | |
'toplevel_page_accessibility_checker', | |
'accessibility-checker_page_accessibility_checker_settings', | |
'toplevel_page_wp-accessibility', | |
'accessibility_page_accessibility-toolbar', | |
'toplevel_page_accessibility-settings', | |
'wp-accessibility_page_wp-accessibility-help' | |
]; | |
public static function instance() | |
{ | |
is_null( self::$ins ) && self::$ins = new self; | |
return self::$ins; | |
} | |
public static function init() | |
{ | |
if (is_network_admin()) return; | |
add_action( 'plugins_loaded', [self::instance(), 'setup'] ); | |
} | |
public function setup() | |
{ | |
$this->_plugin_check = is_plugin_active('accessibility-checker/accessibility-checker.php'); | |
if ( $this->_plugin_check ) $this->_plugin_first = 'accessibility_checker'; | |
$this->_plugin_wpacc = is_plugin_active('wp-accessibility/wp-accessibility.php'); | |
if ( $this->_plugin_wpacc && !$this->_plugin_first ) $this->_plugin_first = 'wp-accessibility'; | |
$this->_plugin_setts = is_plugin_active('pojo-accessibility/pojo-accessibility.php'); | |
if ( $this->_plugin_setts && !$this->_plugin_first ) $this->_plugin_first = 'accessibility-settings'; | |
if ( !$this->_plugin_check && !$this->_plugin_setts && !$this->_plugin_wpacc ) | |
return; | |
add_action('admin_init', [$this, 'adminit']); | |
add_action('admin_menu', [$this, 'menu']); | |
add_action('admin_head', [$this, 'enqueue']); | |
} | |
public function adminit() | |
{ | |
global $menu; | |
foreach ( $this->_look as $name ) | |
{ | |
$check = $this->_recursiveSearch($name, $menu); | |
if ( $check ) unset( $menu[$check] ); | |
} | |
remove_submenu_page('all-accessibility', 'all-accessibility'); | |
} | |
private function _submenuArrow() | |
{ | |
return '<span style="display:inline-block;transform:scaleX(-1);margin-right:5px;">↵</span>'; | |
} | |
public function menu() | |
{ | |
$first = 'all-accessibility'; | |
add_menu_page( | |
'Accessibility', | |
'<span style="color:#e57300;">Accessibility</span>', | |
'edit_pages', | |
$first, | |
'__return_true', | |
'dashicons-universal-access', // icon default for empty | |
999 // priority | |
); | |
if ( $this->_plugin_check ) | |
{ | |
add_submenu_page( | |
$first, | |
'Accessibility Checker', | |
'Accessibility Checker', | |
'manage_options', | |
$this->_look[0], | |
'__return_true' | |
); | |
add_submenu_page( | |
$first, | |
'Settings', | |
$this->_submenuArrow() . ' Settings', | |
'manage_options', | |
'accessibility_checker_settings', | |
'__return_true' | |
); | |
} | |
if ( $this->_plugin_setts ) | |
{ | |
add_submenu_page( | |
$first, | |
'Accessibility Settings', | |
'Accessibility Settings', | |
'manage_options', | |
$this->_look[1], | |
'__return_true' | |
); | |
add_submenu_page( | |
$first, | |
'Toolbar', | |
$this->_submenuArrow() . ' Toolbar', | |
'manage_options', | |
'accessibility-toolbar', | |
'__return_true' | |
); | |
add_submenu_page( | |
$first, | |
'Customize', | |
$this->_submenuArrow() . ' Customize', | |
'manage_options', | |
'customize.php?autofocus[section]=accessibility', | |
'__return_true' | |
); | |
} | |
if ( $this-> _plugin_wpacc ) | |
{ | |
add_submenu_page( | |
$first, | |
'WP Accessibility', | |
'WP Accessibility', | |
'manage_options', | |
$this->_look[2], | |
'__return_true' | |
); | |
add_submenu_page( | |
$first, | |
'Get Help', | |
$this->_submenuArrow() . ' Get Help', | |
'manage_options', | |
'wp-accessibility-help', | |
'__return_true' | |
); | |
} | |
} | |
public function enqueue(){ | |
if ( !in_array(get_current_screen()->id, $this->_allpages ) ) return; | |
?> | |
<style> | |
div.promotion { | |
display: none !important; | |
} | |
</style> | |
<script type="text/javascript"> | |
jQuery(document).ready( function($) | |
{ | |
$('#toplevel_page_all-accessibility').removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu wp-menu-open'); | |
}); | |
</script> | |
<?php | |
} | |
private function _recursiveSearch ($needle, $haystack) | |
{ | |
foreach ($haystack as $key => $value) { | |
$current_key = $key; | |
if ($needle === $value OR ( | |
is_array($value) | |
&& $this->_recursiveSearch($needle, $value) !== false | |
) | |
) { | |
return $current_key; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment