Directory

Check ZipArchive class before zip export by t-hamano · Pull Request #609 · WordPress/create-block-theme · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check ZipArchive class before zip export #609

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Apr 30, 2024

Fixes #492

This PR displays an appropriate error message when a process that creates a zip file requires the ZipArchive class and the class does not exist.

Suggestions for displayed text are also welcome!

image

image

Testing Instructions

To test this PR, you need to disable the zip extension locally. For wp-env, please follow the steps below.

  • Run wp-env: npm run wp-env start
  • Check the container name: docker ps
  • Go inside the container: docker exec -it {YOUR-CONTAINER-NAME}-wordpress-1 bash
  • Remove zip extension: rm /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
  • Restart Apache: /etc/init.d/apache2 reload
  • Exit the container: exit
  • Check the Site Health page to make sure the zip extension is disabled:

After that, confirm that an error message is displayed when you perform the following operations:

  • Site Editor
    • Create Block Theme Option > Export Zip
  • Appearance > Create Block Theme
    • Export {themeName}
    • Create sibling of {themeName}
    • Create child of {themeName}
    • Clone {themeName}

P.S. Restart wp-env and the zip extension will be automatically enabled again.

Supplement

In addition to the REST API endpoint that this PR changes, the ZipArchive class is also used in the callback functions of the following two endpoints. However, these two endpoints currently don't seem to be called from anywhere.

Endpoint Callback function
create-block-theme/v1/export-clone/ rest_export_cloned_theme
create-block-theme/v1/export-child-clone/ rest_export_child_cloned_theme

@@ -462,6 +462,9 @@ function blockbase_save_theme() {
$this->create_blank_theme( $_POST['theme'], $_FILES['screenshot'] );

add_action( 'admin_notices', array( 'Form_Messages', 'admin_notice_blank_success' ) );
} elseif ( ! class_exists( 'ZipArchive' ) ) {
// Avoid running if ZipArchive is not enabled.
add_action( 'admin_notices', array( 'Form_Messages', 'admin_notice_error_unsupported_zip_archive' ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything after this should require the zipArchive class.

Copy link
Contributor

@pbking pbking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the steps to disable zip in my wp-env.

Tests well, works as expected. I think the copy used is fine.

🚢

@pbking pbking merged commit 9830e9d into WordPress:trunk Apr 30, 2024
2 checks passed
@t-hamano t-hamano deleted the check-zip-archive branch May 1, 2024 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Fatal error: Uncaught Error: Call to undefined method WP_Error::addThemeDir()
2 participants