PluginProbe
Module Control for Jetpack / 1.4
Module Control for Jetpack v1.4
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.4, at jetpack-module-control.php

747 lines 24.7 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-mc
10 * Domain Path: /languages/
11 * License: GPL2+
12 * Version: 1.4
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.4';
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
226 private function get_available_modules() {
227 // TODO : consider removing connection dependent modules when 'jetpack_mc_development_mode' is ON
228
229 if ( null === self::$modules ) {
230 if ( class_exists('Jetpack') ) {
231 remove_filter( 'jetpack_get_available_modules', array($this, 'blacklist') );
232 $modules = array();
233 foreach ( Jetpack::get_available_modules() as $slug ) {
234 $module = Jetpack::get_module( $slug );
235 if ( $module )
236 $modules[$slug] = $module;
237 }
238 self::$modules = $modules;
239 add_filter( 'jetpack_get_available_modules', array($this, 'blacklist') );
240 } else {
241 self::$modules = self::$known_modules;
242 }
243 }
244 return self::$modules;
245 }
246
247 /**
248 * Return plugin basename
249 *
250 * @since 0.1
251 *
252 * @return string Plugin basename
253 */
254
255 private function plugin_basename() {
256 if ( null === self::$plugin_basename ) {
257 self::$plugin_basename = plugin_basename( __FILE__ );
258 }
259 return self::$plugin_basename;
260 }
261
262 /**
263 * MANUAL CONTROL
264 */
265
266 /**
267 * Adds the Manual Control option
268 *
269 * @since 0.1
270 * @see get_site_option(), checked(), disabled()
271 *
272 * @uses jetpack_mc_manual_control network option
273 * @echo Html Checkbox input field for jetpack_mc_manual_control option
274 * @return void
275 */
276
277 public function manual_control_settings() {
278
279 if ( is_network_admin() ) {
280 // we're in network admin: retrieve network settings
281 $disabled = is_plugin_active_for_network('manual-control/manual-control.php');
282 $option = $disabled ? '1' : get_site_option('jetpack_mc_manual_control');
283 } else {
284 // we're in site admin
285 if ( is_plugin_active('manual-control/manual-control.php') ) {
286 $option = '1';
287 $disabled = true;
288 } else {
289 // retrieve site setting
290 $option = get_option('jetpack_mc_manual_control');
291 // fall back on network settings
292 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_manual_control');
293 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;
294 }
295 }
296
297 ?>
298 <label>
299 <input type='checkbox' name='jetpack_mc_manual_control' value='1'
300 <?php checked( $option, '1' ); ?>
301 <?php disabled( $disabled ); ?>>
302 <?php _e('Prevent Jetpack from auto-activating (new) modules','jetpack-mc'); ?>
303 </label>
304 <p class="description"><?php echo sprintf( __('Note: The module %s is excepted from this rule.','jetpack-mc'), _x('Protect','Module Name','jetpack') ); ?></p>
305 <?php
306
307 } // END manual_control_settings()
308
309 /**
310 * Activates Manual Control by returning an empty array on module auto-activation.
311 * First modelled after Manual Control for Jetpack by Mark Jaquith http://coveredwebservices.com/
312 * To be converted to allow selected modules instead of all or none.
313 *
314 * @since 0.1
315 * @see add_filter()
316 */
317
318 public function manual_control( $modules ) {
319
320 $option = get_option('jetpack_mc_manual_control');
321 // if false, fall back on network settings
322 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_manual_control');
323
324 return !empty($option) ? array() : $modules;
325
326 } // END manual_control()
327
328 /**
329 * DEVELOPMENT MODE
330 */
331
332 /**
333 * Adds the Jetpack Without WordPress.com option
334 *
335 * @since 1.0
336 * @see get_site_option(), checked(), disabled()
337 *
338 * @echo Html Checkbox input field for jetpack_mc_development_mode option
339 * @return void
340 */
341
342 public function development_mode_settings() {
343
344 if ( is_network_admin() ) {
345 // we're in network admin
346 if ( is_plugin_active_for_network('slimjetpack/slimjetpack.php') || is_plugin_active_for_network('unplug-jetpack/unplug-jetpack.php') ) {
347 $option = '1';
348 $disabled = true;
349 } else {
350 // retrieve network settings
351 $option = get_site_option('jetpack_mc_development_mode');
352 $disabled = false;
353 }
354 } else {
355 // we're in site admin
356 if ( is_plugin_active('slimjetpack/slimjetpack.php') || is_plugin_active('unplug-jetpack/unplug-jetpack.php') ) {
357 $option = '1';
358 $disabled = true;
359 } else {
360 //retrieve site setting
361 $option = get_option('jetpack_mc_development_mode');
362 // fall back on network settings
363 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_development_mode');
364 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;
365 }
366 }
367
368 ?>
369 <label>
370 <input type='checkbox' name='jetpack_mc_development_mode' value='1'
371 <?php checked( $option, '1' ); ?>
372 <?php disabled( $disabled ); ?>>
373 <?php _e('Use Jetpack modules without a WordPress.com connection','jetpack-mc'); ?>
374 </label>
375 <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-mc'); ?></p>
376 <?php
377
378 } // END development_mode_settings()
379
380 /**
381 * Activates Development Mode by returning true on jetpack_development_mode filter.
382 * Based on http://jeremy.hu/customize-the-list-of-modules-available-in-jetpack/
383 *
384 * @since 1.0
385 * @see add_filter()
386 */
387
388 public function development_mode() {
389
390 $option = get_option('jetpack_mc_development_mode');
391 // if false, fall back on network settings
392 if ( $option === false && is_multisite() ) $option = get_site_option('jetpack_mc_development_mode');
393
394 return !empty($option) ? true : false;
395
396 } // END development_mode()
397
398 /**
399 * ADMIN NOTICES
400 */
401
402 /**
403 * Disables Centralized Site Management banner by returning false on can_display_jetpack_manage_notice filter.
404 *
405 * @since 0.1
406 * @see add_filter()
407 */
408
409 private function no_manage_notice() {
410
411 $blacklist = get_option('jetpack_mc_blacklist');
412
413 // fall back on network setting
414 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist');
415
416 if ( is_array( $blacklist ) && in_array( 'manage', $blacklist ) )
417 add_filter( 'can_display_jetpack_manage_notice', '__return_false' );
418
419 } // END no_manage_notice()
420
421 /**
422 * Disables Centralized Site Management banner by removing show_development_mode_notice from jetpack_notices actions.
423 *
424 * @since 0.1
425 * @see add_filter()
426 */
427 private function no_dev_notice() {
428
429 if ( class_exists('Jetpack') && ( get_option('jetpack_mc_development_mode') || get_site_option('jetpack_mc_development_mode') ) )
430 remove_action( 'jetpack_notices', array( Jetpack::init(), 'show_development_mode_notice' ) );
431
432 } // END no_dev_notice()
433
434 /**
435 * BLACKLIST
436 */
437
438 /**
439 * Adds a checkmark list of modules to blacklist
440 *
441 * @since 0.1
442 * @see get_site_option(), checked()
443 *
444 * @uses jetpack_mc_blacklist network option
445 * @echo Html Checkbox input field table for jetpack_mc_blacklist option
446 */
447
448 public function blacklist_settings() {
449
450 if ( is_network_admin() ) {
451 // in network admin retrieve network settings
452 $blacklist = get_site_option( 'jetpack_mc_blacklist', array() );
453 $disabled = false;
454 } else {
455 // in site admin retrieve site settings
456 $blacklist = get_option( 'jetpack_mc_blacklist' );
457 // fall back on network setting
458 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist');
459 $disabled = defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ? true : false;
460 }
461
462 // blacklist must be an array, if anything else then just make it an empty array
463 if ( !is_array($blacklist) ) $blacklist = array();
464
465 $modules = $this->get_available_modules();
466 asort($modules);
467
468 $icons = self::$known_modules_icons;
469
470 ?>
471 <fieldset><legend class="screen-reader-text"><span><?php _e('Blacklist Modules','jetpack-mc'); ?></span></legend>
472 <?php
473 foreach ( $modules as $slug => $module ) {
474 $icon = isset($icons[$slug]) ? $icons[$slug] : self::$default_icon;
475 ?>
476 <label>
477 <input type='checkbox' name='jetpack_mc_blacklist[]' value='<?php echo $slug; ?>'
478 <?php checked( in_array( $slug, $blacklist ), true ); ?>
479 <?php disabled( $disabled ); ?>>
480 <span class="dashicons dashicons-<?php echo $icon; ?>"></span> <?php _ex( $module['name'], 'Module Name', 'jetpack' ) ?>
481 </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-mc') . '">*</a>' : ''; ?><br>
482 <?php
483 }
484 ?>
485 <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-mc'); ?></p></aside>
486 </fieldset>
487 <?php
488
489 } // END blacklist_settings()
490
491 /**
492 * Blacklist Jetpack modules
493 * Modelled after ParhamG's blacklist_jetpack_modules.php https://gist.github.com/ParhamG/6494979
494 *
495 * @since 0.1
496 * @param $modules
497 *
498 * @return Array Allowed modules after unsetting blacklisted modules from all modules array
499 */
500
501 public function blacklist ( $modules ) {
502
503 $blacklist = get_option('jetpack_mc_blacklist');
504
505 // fall back on network setting
506 if ( $blacklist === false && is_multisite() ) $blacklist = get_site_option('jetpack_mc_blacklist');
507
508 foreach ( (array)$blacklist as $mod )
509 if ( isset( $modules[$mod] ) )
510 unset( $modules[$mod] );
511
512 return $modules;
513
514 } // END blacklist()
515
516 /**
517 * ADMIN
518 */
519
520 /**
521 * Initiate plugins admin stuff
522 *
523 * @since 0.1
524 */
525
526 public function admin_init(){
527
528 $this->no_manage_notice();
529
530 $this->no_dev_notice();
531
532 if ( is_plugin_active_for_network( $this->plugin_basename() ) ) {
533 // Check for network activation, else these will also take effect when
534 // plugin is activated on the primary site alone.
535 // TODO : see if you can actually use this scenario where plugin is activatied on site 1 and
536 // network options can be set to serve as default settings for other site activations !
537
538 // Add settings to Network Settings
539 // thanks to http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/
540 add_filter( 'wpmu_options', array( $this, 'show_network_settings' ) );
541 add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) );
542
543 // Plugin action links
544 add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename(), array($this, 'add_action_link') );
545 }
546
547 // Plugin action links
548 add_filter( 'plugin_action_links_' . $this->plugin_basename(), array($this, 'add_action_link') );
549
550 // Do regular register/add_settings stuff in 'general' settings on options-general.php
551 $settings = 'general';
552
553 add_settings_section('jetpack-mc', '<a name="jetpack-mc"></a>' . __('Jetpack Module Control','jetpack-mc'), array($this, 'add_settings_section'), $settings);
554
555 // register settings
556 if ( defined('JETPACK_MC_LOCKDOWN') && JETPACK_MC_LOCKDOWN ) {
557 // do not register site settings to prevent them being updated
558 } else {
559 register_setting( $settings, 'jetpack_mc_manual_control' ); // sanitize_callback 'boolval' ?
560 register_setting( $settings, 'jetpack_mc_development_mode' ); // sanitize_callback 'boolval' ?
561 register_setting( $settings, 'jetpack_mc_blacklist', 'array_values' );
562 }
563
564 // add settings fields
565 add_settings_field( 'jetpack_mc_manual_control', __('Manual Control','jetpack-mc'), array($this, 'manual_control_settings'), $settings, 'jetpack-mc' ); // array('label_for' => 'elementid')
566 add_settings_field( 'jetpack_mc_development_mode', __('Development Mode','jetpack-mc'), array($this, 'development_mode_settings'), $settings, 'jetpack-mc' ); // array('label_for' => 'elementid')
567 add_settings_field( 'jetpack_mc_blacklist', __('Blacklist Modules','jetpack-mc'), array($this, 'blacklist_settings'), $settings, 'jetpack-mc' );
568
569 }
570
571 /**
572 * Saves the network settings
573 *
574 * @since 0.2
575 */
576 public function save_network_settings() {
577
578 $posted_settings = array(
579 'jetpack_mc_manual_control' => '',
580 'jetpack_mc_development_mode' => '',
581 'jetpack_mc_blacklist' => ''
582 );
583
584 isset( $_POST['jetpack_mc_manual_control'] ) && $posted_settings['jetpack_mc_manual_control'] = '1';
585
586 isset( $_POST['jetpack_mc_development_mode'] ) && $posted_settings['jetpack_mc_development_mode'] = '1';
587
588 isset( $_POST['jetpack_mc_blacklist'] ) && is_array( $_POST['jetpack_mc_blacklist'] ) && $posted_settings['jetpack_mc_blacklist'] = array_values( $_POST['jetpack_mc_blacklist'] );
589
590 foreach( $posted_settings as $name => $value )
591 update_site_option( $name, $value );
592
593 }
594
595 /**
596 * Prints the network settings
597 *
598 * @since 0.2
599 */
600 public function show_network_settings() {
601
602 ?>
603 <h3><a name="jetpack-mc"></a><?php _e('Jetpack Module Control','jetpack-mc'); ?></h3>
604 <?php
605 $this->add_settings_section('');
606 ?>
607 <table class="form-table">
608 <tbody>
609 <tr>
610 <th scope="row"><?php _e('Manual Control','jetpack-mc'); ?></th>
611 <td>
612 <?php
613 $this->manual_control_settings();
614 ?>
615 </td>
616 </tr>
617 <tr>
618 <th scope="row"><?php _e('Development Mode','jetpack-mc'); ?></th>
619 <td>
620 <?php
621 $this->development_mode_settings();
622 ?>
623 </td>
624 </tr>
625 <tr>
626 <th scope="row"><?php _e('Blacklist Modules','jetpack-mc'); ?></th>
627 <td>
628 <?php
629 $this->blacklist_settings();
630 ?>
631 </td>
632 </tr>
633 </tbody>
634 </table>
635 <?php
636 }
637
638 /**
639 * Echos a settings section header
640 *
641 * @since 0.1
642 *
643 * @param $option (unused)
644 * @echo Html
645 */
646 public function add_settings_section( $option ) {
647 echo '<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=Jetpack%20Module%20Control&item_number='
648 . $this->version
649 . '&no_shipping=0&tax=0&charset=UTF%2d8&currency_code=EUR" title="'
650 . __('Donate to keep plugin development going!','jetpack-mc')
651 . '" 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="'
652 . __('Donate to keep plugin development going!','jetpack-mc') . '" width="92" height="26" /></a>'
653 . sprintf(__('The options in this section are provided by %s.','jetpack-mc'),'<strong><a href="http://status301.net/wordpress-plugins/jetpack-module-control/">'
654 . __('Jetpack Module Control','jetpack-mc') . ' ' . $this->version . '</a></strong>') . ' '
655 . __('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-mc') . ' ';
656
657 if ( !is_multisite() )
658 echo sprintf(__('These settings can be locked down by adding %s to your wp-config.php file.','jetpack-mc'),'<code>define(\'JETPACK_MC_LOCKDOWN\', true);</code>');
659 else if ( !is_network_admin() )
660 echo '<br><em>' . __('These settings are only visible to you as Super Admin and allow overriding the network settings on this site only.','jetpack-mc') . '</em>';
661
662 echo '</p>';
663
664 } // END add_setting_section()
665
666 /**
667 * Adds an action link on the Plugins page
668 *
669 * @since 0.1
670 * @see is_plugin_active_for_network(), admin_url(), network_admin_url()
671 *
672 * @param array $links Plugin de/activation and deletion links
673 * @return array Plugin links plus Settings link
674 */
675 public function add_action_link( $links ) {
676 $settings_link = is_plugin_active_for_network( $this->plugin_basename() ) ?
677 '<a href="' . network_admin_url('settings.php#jetpack-mc') . '">' . translate('Network Settings') . '</a>' :
678 '<a href="' . admin_url('options-general.php#jetpack-mc') . '">' . translate('Settings') . '</a>';
679 return array_merge(
680 array( 'settings' => $settings_link ),
681 $links
682 );
683 return $links;
684 }
685
686 /**
687 * Routines to execute on plugins_loaded
688 *
689 * We need to add our jetpack_get_available_modules filter
690 * AFTER running get_available_modules() because of bug in Jetpack
691 * https://github.com/Automattic/jetpack/issues/2026
692 * https://github.com/Automattic/jetpack/pull/2027 >> request accepted and fixed
693 *
694 * @since 0.1
695 */
696 public function plugins_loaded() {
697 global $pagenow;
698
699 // only need translations on admin page
700 if ( is_admin() ) {
701 load_plugin_textdomain( 'jetpack-mc', false, dirname( $this->plugin_basename() ) . '/languages/' );
702
703 // populate jetpack modules list before filter is added
704 /* if ( in_array( $pagenow, array( 'options-general.php', 'settings.php' ) ) )
705 $this->get_available_modules();*/
706 }
707
708 add_filter( 'jetpack_get_default_modules', array( $this, 'manual_control' ), 99 );
709 add_filter( 'jetpack_development_mode', array( $this, 'development_mode' ) );
710 add_filter( 'jetpack_get_available_modules', array( $this, 'blacklist' ) );
711 }
712
713 /**
714 * Getter method for retrieving single object instance.
715 *
716 * @since 0.1
717 *
718 * @return Jetpack_Module_Control|null instance object
719 */
720 public static function instance() {
721 if(is_null(self::$instance)) {
722 self::$instance = new self();
723 }
724 return self::$instance;
725 } // End instance ()
726
727 /**
728 * Constructor
729 *
730 * @since 0.1
731 */
732 private function __construct() {
733 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 0 );
734 add_action( 'admin_init', array($this,'admin_init'), 11 );
735 }
736
737 /**
738 * Cloning
739 *
740 * @since 0.1
741 */
742 private function __clone() { }
743
744 }
745
746 Jetpack_Module_Control::instance();
747