Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions includes/class-create-block-theme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function register_rest_routes() {
);
}

function rest_get_theme_data( $request ) {
function rest_get_theme_data() {
try {
$theme_data = CBT_Theme_JSON_Resolver::get_theme_file_contents();
return new WP_REST_Response(
Expand All @@ -177,7 +177,7 @@ function rest_get_theme_data( $request ) {
}
}

function rest_get_readme_data( $request ) {
function rest_get_readme_data() {
try {
$readme_data = CBT_Theme_Readme::get_sections();
return new WP_REST_Response(
Expand Down Expand Up @@ -288,7 +288,7 @@ function rest_create_blank_theme( $request ) {
/**
* Export the theme as a ZIP file.
*/
function rest_export_theme( $request ) {
function rest_export_theme() {
if ( ! class_exists( 'ZipArchive' ) ) {
return new WP_Error(
'missing_zip_package',
Expand All @@ -306,10 +306,10 @@ function rest_export_theme( $request ) {

if ( is_child_theme() ) {
wp_cache_flush();
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'current', $theme_slug );
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'current' );
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'current' );
} else {
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'all', null );
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'all' );
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'all' );
}

Expand Down Expand Up @@ -418,7 +418,7 @@ function rest_save_theme( $request ) {
* It includes the font families from the theme.json data (theme.json file + global styles) and the theme style variations.
* The font families with font faces containing src urls relative to the theme folder are converted to absolute urls.
*/
function rest_get_font_families( $request ) {
function rest_get_font_families() {
$font_families = CBT_Theme_Fonts::get_all_fonts();

return new WP_REST_Response(
Expand Down Expand Up @@ -457,6 +457,7 @@ function rest_reset_theme( $request ) {
}

private function sanitize_theme_data( $theme ) {
$sanitized_theme = array();
$sanitized_theme['name'] = sanitize_text_field( $theme['name'] );
$sanitized_theme['description'] = sanitize_text_field( $theme['description'] ?? '' );
$sanitized_theme['uri'] = sanitize_text_field( $theme['uri'] ?? '' );
Expand Down
6 changes: 3 additions & 3 deletions includes/class-create-block-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ private function load_dependencies() {
* @access private
*/
private function define_admin_hooks() {
$plugin_api = new CBT_Theme_API();
$editor_tools = new CBT_Editor_Tools();
$admin_landing = new CBT_Admin_Landing();
new CBT_Theme_API();
new CBT_Editor_Tools();
new CBT_Admin_Landing();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions includes/create-theme/theme-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function replace_local_pattern_references( $pattern ) {
$templates_to_update = array_unique( $templates_to_update );

// Only update templates that reference the pattern
CBT_Theme_Templates::add_templates_to_local( 'all', null, null, $options, $templates_to_update );
CBT_Theme_Templates::add_templates_to_local( 'all', null, null, null, $templates_to_update );

// List all template and pattern files in the theme
$base_dir = get_stylesheet_directory();
Expand Down Expand Up @@ -185,7 +185,6 @@ public static function add_patterns_to_theme( $options = null ) {
}

// Create the pattern file.
$pattern_file = $patterns_dir . $pattern->name . '.php';
file_put_contents(
$patterns_dir . DIRECTORY_SEPARATOR . $pattern->name . '.php',
$pattern->content
Expand Down
8 changes: 0 additions & 8 deletions includes/create-theme/theme-readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,17 @@ public static function get_content() {
* {
* @type string $name The theme name.
* @type string $description The theme description.
* @type string $uri The theme URI.
* @type string $author The theme author.
* @type string $author_uri The theme author URI.
* @type string $copyright_year The copyright year.
* @type string $image_credits The image credits.
* @type string $recommended_plugins The recommended plugins.
* @type bool $is_child_theme Whether the theme is a child theme.
* }
*
* @return string The readme content.
*/
public static function create( $theme ) {
$name = $theme['name'];
$description = $theme['description'] ?? '';
$uri = $theme['uri'] ?? '';
$author = $theme['author'] ?? '';
$author_uri = $theme['author_uri'] ?? '';
$copy_year = $theme['copyright_year'] ?? gmdate( 'Y' );
$wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version();
$requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp'];
$required_php_version = $theme['required_php_version'] ?? '5.7';
Expand All @@ -57,7 +50,6 @@ public static function create( $theme ) {
$image_credits = $theme['image_credits'] ?? '';
$recommended_plugins = $theme['recommended_plugins'] ?? '';
$font_credits = $theme['font_credits'] ?? '';
$is_child_theme = $theme['is_child_theme'] ?? false;

// Generates the copyright section text.
$copyright_section_content = self::get_copyright_text( $theme );
Expand Down
2 changes: 1 addition & 1 deletion includes/create-theme/theme-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function clear_user_styles_customizations() {
$update_request->set_param( 'id', $user_custom_post_type_id );
$update_request->set_param( 'settings', array() );
$update_request->set_param( 'styles', array() );
$updated_global_styles = $global_styles_controller->update_item( $update_request );
$global_styles_controller->update_item( $update_request );
delete_transient( 'global_styles' );
delete_transient( 'global_styles_' . get_stylesheet() );
delete_transient( 'gutenberg_global_styles' );
Expand Down
2 changes: 1 addition & 1 deletion includes/create-theme/theme-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function clone_theme_to_folder( $location, $new_slug, $new_name )
);

// Add all the files (except for templates)
foreach ( $files as $name => $file ) {
foreach ( $files as $file ) {

// Get real and relative path for current file
$file_path = wp_normalize_path( $file );
Expand Down
4 changes: 2 additions & 2 deletions includes/create-theme/theme-zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function copy_theme_to_zip( $zip, $new_slug, $new_name ) {
);

// Add all the files (except for templates)
foreach ( $files as $name => $file ) {
foreach ( $files as $file ) {

// Skip directories (they would be added automatically)
if ( ! $file->isDir() ) {
Expand Down Expand Up @@ -162,7 +162,7 @@ public static function copy_theme_to_zip( $zip, $new_slug, $new_name ) {
* user = only user edited templates
* all = all templates no matter what
*/
public static function add_templates_to_zip( $zip, $export_type, $new_slug ) {
public static function add_templates_to_zip( $zip, $export_type ) {

$theme_templates = CBT_Theme_Templates::get_theme_templates( $export_type );
$template_folders = get_block_theme_folders();
Expand Down
7 changes: 7 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
</properties>
</rule>

<!-- Detect unused PHP variables -->
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="allowUnusedParametersBeforeUsed" value="true"/>
</properties>
</rule>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

Expand Down
6 changes: 0 additions & 6 deletions tests/CbtThemeReadme/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@ public function test_create( $data ) {
$readme_without_newlines = $this->remove_newlines( $readme );

$expected_name = '== ' . $data['name'] . ' ==';
$expected_description = '== Description ==' . $data['description'];
$expected_uri = 'Theme URI: ' . $data['uri'];
$expected_author = 'Contributors: ' . $data['author'];
$expected_author_uri = 'Author URI: ' . $data['author_uri'];
$expected_requires_wp = 'Requires at least: ' . $data['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version();
$expected_wp_version = 'Tested up to: ' . $data['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version();
$expected_php_version = 'Requires PHP: ' . $data['required_php_version'];
$expected_license = 'License: ' . $data['license'];
$expected_license_uri = 'License URI: ' . $data['license_uri'];
$expected_font_credits = '== Fonts ==' .
( isset( $data['font_credits'] )
? $this->remove_newlines( $data['font_credits'] )
Expand Down