ic * @author Grégory Viguier * * @param int|null $value Option value. * @return int|null */ public function is_mobile_plugin_active_callback( $value ) { if ( static::is_mobile_plugin_active() ) { return 1; } return $value; } /** ----------------------------------------------------------------------------------------- */ /** MAIN HELPERS ============================================================================ */ /** ----------------------------------------------------------------------------------------- */ /** * Update the config file and the advanced cache file. * * @since 3.2 * @access public * @author Grégory Viguier */ public static function update_mobile_cache_activation() { // Reset class cache. static::reset_class_cache(); // Update the config file. rocket_generate_config_file(); // Update the advanced cache file. rocket_generate_advanced_cache_file(); // Flush htaccess file. flush_rocket_htaccess(); } /** * Reset `is_mobile_plugin_active()` cache. * * @since 3.2 * @access public * @author Grégory Viguier */ public static function reset_class_cache() { // Reset class cache. unset( static::$is_mobile_active[ get_current_network_id() ][ get_current_blog_id() ] ); } /** * Get the concerned plugins. * * @since 3.2 * @access public * @author Grégory Viguier * * @return array */ public static function get_mobile_plugins() { return [ 'jetpack/jetpack.php' => [ 'is_active_callback' => function () { if ( ! class_exists( 'Jetpack' ) ) { return false; } return \Jetpack::is_active() && \Jetpack::is_module_active( 'minileven' ); }, 'activation_hook' => 'jetpack_activate_module_minileven', 'deactivation_hook' => 'jetpack_deactivate_module_minileven', ], 'wptouch/wptouch.php' => [], 'wiziapp-create-your-own-native-iphone-app/wiziapp.php' => [], 'wordpress-mobile-pack/wordpress-mobile-pack.php' => [], 'wp-mobilizer/wp-mobilizer.php' => [], 'wp-mobile-edition/wp-mobile-edition.php' => [], 'device-theme-switcher/dts_controller.php' => [], 'wp-mobile-detect/wp-mobile-detect.php' => [], 'easy-social-share-buttons3/easy-social-share-buttons3.php' => [], 'jet-menu/jet-menu.php' => [], 'wpdiscuz/class.WpdiscuzCore.php' => [], ]; } /** * Tell if a mobile plugin is active. * * @since 3.2 * @access public * @author Grégory Viguier * * @return bool True if a mobile plugin in the list is active, false otherwise. */ public static function is_mobile_plugin_active() { $network_id = get_current_network_id(); $blog_id = get_current_blog_id(); if ( isset( static::$is_mobile_active[ $network_id ][ $blog_id ] ) ) { return static::$is_mobile_active[ $network_id ][ $blog_id ]; } if ( ! function_exists( '\is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( ! isset( static::$is_mobile_active[ $network_id ] ) ) { static::$is_mobile_active[ $network_id ] = []; } foreach ( static::get_mobile_plugins() as $mobile_plugin => $mobile_plugin_data ) { if ( \is_plugin_active( $mobile_plugin ) && isset( $mobile_plugin_data['is_active_callback'] ) && call_user_func( $mobile_plugin_data['is_active_callback'] ) ) { static::$is_mobile_active[ $network_id ][ $blog_id ] = true; return true; } if ( \is_plugin_active( $mobile_plugin ) && ! isset( $mobile_plugin_data['is_active_callback'] ) ) { static::$is_mobile_active[ $network_id ][ $blog_id ] = true; return true; } } static::$is_mobile_active[ $network_id ][ $blog_id ] = false; return false; } }