Changeset 48164
- Timestamp:
- 06/25/2020 09:37:25 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/file.php
r48163 r48164 66 66 67 67 /** 68 * Get the description for standard WordPress theme files and other various standard 69 * WordPress files 68 * Gets the description for standard WordPress theme files. 70 69 * 71 70 * @since 1.5.0 … … 73 72 * @global array $wp_file_descriptions Theme file descriptions. 74 73 * @global array $allowed_files List of allowed files. 75 * @param string $file Filesystem path or filename 74 * 75 * @param string $file Filesystem path or filename. 76 76 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist. 77 * Appends 'Page Template' to basename of $file if the file is a page template 77 * Appends 'Page Template' to basename of $file if the file is a page template. 78 78 */ 79 79 function get_file_description( $file ) { 80 80 global $wp_file_descriptions, $allowed_files; 81 81 82 $dirname = pathinfo( $file, PATHINFO_DIRNAME ); 83 82 $dirname = pathinfo( $file, PATHINFO_DIRNAME ); 84 83 $file_path = $allowed_files[ $file ]; 84 85 85 if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $dirname ) { 86 86 return $wp_file_descriptions[ basename( $file ) ]; 87 87 } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) { 88 88 $template_data = implode( '', file( $file_path ) ); 89 89 90 if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) { 90 91 /* translators: %s: Template name. */ … … 97 98 98 99 /** 99 * Get the absolute filesystem path to the root of the WordPress installation100 * Gets the absolute filesystem path to the root of the WordPress installation. 100 101 * 101 102 * @since 1.5.0 102 103 * 103 * @return string Full filesystem path to the root of the WordPress installation 104 * @return string Full filesystem path to the root of the WordPress installation. 104 105 */ 105 106 function get_home_path() { 106 107 $home = set_url_scheme( get_option( 'home' ), 'http' ); 107 108 $siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' ); 109 108 110 if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) { 109 111 $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */ … … 120 122 /** 121 123 * Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep. 124 * 122 125 * The depth of the recursiveness can be controlled by the $levels param. 123 126 * … … 293 296 294 297 /** 295 * Print file editor templates (for plugins and themes).298 * Prints file editor templates (for plugins and themes). 296 299 * 297 300 * @since 4.9.0 … … 343 346 344 347 /** 345 * Attempt to edit a file for a theme or plugin.348 * Attempts to edit a file for a theme or plugin. 346 349 * 347 350 * When editing a PHP file, loopback requests will be made to the admin and the homepage … … 501 504 return new WP_Error( 'unable_to_write', __( 'Unable to write to file.' ) ); 502 505 } 506 503 507 wp_opcache_invalidate( $real_file, true ); 504 508 … … 630 634 631 635 /** 632 * Returns a filename of a Temporary unique file. 636 * Returns a filename of a temporary unique file. 637 * 633 638 * Please note that the calling function must unlink() this itself. 634 639 * 635 640 * The filename is based off the passed parameter or defaults to the current unix timestamp, 636 * while the directory can either be passed as well, or by leaving it blank, default to a writable temporary directory. 641 * while the directory can either be passed as well, or by leaving it blank, default to a writable 642 * temporary directory. 637 643 * 638 644 * @since 2.6.0 … … 640 646 * @param string $filename Optional. Filename to base the Unique file off. Default empty. 641 647 * @param string $dir Optional. Directory to store the file in. Default empty. 642 * @return string a writable filename648 * @return string A writable filename. 643 649 */ 644 650 function wp_tempnam( $filename = '', $dir = '' ) { … … 684 690 * 685 691 * @param string $file File the user is attempting to edit. 686 * @param string[] $allowed_files Optional. Array of allowed files to edit. `$file` must match an entry exactly. 692 * @param string[] $allowed_files Optional. Array of allowed files to edit. 693 * `$file` must match an entry exactly. 687 694 * @return string|void Returns the file name on success, dies on failure. 688 695 */ … … 707 714 708 715 /** 709 * Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, 710 * and moving the file to the appropriate directory within the uploads directory. 716 * Handles PHP uploads in WordPress. 717 * 718 * Sanitizes file names, checks extensions for mime type, and moves the file 719 * to the appropriate directory within the uploads directory. 711 720 * 712 721 * @access private … … 715 724 * @see wp_handle_upload_error 716 725 * 717 * @param string[] $file Reference to a single element of `$_FILES`. Call the function once for each uploaded file. 718 * @param string[]|false $overrides An associative array of names => values to override default variables. Default false. 726 * @param string[] $file Reference to a single element of `$_FILES`. 727 * Call the function once for each uploaded file. 728 * @param string[]|false $overrides An associative array of names => values 729 * to override default variables. Default false. 719 730 * @param string $time Time formatted in 'yyyy/mm'. 720 731 * @param string $action Expected value for `$_POST['action']`. 721 * @return string[] On success, returns an associative array of file attributes. On failure, returns 722 * `$overrides['upload_error_handler']( &$file, $message )` or `array( 'error' => $message )`. 732 * @return string[] On success, returns an associative array of file attributes. 733 * On failure, returns `$overrides['upload_error_handler']( &$file, $message )` 734 * or `array( 'error' => $message )`. 723 735 */ 724 736 function _wp_handle_upload( &$file, $overrides, $time, $action ) { … … 954 966 * @see _wp_handle_upload() 955 967 * 956 * @param array $file Reference to a single element of `$_FILES`. Call the function once for957 * each uploaded file.958 * @param array|bool $overrides Optional. An associative array of names =>values to override default959 * variables. Default false.968 * @param array $file Reference to a single element of `$_FILES`. 969 * Call the function once for each uploaded file. 970 * @param array|bool $overrides Optional. An associative array of names => values 971 * to override default variables. Default false. 960 972 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. 961 * @return array On success, returns an associative array of file attributes. On failure, returns 962 * $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). 973 * @return array On success, returns an associative array of file attributes. 974 * On failure, returns `$overrides['upload_error_handler']( &$file, $message )` 975 * or `array( 'error' => $message )`. 963 976 */ 964 977 function wp_handle_upload( &$file, $overrides = false, $time = null ) { … … 984 997 * @see _wp_handle_upload() 985 998 * 986 * @param array $file An array similar to that of a PHP `$_FILES` POST array 987 * @param array|bool $overrides Optional. An associative array of names=>values to override default 988 * variables. Default false. 999 * @param array $file Reference to a single element of `$_FILES`. 1000 * Call the function once for each uploaded file. 1001 * @param array|bool $overrides Optional. An associative array of names => values 1002 * to override default variables. Default false. 989 1003 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. 990 * @return array On success, returns an associative array of file attributes. On failure, returns 991 * $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). 1004 * @return array On success, returns an associative array of file attributes. 1005 * On failure, returns `$overrides['upload_error_handler']( &$file, $message )` 1006 * or `array( 'error' => $message )`. 992 1007 */ 993 1008 function wp_handle_sideload( &$file, $overrides = false, $time = null ) { … … 1000 1015 $action = $overrides['action']; 1001 1016 } 1017 1002 1018 return _wp_handle_upload( $file, $overrides, $time, $action ); 1003 1019 } … … 1012 1028 * 1013 1029 * @param string $url The URL of the file to download. 1014 * @param int $timeout The timeout for the request to download the file. Default 300 seconds. 1015 * @param bool $signature_verification Whether to perform Signature Verification. Default false. 1030 * @param int $timeout The timeout for the request to download the file. 1031 * Default 300 seconds. 1032 * @param bool $signature_verification Whether to perform Signature Verification. 1033 * Default false. 1016 1034 * @return string|WP_Error Filename on success, WP_Error on failure. 1017 1035 */ … … 1360 1378 1361 1379 /** 1362 * Retrieve the list of signing keys trusted by WordPress.1380 * Retrieves the list of signing keys trusted by WordPress. 1363 1381 * 1364 1382 * @since 5.2.0 … … 1742 1760 } 1743 1761 } 1762 1744 1763 wp_opcache_invalidate( $to . $filename ); 1745 1764 } elseif ( 'd' === $fileinfo['type'] ) { … … 1780 1799 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. 1781 1800 * 1782 * @param array|false $args Optional. Connection args, These are passed directly to 1783 * the `WP_Filesystem_*()` classes. Default false. 1784 * @param string|false $context Optional. Context for get_filesystem_method(). Default false. 1785 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false. 1786 * @return bool|null True on success, false on failure, null if the filesystem method class file does not exist. 1801 * @param array|false $args Optional. Connection args, These are passed 1802 * directly to the `WP_Filesystem_*()` classes. 1803 * Default false. 1804 * @param string|false $context Optional. Context for get_filesystem_method(). 1805 * Default false. 1806 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. 1807 * Default false. 1808 * @return bool|null True on success, false on failure, 1809 * null if the filesystem method class file does not exist. 1787 1810 */ 1788 1811 function WP_Filesystem( $args = false, $context = false, $allow_relaxed_file_ownership = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid … … 1943 1966 * @since 2.6.0 1944 1967 * 1945 * @param string $method Filesystem method to return.1946 * @param array $args An array of connection details for the method.1947 * @param string $context Full path to the directory that is tested for being writable.1968 * @param string $method Filesystem method to return. 1969 * @param array $args An array of connection details for the method. 1970 * @param string $context Full path to the directory that is tested for being writable. 1948 1971 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable. 1949 1972 */ … … 1969 1992 * @param string $form_post The URL to post the form to. 1970 1993 * @param string $type Optional. Chosen type of filesystem. Default empty. 1971 * @param bool|WP_Error $error Optional. Whether the current request has failed to connect, 1972 * or an error object. Default false. 1973 * @param string $context Optional. Full path to the directory that is tested for being 1974 * writable. Default empty. 1975 * @param array $extra_fields Optional. Extra `POST` fields to be checked for inclusion in 1976 * the post. Default null. 1977 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false. 1978 * @return bool|array True if no filesystem credentials are required, false if they are required but have not been 1979 * provided, array of credentials if they are required and have been provided. 1994 * @param bool|WP_Error $error Optional. Whether the current request has failed 1995 * to connect, or an error object. Default false. 1996 * @param string $context Optional. Full path to the directory that is tested 1997 * for being writable. Default empty. 1998 * @param array $extra_fields Optional. Extra `POST` fields to be checked 1999 * for inclusion in the post. Default null. 2000 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. 2001 * Default false. 2002 * @return bool|array True if no filesystem credentials are required, 2003 * false if they are required but have not been provided, 2004 * array of credentials if they are required and have been provided. 1980 2005 */ 1981 2006 function request_filesystem_credentials( $form_post, $type = '', $error = false, $context = '', $extra_fields = null, $allow_relaxed_file_ownership = false ) { … … 2251 2276 2252 2277 /** 2253 * Print the filesystem credentials modal when needed.2278 * Prints the filesystem credentials modal when needed. 2254 2279 * 2255 2280 * @since 4.2.0 … … 2279 2304 2280 2305 /** 2281 * Attempt to clear the opcode cache for an individual PHP file.2306 * Attempts to clear the opcode cache for an individual PHP file. 2282 2307 * 2283 2308 * This function can be called safely without having to check the file extension … … 2286 2311 * Whether or not invalidation is possible is cached to improve performance. 2287 2312 * 2288 * @since 5.5 2313 * @since 5.5.0 2289 2314 * 2290 2315 * @link https://www.php.net/manual/en/function.opcache-invalidate.php 2291 2316 * 2292 2317 * @param string $filepath Path to the file, including extension, for which the opcode cache is to be cleared. 2293 * @param bool $force Invalidate even if the modification time is not newer than the file in cache. Default `false`.2294 * 2295 * @return bool `true`if opcache was invalidated for `$filepath`, or there was nothing to invalidate.2296 * `false`if opcache invalidation is not available, or is disabled via filter.2318 * @param bool $force Invalidate even if the modification time is not newer than the file in cache. 2319 * Default false. 2320 * @return bool True if opcache was invalidated for `$filepath`, or there was nothing to invalidate. 2321 * False if opcache invalidation is not available, or is disabled via filter. 2297 2322 */ 2298 2323 function wp_opcache_invalidate( $filepath, $force = false ) { … … 2310 2335 * the beginning of the path of the origin file. 2311 2336 * 2312 * `$_SERVER['SCRIPT_FILENAME']` approximates the origin file's path, but 2313 * `realpath()` is necessary because `SCRIPT_FILENAME` can be a relative path 2314 * when run from CLI. 2337 * `$_SERVER['SCRIPT_FILENAME']` approximates the origin file's path, but `realpath()` 2338 * is necessary because `SCRIPT_FILENAME` can be a relative path when run from CLI. 2315 2339 * 2316 2340 * For more details, see: … … 2319 2343 * - https://core.trac.wordpress.org/ticket/36455 2320 2344 */ 2321 if ( null === $can_invalidate ) { 2322 $can_invalidate = function_exists( 'opcache_invalidate' ) && 2323 ( ! ini_get( 'opcache.restrict_api' ) || 2324 stripos( realpath( $_SERVER['SCRIPT_FILENAME'] ), ini_get( 'opcache.restrict_api' ) ) === 0 ); 2345 if ( null === $can_invalidate 2346 && function_exists( 'opcache_invalidate' ) 2347 && ( ! ini_get( 'opcache.restrict_api' ) 2348 || stripos( realpath( $_SERVER['SCRIPT_FILENAME'] ), ini_get( 'opcache.restrict_api' ) ) === 0 ) 2349 ) { 2350 $can_invalidate = true; 2325 2351 } 2326 2352 … … 2338 2364 * Filters whether to invalidate a file from the opcode cache. 2339 2365 * 2340 * @since 5.5 2341 * 2342 * @param bool $will_invalidate Whether WordPress will invalidate `$filename`. Default `true`.2366 * @since 5.5.0 2367 * 2368 * @param bool $will_invalidate Whether WordPress will invalidate `$filename`. Default true. 2343 2369 * @param string $filename The PHP filename to invalidate. 2344 2370 */
Note: See TracChangeset
for help on using the changeset viewer.