Skip to content

Commit

Permalink
Remove unused REAT API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jun 10, 2024
1 parent 8d65218 commit 6cd1d20
Showing 1 changed file with 0 additions and 134 deletions.
134 changes: 0 additions & 134 deletions includes/class-create-block-theme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,6 @@ public function register_rest_routes() {
},
)
);
register_rest_route(
'create-block-theme/v1',
'/export-clone',
array(
'methods' => 'POST',
'callback' => array( $this, 'rest_export_cloned_theme' ),
'permission_callback' => function () {
return current_user_can( 'edit_theme_options' );
},
)
);
register_rest_route(
'create-block-theme/v1',
'/export-child-clone',
array(
'methods' => 'POST',
'callback' => array( $this, 'rest_export_child_cloned_theme' ),
'permission_callback' => function () {
return current_user_can( 'edit_theme_options' );
},
)
);
register_rest_route(
'create-block-theme/v1',
'/get-readme-data',
Expand Down Expand Up @@ -289,118 +267,6 @@ function rest_create_blank_theme( $request ) {
);
}

function rest_export_cloned_theme( $request ) {

//TODO: Handle Screenshots
$screenshot = null;
$theme = $this->sanitize_theme_data( $request->get_params() );

// Use previous theme's tags if custom tags are empty.
if ( empty( $theme['tags_custom'] ) ) {
$theme['tags_custom'] = implode( ', ', wp_get_theme()->get( 'Tags' ) );
}

// Create ZIP file in the temporary directory.
$filename = tempnam( get_temp_dir(), $theme['slug'] );
$zip = CBT_Theme_Zip::create_zip( $filename, $theme['slug'] );
$zip = CBT_Theme_Zip::copy_theme_to_zip( $zip, $theme['slug'], $theme['name'] );
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'all', $theme['slug'] );

//TODO: Should the font persistent be optional?
// If so then the Font Library fonts will need to be removed from the theme.json settings.
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'all' );
$theme_json = CBT_Theme_Zip::add_activated_fonts_to_zip( $zip, $theme_json );
$zip = CBT_Theme_Zip::add_theme_json_to_zip( $zip, $theme_json );

// Add readme.txt.
$zip->addFromStringToTheme(
'readme.txt',
CBT_Theme_Readme::create( $theme )
);

// Build style.css with new theme metadata
$css_contents = file_get_contents( get_stylesheet_directory() . '/style.css' );
$css_contents = trim( substr( $css_contents, strpos( $css_contents, '*/' ) + 2 ) );
$css_contents = CBT_Theme_Styles::build_style_css( $theme ) . $css_contents;
$zip->addFromStringToTheme(
'style.css',
$css_contents
);

// Add / replace screenshot.
if ( CBT_Theme_Utils::is_valid_screenshot( $screenshot ) ) {
$zip->addFileToTheme(
$screenshot['tmp_name'],
'screenshot.png'
);
}

$zip->close();

wp_cache_flush();

header( 'Content-Type: application/zip' );
header( 'Content-Disposition: attachment; filename=' . $theme['slug'] . '.zip' );
header( 'Content-Length: ' . filesize( $filename ) );
flush();
echo readfile( $filename );
}

function rest_export_child_cloned_theme( $request ) {

//TODO: Handle Screenshots
$screenshot = null;
$theme = $this->sanitize_theme_data( $request->get_params() );

// Create ZIP file in the temporary directory.
$filename = tempnam( get_temp_dir(), $theme['slug'] );
$zip = CBT_Theme_Zip::create_zip( $filename, $theme['slug'] );

//TODO: Should the font persistent be optional?
// If so then the Font Library fonts will need to be removed from the theme.json settings.
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'variation' );
$theme_json = CBT_Theme_Zip::add_activated_fonts_to_zip( $zip, $theme_json );
$zip = CBT_Theme_Zip::add_theme_json_to_zip( $zip, $theme_json );

// Add readme.txt.
$zip->addFromStringToTheme(
'readme.txt',
CBT_Theme_Readme::create( $theme )
);

// Build style.css with new theme metadata
$theme['template'] = wp_get_theme()->get( 'TextDomain' );
$css_contents = CBT_Theme_Styles::build_style_css( $theme );
$zip->addFromStringToTheme(
'style.css',
$css_contents
);

// Add / replace screenshot.
if ( CBT_Theme_Utils::is_valid_screenshot( $screenshot ) ) {
$zip->addFileToTheme(
$screenshot['tmp_name'],
'screenshot.png'
);
} else {
$source = plugin_dir_path( __DIR__ ) . 'assets/boilerplate/screenshot.png';
$zip->addFileToTheme(
$source,
'screenshot.png'
);
}

$zip->close();

wp_cache_flush();

header( 'Content-Type: application/zip' );
header( 'Content-Disposition: attachment; filename=' . $theme['slug'] . '.zip' );
header( 'Content-Length: ' . filesize( $filename ) );
flush();
echo readfile( $filename );
}

/**
* Export the theme as a ZIP file.
*/
Expand Down

0 comments on commit 6cd1d20

Please sign in to comment.