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
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
- Scaling
- Scales with input
- Instructions
- 17–76
- Plugin surface
- None
- Called by
- 1
Reaches an outbound HTTP request via wp_remote_get().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 118.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Site_Health_Auto_Updates::test_all_files_writable() - httpoutbound HTTP request
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 17 | ->request_filesystem_credentials() |
| always | 22 | ->request_filesystem_credentials(), WP_Filesystem() |
| always | 37–40 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums() |
| always | 44–47 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums() |
| always | 46–61 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), array_keys(), __() |
| always | 53–56 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), __(), sprintf(), __() |
| always | 55–68 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums(), array_keys(), __() |
| always | 60–63 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums(), __(), sprintf(), __() |
| always | 61–69 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), array_keys(), array_slice(), __() |
| always | 70–76 | ->request_filesystem_credentials(), WP_Filesystem(), function_exists(), get_core_checksums(), get_core_checksums(), array_keys(), array_slice(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 118 | 17–76 | 15 | |
| 8.5 | 118 | 17–76 | 15 | |
| 8.4 | 118 | 17–76 | 15 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 127 | 17–82 | 15 | |
| 8.2 | 127 | 17–82 | 15 | |
| 8.1 | 127 | 17–82 | 15 | |
| 7.4 | 127 | 17–82 | 15 |
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
- WP_Site_Health_Auto_Updates::run_tests()Runs tests to determine if auto-updates can run.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.