From 789d1d9c2e9de0a82ab6bb59393c2a2dc829e11f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 2 Dec 2024 17:10:15 +0000 Subject: [PATCH] Plugins: Make more plugin-related functions available early on. This is a follow-up to [59461], which moved `get_plugin_data()` from `wp-admin/includes/plugin.php` to `wp-includes/functions.php` so it's available during the plugin loading process. Related functions like `is_plugin_active()` are often used together and should therefore be moved as well, to improve backward compatibility for plugins which load `wp-admin/includes/plugin.php` only conditionally. Props johnbillion, dd32, swissspidy. See #62244. Built from https://develop.svn.wordpress.org/trunk@59479 git-svn-id: http://core.svn.wordpress.org/trunk@58865 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 91 ------------------------------------ wp-includes/functions.php | 91 ++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 92 insertions(+), 92 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 0969f95657..977801d92b 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -304,97 +304,6 @@ function _get_dropins() { return $dropins; } -/** - * Determines whether a plugin is active. - * - * Only plugins installed in the plugins/ folder can be active. - * - * Plugins in the mu-plugins/ folder can't be "activated," so this function will - * return false for those plugins. - * - * For more information on this and similar theme functions, check out - * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ - * Conditional Tags} article in the Theme Developer Handbook. - * - * @since 2.5.0 - * - * @param string $plugin Path to the plugin file relative to the plugins directory. - * @return bool True, if in the active plugins list. False, not in the list. - */ -function is_plugin_active( $plugin ) { - return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin ); -} - -/** - * Determines whether the plugin is inactive. - * - * Reverse of is_plugin_active(). Used as a callback. - * - * For more information on this and similar theme functions, check out - * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ - * Conditional Tags} article in the Theme Developer Handbook. - * - * @since 3.1.0 - * - * @see is_plugin_active() - * - * @param string $plugin Path to the plugin file relative to the plugins directory. - * @return bool True if inactive. False if active. - */ -function is_plugin_inactive( $plugin ) { - return ! is_plugin_active( $plugin ); -} - -/** - * Determines whether the plugin is active for the entire network. - * - * Only plugins installed in the plugins/ folder can be active. - * - * Plugins in the mu-plugins/ folder can't be "activated," so this function will - * return false for those plugins. - * - * For more information on this and similar theme functions, check out - * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ - * Conditional Tags} article in the Theme Developer Handbook. - * - * @since 3.0.0 - * - * @param string $plugin Path to the plugin file relative to the plugins directory. - * @return bool True if active for the network, otherwise false. - */ -function is_plugin_active_for_network( $plugin ) { - if ( ! is_multisite() ) { - return false; - } - - $plugins = get_site_option( 'active_sitewide_plugins' ); - if ( isset( $plugins[ $plugin ] ) ) { - return true; - } - - return false; -} - -/** - * Checks for "Network: true" in the plugin header to see if this should - * be activated only as a network wide plugin. The plugin would also work - * when Multisite is not enabled. - * - * Checks for "Site Wide Only: true" for backward compatibility. - * - * @since 3.0.0 - * - * @param string $plugin Path to the plugin file relative to the plugins directory. - * @return bool True if plugin is network only, false otherwise. - */ -function is_network_only_plugin( $plugin ) { - $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); - if ( $plugin_data ) { - return $plugin_data['Network']; - } - return false; -} - /** * Attempts activation of plugin in a "sandbox" and redirects on success. * diff --git a/wp-includes/functions.php b/wp-includes/functions.php index dd0066cf3f..44f908a301 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7145,6 +7145,97 @@ function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup return $plugin_data; } +/** + * Determines whether a plugin is active. + * + * Only plugins installed in the plugins/ folder can be active. + * + * Plugins in the mu-plugins/ folder can't be "activated," so this function will + * return false for those plugins. + * + * For more information on this and similar theme functions, check out + * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ + * Conditional Tags} article in the Theme Developer Handbook. + * + * @since 2.5.0 + * + * @param string $plugin Path to the plugin file relative to the plugins directory. + * @return bool True, if in the active plugins list. False, not in the list. + */ +function is_plugin_active( $plugin ) { + return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin ); +} + +/** + * Determines whether the plugin is inactive. + * + * Reverse of is_plugin_active(). Used as a callback. + * + * For more information on this and similar theme functions, check out + * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ + * Conditional Tags} article in the Theme Developer Handbook. + * + * @since 3.1.0 + * + * @see is_plugin_active() + * + * @param string $plugin Path to the plugin file relative to the plugins directory. + * @return bool True if inactive. False if active. + */ +function is_plugin_inactive( $plugin ) { + return ! is_plugin_active( $plugin ); +} + +/** + * Determines whether the plugin is active for the entire network. + * + * Only plugins installed in the plugins/ folder can be active. + * + * Plugins in the mu-plugins/ folder can't be "activated," so this function will + * return false for those plugins. + * + * For more information on this and similar theme functions, check out + * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ + * Conditional Tags} article in the Theme Developer Handbook. + * + * @since 3.0.0 + * + * @param string $plugin Path to the plugin file relative to the plugins directory. + * @return bool True if active for the network, otherwise false. + */ +function is_plugin_active_for_network( $plugin ) { + if ( ! is_multisite() ) { + return false; + } + + $plugins = get_site_option( 'active_sitewide_plugins' ); + if ( isset( $plugins[ $plugin ] ) ) { + return true; + } + + return false; +} + +/** + * Checks for "Network: true" in the plugin header to see if this should + * be activated only as a network wide plugin. The plugin would also work + * when Multisite is not enabled. + * + * Checks for "Site Wide Only: true" for backward compatibility. + * + * @since 3.0.0 + * + * @param string $plugin Path to the plugin file relative to the plugins directory. + * @return bool True if plugin is network only, false otherwise. + */ +function is_network_only_plugin( $plugin ) { + $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); + if ( $plugin_data ) { + return $plugin_data['Network']; + } + return false; +} + /** * Returns true. * diff --git a/wp-includes/version.php b/wp-includes/version.php index d764881ec6..b60b68f349 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59478'; +$wp_version = '6.8-alpha-59479'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.