| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Module Control for Jetpack |
| 4 |
* Plugin URI: https://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: https://status301.net/ |
| 8 |
* Requires Plugins: jetpack |
| 9 |
* Network: true |
| 10 |
* Text Domain: jetpack-module-control |
| 11 |
* License: GPL2+ |
| 12 |
* Version: 1.7.2 |
| 13 |
* |
| 14 |
* @package Module Control for Jetpack |
| 15 |
*/ |
| 16 |
|
| 17 |
/* |
| 18 |
* ROADMAP |
| 19 |
* |
| 20 |
* version 2.0 |
| 21 |
* Replace "Prevent the Jetpack plugin from auto-activating (new) modules" with |
| 22 |
* finer grained "Select which modules to auto-activate" |
| 23 |
* see http://jeremy.hu/customize-the-list-of-modules-available-in-jetpack/ |
| 24 |
* function jeherve_auto_activate_stats() { |
| 25 |
return array( 'stats' ); |
| 26 |
} |
| 27 |
add_filter( 'jetpack_get_default_modules', 'jeherve_auto_activate_stats' ); |
| 28 |
* |
| 29 |
* TO CONSIDER |
| 30 |
* |
| 31 |
* Make blacklist or whitelist optional |
| 32 |
* |
| 33 |
* Option to disable JUMPSTART with "Jetpack_Options::update_option( 'jumpstart', 'jumpstart_dismissed' );" ?? |
| 34 |
* or do we need to go through apply_filters( 'jetpack_module_feature' ... |
| 35 |
* If we want to be able to select which modules should appear in Jumpstart later! |
| 36 |
* |
| 37 |
* Can we disable Debug link in the footer menu? |
| 38 |
* |
| 39 |
* Option to "force_deactivate" (same as blacklist?) as described on https://github.com/Automattic/jetpack/issues/1452 |
| 40 |
* |
| 41 |
*/ |
| 42 |
|
| 43 |
defined( 'WPINC' ) || die( 'No direct access allowed.' ); |
| 44 |
|
| 45 |
define( 'JMC_BASENAME', plugin_basename( __FILE__ ) ); |
| 46 |
|
| 47 |
add_filter( 'jetpack_get_default_modules', array( '\JMC\Plugin', 'manual_control' ), 99 ); |
| 48 |
add_filter( 'jetpack_offline_mode', array( '\JMC\Plugin', 'development_mode' ) ); |
| 49 |
add_filter( 'jetpack_get_available_modules', array( '\JMC\Plugin', 'blacklist' ) ); |
| 50 |
|
| 51 |
add_action( 'admin_init', array( '\JMC\Admin', 'init' ), 11 ); |
| 52 |
add_action( 'admin_menu', array( '\JMC\Admin', 'control_submenus' ), 1001 ); |
| 53 |
add_filter( 'wp_default_autoload_value', array( '\JMC\Admin', 'autoload_value' ), 10, 2 ); |
| 54 |
|
| 55 |
register_activation_hook( __FILE__, array( '\JMC\Admin', 'activate' ) ); |
| 56 |
register_deactivation_hook( __FILE__, array( '\JMC\Admin', 'deactivate' ) ); |
| 57 |
|
| 58 |
/** |
| 59 |
* Register JMC autoloader |
| 60 |
* http://justintadlock.com/archives/2018/12/14/php-namespaces-for-wordpress-developers |
| 61 |
* |
| 62 |
* @since 1.7 |
| 63 |
* |
| 64 |
* @param string $class_name Namespaced class name. |
| 65 |
*/ |
| 66 |
spl_autoload_register( |
| 67 |
function ( $class_name ) { |
| 68 |
// Bail if the class is not in our namespace. |
| 69 |
if ( 0 !== strpos( $class_name, 'JMC\\' ) ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
// Build the filename and path. |
| 74 |
$class_name = str_replace( 'JMC', 'inc', $class_name ); |
| 75 |
$class_name = strtolower( $class_name ); |
| 76 |
$path_array = explode( '\\', $class_name ); |
| 77 |
$class_name = array_pop( $path_array ); |
| 78 |
$class_name = str_replace( '_', '-', $class_name ); |
| 79 |
$file = realpath( __DIR__ ) . DIRECTORY_SEPARATOR . \implode( DIRECTORY_SEPARATOR, $path_array ) . DIRECTORY_SEPARATOR . 'class-' . $class_name . '.php'; |
| 80 |
|
| 81 |
// If the file exists for the class name, load it. |
| 82 |
if ( file_exists( $file ) ) { |
| 83 |
include_once $file; |
| 84 |
} |
| 85 |
} |
| 86 |
); |
| 87 |
|