> Read the accompanying readme.txt file for instructions and documentation. =>> Also, visit the plugin's homepage for additional information and updates. =>> Or visit: http://wordpress.org/extend/plugins/admin-expert-mode/ */ /* Copyright (c) 2009-2012 by Scott Reilly (aka coffee2code) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ if ( is_admin() && ! class_exists( 'c2c_AdminExpertMode' ) ) : class c2c_AdminExpertMode { private static $admin_options_name = 'c2c_admin_expert_mode'; private static $field_name = 'admin_expert_mode'; private static $textdomain = 'admin-expert-mode'; private static $prompt = ''; private static $help_text = ''; private static $config = array(); private static $options = array(); private static $activating = false; private static $is_active = false; // Has admin expert mode been determined to be active? /** * Returns version of the plugin. * * @since 1.8 */ public static function version() { return '1.8'; } /** * Constructor */ public static function init() { add_action( 'init', array( __CLASS__, 'do_init' ) ); register_activation_hook( __FILE__, array( __CLASS__, 'plugin_activated' ) ); } /** * Perform initialization */ public static function do_init() { load_plugin_textdomain( self::$textdomain, false, basename( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'lang' ); self::$prompt = __( 'Expert mode', self::$textdomain ); self::$help_text = __( 'Enable expert mode (if you are familiar with WordPress and don\'t need the inline documentation in the admin).', self::$textdomain ); add_action( 'admin_notices', array( __CLASS__, 'display_activation_notice' ) ); add_action( 'load-profile.php', array( __CLASS__, 'register_profile_page_hooks' ) ); // Register and enqueue styles for admin page self::register_styles(); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_admin_css' ) ); } /** * Filters/actions to hook on the admin profile.php page. * */ public static function register_profile_page_hooks() { self::maybe_save_options(); add_action( 'profile_personal_options', array( __CLASS__, 'show_option' ) ); } /** * Set a temporary flag (transient) to indicate the plugin was just activated. * * @return void */ public static function plugin_activated() { set_transient( 'aem_activated', 'show', 10 ); } /** * Output activation notice * * @return void (Text is echoed.) */ public static function display_activation_notice() { if ( get_transient( 'aem_activated' ) ) { if ( self::is_admin_expert_mode_active() ) $msg = __( 'Expert mode is now enabled for you since you had it previously enabled. You can disable it in your profile. Reminder: other admins must separately enable expert mode for themselves via their own profiles. (See the readme.txt for more advanced controls.)', self::$textdomain ); else $msg = __( 'NOTE: You must enable expert mode for yourself (in your profile) for it to take effect. Other admin users must do the same for themselves as well. (See the readme.txt for more advanced controls.)', self::$textdomain ); $msg = sprintf( $msg, admin_url( 'profile.php' ) ); echo "

$msg

"; } } /** * Indicates if admin expert mode is active for the current user. * * Takes the following into account in this order * * Value of 'c2c_admin_expert_mode' filter, if true * * Value of the per-user setting * * @return void (Text is echoed.) */ public static function is_admin_expert_mode_active() { $options = self::get_options(); if ( self::$is_active || apply_filters( 'c2c_admin_expert_mode', $options[self::$field_name], get_user_option( 'user_login' ) ) ) self::$is_active = true; return self::$is_active; } /** * Registers styles. * * @since 1.8 */ public static function register_styles() { wp_register_style( __CLASS__ . '_admin', plugins_url( 'admin.css', __FILE__ ) ); } /** * Enqueues stylesheets if the user has admin expert mode activated. * * @since 1.8 */ public static function enqueue_admin_css() { if ( self::is_admin_expert_mode_active() ) wp_enqueue_style( __CLASS__ . '_admin' ); } /** * Outputs the form input field for the admin expert mode setting checkbox. * * @return void (Text is echoed.) */ public static function show_option( $user ) { $options = self::get_options(); $checked = $options[self::$field_name] ? ' checked="checked"' : ''; echo ''; echo '
' . self::$prompt . '
'; } /** * Returns array of the plugin's settings. * * @return array The plugin's settings */ public static function get_options() { if ( ! empty( self::$options ) ) return self::$options; $existing_options = get_user_option( self::$admin_options_name ); $default = apply_filters( 'c2c_admin_expert_mode_default', false ); self::$options = wp_parse_args( $existing_options, array( self::$field_name => $default ) ); return self::$options; } /** * Saves the user setting. * * @return void */ public static function maybe_save_options() { $user = wp_get_current_user(); if ( isset( $_POST['action'] ) && $_POST['action'] == 'update' ) { $options = self::get_options(); $options[self::$field_name] = $_POST[self::$field_name] ? 1 : 0; update_user_option( $user->ID, self::$admin_options_name, $options ); self::$options = $options; } } } // end c2c_AdminExpertMode c2c_AdminExpertMode::init(); endif; // end if !class_exists() ?>