Plugin_Upgrader::check_package( string $source )

Check a source package to be sure it contains a plugin.


Description Description

This function is added to the ‘upgrader_source_selection’ filter by Plugin_Upgrader::install().


Parameters Parameters

$source

(string) (Required) The path to the downloaded package source.


Top ↑

Return Return

(string|WP_Error) The source as passed, or a WP_Error object if no plugins were found.


Top ↑

Source Source

File: wp-admin/includes/class-plugin-upgrader.php

	public function check_package($source) {
		global $wp_filesystem;

		if ( is_wp_error($source) )
			return $source;

		$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
		if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
			return $source;

		// Check the folder contains at least 1 valid plugin.
		$plugins_found = false;
		$files = glob( $working_directory . '*.php' );
		if ( $files ) {
			foreach ( $files as $file ) {
				$info = get_plugin_data( $file, false, false );
				if ( ! empty( $info['Name'] ) ) {
					$plugins_found = true;
					break;
				}
			}
		}

		if ( ! $plugins_found )
			return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );

		return $source;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.