Title: Theme_Upgrader::check_package
Published: April 25, 2014
Last modified: February 24, 2026

---

# Theme_Upgrader::check_package( string $source ): string|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

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

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

Checks that the package source contains a valid theme.

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

Hooked to the [‘upgrader_source_selection’](https://developer.wordpress.org/reference/hooks/upgrader_source_selection/)
filter by [Theme_Upgrader::install()](https://developer.wordpress.org/reference/classes/theme_upgrader/install/).

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

 `$source`stringrequired

The path to the downloaded package source.

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

 string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) 
The source as passed, or a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object on failure.

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

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

    	$wp_version           = wp_get_wp_version();
    	$this->new_theme_data = array();

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

    	// Check that the folder contains a valid theme.
    	$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
    	if ( ! is_dir( $working_directory ) ) { // Confidence check, if the above fails, let's not prevent installation.
    		return $source;
    	}

    	// A proper archive should have a style.css file in the single subdirectory.
    	if ( ! file_exists( $working_directory . 'style.css' ) ) {
    		return new WP_Error(
    			'incompatible_archive_theme_no_style',
    			$this->strings['incompatible_archive'],
    			sprintf(
    				/* translators: %s: style.css */
    				__( 'The theme is missing the %s stylesheet.' ),
    				'<code>style.css</code>'
    			)
    		);
    	}

    	// All these headers are needed on Theme_Installer_Skin::do_overwrite().
    	$new_theme_data = get_file_data(
    		$working_directory . 'style.css',
    		array(
    			'Name'        => 'Theme Name',
    			'Version'     => 'Version',
    			'Author'      => 'Author',
    			'Template'    => 'Template',
    			'RequiresWP'  => 'Requires at least',
    			'RequiresPHP' => 'Requires PHP',
    		)
    	);

    	if ( empty( $new_theme_data['Name'] ) ) {
    		return new WP_Error(
    			'incompatible_archive_theme_no_name',
    			$this->strings['incompatible_archive'],
    			sprintf(
    				/* translators: %s: style.css */
    				__( 'The %s stylesheet does not contain a valid theme header.' ),
    				'<code>style.css</code>'
    			)
    		);
    	}

    	/*
    	 * Parent themes must contain an index file:
    	 * - classic themes require /index.php
    	 * - block themes require /templates/index.html or block-templates/index.html (deprecated 5.9.0).
    	 */
    	if (
    		empty( $new_theme_data['Template'] ) &&
    		! file_exists( $working_directory . 'index.php' ) &&
    		! file_exists( $working_directory . 'templates/index.html' ) &&
    		! file_exists( $working_directory . 'block-templates/index.html' )
    	) {
    		return new WP_Error(
    			'incompatible_archive_theme_no_index',
    			$this->strings['incompatible_archive'],
    			sprintf(
    				/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */
    				__( 'Template is missing. Standalone themes need to have a %1$s or %2$s template file. <a href="%3$s">Child themes</a> need to have a %4$s header in the %5$s stylesheet.' ),
    				'<code>templates/index.html</code>',
    				'<code>index.php</code>',
    				__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
    				'<code>Template</code>',
    				'<code>style.css</code>'
    			)
    		);
    	}

    	$requires_php = isset( $new_theme_data['RequiresPHP'] ) ? $new_theme_data['RequiresPHP'] : null;
    	$requires_wp  = isset( $new_theme_data['RequiresWP'] ) ? $new_theme_data['RequiresWP'] : null;

    	if ( ! is_php_version_compatible( $requires_php ) ) {
    		$error = sprintf(
    			/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
    			__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
    			PHP_VERSION,
    			$requires_php
    		);

    		return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
    	}
    	if ( ! is_wp_version_compatible( $requires_wp ) ) {
    		$error = sprintf(
    			/* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */
    			__( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ),
    			$wp_version,
    			$requires_wp
    		);

    		return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
    	}

    	$this->new_theme_data = $new_theme_data;

    	return $source;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-theme-upgrader.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-theme-upgrader.php#L562)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-theme-upgrader.php#L562-L669)

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

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

Returns the current WordPress version.

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

Checks compatibility with the current PHP version.

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

Checks compatibility with the current WordPress version.

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

Retrieves metadata from a file.

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

Retrieves the translation of $text.

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

Appends a trailing slash.

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

Checks whether the given variable is a WordPress Error.

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

Initializes the error.

  |

[Show 4 more](https://developer.wordpress.org/reference/classes/theme_upgrader/check_package/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/theme_upgrader/check_package/?output_format=md#)

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

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

## User Contributed Notes

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