Skip to content

Commit daad863

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59479 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6383964 commit daad863

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

src/wp-admin/includes/plugin.php

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -304,97 +304,6 @@ function _get_dropins() {
304304
return $dropins;
305305
}
306306

307-
/**
308-
* Determines whether a plugin is active.
309-
*
310-
* Only plugins installed in the plugins/ folder can be active.
311-
*
312-
* Plugins in the mu-plugins/ folder can't be "activated," so this function will
313-
* return false for those plugins.
314-
*
315-
* For more information on this and similar theme functions, check out
316-
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
317-
* Conditional Tags} article in the Theme Developer Handbook.
318-
*
319-
* @since 2.5.0
320-
*
321-
* @param string $plugin Path to the plugin file relative to the plugins directory.
322-
* @return bool True, if in the active plugins list. False, not in the list.
323-
*/
324-
function is_plugin_active( $plugin ) {
325-
return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin );
326-
}
327-
328-
/**
329-
* Determines whether the plugin is inactive.
330-
*
331-
* Reverse of is_plugin_active(). Used as a callback.
332-
*
333-
* For more information on this and similar theme functions, check out
334-
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
335-
* Conditional Tags} article in the Theme Developer Handbook.
336-
*
337-
* @since 3.1.0
338-
*
339-
* @see is_plugin_active()
340-
*
341-
* @param string $plugin Path to the plugin file relative to the plugins directory.
342-
* @return bool True if inactive. False if active.
343-
*/
344-
function is_plugin_inactive( $plugin ) {
345-
return ! is_plugin_active( $plugin );
346-
}
347-
348-
/**
349-
* Determines whether the plugin is active for the entire network.
350-
*
351-
* Only plugins installed in the plugins/ folder can be active.
352-
*
353-
* Plugins in the mu-plugins/ folder can't be "activated," so this function will
354-
* return false for those plugins.
355-
*
356-
* For more information on this and similar theme functions, check out
357-
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
358-
* Conditional Tags} article in the Theme Developer Handbook.
359-
*
360-
* @since 3.0.0
361-
*
362-
* @param string $plugin Path to the plugin file relative to the plugins directory.
363-
* @return bool True if active for the network, otherwise false.
364-
*/
365-
function is_plugin_active_for_network( $plugin ) {
366-
if ( ! is_multisite() ) {
367-
return false;
368-
}
369-
370-
$plugins = get_site_option( 'active_sitewide_plugins' );
371-
if ( isset( $plugins[ $plugin ] ) ) {
372-
return true;
373-
}
374-
375-
return false;
376-
}
377-
378-
/**
379-
* Checks for "Network: true" in the plugin header to see if this should
380-
* be activated only as a network wide plugin. The plugin would also work
381-
* when Multisite is not enabled.
382-
*
383-
* Checks for "Site Wide Only: true" for backward compatibility.
384-
*
385-
* @since 3.0.0
386-
*
387-
* @param string $plugin Path to the plugin file relative to the plugins directory.
388-
* @return bool True if plugin is network only, false otherwise.
389-
*/
390-
function is_network_only_plugin( $plugin ) {
391-
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
392-
if ( $plugin_data ) {
393-
return $plugin_data['Network'];
394-
}
395-
return false;
396-
}
397-
398307
/**
399308
* Attempts activation of plugin in a "sandbox" and redirects on success.
400309
*

src/wp-includes/functions.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7145,6 +7145,97 @@ function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup
71457145
return $plugin_data;
71467146
}
71477147

7148+
/**
7149+
* Determines whether a plugin is active.
7150+
*
7151+
* Only plugins installed in the plugins/ folder can be active.
7152+
*
7153+
* Plugins in the mu-plugins/ folder can't be "activated," so this function will
7154+
* return false for those plugins.
7155+
*
7156+
* For more information on this and similar theme functions, check out
7157+
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
7158+
* Conditional Tags} article in the Theme Developer Handbook.
7159+
*
7160+
* @since 2.5.0
7161+
*
7162+
* @param string $plugin Path to the plugin file relative to the plugins directory.
7163+
* @return bool True, if in the active plugins list. False, not in the list.
7164+
*/
7165+
function is_plugin_active( $plugin ) {
7166+
return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin );
7167+
}
7168+
7169+
/**
7170+
* Determines whether the plugin is inactive.
7171+
*
7172+
* Reverse of is_plugin_active(). Used as a callback.
7173+
*
7174+
* For more information on this and similar theme functions, check out
7175+
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
7176+
* Conditional Tags} article in the Theme Developer Handbook.
7177+
*
7178+
* @since 3.1.0
7179+
*
7180+
* @see is_plugin_active()
7181+
*
7182+
* @param string $plugin Path to the plugin file relative to the plugins directory.
7183+
* @return bool True if inactive. False if active.
7184+
*/
7185+
function is_plugin_inactive( $plugin ) {
7186+
return ! is_plugin_active( $plugin );
7187+
}
7188+
7189+
/**
7190+
* Determines whether the plugin is active for the entire network.
7191+
*
7192+
* Only plugins installed in the plugins/ folder can be active.
7193+
*
7194+
* Plugins in the mu-plugins/ folder can't be "activated," so this function will
7195+
* return false for those plugins.
7196+
*
7197+
* For more information on this and similar theme functions, check out
7198+
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
7199+
* Conditional Tags} article in the Theme Developer Handbook.
7200+
*
7201+
* @since 3.0.0
7202+
*
7203+
* @param string $plugin Path to the plugin file relative to the plugins directory.
7204+
* @return bool True if active for the network, otherwise false.
7205+
*/
7206+
function is_plugin_active_for_network( $plugin ) {
7207+
if ( ! is_multisite() ) {
7208+
return false;
7209+
}
7210+
7211+
$plugins = get_site_option( 'active_sitewide_plugins' );
7212+
if ( isset( $plugins[ $plugin ] ) ) {
7213+
return true;
7214+
}
7215+
7216+
return false;
7217+
}
7218+
7219+
/**
7220+
* Checks for "Network: true" in the plugin header to see if this should
7221+
* be activated only as a network wide plugin. The plugin would also work
7222+
* when Multisite is not enabled.
7223+
*
7224+
* Checks for "Site Wide Only: true" for backward compatibility.
7225+
*
7226+
* @since 3.0.0
7227+
*
7228+
* @param string $plugin Path to the plugin file relative to the plugins directory.
7229+
* @return bool True if plugin is network only, false otherwise.
7230+
*/
7231+
function is_network_only_plugin( $plugin ) {
7232+
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
7233+
if ( $plugin_data ) {
7234+
return $plugin_data['Network'];
7235+
}
7236+
return false;
7237+
}
7238+
71487239
/**
71497240
* Returns true.
71507241
*

0 commit comments

Comments
 (0)