返回介绍

WP_Filesystem()

发布于 2017-09-11 11:56:44 字数 4188 浏览 1081 评论 0 收藏 0

WP_Filesystem( array|false $args = false,  string|false $context = false,  bool $allow_relaxed_file_ownership = false )

Initialises and connects the WordPress Filesystem Abstraction classes.


description

This function will include the chosen transport and attempt connecting.

Plugins may add extra transports, And force WordPress to use them by returning the filename via the ‘filesystem_method_file’ filter.


参数

$args

(array|false) (Optional) Connection args, These are passed directly to the WP_Filesystem_*() classes.

Default value: false

$context

(string|false) (Optional) Context for get_filesystem_method().

Default value: false

$allow_relaxed_file_ownership

(bool) (Optional) Whether to allow Group/World writable.

Default value: false


返回值

(null|bool) false on failure, true on success.


源代码

File: wp-admin/includes/file.php

function WP_Filesystem( $args = false, $context = false, $allow_relaxed_file_ownership = false ) {
	global $wp_filesystem;

	require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');

	$method = get_filesystem_method( $args, $context, $allow_relaxed_file_ownership );

	if ( ! $method )
		return false;

	if ( ! class_exists( "WP_Filesystem_$method" ) ) {

		/**
		 * Filters the path for a specific filesystem method class file.
		 *
		 * @since 2.6.0
		 *
		 * @see get_filesystem_method()
		 *
		 * @param string $path   Path to the specific filesystem method class file.
		 * @param string $method The filesystem method to use.
		 */
		$abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );

		if ( ! file_exists($abstraction_file) )
			return;

		require_once($abstraction_file);
	}
	$method = "WP_Filesystem_$method";

	$wp_filesystem = new $method($args);

	//Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default.
	if ( ! defined('FS_CONNECT_TIMEOUT') )
		define('FS_CONNECT_TIMEOUT', 30);
	if ( ! defined('FS_TIMEOUT') )
		define('FS_TIMEOUT', 30);

	if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
		return false;

	if ( !$wp_filesystem->connect() )
		return false; //There was an error connecting to the server.

	// Set the permission constants if not already set.
	if ( ! defined('FS_CHMOD_DIR') )
		define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
	if ( ! defined('FS_CHMOD_FILE') )
		define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );

	return true;
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-admin/includes/file.php: get_filesystem_method()
  • wp-admin/includes/file.php: filesystem_method_file
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/load.php: is_wp_error()

Used By

  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_plugin()
  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_theme()
  • wp-admin/includes/class-wp-upgrader.php: WP_Upgrader::fs_connect()
  • wp-admin/includes/theme.php: delete_theme()
  • wp-admin/includes/plugin.php: delete_plugins()
  • wp-admin/update-core.php: do_core_upgrade()
  • Show 1 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文