Title: validate_plugin
Published: April 25, 2014
Last modified: August 20, 2026

---

# validate_plugin( string $plugin ): int|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#wp--skip-link--target)

Validates the plugin path.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#description)󠁿

Checks that the main plugin file exists and is a valid plugin. See [validate_file()](https://developer.wordpress.org/reference/functions/validate_file/).

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#parameters)󠁿

 `$plugin`stringrequired

Path to the plugin file relative to the plugins directory.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#return)󠁿

 int|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) 0 on
success, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#source)󠁿

    ```php
    function validate_plugin( $plugin ) {
    	if ( validate_file( $plugin ) ) {
    		return new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ) );
    	}
    	if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
    		return new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ) );
    	}

    	$installed_plugins = get_plugins();
    	if ( ! isset( $installed_plugins[ $plugin ] ) ) {
    		return new WP_Error( 'no_plugin_header', __( 'The plugin does not have a valid header.' ) );
    	}
    	return 0;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/plugin.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/plugin.php#L1109)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/plugin.php#L1109-L1122)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#related)󠁿

| Uses | Description | 
| [get_plugins()](https://developer.wordpress.org/reference/functions/get_plugins/)`wp-admin/includes/plugin.php` |

Checks the plugins directory and retrieve all plugin files with plugin data.

  | 
| [validate_file()](https://developer.wordpress.org/reference/functions/validate_file/)`wp-includes/functions.php` |

Validates a file name and path against an allowed set of rules.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#)

| Used by | Description | 
| [_wp_connectors_get_connector_script_module_data()](https://developer.wordpress.org/reference/functions/_wp_connectors_get_connector_script_module_data/)`wp-includes/connectors.php` |

Exposes connector settings to the connectors-wp-admin script module.

  | 
| [activate_plugin()](https://developer.wordpress.org/reference/functions/activate_plugin/)`wp-admin/includes/plugin.php` |

Attempts activation of plugin in a “sandbox” and redirects on success.

  | 
| [validate_active_plugins()](https://developer.wordpress.org/reference/functions/validate_active_plugins/)`wp-admin/includes/plugin.php` |

Validates active plugins.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/validate_plugin/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fvalidate_plugin%2F)
before being able to contribute a note or feedback.