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 } |
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 ); |
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 ) { |
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 |
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' ), |
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. |
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 } |