WP_REST_Plugins_Controller::is_filesystem_available() WordPress Method

The WP_REST_Plugins_Controller::is_filesystem_available() method is used to check if the filesystem is available for use by the WordPress REST API. This is useful for checking if the REST API can be used to install or update plugins.

WP_REST_Plugins_Controller::is_filesystem_available() #

Determine if the endpoints are available.


Description

Only the ‘Direct’ filesystem transport, and SSH/FTP when credentials are stored are supported at present.


Top ↑

Return

(true|WP_Error) True if filesystem is available, WP_Error otherwise.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php

	protected function is_filesystem_available() {
		$filesystem_method = get_filesystem_method();

		if ( 'direct' === $filesystem_method ) {
			return true;
		}

		ob_start();
		$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
		ob_end_clean();

		if ( $filesystem_credentials_are_stored ) {
			return true;
		}

		return new WP_Error( 'fs_unavailable', __( 'The filesystem is currently unavailable for managing plugins.' ), array( 'status' => 500 ) );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.