Last active
November 29, 2016 22:12
-
-
Save logoscreative/9323852 to your computer and use it in GitHub Desktop.
Sample Plugin for "Cleaning up the WordPress Admin"
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 | |
/** | |
* Your Name Global Plugin | |
* | |
* Core settings for Your Name sites. | |
* | |
* @package core_yourplugin | |
* @author Your Name <[email protected]> | |
* @link http://example.com | |
* @copyright 2014 Your Name | |
* | |
* @wordpress-plugin | |
* Plugin Name: Your Name Global Plugin | |
* Plugin URI: http://example.com | |
* Description: Core settings for Your Name sites. | |
* Version: 1.0.0 | |
* Author: Your Name <[email protected]> | |
* Author URI: http://example.com | |
*/ | |
// If this file is called directly, abort. | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
} | |
/** | |
* Turn off things that can screw things up. | |
* | |
* @since 1.0.0 | |
* | |
* @package core_yourplugin | |
* @author Your Name <[email protected]> | |
*/ | |
define( 'DISALLOW_FILE_EDIT', true ); | |
define( 'DISALLOW_FILE_MODS', true ); | |
/** | |
* Plugin class. | |
* | |
* @package core_yourplugin | |
* @author Your Name <[email protected]> | |
*/ | |
class core_yourplugin { | |
/** | |
* Plugin version, used for cache-busting of style and script file references. | |
* | |
* @since 1.0.0 | |
* | |
* @const string | |
*/ | |
const VERSION = '1.0.0'; | |
/** | |
* Unique identifier for your plugin. | |
* | |
* Use this value (not the variable name) as the text domain when internationalizing strings of text. It should | |
* match the Text Domain file header in the main plugin file. | |
* | |
* @since 1.0.0 | |
* | |
* @var string | |
*/ | |
protected $plugin_slug = 'yourplugin-mu'; | |
/** | |
* Instance of this class. | |
* | |
* @since 1.0.0 | |
* | |
* @var object | |
*/ | |
protected static $instance = null; | |
/** | |
* Slug of the plugin screen. | |
* | |
* @since 1.0.0 | |
* | |
* @var string | |
*/ | |
protected $plugin_screen_hook_suffix = null; | |
/** | |
* Initialize the plugin by setting localization, filters, and administration functions. | |
* | |
* @since 1.0.0 | |
*/ | |
private function __construct() { | |
add_action( 'admin_menu', array( $this, 'yourplugin_remove_tools' ), 999 ); | |
add_filter( 'all_plugins', array( $this, 'yourplugin_filter_plugins' ) ); | |
add_action( 'wp_before_admin_bar_render', array( $this, 'yourplugin_remove_admin_bar_links' ) ); | |
add_action( 'admin_init', array( $this, 'yourplugin_disable_dashboard_widgets' ) ); | |
} | |
/** | |
* Return an instance of this class. | |
* | |
* @since 1.0.0 | |
* | |
* @return object A single instance of this class. | |
*/ | |
public static function get_instance() { | |
// If the single instance hasn't been set, set it now. | |
if ( null == self::$instance ) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} | |
/** | |
* NOTE: Remove Stupid Tools.php & Sensitive Plugins from View | |
* | |
* @since 1.0.0 | |
*/ | |
public function yourplugin_remove_tools() { | |
remove_submenu_page( 'tools.php', 'tools.php' ); | |
remove_menu_page( 'better-wp-security' ); | |
remove_menu_page( 'w3tc_dashboard' ); | |
} | |
/** | |
* NOTE: Hide Sensitive Plugins from Plugins Listing | |
* | |
* @since 1.0.0 | |
*/ | |
public function yourplugin_filter_plugins( $plugins ) { | |
$hidden = array( | |
'Better WP Security', | |
'W3 Total Cache' | |
); | |
foreach ($plugins as $key => &$plugin ) { | |
if ( in_array( $plugin["Name"], $hidden ) ) { | |
unset($plugins[$key]); | |
} | |
} | |
return $plugins; | |
} | |
/** | |
* NOTE: Hide Extraneous Plugin Options from the Menu Bar | |
* | |
* @since 1.0.0 | |
*/ | |
public function yourplugin_remove_admin_bar_links() { | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_menu('w3tc-faq'); | |
$wp_admin_bar->remove_menu('w3tc-support'); | |
} | |
/** | |
* NOTE: Hide WordPress News | |
* | |
* @since 1.0.0 | |
*/ | |
public function yourplugin_disable_dashboard_widgets() { | |
remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' ); | |
} | |
} | |
core_yourplugin::get_instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment