}
/**
- * 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 ) {
* @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.
305 => 'Use Proxy',
306 => 'Reserved',
307 => 'Temporary Redirect',
+ 308 => 'Permanent Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot',
+ 421 => 'Misdirected Request',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
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',
}
/**
- * 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
*
* @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;
* @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'] );
+ }
+
+ $ref = wp_get_raw_referer();
- if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) )
+ 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;
}
*
* 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 );
}
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.
*
* '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(), $tested_paths = 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'];
+
+ if ( array_key_exists( $path, $tested_paths ) ) {
+ $uploads['error'] = $tested_paths[ $path ];
+ } else {
+ 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 ) );
+ }
+
+ $tested_paths[ $path ] = $uploads['error'];
+ }
+ }
+
+ 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' ) );
$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,
+ );
}
/**
$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" ) ) {
}
}
- return $filename;
+ /** This filter is documented in wp-includes/functions.php */
+ return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
}
/**
':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",
':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",
// 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",
* 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.
* 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.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
- trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class, $version, '<pre>__construct()</pre>' ) );
+ 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 <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
+ $class, $parent_class, $version, '<pre>__construct()</pre>' ) );
+ } else {
+ /* translators: 1: PHP class name, 2: version number, 3: __construct() method */
+ trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
+ $class, $version, '<pre>__construct()</pre>' ) );
+ }
} else {
- trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class, $version, '<pre>__construct()</pre>' ) );
+ if ( ! empty( $parent_class ) ) {
+ trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
+ $class, $parent_class, $version, '<pre>__construct()</pre>' ) );
+ } else {
+ trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
+ $class, $version, '<pre>__construct()</pre>' ) );
+ }
}
}
<div id="wp-auth-check-wrap" class="<?php echo $wrap_class; ?>">
<div id="wp-auth-check-bg"></div>
<div id="wp-auth-check">
- <div class="wp-auth-check-close" tabindex="0" title="<?php esc_attr_e('Close'); ?>"></div>
+ <button type="button" class="wp-auth-check-close button-link"><span class="screen-reader-text"><?php _e( 'Close dialog' ); ?></span></button>
<?php
if ( $same_domain ) {
?>
- <div id="wp-auth-check-form" data-src="<?php echo esc_url( add_query_arg( array( 'interim-login' => 1 ), $login_url ) ); ?>"></div>
+ <div id="wp-auth-check-form" class="loading" data-src="<?php echo esc_url( add_query_arg( array( 'interim-login' => 1 ), $login_url ) ); ?>"></div>
<?php
}