wppaste
WordPress

WP_Site_Health_Auto_Updates::test_all_files_writable(): array|false

Since
5.2.0
Source
wp-admin/includes/class-wp-site-health-auto-updates.php:328
Checks if core files are writable by the web user/group.

Compatibility

WordPress
since 5.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

array|false
The test results if at least some of WordPress core files are writeable, or if a list of the checksums could not be retrieved from WordPress.org.
False if the core files are not writeable.

Performance profile

How much work a call to WP_Site_Health_Auto_Updates::test_all_files_writable() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Reaches an outbound HTTP request via wp_remote_get().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
17–76

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 118.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_Site_Health_Auto_Updates::test_all_files_writable()
  • httpoutbound HTTP requestwp_remote_get()one call below WP_Site_Health_Auto_Updates::test_all_files_writable()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 10 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health_Auto_Updates::test_all_files_writable() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always17->request_filesystem_credentials()
always22->request_filesystem_credentials(), WP_Filesystem()
always37–40->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums()
always44–47->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums()
always46–61->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), array_keys(), __()
always53–56->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), __(), sprintf(), __()
always55–68->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums(), array_keys(), __()
always60–63->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums(), __(), sprintf(), __()
always61–69->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), array_keys(), array_slice(), __()
always70–76->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums(), array_keys(), array_slice(), __()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11817–7615
8.511817–7615
8.411817–76159 fewer instructions than PHP 8.3
8.312717–8215
8.212717–8215
8.112717–8215
7.412717–8215

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 6

  • WP_Filesystem()Initializes and connects the WordPress Filesystem Abstraction classes.
  • get_core_checksums()Gets and caches the checksums for the given version of WordPress.
  • str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
  • __()Retrieves the translation of $text.
  • str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
  • Automatic_Upgrader_Skin::__construct()

Used by · 1

Source code

	public function test_all_files_writable() {		global $wp_filesystem; 		require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z 		$skin    = new Automatic_Upgrader_Skin();		$success = $skin->request_filesystem_credentials( false, ABSPATH ); 		if ( ! $success ) {			return false;		} 		WP_Filesystem(); 		if ( 'direct' !== $wp_filesystem->method ) {			return false;		} 		// Make sure the `get_core_checksums()` function is available during our REST API call.		if ( ! function_exists( 'get_core_checksums' ) ) {			require_once ABSPATH . 'wp-admin/includes/update.php';		} 		$checksums = get_core_checksums( $wp_version, 'en_US' );		$dev       = ( str_contains( $wp_version, '-' ) );		// Get the last stable version's files and test against that.		if ( ! $checksums && $dev ) {			$checksums = get_core_checksums( (float) $wp_version - 0.1, 'en_US' );		} 		// There aren't always checksums for development releases, so just skip the test if we still can't find any.		if ( ! $checksums && $dev ) {			return false;		} 		if ( ! $checksums ) {			$description = sprintf(				/* translators: %s: WordPress version. */				__( "Couldn't retrieve a list of the checksums for WordPress %s." ),				$wp_version			);			$description .= ' ' . __( 'This could mean that connections are failing to WordPress.org.' );			return array(				'description' => $description,				'severity'    => 'warning',			);		} 		$unwritable_files = array();		foreach ( array_keys( $checksums ) as $file ) {			if ( str_starts_with( $file, 'wp-content' ) ) {				continue;			}			if ( ! file_exists( ABSPATH . $file ) ) {				continue;			}			if ( ! is_writable( ABSPATH . $file ) ) {				$unwritable_files[] = $file;			}		} 		if ( $unwritable_files ) {			if ( count( $unwritable_files ) > 20 ) {				$unwritable_files   = array_slice( $unwritable_files, 0, 20 );				$unwritable_files[] = '...';			}			return array(				'description' => __( 'Some files are not writable by WordPress:' ) . ' <ul><li>' . implode( '</li><li>', $unwritable_files ) . '</li></ul>',				'severity'    => 'fail',			);		} else {			return array(				'description' => __( 'All of your WordPress files are writable.' ),				'severity'    => 'pass',			);		}	}

Changelog

Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-admin/includes/class-wp-site-health-auto-updates.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.