Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu...
File: compat.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress implementation for PHP functions either missing from older PHP versions or not included by default.
[2] Fix | Delete
*
[3] Fix | Delete
* This file is loaded extremely early and the functions can be relied upon by drop-ins.
[4] Fix | Delete
* Ergo, please ensure you do not rely on external functions when writing code for this file.
[5] Fix | Delete
* Only use functions built into PHP or are defined in this file and have adequate testing
[6] Fix | Delete
* and error suppression to ensure the file will run correctly and not break websites.
[7] Fix | Delete
*
[8] Fix | Delete
* @package PHP
[9] Fix | Delete
* @access private
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
// If gettext isn't available.
[13] Fix | Delete
if ( ! function_exists( '_' ) ) {
[14] Fix | Delete
/**
[15] Fix | Delete
* Compat function to mimic _(), an alias of gettext().
[16] Fix | Delete
*
[17] Fix | Delete
* @since 0.71
[18] Fix | Delete
*
[19] Fix | Delete
* @see https://php.net/manual/en/function.gettext.php
[20] Fix | Delete
*
[21] Fix | Delete
* @param string $message The message being translated.
[22] Fix | Delete
* @return string
[23] Fix | Delete
*/
[24] Fix | Delete
function _( $message ) {
[25] Fix | Delete
return $message;
[26] Fix | Delete
}
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Returns whether PCRE/u (PCRE_UTF8 modifier) is available for use.
[31] Fix | Delete
*
[32] Fix | Delete
* @ignore
[33] Fix | Delete
* @since 4.2.2
[34] Fix | Delete
* @since 6.9.0 Deprecated the `$set` argument.
[35] Fix | Delete
* @access private
[36] Fix | Delete
*
[37] Fix | Delete
* @param bool $set Deprecated. This argument is no longer used for testing purposes.
[38] Fix | Delete
*/
[39] Fix | Delete
function _wp_can_use_pcre_u( $set = null ) {
[40] Fix | Delete
static $utf8_pcre = null;
[41] Fix | Delete
[42] Fix | Delete
if ( isset( $set ) ) {
[43] Fix | Delete
_deprecated_argument( __FUNCTION__, '6.9.0' );
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if ( isset( $utf8_pcre ) ) {
[47] Fix | Delete
return $utf8_pcre;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$utf8_pcre = true;
[51] Fix | Delete
set_error_handler(
[52] Fix | Delete
function ( $errno, $errstr ) use ( &$utf8_pcre ) {
[53] Fix | Delete
if ( str_starts_with( $errstr, 'preg_match():' ) ) {
[54] Fix | Delete
$utf8_pcre = false;
[55] Fix | Delete
return true;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
return false;
[59] Fix | Delete
},
[60] Fix | Delete
E_WARNING
[61] Fix | Delete
);
[62] Fix | Delete
[63] Fix | Delete
/*
[64] Fix | Delete
* Attempt to compile a PCRE pattern with the PCRE_UTF8 flag. For
[65] Fix | Delete
* systems lacking Unicode support this will trigger a warning
[66] Fix | Delete
* during compilation, which the error handler will intercept.
[67] Fix | Delete
*/
[68] Fix | Delete
preg_match( '//u', '' );
[69] Fix | Delete
restore_error_handler();
[70] Fix | Delete
[71] Fix | Delete
return $utf8_pcre;
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Indicates if a given slug for a character set represents the UTF-8 text encoding.
[76] Fix | Delete
*
[77] Fix | Delete
* A charset is considered to represent UTF-8 if it is a case-insensitive match
[78] Fix | Delete
* of "UTF-8" with or without the hyphen.
[79] Fix | Delete
*
[80] Fix | Delete
* Example:
[81] Fix | Delete
*
[82] Fix | Delete
* true === _is_utf8_charset( 'UTF-8' );
[83] Fix | Delete
* true === _is_utf8_charset( 'utf8' );
[84] Fix | Delete
* false === _is_utf8_charset( 'latin1' );
[85] Fix | Delete
* false === _is_utf8_charset( 'UTF 8' );
[86] Fix | Delete
*
[87] Fix | Delete
* // Only strings match.
[88] Fix | Delete
* false === _is_utf8_charset( [ 'charset' => 'utf-8' ] );
[89] Fix | Delete
*
[90] Fix | Delete
* `is_utf8_charset` should be used outside of this file.
[91] Fix | Delete
*
[92] Fix | Delete
* @ignore
[93] Fix | Delete
* @since 6.6.1
[94] Fix | Delete
*
[95] Fix | Delete
* @param string $charset_slug Slug representing a text character encoding, or "charset".
[96] Fix | Delete
* E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS".
[97] Fix | Delete
*
[98] Fix | Delete
* @return bool Whether the slug represents the UTF-8 encoding.
[99] Fix | Delete
*/
[100] Fix | Delete
function _is_utf8_charset( $charset_slug ) {
[101] Fix | Delete
if ( ! is_string( $charset_slug ) ) {
[102] Fix | Delete
return false;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
return (
[106] Fix | Delete
0 === strcasecmp( 'UTF-8', $charset_slug ) ||
[107] Fix | Delete
0 === strcasecmp( 'UTF8', $charset_slug )
[108] Fix | Delete
);
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
if ( ! function_exists( 'mb_substr' ) ) :
[112] Fix | Delete
/**
[113] Fix | Delete
* Compat function to mimic mb_substr().
[114] Fix | Delete
*
[115] Fix | Delete
* @ignore
[116] Fix | Delete
* @since 3.2.0
[117] Fix | Delete
*
[118] Fix | Delete
* @see _mb_substr()
[119] Fix | Delete
*
[120] Fix | Delete
* @param string $string The string to extract the substring from.
[121] Fix | Delete
* @param int $start Position to being extraction from in `$string`.
[122] Fix | Delete
* @param int|null $length Optional. Maximum number of characters to extract from `$string`.
[123] Fix | Delete
* Default null.
[124] Fix | Delete
* @param string|null $encoding Optional. Character encoding to use. Default null.
[125] Fix | Delete
* @return string Extracted substring.
[126] Fix | Delete
*/
[127] Fix | Delete
function mb_substr( $string, $start, $length = null, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
[128] Fix | Delete
return _mb_substr( $string, $start, $length, $encoding );
[129] Fix | Delete
}
[130] Fix | Delete
endif;
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Internal compat function to mimic mb_substr().
[134] Fix | Delete
*
[135] Fix | Delete
* Only supports UTF-8 and non-shifting single-byte encodings. For all other encodings
[136] Fix | Delete
* expect the substrings to be misaligned. When the given encoding (or the `blog_charset`
[137] Fix | Delete
* if none is provided) isn’t UTF-8 then the function returns the output of {@see \substr()}.
[138] Fix | Delete
*
[139] Fix | Delete
* @ignore
[140] Fix | Delete
* @since 3.2.0
[141] Fix | Delete
*
[142] Fix | Delete
* @param string $str The string to extract the substring from.
[143] Fix | Delete
* @param int $start Character offset at which to start the substring extraction.
[144] Fix | Delete
* @param int|null $length Optional. Maximum number of characters to extract from `$str`.
[145] Fix | Delete
* Default null.
[146] Fix | Delete
* @param string|null $encoding Optional. Character encoding to use. Default null.
[147] Fix | Delete
* @return string Extracted substring.
[148] Fix | Delete
*/
[149] Fix | Delete
function _mb_substr( $str, $start, $length = null, $encoding = null ) {
[150] Fix | Delete
if ( null === $str ) {
[151] Fix | Delete
return '';
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
// The solution below works only for UTF-8; treat all other encodings as byte streams.
[155] Fix | Delete
if ( ! _is_utf8_charset( $encoding ?? get_option( 'blog_charset' ) ) ) {
[156] Fix | Delete
return is_null( $length ) ? substr( $str, $start ) : substr( $str, $start, $length );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
$total_length = ( $start < 0 || $length < 0 )
[160] Fix | Delete
? _wp_utf8_codepoint_count( $str )
[161] Fix | Delete
: 0;
[162] Fix | Delete
[163] Fix | Delete
$normalized_start = $start < 0
[164] Fix | Delete
? max( 0, $total_length + $start )
[165] Fix | Delete
: $start;
[166] Fix | Delete
[167] Fix | Delete
/*
[168] Fix | Delete
* The starting offset is provided as characters, which means this needs to
[169] Fix | Delete
* find how many bytes that many characters occupies at the start of the string.
[170] Fix | Delete
*/
[171] Fix | Delete
$starting_byte_offset = _wp_utf8_codepoint_span( $str, 0, $normalized_start );
[172] Fix | Delete
[173] Fix | Delete
$normalized_length = $length < 0
[174] Fix | Delete
? max( 0, $total_length - $normalized_start + $length )
[175] Fix | Delete
: $length;
[176] Fix | Delete
[177] Fix | Delete
/*
[178] Fix | Delete
* This is the main step. It finds how many bytes the given length of code points
[179] Fix | Delete
* occupies in the input, starting at the byte offset calculated above.
[180] Fix | Delete
*/
[181] Fix | Delete
$byte_length = isset( $normalized_length )
[182] Fix | Delete
? _wp_utf8_codepoint_span( $str, $starting_byte_offset, $normalized_length )
[183] Fix | Delete
: ( strlen( $str ) - $starting_byte_offset );
[184] Fix | Delete
[185] Fix | Delete
// The result is a normal byte-level substring using the computed ranges.
[186] Fix | Delete
return substr( $str, $starting_byte_offset, $byte_length );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( ! function_exists( 'mb_strlen' ) ) :
[190] Fix | Delete
/**
[191] Fix | Delete
* Compat function to mimic mb_strlen().
[192] Fix | Delete
*
[193] Fix | Delete
* @ignore
[194] Fix | Delete
* @since 4.2.0
[195] Fix | Delete
*
[196] Fix | Delete
* @see _mb_strlen()
[197] Fix | Delete
*
[198] Fix | Delete
* @param string $string The string to retrieve the character length from.
[199] Fix | Delete
* @param string|null $encoding Optional. Character encoding to use. Default null.
[200] Fix | Delete
* @return int String length of `$string`.
[201] Fix | Delete
*/
[202] Fix | Delete
function mb_strlen( $string, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
[203] Fix | Delete
return _mb_strlen( $string, $encoding );
[204] Fix | Delete
}
[205] Fix | Delete
endif;
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* Internal compat function to mimic mb_strlen().
[209] Fix | Delete
*
[210] Fix | Delete
* Only supports UTF-8 and non-shifting single-byte encodings. For all other
[211] Fix | Delete
* encodings expect the counts to be wrong. When the given encoding (or the
[212] Fix | Delete
* `blog_charset` if none is provided) isn’t UTF-8 then the function returns
[213] Fix | Delete
* the byte-count of the provided string.
[214] Fix | Delete
*
[215] Fix | Delete
* @ignore
[216] Fix | Delete
* @since 4.2.0
[217] Fix | Delete
*
[218] Fix | Delete
* @param string $str The string to retrieve the character length from.
[219] Fix | Delete
* @param string|null $encoding Optional. Count characters according to this encoding.
[220] Fix | Delete
* Default is to consult `blog_charset`.
[221] Fix | Delete
* @return int Count of code points if UTF-8, byte length otherwise.
[222] Fix | Delete
*/
[223] Fix | Delete
function _mb_strlen( $str, $encoding = null ) {
[224] Fix | Delete
return _is_utf8_charset( $encoding ?? get_option( 'blog_charset' ) )
[225] Fix | Delete
? _wp_utf8_codepoint_count( $str )
[226] Fix | Delete
: strlen( $str );
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
if ( ! function_exists( 'utf8_encode' ) ) :
[230] Fix | Delete
if ( extension_loaded( 'mbstring' ) ) :
[231] Fix | Delete
/**
[232] Fix | Delete
* Converts a string from ISO-8859-1 to UTF-8.
[233] Fix | Delete
*
[234] Fix | Delete
* @deprecated Use {@see \mb_convert_encoding()} instead.
[235] Fix | Delete
*
[236] Fix | Delete
* @since 6.9.0
[237] Fix | Delete
*
[238] Fix | Delete
* @param string $iso_8859_1_text Text treated as ISO-8859-1 (latin1) bytes.
[239] Fix | Delete
* @return string Text converted into a UTF-8.
[240] Fix | Delete
*/
[241] Fix | Delete
function utf8_encode( $iso_8859_1_text ): string {
[242] Fix | Delete
_deprecated_function( __FUNCTION__, '6.9.0', 'mb_convert_encoding' );
[243] Fix | Delete
[244] Fix | Delete
return mb_convert_encoding( $iso_8859_1_text, 'UTF-8', 'ISO-8859-1' );
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
else :
[248] Fix | Delete
/**
[249] Fix | Delete
* @ignore
[250] Fix | Delete
* @private
[251] Fix | Delete
*
[252] Fix | Delete
* @since 6.9.0
[253] Fix | Delete
*/
[254] Fix | Delete
function utf8_encode( $iso_8859_1_text ): string {
[255] Fix | Delete
_deprecated_function( __FUNCTION__, '6.9.0', 'mb_convert_encoding' );
[256] Fix | Delete
[257] Fix | Delete
return _wp_utf8_encode_fallback( $iso_8859_1_text );
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
endif;
[261] Fix | Delete
endif;
[262] Fix | Delete
[263] Fix | Delete
if ( ! function_exists( 'utf8_decode' ) ) :
[264] Fix | Delete
if ( extension_loaded( 'mbstring' ) ) :
[265] Fix | Delete
/**
[266] Fix | Delete
* Converts a string from UTF-8 to ISO-8859-1.
[267] Fix | Delete
*
[268] Fix | Delete
* @deprecated Use {@see \mb_convert_encoding()} instead.
[269] Fix | Delete
*
[270] Fix | Delete
* @since 6.9.0
[271] Fix | Delete
*
[272] Fix | Delete
* @param string $utf8_text Text treated as UTF-8.
[273] Fix | Delete
* @return string Text converted into ISO-8859-1.
[274] Fix | Delete
*/
[275] Fix | Delete
function utf8_decode( $utf8_text ): string {
[276] Fix | Delete
_deprecated_function( __FUNCTION__, '6.9.0', 'mb_convert_encoding' );
[277] Fix | Delete
[278] Fix | Delete
return mb_convert_encoding( $utf8_text, 'ISO-8859-1', 'UTF-8' );
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
else :
[282] Fix | Delete
/**
[283] Fix | Delete
* @ignore
[284] Fix | Delete
* @private
[285] Fix | Delete
*
[286] Fix | Delete
* @since 6.9.0
[287] Fix | Delete
*/
[288] Fix | Delete
function utf8_decode( $utf8_text ): string {
[289] Fix | Delete
_deprecated_function( __FUNCTION__, '6.9.0', 'mb_convert_encoding' );
[290] Fix | Delete
[291] Fix | Delete
return _wp_utf8_decode_fallback( $utf8_text );
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
endif;
[295] Fix | Delete
endif;
[296] Fix | Delete
[297] Fix | Delete
// sodium_crypto_box() was introduced in PHP 7.2.
[298] Fix | Delete
if ( ! function_exists( 'sodium_crypto_box' ) ) {
[299] Fix | Delete
require ABSPATH . WPINC . '/sodium_compat/autoload.php';
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
if ( ! function_exists( 'is_countable' ) ) {
[303] Fix | Delete
/**
[304] Fix | Delete
* Polyfill for is_countable() function added in PHP 7.3.
[305] Fix | Delete
*
[306] Fix | Delete
* Verify that the content of a variable is an array or an object
[307] Fix | Delete
* implementing the Countable interface.
[308] Fix | Delete
*
[309] Fix | Delete
* @since 4.9.6
[310] Fix | Delete
*
[311] Fix | Delete
* @param mixed $value The value to check.
[312] Fix | Delete
* @return bool True if `$value` is countable, false otherwise.
[313] Fix | Delete
*/
[314] Fix | Delete
function is_countable( $value ) {
[315] Fix | Delete
return ( is_array( $value )
[316] Fix | Delete
|| $value instanceof Countable
[317] Fix | Delete
|| $value instanceof SimpleXMLElement
[318] Fix | Delete
|| $value instanceof ResourceBundle
[319] Fix | Delete
);
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
if ( ! function_exists( 'array_key_first' ) ) {
[324] Fix | Delete
/**
[325] Fix | Delete
* Polyfill for array_key_first() function added in PHP 7.3.
[326] Fix | Delete
*
[327] Fix | Delete
* Get the first key of the given array without affecting
[328] Fix | Delete
* the internal array pointer.
[329] Fix | Delete
*
[330] Fix | Delete
* @since 5.9.0
[331] Fix | Delete
*
[332] Fix | Delete
* @param array $array An array.
[333] Fix | Delete
* @return string|int|null The first key of array if the array
[334] Fix | Delete
* is not empty; `null` otherwise.
[335] Fix | Delete
*/
[336] Fix | Delete
function array_key_first( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
[337] Fix | Delete
if ( empty( $array ) ) {
[338] Fix | Delete
return null;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
foreach ( $array as $key => $value ) {
[342] Fix | Delete
return $key;
[343] Fix | Delete
}
[344] Fix | Delete
}
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
if ( ! function_exists( 'array_key_last' ) ) {
[348] Fix | Delete
/**
[349] Fix | Delete
* Polyfill for `array_key_last()` function added in PHP 7.3.
[350] Fix | Delete
*
[351] Fix | Delete
* Get the last key of the given array without affecting the
[352] Fix | Delete
* internal array pointer.
[353] Fix | Delete
*
[354] Fix | Delete
* @since 5.9.0
[355] Fix | Delete
*
[356] Fix | Delete
* @param array $array An array.
[357] Fix | Delete
* @return string|int|null The last key of array if the array
[358] Fix | Delete
*. is not empty; `null` otherwise.
[359] Fix | Delete
*/
[360] Fix | Delete
function array_key_last( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
[361] Fix | Delete
if ( empty( $array ) ) {
[362] Fix | Delete
return null;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
end( $array );
[366] Fix | Delete
[367] Fix | Delete
return key( $array );
[368] Fix | Delete
}
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
if ( ! function_exists( 'array_is_list' ) ) {
[372] Fix | Delete
/**
[373] Fix | Delete
* Polyfill for `array_is_list()` function added in PHP 8.1.
[374] Fix | Delete
*
[375] Fix | Delete
* Determines if the given array is a list.
[376] Fix | Delete
*
[377] Fix | Delete
* An array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1.
[378] Fix | Delete
*
[379] Fix | Delete
* @see https://github.com/symfony/polyfill-php81/tree/main
[380] Fix | Delete
*
[381] Fix | Delete
* @since 6.5.0
[382] Fix | Delete
*
[383] Fix | Delete
* @param array<mixed> $arr The array being evaluated.
[384] Fix | Delete
* @return bool True if array is a list, false otherwise.
[385] Fix | Delete
*/
[386] Fix | Delete
function array_is_list( $arr ) {
[387] Fix | Delete
if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) {
[388] Fix | Delete
return true;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
$next_key = -1;
[392] Fix | Delete
[393] Fix | Delete
foreach ( $arr as $k => $v ) {
[394] Fix | Delete
if ( ++$next_key !== $k ) {
[395] Fix | Delete
return false;
[396] Fix | Delete
}
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
return true;
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
if ( ! function_exists( 'str_contains' ) ) {
[404] Fix | Delete
/**
[405] Fix | Delete
* Polyfill for `str_contains()` function added in PHP 8.0.
[406] Fix | Delete
*
[407] Fix | Delete
* Performs a case-sensitive check indicating if needle is
[408] Fix | Delete
* contained in haystack.
[409] Fix | Delete
*
[410] Fix | Delete
* @since 5.9.0
[411] Fix | Delete
*
[412] Fix | Delete
* @param string $haystack The string to search in.
[413] Fix | Delete
* @param string $needle The substring to search for in the `$haystack`.
[414] Fix | Delete
* @return bool True if `$needle` is in `$haystack`, otherwise false.
[415] Fix | Delete
*/
[416] Fix | Delete
function str_contains( $haystack, $needle ) {
[417] Fix | Delete
if ( '' === $needle ) {
[418] Fix | Delete
return true;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
return false !== strpos( $haystack, $needle );
[422] Fix | Delete
}
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
if ( ! function_exists( 'str_starts_with' ) ) {
[426] Fix | Delete
/**
[427] Fix | Delete
* Polyfill for `str_starts_with()` function added in PHP 8.0.
[428] Fix | Delete
*
[429] Fix | Delete
* Performs a case-sensitive check indicating if
[430] Fix | Delete
* the haystack begins with needle.
[431] Fix | Delete
*
[432] Fix | Delete
* @since 5.9.0
[433] Fix | Delete
*
[434] Fix | Delete
* @param string $haystack The string to search in.
[435] Fix | Delete
* @param string $needle The substring to search for in the `$haystack`.
[436] Fix | Delete
* @return bool True if `$haystack` starts with `$needle`, otherwise false.
[437] Fix | Delete
*/
[438] Fix | Delete
function str_starts_with( $haystack, $needle ) {
[439] Fix | Delete
if ( '' === $needle ) {
[440] Fix | Delete
return true;
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
return 0 === strpos( $haystack, $needle );
[444] Fix | Delete
}
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
if ( ! function_exists( 'str_ends_with' ) ) {
[448] Fix | Delete
/**
[449] Fix | Delete
* Polyfill for `str_ends_with()` function added in PHP 8.0.
[450] Fix | Delete
*
[451] Fix | Delete
* Performs a case-sensitive check indicating if
[452] Fix | Delete
* the haystack ends with needle.
[453] Fix | Delete
*
[454] Fix | Delete
* @since 5.9.0
[455] Fix | Delete
*
[456] Fix | Delete
* @param string $haystack The string to search in.
[457] Fix | Delete
* @param string $needle The substring to search for in the `$haystack`.
[458] Fix | Delete
* @return bool True if `$haystack` ends with `$needle`, otherwise false.
[459] Fix | Delete
*/
[460] Fix | Delete
function str_ends_with( $haystack, $needle ) {
[461] Fix | Delete
if ( '' === $haystack ) {
[462] Fix | Delete
return '' === $needle;
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
$len = strlen( $needle );
[466] Fix | Delete
[467] Fix | Delete
return substr( $haystack, -$len, $len ) === $needle;
[468] Fix | Delete
}
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
if ( ! function_exists( 'array_find' ) ) {
[472] Fix | Delete
/**
[473] Fix | Delete
* Polyfill for `array_find()` function added in PHP 8.4.
[474] Fix | Delete
*
[475] Fix | Delete
* Searches an array for the first element that passes a given callback.
[476] Fix | Delete
*
[477] Fix | Delete
* @since 6.8.0
[478] Fix | Delete
*
[479] Fix | Delete
* @param array $array The array to search.
[480] Fix | Delete
* @param callable $callback The callback to run for each element.
[481] Fix | Delete
* @return mixed|null The first element in the array that passes the `$callback`, otherwise null.
[482] Fix | Delete
*/
[483] Fix | Delete
function array_find( array $array, callable $callback ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
[484] Fix | Delete
foreach ( $array as $key => $value ) {
[485] Fix | Delete
if ( $callback( $value, $key ) ) {
[486] Fix | Delete
return $value;
[487] Fix | Delete
}
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
return null;
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
if ( ! function_exists( 'array_find_key' ) ) {
[495] Fix | Delete
/**
[496] Fix | Delete
* Polyfill for `array_find_key()` function added in PHP 8.4.
[497] Fix | Delete
*
[498] Fix | Delete
* Searches an array for the first key that passes a given callback.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function