Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



validate_plugin_requirements ›

Od5.2.0
Przestarzałyn/a
validate_plugin_requirements ( $plugin )
Parametry:
  • (string) $plugin Path to the plugin file relative to the plugins directory.
    Wymagane: Tak
Powrót:
  • (true|WP_Error) True if requirements are met, WP_Error on failure.
Zdefiniowane na:
Codex:

Validate the plugin requirements for WP version and PHP version.



Źródło

function validate_plugin_requirements( $plugin ) {
	$readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt';

	if ( file_exists( $readme_file ) ) {
		$plugin_data = get_file_data(
			$readme_file,
			array(
				'requires'     => 'Requires at least',
				'requires_php' => 'Requires PHP',
			),
			'plugin'
		);
	} else {
		return true;
	}

	$plugin_data['wp_compatible']  = is_wp_version_compatible( $plugin_data['requires'] );
	$plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );

	$plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );

	if ( ! $plugin_data['wp_compatible'] && ! $plugin_data['php_compatible'] ) {
		return new WP_Error(
			'plugin_wp_php_incompatible',
			sprintf(
				/* translators: %s: plugin name */
				__( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.' ),
				$plugin_data['Name']
			)
		);
	} elseif ( ! $plugin_data['php_compatible'] ) {
		return new WP_Error(
			'plugin_php_incompatible',
			sprintf(
				/* translators: %s: plugin name */
				__( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.' ),
				$plugin_data['Name']
			)
		);
	} elseif ( ! $plugin_data['wp_compatible'] ) {
		return new WP_Error(
			'plugin_wp_incompatible',
			sprintf(
				/* translators: %s: plugin name */
				__( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.' ),
				$plugin_data['Name']
			)
		);
	}

	return true;
}