Changeset 3090331
- Timestamp:
- 05/21/2024 05:06:13 PM (3 months ago)
- Location:
- jetpack-module-control/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
jetpack-module-control/trunk/jetpack-module-control.php
r2365105 r3090331 1 1 <?php 2 /* 2 /* 3 3 * Plugin Name: Module Control for Jetpack 4 4 * Plugin URI: https://status301.net/wordpress-plugins/jetpack-module-control/ … … 6 6 * Author: RavanH 7 7 * Author URI: https://status301.net/ 8 8 9 * Network: true 9 10 * Text Domain: jetpack-module-control 10 11 * License: GPL2+ 11 * Version: 1.6 12 * Version: 1.7-alpha2 13 * 14 * @package Module Control for Jetpack 12 15 */ 13 16 … … 19 22 * finer grained "Select which modules to auto-activate" 20 23 * see http://jeremy.hu/customize-the-list-of-modules-available-in-jetpack/ 21 * 24 * function jeherve_auto_activate_stats() { 22 25 return array( 'stats' ); 23 26 } … … 42 45 * Jetpack Module Control Class 43 46 * 44 * since 0.147 * ince 0.1 45 48 */ 46 49 class Jetpack_Module_Control { … … 48 51 /** 49 52 * The single instance. 50 * @var object 51 * @access private 52 * @since 0.1 53 * 54 * @var object 55 * @access private 56 * @since 0.1 53 57 */ 54 58 private static $instance = null; … … 56 60 /** 57 61 * The plugins basename. 58 * @var string 59 * @access private 60 * @since 0.1 62 * 63 * @var string 64 * @access private 65 * @since 0.1 61 66 */ 62 67 private static $plugin_basename = null; … … 64 69 /** 65 70 * Current plugin version. 71 66 72 * @since 0.1 67 73 * @var string … … 71 77 /** 72 78 * Available modules array 79 73 80 * @since 0.1 74 81 * @access private … … 79 86 /** 80 87 * Know modules array with names 88 81 89 * @since 0.2 82 90 * @access private … … 84 92 */ 85 93 private static $known_modules = array( 86 'wordads' => array( 'name' => 'Ads', 87 'requires_connection' => true ), 88 // 'after-the-deadline' => array( 'name' => 'Spelling and Grammar', 89 // 'requires_connection' => true ), 90 'carousel' => array( 'name' => 'Carousel', 91 'requires_connection' => false ), 92 'comments' => array( 'name' => 'Comments', 93 'requires_connection' => true ), 94 'comment-likes' => array( 'name' => 'Comment Likes', 95 'requires_connection' => true ), 96 'contact-form' => array( 'name' => 'Contact Form', 97 'requires_connection' => false ), 98 'copy-post' => array( 'name' => 'Copy Post', 99 'requires_connection' => false ), 100 'custom-content-types' => array( 'name' => 'Custom content types', 101 'requires_connection' => false ), 102 'custom-css' => array( 'name' => 'Custom CSS', 103 'requires_connection' => false ), 104 'enhanced-distribution' => array( 'name' => 'Enhanced Distribution', 105 'requires_connection' => true ), 106 'google-analytics' => array( 'name' => 'Google Analytics', 107 'requires_connection' => true ), 108 'gravatar-hovercards' => array( 'name' => 'Gravatar Hovercards', 109 'requires_connection' => false ), 110 'infinite-scroll' => array( 'name' => 'Infinite Scroll', 111 'requires_connection' => false ), 112 'json-api' => array( 'name' => 'JSON API', 113 'requires_connection' => true ), 114 'latex' => array( 'name' => 'Beautiful Math', 115 'requires_connection' => false ), 116 'lazy-images' => array( 'name' => 'Lazy Images', 117 'requires_connection' => false ), 118 'likes' => array( 'name' => 'Likes', 119 'requires_connection' => true ), 120 // 'manage' => array( 'name' => 'Manage', 121 // 'requires_connection' => true ), 122 'markdown' => array( 'name' => 'Markdown', 123 'requires_connection' => false ), 124 // 'minileven' => array( 'name' => 'Mobile Theme', 125 // 'requires_connection' => false ), 126 'monitor' => array( 'name' => 'Monitor', 127 'requires_connection' => true ), 128 'notes' => array( 'name' => 'Notifications', 129 'requires_connection' => true ), 130 // 'omnisearch' => array( 'name' => 'Omnisearch', 131 // 'requires_connection' => false ), 132 'photon' => array( 'name' => 'Image CDN', 133 'requires_connection' => true ), 134 'photon-cdn' => array( 'name' => 'Asset CDN', 135 'requires_connection' => true ), 136 'post-by-email' => array( 'name' => 'Post by Email', 137 'requires_connection' => true ), 138 'protect' => array( 'name' => 'Protect', 139 'requires_connection' => true ), 140 'publicize' => array( 'name' => 'Publicize', 141 'requires_connection' => true ), 142 'related-posts' => array( 'name' => 'Related Posts', 143 'requires_connection' => true ), 144 'search' => array( 'name' => 'Search', 145 'requires_connection' => true ), 146 'seo-tools' => array( 'name' => 'SEO Tools', 147 'requires_connection' => true ), 148 'sharedaddy' => array( 'name' => 'Sharing', 149 'requires_connection' => false ), 150 'shortcodes' => array( 'name' => 'Shortcode Embeds', 151 'requires_connection' => false ), 152 'shortlinks' => array( 'name' => 'WP.me Shortlinks', 153 'requires_connection' => true ), 154 // 'site-icon' => array( 'name' => 'Site Icon', 155 // 'requires_connection' => false ), 156 'sitemaps' => array( 'name' => 'Sitemaps', 157 'requires_connection' => false ), 158 'sso' => array( 'name' => 'Secure Sign On', 159 'requires_connection' => true ), 160 'stats' => array( 'name' => 'Site Stats', 161 'requires_connection' => true ), 162 'subscriptions' => array( 'name' => 'Subscriptions', 163 'requires_connection' => true ), 164 'tiled-gallery' => array( 'name' => 'Tiled Galleries', 165 'requires_connection' => false ), 166 'vaultpress' => array( 'name' => 'Backups and Scanning', 167 'requires_connection' => false ), 168 'verification-tools' => array( 'name' => 'Site Verification', 169 'requires_connection' => false ), 170 'videopress' => array( 'name' => 'VideoPress', 171 'requires_connection' => true ), 172 'widget-visibility' => array( 'name' => 'Widget Visibility', 173 'requires_connection' => false ), 174 'widgets' => array( 'name' => 'Extra Sidebar Widgets', 175 'requires_connection' => false ), 176 'woocommerce-analytics' => array( 'name' => 'WooCommerce Analytics', 177 'requires_connection' => true ), 178 'masterbar' => array( 'name' => 'WordPress.com Toolbar', 179 'requires_connection' => true ) 180 ); 94 'wordads' => array( 95 'name' => 'Ads', 96 'requires_connection' => true, 97 ), 98 'carousel' => array( 99 'name' => 'Carousel', 100 'requires_connection' => false, 101 ), 102 'comments' => array( 103 'name' => 'Comments', 104 'requires_connection' => true, 105 ), 106 'comment-likes' => array( 107 'name' => 'Comment Likes', 108 'requires_connection' => true, 109 ), 110 'contact-form' => array( 111 'name' => 'Contact Form', 112 'requires_connection' => false, 113 ), 114 'copy-post' => array( 115 'name' => 'Copy Post', 116 'requires_connection' => false, 117 ), 118 'custom-content-types' => array( 119 'name' => 'Custom content types', 120 'requires_connection' => false, 121 ), 122 'custom-css' => array( 123 'name' => 'Custom CSS', 124 'requires_connection' => false, 125 ), 126 'enhanced-distribution' => array( 127 'name' => 'Enhanced Distribution', 128 'requires_connection' => true, 129 ), 130 'google-analytics' => array( 131 'name' => 'Google Analytics', 132 'requires_connection' => true, 133 ), 134 'gravatar-hovercards' => array( 135 'name' => 'Gravatar Hovercards', 136 'requires_connection' => false, 137 ), 138 'infinite-scroll' => array( 139 'name' => 'Infinite Scroll', 140 'requires_connection' => false, 141 ), 142 'json-api' => array( 143 'name' => 'JSON API', 144 'requires_connection' => true, 145 ), 146 'latex' => array( 147 'name' => 'Beautiful Math', 148 'requires_connection' => false, 149 ), 150 'lazy-images' => array( 151 'name' => 'Lazy Images', 152 'requires_connection' => false, 153 ), 154 'likes' => array( 155 'name' => 'Likes', 156 'requires_connection' => true, 157 ), 158 'markdown' => array( 159 'name' => 'Markdown', 160 'requires_connection' => false, 161 ), 162 'monitor' => array( 163 'name' => 'Monitor', 164 'requires_connection' => true, 165 ), 166 'notes' => array( 167 'name' => 'Notifications', 168 'requires_connection' => true, 169 ), 170 'photon' => array( 171 'name' => 'Image CDN', 172 'requires_connection' => true, 173 ), 174 'photon-cdn' => array( 175 'name' => 'Asset CDN', 176 'requires_connection' => true, 177 ), 178 'post-by-email' => array( 179 'name' => 'Post by Email', 180 'requires_connection' => true, 181 ), 182 'protect' => array( 183 'name' => 'Protect', 184 'requires_connection' => true, 185 ), 186 'publicize' => array( 187 'name' => 'Publicize', 188 'requires_connection' => true, 189 ), 190 'related-posts' => array( 191 'name' => 'Related Posts', 192 'requires_connection' => true, 193 ), 194 'search' => array( 195 'name' => 'Search', 196 'requires_connection' => true, 197 ), 198 'seo-tools' => array( 199 'name' => 'SEO Tools', 200 'requires_connection' => true, 201 ), 202 'sharedaddy' => array( 203 'name' => 'Sharing', 204 'requires_connection' => false, 205 ), 206 'shortcodes' => array( 207 'name' => 'Shortcode Embeds', 208 'requires_connection' => false, 209 ), 210 'shortlinks' => array( 211 'name' => 'WP.me Shortlinks', 212 'requires_connection' => true, 213 ), 214 'sitemaps' => array( 215 'name' => 'Sitemaps', 216 'requires_connection' => false, 217 ), 218 'sso' => array( 219 'name' => 'Secure Sign On', 220 'requires_connection' => true, 221 ), 222 'stats' => array( 223 'name' => 'Site Stats', 224 'requires_connection' => true, 225 ), 226 'subscriptions' => array( 227 'name' => 'Subscriptions', 228 'requires_connection' => true, 229 ), 230 'tiled-gallery' => array( 231 'name' => 'Tiled Galleries', 232 'requires_connection' => false, 233 ), 234 'vaultpress' => array( 235 'name' => 'Backups and Scanning', 236 'requires_connection' => false, 237 ), 238 'verification-tools' => array( 239 'name' => 'Site Verification', 240 'requires_connection' => false, 241 ), 242 'videopress' => array( 243 'name' => 'VideoPress', 244 'requires_connection' => true, 245 ), 246 'widget-visibility' => array( 247 'name' => 'Widget Visibility', 248 'requires_connection' => false, 249 ), 250 'widgets' => array( 251 'name' => 'Extra Sidebar Widgets', 252 'requires_connection' => false, 253 ), 254 'woocommerce-analytics' => array( 255 'name' => 'WooCommerce Analytics', 256 'requires_connection' => true, 257 ), 258 'masterbar' => array( 259 'name' => 'WordPress.com Toolbar', 260 'requires_connection' => true, 261 ), 262 ); 181 263 182 264 /** … … 189 271 */ 190 272 private static $known_modules_icons = array( 191 'wordads'=> 'megaphone',192 'after-the-deadline'=> 'edit',193 'carousel'=> 'camera',194 'comments'=> 'format-chat',195 'comment-likes'=> 'star-filled',196 'contact-form'=> 'feedback',197 'copy-post'=> 'admin-page',198 'custom-content-types'=> 'media-default',199 'custom-css'=> 'admin-appearance',200 'enhanced-distribution'=> 'share',201 'google-analytics'=> 'chart-line',202 'gravatar-hovercards' => 'id', // not available203 'infinite-scroll'=> 'star-filled',204 'json-api'=> 'share-alt',205 'latex'=> 'star-filled',206 'likes'=> 'star-filled',207 'lazy-images'=> 'images-alt',208 'manage'=> 'wordpress-alt',209 'markdown'=> 'editor-code',210 'minileven'=> 'smartphone',211 'monitor'=> 'flag',212 'notes'=> 'admin-comments',213 'omnisearch'=> 'search',214 'photon'=> 'visibility',215 'photon-cdn'=> 'visibility',216 'post-by-email'=> 'email',217 'protect'=> 'lock',218 'publicize'=> 'share',219 'related-posts'=> 'update',220 'search'=> 'search',221 'seo-tools'=> 'chart-bar',222 'sharedaddy'=> 'share-alt',223 'shortcodes'=> 'text',224 'shortlinks'=> 'admin-links',225 'site-icon'=> 'admin-site',226 'sitemaps'=> 'networking',227 'sso'=> 'wordpress-alt',228 'stats'=> 'chart-area',229 'subscriptions'=> 'email',230 'tiled-gallery'=> 'layout',231 'vaultpress' => 'shield-alt', // not availabe232 'verification-tools' => 'clipboard', // maybe yes233 'videopress'=> 'embed-video',234 'widget-visibility'=> 'welcome-widgets-menus',235 'widgets'=> 'welcome-widgets-menus',236 'woocommerce-analytics'=> 'cart',237 'masterbar'=> 'wordpress',238 273 => 'megaphone', 274 => 'edit', 275 => 'camera', 276 => 'format-chat', 277 => 'star-filled', 278 => 'feedback', 279 => 'admin-page', 280 => 'media-default', 281 => 'admin-appearance', 282 => 'share', 283 => 'chart-line', 284 285 => 'star-filled', 286 => 'share-alt', 287 => 'star-filled', 288 => 'star-filled', 289 => 'images-alt', 290 => 'wordpress-alt', 291 => 'editor-code', 292 => 'smartphone', 293 => 'flag', 294 => 'admin-comments', 295 => 'search', 296 => 'visibility', 297 => 'visibility', 298 => 'email', 299 => 'lock', 300 => 'share', 301 => 'update', 302 => 'search', 303 => 'chart-bar', 304 => 'share-alt', 305 => 'text', 306 => 'admin-links', 307 => 'admin-site', 308 => 'networking', 309 => 'wordpress-alt', 310 => 'chart-area', 311 => 'email', 312 => 'layout', 313 314 315 => 'embed-video', 316 => 'welcome-widgets-menus', 317 => 'welcome-widgets-menus', 318 => 'cart', 319 => 'wordpress', 320 ); 239 321 240 322 /** 241 323 * Default dashicon 324 242 325 * @since 1.0 243 326 * @access private … … 248 331 /** 249 332 * Return Jetpack available modules 333 250 334 * @since 0.1 251 335 * @return array … … 253 337 private function get_available_modules() { 254 338 if ( null === self::$modules ) { 255 if ( class_exists( 'Jetpack') ) {256 remove_filter( 'jetpack_get_available_modules', array( $this, 'blacklist') );339 if ( class_exists() ) { 340 remove_filter( 'jetpack_get_available_modules', array() ); 257 341 $modules = array(); 258 342 foreach ( Jetpack::get_available_modules() as $slug ) { 259 343 $module = Jetpack::get_module( $slug ); 260 if ( $module ) 261 $modules[$slug] = $module; 344 if ( $module ) { 345 $modules[ $slug ] = $module; 346 } 262 347 } 263 348 self::$modules = $modules; 264 add_filter( 'jetpack_get_available_modules', array( $this, 'blacklist') );349 add_filter( 'jetpack_get_available_modules', array() ); 265 350 } else { 266 351 self::$modules = self::$known_modules; … … 298 383 public function subsite_override_settings() { 299 384 300 if ( is_network_admin() ) {301 $option = get_site_option( 'jetpack_mc_subsite_override');385 if( is_network_admin() ) { 386 $option = get_site_option(); 302 387 } 303 388 $disabled = false; … … 307 392 <?php checked( $option, '1' ); ?> 308 393 <?php disabled( $disabled ); ?>> 309 <?php _e('Allow individual site administrators to manage their own settings for Jetpack Module Control','jetpack-module-control'); ?>394 <?php ); ?> 310 395 </label> 311 396 … … 322 407 323 408 if ( is_multisite() ) { 324 $option = get_site_option( 'jetpack_mc_subsite_override');409 $option = get_site_option(); 325 410 } else { 326 // Always return true if not multisite411 // 327 412 $option = true; 328 413 } 329 414 330 415 return $option; 331 332 416 } // END subsite_override() 333 417 … … 350 434 351 435 if ( is_network_admin() ) { 352 // we're in network admin: retrieve network settings 353 $disabled = is_plugin_active_for_network('manual-control/manual-control.php'); 354 $option = $disabled ? '1' : get_site_option('jetpack_mc_manual_control'); 436 // we're in network admin: retrieve network settings. 437 $disabled = is_plugin_active_for_network( 'manual-control/manual-control.php' ); 438 $option = $disabled ? '1' : get_site_option( 'jetpack_mc_manual_control' ); 439 } elseif ( is_plugin_active( 'manual-control/manual-control.php' ) ) { 440 $option = '1'; 441 $disabled = true; 355 442 } else { 356 // we're in site admin357 if ( is_plugin_active('manual-control/manual-control.php') ) {358 $option = '1';359 $ disabled = true;443 // 444 if ( ) ) { 445 446 $; 360 447 } else { 361 // check if subsite override allowed 362 if( $this->subsite_override() ) { 363 // retrieve site setting 364 $option = get_option('jetpack_mc_manual_control'); 365 } else { 366 $option = false; 367 } 368 // fall back on network settings 369 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_manual_control'); 370 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false; 371 } 448 $option = false; 449 } 450 // fall back on network settings. 451 if ( false === $option && is_multisite() ) { 452 $option = get_site_option( 'jetpack_mc_manual_control' ); 453 } 454 $disabled = defined( 'JETPACK_MC_LOCKDOWN' ) && JETPACK_MC_LOCKDOWN ? true : false; 372 455 } 373 456 … … 377 460 <?php checked( $option, '1' ); ?> 378 461 <?php disabled( $disabled ); ?>> 379 <?php _e('Prevent Jetpack from auto-activating (new) modules','jetpack-module-control'); ?>462 <?php ); ?> 380 463 </label> 381 <p class="description"><?php echo sprintf( __('Note: The module %s is excepted from this rule.','jetpack-module-control'), translate_with_gettext_context('Protect','Module Name','jetpack') ); ?></p>464 <p class="description"><?php ) ); ?></p> 382 465 <?php 383 384 466 } // END manual_control_settings() 385 467 … … 391 473 * @since 0.1 392 474 * @see add_filter() 475 393 476 */ 394 477 public function manual_control( $modules ) { 395 478 396 // check if subsite override allowed 397 if ( $this->subsite_override() ) {398 $option = get_option( 'jetpack_mc_manual_control');479 // check if subsite override allowed 480 if( $this->subsite_override() ) { 481 $option = get_option(); 399 482 } else { 400 483 $option = false; 401 484 } 402 // if false, fall back on network settings 403 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_manual_control'); 404 405 return !empty($option) ? array() : $modules; 406 485 // if false, fall back on network settings. 486 if ( false === $option && is_multisite() ) { 487 $option = get_site_option( 'jetpack_mc_manual_control' ); 488 } 489 490 return ! empty( $option ) ? array() : $modules; 407 491 } // END manual_control() 408 492 … … 411 495 */ 412 496 413 /** 414 * Get the Jetpack Without WordPress.com option 415 * 416 * @since 1.6 417 * 418 * @return bool|string 419 */ 420 private function get_development_mode() { 421 422 if ( is_network_admin() ) { 423 // we're in network admin 424 if ( is_plugin_active_for_network('slimjetpack/slimjetpack.php') || is_plugin_active_for_network('unplug-jetpack/unplug-jetpack.php') ) { 425 $option = '1'; 426 } else { 427 // retrieve network settings 428 $option = get_site_option('jetpack_mc_development_mode'); 429 } 430 } else { 431 // we're in site admin 432 if ( is_plugin_active('slimjetpack/slimjetpack.php') || is_plugin_active('unplug-jetpack/unplug-jetpack.php') ) { 433 $option = '1'; 434 } else { 435 // check if subsite override allowed 436 if( $this->subsite_override() ) { 437 //retrieve site setting 438 $option = get_option('jetpack_mc_development_mode'); 439 } else { 440 $option = false; 441 } 442 // fall back on network settings 443 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_development_mode'); 444 } 445 } 497 /** 498 * Get the Jetpack Without WordPress.com option 499 * 500 * @since 1.6 501 * 502 * @return bool|string 503 */ 504 private function get_development_mode() { 505 506 if ( is_network_admin() ) { 507 // we're in network admin. 508 if ( is_plugin_active_for_network( 'slimjetpack/slimjetpack.php' ) || is_plugin_active_for_network( 'unplug-jetpack/unplug-jetpack.php' ) ) { 509 $option = '1'; 510 } else { 511 // retrieve network settings. 512 $option = get_site_option( 'jetpack_mc_development_mode' ); 513 } 514 } elseif ( is_plugin_active( 'slimjetpack/slimjetpack.php' ) || is_plugin_active( 'unplug-jetpack/unplug-jetpack.php' ) ) { 515 $option = '1'; 516 } else { 517 // check if subsite override allowed. 518 if ( $this->subsite_override() ) { 519 // retrieve site setting. 520 $option = get_option( 'jetpack_mc_development_mode' ); 521 } else { 522 $option = false; 523 } 524 // fall back on network settings. 525 if ( false === $option && is_multisite() ) { 526 $option = get_site_option( 'jetpack_mc_development_mode' ); 527 } 528 } 446 529 447 530 return $option; … … 459 542 public function development_mode_settings() { 460 543 461 $option = $this->get_development_mode();462 $disabled = ! is_network_admin() && defined( 'JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;463 464 if ( is_network_admin() && ( is_plugin_active_for_network( 'slimjetpack/slimjetpack.php') || is_plugin_active_for_network('unplug-jetpack/unplug-jetpack.php') ) || is_plugin_active('slimjetpack/slimjetpack.php') || is_plugin_active('unplug-jetpack/unplug-jetpack.php') ) {544 $option = $this->get_development_mode(); 545 $disabled = ! is_network_admin() && defined() && JETPACK_MC_LOCKDOWN ? true : false; 546 547 if ( is_network_admin() && ( is_plugin_active_for_network() ) { 465 548 $disabled = true; 466 549 } … … 471 554 <?php checked( $option, '1' ); ?> 472 555 <?php disabled( $disabled ); ?>> 473 <?php _e('Use Jetpack modules without a WordPress.com connection','jetpack-module-control'); ?>556 <?php ); ?> 474 557 </label> 475 <p class="description"><?php _e('By forcing Jetpack into development mode, modules are used without a WordPress.com account. All modules that require a WordPress.com connection will be unavailable. These modules are marked with an asterisk (*) below. The admin message about Jetpack running in development mode will be hidden.','jetpack-module-control'); ?></p>558 <p class="description"><?php ); ?></p> 476 559 <?php 477 478 560 } // END development_mode_settings() 479 561 … … 486 568 */ 487 569 public function development_mode() { 488 // check if subsite override allowed 489 if ( $this->subsite_override() ) {490 $option = get_option( 'jetpack_mc_development_mode');570 // check if subsite override allowed 571 if( $this->subsite_override() ) { 572 $option = get_option(); 491 573 } else { 492 574 $option = false; 493 575 } 494 576 495 // if false, fall back on network settings 496 if ( $option === false&& is_multisite() ) {497 $option = get_site_option( 'jetpack_mc_development_mode');498 } 499 500 return ! empty($option) ? true : false;577 // if false, fall back on network settings 578 if ( && is_multisite() ) { 579 $option = get_site_option(); 580 } 581 582 return !) ? true : false; 501 583 } 502 584 … … 512 594 */ 513 595 private function no_manage_notice() { 514 // check if subsite override allowed 515 if ( $this->subsite_override() ) {516 $blacklist = get_option( 'jetpack_mc_blacklist');596 // check if subsite override allowed 597 if( $this->subsite_override() ) { 598 $blacklist = get_option(); 517 599 } else { 518 600 $blacklist = false; 519 601 } 520 602 521 // fall back on network setting 522 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist'); 523 524 if ( is_array( $blacklist ) && in_array( 'manage', $blacklist ) ) { 603 // fall back on network setting. 604 if ( false === $blacklist && is_multisite() ) { 605 $blacklist = get_site_option( 'jetpack_mc_blacklist' ); 606 } 607 608 if ( is_array( $blacklist ) && in_array( 'manage', $blacklist, true ) ) { 525 609 add_filter( 'can_display_jetpack_manage_notice', '__return_false' ); 526 610 } … … 534 618 */ 535 619 private function no_dev_notice() { 536 if ( class_exists( 'Jetpack') && ( get_option('jetpack_mc_development_mode') || get_site_option('jetpack_mc_development_mode') ) ) {620 if ( class_exists() ) ) { 537 621 remove_action( 'jetpack_notices', array( Jetpack::init(), 'show_development_mode_notice' ) ); 538 622 } … … 555 639 556 640 if ( is_network_admin() ) { 557 // in network admin retrieve network settings 641 // in network admin retrieve network settings 558 642 $blacklist = get_site_option( 'jetpack_mc_blacklist', array() ); 559 $disabled = false;643 $disabled = false; 560 644 } else { 561 // check if subsite override allowed 562 if ( $this->subsite_override() ) {563 // in site admin retrieve site settings 645 // check if subsite override allowed 646 if( $this->subsite_override() ) { 647 // in site admin retrieve site settings 564 648 $blacklist = get_option( 'jetpack_mc_blacklist' ); 565 649 } else { … … 567 651 } 568 652 569 // fall back on network setting 570 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist'); 571 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false; 653 // fall back on network setting. 654 if ( false === $blacklist && is_multisite() ) { 655 $blacklist = get_site_option( 'jetpack_mc_blacklist' ); 656 } 657 $disabled = defined( 'JETPACK_MC_LOCKDOWN' ) && JETPACK_MC_LOCKDOWN ? true : false; 572 658 } 573 659 574 660 $devmode = $this->get_development_mode(); 575 661 576 // blacklist must be an array, if anything else then just make it an empty array 577 if ( !is_array($blacklist) ) $blacklist = array(); 662 // blacklist must be an array, if anything else then just make it an empty array. 663 if ( ! is_array( $blacklist ) ) { 664 $blacklist = array(); 665 } 578 666 579 667 $modules = $this->get_available_modules(); 580 asort( $modules);668 asort(); 581 669 582 670 ?> 583 <fieldset><legend class="screen-reader-text"><span><?php _e('Blacklist Modules','jetpack-module-control'); ?></span></legend>671 <fieldset><legend class="screen-reader-text"><span><?php ); ?></span></legend> 584 672 <?php 585 673 foreach ( $modules as $slug => $module ) { 586 $icon = isset(self::$known_modules_icons[$slug]) ? self::$known_modules_icons[$slug] : self::$default_icon; 587 $reqconn = !empty($module['requires_connection']) && true === $module['requires_connection']; 588 if ( $devmode && $reqconn ) continue; 674 $icon = isset( self::$known_modules_icons[ $slug ] ) ? self::$known_modules_icons[ $slug ] : self::$default_icon; 675 $reqconn = ! empty( $module['requires_connection'] ) && true === $module['requires_connection']; 676 if ( $devmode && $reqconn ) { 677 continue; 678 } 589 679 ?> 590 680 <label> 591 <input type='checkbox' name='jetpack_mc_blacklist[]' value='<?php echo $slug; ?>'592 <?php checked( in_array( $slug, $blacklist ) ); ?>681 <input type='checkbox' name='jetpack_mc_blacklist[]' value='<?php echo ; ?>' 682 <?php checked( in_array( $slug, $blacklist ) ); ?> 593 683 <?php disabled( $disabled ); ?>> 594 <span class="dashicons dashicons-<?php echo $icon; ?>"></span> <?php echo translate_with_gettext_context( $module['name'], 'Module Name', 'jetpack' )?>595 </label><?php echo $reqconn ? ' <a href="#jmc-note-1" style="text-decoration:none" title="' . __('Requires a WordPress.com connection','jetpack-module-control') . '">*</a>' : ''; ?><br>684 <span class="dashicons dashicons-<?php echo ?> 685 </label><?php echo $reqconn ? ' <a href="#jmc-note-1" style="text-decoration:none" title="' . ) . '">*</a>' : ''; ?><br> 596 686 <?php 597 687 } 598 if ( ! $devmode ) echo '<aside role="note" id="jmc-note-1"><p class="description">' . __('*) Modules marked with an asterisk require a WordPress.com connection. They will be unavailable if Jetpack is forced into offline mode.','jetpack-module-control') . '</p></aside>'; 688 if ( ! $devmode ) { 689 echo '<aside role="note" id="jmc-note-1"><p class="description">' . esc_html__( '*) Modules marked with an asterisk require a WordPress.com connection. They will be unavailable if Jetpack is forced into offline mode.', 'jetpack-module-control' ) . '</p></aside>'; 690 } 599 691 ?> 600 692 </fieldset> 601 693 <?php 602 603 694 } // END blacklist_settings() 604 695 … … 608 699 * 609 700 * @since 0.1 610 * @param $modules701 * @param 611 702 * 612 703 * @return Array Allowed modules after unsetting blacklisted modules from all modules array 613 704 */ 614 public function blacklist 615 616 // check if subsite override allowed 617 if ( $this->subsite_override() ) {618 $blacklist = get_option( 'jetpack_mc_blacklist');705 public function blacklist( $modules ) { 706 707 // check if subsite override allowed 708 if( $this->subsite_override() ) { 709 $blacklist = get_option(); 619 710 } else { 620 711 $blacklist = false; 621 712 } 622 713 623 // fall back on network setting 624 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist'); 625 626 foreach ( (array)$blacklist as $mod ) 627 if ( isset( $modules[$mod] ) ) 628 unset( $modules[$mod] ); 714 // fall back on network setting. 715 if ( false === $blacklist && is_multisite() ) { 716 $blacklist = get_site_option( 'jetpack_mc_blacklist' ); 717 } 718 719 foreach ( (array) $blacklist as $mod ) { 720 if ( isset( $modules[ $mod ] ) ) { 721 unset( $modules[ $mod ] ); 722 } 723 } 629 724 630 725 return $modules; 631 632 726 } 633 727 … … 641 735 * @since 0.1 642 736 */ 643 public function admin_init(){ 737 public function admin_init() { 738 739 // Admin translations. 740 load_plugin_textdomain( 'jetpack-module-control' ); 644 741 645 742 $this->no_manage_notice(); … … 654 751 655 752 // Add settings to Network Settings 656 // thanks to http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/ 753 // thanks to http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/ 657 754 add_filter( 'wpmu_options', array( $this, 'show_network_settings' ) ); 658 755 add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) ); 659 756 660 // Plugin action links 661 add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename(), array( $this, 'add_action_link') );662 } 663 664 // check if subsite override allowed 665 if ($this->subsite_override()) {666 // Plugin action links 667 add_filter( 'plugin_action_links_' . $this->plugin_basename(), array( $this, 'add_action_link') );668 669 // Do regular register/add_settings stuff in 'general' settings on options-general.php 757 // Plugin action links 758 add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename(), array() ); 759 } 760 761 // check if subsite override allowed 762 if) { 763 // Plugin action links 764 add_filter( 'plugin_action_links_' . $this->plugin_basename(), array() ); 765 766 // Do regular register/add_settings stuff in 'general' settings on options-general.php 670 767 $settings = 'general'; 671 768 672 add_settings_section('jetpack-module-control', '<a name="jetpack-mc"></a>' . __('Jetpack Module Control','jetpack-module-control'), array($this, 'add_settings_section'), $settings); 673 674 // register settings 675 if ( defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ) { 676 // do not register site settings to prevent them being updated 677 } else { 769 add_settings_section( 'jetpack-module-control', '<a name="jetpack-mc"></a>' . __( 'Jetpack Module Control', 'jetpack-module-control' ), array( $this, 'add_settings_section' ), $settings ); 770 771 // register settings. 772 if ( ! defined( 'JETPACK_MC_LOCKDOWN' ) || ! JETPACK_MC_LOCKDOWN ) { 678 773 register_setting( $settings, 'jetpack_mc_manual_control' ); // sanitize_callback 'boolval' ? 679 774 register_setting( $settings, 'jetpack_mc_development_mode' ); // sanitize_callback 'boolval' ? 680 register_setting( $settings, 'jetpack_mc_blacklist', array($this, 'sanitize_blacklist') ); 681 } 682 683 // add settings fields 684 add_settings_field( 'jetpack_mc_manual_control', __('Manual Control','jetpack-module-control'), array($this, 'manual_control_settings'), $settings, 'jetpack-module-control' ); // array('label_for' => 'elementid') 685 add_settings_field( 'jetpack_mc_development_mode', __('Offline Mode','jetpack-module-control'), array($this, 'development_mode_settings'), $settings, 'jetpack-module-control' ); // array('label_for' => 'elementid') 686 add_settings_field( 'jetpack_mc_blacklist', __('Blacklist Modules','jetpack-module-control'), array($this, 'blacklist_settings'), $settings, 'jetpack-module-control' ); 687 } 688 775 register_setting( $settings, 'jetpack_mc_blacklist', array( $this, 'sanitize_blacklist' ) ); 776 } 777 778 // add settings fields. 779 add_settings_field( 'jetpack_mc_manual_control', __( 'Manual Control', 'jetpack-module-control' ), array( $this, 'manual_control_settings' ), $settings, 'jetpack-module-control' ); 780 add_settings_field( 'jetpack_mc_development_mode', __( 'Offline Mode', 'jetpack-module-control' ), array( $this, 'development_mode_settings' ), $settings, 'jetpack-module-control' ); 781 add_settings_field( 'jetpack_mc_blacklist', __( 'Blacklist Modules', 'jetpack-module-control' ), array( $this, 'blacklist_settings' ), $settings, 'jetpack-module-control' ); 782 } 689 783 } 690 784 … … 693 787 * 694 788 * @since 1.6 789 695 790 */ 696 791 public function sanitize_blacklist( $options ) { 697 return is_array( $options) ? array_values($options) : $options;792 return is_array() : $options; 698 793 } 699 794 … … 704 799 */ 705 800 public function save_network_settings() { 801 706 802 707 803 $posted_settings = array( 708 'jetpack_mc_manual_control' => '', 709 'jetpack_mc_development_mode' => '', 710 'jetpack_mc_blacklist' => '', 711 'jetpack_mc_subsite_override' => '' 712 ); 713 714 isset( $_POST['jetpack_mc_subsite_override'] ) && $posted_settings['jetpack_mc_subsite_override'] = '1'; 715 716 isset( $_POST['jetpack_mc_manual_control'] ) && $posted_settings['jetpack_mc_manual_control'] = '1'; 717 718 isset( $_POST['jetpack_mc_development_mode'] ) && $posted_settings['jetpack_mc_development_mode'] = '1'; 719 720 isset( $_POST['jetpack_mc_blacklist'] ) && $posted_settings['jetpack_mc_blacklist'] = $this->sanitize_blacklist( $_POST['jetpack_mc_blacklist'] ); 721 722 foreach( $posted_settings as $name => $value ) { 804 'jetpack_mc_manual_control' => isset( $_POST['jetpack_mc_manual_control'] ), 805 'jetpack_mc_development_mode' => isset( $_POST['jetpack_mc_development_mode'] ), 806 'jetpack_mc_blacklist' => isset( $_POST['jetpack_mc_blacklist'] ) ? $this->sanitize_blacklist( $_POST['jetpack_mc_blacklist'] ) : false, 807 'jetpack_mc_subsite_override' => isset( $_POST['jetpack_mc_subsite_override'] ), 808 ); 809 810 foreach ( $posted_settings as $name => $value ) { 723 811 update_site_option( $name, $value ); 724 812 } 725 726 813 } 727 814 … … 733 820 public function show_network_settings() { 734 821 ?> 735 <h3><a name="jetpack-mc"></a><?php _e('Jetpack Module Control','jetpack-module-control'); ?></h3>822 <h3><a name="jetpack-mc"></a><?php ); ?></h3> 736 823 <?php 737 $this->add_settings_section('');824 ); 738 825 ?> 739 826 <table class="form-table"> 740 827 <tbody> 741 828 <tr> 742 <th scope="row"><?php _e('Sub-site Override','jetpack-module-control'); ?></th>829 <th scope="row"><?php ); ?></th> 743 830 <td> 744 831 <?php … … 749 836 750 837 <tr> 751 <th scope="row"><?php _e('Manual Control','jetpack-module-control'); ?></th>838 <th scope="row"><?php ); ?></th> 752 839 <td> 753 840 <?php … … 757 844 </tr> 758 845 <tr> 759 <th scope="row"><?php _e('Development Mode','jetpack-module-control'); ?></th>846 <th scope="row"><?php ); ?></th> 760 847 <td> 761 848 <?php … … 765 852 </tr> 766 853 <tr> 767 <th scope="row"><?php _e('Blacklist Modules','jetpack-module-control'); ?></th>854 <th scope="row"><?php ); ?></th> 768 855 <td> 769 856 <?php … … 773 860 </tr> 774 861 </tbody> 775 776 777 } 778 779 862 </table> 863 <?php 864 } 865 866 /** 780 867 * Echos a settings section header 781 868 * 782 869 * @since 0.1 783 870 * 784 * @param $option (unused)785 871 * @echo Html 786 872 */ 787 public function add_settings_section( $option) {873 public function add_settings_section() { 788 874 echo '<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=Jetpack%20Module%20Control&item_number=' 789 . $this->version875 . 790 876 . '&no_shipping=0&tax=0&charset=UTF%2d8¤cy_code=EUR" title="' 791 . __('Donate to keep plugin development going!','jetpack-module-control')877 . ) 792 878 . '" target="_blank"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" style="border:none;float:right;margin:5px 0 0 10px" alt="' 793 . __('Donate to keep plugin development going!','jetpack-module-control') . '" width="92" height="26" /></a>' 794 . sprintf(__('The options in this section are provided by %s.','jetpack-module-control'),'<strong><a href="http://status301.net/wordpress-plugins/jetpack-module-control/">' 795 . __('Jetpack Module Control','jetpack-module-control') . ' ' . $this->version . '</a></strong>') . ' ' 796 . __('This plugin brings additional control over Jetpack modules. You can blacklist / remove individual modules, prevent auto-activation or allow activation without a WordPress.com account.','jetpack-module-control') . ' '; 797 798 if ( !is_multisite() ) 799 echo sprintf(__('These settings can be locked down by adding %s to your wp-config.php file.','jetpack-module-control'),'<code>define(\'JETPACK_MC_LOCKDOWN\', true);</code>'); 800 else if ( is_network_admin() ) 801 echo '<br><em>' . __('These settings are only visible to you as Super Admin and these settings affect all sites on the network.','jetpack-module-control') . '</em>'; 879 . esc_html__( 'Donate to keep plugin development going!', 'jetpack-module-control' ) . '" width="92" height="26" /></a>' 880 . sprintf( /* translators: plugin name, linked to plugin home page */ 881 esc_html__( 'The options in this section are provided by %s.', 'jetpack-module-control' ), 882 '<strong><a href="http://status301.net/wordpress-plugins/jetpack-module-control/">' 883 . esc_html__( 'Jetpack Module Control', 'jetpack-module-control' ) . ' ' . esc_html( $this->version ) . '</a></strong>' 884 ) . ' ' 885 . esc_html__( 'This plugin brings additional control over Jetpack modules. You can blacklist / remove individual modules, prevent auto-activation or allow activation without a WordPress.com account.', 'jetpack-module-control' ) . ' '; 886 887 if ( ! is_multisite() ) { 888 printf( /* translators: code snippet */ esc_html__( 'These settings can be locked down by adding %s to your wp-config.php file.', 'jetpack-module-control' ), '<code>define(\'JETPACK_MC_LOCKDOWN\', true);</code>' ); 889 } elseif ( is_network_admin() ) { 890 echo '<br><em>' . esc_html__( 'These settings are only visible to you as Super Admin and these settings affect all sites on the network.', 'jetpack-module-control' ) . '</em>'; 891 } 802 892 803 893 echo '</p>'; … … 810 900 * @see is_plugin_active_for_network(), admin_url(), network_admin_url() 811 901 * 812 * @param array $links Plugin de/activation and deletion links 813 * @return array Plugin links plus Settings link 902 * @param array $links Plugin de/activation and deletion links 903 * @return array Plugin links plus Settings link 814 904 */ 815 905 public function add_action_link( $links ) { 816 906 $settings_link = is_plugin_active_for_network( $this->plugin_basename() ) ? 817 '<a href="' . network_admin_url('settings.php#jetpack-mc') . '">' . translate('Network Settings') . '</a>' : 818 '<a href="' . admin_url('options-general.php#jetpack-mc') . '">' . translate('Settings') . '</a>'; 907 '<a href="' . network_admin_url( 'settings.php#jetpack-mc' ) . '">' . esc_html__( 'Network Settings' ) . '</a>' : 908 '<a href="' . admin_url( 'options-general.php#jetpack-mc' ) . '">' . esc_html__( 'Settings' ) . '</a>'; 909 819 910 return array_merge( 820 911 array( 'settings' => $settings_link ), 821 912 $links 822 913 ); 823 return $links; 824 } 825 826 /** 827 * Routines to execute on plugins_loaded 828 * 829 * https://github.com/Automattic/jetpack/pull/2027 >> request accepted and fixed 830 * 831 * @since 0.1 832 */ 833 public function plugins_loaded() { 834 global $pagenow; 835 836 // only need translations on admin page 837 if ( is_admin() ) { 838 load_plugin_textdomain( 'jetpack-module-control' ); 839 } 840 914 } 915 916 /** 917 * Getter method for retrieving single object instance. 918 * 919 * @since 0.1 920 * 921 * @return Jetpack_Module_Control|null instance object 922 */ 923 public static function instance() { 924 if ( is_null( self::$instance ) ) { 925 self::$instance = new self(); 926 } 927 return self::$instance; 928 } 929 930 /** 931 * Constructor 932 * 933 * @since 0.1 934 */ 935 private function __construct() { 841 936 add_filter( 'jetpack_get_default_modules', array( $this, 'manual_control' ), 99 ); 842 937 add_filter( 'jetpack_offline_mode', array( $this, 'development_mode' ) ); 843 938 add_filter( 'jetpack_get_available_modules', array( $this, 'blacklist' ) ); 844 } 845 846 /** 847 * Getter method for retrieving single object instance. 848 * 849 * @since 0.1 850 * 851 * @return Jetpack_Module_Control|null instance object 852 */ 853 public static function instance() { 854 if(is_null(self::$instance)) { 855 self::$instance = new self(); 856 } 857 return self::$instance; 858 } 859 860 /** 861 * Constructor 939 940 add_action( 'admin_init', array( $this, 'admin_init' ), 11 ); 941 } 942 943 /** 944 * Cloning 862 945 * 863 946 * @since 0.1 864 947 */ 865 private function __construct() {866 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 0 );867 add_action( 'admin_init', array($this,'admin_init'), 11 );868 }869 870 /**871 * Cloning872 *873 * @since 0.1874 */875 948 private function __clone() { } 876 877 949 } 878 950 -
jetpack-module-control/trunk/readme.txt
r2933440 r3090331 2 2 Contributors: RavanH 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=Module%20Control%20for%20Jetpack 4 Tags: Jetpack, jet pack, jetpack light, manual control, blacklist, blacklist jetpack modules, slim jetpack 4 Tags: Jetpack, jet pack, jetpack light, manual control, blacklist, blacklist jetpack modules, slim jetpack 5 5 Stable tag: 1.6 6 6 Requires at least: 4.0 7 Tested up to: 6. 27 Tested up to: 6. 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 13 13 == Description == 14 14 15 [Jetpack](https://wordpress.org/plugins/jetpack/) adds powerful features ... but sometimes we don't want them all. This plugin brings additional control over Jetpack modules.15 [Jetpack](https://wordpress.org/plugins/jetpack/) adds powerful features. 16 16 17 17 = Features = … … 19 19 1. Blacklist / remove individual Jetpack modules. 20 20 1. Prevent module auto-activation on connection or after an upgrade. 21 1. Allow activation of Jetpack moduleswithout a WordPress.com connection.21 1. without a WordPress.com connection. 22 22 1. Single site and Multisite compatible. 23 23 … … 26 26 In most use cases, a carefully considered combination of Jetpack modules can be a really good thing. But not always is much consideration being done beforehand. Or site admins just don't know all the implications... 27 27 28 - Maybe your Nginx web server uses FastCGI caching, making it incompatible with the Mobile Theme module? Blacklist that module to prevent any admin from activating it.29 - Do you already a light box provided by your theme or another plugin? Then blacklist the Carousel module to prevent accidental activation.28 - 29 - Do you already a light box provided by your theme or another plugin? Then blacklist the Carousel module to prevent accidental activation. 30 30 - Or you're running a Multisite and do not want any admins monitoring uptime with the Monitor module just to call you every time their site is briefly inaccessible? 31 - O r you offer your own backup service and do not care much for VaultPress competition?32 - You're running a school network and (some) sites are managed by minors who are not allowed to sign up for an account at WordPress.com? Then use the Jetpack DevelopmentMode option to allow usage of modules that do not require a connection.31 - Offer your own backup service and do not care much for VaultPress competition? 32 - You're running a school network and (some) sites are managed by minors who are not allowed to sign up for an account at WordPress.com? Then use the Jetpack Mode option to allow usage of modules that do not require a connection. 33 33 34 34 Any one of Jetpack's modules can bring overlapping or even conflicting functionality. In such cases, being able to prevent (accidental) activation is a good thing. … … 66 66 67 67 == Changelog == 68 69 70 71 72 73 68 74 69 75 = 1.6 =
Note: See TracChangeset
for help on using the changeset viewer.