Quantcast
Channel: Support – Jetpack
Viewing all articles
Browse latest Browse all 371

Module Overrides

$
0
0

Jetpack has A LOT of functionality which is divided into modules. By default, modules are controlled by the Jetpack user interface (UI). When a module is forced on or off, the toggle in the Jetpack user interface for that module becomes disabled. When a module is completely removed, no UI will show for that module.

How are modules disabled?

In cases where Jetpack has a feature that is incompatible on a hosting platform, plugin, or theme, it may be preferable to disable the module in Jetpack. This is easily done via a filter in Jetpack, however, we would caution developers to consider the user experience (UX) when disabling functionality.

For example, if a user expects a commonly used module to be available, and it’s not, that could cause confusion for the user.

Now that we’ve covered that, let’s look at how we can disable Jetpack modules.

Disable module with popover explanation

To disable a module but not remove the UI, we’ll use the jetpack_active_modules filter.

Here’s an example:

add_filter( 'option_jetpack_active_modules', 'jetpack_test_module_override' );
function jetpack_test_module_override( $modules ) {
    $disabled_modules = array(
        'sitemaps',
        'sso',
    );

    foreach ( $disabled_modules as $module_slug ) {
        $found = array_search( $module_slug, $modules );
        if ( false !== $found ) {
            unset( $modules[ $found ] );
        }
    }
    
    return $modules;
}

Completely removing the module and its UI

The filter that we’ll use to disable a module and remove its UI is jetpack_get_available_modules.

Here’s an example:

add_filter( 'jetpack_get_available_modules', 'jetpack_docs_filter_module_example' );
function jetpack_docs_filter_module_example( $modules ) {
    if( isset( $modules['photon'] ) ) {
        unset( $modules['photon'] );
    }

    return $modules;
}

Forcing modules to be active

In some cases, forcing a module to be active may be preferable. For example, to minimize bandwidth, a developer could force the Photon module to be active. In these cases, it is possible to force a module on with the jetpack_active_modules filter.

Here’s an example:

add_filter( 'option_jetpack_active_modules', 'jetpack_docs_filter_active_modules' );
function jetpack_docs_filter_active_modules( $modules ) {
    return array_values( array_merge( $modules, array( 'photon' ) ) );
}

Who is overriding my modules?

Because of how WordPress filters work, any plugin or theme could be modifying the modules that are available and/or active. A few methods for finding where the modules are being overridden are:

  1. Change your theme then refresh the Jetpack UI
  2. Disable plugins one-by-one, refreshing the Jetpack UI each time
  3. Download the wp-content directory of your site via FTP or SFTP and then search for jetpack_active_modules or jetpack_get_available_modules in the directory

Viewing all articles
Browse latest Browse all 371

Trending Articles