array( 'name' => 'Spelling and Grammar', 'requires_connection' => true ), 'carousel' => array( 'name' => 'Carousel', 'requires_connection' => false ), 'comments' => array( 'name' => 'Jetpack Comments', 'requires_connection' => true ), 'contact-form' => array( 'name' => 'Contact Form', 'requires_connection' => false ), 'custom-content-types' => array( 'name' => 'Custom Content Types', 'requires_connection' => false ), 'custom-css' => array( 'name' => 'Custom CSS', 'requires_connection' => false ), 'enhanced-distribution' => array( 'name' => 'Enhanced Distribution', 'requires_connection' => true ), 'gravatar-hovercards' => array( 'name' => 'Gravatar Hovercards', 'requires_connection' => false ), 'infinite-scroll' => array( 'name' => 'Infinite Scroll', 'requires_connection' => false ), 'json-api' => array( 'name' => 'JSON API', 'requires_connection' => true ), 'latex' => array( 'name' => 'Beautiful Math', 'requires_connection' => false ), 'likes' => array( 'name' => 'Likes', 'requires_connection' => true ), 'manage' => array( 'name' => 'Manage', 'requires_connection' => true ), 'markdown' => array( 'name' => 'Markdown', 'requires_connection' => false ), 'minileven' => array( 'name' => 'Mobile Theme', 'requires_connection' => false ), 'monitor' => array( 'name' => 'Monitor', 'requires_connection' => true ), 'notes' => array( 'name' => 'Notifications', 'requires_connection' => true ), 'omnisearch' => array( 'name' => 'Omnisearch', 'requires_connection' => false ), 'photon' => array( 'name' => 'Photon', 'requires_connection' => true ), 'post-by-email' => array( 'name' => 'Post by Email', 'requires_connection' => true ), 'protect' => array( 'name' => 'Protect', 'requires_connection' => true ), 'publicize' => array( 'name' => 'Publicize', 'requires_connection' => true ), 'related-posts' => array( 'name' => 'Related Posts', 'requires_connection' => true ), 'sharedaddy' => array( 'name' => 'Sharing', 'requires_connection' => false ), 'shortcodes' => array( 'name' => 'Shortcode Embeds', 'requires_connection' => false ), 'shortlinks' => array( 'name' => 'WP.me Shortlinks', 'requires_connection' => true ), 'site-icon' => array( 'name' => 'Site Icon', 'requires_connection' => false ), 'sso' => array( 'name' => 'Jetpack Single Sign On', 'requires_connection' => true ), 'stats' => array( 'name' => 'WordPress.com Stats', 'requires_connection' => true ), 'subscriptions' => array( 'name' => 'Subscriptions', 'requires_connection' => true ), 'tiled-gallery' => array( 'name' => 'Tiled Galleries', 'requires_connection' => false ), 'vaultpress' => array( 'name' => 'VaultPress', 'requires_connection' => false ), 'verification-tools' => array( 'name' => 'Site Verification', 'requires_connection' => false ), 'videopress' => array( 'name' => 'VideoPress', 'requires_connection' => true ), 'widget-visibility' => array( 'name' => 'Widget Visibility', 'requires_connection' => false ), 'widgets' => array( 'name' => 'Extra Sidebar Widgets', 'requires_connection' => false ) ); /** * Know modules array with dashicons * @since 0.3 * @access private * @var array */ private static $known_modules_icons = array( 'after-the-deadline' => 'edit', 'carousel' => 'camera', 'comments' => 'format-chat', 'contact-form' => 'feedback', 'custom-content-types' => 'media-default', 'custom-css' => 'admin-appearance', 'enhanced-distribution' => 'share', 'gravatar-hovercards' => 'id', // not available 'infinite-scroll' => 'star-filled', 'json-api' => 'share-alt', 'latex' => 'star-filled', 'likes' => 'star-filled', 'manage' => 'wordpress-alt', 'markdown' => 'editor-code', 'minileven' => 'smartphone', 'monitor' => 'flag', 'notes' => 'admin-comments', 'omnisearch' => 'search', 'photon' => 'visibility', 'post-by-email' => 'email', 'protect' => 'lock', 'publicize' => 'share', 'related-posts' => 'update', 'sharedaddy' => 'share-alt', 'shortcodes' => 'text', 'shortlinks' => 'admin-links', 'site-icon' => 'admin-site', 'sso' => 'wordpress-alt', 'stats' => 'wordpress-alt', 'subscriptions' => 'email', 'tiled-gallery' => 'schedule', // not available. maybe tagcloud ? 'vaultpress' => 'shield-alt', // not availabe 'verification-tools' => 'clipboard', // maye yes 'videopress' => 'controls-play', 'widget-visibility' => 'welcome-widgets-menus', 'widgets' => 'welcome-widgets-menus' ); /** * Default dashicon * @since 1.0 * @access private * @var string */ private static $default_icon = 'star-empty'; /** * Return Jetpack available modules * @since 0.1 * @return array */ private function get_available_modules() { if ( null === self::$modules ) { if ( class_exists('Jetpack') ) { //remove_filter( 'jetpack_get_available_modules', array($this, 'blacklist') ); // remove filter useless here because of bug in Jetpack $modules = array(); foreach ( Jetpack::get_available_modules() as $slug ) { $module = Jetpack::get_module( $slug ); if ( $module ) $modules[$slug] = $module; } self::$modules = $modules; //add_filter( 'jetpack_get_available_modules', array($this, 'blacklist') ); } else { self::$modules = self::$known_modules; } } return self::$modules; } /** * Return plugin basename * * @since 0.1 * * @return string Plugin basename */ private function plugin_basename() { if ( null === self::$plugin_basename ) { self::$plugin_basename = plugin_basename( __FILE__ ); } return self::$plugin_basename; } /** * MANUAL CONTROL */ /** * Adds the Manual Control option * * @since 0.1 * @see get_site_option(), checked(), disabled() * * @uses jetpack_mc_manual_control network option * @echo Html Checkbox input field for jetpack_mc_manual_control option * @return void */ public function manual_control_settings() { $cws_manual_control = class_exists('CWS_Manual_Control_for_Jetpack_Plugin') ? true : false; $option = $cws_manual_control ? '1' : get_site_option('jetpack_mc_manual_control'); $disabled = $cws_manual_control || ( defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ) ? true : false; ?>
get_available_modules(); asort($modules); $icons = self::$known_modules_icons; $lockdown = defined('JETPACK_MC_LOCKDOWN') ? JETPACK_MC_LOCKDOWN : false; ?> no_manage_notice(); $this->no_dev_notice(); if ( is_plugin_active_for_network( $this->plugin_basename() ) ) { add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename(), array($this, 'add_action_link') ); // Add settings to Network Settings // thanks to http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/ if ( is_network_admin() ) { add_filter( 'wpmu_options', array( $this, 'show_network_settings' ) ); if ( defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ) { // do not add action to save network settings } else { add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) ); } } } else { add_filter( 'plugin_action_links_' . $this->plugin_basename(), array($this, 'add_action_link') ); // Do regular register/add_settings stuff in 'general' settings on options-general.php $settings = 'general'; add_settings_section('jetpack-mc', '' . __('Jetpack Module Control','jetpack-mc'), array($this, 'add_settings_section'), $settings); // register settings if ( defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ) { // do not register settings to prevent them being updated } else { register_setting( $settings, 'jetpack_mc_manual_control' ); // sanitize_callback 'boolval' ? register_setting( $settings, 'jetpack_mc_development_mode' ); // sanitize_callback 'boolval' ? register_setting( $settings, 'jetpack_mc_blacklist', 'array_values' ); } // add settings fields add_settings_field( 'jetpack_mc_manual_control', __('Manual Control','jetpack-mc'), array($this, 'manual_control_settings'), $settings, 'jetpack-mc' ); // array('label_for' => 'elementid') add_settings_field( 'jetpack_mc_development_mode', __('Development Mode','jetpack-mc'), array($this, 'development_mode_settings'), $settings, 'jetpack-mc' ); // array('label_for' => 'elementid') add_settings_field( 'jetpack_mc_blacklist', __('Blacklist Modules','jetpack-mc'), array($this, 'blacklist_settings'), $settings, 'jetpack-mc' ); } } /** * Saves the network settings * * @since 0.2 */ public function save_network_settings() { $posted_settings = array(); if( isset( $_POST['jetpack_mc_manual_control'] ) ) $posted_settings['jetpack_mc_manual_control'] = '1'; if( isset( $_POST['jetpack_mc_development_mode'] ) ) $posted_settings['jetpack_mc_development_mode'] = '1'; if( isset( $_POST['jetpack_mc_blacklist'] ) ) $posted_settings['jetpack_mc_blacklist'] = array_values($_POST['jetpack_mc_blacklist']); foreach ( $posted_settings as $name => $value ) update_site_option( $name, $value ); } /** * Prints the network settings * * @since 0.2 */ public function show_network_settings() { ?>| manual_control_settings(); ?> | |
| development_mode_settings(); ?> | |
| blacklist_settings(); ?> |
define(\'JETPACK_MC_LOCKDOWN\', true);')
. '';
} // END add_setting_section()
/**
* Adds an action link on the Plugins page
*
* @since 0.1
* @see is_plugin_active_for_network(), admin_url(), network_admin_url()
*
* @param array $links Plugin de/activation and deletion links
* @return array Plugin links plus Settings link
*/
public function add_action_link( $links ) {
$settings_link = is_plugin_active_for_network( $this->plugin_basename() ) ?
'' . translate('Network Settings') . '' :
'' . translate('Settings') . '';
return array_merge(
array( 'settings' => $settings_link ),
$links
);
return $links;
}
/**
* Routines to execute on plugins_loaded
*
* We need to add our jetpack_get_available_modules filter
* AFTER running get_available_modules() because of bug in Jetpack
* https://github.com/Automattic/jetpack/issues/2026
* https://github.com/Automattic/jetpack/pull/2027
*
* @since 0.1
*/
public function plugins_loaded() {
global $pagenow;
// only need translations on admin page
if ( is_admin() ) {
load_plugin_textdomain('jetpack-mc', false, $this->plugin_basename() . '/languages/');
// populate jetpack modules list before filter is added
if ( in_array( $pagenow, array( 'options-general.php', 'settings.php' ) ) )
$this->get_available_modules();
}
add_filter( 'jetpack_get_default_modules', array( $this, 'manual_control' ), 99 );
add_filter( 'jetpack_development_mode', array( $this, 'development_mode' ) );
add_filter( 'jetpack_get_available_modules', array( $this, 'blacklist' ) );
}
/**
* Getter method for retrieving single object instance.
*
* @since 0.1
*
* @return Jetpack_Module_Control|null instance object
*/
public static function instance() {
if(is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
} // End instance ()
/**
* Constructor
*
* @since 0.1
*/
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 0 );
add_action( 'admin_init', array($this,'admin_init'), 11 );
}
/**
* Cloning
*
* @since 0.1
*/
private function __clone() { }
}
Jetpack_Module_Control::instance();