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

Explicitly require the hash extension. #8138

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

johnbillion
Copy link
Member

Copy link

github-actions bot commented Jan 16, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props johnbillion, ayeshrajans, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@johnbillion
Copy link
Member Author

@dd32 I would like to ask you to double check those stats you pulled about the hash extension. It's great that only a single site on 6.1+ has json but not hash, but it's also a suspiciously low number. Is there any chance it may not be accurate? Better to be safe than sorry. Thanks!

@Ayesh
Copy link

Ayesh commented Jan 16, 2025

PHP 7.4 is the first version to properly bundle the hash extension, so prior to PHP 7.4, it is technically possible to compile PHP without the hash extension.

@peterwilsoncc
Copy link
Contributor

@johnbillion In it's current form, the error will only show the first extension that is missing. If an install is missing both required extensions, I think it would be helpful to include that in the WP_Error. Does something like this work?

	// Add a warning when required PHP extensions are missing.
	$required_php_extensions = array( 'json', 'hash' );
	$missing_php_extensions  = array();
	foreach ( $required_php_extensions as $required_php_extension ) {
		if ( ! extension_loaded( $required_php_extension ) ) {
			$missing_php_extensions[] = $required_php_extension;
		}
	}

	if ( ! empty( $missing_php_extensions ) ) {
		$php_extension_error = new WP_Error();
		foreach ( $missing_php_extensions as $missing_php_extension ) {
			$php_extension_error->add(
				"php_not_compatible_{$missing_php_extension}",
				sprintf(
					/* translators: 1: WordPress version number, 2: The PHP extension name needed. */
					__( 'The update cannot be installed because WordPress %1$s requires the %2$s PHP extension.' ),
					$wp_version,
					strtoupper( $missing_php_extension )
				)
			);
		}
		return $php_extension_error;
	}

@johnbillion
Copy link
Member Author

@Ayesh Yep that's correct. Dion ran the numbers in #8097 and saw almost zero affected sites with hash disabled, hence this proposal. I've asked him to run the numbers again to double check!

@johnbillion
Copy link
Member Author

@peterwilsoncc Good point, I'll take a look

@johnbillion
Copy link
Member Author

So we've a catch-22 situation here, the code in update_core() cannot introduce any new logic to prevent an update from occurring because its code won't yet be in place during the update. The update_core() function specifically reads $required_php_version and $required_mysql_version from wp-includes/version.php in the update package for the PHP and MySQL version checks.

For future-proofing we could introduce a $required_php_extensions global in this file, but it wouldn't be able to take effect during any update from a version earlier than 6.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants