X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/03f2fa83c13c1b532284205fa7efcab9b8b2c41f..refs/tags/wordpress-4.5:/wp-includes/functions.php diff --git a/wp-includes/functions.php b/wp-includes/functions.php index e3fb3531..0e720ee1 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -172,6 +172,11 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { function wp_maybe_decline_date( $date ) { global $wp_locale; + // i18n functions are not available in SHORTINIT mode + if ( ! function_exists( '_x' ) ) { + return $date; + } + /* translators: If months in your language require a genitive case, * translate this to 'on'. Do not translate into your own language. */ @@ -200,14 +205,14 @@ function wp_maybe_decline_date( $date ) { } /** - * Convert integer number to format based on the locale. + * Convert float number to format based on the locale. * * @since 2.3.0 * * @global WP_Locale $wp_locale * - * @param int $number The number to convert based on locale. - * @param int $decimals Optional. Precision of the number of decimal places. Default 0. + * @param float $number The number to convert based on locale. + * @param int $decimals Optional. Precision of the number of decimal places. Default 0. * @return string Converted number in string format. */ function number_format_i18n( $number, $decimals = 0 ) { @@ -670,8 +675,8 @@ function is_new_day() { * @since 2.3.0 * * @see _http_build_query() Used to build the query - * @see http://us2.php.net/manual/en/function.http-build-query.php for more on what - * http_build_query() does. + * @link http://us2.php.net/manual/en/function.http-build-query.php for more on what + * http_build_query() does. * * @param array $data URL-encode key/value pairs. * @return string URL-encoded string. @@ -989,6 +994,7 @@ function get_status_header_desc( $code ) { 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect', + 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', @@ -1009,6 +1015,7 @@ function get_status_header_desc( $code ) { 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', + 421 => 'Misdirected Request', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', @@ -1016,6 +1023,7 @@ function get_status_header_desc( $code ) { 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', + 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', @@ -1326,7 +1334,7 @@ function do_robots() { } /** - * Test whether blog is already installed. + * Test whether WordPress is already installed. * * The cache will be checked first. If you have a cache plugin, which saves * the cache values, then this will work. If you use the default WordPress @@ -1338,7 +1346,7 @@ function do_robots() { * * @global wpdb $wpdb WordPress database abstraction object. * - * @return bool Whether the blog is already installed. + * @return bool Whether the site is already installed. */ function is_blog_installed() { global $wpdb; @@ -1512,16 +1520,35 @@ function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) { * @return false|string False on failure. Referer URL on success. */ function wp_get_referer() { - if ( ! function_exists( 'wp_validate_redirect' ) ) + if ( ! function_exists( 'wp_validate_redirect' ) ) { return false; - $ref = false; - if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) - $ref = wp_unslash( $_REQUEST['_wp_http_referer'] ); - elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) - $ref = wp_unslash( $_SERVER['HTTP_REFERER'] ); + } - if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) ) + $ref = wp_get_raw_referer(); + + if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) && $ref !== home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) ) { return wp_validate_redirect( $ref, false ); + } + + return false; +} + +/** + * Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer. + * + * Do not use for redirects, use {@see wp_get_referer()} instead. + * + * @since 4.5.0 + * + * @return string|false Referer URL on success, false on failure. + */ +function wp_get_raw_referer() { + if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { + return wp_unslash( $_REQUEST['_wp_http_referer'] ); + } else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { + return wp_unslash( $_SERVER['HTTP_REFERER'] ); + } + return false; } @@ -1660,17 +1687,19 @@ function path_join( $base, $path ) { * * On windows systems, replaces backslashes with forward slashes * and forces upper-case drive letters. - * Ensures that no duplicate slashes exist. + * Allows for two leading slashes for Windows network shares, but + * ensures that all other duplicate slashes are reduced to a single. * * @since 3.9.0 * @since 4.4.0 Ensures upper-case drive letters on Windows systems. + * @since 4.5.0 Allows for Windows network shares. * * @param string $path Path to normalize. * @return string Normalized path. */ function wp_normalize_path( $path ) { $path = str_replace( '\\', '/', $path ); - $path = preg_replace( '|/+|','/', $path ); + $path = preg_replace( '|(?<=.)/+|', '/', $path ); if ( ':' === substr( $path, 1, 1 ) ) { $path = ucfirst( $path ); } @@ -1772,6 +1801,23 @@ function win_is_writable( $path ) { return true; } +/** + * Retrieves uploads directory information. + * + * Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory. + * Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases + * when not uploading files. + * + * @since 4.5.0 + * + * @see wp_upload_dir() + * + * @return array See wp_upload_dir() for description. + */ +function wp_get_upload_dir() { + return wp_upload_dir( null, false ); +} + /** * Get an array containing the current upload directory's path and url. * @@ -1797,14 +1843,71 @@ function win_is_writable( $path ) { * 'subdir' - sub directory if uploads use year/month folders option is on. * 'basedir' - path without subdir. * 'baseurl' - URL path without subdir. - * 'error' - set to false. + * 'error' - false or error message. * * @since 2.0.0 + * @uses _wp_upload_dir() * * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. + * @param bool $create_dir Optional. Whether to check and create the uploads directory. Default true (backwards compatible). + * @param bool $refresh_cache Optional. Whether to refresh the cache. Default false. * @return array See above for description. */ -function wp_upload_dir( $time = null ) { +function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) { + static $cache = array(); + + $key = sprintf( '%d-%s', get_current_blog_id(), (string) $time ); + + if ( $refresh_cache || empty( $cache[ $key ] ) ) { + $cache[ $key ] = _wp_upload_dir( $time ); + } + + /** + * Filter the uploads directory data. + * + * @since 2.0.0 + * + * @param array $uploads Array of upload directory data with keys of 'path', + * 'url', 'subdir, 'basedir', and 'error'. + */ + $uploads = apply_filters( 'upload_dir', $cache[ $key ] ); + + if ( $create_dir ) { + $path = $uploads['path']; + $tested_paths = wp_cache_get( 'upload_dir_tested_paths' ); + + if ( ! is_array( $tested_paths ) ) { + $tested_paths = array(); + } + + if ( ! in_array( $path, $tested_paths, true ) ) { + if ( ! wp_mkdir_p( $path ) ) { + if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { + $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; + } else { + $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; + } + + $uploads['error'] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), esc_html( $error_path ) ); + } else { + $tested_paths[] = $path; + wp_cache_set( 'upload_dir_tested_paths', $tested_paths ); + } + } + } + + return $uploads; +} + +/** + * A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path. + * + * @access private + * + * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. + * @return array See wp_upload_dir() + */ +function _wp_upload_dir( $time = null ) { $siteurl = get_option( 'siteurl' ); $upload_path = trim( get_option( 'upload_path' ) ); @@ -1893,36 +1996,14 @@ function wp_upload_dir( $time = null ) { $dir .= $subdir; $url .= $subdir; - /** - * Filter the uploads directory data. - * - * @since 2.0.0 - * - * @param array $uploads Array of upload directory data with keys of 'path', - * 'url', 'subdir, 'basedir', and 'error'. - */ - $uploads = apply_filters( 'upload_dir', - array( - 'path' => $dir, - 'url' => $url, - 'subdir' => $subdir, - 'basedir' => $basedir, - 'baseurl' => $baseurl, - 'error' => false, - ) ); - - // Make sure we have an uploads directory. - if ( ! wp_mkdir_p( $uploads['path'] ) ) { - if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) - $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; - else - $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; - - $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); - $uploads['error'] = $message; - } - - return $uploads; + return array( + 'path' => $dir, + 'url' => $url, + 'subdir' => $subdir, + 'basedir' => $basedir, + 'baseurl' => $baseurl, + 'error' => false, + ); } /** @@ -1976,7 +2057,18 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 ); $number = $new_number; } - return $filename2; + + /** + * Filter the result when generating a unique file name. + * + * @since 4.5.0 + * + * @param string $filename Unique file name. + * @param string $ext File extension, eg. ".png". + * @param string $dir Directory path. + * @param callable|null $unique_filename_callback Callback function that generates the unique file name. + */ + return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback ); } while ( file_exists( $dir . "/$filename" ) ) { @@ -1988,7 +2080,8 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) } } - return $filename; + /** This filter is documented in wp-includes/functions.php */ + return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback ); } /** @@ -3114,7 +3207,7 @@ function smilies_init() { ':twisted:' => "\xf0\x9f\x98\x88", ':arrow:' => "\xe2\x9e\xa1", ':shock:' => "\xf0\x9f\x98\xaf", - ':smile:' => 'simple-smile.png', + ':smile:' => "\xf0\x9f\x99\x82", ':???:' => "\xf0\x9f\x98\x95", ':cool:' => "\xf0\x9f\x98\x8e", ':evil:' => "\xf0\x9f\x91\xbf", @@ -3128,11 +3221,11 @@ function smilies_init() { ':eek:' => "\xf0\x9f\x98\xae", ':lol:' => "\xf0\x9f\x98\x86", ':mad:' => "\xf0\x9f\x98\xa1", - ':sad:' => 'frownie.png', + ':sad:' => "\xf0\x9f\x99\x81", '8-)' => "\xf0\x9f\x98\x8e", '8-O' => "\xf0\x9f\x98\xaf", - ':-(' => 'frownie.png', - ':-)' => 'simple-smile.png', + ':-(' => "\xf0\x9f\x99\x81", + ':-)' => "\xf0\x9f\x99\x82", ':-?' => "\xf0\x9f\x98\x95", ':-D' => "\xf0\x9f\x98\x80", ':-P' => "\xf0\x9f\x98\x9b", @@ -3143,8 +3236,8 @@ function smilies_init() { // This one transformation breaks regular text with frequency. // '8)' => "\xf0\x9f\x98\x8e", '8O' => "\xf0\x9f\x98\xaf", - ':(' => 'frownie.png', - ':)' => 'simple-smile.png', + ':(' => "\xf0\x9f\x99\x81", + ':)' => "\xf0\x9f\x99\x82", ':?' => "\xf0\x9f\x98\x95", ':D' => "\xf0\x9f\x98\x80", ':P' => "\xf0\x9f\x98\x9b", @@ -3282,7 +3375,8 @@ function wp_is_numeric_array( $data ) { * against each object. Default empty array. * @param string $operator Optional. The logical operation to perform. 'or' means * only one element from the array needs to match; 'and' - * means all elements must match. Default 'and'. + * means all elements must match; 'not' means no elements may + * match. Default 'and'. * @param bool|string $field A field from the object to place instead of the entire object. * Default false. * @return array A list of objects or object fields. @@ -3588,22 +3682,28 @@ function _deprecated_function( $function, $version, $replacement = null ) { * This function is to be used in every PHP4 style constructor method that is deprecated. * * @since 4.3.0 + * @since 4.5.0 Added the `$parent_class` parameter. + * * @access private * - * @param string $class The class containing the deprecated constructor. - * @param string $version The version of WordPress that deprecated the function. + * @param string $class The class containing the deprecated constructor. + * @param string $version The version of WordPress that deprecated the function. + * @param string $parent_class Optional. The parent class calling the deprecated constructor. + * Default empty string. */ -function _deprecated_constructor( $class, $version ) { +function _deprecated_constructor( $class, $version, $parent_class = '' ) { /** * Fires when a deprecated constructor is called. * * @since 4.3.0 + * @since 4.5.0 Added the `$parent_class` parameter. * - * @param string $class The class containing the deprecated constructor. - * @param string $version The version of WordPress that deprecated the function. + * @param string $class The class containing the deprecated constructor. + * @param string $version The version of WordPress that deprecated the function. + * @param string $parent_class The parent class calling the deprecated constructor. */ - do_action( 'deprecated_constructor_run', $class, $version ); + do_action( 'deprecated_constructor_run', $class, $version, $parent_class ); /** * Filter whether to trigger an error for deprecated functions. @@ -3616,9 +3716,23 @@ function _deprecated_constructor( $class, $version ) { */ if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) { if ( function_exists( '__' ) ) { - trigger_error( sprintf( __( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.' ), $class, $version, '
__construct()
' ) ); + if ( ! empty( $parent_class ) ) { + /* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */ + trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is deprecated since version %3$s! Use %4$s instead.' ), + $class, $parent_class, $version, '
__construct()
' ) ); + } else { + /* translators: 1: PHP class name, 2: version number, 3: __construct() method */ + trigger_error( sprintf( __( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.' ), + $class, $version, '
__construct()
' ) ); + } } else { - trigger_error( sprintf( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.', $class, $version, '
__construct()
' ) ); + if ( ! empty( $parent_class ) ) { + trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is deprecated since version %3$s! Use %4$s instead.', + $class, $parent_class, $version, '
__construct()
' ) ); + } else { + trigger_error( sprintf( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.', + $class, $version, '
__construct()
' ) ); + } } } @@ -4929,12 +5043,12 @@ function wp_auth_check_html() {
-
+ -
+