Changeset 47084 for trunk/src/wp-admin/includes/file.php
- Timestamp:
- 01/18/2020 12:52:28 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/file.php (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/file.php
r47060 r47084 22 22 '404.php' => __( '404 Template' ), 23 23 'link.php' => __( 'Links Template' ), 24 // Archives 24 // Archives. 25 25 'index.php' => __( 'Main Index Template' ), 26 26 'archive.php' => __( 'Archives' ), … … 32 32 'search.php' => __( 'Search Results' ), 33 33 'date.php' => __( 'Date Template' ), 34 // Content 34 // Content. 35 35 'singular.php' => __( 'Singular Template' ), 36 36 'single.php' => __( 'Single Post' ), … … 38 38 'front-page.php' => __( 'Homepage' ), 39 39 'privacy-policy.php' => __( 'Privacy Policy Page' ), 40 // Attachments 40 // Attachments. 41 41 'attachment.php' => __( 'Attachment Template' ), 42 42 'image.php' => __( 'Image Attachment Template' ), … … 44 44 'audio.php' => __( 'Audio Attachment Template' ), 45 45 'application.php' => __( 'Application Attachment Template' ), 46 // Embeds 46 // Embeds. 47 47 'embed.php' => __( 'Embed Template' ), 48 48 'embed-404.php' => __( 'Embed 404 Template' ), … … 50 50 'header-embed.php' => __( 'Embed Header Template' ), 51 51 'footer-embed.php' => __( 'Embed Footer Template' ), 52 // Stylesheets 52 // Stylesheets. 53 53 'style.css' => __( 'Stylesheet' ), 54 54 'editor-style.css' => __( 'Visual Editor Stylesheet' ), 55 55 'editor-style-rtl.css' => __( 'Visual Editor RTL Stylesheet' ), 56 56 'rtl.css' => __( 'RTL Stylesheet' ), 57 // Other 57 // Other. 58 58 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), 59 59 '.htaccess' => __( '.htaccess (for rewrite rules )' ), 60 // Deprecated files 60 // Deprecated files. 61 61 'wp-layout.css' => __( 'Stylesheet' ), 62 62 'wp-comments.php' => __( 'Comments Template' ), … … 456 456 } 457 457 458 // Compare based on relative paths 458 // Compare based on relative paths. 459 459 if ( 0 !== validate_file( $file, array_keys( $allowed_files ) ) ) { 460 460 return new WP_Error( 'disallowed_theme_file', __( 'Sorry, that file cannot be edited.' ) ); … … 508 508 $transient = 'scrape_key_' . $scrape_key; 509 509 $scrape_nonce = strval( rand() ); 510 set_transient( $transient, $scrape_nonce, 60 ); // It shouldn't take more than 60 seconds to make the two loopback requests. 510 // It shouldn't take more than 60 seconds to make the two loopback requests. 511 set_transient( $transient, $scrape_nonce, 60 ); 511 512 512 513 $cookies = wp_unslash( $_COOKIE ); … … 645 646 } 646 647 647 // Use the basename of the given file without the extension as the name for the temporary directory 648 // Use the basename of the given file without the extension as the name for the temporary directory. 648 649 $temp_filename = basename( $filename ); 649 650 $temp_filename = preg_replace( '|\.[^.]*$|', '', $temp_filename ); … … 654 655 } 655 656 656 // Suffix some random data to avoid filename conflicts 657 // Suffix some random data to avoid filename conflicts. 657 658 $temp_filename .= '-' . wp_generate_password( 6, false ); 658 659 $temp_filename .= '.tmp'; … … 736 737 $file = apply_filters( "{$action}_prefilter", $file ); 737 738 738 // You may define your own function and pass the name in $overrides['upload_error_handler'] 739 // You may define your own function and pass the name in $overrides['upload_error_handler']. 739 740 $upload_error_handler = 'wp_handle_upload_error'; 740 741 if ( isset( $overrides['upload_error_handler'] ) ) { … … 749 750 // Install user overrides. Did we mention that this voids your warranty? 750 751 751 // You may define your own function and pass the name in $overrides['unique_filename_callback'] 752 // You may define your own function and pass the name in $overrides['unique_filename_callback']. 752 753 $unique_filename_callback = null; 753 754 if ( isset( $overrides['unique_filename_callback'] ) ) { … … 823 824 $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename']; 824 825 825 // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect 826 // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect. 826 827 if ( $proper_filename ) { 827 828 $file['name'] = $proper_filename; … … 870 871 $move_new_file = @move_uploaded_file( $file['tmp_name'], $new_file ); 871 872 } else { 872 // use copy and unlink because rename breaks streams.873 // Use copy and unlink because rename breaks streams. 873 874 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged 874 875 $move_new_file = @copy( $file['tmp_name'], $new_file ); … … 1002 1003 */ 1003 1004 function download_url( $url, $timeout = 300, $signature_verification = false ) { 1004 // WARNING: The file is not automatically deleted, The script must unlink() the file.1005 // WARNING: The file is not automatically deleted, the script must unlink() the file. 1005 1006 if ( ! $url ) { 1006 1007 return new WP_Error( 'http_no_url', __( 'Invalid URL Provided.' ) ); … … 1083 1084 if ( ! $signature ) { 1084 1085 // Retrieve signatures from a file if the header wasn't included. 1085 // WordPress.org stores signatures at $package_url.sig 1086 // WordPress.org stores signatures at $package_url.sig. 1086 1087 1087 1088 $signature_url = false; … … 1105 1106 $signature_url, 1106 1107 array( 1107 'limit_response_size' => 10 * 1024, // 10KB should be large enough for quite a few signatures.1108 'limit_response_size' => 10 * KB_IN_BYTES, // 10KB should be large enough for quite a few signatures. 1108 1109 ) 1109 1110 ); … … 1162 1163 $expected_raw_md5 = base64_decode( $expected_md5 ); 1163 1164 } else { 1164 return false; // unknown format1165 return false; // Unknown format. 1165 1166 } 1166 1167 … … 1211 1212 } 1212 1213 1213 // Check for a edge-case affecting PHP Maths abilities 1214 // Check for a edge-case affecting PHP Maths abilities. 1214 1215 if ( 1215 1216 ! extension_loaded( 'sodium' ) && … … 1251 1252 } 1252 1253 1253 // This cannot be performed in a reasonable amount of time 1254 // This cannot be performed in a reasonable amount of time. 1254 1255 // https://github.com/paragonie/sodium_compat#help-sodium_compat-is-slow-how-can-i-make-it-fast 1255 1256 if ( ! $sodium_compat_is_fast ) { … … 1479 1480 } 1480 1481 1481 if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory 1482 if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory. 1482 1483 continue; 1483 1484 } … … 1516 1517 foreach ( $needed_dirs as $dir ) { 1517 1518 // Check the parent folders of the folders all exist within the creation array. 1518 if ( untrailingslashit( $to ) == $dir ) { // Skip over the working directory, We know this exists (or will exist)1519 if ( untrailingslashit( $to ) == $dir ) { // Skip over the working directory, we know this exists (or will exist). 1519 1520 continue; 1520 1521 } 1521 if ( strpos( $dir, $to ) === false ) { // If the directory is not within the working directory, Skip it1522 if ( strpos( $dir, $to ) === false ) { // If the directory is not within the working directory, skip it. 1522 1523 continue; 1523 1524 } … … 1550 1551 } 1551 1552 1552 if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files 1553 if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files. 1553 1554 continue; 1554 1555 } … … 1616 1617 $uncompressed_size = 0; 1617 1618 1618 // Determine any children directories needed (From within the archive) 1619 // Determine any children directories needed (From within the archive). 1619 1620 foreach ( $archive_files as $file ) { 1620 if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory 1621 if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory. 1621 1622 continue; 1622 1623 } … … 1642 1643 foreach ( $needed_dirs as $dir ) { 1643 1644 // Check the parent folders of the folders all exist within the creation array. 1644 if ( untrailingslashit( $to ) == $dir ) { // Skip over the working directory, We know this exists (or will exist)1645 if ( untrailingslashit( $to ) == $dir ) { // Skip over the working directory, we know this exists (or will exist). 1645 1646 continue; 1646 1647 } 1647 if ( strpos( $dir, $to ) === false ) { // If the directory is not within the working directory, Skip it1648 if ( strpos( $dir, $to ) === false ) { // If the directory is not within the working directory, skip it. 1648 1649 continue; 1649 1650 } … … 1666 1667 unset( $needed_dirs ); 1667 1668 1668 // Extract the files from the zip 1669 // Extract the files from the zip. 1669 1670 foreach ( $archive_files as $file ) { 1670 1671 if ( $file['folder'] ) { … … 1672 1673 } 1673 1674 1674 if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files 1675 if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files. 1675 1676 continue; 1676 1677 } … … 1731 1732 } 1732 1733 1733 // generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list1734 // Generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list. 1734 1735 $sub_skip_list = array(); 1735 1736 foreach ( $skip_list as $skip_item ) { … … 1749 1750 1750 1751 /** 1751 * Initiali ses and connects the WordPress Filesystem Abstraction classes.1752 * Initializes and connects the WordPress Filesystem Abstraction classes. 1752 1753 * 1753 1754 * This function will include the chosen transport and attempt connecting. … … 1801 1802 $wp_filesystem = new $method( $args ); 1802 1803 1803 //Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default. 1804 /* 1805 * Define the timeouts for the connections. Only available after the constructor is called 1806 * to allow for per-transport overriding of the default. 1807 */ 1804 1808 if ( ! defined( 'FS_CONNECT_TIMEOUT' ) ) { 1805 1809 define( 'FS_CONNECT_TIMEOUT', 30 ); … … 1814 1818 1815 1819 if ( ! $wp_filesystem->connect() ) { 1816 return false; // There was an error connecting to the server.1820 return false; // There was an error connecting to the server. 1817 1821 } 1818 1822 … … 1855 1859 */ 1856 1860 function get_filesystem_method( $args = array(), $context = '', $allow_relaxed_file_ownership = false ) { 1857 $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets' 1861 // Please ensure that this is either 'direct', 'ssh2', 'ftpext', or 'ftpsockets'. 1862 $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; 1858 1863 1859 1864 if ( ! $context ) { … … 1874 1879 if ( $temp_handle ) { 1875 1880 1876 // Attempt to determine the file owner of the WordPress files, and that of newly created files 1881 // Attempt to determine the file owner of the WordPress files, and that of newly created files. 1877 1882 $wp_file_owner = false; 1878 1883 $temp_file_owner = false; … … 1883 1888 1884 1889 if ( $wp_file_owner !== false && $wp_file_owner === $temp_file_owner ) { 1885 // WordPress is creating files as the same owner as the WordPress files, 1886 // this means it's safe to modify & create new files via PHP. 1890 /* 1891 * WordPress is creating files as the same owner as the WordPress files, 1892 * this means it's safe to modify & create new files via PHP. 1893 */ 1887 1894 $method = 'direct'; 1888 1895 $GLOBALS['_wp_filesystem_direct_method'] = 'file_owner'; 1889 1896 } elseif ( $allow_relaxed_file_ownership ) { 1890 // The $context directory is writable, and $allow_relaxed_file_ownership is set, this means we can modify files 1891 // safely in this directory. This mode doesn't create new files, only alter existing ones. 1897 /* 1898 * The $context directory is writable, and $allow_relaxed_file_ownership is set, 1899 * this means we can modify files safely in this directory. 1900 * This mode doesn't create new files, only alter existing ones. 1901 */ 1892 1902 $method = 'direct'; 1893 1903 $GLOBALS['_wp_filesystem_direct_method'] = 'relaxed_ownership'; … … 1906 1916 } 1907 1917 if ( ! $method && ( extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) ) { 1908 $method = 'ftpsockets'; // Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread1918 $method = 'ftpsockets'; // Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread. 1909 1919 } 1910 1920 … … 1999 2009 $submitted_form = wp_unslash( $_POST ); 2000 2010 2001 // Verify nonce, or unset submitted form field values on failure 2011 // Verify nonce, or unset submitted form field values on failure. 2002 2012 if ( ! isset( $_POST['_fs_nonce'] ) || ! wp_verify_nonce( $_POST['_fs_nonce'], 'filesystem-credentials' ) ) { 2003 2013 unset( … … 2011 2021 } 2012 2022 2013 // If defined, set it to that , Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)2023 // If defined, set it to that. Else, if POST'd, set it to that. If not, set it to whatever it previously was (saved details in option). 2014 2024 $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : ( ! empty( $submitted_form['hostname'] ) ? $submitted_form['hostname'] : $credentials['hostname'] ); 2015 2025 $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : ( ! empty( $submitted_form['username'] ) ? $submitted_form['username'] : $credentials['username'] ); 2016 2026 $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ( ! empty( $submitted_form['password'] ) ? $submitted_form['password'] : '' ); 2017 2027 2018 // Check to see if we are setting the public/private keys for ssh 2028 // Check to see if we are setting the public/private keys for ssh. 2019 2029 $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ( ! empty( $submitted_form['public_key'] ) ? $submitted_form['public_key'] : '' ); 2020 2030 $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ( ! empty( $submitted_form['private_key'] ) ? $submitted_form['private_key'] : '' ); 2021 2031 2022 // Sanitize the hostname, Some people might pass in odd-data:2023 $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); // Strip any schemes off2032 // Sanitize the hostname, some people might pass in odd data. 2033 $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); // Strip any schemes off. 2024 2034 2025 2035 if ( strpos( $credentials['hostname'], ':' ) ) { … … 2034 2044 if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) { 2035 2045 $credentials['connection_type'] = 'ssh'; 2036 } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { // Only the FTP Extension understands SSL2046 } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { // Only the FTP Extension understands SSL. 2037 2047 $credentials['connection_type'] = 'ftps'; 2038 2048 } elseif ( ! empty( $submitted_form['connection_type'] ) ) { 2039 2049 $credentials['connection_type'] = $submitted_form['connection_type']; 2040 } elseif ( ! isset( $credentials['connection_type'] ) ) { // All else fails (And it's not defaulted to something else saved), Default to FTP2050 } elseif ( ! isset( $credentials['connection_type'] ) ) { // All else fails (and it's not defaulted to something else saved), default to FTP. 2041 2051 $credentials['connection_type'] = 'ftp'; 2042 2052 } … … 2047 2057 ) ) { 2048 2058 $stored_credentials = $credentials; 2049 if ( ! empty( $stored_credentials['port'] ) ) { // save port as part of hostname to simplify above code.2059 if ( ! empty( $stored_credentials['port'] ) ) { // Save port as part of hostname to simplify above code. 2050 2060 $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; 2051 2061 } … … 2076 2086 $types['ftp'] = __( 'FTP' ); 2077 2087 } 2078 if ( extension_loaded( 'ftp' ) ) { // Only this supports FTPS2088 if ( extension_loaded( 'ftp' ) ) { // Only this supports FTPS. 2079 2089 $types['ftps'] = __( 'FTPS (SSL)' ); 2080 2090 }
Note: See TracChangeset
for help on using the changeset viewer.