= (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ); self::$current_blog_id = get_current_blog_id(); } return true; } /** * Called once to configure this class after plugins_loaded. * * @return void */ public static function configure() { if ( self::$configured ) { return; } if ( is_multisite() ) { self::$current_blog_id = get_current_blog_id(); } // If a plugin was activated or deactivated. $number_of_plugins_differ = count( self::$plugins ) !== count( (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ) ); if ( $number_of_plugins_differ || true === self::$refresh_connected_plugins ) { self::update_active_plugins_option(); } self::$configured = true; } /** * Updates the active plugins option with current list of active plugins. * * @return void */ public static function update_active_plugins_option() { // Note: Since this options is synced to wpcom, if you change its structure, you have to update the sanitizer at wpcom side. update_option( self::ACTIVE_PLUGINS_OPTION_NAME, self::$plugins ); } /** * Add the plugin to the set of disconnected ones. * * @param string $slug Plugin slug. * * @return bool */ public static function disable_plugin( $slug ) { $disconnects = self::get_all_disabled_plugins(); if ( ! in_array( $slug, $disconnects, true ) ) { $disconnects[] = $slug; update_option( self::PLUGINS_DISABLED_OPTION_NAME, $disconnects ); } return true; } /** * Remove the plugin from the set of disconnected ones. * * @param string $slug Plugin slug. * * @return bool */ public static function enable_plugin( $slug ) { $disconnects = self::get_all_disabled_plugins(); $slug_index = array_search( $slug, $disconnects, true ); if ( false !== $slug_index ) { unset( $disconnects[ $slug_index ] ); update_option( self::PLUGINS_DISABLED_OPTION_NAME, $disconnects ); } return true; } /** * Get all plugins that were disconnected by user. * * @return array */ public static function get_all_disabled_plugins() { return (array) get_option( self::PLUGINS_DISABLED_OPTION_NAME, array() ); } }