bb_validate_plugin

Validate the plugin path.

Description

(WP_Error|int) bb_validate_plugin( (string) $plugin, (string) $location = 'all', (string) $type = 'all' ); 

Checks that the file exists and is valid file.

Returns (WP_Error|int)

0 on success, WP_Error on failure.

Parameters (3)

0. $plugin (string)
The plugin.
1. $location — Optional. (string) => 'all'
The location of plugin, one of user,, core or all
2. $type — Optional. (string) => 'all'
The type of plugin, one of all,, autoload or normal

Usage

  1. if ( !function_exists( 'bb_validate_plugin' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-plugin.php'; 
  3.  
  4. // The plugin. 
  5. $plugin = ''; 
  6.  
  7. // The location of plugin, one of 'user', 'core' or 'all' 
  8. $location = 'all'; 
  9.  
  10. // The type of plugin, one of 'all', 'autoload' or 'normal' 
  11. $type = 'all'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_validate_plugin($plugin, $location, $type); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-plugin.php  
  1. function bb_validate_plugin( $plugin, $location = 'all', $type = 'all' ) { 
  2. if ( validate_file( trim( $plugin ) ) ) { 
  3. return new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ) ); 
  4. $path = bb_get_plugin_path( trim( $plugin ) ); 
  5. if ( !file_exists( $path ) ) { 
  6. return new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ) ); 
  7. if ( !in_array( trim( $plugin ), array_keys( bb_get_plugins( $location, $type ) ) ) ) { 
  8. return new WP_Error( 'plugin_not_available', __( 'That type of plugin is not available in the specified location.' ) ); 
  9.  
  10. return $path;