Theme_Upgrader::check_package()
最后更新于:2021-11-26 04:12:54
Theme_Upgrader::check_package( string$source)Checks that the package source contains a valid theme.
参数
- $source
-
(string) (Required) The path to the downloaded package source.
响应
(string|GC_Error) The source as passed, or a GC_Error object on failure.
源文件
文件: gc-admin/includes/class-theme-upgrader.php
public function check_package( $source ) {
global $gc_filesystem, $gc_version;
$this->new_theme_data = array();
if ( is_gc_error( $source ) ) {
return $source;
}
// Check that the folder contains a valid theme.
$working_directory = str_replace( $gc_filesystem->gc_content_dir(), trailingslashit( GC_CONTENT_DIR ), $source );
if ( ! is_dir( $working_directory ) ) { // Sanity 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 GC_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().
$info = get_file_data(
$working_directory . 'style.css',
array(
'Name' => 'Theme Name',
'Version' => 'Version',
'Author' => 'Author',
'Template' => 'Template',
'RequiresGC' => 'Requires at least',
'RequiresPHP' => 'Requires PHP',
)
);
if ( empty( $info['Name'] ) ) {
return new GC_Error(
'incompatible_archive_theme_no_name',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: style.css */
__( 'The %s stylesheet doesn’t contain a valid theme header.' ),
'<code>style.css</code>'
)
);
}
// If it's not a child theme, it must have at least an index.php to be legit.
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
return new GC_Error(
'incompatible_archive_theme_no_index',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: index.php */
__( 'The theme is missing the %s file.' ),
'<code>index.php</code>'
)
);
}
$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
$requires_gc = isset( $info['RequiresGC'] ) ? $info['RequiresGC'] : 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.' ),
phpversion(),
$requires_php
);
return new GC_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
}
if ( ! is_gc_version_compatible( $requires_gc ) ) {
$error = sprintf(
/* translators: 1: Current GeChiUI version, 2: Version required by the uploaded theme. */
__( 'Your GeChiUI version is %1$s, however the uploaded theme requires %2$s.' ),
$gc_version,
$requires_gc
);
return new GC_Error( 'incompatible_gc_required_version', $this->strings['incompatible_archive'], $error );
}
$this->new_theme_data = $info;
return $source;
}