wp_get_active_and_valid_plugins

Retrieve an array of active and valid plugin files.

Description

(array) wp_get_active_and_valid_plugins(); 

While upgrading or installing WordPress, no plugins are returned.

The default directory is wp-content/plugins. To change the default directory manually, define WP_PLUGIN_DIR and WP_PLUGIN_URL in wp-config.php.

Returns (array)

Files.


Usage

  1. if ( !function_exists( 'wp_get_active_and_valid_plugins' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_get_active_and_valid_plugins(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/load.php  
  1. function wp_get_active_and_valid_plugins() { 
  2. $plugins = array(); 
  3. $active_plugins = (array) get_option( 'active_plugins', array() ); 
  4.  
  5. // Check for hacks file if the option is enabled 
  6. if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { 
  7. _deprecated_file( 'my-hacks.php', '1.5.0' ); 
  8. array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); 
  9.  
  10. if ( empty( $active_plugins ) || wp_installing() ) 
  11. return $plugins; 
  12.  
  13. $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 
  14.  
  15. foreach ( $active_plugins as $plugin ) { 
  16. if ( ! validate_file( $plugin ) // $plugin must validate as file 
  17. && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' 
  18. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 
  19. // not already included as a network plugin 
  20. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) ) 
  21. $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 
  22. return $plugins;