Make WordPress Core


Ignore:
Timestamp:
12/02/2024 05:08:19 PM (7 months ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/plugin.php

    r59461 r59479  
    303303
    304304    return $dropins;
    305 }
    306 
    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;
    396305}
    397306
Note: See TracChangeset for help on using the changeset viewer.