PluginProbe
Module Control for Jetpack / 1.5
Module Control for Jetpack v1.5
1.7.4 1.7.3 trunk 0.4 1.0 1.2 1.3 1.4 1.4.1 1.4.2 1.5 1.6 1.7 1.7.1 1.7.2
jetpack-module-control / jetpack-module-control.php

jetpack-module-control.php in Module Control for Jetpack 1.5, at jetpack-module-control.php

828 lines 26.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Module Control for Jetpack
4 * Plugin URI: http://status301.net/wordpress-plugins/jetpack-module-control/
5 * Description: 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.
6 * Author: RavanH
7 * Author URI: http://status301.net/
8 * Network: true
9 * Text Domain: jetpack-module-control
10 * Domain Path: /languages
11 * License: GPL2+
12 * Version: 1.5
13 */
14
15 /*
16 * ROADMAP
17 *
18 * version 2.0
19 * Replace "Prevent the Jetpack plugin from auto-activating (new) modules" with
20 * finer grained "Select which modules to auto-activate"
21 * see http://jeremy.hu/customize-the-list-of-modules-available-in-jetpack/
22 * function jeherve_auto_activate_stats() {
23 return array( 'stats' );
24 }
25 add_filter( 'jetpack_get_default_modules', 'jeherve_auto_activate_stats' );
26 *
27 * TO CONSIDER
28 *
29 * Make blacklist or whitelist optional
30 *
31 * Option to disable JUMPSTART with "Jetpack_Options::update_option( 'jumpstart', 'jumpstart_dismissed' );" ??
32 * or do we need to go through apply_filters( 'jetpack_module_feature' ...
33 * If we want to be able to select which modules should appear in Jumpstart later!
34 *
35 * Can we disable Debug link in the footer menu? No...
36 *
37 * Option to "force_deactivate" (same as blacklist?) as described on https://github.com/Automattic/jetpack/issues/1452
38 *
39 */
40
41
42 /**
43 * Jetpack Module Control Class
44 *
45 * since 0.1
46 */
47 class Jetpack_Module_Control {
48
49 /**
50 * The single instance.
51 * @var object
52 * @access private
53 * @since 0.1
54 */
55 private static $instance = null;
56
57 /**
58 * The plugins basename.
59 * @var string
60 * @access private
61 * @since 0.1
62 */
63 private static $plugin_basename = null;
64
65 /**
66 * Current plugin version.
67 * @since 0.1
68 * @var string
69 */
70 public $version = '1.5';
71
72 /**
73 * Available modules array
74 * @since 0.1
75 * @access private
76 * @var array
77 */
78 private static $modules = null;
79
80 /**
81 * Know modules array with names
82 * @since 0.2
83 * @access private
84 * @var array
85 */
86 private static $known_modules = array(
87 'after-the-deadline' => array( 'name' => 'Spelling and Grammar',
88 'requires_connection' => true ),
89 'carousel' => array( 'name' => 'Carousel',
90 'requires_connection' => false ),
91 'comments' => array( 'name' => 'Jetpack Comments',
92 'requires_connection' => true ),
93 'contact-form' => array( 'name' => 'Contact Form',
94 'requires_connection' => false ),
95 'custom-content-types' => array( 'name' => 'Custom Content Types',
96 'requires_connection' => false ),
97 'custom-css' => array( 'name' => 'Custom CSS',
98 'requires_connection' => false ),
99 'enhanced-distribution' => array( 'name' => 'Enhanced Distribution',
100 'requires_connection' => true ),
101 'gravatar-hovercards' => array( 'name' => 'Gravatar Hovercards',
102 'requires_connection' => false ),
103 'infinite-scroll' => array( 'name' => 'Infinite Scroll',
104 'requires_connection' => false ),
105 'json-api' => array( 'name' => 'JSON API',
106 'requires_connection' => true ),
107 'latex' => array( 'name' => 'Beautiful Math',
108 'requires_connection' => false ),
109 'likes' => array( 'name' => 'Likes',
110 'requires_connection' => true ),
111 'manage' => array( 'name' => 'Manage',
112 'requires_connection' => true ),
113 'markdown' => array( 'name' => 'Markdown',
114 'requires_connection' => false ),
115 'minileven' => array( 'name' => 'Mobile Theme',
116 'requires_connection' => false ),
117 'monitor' => array( 'name' => 'Monitor',
118 'requires_connection' => true ),
119 'notes' => array( 'name' => 'Notifications',
120 'requires_connection' => true ),
121 'omnisearch' => array( 'name' => 'Omnisearch',
122 'requires_connection' => false ),
123 'photon' => array( 'name' => 'Photon',
124 'requires_connection' => true ),
125 'post-by-email' => array( 'name' => 'Post by Email',
126 'requires_connection' => true ),
127 'protect' => array( 'name' => 'Protect',
128 'requires_connection' => true ),
129 'publicize' => array( 'name' => 'Publicize',
130 'requires_connection' => true ),
131 'related-posts' => array( 'name' => 'Related Posts',
132 'requires_connection' => true ),
133 'sharedaddy' => array( 'name' => 'Sharing',
134 'requires_connection' => false ),
135 'shortcodes' => array( 'name' => 'Shortcode Embeds',
136 'requires_connection' => false ),
137 'shortlinks' => array( 'name' => 'WP.me Shortlinks',
138 'requires_connection' => true ),
139 'site-icon' => array( 'name' => 'Site Icon',
140 'requires_connection' => false ),
141 'sitemaps' => array( 'name' => 'Sitemaps',
142 'requires_connection' => false ),
143 'sso' => array( 'name' => 'Jetpack Single Sign On',
144 'requires_connection' => true ),
145 'stats' => array( 'name' => 'WordPress.com Stats',
146 'requires_connection' => true ),
147 'subscriptions' => array( 'name' => 'Subscriptions',
148 'requires_connection' => true ),
149 'tiled-gallery' => array( 'name' => 'Tiled Galleries',
150 'requires_connection' => false ),
151 'vaultpress' => array( 'name' => 'VaultPress',
152 'requires_connection' => false ),
153 'verification-tools' => array( 'name' => 'Site Verification',
154 'requires_connection' => false ),
155 'videopress' => array( 'name' => 'VideoPress',
156 'requires_connection' => true ),
157 'widget-visibility' => array( 'name' => 'Widget Visibility',
158 'requires_connection' => false ),
159 'widgets' => array( 'name' => 'Extra Sidebar Widgets',
160 'requires_connection' => false )
161 );
162
163 /**
164 * Know modules array with dashicons
165 * https://developer.wordpress.org/resource/dashicons/
166 * TODO switch to http://genericons.com/
167 *
168 * @since 0.3
169 * @access private
170 * @var array
171 */
172 private static $known_modules_icons = array(
173 'after-the-deadline' => 'edit',
174 'carousel' => 'camera',
175 'comments' => 'format-chat',
176 'contact-form' => 'feedback',
177 'custom-content-types' => 'media-default',
178 'custom-css' => 'admin-appearance',
179 'enhanced-distribution' => 'share',
180 'gravatar-hovercards' => 'id', // not available
181 'infinite-scroll' => 'star-filled',
182 'json-api' => 'share-alt',
183 'latex' => 'star-filled',
184 'likes' => 'star-filled',
185 'manage' => 'wordpress-alt',
186 'markdown' => 'editor-code',
187 'minileven' => 'smartphone',
188 'monitor' => 'flag',
189 'notes' => 'admin-comments',
190 'omnisearch' => 'search',
191 'photon' => 'visibility',
192 'post-by-email' => 'email',
193 'protect' => 'lock',
194 'publicize' => 'share',
195 'related-posts' => 'update',
196 'sharedaddy' => 'share-alt',
197 'shortcodes' => 'text',
198 'shortlinks' => 'admin-links',
199 'site-icon' => 'admin-site',
200 'sitemaps' => 'networking',
201 'sso' => 'wordpress-alt',
202 'stats' => 'wordpress-alt',
203 'subscriptions' => 'email',
204 'tiled-gallery' => 'layout',
205 'vaultpress' => 'shield-alt', // not availabe
206 'verification-tools' => 'clipboard', // maybe yes
207 'videopress' => 'controls-play',
208 'widget-visibility' => 'welcome-widgets-menus',
209 'widgets' => 'welcome-widgets-menus'
210 );
211
212 /**
213 * Default dashicon
214 * @since 1.0
215 * @access private
216 * @var string
217 */
218 private static $default_icon = 'star-empty';
219
220 /**
221 * Return Jetpack available modules
222 * @since 0.1
223 * @return array
224 */
225 private function get_available_modules() {
226 // TODO : consider removing connection dependent modules when 'jetpack_mc_development_mode' is ON
227
228 if ( null === self::$modules ) {
229 if ( class_exists('Jetpack') ) {
230 remove_filter( 'jetpack_get_available_modules', array($this, 'blacklist') );
231 $modules = array();
232 foreach ( Jetpack::get_available_modules() as $slug ) {
233 $module = Jetpack::get_module( $slug );
234 if ( $module )
235 $modules[$slug] = $module;
236 }
237 self::$modules = $modules;
238 add_filter( 'jetpack_get_available_modules', array($this, 'blacklist') );
239 } else {
240 self::$modules = self::$known_modules;
241 }
242 }
243 return self::$modules;
244 }
245
246 /**
247 * Return plugin basename
248 *
249 * @since 0.1
250 *
251 * @return string Plugin basename
252 */
253 private function plugin_basename() {
254 if ( null === self::$plugin_basename ) {
255 self::$plugin_basename = plugin_basename( __FILE__ );
256 }
257 return self::$plugin_basename;
258 }
259
260 /**
261 * Sub-site override
262 */
263
264 /**
265 * Adds the sub-site override option
266 *
267 * @see get_site_option(), checked(), disabled()
268 * @uses jetpack_mc_subsite_override network option
269 * @echo Html Checkbox input field for jetpack_mc_subsite_override option
270 * @return void
271 */
272 public function subsite_override_settings() {
273
274 if( is_network_admin() ) {
275 $option = get_site_option('jetpack_mc_subsite_override');
276 }
277 $disabled = false;
278 ?>
279 <label>
280 <input type='checkbox' name='jetpack_mc_subsite_override' value='1'
281 <?php checked( $option, '1' ); ?>
282 <?php disabled( $disabled ); ?>>
283 <?php _e('Allow individual site administrators to manage their own settings for Jetpack Module Control','jetpack-module-control'); ?>
284 </label>
285
286 <?php
287 } // END subsite_override_settings()
288
289 /**
290 * Checks if subsite override is allowed on multisite.
291 *
292 * @uses get_site_option()
293 * @return bool jetpack_mc_subsite_override network option. Always true if single site installation
294 */
295 public function subsite_override() {
296
297 if ( is_multisite() ) {
298 $option = get_site_option('jetpack_mc_subsite_override');
299 } else {
300 //Always return true if not multisite
301 $option = true;
302 }
303
304 return $option;
305
306 } // END subsite_override()
307
308
309 /**
310 * MANUAL CONTROL
311 */
312
313 /**
314 * Adds the Manual Control option
315 *
316 * @since 0.1
317 * @see get_site_option(), checked(), disabled()
318 *
319 * @uses jetpack_mc_manual_control network option
320 * @echo Html Checkbox input field for jetpack_mc_manual_control option
321 * @return void
322 */
323 public function manual_control_settings() {
324
325 if ( is_network_admin() ) {
326 // we're in network admin: retrieve network settings
327 $disabled = is_plugin_active_for_network('manual-control/manual-control.php');
328 $option = $disabled ? '1' : get_site_option('jetpack_mc_manual_control');
329 } else {
330 // we're in site admin
331 if ( is_plugin_active('manual-control/manual-control.php') ) {
332 $option = '1';
333 $disabled = true;
334 } else {
335 // check if subsite override allowed
336 if( $this->subsite_override() ) {
337 // retrieve site setting
338 $option = get_option('jetpack_mc_manual_control');
339 } else {
340 $option = false;
341 }
342 // fall back on network settings
343 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_manual_control');
344 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;
345 }
346 }
347
348 ?>
349 <label>
350 <input type='checkbox' name='jetpack_mc_manual_control' value='1'
351 <?php checked( $option, '1' ); ?>
352 <?php disabled( $disabled ); ?>>
353 <?php _e('Prevent Jetpack from auto-activating (new) modules','jetpack-module-control'); ?>
354 </label>
355 <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>
356 <?php
357
358 } // END manual_control_settings()
359
360 /**
361 * Activates Manual Control by returning an empty array on module auto-activation.
362 * First modelled after Manual Control for Jetpack by Mark Jaquith http://coveredwebservices.com/
363 * To be converted to allow selected modules instead of all or none.
364 *
365 * @since 0.1
366 * @see add_filter()
367 */
368 public function manual_control( $modules ) {
369
370 // check if subsite override allowed
371 if( $this->subsite_override() ) {
372 $option = get_option('jetpack_mc_manual_control');
373 } else {
374 $option = false;
375 }
376 // if false, fall back on network settings
377 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_manual_control');
378
379 return !empty($option) ? array() : $modules;
380
381 } // END manual_control()
382
383 /**
384 * DEVELOPMENT MODE
385 */
386
387 /**
388 * Adds the Jetpack Without WordPress.com option
389 *
390 * @since 1.0
391 * @see get_site_option(), checked(), disabled()
392 *
393 * @echo Html Checkbox input field for jetpack_mc_development_mode option
394 * @return void
395 */
396 public function development_mode_settings() {
397
398 if ( is_network_admin() ) {
399 // we're in network admin
400 if ( is_plugin_active_for_network('slimjetpack/slimjetpack.php') || is_plugin_active_for_network('unplug-jetpack/unplug-jetpack.php') ) {
401 $option = '1';
402 $disabled = true;
403 } else {
404 // retrieve network settings
405 $option = get_site_option('jetpack_mc_development_mode');
406 $disabled = false;
407 }
408 } else {
409 // we're in site admin
410 if ( is_plugin_active('slimjetpack/slimjetpack.php') || is_plugin_active('unplug-jetpack/unplug-jetpack.php') ) {
411 $option = '1';
412 $disabled = true;
413 } else {
414 // check if subsite override allowed
415 if( $this->subsite_override() ) {
416 //retrieve site setting
417 $option = get_option('jetpack_mc_development_mode');
418 } else {
419 $option = false;
420 }
421 // fall back on network settings
422 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_development_mode');
423 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;
424 }
425 }
426
427 ?>
428 <label>
429 <input type='checkbox' name='jetpack_mc_development_mode' value='1'
430 <?php checked( $option, '1' ); ?>
431 <?php disabled( $disabled ); ?>>
432 <?php _e('Use Jetpack modules without a WordPress.com connection','jetpack-module-control'); ?>
433 </label>
434 <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>
435 <?php
436
437 } // END development_mode_settings()
438
439 /**
440 * Activates Development Mode by returning true on jetpack_development_mode filter.
441 * Based on http://jeremy.hu/customize-the-list-of-modules-available-in-jetpack/
442 *
443 * @since 1.0
444 * @see add_filter()
445 */
446 public function development_mode() {
447 // check if subsite override allowed
448 if( $this->subsite_override() ) {
449 $option = get_option('jetpack_mc_development_mode');
450 } else {
451 $option = false;
452 }
453
454 // if false, fall back on network settings
455 if ( $option === false && is_multisite() ) {
456 $option = get_site_option('jetpack_mc_development_mode');
457 }
458
459 return !empty($option) ? true : false;
460 }
461
462 /**
463 * ADMIN NOTICES
464 */
465
466 /**
467 * Disables Centralized Site Management banner by returning false on can_display_jetpack_manage_notice filter.
468 *
469 * @since 0.1
470 * @see add_filter()
471 */
472 private function no_manage_notice() {
473 // check if subsite override allowed
474 if( $this->subsite_override() ) {
475 $blacklist = get_option('jetpack_mc_blacklist');
476 } else {
477 $blacklist = false;
478 }
479
480 // fall back on network setting
481 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist');
482
483 if ( is_array( $blacklist ) && in_array( 'manage', $blacklist ) ) {
484 add_filter( 'can_display_jetpack_manage_notice', '__return_false' );
485 }
486 }
487
488 /**
489 * Disables Centralized Site Management banner by removing show_development_mode_notice from jetpack_notices actions.
490 *
491 * @since 0.1
492 * @see add_filter()
493 */
494 private function no_dev_notice() {
495 if ( class_exists('Jetpack') && ( get_option('jetpack_mc_development_mode') || get_site_option('jetpack_mc_development_mode') ) ) {
496 remove_action( 'jetpack_notices', array( Jetpack::init(), 'show_development_mode_notice' ) );
497 }
498 }
499
500 /**
501 * BLACKLIST
502 */
503
504 /**
505 * Adds a checkmark list of modules to blacklist
506 *
507 * @since 0.1
508 * @see get_site_option(), checked()
509 *
510 * @uses jetpack_mc_blacklist network option
511 * @echo Html Checkbox input field table for jetpack_mc_blacklist option
512 */
513 public function blacklist_settings() {
514
515 if ( is_network_admin() ) {
516 // in network admin retrieve network settings
517 $blacklist = get_site_option( 'jetpack_mc_blacklist', array() );
518 $disabled = false;
519 } else {
520 // check if subsite override allowed
521 if( $this->subsite_override() ) {
522 // in site admin retrieve site settings
523 $blacklist = get_option( 'jetpack_mc_blacklist' );
524 } else {
525 $blacklist = false;
526 }
527
528 // fall back on network setting
529 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist');
530 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;
531 }
532
533 // blacklist must be an array, if anything else then just make it an empty array
534 if ( !is_array($blacklist) ) $blacklist = array();
535
536 $modules = $this->get_available_modules();
537 asort($modules);
538
539 $icons = self::$known_modules_icons;
540
541 ?>
542 <fieldset><legend class="screen-reader-text"><span><?php _e('Blacklist Modules','jetpack-module-control'); ?></span></legend>
543 <?php
544 foreach ( $modules as $slug => $module ) {
545 $icon = isset($icons[$slug]) ? $icons[$slug] : self::$default_icon;
546 ?>
547 <label>
548 <input type='checkbox' name='jetpack_mc_blacklist[]' value='<?php echo $slug; ?>'
549 <?php checked( in_array( $slug, $blacklist ), true ); ?>
550 <?php disabled( $disabled ); ?>>
551 <span class="dashicons dashicons-<?php echo $icon; ?>"></span> <?php echo translate_with_gettext_context( $module['name'], 'Module Name', 'jetpack' ) ?>
552 </label><?php echo !empty($module['requires_connection']) && true === $module['requires_connection'] ? ' <a href="#jmc-note-1" style="text-decoration:none" title="' . __('Requires a WordPress.com connection','jetpack-module-control') . '">*</a>' : ''; ?><br>
553 <?php
554 }
555 ?>
556 <aside role="note" id="jmc-note-1"><p class="description"><?php _e('*) Modules marked with an asterisk require a WordPress.com connection. They will be unavailable if Jetpack is forced into development mode.','jetpack-module-control'); ?></p></aside>
557 </fieldset>
558 <?php
559
560 } // END blacklist_settings()
561
562 /**
563 * Blacklist Jetpack modules
564 * Modelled after ParhamG's blacklist_jetpack_modules.php https://gist.github.com/ParhamG/6494979
565 *
566 * @since 0.1
567 * @param $modules
568 *
569 * @return Array Allowed modules after unsetting blacklisted modules from all modules array
570 */
571 public function blacklist ( $modules ) {
572
573 // check if subsite override allowed
574 if( $this->subsite_override() ) {
575 $blacklist = get_option('jetpack_mc_blacklist');
576 } else {
577 $blacklist = false;
578 }
579
580 // fall back on network setting
581 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist');
582
583 foreach ( (array)$blacklist as $mod )
584 if ( isset( $modules[$mod] ) )
585 unset( $modules[$mod] );
586
587 return $modules;
588
589 }
590
591 /**
592 * ADMIN
593 */
594
595 /**
596 * Initiate plugins admin stuff
597 *
598 * @since 0.1
599 */
600 public function admin_init(){
601
602 $this->no_manage_notice();
603
604 $this->no_dev_notice();
605
606 if ( is_plugin_active_for_network( $this->plugin_basename() ) ) {
607 // Check for network activation, else these will also take effect when
608 // plugin is activated on the primary site alone.
609 // TODO : see if you can actually use this scenario where plugin is activatied on site 1 and
610 // network options can be set to serve as default settings for other site activations !
611
612 // Add settings to Network Settings
613 // thanks to http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/
614 add_filter( 'wpmu_options', array( $this, 'show_network_settings' ) );
615 add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) );
616
617 // Plugin action links
618 add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename(), array($this, 'add_action_link') );
619 }
620
621 // check if subsite override allowed
622 if($this->subsite_override()) {
623 // Plugin action links
624 add_filter( 'plugin_action_links_' . $this->plugin_basename(), array($this, 'add_action_link') );
625
626 // Do regular register/add_settings stuff in 'general' settings on options-general.php
627 $settings = 'general';
628
629 add_settings_section('jetpack-module-control', '<a name="jetpack-mc"></a>' . __('Jetpack Module Control','jetpack-module-control'), array($this, 'add_settings_section'), $settings);
630
631 // register settings
632 if ( defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ) {
633 // do not register site settings to prevent them being updated
634 } else {
635 register_setting( $settings, 'jetpack_mc_manual_control' ); // sanitize_callback 'boolval' ?
636 register_setting( $settings, 'jetpack_mc_development_mode' ); // sanitize_callback 'boolval' ?
637 register_setting( $settings, 'jetpack_mc_blacklist', 'array_values' );
638 }
639
640 // add settings fields
641 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')
642 add_settings_field( 'jetpack_mc_development_mode', __('Development Mode','jetpack-module-control'), array($this, 'development_mode_settings'), $settings, 'jetpack-module-control' ); // array('label_for' => 'elementid')
643 add_settings_field( 'jetpack_mc_blacklist', __('Blacklist Modules','jetpack-module-control'), array($this, 'blacklist_settings'), $settings, 'jetpack-module-control' );
644 }
645
646 }
647
648 /**
649 * Saves the network settings
650 *
651 * @since 0.2
652 */
653 public function save_network_settings() {
654
655 $posted_settings = array(
656 'jetpack_mc_manual_control' => '',
657 'jetpack_mc_development_mode' => '',
658 'jetpack_mc_blacklist' => '',
659 'jetpack_mc_subsite_override' => ''
660 );
661
662 isset( $_POST['jetpack_mc_subsite_override'] ) && $posted_settings['jetpack_mc_subsite_override'] = '1';
663
664 isset( $_POST['jetpack_mc_manual_control'] ) && $posted_settings['jetpack_mc_manual_control'] = '1';
665
666 isset( $_POST['jetpack_mc_development_mode'] ) && $posted_settings['jetpack_mc_development_mode'] = '1';
667
668 isset( $_POST['jetpack_mc_blacklist'] ) && is_array( $_POST['jetpack_mc_blacklist'] ) && $posted_settings['jetpack_mc_blacklist'] = array_values( $_POST['jetpack_mc_blacklist'] );
669
670 foreach( $posted_settings as $name => $value ) {
671 update_site_option( $name, $value );
672 }
673
674 }
675
676 /**
677 * Prints the network settings
678 *
679 * @since 0.2
680 */
681 public function show_network_settings() {
682 ?>
683 <h3><a name="jetpack-mc"></a><?php _e('Jetpack Module Control','jetpack-module-control'); ?></h3>
684 <?php
685 $this->add_settings_section('');
686 ?>
687 <table class="form-table">
688 <tbody>
689 <tr>
690 <th scope="row"><?php _e('Sub-site Override','jetpack-module-control'); ?></th>
691 <td>
692 <?php
693 $this->subsite_override_settings();
694 ?>
695 </td>
696 </tr>
697
698 <tr>
699 <th scope="row"><?php _e('Manual Control','jetpack-module-control'); ?></th>
700 <td>
701 <?php
702 $this->manual_control_settings();
703 ?>
704 </td>
705 </tr>
706 <tr>
707 <th scope="row"><?php _e('Development Mode','jetpack-module-control'); ?></th>
708 <td>
709 <?php
710 $this->development_mode_settings();
711 ?>
712 </td>
713 </tr>
714 <tr>
715 <th scope="row"><?php _e('Blacklist Modules','jetpack-module-control'); ?></th>
716 <td>
717 <?php
718 $this->blacklist_settings();
719 ?>
720 </td>
721 </tr>
722 </tbody>
723 </table>
724 <?php
725 }
726
727 /**
728 * Echos a settings section header
729 *
730 * @since 0.1
731 *
732 * @param $option (unused)
733 * @echo Html
734 */
735 public function add_settings_section( $option ) {
736 echo '<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=Jetpack%20Module%20Control&item_number='
737 . $this->version
738 . '&no_shipping=0&tax=0&charset=UTF%2d8&currency_code=EUR" title="'
739 . __('Donate to keep plugin development going!','jetpack-module-control')
740 . '" 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="'
741 . __('Donate to keep plugin development going!','jetpack-module-control') . '" width="92" height="26" /></a>'
742 . sprintf(__('The options in this section are provided by %s.','jetpack-module-control'),'<strong><a href="http://status301.net/wordpress-plugins/jetpack-module-control/">'
743 . __('Jetpack Module Control','jetpack-module-control') . ' ' . $this->version . '</a></strong>') . ' '
744 . __('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') . ' ';
745
746 if ( !is_multisite() )
747 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>');
748 else if ( is_network_admin() )
749 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>';
750
751 echo '</p>';
752 }
753
754 /**
755 * Adds an action link on the Plugins page
756 *
757 * @since 0.1
758 * @see is_plugin_active_for_network(), admin_url(), network_admin_url()
759 *
760 * @param array $links Plugin de/activation and deletion links
761 * @return array Plugin links plus Settings link
762 */
763 public function add_action_link( $links ) {
764 $settings_link = is_plugin_active_for_network( $this->plugin_basename() ) ?
765 '<a href="' . network_admin_url('settings.php#jetpack-mc') . '">' . translate('Network Settings') . '</a>' :
766 '<a href="' . admin_url('options-general.php#jetpack-mc') . '">' . translate('Settings') . '</a>';
767 return array_merge(
768 array( 'settings' => $settings_link ),
769 $links
770 );
771 return $links;
772 }
773
774 /**
775 * Routines to execute on plugins_loaded
776 *
777 * https://github.com/Automattic/jetpack/pull/2027 >> request accepted and fixed
778 *
779 * @since 0.1
780 */
781 public function plugins_loaded() {
782 global $pagenow;
783
784 // only need translations on admin page
785 if ( is_admin() ) {
786 load_plugin_textdomain( 'jetpack-module-control', false, dirname( $this->plugin_basename() ) . '/languages/' );
787 }
788
789 add_filter( 'jetpack_get_default_modules', array( $this, 'manual_control' ), 99 );
790 add_filter( 'jetpack_development_mode', array( $this, 'development_mode' ) );
791 add_filter( 'jetpack_get_available_modules', array( $this, 'blacklist' ) );
792 }
793
794 /**
795 * Getter method for retrieving single object instance.
796 *
797 * @since 0.1
798 *
799 * @return Jetpack_Module_Control|null instance object
800 */
801 public static function instance() {
802 if(is_null(self::$instance)) {
803 self::$instance = new self();
804 }
805 return self::$instance;
806 }
807
808 /**
809 * Constructor
810 *
811 * @since 0.1
812 */
813 private function __construct() {
814 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 0 );
815 add_action( 'admin_init', array($this,'admin_init'), 11 );
816 }
817
818 /**
819 * Cloning
820 *
821 * @since 0.1
822 */
823 private function __clone() { }
824
825 }
826
827 Jetpack_Module_Control::instance();
828