wp/wp-includes/functions.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
     2 /**
     2 /**
     3  * Main WordPress API
     3  * Main WordPress API
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
       
     7 
       
     8 // Don't load directly.
       
     9 if ( ! defined( 'ABSPATH' ) ) {
       
    10 	die( '-1' );
       
    11 }
     7 
    12 
     8 require ABSPATH . WPINC . '/option.php';
    13 require ABSPATH . WPINC . '/option.php';
     9 
    14 
    10 /**
    15 /**
    11  * Converts given MySQL date string into a different format.
    16  * Converts given MySQL date string into a different format.
    71  * @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
    76  * @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
    72  */
    77  */
    73 function current_time( $type, $gmt = 0 ) {
    78 function current_time( $type, $gmt = 0 ) {
    74 	// Don't use non-GMT timestamp, unless you know the difference and really need to.
    79 	// Don't use non-GMT timestamp, unless you know the difference and really need to.
    75 	if ( 'timestamp' === $type || 'U' === $type ) {
    80 	if ( 'timestamp' === $type || 'U' === $type ) {
    76 		return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    81 		return $gmt ? time() : time() + (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    77 	}
    82 	}
    78 
    83 
    79 	if ( 'mysql' === $type ) {
    84 	if ( 'mysql' === $type ) {
    80 		$type = 'Y-m-d H:i:s';
    85 		$type = 'Y-m-d H:i:s';
    81 	}
    86 	}
   592 
   597 
   593 	// The timestamp for MySQL string day.
   598 	// The timestamp for MySQL string day.
   594 	$day = mktime( 0, 0, 0, $md, $mm, $my );
   599 	$day = mktime( 0, 0, 0, $md, $mm, $my );
   595 
   600 
   596 	// The day of the week from the timestamp.
   601 	// The day of the week from the timestamp.
   597 	$weekday = gmdate( 'w', $day );
   602 	$weekday = (int) gmdate( 'w', $day );
   598 
   603 
   599 	if ( ! is_numeric( $start_of_week ) ) {
   604 	if ( ! is_numeric( $start_of_week ) ) {
   600 		$start_of_week = get_option( 'start_of_week' );
   605 		$start_of_week = (int) get_option( 'start_of_week' );
   601 	}
   606 	}
   602 
   607 
   603 	if ( $weekday < $start_of_week ) {
   608 	if ( $weekday < $start_of_week ) {
   604 		$weekday += 7;
   609 		$weekday += 7;
   605 	}
   610 	}
   607 	// The most recent week start day on or before $day.
   612 	// The most recent week start day on or before $day.
   608 	$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
   613 	$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
   609 
   614 
   610 	// $start + 1 week - 1 second.
   615 	// $start + 1 week - 1 second.
   611 	$end = $start + WEEK_IN_SECONDS - 1;
   616 	$end = $start + WEEK_IN_SECONDS - 1;
       
   617 
   612 	return compact( 'start', 'end' );
   618 	return compact( 'start', 'end' );
   613 }
   619 }
   614 
   620 
   615 /**
   621 /**
   616  * Serializes data, if needed.
   622  * Serializes data, if needed.
  1481 
  1487 
  1482 /**
  1488 /**
  1483  * Gets the HTTP header information to prevent caching.
  1489  * Gets the HTTP header information to prevent caching.
  1484  *
  1490  *
  1485  * The several different headers cover the different ways cache prevention
  1491  * The several different headers cover the different ways cache prevention
  1486  * is handled by different browsers.
  1492  * is handled by different browsers or intermediate caches such as proxy servers.
  1487  *
  1493  *
  1488  * @since 2.8.0
  1494  * @since 2.8.0
  1489  * @since 6.3.0 The `Cache-Control` header for logged in users now includes the
  1495  * @since 6.3.0 The `Cache-Control` header for logged in users now includes the
  1490  *              `no-store` and `private` directives.
  1496  *              `no-store` and `private` directives.
       
  1497  * @since 6.8.0 The `Cache-Control` header now includes the `no-store` and `private`
       
  1498  *              directives regardless of whether a user is logged in.
  1491  *
  1499  *
  1492  * @return array The associative array of header names and field values.
  1500  * @return array The associative array of header names and field values.
  1493  */
  1501  */
  1494 function wp_get_nocache_headers() {
  1502 function wp_get_nocache_headers() {
  1495 	$cache_control = ( function_exists( 'is_user_logged_in' ) && is_user_logged_in() )
  1503 	$cache_control = 'no-cache, must-revalidate, max-age=0, no-store, private';
  1496 		? 'no-cache, must-revalidate, max-age=0, no-store, private'
       
  1497 		: 'no-cache, must-revalidate, max-age=0';
       
  1498 
  1504 
  1499 	$headers = array(
  1505 	$headers = array(
  1500 		'Expires'       => 'Wed, 11 Jan 1984 05:00:00 GMT',
  1506 		'Expires'       => 'Wed, 11 Jan 1984 05:00:00 GMT',
  1501 		'Cache-Control' => $cache_control,
  1507 		'Cache-Control' => $cache_control,
  1502 	);
  1508 	);
  1707 	 * @since 2.1.0
  1713 	 * @since 2.1.0
  1708 	 */
  1714 	 */
  1709 	do_action( 'do_robotstxt' );
  1715 	do_action( 'do_robotstxt' );
  1710 
  1716 
  1711 	$output = "User-agent: *\n";
  1717 	$output = "User-agent: *\n";
  1712 	$public = get_option( 'blog_public' );
  1718 	$public = (bool) get_option( 'blog_public' );
  1713 
  1719 
  1714 	$site_url = parse_url( site_url() );
  1720 	$site_url = parse_url( site_url() );
  1715 	$path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
  1721 	$path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
  1716 	$output  .= "Disallow: $path/wp-admin/\n";
  1722 	$output  .= "Disallow: $path/wp-admin/\n";
  1717 	$output  .= "Allow: $path/wp-admin/admin-ajax.php\n";
  1723 	$output  .= "Allow: $path/wp-admin/admin-ajax.php\n";
  2255  *
  2261  *
  2256  * @param string $path Path to check for write-ability.
  2262  * @param string $path Path to check for write-ability.
  2257  * @return bool Whether the path is writable.
  2263  * @return bool Whether the path is writable.
  2258  */
  2264  */
  2259 function wp_is_writable( $path ) {
  2265 function wp_is_writable( $path ) {
  2260 	if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
  2266 	if ( 'Windows' === PHP_OS_FAMILY ) {
  2261 		return win_is_writable( $path );
  2267 		return win_is_writable( $path );
  2262 	} else {
  2268 	}
  2263 		return @is_writable( $path );
  2269 
  2264 	}
  2270 	return @is_writable( $path );
  2265 }
  2271 }
  2266 
  2272 
  2267 /**
  2273 /**
  2268  * Workaround for Windows bug in is_writable() function
  2274  * Workaround for Windows bug in is_writable() function
  2269  *
  2275  *
  2704 		/*
  2710 		/*
  2705 		 * Check if an image will be converted after uploading or some existing image sub-size file names may conflict
  2711 		 * Check if an image will be converted after uploading or some existing image sub-size file names may conflict
  2706 		 * when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes.
  2712 		 * when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes.
  2707 		 */
  2713 		 */
  2708 		if ( $is_image ) {
  2714 		if ( $is_image ) {
  2709 			/** This filter is documented in wp-includes/class-wp-image-editor.php */
  2715 			$output_formats = wp_get_image_editor_output_format( $_dir . $filename, $mime_type );
  2710 			$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type );
       
  2711 			$alt_types      = array();
  2716 			$alt_types      = array();
  2712 
  2717 
  2713 			if ( ! empty( $output_formats[ $mime_type ] ) ) {
  2718 			if ( ! empty( $output_formats[ $mime_type ] ) ) {
  2714 				// The image will be converted to this format/mime type.
  2719 				// The image will be converted to this format/mime type.
  2715 				$alt_mime_type = $output_formats[ $mime_type ];
  2720 				$alt_mime_type = $output_formats[ $mime_type ];
  3100 	if ( $type && str_starts_with( $type, 'image/' ) ) {
  3105 	if ( $type && str_starts_with( $type, 'image/' ) ) {
  3101 
  3106 
  3102 		// Attempt to figure out what type of image it actually is.
  3107 		// Attempt to figure out what type of image it actually is.
  3103 		$real_mime = wp_get_image_mime( $file );
  3108 		$real_mime = wp_get_image_mime( $file );
  3104 
  3109 
  3105 		if ( $real_mime && $real_mime !== $type ) {
  3110 		$heic_images_extensions = array(
       
  3111 			'heif',
       
  3112 			'heics',
       
  3113 			'heifs',
       
  3114 		);
       
  3115 
       
  3116 		if ( $real_mime && ( $real_mime !== $type || in_array( $ext, $heic_images_extensions, true ) ) ) {
  3106 			/**
  3117 			/**
  3107 			 * Filters the list mapping image mime types to their respective extensions.
  3118 			 * Filters the list mapping image mime types to their respective extensions.
  3108 			 *
  3119 			 *
  3109 			 * @since 3.0.0
  3120 			 * @since 3.0.0
  3110 			 *
  3121 			 *
  3111 			 * @param array $mime_to_ext Array of image mime types and their matching extensions.
  3122 			 * @param array $mime_to_ext Array of image mime types and their matching extensions.
  3112 			 */
  3123 			 */
  3113 			$mime_to_ext = apply_filters(
  3124 			$mime_to_ext = apply_filters(
  3114 				'getimagesize_mimes_to_exts',
  3125 				'getimagesize_mimes_to_exts',
  3115 				array(
  3126 				array(
  3116 					'image/jpeg' => 'jpg',
  3127 					'image/jpeg'          => 'jpg',
  3117 					'image/png'  => 'png',
  3128 					'image/png'           => 'png',
  3118 					'image/gif'  => 'gif',
  3129 					'image/gif'           => 'gif',
  3119 					'image/bmp'  => 'bmp',
  3130 					'image/bmp'           => 'bmp',
  3120 					'image/tiff' => 'tif',
  3131 					'image/tiff'          => 'tif',
  3121 					'image/webp' => 'webp',
  3132 					'image/webp'          => 'webp',
  3122 					'image/avif' => 'avif',
  3133 					'image/avif'          => 'avif',
       
  3134 
       
  3135 					/*
       
  3136 					 * In theory there are/should be file extensions that correspond to the
       
  3137 					 * mime types: .heif, .heics and .heifs. However it seems that HEIC images
       
  3138 					 * with any of the mime types commonly have a .heic file extension.
       
  3139 					 * Seems keeping the status quo here is best for compatibility.
       
  3140 					 */
       
  3141 					'image/heic'          => 'heic',
       
  3142 					'image/heif'          => 'heic',
       
  3143 					'image/heic-sequence' => 'heic',
       
  3144 					'image/heif-sequence' => 'heic',
  3123 				)
  3145 				)
  3124 			);
  3146 			);
  3125 
  3147 
  3126 			// Replace whatever is after the last period in the filename with the correct extension.
  3148 			// Replace whatever is after the last period in the filename with the correct extension.
  3127 			if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
  3149 			if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
  3128 				$filename_parts = explode( '.', $filename );
  3150 				$filename_parts = explode( '.', $filename );
       
  3151 
  3129 				array_pop( $filename_parts );
  3152 				array_pop( $filename_parts );
  3130 				$filename_parts[] = $mime_to_ext[ $real_mime ];
  3153 				$filename_parts[] = $mime_to_ext[ $real_mime ];
  3131 				$new_filename     = implode( '.', $filename_parts );
  3154 				$new_filename     = implode( '.', $filename_parts );
  3132 
  3155 
  3133 				if ( $new_filename !== $filename ) {
  3156 				if ( $new_filename !== $filename ) {
  3297  * This depends on exif_imagetype() or getimagesize() to determine real mime types.
  3320  * This depends on exif_imagetype() or getimagesize() to determine real mime types.
  3298  *
  3321  *
  3299  * @since 4.7.1
  3322  * @since 4.7.1
  3300  * @since 5.8.0 Added support for WebP images.
  3323  * @since 5.8.0 Added support for WebP images.
  3301  * @since 6.5.0 Added support for AVIF images.
  3324  * @since 6.5.0 Added support for AVIF images.
       
  3325  * @since 6.7.0 Added support for HEIC images.
  3302  *
  3326  *
  3303  * @param string $file Full path to the file.
  3327  * @param string $file Full path to the file.
  3304  * @return string|false The actual mime type or false if the type cannot be determined.
  3328  * @return string|false The actual mime type or false if the type cannot be determined.
  3305  */
  3329  */
  3306 function wp_get_image_mime( $file ) {
  3330 function wp_get_image_mime( $file ) {
  3313 		if ( is_callable( 'exif_imagetype' ) ) {
  3337 		if ( is_callable( 'exif_imagetype' ) ) {
  3314 			$imagetype = exif_imagetype( $file );
  3338 			$imagetype = exif_imagetype( $file );
  3315 			$mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
  3339 			$mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
  3316 		} elseif ( function_exists( 'getimagesize' ) ) {
  3340 		} elseif ( function_exists( 'getimagesize' ) ) {
  3317 			// Don't silence errors when in debug mode, unless running unit tests.
  3341 			// Don't silence errors when in debug mode, unless running unit tests.
  3318 			if ( defined( 'WP_DEBUG' ) && WP_DEBUG
  3342 			if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! defined( 'WP_RUN_CORE_TESTS' ) ) {
  3319 				&& ! defined( 'WP_RUN_CORE_TESTS' )
       
  3320 			) {
       
  3321 				// Not using wp_getimagesize() here to avoid an infinite loop.
  3343 				// Not using wp_getimagesize() here to avoid an infinite loop.
  3322 				$imagesize = getimagesize( $file );
  3344 				$imagesize = getimagesize( $file );
  3323 			} else {
  3345 			} else {
  3324 				$imagesize = @getimagesize( $file );
  3346 				$imagesize = @getimagesize( $file );
  3325 			}
  3347 			}
  3362 		 */
  3384 		 */
  3363 
  3385 
  3364 		// Divide the header string into 4 byte groups.
  3386 		// Divide the header string into 4 byte groups.
  3365 		$magic = str_split( $magic, 8 );
  3387 		$magic = str_split( $magic, 8 );
  3366 
  3388 
  3367 		if (
  3389 		if ( isset( $magic[1] ) && isset( $magic[2] ) && 'ftyp' === hex2bin( $magic[1] ) ) {
  3368 			isset( $magic[1] ) &&
  3390 			if ( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) ) {
  3369 			isset( $magic[2] ) &&
  3391 				$mime = 'image/avif';
  3370 			'ftyp' === hex2bin( $magic[1] ) &&
  3392 			} elseif ( 'heic' === hex2bin( $magic[2] ) ) {
  3371 			( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) )
  3393 				$mime = 'image/heic';
  3372 		) {
  3394 			} elseif ( 'heif' === hex2bin( $magic[2] ) ) {
  3373 			$mime = 'image/avif';
  3395 				$mime = 'image/heif';
       
  3396 			} else {
       
  3397 				/*
       
  3398 				 * HEIC/HEIF images and image sequences/animations may have other strings here
       
  3399 				 * like mif1, msf1, etc. For now fall back to using finfo_file() to detect these.
       
  3400 				 */
       
  3401 				if ( extension_loaded( 'fileinfo' ) ) {
       
  3402 					$fileinfo  = finfo_open( FILEINFO_MIME_TYPE );
       
  3403 					$mime_type = finfo_file( $fileinfo, $file );
       
  3404 					finfo_close( $fileinfo );
       
  3405 
       
  3406 					if ( wp_is_heic_image_mime_type( $mime_type ) ) {
       
  3407 						$mime = $mime_type;
       
  3408 					}
       
  3409 				}
       
  3410 			}
  3374 		}
  3411 		}
  3375 	} catch ( Exception $e ) {
  3412 	} catch ( Exception $e ) {
  3376 		$mime = false;
  3413 		$mime = false;
  3377 	}
  3414 	}
  3378 
  3415 
  3384  *
  3421  *
  3385  * @since 3.5.0
  3422  * @since 3.5.0
  3386  * @since 4.2.0 Support was added for GIMP (.xcf) files.
  3423  * @since 4.2.0 Support was added for GIMP (.xcf) files.
  3387  * @since 4.9.2 Support was added for Flac (.flac) files.
  3424  * @since 4.9.2 Support was added for Flac (.flac) files.
  3388  * @since 4.9.6 Support was added for AAC (.aac) files.
  3425  * @since 4.9.6 Support was added for AAC (.aac) files.
       
  3426  * @since 6.8.0 Support was added for `audio/x-wav`.
  3389  *
  3427  *
  3390  * @return string[] Array of mime types keyed by the file extension regex corresponding to those types.
  3428  * @return string[] Array of mime types keyed by the file extension regex corresponding to those types.
  3391  */
  3429  */
  3392 function wp_get_mime_types() {
  3430 function wp_get_mime_types() {
  3393 	/**
  3431 	/**
  3411 			'bmp'                          => 'image/bmp',
  3449 			'bmp'                          => 'image/bmp',
  3412 			'tiff|tif'                     => 'image/tiff',
  3450 			'tiff|tif'                     => 'image/tiff',
  3413 			'webp'                         => 'image/webp',
  3451 			'webp'                         => 'image/webp',
  3414 			'avif'                         => 'image/avif',
  3452 			'avif'                         => 'image/avif',
  3415 			'ico'                          => 'image/x-icon',
  3453 			'ico'                          => 'image/x-icon',
       
  3454 
       
  3455 			// TODO: Needs improvement. All images with the following mime types seem to have .heic file extension.
  3416 			'heic'                         => 'image/heic',
  3456 			'heic'                         => 'image/heic',
       
  3457 			'heif'                         => 'image/heif',
       
  3458 			'heics'                        => 'image/heic-sequence',
       
  3459 			'heifs'                        => 'image/heif-sequence',
       
  3460 
  3417 			// Video formats.
  3461 			// Video formats.
  3418 			'asf|asx'                      => 'video/x-ms-asf',
  3462 			'asf|asx'                      => 'video/x-ms-asf',
  3419 			'wmv'                          => 'video/x-ms-wmv',
  3463 			'wmv'                          => 'video/x-ms-wmv',
  3420 			'wmx'                          => 'video/x-ms-wmx',
  3464 			'wmx'                          => 'video/x-ms-wmx',
  3421 			'wm'                           => 'video/x-ms-wm',
  3465 			'wm'                           => 'video/x-ms-wm',
  3442 			'dfxp'                         => 'application/ttaf+xml',
  3486 			'dfxp'                         => 'application/ttaf+xml',
  3443 			// Audio formats.
  3487 			// Audio formats.
  3444 			'mp3|m4a|m4b'                  => 'audio/mpeg',
  3488 			'mp3|m4a|m4b'                  => 'audio/mpeg',
  3445 			'aac'                          => 'audio/aac',
  3489 			'aac'                          => 'audio/aac',
  3446 			'ra|ram'                       => 'audio/x-realaudio',
  3490 			'ra|ram'                       => 'audio/x-realaudio',
  3447 			'wav'                          => 'audio/wav',
  3491 			'wav|x-wav'                    => 'audio/wav',
  3448 			'ogg|oga'                      => 'audio/ogg',
  3492 			'ogg|oga'                      => 'audio/ogg',
  3449 			'flac'                         => 'audio/flac',
  3493 			'flac'                         => 'audio/flac',
  3450 			'mid|midi'                     => 'audio/midi',
  3494 			'mid|midi'                     => 'audio/midi',
  3451 			'wma'                          => 'audio/x-ms-wma',
  3495 			'wma'                          => 'audio/x-ms-wma',
  3452 			'wax'                          => 'audio/x-ms-wax',
  3496 			'wax'                          => 'audio/x-ms-wax',
  3531 	 * @param array[] $ext2type Multi-dimensional array of file extensions types keyed by the type of file.
  3575 	 * @param array[] $ext2type Multi-dimensional array of file extensions types keyed by the type of file.
  3532 	 */
  3576 	 */
  3533 	return apply_filters(
  3577 	return apply_filters(
  3534 		'ext2type',
  3578 		'ext2type',
  3535 		array(
  3579 		array(
  3536 			'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp', 'avif' ),
  3580 			'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'heif', 'webp', 'avif' ),
  3537 			'audio'       => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
  3581 			'audio'       => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
  3538 			'video'       => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ),
  3582 			'video'       => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ),
  3539 			'document'    => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ),
  3583 			'document'    => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ),
  3540 			'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ),
  3584 			'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ),
  3541 			'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ),
  3585 			'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ),
  3626  *
  3670  *
  3627  * @param string $action The nonce action.
  3671  * @param string $action The nonce action.
  3628  */
  3672  */
  3629 function wp_nonce_ays( $action ) {
  3673 function wp_nonce_ays( $action ) {
  3630 	// Default title and response code.
  3674 	// Default title and response code.
  3631 	$title         = __( 'Something went wrong.' );
  3675 	$title         = __( 'An error occurred.' );
  3632 	$response_code = 403;
  3676 	$response_code = 403;
  3633 
  3677 
  3634 	if ( 'log-out' === $action ) {
  3678 	if ( 'log-out' === $action ) {
  3635 		$title = sprintf(
  3679 		$title = sprintf(
  3636 			/* translators: %s: Site title. */
  3680 			/* translators: %s: Site title. */
  3856 		?>
  3900 		?>
  3857 <!DOCTYPE html>
  3901 <!DOCTYPE html>
  3858 <html <?php echo $dir_attr; ?>>
  3902 <html <?php echo $dir_attr; ?>>
  3859 <head>
  3903 <head>
  3860 	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $parsed_args['charset']; ?>" />
  3904 	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $parsed_args['charset']; ?>" />
  3861 	<meta name="viewport" content="width=device-width">
  3905 	<meta name="viewport" content="width=device-width, initial-scale=1.0">
  3862 		<?php
  3906 		<?php
  3863 		if ( function_exists( 'wp_robots' ) && function_exists( 'wp_robots_no_robots' ) && function_exists( 'add_filter' ) ) {
  3907 		if ( function_exists( 'wp_robots' ) && function_exists( 'wp_robots_no_robots' ) && function_exists( 'add_filter' ) ) {
  3864 			add_filter( 'wp_robots', 'wp_robots_no_robots' );
  3908 			add_filter( 'wp_robots', 'wp_robots_no_robots' );
  3865 			// Prevent warnings because of $wp_query not existing.
  3909 			// Prevent warnings because of $wp_query not existing.
  3866 			remove_filter( 'wp_robots', 'wp_robots_noindex_embeds' );
  3910 			remove_filter( 'wp_robots', 'wp_robots_noindex_embeds' );
  4693  *
  4737  *
  4694  * @since 4.7.0
  4738  * @since 4.7.0
  4695  * @access private
  4739  * @access private
  4696  */
  4740  */
  4697 function _delete_option_fresh_site() {
  4741 function _delete_option_fresh_site() {
  4698 	update_option( 'fresh_site', '0' );
  4742 	update_option( 'fresh_site', '0', false );
  4699 }
  4743 }
  4700 
  4744 
  4701 /**
  4745 /**
  4702  * Sets the localized direction for MCE plugin.
  4746  * Sets the localized direction for MCE plugin.
  4703  *
  4747  *
  5465 	// Otherwise, be terse.
  5509 	// Otherwise, be terse.
  5466 	wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
  5510 	wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
  5467 }
  5511 }
  5468 
  5512 
  5469 /**
  5513 /**
  5470  * Converts a value to non-negative integer.
       
  5471  *
       
  5472  * @since 2.5.0
       
  5473  *
       
  5474  * @param mixed $maybeint Data you wish to have converted to a non-negative integer.
       
  5475  * @return int A non-negative integer.
       
  5476  */
       
  5477 function absint( $maybeint ) {
       
  5478 	return abs( (int) $maybeint );
       
  5479 }
       
  5480 
       
  5481 /**
       
  5482  * Marks a function as deprecated and inform when it has been used.
  5514  * Marks a function as deprecated and inform when it has been used.
  5483  *
  5515  *
  5484  * There is a {@see 'deprecated_function_run'} hook that will be called that can be used
  5516  * There is a {@see 'deprecated_function_run'} hook that will be called that can be used
  5485  * to get the backtrace up to what file and function called the deprecated function.
  5517  * to get the backtrace up to what file and function called the deprecated function.
  5486  *
  5518  *
  6080 			'strong' => array(),
  6112 			'strong' => array(),
  6081 		),
  6113 		),
  6082 		array( 'http', 'https' )
  6114 		array( 'http', 'https' )
  6083 	);
  6115 	);
  6084 
  6116 
       
  6117 	if ( E_USER_ERROR === $error_level ) {
       
  6118 		throw new WP_Exception( $message );
       
  6119 	}
       
  6120 
  6085 	trigger_error( $message, $error_level );
  6121 	trigger_error( $message, $error_level );
  6086 }
  6122 }
  6087 
  6123 
  6088 /**
  6124 /**
  6089  * Determines whether the server is running an earlier than 1.5.0 version of lighttpd.
  6125  * Determines whether the server is running an earlier than 1.5.0 version of lighttpd.
  6235 /**
  6271 /**
  6236  * Determines whether to force SSL used for the Administration Screens.
  6272  * Determines whether to force SSL used for the Administration Screens.
  6237  *
  6273  *
  6238  * @since 2.6.0
  6274  * @since 2.6.0
  6239  *
  6275  *
  6240  * @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
  6276  * @param string|bool|null $force Optional. Whether to force SSL in admin screens. Default null.
  6241  * @return bool True if forced, false if not forced.
  6277  * @return bool True if forced, false if not forced.
  6242  */
  6278  */
  6243 function force_ssl_admin( $force = null ) {
  6279 function force_ssl_admin( $force = null ) {
  6244 	static $forced = false;
  6280 	static $forced = false;
  6245 
  6281 
  6246 	if ( ! is_null( $force ) ) {
  6282 	if ( ! is_null( $force ) ) {
  6247 		$old_forced = $forced;
  6283 		$old_forced = $forced;
  6248 		$forced     = $force;
  6284 		$forced     = (bool) $force;
  6249 		return $old_forced;
  6285 		return $old_forced;
  6250 	}
  6286 	}
  6251 
  6287 
  6252 	return $forced;
  6288 	return $forced;
  6253 }
  6289 }
  7107 function send_frame_options_header() {
  7143 function send_frame_options_header() {
  7108 	header( 'X-Frame-Options: SAMEORIGIN' );
  7144 	header( 'X-Frame-Options: SAMEORIGIN' );
  7109 }
  7145 }
  7110 
  7146 
  7111 /**
  7147 /**
       
  7148  * Sends a referrer policy header so referrers are not sent externally from administration screens.
       
  7149  *
       
  7150  * @since 4.9.0
       
  7151  * @since 6.8.0 This function was moved from `wp-admin/includes/misc.php` to `wp-includes/functions.php`.
       
  7152  */
       
  7153 function wp_admin_headers() {
       
  7154 	$policy = 'strict-origin-when-cross-origin';
       
  7155 
       
  7156 	/**
       
  7157 	 * Filters the admin referrer policy header value.
       
  7158 	 *
       
  7159 	 * @since 4.9.0
       
  7160 	 * @since 4.9.5 The default value was changed to 'strict-origin-when-cross-origin'.
       
  7161 	 *
       
  7162 	 * @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
       
  7163 	 *
       
  7164 	 * @param string $policy The admin referrer policy header value. Default 'strict-origin-when-cross-origin'.
       
  7165 	 */
       
  7166 	$policy = apply_filters( 'admin_referrer_policy', $policy );
       
  7167 
       
  7168 	header( sprintf( 'Referrer-Policy: %s', $policy ) );
       
  7169 }
       
  7170 
       
  7171 /**
  7112  * Retrieves a list of protocols to allow in HTML attributes.
  7172  * Retrieves a list of protocols to allow in HTML attributes.
  7113  *
  7173  *
  7114  * @since 3.3.0
  7174  * @since 3.3.0
  7115  * @since 4.3.0 Added 'webcal' to the protocols array.
  7175  * @since 4.3.0 Added 'webcal' to the protocols array.
  7116  * @since 4.7.0 Added 'urn' to the protocols array.
  7176  * @since 4.7.0 Added 'urn' to the protocols array.
  7633 
  7693 
  7634 /**
  7694 /**
  7635  * Deletes a file.
  7695  * Deletes a file.
  7636  *
  7696  *
  7637  * @since 4.2.0
  7697  * @since 4.2.0
       
  7698  * @since 6.7.0 A return value was added.
  7638  *
  7699  *
  7639  * @param string $file The path to the file to delete.
  7700  * @param string $file The path to the file to delete.
       
  7701  * @return bool True on success, false on failure.
  7640  */
  7702  */
  7641 function wp_delete_file( $file ) {
  7703 function wp_delete_file( $file ) {
  7642 	/**
  7704 	/**
  7643 	 * Filters the path of the file to delete.
  7705 	 * Filters the path of the file to delete.
  7644 	 *
  7706 	 *
  7645 	 * @since 2.1.0
  7707 	 * @since 2.1.0
  7646 	 *
  7708 	 *
  7647 	 * @param string $file Path to the file to delete.
  7709 	 * @param string $file Path to the file to delete.
  7648 	 */
  7710 	 */
  7649 	$delete = apply_filters( 'wp_delete_file', $file );
  7711 	$delete = apply_filters( 'wp_delete_file', $file );
       
  7712 
  7650 	if ( ! empty( $delete ) ) {
  7713 	if ( ! empty( $delete ) ) {
  7651 		@unlink( $delete );
  7714 		return @unlink( $delete );
  7652 	}
  7715 	}
       
  7716 
       
  7717 	return false;
  7653 }
  7718 }
  7654 
  7719 
  7655 /**
  7720 /**
  7656  * Deletes a file if its path is within the given directory.
  7721  * Deletes a file if its path is within the given directory.
  7657  *
  7722  *
  7680 
  7745 
  7681 	if ( false === $real_file || false === $real_directory || ! str_starts_with( $real_file, trailingslashit( $real_directory ) ) ) {
  7746 	if ( false === $real_file || false === $real_directory || ! str_starts_with( $real_file, trailingslashit( $real_directory ) ) ) {
  7682 		return false;
  7747 		return false;
  7683 	}
  7748 	}
  7684 
  7749 
  7685 	wp_delete_file( $file );
  7750 	return wp_delete_file( $file );
  7686 
       
  7687 	return true;
       
  7688 }
  7751 }
  7689 
  7752 
  7690 /**
  7753 /**
  7691  * Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page.
  7754  * Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page.
  7692  *
  7755  *
  8005 	 * This may occur multiple times per page load and registered
  8068 	 * This may occur multiple times per page load and registered
  8006 	 * actions must be performant.
  8069 	 * actions must be performant.
  8007 	 *
  8070 	 *
  8008 	 * @since 6.3.0
  8071 	 * @since 6.3.0
  8009 	 *
  8072 	 *
  8010 	 * @param string    $group         The cache group name.
  8073 	 * @param string       $group         The cache group name.
  8011 	 * @param int       $time          The new last changed time.
  8074 	 * @param string       $time          The new last changed time (msec sec).
  8012 	 * @param int|false $previous_time The previous last changed time. False if not previously set.
  8075 	 * @param string|false $previous_time The previous last changed time. False if not previously set.
  8013 	 */
  8076 	 */
  8014 	do_action( 'wp_cache_set_last_changed', $group, $time, $previous_time );
  8077 	do_action( 'wp_cache_set_last_changed', $group, $time, $previous_time );
  8015 
  8078 
  8016 	return $time;
  8079 	return $time;
  8017 }
  8080 }
  8498 		return;
  8561 		return;
  8499 	}
  8562 	}
  8500 
  8563 
  8501 	echo '<p class="button-container">';
  8564 	echo '<p class="button-container">';
  8502 	printf(
  8565 	printf(
  8503 		'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
  8566 		'<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
  8504 		esc_url( $direct_update_url ),
  8567 		esc_url( $direct_update_url ),
  8505 		__( 'Update PHP' ),
  8568 		__( 'Update PHP' ),
  8506 		/* translators: Hidden accessibility text. */
  8569 		/* translators: Hidden accessibility text. */
  8507 		__( '(opens in a new tab)' )
  8570 		__( '(opens in a new tab)' )
  8508 	);
  8571 	);
  8803 
  8866 
  8804 	set_transient( 'dirsize_cache', $directory_cache, $expiration );
  8867 	set_transient( 'dirsize_cache', $directory_cache, $expiration );
  8805 }
  8868 }
  8806 
  8869 
  8807 /**
  8870 /**
       
  8871  * Returns the current WordPress version.
       
  8872  *
       
  8873  * Returns an unmodified value of `$wp_version`. Some plugins modify the global
       
  8874  * in an attempt to improve security through obscurity. This practice can cause
       
  8875  * errors in WordPress, so the ability to get an unmodified version is needed.
       
  8876  *
       
  8877  * @since 6.7.0
       
  8878  *
       
  8879  * @return string The current WordPress version.
       
  8880  */
       
  8881 function wp_get_wp_version() {
       
  8882 	static $wp_version;
       
  8883 
       
  8884 	if ( ! isset( $wp_version ) ) {
       
  8885 		require ABSPATH . WPINC . '/version.php';
       
  8886 	}
       
  8887 
       
  8888 	return $wp_version;
       
  8889 }
       
  8890 
       
  8891 /**
  8808  * Checks compatibility with the current WordPress version.
  8892  * Checks compatibility with the current WordPress version.
  8809  *
  8893  *
  8810  * @since 5.2.0
  8894  * @since 5.2.0
  8811  *
  8895  *
  8812  * @global string $wp_version The WordPress version string.
  8896  * @global string $_wp_tests_wp_version The WordPress version string. Used only in Core tests.
  8813  *
  8897  *
  8814  * @param string $required Minimum required WordPress version.
  8898  * @param string $required Minimum required WordPress version.
  8815  * @return bool True if required version is compatible or empty, false if not.
  8899  * @return bool True if required version is compatible or empty, false if not.
  8816  */
  8900  */
  8817 function is_wp_version_compatible( $required ) {
  8901 function is_wp_version_compatible( $required ) {
  8818 	global $wp_version;
  8902 	if (
       
  8903 		defined( 'WP_RUN_CORE_TESTS' )
       
  8904 		&& WP_RUN_CORE_TESTS
       
  8905 		&& isset( $GLOBALS['_wp_tests_wp_version'] )
       
  8906 	) {
       
  8907 		$wp_version = $GLOBALS['_wp_tests_wp_version'];
       
  8908 	} else {
       
  8909 		$wp_version = wp_get_wp_version();
       
  8910 	}
  8819 
  8911 
  8820 	// Strip off any -alpha, -RC, -beta, -src suffixes.
  8912 	// Strip off any -alpha, -RC, -beta, -src suffixes.
  8821 	list( $version ) = explode( '-', $wp_version );
  8913 	list( $version ) = explode( '-', $wp_version );
  8822 
  8914 
  8823 	if ( is_string( $required ) ) {
  8915 	if ( is_string( $required ) ) {
  9001 	 */
  9093 	 */
  9002 	do_action( 'wp_admin_notice', $message, $args );
  9094 	do_action( 'wp_admin_notice', $message, $args );
  9003 
  9095 
  9004 	echo wp_kses_post( wp_get_admin_notice( $message, $args ) );
  9096 	echo wp_kses_post( wp_get_admin_notice( $message, $args ) );
  9005 }
  9097 }
       
  9098 
       
  9099 /**
       
  9100  * Checks if a mime type is for a HEIC/HEIF image.
       
  9101  *
       
  9102  * @since 6.7.0
       
  9103  *
       
  9104  * @param string $mime_type The mime type to check.
       
  9105  * @return bool Whether the mime type is for a HEIC/HEIF image.
       
  9106  */
       
  9107 function wp_is_heic_image_mime_type( $mime_type ) {
       
  9108 	$heic_mime_types = array(
       
  9109 		'image/heic',
       
  9110 		'image/heif',
       
  9111 		'image/heic-sequence',
       
  9112 		'image/heif-sequence',
       
  9113 	);
       
  9114 
       
  9115 	return in_array( $mime_type, $heic_mime_types, true );
       
  9116 }
       
  9117 
       
  9118 /**
       
  9119  * Returns a cryptographically secure hash of a message using a fast generic hash function.
       
  9120  *
       
  9121  * Use the wp_verify_fast_hash() function to verify the hash.
       
  9122  *
       
  9123  * This function does not salt the value prior to being hashed, therefore input to this function must originate from
       
  9124  * a random generator with sufficiently high entropy, preferably greater than 128 bits. This function is used internally
       
  9125  * in WordPress to hash security keys and application passwords which are generated with high entropy.
       
  9126  *
       
  9127  * Important:
       
  9128  *
       
  9129  *  - This function must not be used for hashing user-generated passwords. Use wp_hash_password() for that.
       
  9130  *  - This function must not be used for hashing other low-entropy input. Use wp_hash() for that.
       
  9131  *
       
  9132  * The BLAKE2b algorithm is used by Sodium to hash the message.
       
  9133  *
       
  9134  * @since 6.8.0
       
  9135  *
       
  9136  * @throws TypeError Thrown by Sodium if the message is not a string.
       
  9137  *
       
  9138  * @param string $message The message to hash.
       
  9139  * @return string The hash of the message.
       
  9140  */
       
  9141 function wp_fast_hash(
       
  9142 	#[\SensitiveParameter]
       
  9143 	string $message
       
  9144 ): string {
       
  9145 	$hashed = sodium_crypto_generichash( $message, 'wp_fast_hash_6.8+', 30 );
       
  9146 	return '$generic$' . sodium_bin2base64( $hashed, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING );
       
  9147 }
       
  9148 
       
  9149 /**
       
  9150  * Checks whether a plaintext message matches the hashed value. Used to verify values hashed via wp_fast_hash().
       
  9151  *
       
  9152  * The function uses Sodium to hash the message and compare it to the hashed value. If the hash is not a generic hash,
       
  9153  * the hash is treated as a phpass portable hash in order to provide backward compatibility for passwords and security
       
  9154  * keys which were hashed using phpass prior to WordPress 6.8.0.
       
  9155  *
       
  9156  * @since 6.8.0
       
  9157  *
       
  9158  * @throws TypeError Thrown by Sodium if the message is not a string.
       
  9159  *
       
  9160  * @param string $message The plaintext message.
       
  9161  * @param string $hash    Hash of the message to check against.
       
  9162  * @return bool Whether the message matches the hashed message.
       
  9163  */
       
  9164 function wp_verify_fast_hash(
       
  9165 	#[\SensitiveParameter]
       
  9166 	string $message,
       
  9167 	string $hash
       
  9168 ): bool {
       
  9169 	if ( ! str_starts_with( $hash, '$generic$' ) ) {
       
  9170 		// Back-compat for old phpass hashes.
       
  9171 		require_once ABSPATH . WPINC . '/class-phpass.php';
       
  9172 		return ( new PasswordHash( 8, true ) )->CheckPassword( $message, $hash );
       
  9173 	}
       
  9174 
       
  9175 	return hash_equals( $hash, wp_fast_hash( $message ) );
       
  9176 }
       
  9177 
       
  9178 /**
       
  9179  * Generates a unique ID based on the structure and values of a given array.
       
  9180  *
       
  9181  * This function serializes the array into a JSON string and generates a hash
       
  9182  * that serves as a unique identifier. Optionally, a prefix can be added to
       
  9183  * the generated ID for context or categorization.
       
  9184  *
       
  9185  * @since 6.8.0
       
  9186  *
       
  9187  * @param array  $data   The input array to generate an ID from.
       
  9188  * @param string $prefix Optional. A prefix to prepend to the generated ID. Default ''.
       
  9189  *
       
  9190  * @return string The generated unique ID for the array.
       
  9191  */
       
  9192 function wp_unique_id_from_values( array $data, string $prefix = '' ): string {
       
  9193 	if ( empty( $data ) ) {
       
  9194 		_doing_it_wrong(
       
  9195 			__FUNCTION__,
       
  9196 			sprintf(
       
  9197 				/* translators: %s: parameter name. */
       
  9198 				__( 'The %s argument must not be empty.' ),
       
  9199 				'$data'
       
  9200 			),
       
  9201 			'6.8.0'
       
  9202 		);
       
  9203 	}
       
  9204 	$serialized = wp_json_encode( $data );
       
  9205 	$hash       = substr( md5( $serialized ), 0, 8 );
       
  9206 	return $prefix . $hash;
       
  9207 }