mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
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
This commit is contained in:
parent
8f08a8e2e1
commit
789d1d9c2e
@ -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.
|
||||
*
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user