Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Main WordPress API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
require ABSPATH . WPINC . '/option.php';
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Converts given MySQL date string into a different format.
[10] Fix | Delete
*
[11] Fix | Delete
* - `$format` should be a PHP date format string.
[12] Fix | Delete
* - 'U' and 'G' formats will return an integer sum of timestamp with timezone offset.
[13] Fix | Delete
* - `$date` is expected to be local time in MySQL format (`Y-m-d H:i:s`).
[14] Fix | Delete
*
[15] Fix | Delete
* Historically UTC time could be passed to the function to produce Unix timestamp.
[16] Fix | Delete
*
[17] Fix | Delete
* If `$translate` is true then the given date and format string will
[18] Fix | Delete
* be passed to `wp_date()` for translation.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 0.71
[21] Fix | Delete
*
[22] Fix | Delete
* @param string $format Format of the date to return.
[23] Fix | Delete
* @param string $date Date string to convert.
[24] Fix | Delete
* @param bool $translate Whether the return date should be translated. Default true.
[25] Fix | Delete
* @return string|int|false Integer if `$format` is 'U' or 'G', string otherwise.
[26] Fix | Delete
* False on failure.
[27] Fix | Delete
*/
[28] Fix | Delete
function mysql2date( $format, $date, $translate = true ) {
[29] Fix | Delete
if ( empty( $date ) ) {
[30] Fix | Delete
return false;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
$timezone = wp_timezone();
[34] Fix | Delete
$datetime = date_create( $date, $timezone );
[35] Fix | Delete
[36] Fix | Delete
if ( false === $datetime ) {
[37] Fix | Delete
return false;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
// Returns a sum of timestamp with timezone offset. Ideally should never be used.
[41] Fix | Delete
if ( 'G' === $format || 'U' === $format ) {
[42] Fix | Delete
return $datetime->getTimestamp() + $datetime->getOffset();
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
if ( $translate ) {
[46] Fix | Delete
return wp_date( $format, $datetime->getTimestamp(), $timezone );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
return $datetime->format( $format );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Retrieves the current time based on specified type.
[54] Fix | Delete
*
[55] Fix | Delete
* - The 'mysql' type will return the time in the format for MySQL DATETIME field.
[56] Fix | Delete
* - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp
[57] Fix | Delete
* and timezone offset, depending on `$gmt`.
[58] Fix | Delete
* - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
[59] Fix | Delete
*
[60] Fix | Delete
* If `$gmt` is a truthy value then both types will use GMT time, otherwise the
[61] Fix | Delete
* output is adjusted with the GMT offset for the site.
[62] Fix | Delete
*
[63] Fix | Delete
* @since 1.0.0
[64] Fix | Delete
* @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned.
[65] Fix | Delete
*
[66] Fix | Delete
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U',
[67] Fix | Delete
* or PHP date format string (e.g. 'Y-m-d').
[68] Fix | Delete
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
[69] Fix | Delete
* @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
[70] Fix | Delete
*/
[71] Fix | Delete
function current_time( $type, $gmt = 0 ) {
[72] Fix | Delete
// Don't use non-GMT timestamp, unless you know the difference and really need to.
[73] Fix | Delete
if ( 'timestamp' === $type || 'U' === $type ) {
[74] Fix | Delete
return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
if ( 'mysql' === $type ) {
[78] Fix | Delete
$type = 'Y-m-d H:i:s';
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
$timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone();
[82] Fix | Delete
$datetime = new DateTime( 'now', $timezone );
[83] Fix | Delete
[84] Fix | Delete
return $datetime->format( $type );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Retrieves the current time as an object using the site's timezone.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 5.3.0
[91] Fix | Delete
*
[92] Fix | Delete
* @return DateTimeImmutable Date and time object.
[93] Fix | Delete
*/
[94] Fix | Delete
function current_datetime() {
[95] Fix | Delete
return new DateTimeImmutable( 'now', wp_timezone() );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Retrieves the timezone of the site as a string.
[100] Fix | Delete
*
[101] Fix | Delete
* Uses the `timezone_string` option to get a proper timezone name if available,
[102] Fix | Delete
* otherwise falls back to a manual UTC ± offset.
[103] Fix | Delete
*
[104] Fix | Delete
* Example return values:
[105] Fix | Delete
*
[106] Fix | Delete
* - 'Europe/Rome'
[107] Fix | Delete
* - 'America/North_Dakota/New_Salem'
[108] Fix | Delete
* - 'UTC'
[109] Fix | Delete
* - '-06:30'
[110] Fix | Delete
* - '+00:00'
[111] Fix | Delete
* - '+08:45'
[112] Fix | Delete
*
[113] Fix | Delete
* @since 5.3.0
[114] Fix | Delete
*
[115] Fix | Delete
* @return string PHP timezone name or a ±HH:MM offset.
[116] Fix | Delete
*/
[117] Fix | Delete
function wp_timezone_string() {
[118] Fix | Delete
$timezone_string = get_option( 'timezone_string' );
[119] Fix | Delete
[120] Fix | Delete
if ( $timezone_string ) {
[121] Fix | Delete
return $timezone_string;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
$offset = (float) get_option( 'gmt_offset' );
[125] Fix | Delete
$hours = (int) $offset;
[126] Fix | Delete
$minutes = ( $offset - $hours );
[127] Fix | Delete
[128] Fix | Delete
$sign = ( $offset < 0 ) ? '-' : '+';
[129] Fix | Delete
$abs_hour = abs( $hours );
[130] Fix | Delete
$abs_mins = abs( $minutes * 60 );
[131] Fix | Delete
$tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
[132] Fix | Delete
[133] Fix | Delete
return $tz_offset;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Retrieves the timezone of the site as a `DateTimeZone` object.
[138] Fix | Delete
*
[139] Fix | Delete
* Timezone can be based on a PHP timezone string or a ±HH:MM offset.
[140] Fix | Delete
*
[141] Fix | Delete
* @since 5.3.0
[142] Fix | Delete
*
[143] Fix | Delete
* @return DateTimeZone Timezone object.
[144] Fix | Delete
*/
[145] Fix | Delete
function wp_timezone() {
[146] Fix | Delete
return new DateTimeZone( wp_timezone_string() );
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Retrieves the date in localized format, based on a sum of Unix timestamp and
[151] Fix | Delete
* timezone offset in seconds.
[152] Fix | Delete
*
[153] Fix | Delete
* If the locale specifies the locale month and weekday, then the locale will
[154] Fix | Delete
* take over the format for the date. If it isn't, then the date format string
[155] Fix | Delete
* will be used instead.
[156] Fix | Delete
*
[157] Fix | Delete
* Note that due to the way WP typically generates a sum of timestamp and offset
[158] Fix | Delete
* with `strtotime()`, it implies offset added at a _current_ time, not at the time
[159] Fix | Delete
* the timestamp represents. Storing such timestamps or calculating them differently
[160] Fix | Delete
* will lead to invalid output.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 0.71
[163] Fix | Delete
* @since 5.3.0 Converted into a wrapper for wp_date().
[164] Fix | Delete
*
[165] Fix | Delete
* @param string $format Format to display the date.
[166] Fix | Delete
* @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset
[167] Fix | Delete
* in seconds. Default false.
[168] Fix | Delete
* @param bool $gmt Optional. Whether to use GMT timezone. Only applies
[169] Fix | Delete
* if timestamp is not provided. Default false.
[170] Fix | Delete
* @return string The date, translated if locale specifies it.
[171] Fix | Delete
*/
[172] Fix | Delete
function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) {
[173] Fix | Delete
$timestamp = $timestamp_with_offset;
[174] Fix | Delete
[175] Fix | Delete
// If timestamp is omitted it should be current time (summed with offset, unless `$gmt` is true).
[176] Fix | Delete
if ( ! is_numeric( $timestamp ) ) {
[177] Fix | Delete
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
[178] Fix | Delete
$timestamp = current_time( 'timestamp', $gmt );
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
/*
[182] Fix | Delete
* This is a legacy implementation quirk that the returned timestamp is also with offset.
[183] Fix | Delete
* Ideally this function should never be used to produce a timestamp.
[184] Fix | Delete
*/
[185] Fix | Delete
if ( 'U' === $format ) {
[186] Fix | Delete
$date = $timestamp;
[187] Fix | Delete
} elseif ( $gmt && false === $timestamp_with_offset ) { // Current time in UTC.
[188] Fix | Delete
$date = wp_date( $format, null, new DateTimeZone( 'UTC' ) );
[189] Fix | Delete
} elseif ( false === $timestamp_with_offset ) { // Current time in site's timezone.
[190] Fix | Delete
$date = wp_date( $format );
[191] Fix | Delete
} else {
[192] Fix | Delete
/*
[193] Fix | Delete
* Timestamp with offset is typically produced by a UTC `strtotime()` call on an input without timezone.
[194] Fix | Delete
* This is the best attempt to reverse that operation into a local time to use.
[195] Fix | Delete
*/
[196] Fix | Delete
$local_time = gmdate( 'Y-m-d H:i:s', $timestamp );
[197] Fix | Delete
$timezone = wp_timezone();
[198] Fix | Delete
$datetime = date_create( $local_time, $timezone );
[199] Fix | Delete
$date = wp_date( $format, $datetime->getTimestamp(), $timezone );
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Filters the date formatted based on the locale.
[204] Fix | Delete
*
[205] Fix | Delete
* @since 2.8.0
[206] Fix | Delete
*
[207] Fix | Delete
* @param string $date Formatted date string.
[208] Fix | Delete
* @param string $format Format to display the date.
[209] Fix | Delete
* @param int $timestamp A sum of Unix timestamp and timezone offset in seconds.
[210] Fix | Delete
* Might be without offset if input omitted timestamp but requested GMT.
[211] Fix | Delete
* @param bool $gmt Whether to use GMT timezone. Only applies if timestamp was not provided.
[212] Fix | Delete
* Default false.
[213] Fix | Delete
*/
[214] Fix | Delete
$date = apply_filters( 'date_i18n', $date, $format, $timestamp, $gmt );
[215] Fix | Delete
[216] Fix | Delete
return $date;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Retrieves the date, in localized format.
[221] Fix | Delete
*
[222] Fix | Delete
* This is a newer function, intended to replace `date_i18n()` without legacy quirks in it.
[223] Fix | Delete
*
[224] Fix | Delete
* Note that, unlike `date_i18n()`, this function accepts a true Unix timestamp, not summed
[225] Fix | Delete
* with timezone offset.
[226] Fix | Delete
*
[227] Fix | Delete
* @since 5.3.0
[228] Fix | Delete
*
[229] Fix | Delete
* @global WP_Locale $wp_locale WordPress date and time locale object.
[230] Fix | Delete
*
[231] Fix | Delete
* @param string $format PHP date format.
[232] Fix | Delete
* @param int $timestamp Optional. Unix timestamp. Defaults to current time.
[233] Fix | Delete
* @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone
[234] Fix | Delete
* from site settings.
[235] Fix | Delete
* @return string|false The date, translated if locale specifies it. False on invalid timestamp input.
[236] Fix | Delete
*/
[237] Fix | Delete
function wp_date( $format, $timestamp = null, $timezone = null ) {
[238] Fix | Delete
global $wp_locale;
[239] Fix | Delete
[240] Fix | Delete
if ( null === $timestamp ) {
[241] Fix | Delete
$timestamp = time();
[242] Fix | Delete
} elseif ( ! is_numeric( $timestamp ) ) {
[243] Fix | Delete
return false;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
if ( ! $timezone ) {
[247] Fix | Delete
$timezone = wp_timezone();
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
$datetime = date_create( '@' . $timestamp );
[251] Fix | Delete
$datetime->setTimezone( $timezone );
[252] Fix | Delete
[253] Fix | Delete
if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) {
[254] Fix | Delete
$date = $datetime->format( $format );
[255] Fix | Delete
} else {
[256] Fix | Delete
// We need to unpack shorthand `r` format because it has parts that might be localized.
[257] Fix | Delete
$format = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $format );
[258] Fix | Delete
[259] Fix | Delete
$new_format = '';
[260] Fix | Delete
$format_length = strlen( $format );
[261] Fix | Delete
$month = $wp_locale->get_month( $datetime->format( 'm' ) );
[262] Fix | Delete
$weekday = $wp_locale->get_weekday( $datetime->format( 'w' ) );
[263] Fix | Delete
[264] Fix | Delete
for ( $i = 0; $i < $format_length; $i++ ) {
[265] Fix | Delete
switch ( $format[ $i ] ) {
[266] Fix | Delete
case 'D':
[267] Fix | Delete
$new_format .= addcslashes( $wp_locale->get_weekday_abbrev( $weekday ), '\\A..Za..z' );
[268] Fix | Delete
break;
[269] Fix | Delete
case 'F':
[270] Fix | Delete
$new_format .= addcslashes( $month, '\\A..Za..z' );
[271] Fix | Delete
break;
[272] Fix | Delete
case 'l':
[273] Fix | Delete
$new_format .= addcslashes( $weekday, '\\A..Za..z' );
[274] Fix | Delete
break;
[275] Fix | Delete
case 'M':
[276] Fix | Delete
$new_format .= addcslashes( $wp_locale->get_month_abbrev( $month ), '\\A..Za..z' );
[277] Fix | Delete
break;
[278] Fix | Delete
case 'a':
[279] Fix | Delete
$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'a' ) ), '\\A..Za..z' );
[280] Fix | Delete
break;
[281] Fix | Delete
case 'A':
[282] Fix | Delete
$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'A' ) ), '\\A..Za..z' );
[283] Fix | Delete
break;
[284] Fix | Delete
case '\\':
[285] Fix | Delete
$new_format .= $format[ $i ];
[286] Fix | Delete
[287] Fix | Delete
// If character follows a slash, we add it without translating.
[288] Fix | Delete
if ( $i < $format_length ) {
[289] Fix | Delete
$new_format .= $format[ ++$i ];
[290] Fix | Delete
}
[291] Fix | Delete
break;
[292] Fix | Delete
default:
[293] Fix | Delete
$new_format .= $format[ $i ];
[294] Fix | Delete
break;
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
$date = $datetime->format( $new_format );
[299] Fix | Delete
$date = wp_maybe_decline_date( $date, $format );
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
/**
[303] Fix | Delete
* Filters the date formatted based on the locale.
[304] Fix | Delete
*
[305] Fix | Delete
* @since 5.3.0
[306] Fix | Delete
*
[307] Fix | Delete
* @param string $date Formatted date string.
[308] Fix | Delete
* @param string $format Format to display the date.
[309] Fix | Delete
* @param int $timestamp Unix timestamp.
[310] Fix | Delete
* @param DateTimeZone $timezone Timezone.
[311] Fix | Delete
*/
[312] Fix | Delete
$date = apply_filters( 'wp_date', $date, $format, $timestamp, $timezone );
[313] Fix | Delete
[314] Fix | Delete
return $date;
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
/**
[318] Fix | Delete
* Determines if the date should be declined.
[319] Fix | Delete
*
[320] Fix | Delete
* If the locale specifies that month names require a genitive case in certain
[321] Fix | Delete
* formats (like 'j F Y'), the month name will be replaced with a correct form.
[322] Fix | Delete
*
[323] Fix | Delete
* @since 4.4.0
[324] Fix | Delete
* @since 5.4.0 The `$format` parameter was added.
[325] Fix | Delete
*
[326] Fix | Delete
* @global WP_Locale $wp_locale WordPress date and time locale object.
[327] Fix | Delete
*
[328] Fix | Delete
* @param string $date Formatted date string.
[329] Fix | Delete
* @param string $format Optional. Date format to check. Default empty string.
[330] Fix | Delete
* @return string The date, declined if locale specifies it.
[331] Fix | Delete
*/
[332] Fix | Delete
function wp_maybe_decline_date( $date, $format = '' ) {
[333] Fix | Delete
global $wp_locale;
[334] Fix | Delete
[335] Fix | Delete
// i18n functions are not available in SHORTINIT mode.
[336] Fix | Delete
if ( ! function_exists( '_x' ) ) {
[337] Fix | Delete
return $date;
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
/*
[341] Fix | Delete
* translators: If months in your language require a genitive case,
[342] Fix | Delete
* translate this to 'on'. Do not translate into your own language.
[343] Fix | Delete
*/
[344] Fix | Delete
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
[345] Fix | Delete
[346] Fix | Delete
$months = $wp_locale->month;
[347] Fix | Delete
$months_genitive = $wp_locale->month_genitive;
[348] Fix | Delete
[349] Fix | Delete
/*
[350] Fix | Delete
* Match a format like 'j F Y' or 'j. F' (day of the month, followed by month name)
[351] Fix | Delete
* and decline the month.
[352] Fix | Delete
*/
[353] Fix | Delete
if ( $format ) {
[354] Fix | Delete
$decline = preg_match( '#[dj]\.? F#', $format );
[355] Fix | Delete
} else {
[356] Fix | Delete
// If the format is not passed, try to guess it from the date string.
[357] Fix | Delete
$decline = preg_match( '#\b\d{1,2}\.? [^\d ]+\b#u', $date );
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
if ( $decline ) {
[361] Fix | Delete
foreach ( $months as $key => $month ) {
[362] Fix | Delete
$months[ $key ] = '# ' . preg_quote( $month, '#' ) . '\b#u';
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
foreach ( $months_genitive as $key => $month ) {
[366] Fix | Delete
$months_genitive[ $key ] = ' ' . $month;
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
$date = preg_replace( $months, $months_genitive, $date );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/*
[373] Fix | Delete
* Match a format like 'F jS' or 'F j' (month name, followed by day with an optional ordinal suffix)
[374] Fix | Delete
* and change it to declined 'j F'.
[375] Fix | Delete
*/
[376] Fix | Delete
if ( $format ) {
[377] Fix | Delete
$decline = preg_match( '#F [dj]#', $format );
[378] Fix | Delete
} else {
[379] Fix | Delete
// If the format is not passed, try to guess it from the date string.
[380] Fix | Delete
$decline = preg_match( '#\b[^\d ]+ \d{1,2}(st|nd|rd|th)?\b#u', trim( $date ) );
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
if ( $decline ) {
[384] Fix | Delete
foreach ( $months as $key => $month ) {
[385] Fix | Delete
$months[ $key ] = '#\b' . preg_quote( $month, '#' ) . ' (\d{1,2})(st|nd|rd|th)?([-–]\d{1,2})?(st|nd|rd|th)?\b#u';
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
foreach ( $months_genitive as $key => $month ) {
[389] Fix | Delete
$months_genitive[ $key ] = '$1$3 ' . $month;
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
$date = preg_replace( $months, $months_genitive, $date );
[393] Fix | Delete
}
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
// Used for locale-specific rules.
[397] Fix | Delete
$locale = get_locale();
[398] Fix | Delete
[399] Fix | Delete
if ( 'ca' === $locale ) {
[400] Fix | Delete
// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
[401] Fix | Delete
$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
return $date;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Converts float number to format based on the locale.
[409] Fix | Delete
*
[410] Fix | Delete
* @since 2.3.0
[411] Fix | Delete
*
[412] Fix | Delete
* @global WP_Locale $wp_locale WordPress date and time locale object.
[413] Fix | Delete
*
[414] Fix | Delete
* @param float $number The number to convert based on locale.
[415] Fix | Delete
* @param int $decimals Optional. Precision of the number of decimal places. Default 0.
[416] Fix | Delete
* @return string Converted number in string format.
[417] Fix | Delete
*/
[418] Fix | Delete
function number_format_i18n( $number, $decimals = 0 ) {
[419] Fix | Delete
global $wp_locale;
[420] Fix | Delete
[421] Fix | Delete
if ( isset( $wp_locale ) ) {
[422] Fix | Delete
$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
[423] Fix | Delete
} else {
[424] Fix | Delete
$formatted = number_format( $number, absint( $decimals ) );
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* Filters the number formatted based on the locale.
[429] Fix | Delete
*
[430] Fix | Delete
* @since 2.8.0
[431] Fix | Delete
* @since 4.9.0 The `$number` and `$decimals` parameters were added.
[432] Fix | Delete
*
[433] Fix | Delete
* @param string $formatted Converted number in string format.
[434] Fix | Delete
* @param float $number The number to convert based on locale.
[435] Fix | Delete
* @param int $decimals Precision of the number of decimal places.
[436] Fix | Delete
*/
[437] Fix | Delete
return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
/**
[441] Fix | Delete
* Converts a number of bytes to the largest unit the bytes will fit into.
[442] Fix | Delete
*
[443] Fix | Delete
* It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts
[444] Fix | Delete
* number of bytes to human readable number by taking the number of that unit
[445] Fix | Delete
* that the bytes will go into it. Supports YB value.
[446] Fix | Delete
*
[447] Fix | Delete
* Please note that integers in PHP are limited to 32 bits, unless they are on
[448] Fix | Delete
* 64 bit architecture, then they have 64 bit size. If you need to place the
[449] Fix | Delete
* larger size then what PHP integer type will hold, then use a string. It will
[450] Fix | Delete
* be converted to a double, which should always have 64 bit length.
[451] Fix | Delete
*
[452] Fix | Delete
* Technically the correct unit names for powers of 1024 are KiB, MiB etc.
[453] Fix | Delete
*
[454] Fix | Delete
* @since 2.3.0
[455] Fix | Delete
* @since 6.0.0 Support for PB, EB, ZB, and YB was added.
[456] Fix | Delete
*
[457] Fix | Delete
* @param int|string $bytes Number of bytes. Note max integer size for integers.
[458] Fix | Delete
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
[459] Fix | Delete
* @return string|false Number string on success, false on failure.
[460] Fix | Delete
*/
[461] Fix | Delete
function size_format( $bytes, $decimals = 0 ) {
[462] Fix | Delete
$quant = array(
[463] Fix | Delete
/* translators: Unit symbol for yottabyte. */
[464] Fix | Delete
_x( 'YB', 'unit symbol' ) => YB_IN_BYTES,
[465] Fix | Delete
/* translators: Unit symbol for zettabyte. */
[466] Fix | Delete
_x( 'ZB', 'unit symbol' ) => ZB_IN_BYTES,
[467] Fix | Delete
/* translators: Unit symbol for exabyte. */
[468] Fix | Delete
_x( 'EB', 'unit symbol' ) => EB_IN_BYTES,
[469] Fix | Delete
/* translators: Unit symbol for petabyte. */
[470] Fix | Delete
_x( 'PB', 'unit symbol' ) => PB_IN_BYTES,
[471] Fix | Delete
/* translators: Unit symbol for terabyte. */
[472] Fix | Delete
_x( 'TB', 'unit symbol' ) => TB_IN_BYTES,
[473] Fix | Delete
/* translators: Unit symbol for gigabyte. */
[474] Fix | Delete
_x( 'GB', 'unit symbol' ) => GB_IN_BYTES,
[475] Fix | Delete
/* translators: Unit symbol for megabyte. */
[476] Fix | Delete
_x( 'MB', 'unit symbol' ) => MB_IN_BYTES,
[477] Fix | Delete
/* translators: Unit symbol for kilobyte. */
[478] Fix | Delete
_x( 'KB', 'unit symbol' ) => KB_IN_BYTES,
[479] Fix | Delete
/* translators: Unit symbol for byte. */
[480] Fix | Delete
_x( 'B', 'unit symbol' ) => 1,
[481] Fix | Delete
);
[482] Fix | Delete
[483] Fix | Delete
if ( 0 === $bytes ) {
[484] Fix | Delete
/* translators: Unit symbol for byte. */
[485] Fix | Delete
return number_format_i18n( 0, $decimals ) . ' ' . _x( 'B', 'unit symbol' );
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
foreach ( $quant as $unit => $mag ) {
[489] Fix | Delete
if ( (float) $bytes >= $mag ) {
[490] Fix | Delete
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
return false;
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
/**
[498] Fix | Delete
* Converts a duration to human readable format.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function