validate_active_plugins

Validate active plugins.

Description

(array) validate_active_plugins(); 

Validate all active plugins, deactivates invalid and returns an array of deactivated ones.

Returns (array)

invalid plugins, plugin as key, error as value


Usage

  1. if ( !function_exists( 'validate_active_plugins' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = validate_active_plugins(); 
  7.  

Defined (1)

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

/wp-admin/includes/plugin.php  
  1. function validate_active_plugins() { 
  2. $plugins = get_option( 'active_plugins', array() ); 
  3. // Validate vartype: array. 
  4. if ( ! is_array( $plugins ) ) { 
  5. update_option( 'active_plugins', array() ); 
  6. $plugins = array(); 
  7.  
  8. if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { 
  9. $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); 
  10. $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); 
  11.  
  12. if ( empty( $plugins ) ) 
  13. return array(); 
  14.  
  15. $invalid = array(); 
  16.  
  17. // Invalid plugins get deactivated. 
  18. foreach ( $plugins as $plugin ) { 
  19. $result = validate_plugin( $plugin ); 
  20. if ( is_wp_error( $result ) ) { 
  21. $invalid[$plugin] = $result; 
  22. deactivate_plugins( $plugin, true ); 
  23. return $invalid;