validate_plugin

Validate the plugin path.

Description

(WP_Error|int) validate_plugin( (string) $plugin ); 

Checks that the file exists and is a valid file. See validate_file().

Returns (WP_Error|int)

0 on success, WP_Error on failure.

Parameters (1)

0. $plugin (string)
Plugin Path.

Usage

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

Defined (1)

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

/wp-admin/includes/plugin.php  
  1. function validate_plugin($plugin) { 
  2. if ( validate_file($plugin) ) 
  3. return new WP_Error('plugin_invalid', __('Invalid plugin path.')); 
  4. if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) 
  5. return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); 
  6.  
  7. $installed_plugins = get_plugins(); 
  8. if ( ! isset($installed_plugins[$plugin]) ) 
  9. return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.')); 
  10. return 0;