Jetpack::activate_module PHP Method

activate_module() public static method

public static activate_module ( $module, $exit = true, $redirect = true )
    public static function activate_module($module, $exit = true, $redirect = true)
    {
        /**
         * Fires before a module is activated.
         *
         * @since 2.6.0
         *
         * @param string $module Module slug.
         * @param bool $exit Should we exit after the module has been activated. Default to true.
         * @param bool $redirect Should the user be redirected after module activation? Default to true.
         */
        do_action('jetpack_pre_activate_module', $module, $exit, $redirect);
        $jetpack = Jetpack::init();
        if (!strlen($module)) {
            return false;
        }
        if (!Jetpack::is_module($module)) {
            return false;
        }
        // If it's already active, then don't do it again
        $active = Jetpack::get_active_modules();
        foreach ($active as $act) {
            if ($act == $module) {
                return true;
            }
        }
        $module_data = Jetpack::get_module($module);
        if (!Jetpack::is_active()) {
            if (!Jetpack::is_development_mode()) {
                return false;
            }
            // If we're not connected but in development mode, make sure the module doesn't require a connection
            if (Jetpack::is_development_mode() && $module_data['requires_connection']) {
                return false;
            }
        }
        // Check and see if the old plugin is active
        if (isset($jetpack->plugins_to_deactivate[$module])) {
            // Deactivate the old plugin
            if (Jetpack_Client_Server::deactivate_plugin($jetpack->plugins_to_deactivate[$module][0], $jetpack->plugins_to_deactivate[$module][1])) {
                // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module
                // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load.
                Jetpack::state('deactivated_plugins', $module);
                wp_safe_redirect(add_query_arg('jetpack_restate', 1));
                exit;
            }
        }
        // Check the file for fatal errors, a la wp-admin/plugins.php::activate
        Jetpack::state('module', $module);
        Jetpack::state('error', 'module_activation_failed');
        // we'll override this later if the plugin can be included without fatal error
        Jetpack::catch_errors(true);
        ob_start();
        require Jetpack::get_module_path($module);
        /** This action is documented in class.jetpack.php */
        do_action('jetpack_activate_module', $module);
        $active[] = $module;
        Jetpack::update_active_modules($active);
        Jetpack::state('error', false);
        // the override
        ob_end_clean();
        Jetpack::catch_errors(false);
        // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet.
        if ('new_connection' === Jetpack_Options::get_option('jumpstart')) {
            Jetpack_Options::update_option('jumpstart', 'jetpack_action_taken');
            //Jump start is being dismissed send data to MC Stats
            $jetpack->stat('jumpstart', 'manual,' . $module);
            $jetpack->do_stats('server_side');
        }
        if ($redirect) {
            wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
        }
        if ($exit) {
            exit;
        }
        return true;
    }

Usage Example

コード例 #1
0
ファイル: jetpack.php プロジェクト: nicoandrade/Ocin-Lite
/**
 * Add theme support for Infinite Scroll.
 * See: https://jetpack.me/support/infinite-scroll/
 */
function ocin_lite_jetpack_setup()
{
    add_theme_support('infinite-scroll', array('container' => 'main', 'render' => 'ocin_lite_infinite_scroll_render', 'footer' => 'page'));
    //Enable Custom CSS
    if (class_exists('Jetpack')) {
        Jetpack::activate_module('custom-css', false, false);
    }
}
All Usage Examples Of Jetpack::activate_module
Jetpack