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

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