wp/wp-includes/functions.php
author ymh <ymh.work@gmail.com>
Tue, 27 Sep 2022 16:37:53 +0200
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
permissions -rw-r--r--
upgrade wordpress to 6.0.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Main WordPress API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     8
require ABSPATH . WPINC . '/option.php';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     9
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    10
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    11
 * Convert given MySQL date string into a different format.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    12
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    13
 *  - `$format` should be a PHP date format string.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    14
 *  - 'U' and 'G' formats will return an integer sum of timestamp with timezone offset.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    15
 *  - `$date` is expected to be local time in MySQL format (`Y-m-d H:i:s`).
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    16
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    17
 * Historically UTC time could be passed to the function to produce Unix timestamp.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    18
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    19
 * If `$translate` is true then the given date and format string will
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    20
 * be passed to `wp_date()` for translation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
 * @param string $format    Format of the date to return.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
 * @param string $date      Date string to convert.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
 * @param bool   $translate Whether the return date should be translated. Default true.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    27
 * @return string|int|false Integer if `$format` is 'U' or 'G', string otherwise.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    28
 *                          False on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
function mysql2date( $format, $date, $translate = true ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    31
	if ( empty( $date ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    33
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    34
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    35
	$datetime = date_create( $date, wp_timezone() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    36
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    37
	if ( false === $datetime ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    38
		return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    39
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    40
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    41
	// Returns a sum of timestamp with timezone offset. Ideally should never be used.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    42
	if ( 'G' === $format || 'U' === $format ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    43
		return $datetime->getTimestamp() + $datetime->getOffset();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    44
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    45
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    46
	if ( $translate ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    47
		return wp_date( $format, $datetime->getTimestamp() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    48
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    49
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    50
	return $datetime->format( $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    51
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    52
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    53
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    54
 * Retrieves the current time based on specified type.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    56
 *  - The 'mysql' type will return the time in the format for MySQL DATETIME field.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    57
 *  - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    58
 *    and timezone offset, depending on `$gmt`.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    59
 *  - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    60
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    61
 * If `$gmt` is a truthy value then both types will use GMT time, otherwise the
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    62
 * output is adjusted with the GMT offset for the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 * @since 1.0.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    65
 * @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    66
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    67
 * @param string   $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    68
 *                       or PHP date format string (e.g. 'Y-m-d').
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
 * @param int|bool $gmt  Optional. Whether to use GMT timezone. Default false.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    70
 * @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
function current_time( $type, $gmt = 0 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    73
	// Don't use non-GMT timestamp, unless you know the difference and really need to.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    74
	if ( 'timestamp' === $type || 'U' === $type ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    75
		return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    76
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    77
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    78
	if ( 'mysql' === $type ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    79
		$type = 'Y-m-d H:i:s';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    80
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    81
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    82
	$timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    83
	$datetime = new DateTime( 'now', $timezone );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    84
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    85
	return $datetime->format( $type );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    86
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    87
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    88
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    89
 * Retrieves the current time as an object using the site's timezone.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    90
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    91
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    92
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    93
 * @return DateTimeImmutable Date and time object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    94
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    95
function current_datetime() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    96
	return new DateTimeImmutable( 'now', wp_timezone() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    97
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    98
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    99
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   100
 * Retrieves the timezone of the site as a string.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   101
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   102
 * Uses the `timezone_string` option to get a proper timezone name if available,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   103
 * otherwise falls back to a manual UTC ± offset.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   104
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   105
 * Example return values:
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   106
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   107
 *  - 'Europe/Rome'
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   108
 *  - 'America/North_Dakota/New_Salem'
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   109
 *  - 'UTC'
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   110
 *  - '-06:30'
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   111
 *  - '+00:00'
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   112
 *  - '+08:45'
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   113
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   114
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   115
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   116
 * @return string PHP timezone name or a ±HH:MM offset.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   117
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   118
function wp_timezone_string() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   119
	$timezone_string = get_option( 'timezone_string' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   120
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   121
	if ( $timezone_string ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   122
		return $timezone_string;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   123
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   124
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   125
	$offset  = (float) get_option( 'gmt_offset' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   126
	$hours   = (int) $offset;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   127
	$minutes = ( $offset - $hours );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   128
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   129
	$sign      = ( $offset < 0 ) ? '-' : '+';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   130
	$abs_hour  = abs( $hours );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   131
	$abs_mins  = abs( $minutes * 60 );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   132
	$tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   133
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   134
	return $tz_offset;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   135
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   136
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   137
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   138
 * Retrieves the timezone of the site as a `DateTimeZone` object.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   139
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   140
 * Timezone can be based on a PHP timezone string or a ±HH:MM offset.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   141
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   142
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   143
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   144
 * @return DateTimeZone Timezone object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   145
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   146
function wp_timezone() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   147
	return new DateTimeZone( wp_timezone_string() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   148
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   149
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   150
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   151
 * Retrieves the date in localized format, based on a sum of Unix timestamp and
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   152
 * timezone offset in seconds.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 * If the locale specifies the locale month and weekday, then the locale will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 * take over the format for the date. If it isn't, then the date format string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * will be used instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   158
 * Note that due to the way WP typically generates a sum of timestamp and offset
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   159
 * with `strtotime()`, it implies offset added at a _current_ time, not at the time
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   160
 * the timestamp represents. Storing such timestamps or calculating them differently
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   161
 * will lead to invalid output.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   162
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * @since 0.71
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   164
 * @since 5.3.0 Converted into a wrapper for wp_date().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   165
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   166
 * @global WP_Locale $wp_locale WordPress date and time locale object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   167
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   168
 * @param string   $format                Format to display the date.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   169
 * @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   170
 *                                        in seconds. Default false.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   171
 * @param bool     $gmt                   Optional. Whether to use GMT timezone. Only applies
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   172
 *                                        if timestamp is not provided. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
 * @return string The date, translated if locale specifies it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   175
function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   176
	$timestamp = $timestamp_with_offset;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   177
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   178
	// If timestamp is omitted it should be current time (summed with offset, unless `$gmt` is true).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   179
	if ( ! is_numeric( $timestamp ) ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   180
		// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   181
		$timestamp = current_time( 'timestamp', $gmt );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	/*
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   185
	 * This is a legacy implementation quirk that the returned timestamp is also with offset.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   186
	 * Ideally this function should never be used to produce a timestamp.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   188
	if ( 'U' === $format ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   189
		$date = $timestamp;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   190
	} elseif ( $gmt && false === $timestamp_with_offset ) { // Current time in UTC.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   191
		$date = wp_date( $format, null, new DateTimeZone( 'UTC' ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   192
	} elseif ( false === $timestamp_with_offset ) { // Current time in site's timezone.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   193
		$date = wp_date( $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   194
	} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   195
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   196
		 * Timestamp with offset is typically produced by a UTC `strtotime()` call on an input without timezone.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   197
		 * This is the best attempt to reverse that operation into a local time to use.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   198
		 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   199
		$local_time = gmdate( 'Y-m-d H:i:s', $timestamp );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   200
		$timezone   = wp_timezone();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   201
		$datetime   = date_create( $local_time, $timezone );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   202
		$date       = wp_date( $format, $datetime->getTimestamp(), $timezone );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   203
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
	 * Filters the date formatted based on the locale.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   210
	 * @param string $date      Formatted date string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   211
	 * @param string $format    Format to display the date.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   212
	 * @param int    $timestamp A sum of Unix timestamp and timezone offset in seconds.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   213
	 *                          Might be without offset if input omitted timestamp but requested GMT.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   214
	 * @param bool   $gmt       Whether to use GMT timezone. Only applies if timestamp was not provided.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   215
	 *                          Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   217
	$date = apply_filters( 'date_i18n', $date, $format, $timestamp, $gmt );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   218
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   219
	return $date;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   220
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   221
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   222
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   223
 * Retrieves the date, in localized format.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   224
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   225
 * This is a newer function, intended to replace `date_i18n()` without legacy quirks in it.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   226
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   227
 * Note that, unlike `date_i18n()`, this function accepts a true Unix timestamp, not summed
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   228
 * with timezone offset.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   229
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   230
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   231
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   232
 * @global WP_Locale $wp_locale WordPress date and time locale object.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   233
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   234
 * @param string       $format    PHP date format.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   235
 * @param int          $timestamp Optional. Unix timestamp. Defaults to current time.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   236
 * @param DateTimeZone $timezone  Optional. Timezone to output result in. Defaults to timezone
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   237
 *                                from site settings.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   238
 * @return string|false The date, translated if locale specifies it. False on invalid timestamp input.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   239
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   240
function wp_date( $format, $timestamp = null, $timezone = null ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   241
	global $wp_locale;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   242
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   243
	if ( null === $timestamp ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   244
		$timestamp = time();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   245
	} elseif ( ! is_numeric( $timestamp ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   246
		return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   247
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   248
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   249
	if ( ! $timezone ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   250
		$timezone = wp_timezone();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   251
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   252
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   253
	$datetime = date_create( '@' . $timestamp );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   254
	$datetime->setTimezone( $timezone );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   255
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   256
	if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   257
		$date = $datetime->format( $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   258
	} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   259
		// We need to unpack shorthand `r` format because it has parts that might be localized.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   260
		$format = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   261
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   262
		$new_format    = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   263
		$format_length = strlen( $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   264
		$month         = $wp_locale->get_month( $datetime->format( 'm' ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   265
		$weekday       = $wp_locale->get_weekday( $datetime->format( 'w' ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   266
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   267
		for ( $i = 0; $i < $format_length; $i ++ ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   268
			switch ( $format[ $i ] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   269
				case 'D':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   270
					$new_format .= addcslashes( $wp_locale->get_weekday_abbrev( $weekday ), '\\A..Za..z' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   271
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   272
				case 'F':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   273
					$new_format .= addcslashes( $month, '\\A..Za..z' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   274
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   275
				case 'l':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   276
					$new_format .= addcslashes( $weekday, '\\A..Za..z' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   277
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   278
				case 'M':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   279
					$new_format .= addcslashes( $wp_locale->get_month_abbrev( $month ), '\\A..Za..z' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   280
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   281
				case 'a':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   282
					$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'a' ) ), '\\A..Za..z' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   283
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   284
				case 'A':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   285
					$new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'A' ) ), '\\A..Za..z' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   286
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   287
				case '\\':
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   288
					$new_format .= $format[ $i ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   289
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   290
					// If character follows a slash, we add it without translating.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   291
					if ( $i < $format_length ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   292
						$new_format .= $format[ ++$i ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   293
					}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   294
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   295
				default:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   296
					$new_format .= $format[ $i ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   297
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   298
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   299
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   300
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   301
		$date = $datetime->format( $new_format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   302
		$date = wp_maybe_decline_date( $date, $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   303
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   304
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   305
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   306
	 * Filters the date formatted based on the locale.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   307
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   308
	 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   309
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   310
	 * @param string       $date      Formatted date string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   311
	 * @param string       $format    Format to display the date.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   312
	 * @param int          $timestamp Unix timestamp.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   313
	 * @param DateTimeZone $timezone  Timezone.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   314
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   315
	$date = apply_filters( 'wp_date', $date, $format, $timestamp, $timezone );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   316
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   317
	return $date;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   321
 * Determines if the date should be declined.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   322
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   323
 * If the locale specifies that month names require a genitive case in certain
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
 * formats (like 'j F Y'), the month name will be replaced with a correct form.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   325
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
 * @since 4.4.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   327
 * @since 5.4.0 The `$format` parameter was added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   328
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   329
 * @global WP_Locale $wp_locale WordPress date and time locale object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   330
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   331
 * @param string $date   Formatted date string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   332
 * @param string $format Optional. Date format to check. Default empty string.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
 * @return string The date, declined if locale specifies it.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   334
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   335
function wp_maybe_decline_date( $date, $format = '' ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
	global $wp_locale;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   338
	// i18n functions are not available in SHORTINIT mode.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
	if ( ! function_exists( '_x' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
		return $date;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   343
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   344
	 * translators: If months in your language require a genitive case,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
	 * translate this to 'on'. Do not translate into your own language.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
	if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   348
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   349
		$months          = $wp_locale->month;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   350
		$months_genitive = $wp_locale->month_genitive;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   351
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   352
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   353
		 * Match a format like 'j F Y' or 'j. F' (day of the month, followed by month name)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   354
		 * and decline the month.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   355
		 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   356
		if ( $format ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   357
			$decline = preg_match( '#[dj]\.? F#', $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   358
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   359
			// If the format is not passed, try to guess it from the date string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   360
			$decline = preg_match( '#\b\d{1,2}\.? [^\d ]+\b#u', $date );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   361
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   362
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   363
		if ( $decline ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
			foreach ( $months as $key => $month ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   365
				$months[ $key ] = '# ' . preg_quote( $month, '#' ) . '\b#u';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   367
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   368
			foreach ( $months_genitive as $key => $month ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   369
				$months_genitive[ $key ] = ' ' . $month;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   370
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   371
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
			$date = preg_replace( $months, $months_genitive, $date );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   373
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   374
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   375
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   376
		 * Match a format like 'F jS' or 'F j' (month name, followed by day with an optional ordinal suffix)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   377
		 * and change it to declined 'j F'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   378
		 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   379
		if ( $format ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   380
			$decline = preg_match( '#F [dj]#', $format );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   381
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   382
			// If the format is not passed, try to guess it from the date string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   383
			$decline = preg_match( '#\b[^\d ]+ \d{1,2}(st|nd|rd|th)?\b#u', trim( $date ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   384
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   385
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   386
		if ( $decline ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   387
			foreach ( $months as $key => $month ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   388
				$months[ $key ] = '#\b' . preg_quote( $month, '#' ) . ' (\d{1,2})(st|nd|rd|th)?([-–]\d{1,2})?(st|nd|rd|th)?\b#u';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   389
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   390
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   391
			foreach ( $months_genitive as $key => $month ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   392
				$months_genitive[ $key ] = '$1$3 ' . $month;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   393
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   394
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   395
			$date = preg_replace( $months, $months_genitive, $date );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   396
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   397
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   398
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   399
	// Used for locale-specific rules.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
	$locale = get_locale();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   401
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
	if ( 'ca' === $locale ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
		// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
		$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
	return $date;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
 * Convert float number to format based on the locale.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   415
 * @global WP_Locale $wp_locale WordPress date and time locale object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   416
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   417
 * @param float $number   The number to convert based on locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   418
 * @param int   $decimals Optional. Precision of the number of decimal places. Default 0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
 * @return string Converted number in string format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
function number_format_i18n( $number, $decimals = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	global $wp_locale;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   423
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   424
	if ( isset( $wp_locale ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   425
		$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   427
		$formatted = number_format( $number, absint( $decimals ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   428
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   431
	 * Filters the number formatted based on the locale.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
	 * @since 2.8.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   434
	 * @since 4.9.0 The `$number` and `$decimals` parameters were added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
	 * @param string $formatted Converted number in string format.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
	 * @param float  $number    The number to convert based on locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
	 * @param int    $decimals  Precision of the number of decimal places.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   440
	return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   444
 * Converts a number of bytes to the largest unit the bytes will fit into.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
 * It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
 * number of bytes to human readable number by taking the number of that unit
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   448
 * that the bytes will go into it. Supports YB value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
 * Please note that integers in PHP are limited to 32 bits, unless they are on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
 * 64 bit architecture, then they have 64 bit size. If you need to place the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
 * larger size then what PHP integer type will hold, then use a string. It will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
 * be converted to a double, which should always have 64 bit length.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
 * Technically the correct unit names for powers of 1024 are KiB, MiB etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
 * @since 2.3.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   458
 * @since 6.0.0 Support for PB, EB, ZB, and YB was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
 * @param int|string $bytes    Number of bytes. Note max integer size for integers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
 * @param int        $decimals Optional. Precision of number of decimal places. Default 0.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   462
 * @return string|false Number string on success, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
function size_format( $bytes, $decimals = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	$quant = array(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   466
		/* translators: Unit symbol for yottabyte. */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   467
		_x( 'YB', 'unit symbol' ) => YB_IN_BYTES,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   468
		/* translators: Unit symbol for zettabyte. */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   469
		_x( 'ZB', 'unit symbol' ) => ZB_IN_BYTES,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   470
		/* translators: Unit symbol for exabyte. */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   471
		_x( 'EB', 'unit symbol' ) => EB_IN_BYTES,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   472
		/* translators: Unit symbol for petabyte. */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   473
		_x( 'PB', 'unit symbol' ) => PB_IN_BYTES,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   474
		/* translators: Unit symbol for terabyte. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   475
		_x( 'TB', 'unit symbol' ) => TB_IN_BYTES,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   476
		/* translators: Unit symbol for gigabyte. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   477
		_x( 'GB', 'unit symbol' ) => GB_IN_BYTES,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   478
		/* translators: Unit symbol for megabyte. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   479
		_x( 'MB', 'unit symbol' ) => MB_IN_BYTES,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   480
		/* translators: Unit symbol for kilobyte. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   481
		_x( 'KB', 'unit symbol' ) => KB_IN_BYTES,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   482
		/* translators: Unit symbol for byte. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   483
		_x( 'B', 'unit symbol' )  => 1,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   486
	if ( 0 === $bytes ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   487
		/* translators: Unit symbol for byte. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   488
		return number_format_i18n( 0, $decimals ) . ' ' . _x( 'B', 'unit symbol' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   489
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   490
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	foreach ( $quant as $unit => $mag ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   492
		if ( (float) $bytes >= $mag ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
			return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
 * Convert a duration to human readable format.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   502
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   503
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   504
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   505
 * @param string $duration Duration will be in string format (HH:ii:ss) OR (ii:ss),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   506
 *                         with a possible prepended negative sign (-).
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   507
 * @return string|false A human readable duration string, false on failure.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   508
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   509
function human_readable_duration( $duration = '' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   510
	if ( ( empty( $duration ) || ! is_string( $duration ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   511
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   512
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   513
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   514
	$duration = trim( $duration );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   515
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   516
	// Remove prepended negative sign.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   517
	if ( '-' === substr( $duration, 0, 1 ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   518
		$duration = substr( $duration, 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   519
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   520
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   521
	// Extract duration parts.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   522
	$duration_parts = array_reverse( explode( ':', $duration ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   523
	$duration_count = count( $duration_parts );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   524
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   525
	$hour   = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   526
	$minute = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   527
	$second = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   528
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   529
	if ( 3 === $duration_count ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   530
		// Validate HH:ii:ss duration format.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   531
		if ( ! ( (bool) preg_match( '/^([0-9]+):([0-5]?[0-9]):([0-5]?[0-9])$/', $duration ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   532
			return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   533
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   534
		// Three parts: hours, minutes & seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   535
		list( $second, $minute, $hour ) = $duration_parts;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   536
	} elseif ( 2 === $duration_count ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   537
		// Validate ii:ss duration format.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   538
		if ( ! ( (bool) preg_match( '/^([0-5]?[0-9]):([0-5]?[0-9])$/', $duration ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   539
			return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   540
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   541
		// Two parts: minutes & seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   542
		list( $second, $minute ) = $duration_parts;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   543
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   544
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   545
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   546
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   547
	$human_readable_duration = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   548
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   549
	// Add the hour part to the string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   550
	if ( is_numeric( $hour ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   551
		/* translators: %s: Time duration in hour or hours. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   552
		$human_readable_duration[] = sprintf( _n( '%s hour', '%s hours', $hour ), (int) $hour );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   553
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   554
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   555
	// Add the minute part to the string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   556
	if ( is_numeric( $minute ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   557
		/* translators: %s: Time duration in minute or minutes. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   558
		$human_readable_duration[] = sprintf( _n( '%s minute', '%s minutes', $minute ), (int) $minute );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   559
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   560
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   561
	// Add the second part to the string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   562
	if ( is_numeric( $second ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   563
		/* translators: %s: Time duration in second or seconds. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   564
		$human_readable_duration[] = sprintf( _n( '%s second', '%s seconds', $second ), (int) $second );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   565
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   566
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   567
	return implode( ', ', $human_readable_duration );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   568
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   569
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   570
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
 * Get the week start and end from the datetime or date string from MySQL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
 * @param string     $mysqlstring   Date or datetime field type from MySQL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
 * @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   577
 * @return int[] {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   578
 *     Week start and end dates as Unix timestamps.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   579
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   580
 *     @type int $start The week start date as a Unix timestamp.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   581
 *     @type int $end   The week end date as a Unix timestamp.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   582
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
	// MySQL string year.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
	$my = substr( $mysqlstring, 0, 4 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
	// MySQL string month.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
	$mm = substr( $mysqlstring, 8, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
	// MySQL string day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   592
	$md = substr( $mysqlstring, 5, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
	// The timestamp for MySQL string day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
	$day = mktime( 0, 0, 0, $md, $mm, $my );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
	// The day of the week from the timestamp.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   598
	$weekday = gmdate( 'w', $day );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   600
	if ( ! is_numeric( $start_of_week ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		$start_of_week = get_option( 'start_of_week' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   602
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   603
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   604
	if ( $weekday < $start_of_week ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
		$weekday += 7;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   606
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   608
	// The most recent week start day on or before $day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   609
	$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   610
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   611
	// $start + 1 week - 1 second.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   612
	$end = $start + WEEK_IN_SECONDS - 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	return compact( 'start', 'end' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   617
 * Serialize data, if needed.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   618
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   619
 * @since 2.0.5
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   620
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   621
 * @param string|array|object $data Data that might be serialized.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   622
 * @return mixed A scalar data.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   623
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   624
function maybe_serialize( $data ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   625
	if ( is_array( $data ) || is_object( $data ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   626
		return serialize( $data );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   627
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   628
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   629
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   630
	 * Double serialization is required for backward compatibility.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   631
	 * See https://core.trac.wordpress.org/ticket/12930
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   632
	 * Also the world will end. See WP 3.6.1.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   633
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   634
	if ( is_serialized( $data, false ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   635
		return serialize( $data );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   636
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   637
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   638
	return $data;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   639
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   640
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   641
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   642
 * Unserialize data only if it was serialized.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   646
 * @param string $data Data that might be unserialized.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
 * @return mixed Unserialized data can be any type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   649
function maybe_unserialize( $data ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   650
	if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   651
		return @unserialize( trim( $data ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   652
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   653
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   654
	return $data;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
 * Check value to find if it was serialized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
 * If $data is not an string, then returned value will always be false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
 * Serialized data is always a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   665
 * @param string $data   Value to check to see if was serialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   666
 * @param bool   $strict Optional. Whether to be strict about the end of the string. Default true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 * @return bool False if not serialized and true if it was.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
function is_serialized( $data, $strict = true ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   670
	// If it isn't a string, it isn't serialized.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
	if ( ! is_string( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   673
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	$data = trim( $data );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   675
	if ( 'N;' === $data ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
	if ( strlen( $data ) < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
	if ( ':' !== $data[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	if ( $strict ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
		$lastc = substr( $data, -1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   686
		if ( ';' !== $lastc && '}' !== $lastc ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   688
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
		$semicolon = strpos( $data, ';' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
		$brace     = strpos( $data, '}' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
		// Either ; or } must exist.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   693
		if ( false === $semicolon && false === $brace ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   695
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
		// But neither must be in the first X characters.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   697
		if ( false !== $semicolon && $semicolon < 3 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   699
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   700
		if ( false !== $brace && $brace < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   702
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	$token = $data[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	switch ( $token ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   706
		case 's':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
			if ( $strict ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   708
				if ( '"' !== substr( $data, -2, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
					return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   710
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
			} elseif ( false === strpos( $data, '"' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   714
			// Or else fall through.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   715
		case 'a':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   716
		case 'O':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
			return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   718
		case 'b':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   719
		case 'i':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   720
		case 'd':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
			$end = $strict ? '$' : '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   722
			return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 * Check whether serialized data is of string type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
 * @param string $data Serialized data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
 * @return bool False if not a serialized string, true if it is.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
function is_serialized_string( $data ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
	// if it isn't a string, it isn't a serialized string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
	if ( ! is_string( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	$data = trim( $data );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   741
	if ( strlen( $data ) < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   743
	} elseif ( ':' !== $data[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
	} elseif ( ';' !== substr( $data, -1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		return false;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   747
	} elseif ( 's' !== $data[0] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
	} elseif ( '"' !== substr( $data, -2, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 * Retrieve post title from XMLRPC XML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
 * If the title element is not part of the XML, then the default post title from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
 * the $post_default_title will be used instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
 * @global string $post_default_title Default XML-RPC post title.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
 * @param string $content XMLRPC XML Request content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
 * @return string Post title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
function xmlrpc_getposttitle( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	global $post_default_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
		$post_title = $matchtitle[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		$post_title = $post_default_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
	return $post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
 * Retrieve the post category or categories from XMLRPC XML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 * If the category element is not found, then the default post category will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
 * used. The return type then would be what $post_default_category. If the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
 * category is found, then it will always be an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   788
 * @global string $post_default_category Default XML-RPC post category.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
 * @param string $content XMLRPC XML Request content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
 * @return string|array List of categories or category name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
function xmlrpc_getpostcategory( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	global $post_default_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
	if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		$post_category = trim( $matchcat[1], ',' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		$post_category = explode( ',', $post_category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
		$post_category = $post_default_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	return $post_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
 * XMLRPC XML content without title and category elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
 * @param string $content XML-RPC XML Request content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 * @return string XMLRPC XML Request content without title and category elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
function xmlrpc_removepostdata( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	$content = trim( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
 * Use RegEx to extract URLs from arbitrary content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
 * @since 3.7.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   823
 * @since 6.0.0 Fixes support for HTML entities (Trac 30580).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
 * @param string $content Content to extract URLs from.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   826
 * @return string[] Array of URLs found in passed string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
function wp_extract_urls( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	preg_match_all(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
		"#([\"']?)("
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   831
			. '(?:([\w-]+:)?//?)'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   832
			. '[^\s()<>]+'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   833
			. '[.]'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   834
			. '(?:'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   835
				. '\([\w\d]+\)|'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   836
				. '(?:'
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   837
					. "[^`!()\[\]{}:'\".,<>«»“”‘’\s]|"
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   838
					. '(?:[:]\d+)?/?'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   839
				. ')+'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   840
			. ')'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
		. ")\\1#",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
		$content,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
		$post_links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   846
	$post_links = array_unique(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   847
		array_map(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   848
			static function( $link ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   849
				// Decode to replace valid entities, like &amp;.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   850
				$link = html_entity_decode( $link );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   851
				// Maintain backward compatibility by removing extraneous semi-colons (`;`).
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   852
				return str_replace( ';', '', $link );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   853
			},
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   854
			$post_links[2]
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   855
		)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   856
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	return array_values( $post_links );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
 * Check content for video and audio links to add as enclosures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
 * Will not add enclosures that have already been added and will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 * remove enclosures that are no longer in the post. This is called as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
 * pingbacks and trackbacks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
 * @since 1.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   869
 * @since 5.3.0 The `$content` parameter was made optional, and the `$post` parameter was
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   870
 *              updated to accept a post ID or a WP_Post object.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   871
 * @since 5.6.0 The `$content` parameter is no longer optional, but passing `null` to skip it
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   872
 *              is still supported.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   874
 * @global wpdb $wpdb WordPress database abstraction object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   876
 * @param string|null $content Post content. If `null`, the `post_content` field from `$post` is used.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   877
 * @param int|WP_Post $post    Post ID or post object.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   878
 * @return void|false Void on success, false if the post is not found.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   879
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   880
function do_enclose( $content, $post ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   883
	// @todo Tidy this code and make the debug code optional.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   884
	include_once ABSPATH . WPINC . '/class-IXR.php';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   885
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   886
	$post = get_post( $post );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   887
	if ( ! $post ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   888
		return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   889
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   890
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   891
	if ( null === $content ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   892
		$content = $post->post_content;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   893
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	$post_links = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   897
	$pung = get_enclosed( $post->ID );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	$post_links_temp = wp_extract_urls( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	foreach ( $pung as $link_test ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   902
		// Link is no longer in post.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   903
		if ( ! in_array( $link_test, $post_links_temp, true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   904
			$mids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $link_test ) . '%' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   905
			foreach ( $mids as $mid ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
				delete_metadata_by_mid( 'post', $mid );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   907
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
	foreach ( (array) $post_links_temp as $link_test ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   912
		// If we haven't pung it already.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   913
		if ( ! in_array( $link_test, $pung, true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   914
			$test = parse_url( $link_test );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   915
			if ( false === $test ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
				continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   917
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   918
			if ( isset( $test['query'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
				$post_links[] = $link_test;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   920
			} elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
				$post_links[] = $link_test;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   922
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   926
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   927
	 * Filters the list of enclosure links before querying the database.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   928
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   929
	 * Allows for the addition and/or removal of potential enclosures to save
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   930
	 * to postmeta before checking the database for existing enclosures.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   931
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   932
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   933
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   934
	 * @param string[] $post_links An array of enclosure links.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   935
	 * @param int      $post_ID    Post ID.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   936
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   937
	$post_links = apply_filters( 'enclosure_links', $post_links, $post->ID );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   938
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
	foreach ( (array) $post_links as $url ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   940
		$url = strip_fragment_from_url( $url );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   941
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   942
		if ( '' !== $url && ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $url ) . '%' ) ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   943
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   944
			$headers = wp_get_http_headers( $url );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   945
			if ( $headers ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   946
				$len           = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   947
				$type          = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
				$allowed_types = array( 'video', 'audio' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   950
				// Check to see if we can figure out the mime type from the extension.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   951
				$url_parts = parse_url( $url );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   952
				if ( false !== $url_parts && ! empty( $url_parts['path'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
					$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   954
					if ( ! empty( $extension ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
						foreach ( wp_get_mime_types() as $exts => $mime ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
							if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
								$type = $mime;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
								break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   964
				if ( in_array( substr( $type, 0, strpos( $type, '/' ) ), $allowed_types, true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   965
					add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
 * Retrieve HTTP Headers from URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
 * @since 1.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   977
 * @param string $url        URL to retrieve HTTP headers from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
 * @param bool   $deprecated Not Used.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   979
 * @return string|false Headers on success, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
function wp_get_http_headers( $url, $deprecated = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   982
	if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   983
		_deprecated_argument( __FUNCTION__, '2.7.0' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   984
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	$response = wp_safe_remote_head( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   988
	if ( is_wp_error( $response ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   990
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
	return wp_remote_retrieve_headers( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   996
 * Determines whether the publish date of the current post in the loop is different
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   997
 * from the publish date of the previous post in the loop.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   998
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   999
 * For more information on this and similar theme functions, check out
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1000
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1001
 * Conditional Tags} article in the Theme Developer Handbook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
 * @since 0.71
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
 * @global string $currentday  The day of the current post in the loop.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
 * @global string $previousday The day of the previous post in the loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
 * @return int 1 when new day, 0 if not a new day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
function is_new_day() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	global $currentday, $previousday;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1012
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1013
	if ( $currentday !== $previousday ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
		return 1;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1015
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
		return 0;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1017
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
 * Build URL query based on an associative and, or indexed array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
 * This is a convenient function for easily building url queries. It sets the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
 * separator to '&' and uses _http_build_query() function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1026
 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1027
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
 * @see _http_build_query() Used to build the query
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1029
 * @link https://www.php.net/manual/en/function.http-build-query.php for more on what
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1030
 *       http_build_query() does.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
 * @param array $data URL-encode key/value pairs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
 * @return string URL-encoded string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
function build_query( $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
	return _http_build_query( $data, null, '&', '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
 * From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
 * @since 3.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1045
 * @see https://www.php.net/manual/en/function.http-build-query.php
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1046
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1047
 * @param array|object $data      An array or object of data. Converted to array.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1048
 * @param string       $prefix    Optional. Numeric index. If set, start parameter numbering with it.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1049
 *                                Default null.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1050
 * @param string       $sep       Optional. Argument separator; defaults to 'arg_separator.output'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1051
 *                                Default null.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1052
 * @param string       $key       Optional. Used to prefix key name. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1053
 * @param bool         $urlencode Optional. Whether to use urlencode() in the result. Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
 * @return string The query string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
	$ret = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	foreach ( (array) $data as $k => $v ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1060
		if ( $urlencode ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1061
			$k = urlencode( $k );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1062
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1063
		if ( is_int( $k ) && null != $prefix ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1064
			$k = $prefix . $k;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1065
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1066
		if ( ! empty( $key ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
			$k = $key . '%5B' . $k . '%5D';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1068
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1069
		if ( null === $v ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
			continue;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1071
		} elseif ( false === $v ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
			$v = '0';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1073
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1074
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1075
		if ( is_array( $v ) || is_object( $v ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1076
			array_push( $ret, _http_build_query( $v, '', $sep, $k, $urlencode ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1077
		} elseif ( $urlencode ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1078
			array_push( $ret, $k . '=' . urlencode( $v ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1079
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1080
			array_push( $ret, $k . '=' . $v );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1081
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1082
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1083
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1084
	if ( null === $sep ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1085
		$sep = ini_get( 'arg_separator.output' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1086
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1087
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1088
	return implode( $sep, $ret );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
 * Retrieves a modified URL query string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
 * You can rebuild the URL and append query variables to the URL query by using this function.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
 * There are two ways to use this function; either a single key and value, or an associative array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
 * Using a single key and value:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
 *     add_query_arg( 'key', 'value', 'http://example.com' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1101
 * Using an associative array:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1102
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1103
 *     add_query_arg( array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1104
 *         'key1' => 'value1',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1105
 *         'key2' => 'value2',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
 *     ), 'http://example.com' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1107
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1108
 * Omitting the URL from either use results in the current URL being used
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1109
 * (the value of `$_SERVER['REQUEST_URI']`).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
 * Values are expected to be encoded appropriately with urlencode() or rawurlencode().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1112
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
 * Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
 * Important: The return value of add_query_arg() is not escaped by default. Output should be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
 * late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
 * (XSS) attacks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
 * @since 1.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1120
 * @since 5.3.0 Formalized the existing and already documented parameters
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1121
 *              by adding `...$args` to the function signature.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1123
 * @param string|array $key   Either a query variable key, or an associative array of query variables.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1124
 * @param string       $value Optional. Either a query variable value, or a URL to act upon.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1125
 * @param string       $url   Optional. A URL to act upon.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1126
 * @return string New URL query string (unescaped).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1128
function add_query_arg( ...$args ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
	if ( is_array( $args[0] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1130
		if ( count( $args ) < 2 || false === $args[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
			$uri = $_SERVER['REQUEST_URI'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1132
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
			$uri = $args[1];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1134
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1136
		if ( count( $args ) < 3 || false === $args[2] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
			$uri = $_SERVER['REQUEST_URI'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1138
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
			$uri = $args[2];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1140
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1141
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1142
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1143
	$frag = strstr( $uri, '#' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1144
	if ( $frag ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
		$uri = substr( $uri, 0, -strlen( $frag ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1146
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
		$frag = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1148
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
	if ( 0 === stripos( $uri, 'http://' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
		$protocol = 'http://';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1152
		$uri      = substr( $uri, 7 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
	} elseif ( 0 === stripos( $uri, 'https://' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
		$protocol = 'https://';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1155
		$uri      = substr( $uri, 8 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
		$protocol = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	if ( strpos( $uri, '?' ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
		list( $base, $query ) = explode( '?', $uri, 2 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1162
		$base                .= '?';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1164
		$base  = $uri . '?';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
		$query = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1167
		$base  = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
		$query = $uri;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
	wp_parse_str( $query, $qs );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1172
	$qs = urlencode_deep( $qs ); // This re-URL-encodes things that were already in the query string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	if ( is_array( $args[0] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
		foreach ( $args[0] as $k => $v ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
			$qs[ $k ] = $v;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1176
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
		$qs[ $args[0] ] = $args[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
	foreach ( $qs as $k => $v ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1182
		if ( false === $v ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1183
			unset( $qs[ $k ] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1184
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
	$ret = build_query( $qs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
	$ret = trim( $ret, '?' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
	$ret = preg_replace( '#=(&|$)#', '$1', $ret );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	$ret = $protocol . $base . $ret . $frag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
	$ret = rtrim( $ret, '?' );
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1192
	$ret = str_replace( '?#', '#', $ret );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
	return $ret;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1197
 * Removes an item or items from a query string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1201
 * @param string|string[] $key   Query key or keys to remove.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1202
 * @param false|string    $query Optional. When false uses the current URL. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
 * @return string New URL query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1205
function remove_query_arg( $key, $query = false ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1206
	if ( is_array( $key ) ) { // Removing multiple keys.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1207
		foreach ( $key as $k ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
			$query = add_query_arg( $k, false, $query );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1209
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
		return $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
	return add_query_arg( $key, false, $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1216
 * Returns an array of single-use query variable names that can be removed from a URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1217
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1218
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1219
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1220
 * @return string[] An array of query variable names to remove from the URL.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1221
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1222
function wp_removable_query_args() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1223
	$removable_query_args = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1224
		'activate',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1225
		'activated',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1226
		'admin_email_remind_later',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1227
		'approved',
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1228
		'core-major-auto-updates-saved',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1229
		'deactivate',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1230
		'delete_count',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1231
		'deleted',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1232
		'disabled',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1233
		'doing_wp_cron',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1234
		'enabled',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1235
		'error',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1236
		'hotkeys_highlight_first',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1237
		'hotkeys_highlight_last',
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1238
		'ids',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1239
		'locked',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1240
		'message',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1241
		'same',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1242
		'saved',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1243
		'settings-updated',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1244
		'skipped',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1245
		'spammed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1246
		'trashed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1247
		'unspammed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1248
		'untrashed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1249
		'update',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1250
		'updated',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1251
		'wp-post-new-reload',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1252
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1253
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1254
	/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1255
	 * Filters the list of query variable names to remove.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1256
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1257
	 * @since 4.2.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1258
	 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1259
	 * @param string[] $removable_query_args An array of query variable names to remove from a URL.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1260
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1261
	return apply_filters( 'removable_query_args', $removable_query_args );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1262
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1263
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1264
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
 * Walks the array while sanitizing the contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
 * @since 0.71
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1268
 * @since 5.5.0 Non-string values are left untouched.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
 * @param array $array Array to walk while sanitizing contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
 * @return array Sanitized $array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
function add_magic_quotes( $array ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
	foreach ( (array) $array as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
		if ( is_array( $v ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1276
			$array[ $k ] = add_magic_quotes( $v );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1277
		} elseif ( is_string( $v ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1278
			$array[ $k ] = addslashes( $v );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1279
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1280
			continue;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1283
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
	return $array;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
 * HTTP request for URI to retrieve content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
 * @since 1.5.1
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1291
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1292
 * @see wp_safe_remote_get()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
 * @param string $uri URI/URL of web page to retrieve.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1295
 * @return string|false HTTP content. False on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
function wp_remote_fopen( $uri ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1298
	$parsed_url = parse_url( $uri );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1300
	if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1302
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1303
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1304
	$options            = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
	$options['timeout'] = 10;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
	$response = wp_safe_remote_get( $uri, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1309
	if ( is_wp_error( $response ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1311
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
	return wp_remote_retrieve_body( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
 * Set up the WordPress query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1321
 * @global WP       $wp           Current WordPress environment instance.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1322
 * @global WP_Query $wp_query     WordPress Query object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1323
 * @global WP_Query $wp_the_query Copy of the WordPress Query object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1324
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1325
 * @param string|array $query_vars Default WP_Query arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
function wp( $query_vars = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
	global $wp, $wp_query, $wp_the_query;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1329
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
	$wp->main( $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1332
	if ( ! isset( $wp_the_query ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
		$wp_the_query = $wp_query;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1334
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
 * Retrieve the description for the HTTP status.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
 * @since 2.3.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1341
 * @since 3.9.0 Added status codes 418, 428, 429, 431, and 511.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1342
 * @since 4.5.0 Added status codes 308, 421, and 451.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1343
 * @since 5.1.0 Added status code 103.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1345
 * @global array $wp_header_to_desc
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1346
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
 * @param int $code HTTP status code.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1348
 * @return string Status description if found, an empty string otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
function get_status_header_desc( $code ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
	global $wp_header_to_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
	$code = absint( $code );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1355
	if ( ! isset( $wp_header_to_desc ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
		$wp_header_to_desc = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
			100 => 'Continue',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			101 => 'Switching Protocols',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
			102 => 'Processing',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1360
			103 => 'Early Hints',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
			200 => 'OK',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
			201 => 'Created',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
			202 => 'Accepted',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
			203 => 'Non-Authoritative Information',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
			204 => 'No Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
			205 => 'Reset Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			206 => 'Partial Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
			207 => 'Multi-Status',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
			226 => 'IM Used',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
			300 => 'Multiple Choices',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
			301 => 'Moved Permanently',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
			302 => 'Found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
			303 => 'See Other',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
			304 => 'Not Modified',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
			305 => 'Use Proxy',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
			306 => 'Reserved',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
			307 => 'Temporary Redirect',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1380
			308 => 'Permanent Redirect',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
			400 => 'Bad Request',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
			401 => 'Unauthorized',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
			402 => 'Payment Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
			403 => 'Forbidden',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
			404 => 'Not Found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
			405 => 'Method Not Allowed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
			406 => 'Not Acceptable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
			407 => 'Proxy Authentication Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
			408 => 'Request Timeout',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
			409 => 'Conflict',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
			410 => 'Gone',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
			411 => 'Length Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
			412 => 'Precondition Failed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
			413 => 'Request Entity Too Large',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
			414 => 'Request-URI Too Long',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
			415 => 'Unsupported Media Type',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
			416 => 'Requested Range Not Satisfiable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
			417 => 'Expectation Failed',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1400
			418 => 'I\'m a teapot',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1401
			421 => 'Misdirected Request',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
			422 => 'Unprocessable Entity',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
			423 => 'Locked',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
			424 => 'Failed Dependency',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
			426 => 'Upgrade Required',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
			428 => 'Precondition Required',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
			429 => 'Too Many Requests',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1408
			431 => 'Request Header Fields Too Large',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1409
			451 => 'Unavailable For Legal Reasons',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
			500 => 'Internal Server Error',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
			501 => 'Not Implemented',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
			502 => 'Bad Gateway',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
			503 => 'Service Unavailable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
			504 => 'Gateway Timeout',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
			505 => 'HTTP Version Not Supported',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
			506 => 'Variant Also Negotiates',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
			507 => 'Insufficient Storage',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1419
			510 => 'Not Extended',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1420
			511 => 'Network Authentication Required',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1424
	if ( isset( $wp_header_to_desc[ $code ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1425
		return $wp_header_to_desc[ $code ];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1426
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1428
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
 * Set HTTP status header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1435
 * @since 4.4.0 Added the `$description` parameter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1436
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
 * @see get_status_header_desc()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1438
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1439
 * @param int    $code        HTTP status code.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1440
 * @param string $description Optional. A custom description for the HTTP status.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1441
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1442
function status_header( $code, $description = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1443
	if ( ! $description ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1444
		$description = get_status_header_desc( $code );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1445
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1446
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1447
	if ( empty( $description ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1448
		return;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1449
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1450
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1451
	$protocol      = wp_get_server_protocol();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1452
	$status_header = "$protocol $code $description";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1453
	if ( function_exists( 'apply_filters' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1456
		 * Filters an HTTP status header.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
		 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
		 * @param string $status_header HTTP status header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
		 * @param int    $code          HTTP status code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
		 * @param string $description   Description for the status code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
		 * @param string $protocol      Server protocol.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1465
		$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1466
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1468
	if ( ! headers_sent() ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1469
		header( $status_header, true, $code );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1470
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
 * Get the header information to prevent caching.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
 * The several different headers cover the different ways cache prevention
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
 * is handled by different browsers
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
 * @return array The associative array of header names and field values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
function wp_get_nocache_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
	$headers = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1485
		'Expires'       => 'Wed, 11 Jan 1984 05:00:00 GMT',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
		'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1489
	if ( function_exists( 'apply_filters' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1491
		 * Filters the cache-controlling headers.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
		 * @see wp_get_nocache_headers()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
		 * @param array $headers {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
		 *     Header names and field values.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
		 *     @type string $Expires       Expires header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
		 *     @type string $Cache-Control Cache-Control header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
		 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
		$headers = (array) apply_filters( 'nocache_headers', $headers );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
	$headers['Last-Modified'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
	return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1511
 * Set the headers to prevent caching for the different browsers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1512
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
 * Different browsers support different nocache headers, so several
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
 * headers must be sent so that all of them get the point that no
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1515
 * caching should occur.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
 * @since 2.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1519
 * @see wp_get_nocache_headers()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
function nocache_headers() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1522
	if ( headers_sent() ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1523
		return;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1524
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1525
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
	$headers = wp_get_nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	unset( $headers['Last-Modified'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1530
	header_remove( 'Last-Modified' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1532
	foreach ( $headers as $name => $field_value ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1533
		header( "{$name}: {$field_value}" );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1534
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
 * Set the headers for caching for 10 days with JavaScript content type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
function cache_javascript_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
	$expiresOffset = 10 * DAY_IN_SECONDS;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1545
	header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1546
	header( 'Vary: Accept-Encoding' ); // Handle proxies.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1547
	header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiresOffset ) . ' GMT' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
 * Retrieve the number of database queries during the WordPress execution.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1555
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1556
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1557
 * @return int Number of database queries.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
function get_num_queries() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
	return $wpdb->num_queries;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1565
 * Whether input is yes or no.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1566
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1567
 * Must be 'y' to be true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1571
 * @param string $yn Character string containing either 'y' (yes) or 'n' (no).
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1572
 * @return bool True if 'y', false on anything else.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
function bool_from_yn( $yn ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1575
	return ( 'y' === strtolower( $yn ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1579
 * Load the feed template from the use of an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
 * If the feed action does not have a hook, then the function will die with a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
 * message telling the visitor that the feed is not valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
 * It is better to only have one hook for each feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1588
 * @global WP_Query $wp_query WordPress Query object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
function do_feed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
	$feed = get_query_var( 'feed' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
	// Remove the pad, if present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
	$feed = preg_replace( '/^_+/', '', $feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1598
	if ( '' === $feed || 'feed' === $feed ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
		$feed = get_default_feed();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1600
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1602
	if ( ! has_action( "do_feed_{$feed}" ) ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1603
		wp_die( __( '<strong>Error</strong>: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1604
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1606
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1607
	 * Fires once the given feed is loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1608
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1609
	 * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1610
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1611
	 * Possible hook names include:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1612
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1613
	 *  - `do_feed_atom`
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1614
	 *  - `do_feed_rdf`
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1615
	 *  - `do_feed_rss`
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1616
	 *  - `do_feed_rss2`
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1617
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1618
	 * @since 2.1.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1619
	 * @since 4.4.0 The `$feed` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1620
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1621
	 * @param bool   $is_comment_feed Whether the feed is a comment feed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1622
	 * @param string $feed            The feed name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1623
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1624
	do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
 * Load the RDF RSS 0.91 Feed template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1631
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1632
 * @see load_template()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
function do_feed_rdf() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
	load_template( ABSPATH . WPINC . '/feed-rdf.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
 * Load the RSS 1.0 Feed Template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1642
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1643
 * @see load_template()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
function do_feed_rss() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
	load_template( ABSPATH . WPINC . '/feed-rss.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
 * Load either the RSS2 comment feed or the RSS2 posts feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
 * @see load_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1655
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
 * @param bool $for_comments True for the comment feed, false for normal feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
function do_feed_rss2( $for_comments ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1659
	if ( $for_comments ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
		load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1661
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
		load_template( ABSPATH . WPINC . '/feed-rss2.php' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1663
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
 * Load either Atom comment feed or Atom posts feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1671
 * @see load_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1672
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
 * @param bool $for_comments True for the comment feed, false for normal feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
function do_feed_atom( $for_comments ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1676
	if ( $for_comments ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1677
		load_template( ABSPATH . WPINC . '/feed-atom-comments.php' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1678
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
		load_template( ABSPATH . WPINC . '/feed-atom.php' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1680
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1684
 * Displays the default robots.txt file content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
 * @since 2.1.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1687
 * @since 5.3.0 Remove the "Disallow: /" output if search engine visiblity is
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1688
 *              discouraged in favor of robots meta HTML tag via wp_robots_no_robots()
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1689
 *              filter callback.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
function do_robots() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
	header( 'Content-Type: text/plain; charset=utf-8' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1694
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1695
	 * Fires when displaying the robots.txt file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1696
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1697
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1698
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
	do_action( 'do_robotstxt' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
	$output = "User-agent: *\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
	$public = get_option( 'blog_public' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1703
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1704
	$site_url = parse_url( site_url() );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1705
	$path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1706
	$output  .= "Disallow: $path/wp-admin/\n";
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1707
	$output  .= "Allow: $path/wp-admin/admin-ajax.php\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1709
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1710
	 * Filters the robots.txt output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1711
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1712
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1713
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1714
	 * @param string $output The robots.txt output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1715
	 * @param bool   $public Whether the site is considered "public".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1716
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1717
	echo apply_filters( 'robots_txt', $output, $public );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1721
 * Display the favicon.ico file content.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1722
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1723
 * @since 5.4.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1724
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1725
function do_favicon() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1726
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1727
	 * Fires when serving the favicon.ico file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1728
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1729
	 * @since 5.4.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1730
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1731
	do_action( 'do_faviconico' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1732
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1733
	wp_redirect( get_site_icon_url( 32, includes_url( 'images/w-logo-blue-white-bg.png' ) ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1734
	exit;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1735
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1736
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1737
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1738
 * Determines whether WordPress is already installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1740
 * The cache will be checked first. If you have a cache plugin, which saves
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1741
 * the cache values, then this will work. If you use the default WordPress
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
 * cache, and the database goes away, then you might have problems.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1743
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1744
 * Checks for the 'siteurl' option for whether WordPress is installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1746
 * For more information on this and similar theme functions, check out
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1747
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1748
 * Conditional Tags} article in the Theme Developer Handbook.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1749
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1751
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1752
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1753
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1754
 * @return bool Whether the site is already installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
function is_blog_installed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1759
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1760
	 * Check cache first. If options table goes away and we have true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1761
	 * cached, oh well.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1762
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1763
	if ( wp_cache_get( 'is_blog_installed' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1765
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
	$suppress = $wpdb->suppress_errors();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1768
	if ( ! wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
		$alloptions = wp_load_alloptions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1771
	// If siteurl is not set to autoload, check it specifically.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1772
	if ( ! isset( $alloptions['siteurl'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
		$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1774
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
		$installed = $alloptions['siteurl'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1776
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
	$wpdb->suppress_errors( $suppress );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1779
	$installed = ! empty( $installed );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
	wp_cache_set( 'is_blog_installed', $installed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1782
	if ( $installed ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1784
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
	// If visiting repair.php, return true and let it take over.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1787
	if ( defined( 'WP_REPAIRING' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1789
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
	$suppress = $wpdb->suppress_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1793
	/*
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1794
	 * Loop over the WP tables. If none exist, then scratch installation is allowed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1795
	 * If one or more exist, suggest table repair since we got here because the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1796
	 * options table could not be accessed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1797
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
	$wp_tables = $wpdb->tables();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
	foreach ( $wp_tables as $table ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1800
		// The existence of custom user tables shouldn't suggest an unwise state or prevent a clean installation.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1801
		if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1803
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1804
		if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1806
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1807
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1808
		$described_table = $wpdb->get_results( "DESCRIBE $table;" );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1809
		if (
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1810
			( ! $described_table && empty( $wpdb->last_error ) ) ||
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1811
			( is_array( $described_table ) && 0 === count( $described_table ) )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1812
		) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1814
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1816
		// One or more tables exist. This is not good.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
		wp_load_translations_early();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
		// Die with a DB error.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1821
		$wpdb->error = sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1822
			/* translators: %s: Database repair URL. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1823
			__( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1824
			'maint/repair.php?referrer=is_blog_installed'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1825
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1826
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
		dead_db();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
	$wpdb->suppress_errors( $suppress );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
	wp_cache_set( 'is_blog_installed', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
 * Retrieve URL with nonce added to URL query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1842
 * @param string     $actionurl URL to add nonce action.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1843
 * @param int|string $action    Optional. Nonce action name. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1844
 * @param string     $name      Optional. Nonce name. Default '_wpnonce'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1845
 * @return string Escaped URL with nonce action added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
function wp_nonce_url( $actionurl, $action = -1, $name = '_wpnonce' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
	$actionurl = str_replace( '&amp;', '&', $actionurl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
	return esc_html( add_query_arg( $name, wp_create_nonce( $action ), $actionurl ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
 * Retrieve or display nonce hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
 * The nonce field is used to validate that the contents of the form came from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1856
 * the location on the current site and not somewhere else. The nonce does not
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
 * offer absolute protection, but should protect against most cases. It is very
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
 * important to use nonce field in forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
 * The $action and $name are optional, but if you want to have better security,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
 * it is strongly suggested to set those two parameters. It is easier to just
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
 * call the function without any parameters, because validation of the nonce
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
 * doesn't require any parameters, but since crackers know what the default is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
 * it won't be difficult for them to find a way around your nonce and cause
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
 * damage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
 * The input name will be whatever $name value you gave. The input value will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
 * the nonce creation value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1869
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1872
 * @param int|string $action  Optional. Action name. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1873
 * @param string     $name    Optional. Nonce name. Default '_wpnonce'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1874
 * @param bool       $referer Optional. Whether to set the referer field for validation. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1875
 * @param bool       $echo    Optional. Whether to display or return hidden form field. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1876
 * @return string Nonce field HTML markup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1878
function wp_nonce_field( $action = -1, $name = '_wpnonce', $referer = true, $echo = true ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1879
	$name        = esc_attr( $name );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
	$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1882
	if ( $referer ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
		$nonce_field .= wp_referer_field( false );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1884
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1885
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1886
	if ( $echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
		echo $nonce_field;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1888
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
	return $nonce_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
 * Retrieve or display referer hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
 * The referer link is the current Request URI from the server super global. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
 * input name is '_wp_http_referer', in case you wanted to check manually.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1901
 * @param bool $echo Optional. Whether to echo or return the referer field. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
 * @return string Referer field HTML markup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
function wp_referer_field( $echo = true ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1905
	$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1906
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1907
	if ( $echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
		echo $referer_field;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1909
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1910
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
	return $referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
 * Retrieve or display original referer hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
 * The input name is '_wp_original_http_referer' and will be either the same
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1918
 * value of wp_referer_field(), if that was posted already or it will be the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1919
 * current page, if it doesn't exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1920
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1923
 * @param bool   $echo         Optional. Whether to echo the original http referer. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1924
 * @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1925
 *                             Default 'current'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
 * @return string Original referer field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1929
	$ref = wp_get_original_referer();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1930
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1931
	if ( ! $ref ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1932
		$ref = ( 'previous' === $jump_back_to ) ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1933
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1934
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
	$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1936
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1937
	if ( $echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
		echo $orig_referer_field;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1939
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1940
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
	return $orig_referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1945
 * Retrieve referer from '_wp_http_referer' or HTTP referer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1946
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1947
 * If it's the same as the current request URL, will return false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1948
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1951
 * @return string|false Referer URL on success, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
function wp_get_referer() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1954
	if ( ! function_exists( 'wp_validate_redirect' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1956
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1957
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1958
	$ref = wp_get_raw_referer();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1959
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1960
	if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref && home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
		return wp_validate_redirect( $ref, false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1962
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1963
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1964
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1965
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1966
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1967
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1968
 * Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1969
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1970
 * Do not use for redirects, use wp_get_referer() instead.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1971
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1972
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1973
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1974
 * @return string|false Referer URL on success, false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1975
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1976
function wp_get_raw_referer() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1977
	if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1978
		return wp_unslash( $_REQUEST['_wp_http_referer'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1979
	} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1980
		return wp_unslash( $_SERVER['HTTP_REFERER'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1981
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1982
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
 * Retrieve original referer that was posted, if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1991
 * @return string|false Original referer URL on success, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
function wp_get_original_referer() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1994
	if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
		return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1996
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  1997
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
 * Recursive directory creation based on full path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
 * Will attempt to set permissions on folders.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
 * @since 2.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
 * @param string $target Full path to attempt to create.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
 * @return bool Whether the path was created. True if path already exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
function wp_mkdir_p( $target ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
	$wrapper = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2014
	// Strip the protocol.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2015
	if ( wp_is_stream( $target ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
		list( $wrapper, $target ) = explode( '://', $target, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2019
	// From php.net/mkdir user contributed notes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
	$target = str_replace( '//', '/', $target );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2022
	// Put the wrapper back on the target.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2023
	if ( null !== $wrapper ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
		$target = $wrapper . '://' . $target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2027
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2028
	 * Safe mode fails with a trailing slash under certain PHP versions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2029
	 * Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2030
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2031
	$target = rtrim( $target, '/' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2032
	if ( empty( $target ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
		$target = '/';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2034
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2035
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2036
	if ( file_exists( $target ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
		return @is_dir( $target );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2038
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
13
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2040
	// Do not allow path traversals.
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2041
	if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2042
		return false;
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2043
	}
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2044
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
	// We need to find the permissions of the parent folder that exists and inherit that.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
	$target_parent = dirname( $target );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2047
	while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
		$target_parent = dirname( $target_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
	// Get the permission bits.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2052
	$stat = @stat( $target_parent );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2053
	if ( $stat ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
		$dir_perms = $stat['mode'] & 0007777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
		$dir_perms = 0777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
	if ( @mkdir( $target, $dir_perms, true ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2060
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2061
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2062
		 * If a umask is set that modifies $dir_perms, we'll have to re-set
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2063
		 * the $dir_perms correctly with chmod()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2064
		 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2065
		if ( ( $dir_perms & ~umask() ) != $dir_perms ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2066
			$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2067
			for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2068
				chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2069
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2070
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2071
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2079
 * Test if a given filesystem path is absolute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2080
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2081
 * For example, '/foo/bar', or 'c:\windows'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2085
 * @param string $path File path.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
 * @return bool True if path is absolute, false is not absolute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
function path_is_absolute( $path ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2089
	/*
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2090
	 * Check to see if the path is a stream and check to see if its an actual
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2091
	 * path or file as realpath() does not support stream wrappers.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2092
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2093
	if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2094
		return true;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2095
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2096
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2097
	/*
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2098
	 * This is definitive if true but fails if $path does not exist or contains
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2099
	 * a symbolic link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2100
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2101
	if ( realpath( $path ) == $path ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2103
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2104
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2105
	if ( strlen( $path ) == 0 || '.' === $path[0] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2107
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2109
	// Windows allows absolute paths like this.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2110
	if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2112
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2114
	// A path starting with / or \ is absolute; anything else is relative.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2115
	return ( '/' === $path[0] || '\\' === $path[0] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2119
 * Join two filesystem paths together.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2120
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2121
 * For example, 'give me $path relative to $base'. If the $path is absolute,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2122
 * then it the full path is returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2126
 * @param string $base Base path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2127
 * @param string $path Path relative to $base.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
 * @return string The path with the base or absolute path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
function path_join( $base, $path ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2131
	if ( path_is_absolute( $path ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
		return $path;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2133
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2134
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2135
	return rtrim( $base, '/' ) . '/' . ltrim( $path, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2136
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2139
 * Normalize a filesystem path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2140
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2141
 * On windows systems, replaces backslashes with forward slashes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2142
 * and forces upper-case drive letters.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2143
 * Allows for two leading slashes for Windows network shares, but
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2144
 * ensures that all other duplicate slashes are reduced to a single.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2145
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2146
 * @since 3.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2147
 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2148
 * @since 4.5.0 Allows for Windows network shares.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2149
 * @since 4.9.7 Allows for PHP file wrappers.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2150
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2151
 * @param string $path Path to normalize.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2152
 * @return string Normalized path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2153
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2154
function wp_normalize_path( $path ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2155
	$wrapper = '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2156
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2157
	if ( wp_is_stream( $path ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2158
		list( $wrapper, $path ) = explode( '://', $path, 2 );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2159
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2160
		$wrapper .= '://';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2161
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2162
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2163
	// Standardize all paths to use '/'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2164
	$path = str_replace( '\\', '/', $path );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2165
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2166
	// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2167
	$path = preg_replace( '|(?<=.)/+|', '/', $path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2168
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2169
	// Windows paths should uppercase the drive letter.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2170
	if ( ':' === substr( $path, 1, 1 ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2171
		$path = ucfirst( $path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2172
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2173
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2174
	return $wrapper . $path;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2175
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2176
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2177
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2178
 * Determine a writable directory for temporary files.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2179
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2180
 * Function's preference is the return value of sys_get_temp_dir(),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
 * before finally defaulting to /tmp/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
 * In the event that this function does not find a writable location,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2185
 * It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2189
 * @return string Writable temporary directory.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
function get_temp_dir() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2192
	static $temp = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2193
	if ( defined( 'WP_TEMP_DIR' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2194
		return trailingslashit( WP_TEMP_DIR );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2195
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2196
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2197
	if ( $temp ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2198
		return trailingslashit( $temp );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2199
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2200
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2201
	if ( function_exists( 'sys_get_temp_dir' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
		$temp = sys_get_temp_dir();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2203
		if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2204
			return trailingslashit( $temp );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2205
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2206
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2207
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2208
	$temp = ini_get( 'upload_tmp_dir' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2209
	if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2210
		return trailingslashit( $temp );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2211
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
	$temp = WP_CONTENT_DIR . '/';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2214
	if ( is_dir( $temp ) && wp_is_writable( $temp ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
		return $temp;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2216
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2218
	return '/tmp/';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
 * Determine if a directory is writable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2224
 * This function is used to work around certain ACL issues in PHP primarily
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2225
 * affecting Windows Servers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2226
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2227
 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
 * @see win_is_writable()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2231
 * @param string $path Path to check for write-ability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2232
 * @return bool Whether the path is writable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2234
function wp_is_writable( $path ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2235
	if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2236
		return win_is_writable( $path );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2237
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
		return @is_writable( $path );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2239
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
 * Workaround for Windows bug in is_writable() function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
 * PHP has issues with Windows ACL's for determine if a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
 * directory is writable or not, this works around them by
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
 * checking the ability to open files rather than relying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2248
 * upon PHP to interprate the OS ACL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2252
 * @see https://bugs.php.net/bug.php?id=27609
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2253
 * @see https://bugs.php.net/bug.php?id=30931
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2254
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2255
 * @param string $path Windows path to check for write-ability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2256
 * @return bool Whether the path is writable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
function win_is_writable( $path ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2259
	if ( '/' === $path[ strlen( $path ) - 1 ] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2260
		// If it looks like a directory, check a random file within the directory.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2261
		return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2262
	} elseif ( is_dir( $path ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2263
		// If it's a directory (and not a file), check a random file within the directory.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
		return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2265
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2266
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2267
	// Check tmp file for read/write capabilities.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2268
	$should_delete_tmp_file = ! file_exists( $path );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2269
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2270
	$f = @fopen( $path, 'a' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2271
	if ( false === $f ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2272
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2273
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
	fclose( $f );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2275
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2276
	if ( $should_delete_tmp_file ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
		unlink( $path );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2278
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2279
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2283
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2284
 * Retrieves uploads directory information.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2285
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2286
 * Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2287
 * Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2288
 * when not uploading files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2289
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2290
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2291
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2292
 * @see wp_upload_dir()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2293
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2294
 * @return array See wp_upload_dir() for description.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2295
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2296
function wp_get_upload_dir() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2297
	return wp_upload_dir( null, false );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2298
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2299
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2300
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2301
 * Returns an array containing the current upload directory's path and URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2302
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2303
 * Checks the 'upload_path' option, which should be from the web root folder,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2304
 * and if it isn't empty it will be used. If it is empty, then the path will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2305
 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2306
 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
 * The upload URL path is set either by the 'upload_url_path' option or by using
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2310
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2311
 * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2312
 * the administration settings panel), then the time will be used. The format
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2313
 * will be year first and then month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2314
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2315
 * If the path couldn't be created, then an error will be returned with the key
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
 * 'error' containing the error message. The error suggests that the parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
 * directory is not writable by the server.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2320
 * @uses _wp_upload_dir()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2321
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2322
 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2323
 * @param bool   $create_dir Optional. Whether to check and create the uploads directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2324
 *                           Default true for backward compatibility.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2325
 * @param bool   $refresh_cache Optional. Whether to refresh the cache. Default false.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2326
 * @return array {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2327
 *     Array of information about the upload directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2328
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2329
 *     @type string       $path    Base directory and subdirectory or full path to upload directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2330
 *     @type string       $url     Base URL and subdirectory or absolute URL to upload directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2331
 *     @type string       $subdir  Subdirectory if uploads use year/month folders option is on.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2332
 *     @type string       $basedir Path without subdir.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2333
 *     @type string       $baseurl URL path without subdir.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2334
 *     @type string|false $error   False or error message.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2335
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2337
function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2338
	static $cache = array(), $tested_paths = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2339
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2340
	$key = sprintf( '%d-%s', get_current_blog_id(), (string) $time );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2341
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2342
	if ( $refresh_cache || empty( $cache[ $key ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2343
		$cache[ $key ] = _wp_upload_dir( $time );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2344
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2345
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2346
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2347
	 * Filters the uploads directory data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2348
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2349
	 * @since 2.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2350
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2351
	 * @param array $uploads {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2352
	 *     Array of information about the upload directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2353
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2354
	 *     @type string       $path    Base directory and subdirectory or full path to upload directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2355
	 *     @type string       $url     Base URL and subdirectory or absolute URL to upload directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2356
	 *     @type string       $subdir  Subdirectory if uploads use year/month folders option is on.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2357
	 *     @type string       $basedir Path without subdir.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2358
	 *     @type string       $baseurl URL path without subdir.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2359
	 *     @type string|false $error   False or error message.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2360
	 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2361
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2362
	$uploads = apply_filters( 'upload_dir', $cache[ $key ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2363
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2364
	if ( $create_dir ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2365
		$path = $uploads['path'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2366
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2367
		if ( array_key_exists( $path, $tested_paths ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2368
			$uploads['error'] = $tested_paths[ $path ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2369
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2370
			if ( ! wp_mkdir_p( $path ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2371
				if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2372
					$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2373
				} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2374
					$error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2375
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2376
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2377
				$uploads['error'] = sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2378
					/* translators: %s: Directory path. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2379
					__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2380
					esc_html( $error_path )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2381
				);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2382
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2383
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2384
			$tested_paths[ $path ] = $uploads['error'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2385
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2386
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2387
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2388
	return $uploads;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2389
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2390
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2391
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2392
 * A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2393
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2394
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2395
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2396
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2397
 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2398
 * @return array See wp_upload_dir()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2399
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2400
function _wp_upload_dir( $time = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2401
	$siteurl     = get_option( 'siteurl' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2402
	$upload_path = trim( get_option( 'upload_path' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2404
	if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
		$dir = WP_CONTENT_DIR . '/uploads';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
	} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2407
		// $dir is absolute, $upload_path is (maybe) relative to ABSPATH.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
		$dir = path_join( ABSPATH, $upload_path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
		$dir = $upload_path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2413
	$url = get_option( 'upload_url_path' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2414
	if ( ! $url ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2415
		if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path == $dir ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
			$url = WP_CONTENT_URL . '/uploads';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2417
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
			$url = trailingslashit( $siteurl ) . $upload_path;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2419
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2422
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2423
	 * Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2424
	 * We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2425
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
	if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
		$dir = ABSPATH . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
		$url = trailingslashit( $siteurl ) . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2431
	// If multisite (and if not the main site in a post-MU network).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
	if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
		if ( ! get_site_option( 'ms_files_rewriting' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2435
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2436
			 * If ms-files rewriting is disabled (networks created post-3.5), it is fairly
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2437
			 * straightforward: Append sites/%d if we're not on the main site (for post-MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2438
			 * networks). (The extra directory prevents a four-digit ID from conflicting with
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2439
			 * a year-based directory for the main site. But if a MU-era network has disabled
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2440
			 * ms-files rewriting manually, they don't need the extra directory, as they never
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2441
			 * had wp-content/uploads for the main site.)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2442
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2443
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2444
			if ( defined( 'MULTISITE' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
				$ms_dir = '/sites/' . get_current_blog_id();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2446
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
				$ms_dir = '/' . get_current_blog_id();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2448
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
			$dir .= $ms_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
			$url .= $ms_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
		} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2454
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2455
			 * Handle the old-form ms-files.php rewriting if the network still has that enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2456
			 * When ms-files rewriting is enabled, then we only listen to UPLOADS when:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2457
			 * 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2458
			 *    there, and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2459
			 * 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2460
			 *    the original blog ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2461
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2462
			 * Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2463
			 * (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2464
			 * as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2465
			 * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2466
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2468
			if ( defined( 'BLOGUPLOADDIR' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
				$dir = untrailingslashit( BLOGUPLOADDIR );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2470
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
				$dir = ABSPATH . UPLOADS;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2472
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
			$url = trailingslashit( $siteurl ) . 'files';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
	$basedir = $dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
	$baseurl = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
	$subdir = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2481
	if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2482
		// Generate the yearly and monthly directories.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2483
		if ( ! $time ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
			$time = current_time( 'mysql' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2485
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2486
		$y      = substr( $time, 0, 4 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2487
		$m      = substr( $time, 5, 2 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
		$subdir = "/$y/$m";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
	$dir .= $subdir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
	$url .= $subdir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2494
	return array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2495
		'path'    => $dir,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2496
		'url'     => $url,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2497
		'subdir'  => $subdir,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2498
		'basedir' => $basedir,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2499
		'baseurl' => $baseurl,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2500
		'error'   => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2501
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
 * Get a filename that is sanitized and unique for the given directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
 * If the filename is not unique, then a number will be added to the filename
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2508
 * before the extension, and will continue adding numbers until the filename
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2509
 * is unique.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2510
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2511
 * The callback function allows the caller to use their own method to create
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2512
 * unique file names. If defined, the callback should take three arguments:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2513
 * - directory, base filename, and extension - and return a unique filename.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2517
 * @param string   $dir                      Directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2518
 * @param string   $filename                 File name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2519
 * @param callable $unique_filename_callback Callback. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
 * @return string New filename, if given wasn't unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2523
	// Sanitize the file name before we begin processing.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2524
	$filename = sanitize_file_name( $filename );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2525
	$ext2     = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2527
	// Initialize vars used in the wp_unique_filename filter.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2528
	$number        = '';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2529
	$alt_filenames = array();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2530
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2531
	// Separate the filename into a name and extension.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2532
	$ext  = pathinfo( $filename, PATHINFO_EXTENSION );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2533
	$name = pathinfo( $filename, PATHINFO_BASENAME );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2534
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2535
	if ( $ext ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2536
		$ext = '.' . $ext;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2537
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2539
	// Edge case: if file is named '.ext', treat as an empty name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2540
	if ( $name === $ext ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2541
		$name = '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2542
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2543
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2544
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2545
	 * Increment the file number until we have a unique file to save in $dir.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2546
	 * Use callback if supplied.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2547
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
	if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
		$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
	} else {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2551
		$fname = pathinfo( $filename, PATHINFO_FILENAME );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2552
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2553
		// Always append a number to file names that can potentially match image sub-size file names.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2554
		if ( $fname && preg_match( '/-(?:\d+x\d+|scaled|rotated)$/', $fname ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2555
			$number = 1;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2556
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2557
			// At this point the file name may not be unique. This is tested below and the $number is incremented.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2558
			$filename = str_replace( "{$fname}{$ext}", "{$fname}-{$number}{$ext}", $filename );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2559
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2561
		/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2562
		 * Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext()
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2563
		 * in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2564
		 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2565
		$file_type = wp_check_filetype( $filename );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2566
		$mime_type = $file_type['type'];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2567
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2568
		$is_image    = ( ! empty( $mime_type ) && 0 === strpos( $mime_type, 'image/' ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2569
		$upload_dir  = wp_get_upload_dir();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2570
		$lc_filename = null;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2571
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2572
		$lc_ext = strtolower( $ext );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2573
		$_dir   = trailingslashit( $dir );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2574
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2575
		/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2576
		 * If the extension is uppercase add an alternate file name with lowercase extension.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2577
		 * Both need to be tested for uniqueness as the extension will be changed to lowercase
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2578
		 * for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2579
		 * where uppercase extensions were allowed but image sub-sizes were created with
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2580
		 * lowercase extensions.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2581
		 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2582
		if ( $ext && $lc_ext !== $ext ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2583
			$lc_filename = preg_replace( '|' . preg_quote( $ext ) . '$|', $lc_ext, $filename );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2584
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2585
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2586
		/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2587
		 * Increment the number added to the file name if there are any files in $dir
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2588
		 * whose names match one of the possible name variations.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2589
		 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2590
		while ( file_exists( $_dir . $filename ) || ( $lc_filename && file_exists( $_dir . $lc_filename ) ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2591
			$new_number = (int) $number + 1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2592
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2593
			if ( $lc_filename ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2594
				$lc_filename = str_replace(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2595
					array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2596
					"-{$new_number}{$lc_ext}",
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2597
					$lc_filename
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2598
				);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2600
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2601
			if ( '' === "{$number}{$ext}" ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2602
				$filename = "{$filename}-{$new_number}";
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2603
			} else {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2604
				$filename = str_replace(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2605
					array( "-{$number}{$ext}", "{$number}{$ext}" ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2606
					"-{$new_number}{$ext}",
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2607
					$filename
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2608
				);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2609
			}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2610
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2611
			$number = $new_number;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2612
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2613
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2614
		// Change the extension to lowercase if needed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2615
		if ( $lc_filename ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2616
			$filename = $lc_filename;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2617
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2618
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2619
		/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2620
		 * Prevent collisions with existing file names that contain dimension-like strings
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2621
		 * (whether they are subsizes or originals uploaded prior to #42437).
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2622
		 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2623
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2624
		$files = array();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2625
		$count = 10000;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2626
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2627
		// The (resized) image files would have name and extension, and will be in the uploads dir.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2628
		if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2629
			/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2630
			 * Filters the file list used for calculating a unique filename for a newly added file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2631
			 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2632
			 * Returning an array from the filter will effectively short-circuit retrieval
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2633
			 * from the filesystem and return the passed value instead.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2634
			 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2635
			 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2636
			 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2637
			 * @param array|null $files    The list of files to use for filename comparisons.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2638
			 *                             Default null (to retrieve the list from the filesystem).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2639
			 * @param string     $dir      The directory for the new file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2640
			 * @param string     $filename The proposed filename for the new file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2641
			 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2642
			$files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2643
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2644
			if ( null === $files ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2645
				// List of all files and directories contained in $dir.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2646
				$files = @scandir( $dir );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2647
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2648
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2649
			if ( ! empty( $files ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2650
				// Remove "dot" dirs.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2651
				$files = array_diff( $files, array( '.', '..' ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2652
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2653
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2654
			if ( ! empty( $files ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2655
				$count = count( $files );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2656
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2657
				/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2658
				 * Ensure this never goes into infinite loop as it uses pathinfo() and regex in the check,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2659
				 * but string replacement for the changes.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2660
				 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2661
				$i = 0;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2662
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2663
				while ( $i <= $count && _wp_check_existing_file_names( $filename, $files ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2664
					$new_number = (int) $number + 1;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2665
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2666
					// If $ext is uppercase it was replaced with the lowercase version after the previous loop.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2667
					$filename = str_replace(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2668
						array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2669
						"-{$new_number}{$lc_ext}",
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2670
						$filename
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2671
					);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2672
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2673
					$number = $new_number;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2674
					$i++;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2675
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2676
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2677
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2678
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2679
		/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2680
		 * Check if an image will be converted after uploading or some existing image sub-size file names may conflict
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2681
		 * when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2682
		 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2683
		if ( $is_image ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2684
			/** This filter is documented in wp-includes/class-wp-image-editor.php */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2685
			$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2686
			$alt_types      = array();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2687
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2688
			if ( ! empty( $output_formats[ $mime_type ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2689
				// The image will be converted to this format/mime type.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2690
				$alt_mime_type = $output_formats[ $mime_type ];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2691
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2692
				// Other types of images whose names may conflict if their sub-sizes are regenerated.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2693
				$alt_types   = array_keys( array_intersect( $output_formats, array( $mime_type, $alt_mime_type ) ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2694
				$alt_types[] = $alt_mime_type;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2695
			} elseif ( ! empty( $output_formats ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2696
				$alt_types = array_keys( array_intersect( $output_formats, array( $mime_type ) ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2697
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2698
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2699
			// Remove duplicates and the original mime type. It will be added later if needed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2700
			$alt_types = array_unique( array_diff( $alt_types, array( $mime_type ) ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2701
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2702
			foreach ( $alt_types as $alt_type ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2703
				$alt_ext = wp_get_default_extension_for_mime_type( $alt_type );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2704
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2705
				if ( ! $alt_ext ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2706
					continue;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2707
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2708
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2709
				$alt_ext      = ".{$alt_ext}";
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2710
				$alt_filename = preg_replace( '|' . preg_quote( $lc_ext ) . '$|', $alt_ext, $filename );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2711
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2712
				$alt_filenames[ $alt_ext ] = $alt_filename;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2713
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2714
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2715
			if ( ! empty( $alt_filenames ) ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2716
				/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2717
				 * Add the original filename. It needs to be checked again
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2718
				 * together with the alternate filenames when $number is incremented.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2719
				 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2720
				$alt_filenames[ $lc_ext ] = $filename;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2721
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2722
				// Ensure no infinite loop.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2723
				$i = 0;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2724
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2725
				while ( $i <= $count && _wp_check_alternate_file_names( $alt_filenames, $_dir, $files ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2726
					$new_number = (int) $number + 1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2727
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2728
					foreach ( $alt_filenames as $alt_ext => $alt_filename ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2729
						$alt_filenames[ $alt_ext ] = str_replace(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2730
							array( "-{$number}{$alt_ext}", "{$number}{$alt_ext}" ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2731
							"-{$new_number}{$alt_ext}",
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2732
							$alt_filename
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2733
						);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2734
					}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2735
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2736
					/*
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2737
					 * Also update the $number in (the output) $filename.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2738
					 * If the extension was uppercase it was already replaced with the lowercase version.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2739
					 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2740
					$filename = str_replace(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2741
						array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2742
						"-{$new_number}{$lc_ext}",
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2743
						$filename
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2744
					);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2745
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2746
					$number = $new_number;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2747
					$i++;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2748
				}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2749
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2750
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2751
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2752
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2753
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2754
	 * Filters the result when generating a unique file name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2755
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2756
	 * @since 4.5.0
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2757
	 * @since 5.8.1 The `$alt_filenames` and `$number` parameters were added.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2758
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2759
	 * @param string        $filename                 Unique file name.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2760
	 * @param string        $ext                      File extension. Example: ".png".
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2761
	 * @param string        $dir                      Directory path.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2762
	 * @param callable|null $unique_filename_callback Callback function that generates the unique file name.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2763
	 * @param string[]      $alt_filenames            Array of alternate file names that were checked for collisions.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2764
	 * @param int|string    $number                   The highest number that was used to make the file name unique
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2765
	 *                                                or an empty string if unused.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2766
	 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2767
	return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2768
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2769
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2770
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2771
 * Helper function to test if each of an array of file names could conflict with existing files.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2772
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2773
 * @since 5.8.1
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2774
 * @access private
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2775
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2776
 * @param string[] $filenames Array of file names to check.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2777
 * @param string   $dir       The directory containing the files.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2778
 * @param array    $files     An array of existing files in the directory. May be empty.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2779
 * @return bool True if the tested file name could match an existing file, false otherwise.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2780
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2781
function _wp_check_alternate_file_names( $filenames, $dir, $files ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2782
	foreach ( $filenames as $filename ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2783
		if ( file_exists( $dir . $filename ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2784
			return true;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2785
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2786
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2787
		if ( ! empty( $files ) && _wp_check_existing_file_names( $filename, $files ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2788
			return true;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2789
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2790
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2791
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2792
	return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2793
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2795
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2796
 * Helper function to check if a file name could match an existing image sub-size file name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2797
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2798
 * @since 5.3.1
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2799
 * @access private
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2800
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2801
 * @param string $filename The file name to check.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2802
 * @param array  $files    An array of existing files in the directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2803
 * @return bool True if the tested file name could match an existing file, false otherwise.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2804
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2805
function _wp_check_existing_file_names( $filename, $files ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2806
	$fname = pathinfo( $filename, PATHINFO_FILENAME );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2807
	$ext   = pathinfo( $filename, PATHINFO_EXTENSION );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2808
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2809
	// Edge case, file names like `.ext`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2810
	if ( empty( $fname ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2811
		return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2812
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2813
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2814
	if ( $ext ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2815
		$ext = ".$ext";
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2816
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2817
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2818
	$regex = '/^' . preg_quote( $fname ) . '-(?:\d+x\d+|scaled|rotated)' . preg_quote( $ext ) . '$/i';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2819
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2820
	foreach ( $files as $file ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2821
		if ( preg_match( $regex, $file ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2822
			return true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2823
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2824
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2825
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2826
	return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2827
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2828
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2829
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2830
 * Create a file in the upload folder with given content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2831
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2832
 * If there is an error, then the key 'error' will exist with the error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2833
 * If success, then the key 'file' will have the unique file path, the 'url' key
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2834
 * will have the link to the new file. and the 'error' key will be set to false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2835
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2836
 * This function will not move an uploaded file to the upload folder. It will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2837
 * create a new file with the content in $bits parameter. If you move the upload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2838
 * file, read the content of the uploaded file, and then you can give the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2839
 * filename and content to this function, which will add it to the upload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2840
 * folder.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2841
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2842
 * The permissions will be set on the new file automatically by this function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2843
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2844
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2845
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2846
 * @param string      $name       Filename.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2847
 * @param null|string $deprecated Never used. Set to null.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2848
 * @param string      $bits       File content
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2849
 * @param string      $time       Optional. Time formatted in 'yyyy/mm'. Default null.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2850
 * @return array {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2851
 *     Information about the newly-uploaded file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2852
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2853
 *     @type string       $file  Filename of the newly-uploaded file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2854
 *     @type string       $url   URL of the uploaded file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2855
 *     @type string       $type  File type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2856
 *     @type string|false $error Error message, if there has been an error.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2857
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2858
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2859
function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2860
	if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2861
		_deprecated_argument( __FUNCTION__, '2.0.0' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2862
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2863
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2864
	if ( empty( $name ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2865
		return array( 'error' => __( 'Empty filename' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2866
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2867
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2868
	$wp_filetype = wp_check_filetype( $name );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2869
	if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2870
		return array( 'error' => __( 'Sorry, you are not allowed to upload this file type.' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2871
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2873
	$upload = wp_upload_dir( $time );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2874
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2875
	if ( false !== $upload['error'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2876
		return $upload;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2877
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2878
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2879
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2880
	 * Filters whether to treat the upload bits as an error.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2881
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2882
	 * Returning a non-array from the filter will effectively short-circuit preparing the upload bits
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2883
	 * and return that value instead. An error message should be returned as a string.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2884
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2885
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2886
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2887
	 * @param array|string $upload_bits_error An array of upload bits data, or error message to return.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2888
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2889
	$upload_bits_error = apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2890
		'wp_upload_bits',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2891
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2892
			'name' => $name,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2893
			'bits' => $bits,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2894
			'time' => $time,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2895
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2896
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2897
	if ( ! is_array( $upload_bits_error ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2898
		$upload['error'] = $upload_bits_error;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2899
		return $upload;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2900
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2902
	$filename = wp_unique_filename( $upload['path'], $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2903
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2904
	$new_file = $upload['path'] . "/$filename";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
	if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2906
		if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
			$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2908
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2909
			$error_path = wp_basename( $upload['basedir'] ) . $upload['subdir'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2910
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2911
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2912
		$message = sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2913
			/* translators: %s: Directory path. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2914
			__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2915
			$error_path
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2916
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2917
		return array( 'error' => $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2918
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2919
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2920
	$ifp = @fopen( $new_file, 'wb' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2921
	if ( ! $ifp ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2922
		return array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2923
			/* translators: %s: File name. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2924
			'error' => sprintf( __( 'Could not write file %s' ), $new_file ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2925
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2926
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2927
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2928
	fwrite( $ifp, $bits );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2929
	fclose( $ifp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2930
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2931
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2932
	// Set correct file permissions.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2933
	$stat  = @ stat( dirname( $new_file ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2934
	$perms = $stat['mode'] & 0007777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2935
	$perms = $perms & 0000666;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2936
	chmod( $new_file, $perms );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2937
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2938
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2939
	// Compute the URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
	$url = $upload['url'] . "/$filename";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2941
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2942
	if ( is_multisite() ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2943
		clean_dirsize_cache( $new_file );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2944
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2945
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2946
	/** This filter is documented in wp-admin/includes/file.php */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2947
	return apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2948
		'wp_handle_upload',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2949
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2950
			'file'  => $new_file,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2951
			'url'   => $url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2952
			'type'  => $wp_filetype['type'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2953
			'error' => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2954
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2955
		'sideload'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2956
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2957
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2958
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2959
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2960
 * Retrieve the file type based on the extension name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2961
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2962
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2963
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2964
 * @param string $ext The extension to search.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2965
 * @return string|void The file type, example: audio, video, document, spreadsheet, etc.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2966
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2967
function wp_ext2type( $ext ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2968
	$ext = strtolower( $ext );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2969
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2970
	$ext2type = wp_get_ext_types();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2971
	foreach ( $ext2type as $type => $exts ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  2972
		if ( in_array( $ext, $exts, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2973
			return $type;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2974
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2975
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2976
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2977
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2978
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2979
 * Returns first matched extension for the mime-type,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2980
 * as mapped from wp_get_mime_types().
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2981
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2982
 * @since 5.8.1
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2983
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2984
 * @param string $mime_type
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2985
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2986
 * @return string|false
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2987
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2988
function wp_get_default_extension_for_mime_type( $mime_type ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2989
	$extensions = explode( '|', array_search( $mime_type, wp_get_mime_types(), true ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2990
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2991
	if ( empty( $extensions[0] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2992
		return false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2993
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2994
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2995
	return $extensions[0];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2996
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2997
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2998
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2999
 * Retrieve the file type from the file name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3000
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3001
 * You can optionally define the mime array, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3002
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3003
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3004
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3005
 * @param string   $filename File name or path.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3006
 * @param string[] $mimes    Optional. Array of allowed mime types keyed by their file extension regex.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3007
 * @return array {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3008
 *     Values for the extension and mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3009
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3010
 *     @type string|false $ext  File extension, or false if the file doesn't match a mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3011
 *     @type string|false $type File mime type, or false if the file doesn't match a mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3012
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3014
function wp_check_filetype( $filename, $mimes = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3015
	if ( empty( $mimes ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3016
		$mimes = get_allowed_mime_types();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3017
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3018
	$type = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3019
	$ext  = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3020
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3021
	foreach ( $mimes as $ext_preg => $mime_match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3022
		$ext_preg = '!\.(' . $ext_preg . ')$!i';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3023
		if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3024
			$type = $mime_match;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3025
			$ext  = $ext_matches[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3026
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3027
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3028
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3029
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3030
	return compact( 'ext', 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3031
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3033
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3034
 * Attempt to determine the real file type of a file.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3035
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3036
 * If unable to, the file name extension will be used to determine type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3037
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3038
 * If it's determined that the extension does not match the file's real type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3039
 * then the "proper_filename" value will be set with a proper filename and extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3040
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3041
 * Currently this function only supports renaming images validated via wp_get_image_mime().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3042
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3044
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3045
 * @param string   $file     Full path to the file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3046
 * @param string   $filename The name of the file (may differ from $file due to $file being
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3047
 *                           in a tmp directory).
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3048
 * @param string[] $mimes    Optional. Array of allowed mime types keyed by their file extension regex.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3049
 * @return array {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3050
 *     Values for the extension, mime type, and corrected filename.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3051
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3052
 *     @type string|false $ext             File extension, or false if the file doesn't match a mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3053
 *     @type string|false $type            File mime type, or false if the file doesn't match a mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3054
 *     @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3055
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3056
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3057
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
	$proper_filename = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3059
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3060
	// Do basic extension validation and MIME mapping.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3061
	$wp_filetype = wp_check_filetype( $filename, $mimes );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3062
	$ext         = $wp_filetype['ext'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3063
	$type        = $wp_filetype['type'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3064
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3065
	// We can't do any further validation without a file to work with.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3066
	if ( ! file_exists( $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3067
		return compact( 'ext', 'type', 'proper_filename' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3068
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3069
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3070
	$real_mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3071
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3072
	// Validate image types.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3073
	if ( $type && 0 === strpos( $type, 'image/' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3074
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3075
		// Attempt to figure out what type of image it actually is.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3076
		$real_mime = wp_get_image_mime( $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3077
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3078
		if ( $real_mime && $real_mime != $type ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3079
			/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3080
			 * Filters the list mapping image mime types to their respective extensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3081
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3082
			 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3083
			 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3084
			 * @param array $mime_to_ext Array of image mime types and their matching extensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3085
			 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3086
			$mime_to_ext = apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3087
				'getimagesize_mimes_to_exts',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3088
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3089
					'image/jpeg' => 'jpg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3090
					'image/png'  => 'png',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3091
					'image/gif'  => 'gif',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3092
					'image/bmp'  => 'bmp',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3093
					'image/tiff' => 'tif',
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3094
					'image/webp' => 'webp',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3095
				)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3096
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3098
			// Replace whatever is after the last period in the filename with the correct extension.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3099
			if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
				$filename_parts = explode( '.', $filename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
				array_pop( $filename_parts );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3102
				$filename_parts[] = $mime_to_ext[ $real_mime ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3103
				$new_filename     = implode( '.', $filename_parts );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3104
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3105
				if ( $new_filename != $filename ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3106
					$proper_filename = $new_filename; // Mark that it changed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3107
				}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3108
				// Redefine the extension / MIME.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3109
				$wp_filetype = wp_check_filetype( $new_filename, $mimes );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3110
				$ext         = $wp_filetype['ext'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3111
				$type        = $wp_filetype['type'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3112
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3113
				// Reset $real_mime and try validating again.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3114
				$real_mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3115
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3116
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3117
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3118
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3119
	// Validate files that didn't get validated during previous checks.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3120
	if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3121
		$finfo     = finfo_open( FILEINFO_MIME_TYPE );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3122
		$real_mime = finfo_file( $finfo, $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3123
		finfo_close( $finfo );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3124
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3125
		// fileinfo often misidentifies obscure files as one of these types.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3126
		$nonspecific_types = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3127
			'application/octet-stream',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3128
			'application/encrypted',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3129
			'application/CDFV2-encrypted',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3130
			'application/zip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3131
		);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3132
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3133
		/*
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3134
		 * If $real_mime doesn't match the content type we're expecting from the file's extension,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3135
		 * we need to do some additional vetting. Media types and those listed in $nonspecific_types are
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3136
		 * allowed some leeway, but anything else must exactly match the real content type.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3137
		 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3138
		if ( in_array( $real_mime, $nonspecific_types, true ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3139
			// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3140
			if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ), true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3141
				$type = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3142
				$ext  = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3143
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3144
		} elseif ( 0 === strpos( $real_mime, 'video/' ) || 0 === strpos( $real_mime, 'audio/' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3145
			/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3146
			 * For these types, only the major type must match the real value.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3147
			 * This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3148
			 * and some media files are commonly named with the wrong extension (.mov instead of .mp4)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3149
			 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3150
			if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3151
				$type = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3152
				$ext  = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3154
		} elseif ( 'text/plain' === $real_mime ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3155
			// A few common file types are occasionally detected as text/plain; allow those.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3156
			if ( ! in_array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3157
				$type,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3158
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3159
					'text/plain',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3160
					'text/csv',
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3161
					'application/csv',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3162
					'text/richtext',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3163
					'text/tsv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3164
					'text/vtt',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3165
				),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3166
				true
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3167
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3168
			) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3169
				$type = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3170
				$ext  = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3171
			}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3172
		} elseif ( 'application/csv' === $real_mime ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3173
			// Special casing for CSV files.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3174
			if ( ! in_array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3175
				$type,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3176
				array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3177
					'text/csv',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3178
					'text/plain',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3179
					'application/csv',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3180
				),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3181
				true
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3182
			)
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3183
			) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3184
				$type = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3185
				$ext  = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3186
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3187
		} elseif ( 'text/rtf' === $real_mime ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3188
			// Special casing for RTF files.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3189
			if ( ! in_array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3190
				$type,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3191
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3192
					'text/rtf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3193
					'text/plain',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3194
					'application/rtf',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3195
				),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3196
				true
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3197
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3198
			) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3199
				$type = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3200
				$ext  = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3201
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3202
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3203
			if ( $type !== $real_mime ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3204
				/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3205
				 * Everything else including image/* and application/*:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3206
				 * If the real content type doesn't match the file extension, assume it's dangerous.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3207
				 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3208
				$type = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3209
				$ext  = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3210
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3211
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3212
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3213
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3214
	// The mime type must be allowed.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3215
	if ( $type ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3216
		$allowed = get_allowed_mime_types();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3217
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3218
		if ( ! in_array( $type, $allowed, true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3219
			$type = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3220
			$ext  = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3221
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3222
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3223
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3224
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3225
	 * Filters the "real" file type of the given file.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3226
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3227
	 * @since 3.0.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3228
	 * @since 5.1.0 The $real_mime parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3229
	 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3230
	 * @param array        $wp_check_filetype_and_ext {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3231
	 *     Values for the extension, mime type, and corrected filename.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3232
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3233
	 *     @type string|false $ext             File extension, or false if the file doesn't match a mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3234
	 *     @type string|false $type            File mime type, or false if the file doesn't match a mime type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3235
	 *     @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3236
	 * }
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3237
	 * @param string       $file                      Full path to the file.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3238
	 * @param string       $filename                  The name of the file (may differ from $file due to
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3239
	 *                                                $file being in a tmp directory).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3240
	 * @param string[]     $mimes                     Array of mime types keyed by their file extension regex.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3241
	 * @param string|false $real_mime                 The actual mime type or false if the type cannot be determined.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3242
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3243
	return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes, $real_mime );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3244
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3245
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3246
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3247
 * Returns the real mime type of an image file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3248
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3249
 * This depends on exif_imagetype() or getimagesize() to determine real mime types.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3250
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3251
 * @since 4.7.1
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3252
 * @since 5.8.0 Added support for WebP images.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3253
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3254
 * @param string $file Full path to the file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3255
 * @return string|false The actual mime type or false if the type cannot be determined.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3256
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3257
function wp_get_image_mime( $file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3258
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3259
	 * Use exif_imagetype() to check the mimetype if available or fall back to
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3260
	 * getimagesize() if exif isn't available. If either function throws an Exception
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3261
	 * we assume the file could not be validated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3262
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3263
	try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3264
		if ( is_callable( 'exif_imagetype' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3265
			$imagetype = exif_imagetype( $file );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3266
			$mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3267
		} elseif ( function_exists( 'getimagesize' ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3268
			// Don't silence errors when in debug mode, unless running unit tests.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3269
			if ( defined( 'WP_DEBUG' ) && WP_DEBUG
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3270
				&& ! defined( 'WP_RUN_CORE_TESTS' )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3271
			) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3272
				// Not using wp_getimagesize() here to avoid an infinite loop.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3273
				$imagesize = getimagesize( $file );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3274
			} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3275
				// phpcs:ignore WordPress.PHP.NoSilencedErrors
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3276
				$imagesize = @getimagesize( $file );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3277
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3278
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3279
			$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3280
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3281
			$mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3282
		}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3283
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3284
		if ( false !== $mime ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3285
			return $mime;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3286
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3287
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3288
		$magic = file_get_contents( $file, false, null, 0, 12 );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3289
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3290
		if ( false === $magic ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3291
			return false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3292
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3293
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3294
		/*
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3295
		 * Add WebP fallback detection when image library doesn't support WebP.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3296
		 * Note: detection values come from LibWebP, see
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3297
		 * https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3298
		 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3299
		$magic = bin2hex( $magic );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3300
		if (
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3301
			// RIFF.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3302
			( 0 === strpos( $magic, '52494646' ) ) &&
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3303
			// WEBP.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3304
			( 16 === strpos( $magic, '57454250' ) )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3305
		) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3306
			$mime = 'image/webp';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3307
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3308
	} catch ( Exception $e ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3309
		$mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3310
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3311
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3312
	return $mime;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3313
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3314
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3315
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3316
 * Retrieve list of mime types and file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3317
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3318
 * @since 3.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3319
 * @since 4.2.0 Support was added for GIMP (.xcf) files.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3320
 * @since 4.9.2 Support was added for Flac (.flac) files.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3321
 * @since 4.9.6 Support was added for AAC (.aac) files.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3322
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3323
 * @return string[] Array of mime types keyed by the file extension regex corresponding to those types.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3324
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3325
function wp_get_mime_types() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3326
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3327
	 * Filters the list of mime types and file extensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3328
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3329
	 * This filter should be used to add, not remove, mime types. To remove
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3330
	 * mime types, use the {@see 'upload_mimes'} filter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3331
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3332
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3333
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3334
	 * @param string[] $wp_get_mime_types Mime types keyed by the file extension regex
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3335
	 *                                 corresponding to those types.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3336
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3337
	return apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3338
		'mime_types',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3339
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3340
			// Image formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3341
			'jpg|jpeg|jpe'                 => 'image/jpeg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3342
			'gif'                          => 'image/gif',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3343
			'png'                          => 'image/png',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3344
			'bmp'                          => 'image/bmp',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3345
			'tiff|tif'                     => 'image/tiff',
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3346
			'webp'                         => 'image/webp',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3347
			'ico'                          => 'image/x-icon',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3348
			'heic'                         => 'image/heic',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3349
			// Video formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3350
			'asf|asx'                      => 'video/x-ms-asf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3351
			'wmv'                          => 'video/x-ms-wmv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3352
			'wmx'                          => 'video/x-ms-wmx',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3353
			'wm'                           => 'video/x-ms-wm',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3354
			'avi'                          => 'video/avi',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3355
			'divx'                         => 'video/divx',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3356
			'flv'                          => 'video/x-flv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3357
			'mov|qt'                       => 'video/quicktime',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3358
			'mpeg|mpg|mpe'                 => 'video/mpeg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3359
			'mp4|m4v'                      => 'video/mp4',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3360
			'ogv'                          => 'video/ogg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3361
			'webm'                         => 'video/webm',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3362
			'mkv'                          => 'video/x-matroska',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3363
			'3gp|3gpp'                     => 'video/3gpp',  // Can also be audio.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3364
			'3g2|3gp2'                     => 'video/3gpp2', // Can also be audio.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3365
			// Text formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3366
			'txt|asc|c|cc|h|srt'           => 'text/plain',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3367
			'csv'                          => 'text/csv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3368
			'tsv'                          => 'text/tab-separated-values',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3369
			'ics'                          => 'text/calendar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3370
			'rtx'                          => 'text/richtext',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3371
			'css'                          => 'text/css',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3372
			'htm|html'                     => 'text/html',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3373
			'vtt'                          => 'text/vtt',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3374
			'dfxp'                         => 'application/ttaf+xml',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3375
			// Audio formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3376
			'mp3|m4a|m4b'                  => 'audio/mpeg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3377
			'aac'                          => 'audio/aac',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3378
			'ra|ram'                       => 'audio/x-realaudio',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3379
			'wav'                          => 'audio/wav',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3380
			'ogg|oga'                      => 'audio/ogg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3381
			'flac'                         => 'audio/flac',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3382
			'mid|midi'                     => 'audio/midi',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3383
			'wma'                          => 'audio/x-ms-wma',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3384
			'wax'                          => 'audio/x-ms-wax',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3385
			'mka'                          => 'audio/x-matroska',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3386
			// Misc application formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3387
			'rtf'                          => 'application/rtf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3388
			'js'                           => 'application/javascript',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3389
			'pdf'                          => 'application/pdf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3390
			'swf'                          => 'application/x-shockwave-flash',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3391
			'class'                        => 'application/java',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3392
			'tar'                          => 'application/x-tar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3393
			'zip'                          => 'application/zip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3394
			'gz|gzip'                      => 'application/x-gzip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3395
			'rar'                          => 'application/rar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3396
			'7z'                           => 'application/x-7z-compressed',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3397
			'exe'                          => 'application/x-msdownload',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3398
			'psd'                          => 'application/octet-stream',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3399
			'xcf'                          => 'application/octet-stream',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3400
			// MS Office formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3401
			'doc'                          => 'application/msword',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3402
			'pot|pps|ppt'                  => 'application/vnd.ms-powerpoint',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3403
			'wri'                          => 'application/vnd.ms-write',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3404
			'xla|xls|xlt|xlw'              => 'application/vnd.ms-excel',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3405
			'mdb'                          => 'application/vnd.ms-access',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3406
			'mpp'                          => 'application/vnd.ms-project',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3407
			'docx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3408
			'docm'                         => 'application/vnd.ms-word.document.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3409
			'dotx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3410
			'dotm'                         => 'application/vnd.ms-word.template.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3411
			'xlsx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3412
			'xlsm'                         => 'application/vnd.ms-excel.sheet.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3413
			'xlsb'                         => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3414
			'xltx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3415
			'xltm'                         => 'application/vnd.ms-excel.template.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3416
			'xlam'                         => 'application/vnd.ms-excel.addin.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3417
			'pptx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3418
			'pptm'                         => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3419
			'ppsx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3420
			'ppsm'                         => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3421
			'potx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.template',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3422
			'potm'                         => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3423
			'ppam'                         => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3424
			'sldx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3425
			'sldm'                         => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3426
			'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3427
			'oxps'                         => 'application/oxps',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3428
			'xps'                          => 'application/vnd.ms-xpsdocument',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3429
			// OpenOffice formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3430
			'odt'                          => 'application/vnd.oasis.opendocument.text',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3431
			'odp'                          => 'application/vnd.oasis.opendocument.presentation',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3432
			'ods'                          => 'application/vnd.oasis.opendocument.spreadsheet',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3433
			'odg'                          => 'application/vnd.oasis.opendocument.graphics',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3434
			'odc'                          => 'application/vnd.oasis.opendocument.chart',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3435
			'odb'                          => 'application/vnd.oasis.opendocument.database',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3436
			'odf'                          => 'application/vnd.oasis.opendocument.formula',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3437
			// WordPerfect formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3438
			'wp|wpd'                       => 'application/wordperfect',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3439
			// iWork formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3440
			'key'                          => 'application/vnd.apple.keynote',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3441
			'numbers'                      => 'application/vnd.apple.numbers',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3442
			'pages'                        => 'application/vnd.apple.pages',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3443
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3444
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3445
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3446
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3447
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3448
 * Retrieves the list of common file extensions and their types.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3449
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3450
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3451
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3452
 * @return array[] Multi-dimensional array of file extensions types keyed by the type of file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3453
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3454
function wp_get_ext_types() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3455
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3456
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3457
	 * Filters file type based on the extension name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3458
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3459
	 * @since 2.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3460
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3461
	 * @see wp_ext2type()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3462
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3463
	 * @param array[] $ext2type Multi-dimensional array of file extensions types keyed by the type of file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3464
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3465
	return apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3466
		'ext2type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3467
		array(
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3468
			'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3469
			'audio'       => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3470
			'video'       => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3471
			'document'    => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3472
			'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3473
			'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3474
			'text'        => array( 'asc', 'csv', 'tsv', 'txt' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3475
			'archive'     => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3476
			'code'        => array( 'css', 'htm', 'html', 'php', 'js' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3477
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3478
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3479
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3480
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3481
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3482
 * Wrapper for PHP filesize with filters and casting the result as an integer.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3483
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3484
 * @since 6.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3485
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3486
 * @link https://www.php.net/manual/en/function.filesize.php
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3487
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3488
 * @param string $path Path to the file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3489
 * @return int The size of the file in bytes, or 0 in the event of an error.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3490
 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3491
function wp_filesize( $path ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3492
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3493
	 * Filters the result of wp_filesize before the PHP function is run.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3494
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3495
	 * @since 6.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3496
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3497
	 * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3498
	 * @param string   $path Path to the file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3499
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3500
	$size = apply_filters( 'pre_wp_filesize', null, $path );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3501
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3502
	if ( is_int( $size ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3503
		return $size;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3504
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3505
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3506
	$size = file_exists( $path ) ? (int) filesize( $path ) : 0;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3507
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3508
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3509
	 * Filters the size of the file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3510
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3511
	 * @since 6.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3512
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3513
	 * @param int    $size The result of PHP filesize on the file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3514
	 * @param string $path Path to the file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3515
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3516
	return (int) apply_filters( 'wp_filesize', $size, $path );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3517
}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3518
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3519
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3520
 * Retrieve list of allowed mime types and file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3521
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3522
 * @since 2.8.6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3523
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3524
 * @param int|WP_User $user Optional. User to check. Defaults to current user.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3525
 * @return string[] Array of mime types keyed by the file extension regex corresponding
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3526
 *                  to those types.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3527
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3528
function get_allowed_mime_types( $user = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3529
	$t = wp_get_mime_types();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3531
	unset( $t['swf'], $t['exe'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3532
	if ( function_exists( 'current_user_can' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3533
		$unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3534
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3535
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3536
	if ( empty( $unfiltered ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3537
		unset( $t['htm|html'], $t['js'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3538
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3539
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3540
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3541
	 * Filters list of allowed mime types and file extensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3542
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3543
	 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3544
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3545
	 * @param array            $t    Mime types keyed by the file extension regex corresponding to those types.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3546
	 * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3547
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3548
	return apply_filters( 'upload_mimes', $t, $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3549
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3550
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3551
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3552
 * Display "Are You Sure" message to confirm the action being taken.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3553
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3554
 * If the action has the nonce explain message, then it will be displayed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3555
 * along with the "Are you sure?" message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3556
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3557
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3558
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3559
 * @param string $action The nonce action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3560
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3561
function wp_nonce_ays( $action ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3562
	// Default title and response code.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3563
	$title         = __( 'Something went wrong.' );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3564
	$response_code = 403;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3565
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3566
	if ( 'log-out' === $action ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3567
		$title = sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3568
			/* translators: %s: Site title. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3569
			__( 'You are attempting to log out of %s' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3570
			get_bloginfo( 'name' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3571
		);
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3572
		$html        = $title;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3573
		$html       .= '</p><p>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3574
		$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3575
		$html       .= sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3576
			/* translators: %s: Logout URL. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3577
			__( 'Do you really want to <a href="%s">log out</a>?' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3578
			wp_logout_url( $redirect_to )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3579
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3580
	} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3581
		$html = __( 'The link you followed has expired.' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3582
		if ( wp_get_referer() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3583
			$html .= '</p><p>';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3584
			$html .= sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3585
				'<a href="%s">%s</a>',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3586
				esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3587
				__( 'Please try again.' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3588
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3589
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3590
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3591
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3592
	wp_die( $html, $title, $response_code );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3593
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3595
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3596
 * Kills WordPress execution and displays HTML page with an error message.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3597
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3598
 * This function complements the `die()` PHP function. The difference is that
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3599
 * HTML will be displayed to the user. It is recommended to use this function
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3600
 * only when the execution should not continue any further. It is not recommended
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3601
 * to call this function very often, and try to handle as many errors as possible
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3602
 * silently or more gracefully.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3603
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3604
 * As a shorthand, the desired HTTP response code may be passed as an integer to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3605
 * the `$title` parameter (the default title would apply) or the `$args` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3606
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3607
 * @since 2.0.4
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3608
 * @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3609
 *              an integer to be used as the response code.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3610
 * @since 5.1.0 The `$link_url`, `$link_text`, and `$exit` arguments were added.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3611
 * @since 5.3.0 The `$charset` argument was added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3612
 * @since 5.5.0 The `$text_direction` argument has a priority over get_language_attributes()
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3613
 *              in the default handler.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3614
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3615
 * @global WP_Query $wp_query WordPress Query object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3616
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3617
 * @param string|WP_Error  $message Optional. Error message. If this is a WP_Error object,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3618
 *                                  and not an Ajax or XML-RPC request, the error's messages are used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3619
 *                                  Default empty.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3620
 * @param string|int       $title   Optional. Error title. If `$message` is a `WP_Error` object,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3621
 *                                  error data with the key 'title' may be used to specify the title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3622
 *                                  If `$title` is an integer, then it is treated as the response
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3623
 *                                  code. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3624
 * @param string|array|int $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3625
 *     Optional. Arguments to control behavior. If `$args` is an integer, then it is treated
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3626
 *     as the response code. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3627
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3628
 *     @type int    $response       The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3629
 *     @type string $link_url       A URL to include a link to. Only works in combination with $link_text.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3630
 *                                  Default empty string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3631
 *     @type string $link_text      A label for the link to include. Only works in combination with $link_url.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3632
 *                                  Default empty string.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3633
 *     @type bool   $back_link      Whether to include a link to go back. Default false.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3634
 *     @type string $text_direction The text direction. This is only useful internally, when WordPress is still
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3635
 *                                  loading and the site's locale is not set up yet. Accepts 'rtl' and 'ltr'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3636
 *                                  Default is the value of is_rtl().
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3637
 *     @type string $charset        Character set of the HTML output. Default 'utf-8'.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3638
 *     @type string $code           Error code to use. Default is 'wp_die', or the main error code if $message
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3639
 *                                  is a WP_Error.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3640
 *     @type bool   $exit           Whether to exit the process after completion. Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3641
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3642
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3643
function wp_die( $message = '', $title = '', $args = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3644
	global $wp_query;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3645
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3646
	if ( is_int( $args ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3647
		$args = array( 'response' => $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3648
	} elseif ( is_int( $title ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3649
		$args  = array( 'response' => $title );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3650
		$title = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3651
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3652
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3653
	if ( wp_doing_ajax() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3654
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3655
		 * Filters the callback for killing WordPress execution for Ajax requests.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3656
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3657
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3658
		 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3659
		 * @param callable $callback Callback function name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3660
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3661
		$callback = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3662
	} elseif ( wp_is_json_request() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3663
		/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3664
		 * Filters the callback for killing WordPress execution for JSON requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3665
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3666
		 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3667
		 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3668
		 * @param callable $callback Callback function name.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3669
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3670
		$callback = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3671
	} elseif ( defined( 'REST_REQUEST' ) && REST_REQUEST && wp_is_jsonp_request() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3672
		/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3673
		 * Filters the callback for killing WordPress execution for JSONP REST requests.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3674
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3675
		 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3676
		 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3677
		 * @param callable $callback Callback function name.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3678
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3679
		$callback = apply_filters( 'wp_die_jsonp_handler', '_jsonp_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3680
	} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3681
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3682
		 * Filters the callback for killing WordPress execution for XML-RPC requests.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3683
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3684
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3685
		 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3686
		 * @param callable $callback Callback function name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3687
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3688
		$callback = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3689
	} elseif ( wp_is_xml_request()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3690
		|| isset( $wp_query ) &&
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3691
			( function_exists( 'is_feed' ) && is_feed()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3692
			|| function_exists( 'is_comment_feed' ) && is_comment_feed()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3693
			|| function_exists( 'is_trackback' ) && is_trackback() ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3694
		/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3695
		 * Filters the callback for killing WordPress execution for XML requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3696
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3697
		 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3698
		 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3699
		 * @param callable $callback Callback function name.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3700
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3701
		$callback = apply_filters( 'wp_die_xml_handler', '_xml_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3702
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3703
		/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3704
		 * Filters the callback for killing WordPress execution for all non-Ajax, non-JSON, non-XML requests.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3705
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3706
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3707
		 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3708
		 * @param callable $callback Callback function name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3709
		 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3710
		$callback = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3711
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3712
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  3713
	call_user_func( $callback, $message, $title, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3714
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3715
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3716
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3717
 * Kills WordPress execution and displays HTML page with an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3718
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3719
 * This is the default handler for wp_die(). If you want a custom one,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3720
 * you can override this using the {@see 'wp_die_handler'} filter in wp_die().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3721
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3722
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3723
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3724
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3725
 * @param string|WP_Error $message Error message or WP_Error object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3726
 * @param string          $title   Optional. Error title. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3727
 * @param string|array    $args    Optional. Arguments to control behavior. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3728
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3729
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3730
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3731
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3732
	if ( is_string( $message ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3733
		if ( ! empty( $parsed_args['additional_errors'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3734
			$message = array_merge(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3735
				array( $message ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3736
				wp_list_pluck( $parsed_args['additional_errors'], 'message' )
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3737
			);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3738
			$message = "<ul>\n\t\t<li>" . implode( "</li>\n\t\t<li>", $message ) . "</li>\n\t</ul>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3739
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3740
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3741
		$message = sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3742
			'<div class="wp-die-message">%s</div>',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3743
			$message
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3744
		);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3745
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3746
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3747
	$have_gettext = function_exists( '__' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3748
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3749
	if ( ! empty( $parsed_args['link_url'] ) && ! empty( $parsed_args['link_text'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3750
		$link_url = $parsed_args['link_url'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3751
		if ( function_exists( 'esc_url' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3752
			$link_url = esc_url( $link_url );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3753
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3754
		$link_text = $parsed_args['link_text'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3755
		$message  .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3756
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3757
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3758
	if ( isset( $parsed_args['back_link'] ) && $parsed_args['back_link'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3759
		$back_text = $have_gettext ? __( '&laquo; Back' ) : '&laquo; Back';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3760
		$message  .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3761
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3763
	if ( ! did_action( 'admin_head' ) ) :
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3764
		if ( ! headers_sent() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3765
			header( "Content-Type: text/html; charset={$parsed_args['charset']}" );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3766
			status_header( $parsed_args['response'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3767
			nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3768
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3769
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3770
		$text_direction = $parsed_args['text_direction'];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3771
		$dir_attr       = "dir='$text_direction'";
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3772
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3773
		// If `text_direction` was not explicitly passed,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3774
		// use get_language_attributes() if available.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3775
		if ( empty( $args['text_direction'] )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3776
			&& function_exists( 'language_attributes' ) && function_exists( 'is_rtl' )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3777
		) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3778
			$dir_attr = get_language_attributes();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3779
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3780
		?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3781
<!DOCTYPE html>
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3782
<html <?php echo $dir_attr; ?>>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3783
<head>
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3784
	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $parsed_args['charset']; ?>" />
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3785
	<meta name="viewport" content="width=device-width">
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3786
		<?php
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3787
		if ( function_exists( 'wp_robots' ) && function_exists( 'wp_robots_no_robots' ) && function_exists( 'add_filter' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3788
			add_filter( 'wp_robots', 'wp_robots_no_robots' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3789
			wp_robots();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3790
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3791
		?>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3792
	<title><?php echo $title; ?></title>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3793
	<style type="text/css">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3794
		html {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3795
			background: #f1f1f1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3796
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3797
		body {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3798
			background: #fff;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3799
			border: 1px solid #ccd0d4;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3800
			color: #444;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3801
			font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3802
			margin: 2em auto;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3803
			padding: 1em 2em;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3804
			max-width: 700px;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3805
			-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3806
			box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3807
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3808
		h1 {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3809
			border-bottom: 1px solid #dadada;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3810
			clear: both;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3811
			color: #666;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3812
			font-size: 24px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3813
			margin: 30px 0 0 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3814
			padding: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3815
			padding-bottom: 7px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3816
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3817
		#error-page {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3818
			margin-top: 50px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3819
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3820
		#error-page p,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3821
		#error-page .wp-die-message {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3822
			font-size: 14px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3823
			line-height: 1.5;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3824
			margin: 25px 0 20px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3825
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3826
		#error-page code {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3827
			font-family: Consolas, Monaco, monospace;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3828
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3829
		ul li {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3830
			margin-bottom: 10px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3831
			font-size: 14px ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3832
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3833
		a {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3834
			color: #0073aa;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3835
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3836
		a:hover,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3837
		a:active {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3838
			color: #006799;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3839
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3840
		a:focus {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3841
			color: #124964;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3842
			-webkit-box-shadow:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3843
				0 0 0 1px #5b9dd9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3844
				0 0 2px 1px rgba(30, 140, 190, 0.8);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3845
			box-shadow:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3846
				0 0 0 1px #5b9dd9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3847
				0 0 2px 1px rgba(30, 140, 190, 0.8);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3848
			outline: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3849
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3850
		.button {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3851
			background: #f3f5f6;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3852
			border: 1px solid #016087;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3853
			color: #016087;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3854
			display: inline-block;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3855
			text-decoration: none;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3856
			font-size: 13px;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3857
			line-height: 2;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3858
			height: 28px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3859
			margin: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3860
			padding: 0 10px 1px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3861
			cursor: pointer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3862
			-webkit-border-radius: 3px;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3863
			-webkit-appearance: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3864
			border-radius: 3px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3865
			white-space: nowrap;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3866
			-webkit-box-sizing: border-box;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3867
			-moz-box-sizing:    border-box;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3868
			box-sizing:         border-box;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3869
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3870
			vertical-align: top;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3871
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3873
		.button.button-large {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3874
			line-height: 2.30769231;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3875
			min-height: 32px;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3876
			padding: 0 12px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3877
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3878
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3879
		.button:hover,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3880
		.button:focus {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3881
			background: #f1f1f1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3882
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3883
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3884
		.button:focus {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3885
			background: #f3f5f6;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3886
			border-color: #007cba;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3887
			-webkit-box-shadow: 0 0 0 1px #007cba;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3888
			box-shadow: 0 0 0 1px #007cba;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3889
			color: #016087;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3890
			outline: 2px solid transparent;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3891
			outline-offset: 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3892
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3893
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3894
		.button:active {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3895
			background: #f3f5f6;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3896
			border-color: #7e8993;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3897
			-webkit-box-shadow: none;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3898
			box-shadow: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3899
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3900
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3901
		<?php
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3902
		if ( 'rtl' === $text_direction ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3903
			echo 'body { font-family: Tahoma, Arial; }';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3904
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3905
		?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3906
	</style>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3907
</head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3908
<body id="error-page">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3909
<?php endif; // ! did_action( 'admin_head' ) ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3910
	<?php echo $message; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3911
</body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3912
</html>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3913
	<?php
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3914
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3915
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3916
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3917
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3918
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3919
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3920
 * Kills WordPress execution and displays Ajax response with an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3921
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3922
 * This is the handler for wp_die() when processing Ajax requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3923
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3924
 * @since 3.4.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3925
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3926
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3927
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3928
 * @param string       $title   Optional. Error title (unused). Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3929
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3930
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3931
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3932
	// Set default 'response' to 200 for Ajax requests.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3933
	$args = wp_parse_args(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3934
		$args,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3935
		array( 'response' => 200 )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3936
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3937
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3938
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3939
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3940
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3941
		// This is intentional. For backward-compatibility, support passing null here.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3942
		if ( null !== $args['response'] ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3943
			status_header( $parsed_args['response'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3944
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3945
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3946
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3947
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3948
	if ( is_scalar( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3949
		$message = (string) $message;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3950
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3951
		$message = '0';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3952
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3953
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3954
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3955
		die( $message );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3956
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3957
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3958
	echo $message;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3959
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3960
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3961
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3962
 * Kills WordPress execution and displays JSON response with an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3963
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3964
 * This is the handler for wp_die() when processing JSON requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3965
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3966
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3967
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3968
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3969
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3970
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3971
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3972
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3973
function _json_wp_die_handler( $message, $title = '', $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3974
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3975
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3976
	$data = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3977
		'code'              => $parsed_args['code'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3978
		'message'           => $message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3979
		'data'              => array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3980
			'status' => $parsed_args['response'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3981
		),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3982
		'additional_errors' => $parsed_args['additional_errors'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3983
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3984
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3985
	if ( ! headers_sent() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3986
		header( "Content-Type: application/json; charset={$parsed_args['charset']}" );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3987
		if ( null !== $parsed_args['response'] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3988
			status_header( $parsed_args['response'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3989
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3990
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3991
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3992
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3993
	echo wp_json_encode( $data );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  3994
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3995
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3996
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3997
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3998
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3999
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4000
 * Kills WordPress execution and displays JSONP response with an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4001
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4002
 * This is the handler for wp_die() when processing JSONP requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4003
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4004
 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4005
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4006
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4007
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4008
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4009
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4010
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4011
function _jsonp_wp_die_handler( $message, $title = '', $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4012
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4013
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4014
	$data = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4015
		'code'              => $parsed_args['code'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4016
		'message'           => $message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4017
		'data'              => array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4018
			'status' => $parsed_args['response'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4019
		),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4020
		'additional_errors' => $parsed_args['additional_errors'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4021
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4022
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4023
	if ( ! headers_sent() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4024
		header( "Content-Type: application/javascript; charset={$parsed_args['charset']}" );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4025
		header( 'X-Content-Type-Options: nosniff' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4026
		header( 'X-Robots-Tag: noindex' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4027
		if ( null !== $parsed_args['response'] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4028
			status_header( $parsed_args['response'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4029
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4030
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4031
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4032
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4033
	$result         = wp_json_encode( $data );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4034
	$jsonp_callback = $_GET['_jsonp'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4035
	echo '/**/' . $jsonp_callback . '(' . $result . ')';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4036
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4037
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4038
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4039
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4040
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4041
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4042
 * Kills WordPress execution and displays XML response with an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4043
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4044
 * This is the handler for wp_die() when processing XMLRPC requests.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4045
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4046
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4047
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4048
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4049
 * @global wp_xmlrpc_server $wp_xmlrpc_server
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4050
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4051
 * @param string       $message Error message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4052
 * @param string       $title   Optional. Error title. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4053
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4054
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4055
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4056
	global $wp_xmlrpc_server;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4057
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4058
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4059
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4060
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4061
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4062
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4063
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4064
	if ( $wp_xmlrpc_server ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4065
		$error = new IXR_Error( $parsed_args['response'], $message );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4066
		$wp_xmlrpc_server->output( $error->getXml() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4067
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4068
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4069
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4070
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4071
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4072
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4073
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4074
 * Kills WordPress execution and displays XML response with an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4075
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4076
 * This is the handler for wp_die() when processing XML requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4077
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4078
 * @since 5.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4079
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4080
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4081
 * @param string       $message Error message.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4082
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4083
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4084
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4085
function _xml_wp_die_handler( $message, $title = '', $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4086
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4087
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4088
	$message = htmlspecialchars( $message );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4089
	$title   = htmlspecialchars( $title );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4090
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4091
	$xml = <<<EOD
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4092
<error>
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4093
    <code>{$parsed_args['code']}</code>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4094
    <title><![CDATA[{$title}]]></title>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4095
    <message><![CDATA[{$message}]]></message>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4096
    <data>
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4097
        <status>{$parsed_args['response']}</status>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4098
    </data>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4099
</error>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4100
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4101
EOD;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4102
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4103
	if ( ! headers_sent() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4104
		header( "Content-Type: text/xml; charset={$parsed_args['charset']}" );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4105
		if ( null !== $parsed_args['response'] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4106
			status_header( $parsed_args['response'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4107
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4108
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4109
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4110
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4111
	echo $xml;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4112
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4113
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4114
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4115
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4116
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4117
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4118
 * Kills WordPress execution and displays an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4119
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4120
 * This is the handler for wp_die() when processing APP requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4121
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4122
 * @since 3.4.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4123
 * @since 5.1.0 Added the $title and $args parameters.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4124
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4125
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4126
 * @param string       $message Optional. Response to print. Default empty.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4127
 * @param string       $title   Optional. Error title (unused). Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4128
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4129
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4130
function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4131
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4132
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4133
	if ( $parsed_args['exit'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4134
		if ( is_scalar( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4135
			die( (string) $message );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4136
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4137
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4138
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4139
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4140
	if ( is_scalar( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4141
		echo (string) $message;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4142
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4143
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4144
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4145
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4146
 * Processes arguments passed to wp_die() consistently for its handlers.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4147
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4148
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4149
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4150
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4151
 * @param string|WP_Error $message Error message or WP_Error object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4152
 * @param string          $title   Optional. Error title. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4153
 * @param string|array    $args    Optional. Arguments to control behavior. Default empty array.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4154
 * @return array {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4155
 *     Processed arguments.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4156
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4157
 *     @type string $0 Error message.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4158
 *     @type string $1 Error title.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4159
 *     @type array  $2 Arguments to control behavior.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4160
 * }
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4161
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4162
function _wp_die_process_input( $message, $title = '', $args = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4163
	$defaults = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4164
		'response'          => 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4165
		'code'              => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4166
		'exit'              => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4167
		'back_link'         => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4168
		'link_url'          => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4169
		'link_text'         => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4170
		'text_direction'    => '',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4171
		'charset'           => 'utf-8',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4172
		'additional_errors' => array(),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4173
	);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4174
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4175
	$args = wp_parse_args( $args, $defaults );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4176
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4177
	if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4178
		if ( ! empty( $message->errors ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4179
			$errors = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4180
			foreach ( (array) $message->errors as $error_code => $error_messages ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4181
				foreach ( (array) $error_messages as $error_message ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4182
					$errors[] = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4183
						'code'    => $error_code,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4184
						'message' => $error_message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4185
						'data'    => $message->get_error_data( $error_code ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4186
					);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4187
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4188
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4189
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4190
			$message = $errors[0]['message'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4191
			if ( empty( $args['code'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4192
				$args['code'] = $errors[0]['code'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4193
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4194
			if ( empty( $args['response'] ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['status'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4195
				$args['response'] = $errors[0]['data']['status'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4196
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4197
			if ( empty( $title ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['title'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4198
				$title = $errors[0]['data']['title'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4199
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4200
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4201
			unset( $errors[0] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4202
			$args['additional_errors'] = array_values( $errors );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4203
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4204
			$message = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4205
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4206
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4207
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4208
	$have_gettext = function_exists( '__' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4209
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4210
	// The $title and these specific $args must always have a non-empty value.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4211
	if ( empty( $args['code'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4212
		$args['code'] = 'wp_die';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4213
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4214
	if ( empty( $args['response'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4215
		$args['response'] = 500;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4216
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4217
	if ( empty( $title ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4218
		$title = $have_gettext ? __( 'WordPress &rsaquo; Error' ) : 'WordPress &rsaquo; Error';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4219
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4220
	if ( empty( $args['text_direction'] ) || ! in_array( $args['text_direction'], array( 'ltr', 'rtl' ), true ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4221
		$args['text_direction'] = 'ltr';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4222
		if ( function_exists( 'is_rtl' ) && is_rtl() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4223
			$args['text_direction'] = 'rtl';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4224
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4225
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4226
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4227
	if ( ! empty( $args['charset'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4228
		$args['charset'] = _canonical_charset( $args['charset'] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4229
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4230
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4231
	return array( $message, $title, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4232
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4234
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4235
 * Encode a variable into JSON, with some sanity checks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4236
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4237
 * @since 4.1.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4238
 * @since 5.3.0 No longer handles support for PHP < 5.6.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4239
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4240
 * @param mixed $data    Variable (usually an array or object) to encode as JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4241
 * @param int   $options Optional. Options to be passed to json_encode(). Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4242
 * @param int   $depth   Optional. Maximum depth to walk through $data. Must be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4243
 *                       greater than 0. Default 512.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4244
 * @return string|false The JSON encoded string, or false if it cannot be encoded.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4245
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4246
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4247
	$json = json_encode( $data, $options, $depth );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4248
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4249
	// If json_encode() was successful, no need to do more sanity checking.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4250
	if ( false !== $json ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4251
		return $json;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4252
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4253
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4254
	try {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4255
		$data = _wp_json_sanity_check( $data, $depth );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4256
	} catch ( Exception $e ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4257
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4258
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4259
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4260
	return json_encode( $data, $options, $depth );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4261
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4262
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4263
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4264
 * Perform sanity checks on data that shall be encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4265
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4266
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4267
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4268
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4269
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4270
 * @see wp_json_encode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4271
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4272
 * @throws Exception If depth limit is reached.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4273
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4274
 * @param mixed $data  Variable (usually an array or object) to encode as JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4275
 * @param int   $depth Maximum depth to walk through $data. Must be greater than 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4276
 * @return mixed The sanitized data that shall be encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4277
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4278
function _wp_json_sanity_check( $data, $depth ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4279
	if ( $depth < 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4280
		throw new Exception( 'Reached depth limit' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4281
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4282
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4283
	if ( is_array( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4284
		$output = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4285
		foreach ( $data as $id => $el ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4286
			// Don't forget to sanitize the ID!
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4287
			if ( is_string( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4288
				$clean_id = _wp_json_convert_string( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4289
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4290
				$clean_id = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4291
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4292
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4293
			// Check the element type, so that we're only recursing if we really have to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4294
			if ( is_array( $el ) || is_object( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4295
				$output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4296
			} elseif ( is_string( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4297
				$output[ $clean_id ] = _wp_json_convert_string( $el );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4298
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4299
				$output[ $clean_id ] = $el;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4300
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4301
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4302
	} elseif ( is_object( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4303
		$output = new stdClass;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4304
		foreach ( $data as $id => $el ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4305
			if ( is_string( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4306
				$clean_id = _wp_json_convert_string( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4307
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4308
				$clean_id = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4309
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4310
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4311
			if ( is_array( $el ) || is_object( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4312
				$output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4313
			} elseif ( is_string( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4314
				$output->$clean_id = _wp_json_convert_string( $el );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4315
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4316
				$output->$clean_id = $el;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4317
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4318
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4319
	} elseif ( is_string( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4320
		return _wp_json_convert_string( $data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4321
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4322
		return $data;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4323
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4324
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4325
	return $output;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4326
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4327
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4328
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4329
 * Convert a string to UTF-8, so that it can be safely encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4330
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4331
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4332
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4333
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4334
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4335
 * @see _wp_json_sanity_check()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4336
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4337
 * @param string $string The string which is to be converted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4338
 * @return string The checked string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4339
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4340
function _wp_json_convert_string( $string ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4341
	static $use_mb = null;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4342
	if ( is_null( $use_mb ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4343
		$use_mb = function_exists( 'mb_convert_encoding' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4344
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4345
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4346
	if ( $use_mb ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4347
		$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4348
		if ( $encoding ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4349
			return mb_convert_encoding( $string, 'UTF-8', $encoding );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4350
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4351
			return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4352
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4353
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4354
		return wp_check_invalid_utf8( $string, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4355
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4356
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4357
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4358
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4359
 * Prepares response data to be serialized to JSON.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4360
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4361
 * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4362
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4363
 * @ignore
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4364
 * @since 4.4.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4365
 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4366
 *                   has been dropped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4367
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4368
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4369
 * @param mixed $data Native representation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4370
 * @return bool|int|float|null|string|array Data ready for `json_encode()`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4371
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4372
function _wp_json_prepare_data( $data ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4373
	_deprecated_function( __FUNCTION__, '5.3.0' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4374
	return $data;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4375
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4376
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4377
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4378
 * Send a JSON response back to an Ajax request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4379
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4380
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4381
 * @since 4.7.0 The `$status_code` parameter was added.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4382
 * @since 5.6.0 The `$options` parameter was added.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4383
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4384
 * @param mixed $response    Variable (usually an array or object) to encode as JSON,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4385
 *                           then print and die.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4386
 * @param int   $status_code Optional. The HTTP status code to output. Default null.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4387
 * @param int   $options     Optional. Options to be passed to json_encode(). Default 0.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4388
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4389
function wp_send_json( $response, $status_code = null, $options = 0 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4390
	if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4391
		_doing_it_wrong(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4392
			__FUNCTION__,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4393
			sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4394
				/* translators: 1: WP_REST_Response, 2: WP_Error */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4395
				__( 'Return a %1$s or %2$s object from your callback when using the REST API.' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4396
				'WP_REST_Response',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4397
				'WP_Error'
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4398
			),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4399
			'5.5.0'
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4400
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4401
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4402
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4403
	if ( ! headers_sent() ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4404
		header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4405
		if ( null !== $status_code ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4406
			status_header( $status_code );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4407
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4408
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4409
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4410
	echo wp_json_encode( $response, $options );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4411
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4412
	if ( wp_doing_ajax() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4413
		wp_die(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4414
			'',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4415
			'',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4416
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4417
				'response' => null,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4418
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4419
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4420
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4421
		die;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4422
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4423
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4425
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4426
 * Send a JSON response back to an Ajax request, indicating success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4427
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4428
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4429
 * @since 4.7.0 The `$status_code` parameter was added.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4430
 * @since 5.6.0 The `$options` parameter was added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4431
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4432
 * @param mixed $data        Optional. Data to encode as JSON, then print and die. Default null.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4433
 * @param int   $status_code Optional. The HTTP status code to output. Default null.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4434
 * @param int   $options     Optional. Options to be passed to json_encode(). Default 0.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4435
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4436
function wp_send_json_success( $data = null, $status_code = null, $options = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4437
	$response = array( 'success' => true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4438
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4439
	if ( isset( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4440
		$response['data'] = $data;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4441
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4442
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4443
	wp_send_json( $response, $status_code, $options );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4444
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4446
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4447
 * Send a JSON response back to an Ajax request, indicating failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4448
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4449
 * If the `$data` parameter is a WP_Error object, the errors
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4450
 * within the object are processed and output as an array of error
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4451
 * codes and corresponding messages. All other types are output
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4452
 * without further processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4453
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4454
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4455
 * @since 4.1.0 The `$data` parameter is now processed if a WP_Error object is passed in.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4456
 * @since 4.7.0 The `$status_code` parameter was added.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4457
 * @since 5.6.0 The `$options` parameter was added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4458
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4459
 * @param mixed $data        Optional. Data to encode as JSON, then print and die. Default null.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4460
 * @param int   $status_code Optional. The HTTP status code to output. Default null.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4461
 * @param int   $options     Optional. Options to be passed to json_encode(). Default 0.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4462
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4463
function wp_send_json_error( $data = null, $status_code = null, $options = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4464
	$response = array( 'success' => false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4465
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4466
	if ( isset( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4467
		if ( is_wp_error( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4468
			$result = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4469
			foreach ( $data->errors as $code => $messages ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4470
				foreach ( $messages as $message ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4471
					$result[] = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4472
						'code'    => $code,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4473
						'message' => $message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4474
					);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4475
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4476
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4477
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4478
			$response['data'] = $result;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4479
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4480
			$response['data'] = $data;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4481
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4482
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4483
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4484
	wp_send_json( $response, $status_code, $options );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4485
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4486
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4487
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4488
 * Checks that a JSONP callback is a valid JavaScript callback name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4489
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4490
 * Only allows alphanumeric characters and the dot character in callback
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4491
 * function names. This helps to mitigate XSS attacks caused by directly
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4492
 * outputting user input.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4493
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4494
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4495
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4496
 * @param string $callback Supplied JSONP callback function name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4497
 * @return bool Whether the callback function name is valid.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4498
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4499
function wp_check_jsonp_callback( $callback ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4500
	if ( ! is_string( $callback ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4501
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4502
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4503
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4504
	preg_replace( '/[^\w\.]/', '', $callback, -1, $illegal_char_count );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4505
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4506
	return 0 === $illegal_char_count;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4507
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4509
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4510
 * Reads and decodes a JSON file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4511
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4512
 * @since 5.9.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4513
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4514
 * @param string $filename Path to the JSON file.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4515
 * @param array  $options  {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4516
 *     Optional. Options to be used with `json_decode()`.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4517
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4518
 *     @type bool $associative Optional. When `true`, JSON objects will be returned as associative arrays.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4519
 *                             When `false`, JSON objects will be returned as objects.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4520
 * }
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4521
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4522
 * @return mixed Returns the value encoded in JSON in appropriate PHP type.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4523
 *               `null` is returned if the file is not found, or its content can't be decoded.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4524
 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4525
function wp_json_file_decode( $filename, $options = array() ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4526
	$result   = null;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4527
	$filename = wp_normalize_path( realpath( $filename ) );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4528
	if ( ! file_exists( $filename ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4529
		trigger_error(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4530
			sprintf(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4531
				/* translators: %s: Path to the JSON file. */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4532
				__( "File %s doesn't exist!" ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4533
				$filename
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4534
			)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4535
		);
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4536
		return $result;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4537
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4538
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4539
	$options      = wp_parse_args( $options, array( 'associative' => false ) );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4540
	$decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4541
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4542
	if ( JSON_ERROR_NONE !== json_last_error() ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4543
		trigger_error(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4544
			sprintf(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4545
				/* translators: 1: Path to the JSON file, 2: Error message. */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4546
				__( 'Error when decoding a JSON file at path %1$s: %2$s' ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4547
				$filename,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4548
				json_last_error_msg()
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4549
			)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4550
		);
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4551
		return $result;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4552
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4553
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4554
	return $decoded_file;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4555
}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4556
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4557
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4558
 * Retrieve the WordPress home page URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4559
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4560
 * If the constant named 'WP_HOME' exists, then it will be used and returned
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4561
 * by the function. This can be used to counter the redirection on your local
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4562
 * development environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4563
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4564
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4565
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4566
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4567
 * @see WP_HOME
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4568
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4569
 * @param string $url URL for the home location.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4570
 * @return string Homepage location.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4571
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4572
function _config_wp_home( $url = '' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4573
	if ( defined( 'WP_HOME' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4574
		return untrailingslashit( WP_HOME );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4575
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4576
	return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4577
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4579
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4580
 * Retrieve the WordPress site URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4581
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4582
 * If the constant named 'WP_SITEURL' is defined, then the value in that
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4583
 * constant will always be returned. This can be used for debugging a site
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4584
 * on your localhost while not having to change the database to your URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4585
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4586
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4587
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4588
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4589
 * @see WP_SITEURL
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4590
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4591
 * @param string $url URL to set the WordPress site location.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  4592
 * @return string The WordPress site URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4593
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4594
function _config_wp_siteurl( $url = '' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4595
	if ( defined( 'WP_SITEURL' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4596
		return untrailingslashit( WP_SITEURL );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4597
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4598
	return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4599
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4601
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4602
 * Delete the fresh site option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4603
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4604
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4605
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4606
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4607
function _delete_option_fresh_site() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4608
	update_option( 'fresh_site', '0' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4609
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4610
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4611
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4612
 * Set the localized direction for MCE plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4613
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4614
 * Will only set the direction to 'rtl', if the WordPress locale has
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4615
 * the text direction set to 'rtl'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4616
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4617
 * Fills in the 'directionality' setting, enables the 'directionality'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4618
 * plugin, and adds the 'ltr' button to 'toolbar1', formerly
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4619
 * 'theme_advanced_buttons1' array keys. These keys are then returned
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4620
 * in the $mce_init (TinyMCE settings) array.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4621
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4622
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4623
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4624
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4625
 * @param array $mce_init MCE settings array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4626
 * @return array Direction set for 'rtl', if needed by locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4627
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4628
function _mce_set_direction( $mce_init ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4629
	if ( is_rtl() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4630
		$mce_init['directionality'] = 'rtl';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4631
		$mce_init['rtl_ui']         = true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4632
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4633
		if ( ! empty( $mce_init['plugins'] ) && strpos( $mce_init['plugins'], 'directionality' ) === false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4634
			$mce_init['plugins'] .= ',directionality';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4635
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4636
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4637
		if ( ! empty( $mce_init['toolbar1'] ) && ! preg_match( '/\bltr\b/', $mce_init['toolbar1'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4638
			$mce_init['toolbar1'] .= ',ltr';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4639
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4640
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4641
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4642
	return $mce_init;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4643
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4644
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4645
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4646
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4647
 * Convert smiley code to the icon graphic file equivalent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4648
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4649
 * You can turn off smilies, by going to the write setting screen and unchecking
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4650
 * the box, or by setting 'use_smilies' option to false or removing the option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4651
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4652
 * Plugins may override the default smiley list by setting the $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4653
 * to an array, with the key the code the blogger types in and the value the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4654
 * image file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4655
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4656
 * The $wp_smiliessearch global is for the regular expression and is set each
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4657
 * time the function is called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4658
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4659
 * The full list of smilies can be found in the function and won't be listed in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4660
 * the description. Probably should create a Codex page for it, so that it is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4661
 * available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4662
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4663
 * @global array $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4664
 * @global array $wp_smiliessearch
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4665
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4666
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4667
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4668
function smilies_init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4669
	global $wpsmiliestrans, $wp_smiliessearch;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4670
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4671
	// Don't bother setting up smilies if they are disabled.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4672
	if ( ! get_option( 'use_smilies' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4673
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4674
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4675
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4676
	if ( ! isset( $wpsmiliestrans ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4677
		$wpsmiliestrans = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4678
			':mrgreen:' => 'mrgreen.png',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4679
			':neutral:' => "\xf0\x9f\x98\x90",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4680
			':twisted:' => "\xf0\x9f\x98\x88",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4681
			':arrow:'   => "\xe2\x9e\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4682
			':shock:'   => "\xf0\x9f\x98\xaf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4683
			':smile:'   => "\xf0\x9f\x99\x82",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4684
			':???:'     => "\xf0\x9f\x98\x95",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4685
			':cool:'    => "\xf0\x9f\x98\x8e",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4686
			':evil:'    => "\xf0\x9f\x91\xbf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4687
			':grin:'    => "\xf0\x9f\x98\x80",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4688
			':idea:'    => "\xf0\x9f\x92\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4689
			':oops:'    => "\xf0\x9f\x98\xb3",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4690
			':razz:'    => "\xf0\x9f\x98\x9b",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4691
			':roll:'    => "\xf0\x9f\x99\x84",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4692
			':wink:'    => "\xf0\x9f\x98\x89",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4693
			':cry:'     => "\xf0\x9f\x98\xa5",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4694
			':eek:'     => "\xf0\x9f\x98\xae",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4695
			':lol:'     => "\xf0\x9f\x98\x86",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4696
			':mad:'     => "\xf0\x9f\x98\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4697
			':sad:'     => "\xf0\x9f\x99\x81",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4698
			'8-)'       => "\xf0\x9f\x98\x8e",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4699
			'8-O'       => "\xf0\x9f\x98\xaf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4700
			':-('       => "\xf0\x9f\x99\x81",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4701
			':-)'       => "\xf0\x9f\x99\x82",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4702
			':-?'       => "\xf0\x9f\x98\x95",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4703
			':-D'       => "\xf0\x9f\x98\x80",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4704
			':-P'       => "\xf0\x9f\x98\x9b",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4705
			':-o'       => "\xf0\x9f\x98\xae",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4706
			':-x'       => "\xf0\x9f\x98\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4707
			':-|'       => "\xf0\x9f\x98\x90",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4708
			';-)'       => "\xf0\x9f\x98\x89",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4709
			// This one transformation breaks regular text with frequency.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4710
			//     '8)' => "\xf0\x9f\x98\x8e",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4711
			'8O'        => "\xf0\x9f\x98\xaf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4712
			':('        => "\xf0\x9f\x99\x81",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4713
			':)'        => "\xf0\x9f\x99\x82",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4714
			':?'        => "\xf0\x9f\x98\x95",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4715
			':D'        => "\xf0\x9f\x98\x80",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4716
			':P'        => "\xf0\x9f\x98\x9b",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4717
			':o'        => "\xf0\x9f\x98\xae",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4718
			':x'        => "\xf0\x9f\x98\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4719
			':|'        => "\xf0\x9f\x98\x90",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4720
			';)'        => "\xf0\x9f\x98\x89",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4721
			':!:'       => "\xe2\x9d\x97",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4722
			':?:'       => "\xe2\x9d\x93",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4723
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4724
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4725
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4726
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4727
	 * Filters all the smilies.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4728
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4729
	 * This filter must be added before `smilies_init` is run, as
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4730
	 * it is normally only run once to setup the smilies regex.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4731
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4732
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4733
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4734
	 * @param string[] $wpsmiliestrans List of the smilies' hexadecimal representations, keyed by their smily code.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4735
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4736
	$wpsmiliestrans = apply_filters( 'smilies', $wpsmiliestrans );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4737
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4738
	if ( count( $wpsmiliestrans ) == 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4739
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4740
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4741
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4742
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4743
	 * NOTE: we sort the smilies in reverse key order. This is to make sure
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4744
	 * we match the longest possible smilie (:???: vs :?) as the regular
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4745
	 * expression used below is first-match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4746
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4747
	krsort( $wpsmiliestrans );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4748
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4749
	$spaces = wp_spaces_regexp();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4750
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4751
	// Begin first "subpattern".
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4752
	$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4753
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4754
	$subchar = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4755
	foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4756
		$firstchar = substr( $smiley, 0, 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4757
		$rest      = substr( $smiley, 1 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4758
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4759
		// New subpattern?
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4760
		if ( $firstchar != $subchar ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4761
			if ( '' !== $subchar ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4762
				$wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern".
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4763
				$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4764
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4765
			$subchar           = $firstchar;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4766
			$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4767
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4768
			$wp_smiliessearch .= '|';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4769
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4770
		$wp_smiliessearch .= preg_quote( $rest, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4771
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4772
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4773
	$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4774
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4775
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4777
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4778
 * Merges user defined arguments into defaults array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4779
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4780
 * This function is used throughout WordPress to allow for both string or array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4781
 * to be merged into another array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4782
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4783
 * @since 2.2.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4784
 * @since 2.3.0 `$args` can now also be an object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4785
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4786
 * @param string|array|object $args     Value to merge with $defaults.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4787
 * @param array               $defaults Optional. Array that serves as the defaults.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4788
 *                                      Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4789
 * @return array Merged user defined values with defaults.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4790
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4791
function wp_parse_args( $args, $defaults = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4792
	if ( is_object( $args ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4793
		$parsed_args = get_object_vars( $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4794
	} elseif ( is_array( $args ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4795
		$parsed_args =& $args;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4796
	} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4797
		wp_parse_str( $args, $parsed_args );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4798
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4799
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4800
	if ( is_array( $defaults ) && $defaults ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4801
		return array_merge( $defaults, $parsed_args );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4802
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4803
	return $parsed_args;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4804
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4805
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4806
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4807
 * Converts a comma- or space-separated list of scalar values to an array.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4808
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4809
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4810
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4811
 * @param array|string $list List of values.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4812
 * @return array Array of values.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4813
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4814
function wp_parse_list( $list ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4815
	if ( ! is_array( $list ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4816
		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4817
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4818
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4819
	return $list;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4820
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4821
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4822
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4823
 * Cleans up an array, comma- or space-separated list of IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4824
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4825
 * @since 3.0.0
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4826
 * @since 5.1.0 Refactored to use wp_parse_list().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4827
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4828
 * @param array|string $list List of IDs.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4829
 * @return int[] Sanitized array of IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4830
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4831
function wp_parse_id_list( $list ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4832
	$list = wp_parse_list( $list );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4833
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4834
	return array_unique( array_map( 'absint', $list ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4835
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4836
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4837
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4838
 * Cleans up an array, comma- or space-separated list of slugs.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4839
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4840
 * @since 4.7.0
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4841
 * @since 5.1.0 Refactored to use wp_parse_list().
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4842
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4843
 * @param array|string $list List of slugs.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  4844
 * @return string[] Sanitized array of slugs.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4845
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4846
function wp_parse_slug_list( $list ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4847
	$list = wp_parse_list( $list );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4848
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4849
	return array_unique( array_map( 'sanitize_title', $list ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4850
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4851
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4852
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4853
 * Extract a slice of an array, given a list of keys.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4854
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4855
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4856
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4857
 * @param array $array The original array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4858
 * @param array $keys  The list of keys.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4859
 * @return array The array slice.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4860
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4861
function wp_array_slice_assoc( $array, $keys ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4862
	$slice = array();
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4863
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4864
	foreach ( $keys as $key ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4865
		if ( isset( $array[ $key ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4866
			$slice[ $key ] = $array[ $key ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4867
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4868
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4869
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4870
	return $slice;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4871
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4873
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4874
 * Accesses an array in depth based on a path of keys.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4875
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4876
 * It is the PHP equivalent of JavaScript's `lodash.get()` and mirroring it may help other components
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4877
 * retain some symmetry between client and server implementations.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4878
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4879
 * Example usage:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4880
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4881
 *     $array = array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4882
 *         'a' => array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4883
 *             'b' => array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4884
 *                 'c' => 1,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4885
 *             ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4886
 *         ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4887
 *     );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4888
 *     _wp_array_get( $array, array( 'a', 'b', 'c' ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4889
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4890
 * @internal
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4891
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4892
 * @since 5.6.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4893
 * @access private
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4894
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4895
 * @param array $array   An array from which we want to retrieve some information.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4896
 * @param array $path    An array of keys describing the path with which to retrieve information.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4897
 * @param mixed $default The return value if the path does not exist within the array,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4898
 *                       or if `$array` or `$path` are not arrays.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4899
 * @return mixed The value from the path specified.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4900
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4901
function _wp_array_get( $array, $path, $default = null ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4902
	// Confirm $path is valid.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4903
	if ( ! is_array( $path ) || 0 === count( $path ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4904
		return $default;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4905
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4906
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4907
	foreach ( $path as $path_element ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4908
		if (
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4909
			! is_array( $array ) ||
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4910
			( ! is_string( $path_element ) && ! is_integer( $path_element ) && ! is_null( $path_element ) ) ||
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4911
			! array_key_exists( $path_element, $array )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4912
		) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4913
			return $default;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4914
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4915
		$array = $array[ $path_element ];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4916
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4917
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4918
	return $array;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4919
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4920
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4921
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4922
 * Sets an array in depth based on a path of keys.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4923
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4924
 * It is the PHP equivalent of JavaScript's `lodash.set()` and mirroring it may help other components
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4925
 * retain some symmetry between client and server implementations.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4926
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4927
 * Example usage:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4928
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4929
 *     $array = array();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4930
 *     _wp_array_set( $array, array( 'a', 'b', 'c', 1 ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4931
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4932
 *     $array becomes:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4933
 *     array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4934
 *         'a' => array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4935
 *             'b' => array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4936
 *                 'c' => 1,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4937
 *             ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4938
 *         ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4939
 *     );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4940
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4941
 * @internal
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4942
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4943
 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4944
 * @access private
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4945
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4946
 * @param array $array An array that we want to mutate to include a specific value in a path.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4947
 * @param array $path  An array of keys describing the path that we want to mutate.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4948
 * @param mixed $value The value that will be set.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4949
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4950
function _wp_array_set( &$array, $path, $value = null ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4951
	// Confirm $array is valid.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4952
	if ( ! is_array( $array ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4953
		return;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4954
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4955
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4956
	// Confirm $path is valid.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4957
	if ( ! is_array( $path ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4958
		return;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4959
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4960
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4961
	$path_length = count( $path );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4962
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4963
	if ( 0 === $path_length ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4964
		return;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4965
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4966
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4967
	foreach ( $path as $path_element ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4968
		if (
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4969
			! is_string( $path_element ) && ! is_integer( $path_element ) &&
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4970
			! is_null( $path_element )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4971
		) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4972
			return;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4973
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4974
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4975
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4976
	for ( $i = 0; $i < $path_length - 1; ++$i ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4977
		$path_element = $path[ $i ];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4978
		if (
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4979
			! array_key_exists( $path_element, $array ) ||
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4980
			! is_array( $array[ $path_element ] )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4981
		) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4982
			$array[ $path_element ] = array();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4983
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4984
		$array = &$array[ $path_element ]; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4985
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4986
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4987
	$array[ $path[ $i ] ] = $value;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4988
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4989
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4990
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4991
 * This function is trying to replicate what
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4992
 * lodash's kebabCase (JS library) does in the client.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4993
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4994
 * The reason we need this function is that we do some processing
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4995
 * in both the client and the server (e.g.: we generate
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4996
 * preset classes from preset slugs) that needs to
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4997
 * create the same output.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4998
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4999
 * We can't remove or update the client's library due to backward compatibility
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5000
 * (some of the output of lodash's kebabCase is saved in the post content).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5001
 * We have to make the server behave like the client.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5002
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5003
 * Changes to this function should follow updates in the client
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5004
 * with the same logic.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5005
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5006
 * @link https://github.com/lodash/lodash/blob/4.17/dist/lodash.js#L14369
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5007
 * @link https://github.com/lodash/lodash/blob/4.17/dist/lodash.js#L278
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5008
 * @link https://github.com/lodash-php/lodash-php/blob/master/src/String/kebabCase.php
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5009
 * @link https://github.com/lodash-php/lodash-php/blob/master/src/internal/unicodeWords.php
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5010
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5011
 * @param string $string The string to kebab-case.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5012
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5013
 * @return string kebab-cased-string.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5014
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5015
function _wp_to_kebab_case( $string ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5016
	//phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5017
	// ignore the camelCase names for variables so the names are the same as lodash
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5018
	// so comparing and porting new changes is easier.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5019
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5020
	/*
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5021
	 * Some notable things we've removed compared to the lodash version are:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5022
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5023
	 * - non-alphanumeric characters: rsAstralRange, rsEmoji, etc
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5024
	 * - the groups that processed the apostrophe, as it's removed before passing the string to preg_match: rsApos, rsOptContrLower, and rsOptContrUpper
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5025
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5026
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5027
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5028
	/** Used to compose unicode character classes. */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5029
	$rsLowerRange       = 'a-z\\xdf-\\xf6\\xf8-\\xff';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5030
	$rsNonCharRange     = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5031
	$rsPunctuationRange = '\\x{2000}-\\x{206f}';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5032
	$rsSpaceRange       = ' \\t\\x0b\\f\\xa0\\x{feff}\\n\\r\\x{2028}\\x{2029}\\x{1680}\\x{180e}\\x{2000}\\x{2001}\\x{2002}\\x{2003}\\x{2004}\\x{2005}\\x{2006}\\x{2007}\\x{2008}\\x{2009}\\x{200a}\\x{202f}\\x{205f}\\x{3000}';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5033
	$rsUpperRange       = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5034
	$rsBreakRange       = $rsNonCharRange . $rsPunctuationRange . $rsSpaceRange;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5035
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5036
	/** Used to compose unicode capture groups. */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5037
	$rsBreak  = '[' . $rsBreakRange . ']';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5038
	$rsDigits = '\\d+'; // The last lodash version in GitHub uses a single digit here and expands it when in use.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5039
	$rsLower  = '[' . $rsLowerRange . ']';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5040
	$rsMisc   = '[^' . $rsBreakRange . $rsDigits . $rsLowerRange . $rsUpperRange . ']';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5041
	$rsUpper  = '[' . $rsUpperRange . ']';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5042
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5043
	/** Used to compose unicode regexes. */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5044
	$rsMiscLower = '(?:' . $rsLower . '|' . $rsMisc . ')';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5045
	$rsMiscUpper = '(?:' . $rsUpper . '|' . $rsMisc . ')';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5046
	$rsOrdLower  = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5047
	$rsOrdUpper  = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5048
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5049
	$regexp = '/' . implode(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5050
		'|',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5051
		array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5052
			$rsUpper . '?' . $rsLower . '+' . '(?=' . implode( '|', array( $rsBreak, $rsUpper, '$' ) ) . ')',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5053
			$rsMiscUpper . '+' . '(?=' . implode( '|', array( $rsBreak, $rsUpper . $rsMiscLower, '$' ) ) . ')',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5054
			$rsUpper . '?' . $rsMiscLower . '+',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5055
			$rsUpper . '+',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5056
			$rsOrdUpper,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5057
			$rsOrdLower,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5058
			$rsDigits,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5059
		)
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5060
	) . '/u';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5061
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5062
	preg_match_all( $regexp, str_replace( "'", '', $string ), $matches );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5063
	return strtolower( implode( '-', $matches[0] ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5064
	//phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5065
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5066
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5067
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5068
 * Determines if the variable is a numeric-indexed array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5069
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5070
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5071
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5072
 * @param mixed $data Variable to check.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5073
 * @return bool Whether the variable is a list.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5074
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5075
function wp_is_numeric_array( $data ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5076
	if ( ! is_array( $data ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5077
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5078
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5079
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5080
	$keys        = array_keys( $data );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5081
	$string_keys = array_filter( $keys, 'is_string' );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5082
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5083
	return count( $string_keys ) === 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5084
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5085
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5086
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5087
 * Filters a list of objects, based on a set of key => value arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5088
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5089
 * Retrieves the objects from the list that match the given arguments.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5090
 * Key represents property name, and value represents property value.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5091
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5092
 * If an object has more properties than those specified in arguments,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5093
 * that will not disqualify it. When using the 'AND' operator,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5094
 * any missing properties will disqualify it.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5095
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5096
 * When using the `$field` argument, this function can also retrieve
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5097
 * a particular field from all matching objects, whereas wp_list_filter()
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5098
 * only does the filtering.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5099
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5100
 * @since 3.0.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5101
 * @since 4.7.0 Uses `WP_List_Util` class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5102
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5103
 * @param array       $list     An array of objects to filter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5104
 * @param array       $args     Optional. An array of key => value arguments to match
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5105
 *                              against each object. Default empty array.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5106
 * @param string      $operator Optional. The logical operation to perform. 'AND' means
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5107
 *                              all elements from the array must match. 'OR' means only
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5108
 *                              one element needs to match. 'NOT' means no elements may
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5109
 *                              match. Default 'AND'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5110
 * @param bool|string $field    Optional. A field from the object to place instead
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5111
 *                              of the entire object. Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5112
 * @return array A list of objects or object fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5113
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5114
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5115
	if ( ! is_array( $list ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5116
		return array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5117
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5118
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5119
	$util = new WP_List_Util( $list );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5120
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5121
	$util->filter( $args, $operator );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5122
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5123
	if ( $field ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5124
		$util->pluck( $field );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5125
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5126
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5127
	return $util->get_output();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5128
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5129
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5130
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5131
 * Filters a list of objects, based on a set of key => value arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5132
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5133
 * Retrieves the objects from the list that match the given arguments.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5134
 * Key represents property name, and value represents property value.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5135
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5136
 * If an object has more properties than those specified in arguments,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5137
 * that will not disqualify it. When using the 'AND' operator,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5138
 * any missing properties will disqualify it.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5139
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5140
 * If you want to retrieve a particular field from all matching objects,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5141
 * use wp_filter_object_list() instead.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5142
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5143
 * @since 3.1.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5144
 * @since 4.7.0 Uses `WP_List_Util` class.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5145
 * @since 5.9.0 Converted into a wrapper for `wp_filter_object_list()`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5146
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5147
 * @param array  $list     An array of objects to filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5148
 * @param array  $args     Optional. An array of key => value arguments to match
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5149
 *                         against each object. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5150
 * @param string $operator Optional. The logical operation to perform. 'AND' means
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5151
 *                         all elements from the array must match. 'OR' means only
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5152
 *                         one element needs to match. 'NOT' means no elements may
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5153
 *                         match. Default 'AND'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5154
 * @return array Array of found values.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5155
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5156
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5157
	return wp_filter_object_list( $list, $args, $operator );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5158
}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5159
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5160
/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5161
 * Plucks a certain field out of each object or array in an array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5162
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5163
 * This has the same functionality and prototype of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5164
 * array_column() (PHP 5.5) but also supports objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5165
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5166
 * @since 3.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5167
 * @since 4.0.0 $index_key parameter added.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5168
 * @since 4.7.0 Uses `WP_List_Util` class.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5169
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5170
 * @param array      $list      List of objects or arrays.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5171
 * @param int|string $field     Field from the object to place instead of the entire object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5172
 * @param int|string $index_key Optional. Field from the object to use as keys for the new array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5173
 *                              Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5174
 * @return array Array of found values. If `$index_key` is set, an array of found values with keys
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5175
 *               corresponding to `$index_key`. If `$index_key` is null, array keys from the original
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5176
 *               `$list` will be preserved in the results.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5177
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5178
function wp_list_pluck( $list, $field, $index_key = null ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5179
	if ( ! is_array( $list ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5180
		return array();
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5181
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5182
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5183
	$util = new WP_List_Util( $list );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5184
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5185
	return $util->pluck( $field, $index_key );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5186
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5187
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5188
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5189
 * Sorts an array of objects or arrays based on one or more orderby arguments.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5190
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5191
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5192
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5193
 * @param array        $list          An array of objects to sort.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5194
 * @param string|array $orderby       Optional. Either the field name to order by or an array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5195
 *                                    of multiple orderby fields as $orderby => $order.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5196
 * @param string       $order         Optional. Either 'ASC' or 'DESC'. Only used if $orderby
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5197
 *                                    is a string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5198
 * @param bool         $preserve_keys Optional. Whether to preserve keys. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5199
 * @return array The sorted array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5200
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5201
function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5202
	if ( ! is_array( $list ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5203
		return array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5204
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5205
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5206
	$util = new WP_List_Util( $list );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5207
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5208
	return $util->sort( $orderby, $order, $preserve_keys );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5209
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5211
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5212
 * Determines if Widgets library should be loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5213
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5214
 * Checks to make sure that the widgets library hasn't already been loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5215
 * If it hasn't, then it will load the widgets library and run an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5216
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5217
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5218
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5219
function wp_maybe_load_widgets() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5220
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5221
	 * Filters whether to load the Widgets library.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5222
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5223
	 * Returning a falsey value from the filter will effectively short-circuit
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5224
	 * the Widgets library from loading.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5225
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5226
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5227
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5228
	 * @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5229
	 *                                    Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5230
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5231
	if ( ! apply_filters( 'load_default_widgets', true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5232
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5233
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5234
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5235
	require_once ABSPATH . WPINC . '/default-widgets.php';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5236
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5237
	add_action( '_admin_menu', 'wp_widgets_add_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5238
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5240
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5241
 * Append the Widgets menu to the themes main menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5242
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5243
 * @since 2.2.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5244
 * @since 5.9.3 Don't specify menu order when the active theme is a block theme.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5245
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5246
 * @global array $submenu
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5247
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5248
function wp_widgets_add_menu() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5249
	global $submenu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5250
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5251
	if ( ! current_theme_supports( 'widgets' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5252
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5253
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5254
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5255
	$menu_name = __( 'Widgets' );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5256
	if ( wp_is_block_theme() ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5257
		$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5258
	} else {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5259
		$submenu['themes.php'][7] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5260
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5261
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5262
	ksort( $submenu['themes.php'], SORT_NUMERIC );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5263
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5265
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5266
 * Flush all output buffers for PHP 5.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5267
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5268
 * Make sure all output buffers are flushed before our singletons are destroyed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5269
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5270
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5271
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5272
function wp_ob_end_flush_all() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5273
	$levels = ob_get_level();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5274
	for ( $i = 0; $i < $levels; $i++ ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5275
		ob_end_flush();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5276
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5279
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5280
 * Load custom DB error or display WordPress DB error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5282
 * If a file exists in the wp-content directory named db-error.php, then it will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5283
 * be loaded instead of displaying the WordPress DB error. If it is not found,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5284
 * then the WordPress DB error will be displayed instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5285
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5286
 * The WordPress DB error sets the HTTP status header to 500 to try to prevent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5287
 * search engines from caching the message. Custom DB messages should do the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5288
 * same.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5289
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5290
 * This function was backported to WordPress 2.3.2, but originally was added
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5291
 * in WordPress 2.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5292
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5293
 * @since 2.3.2
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5294
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5295
 * @global wpdb $wpdb WordPress database abstraction object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5296
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5297
function dead_db() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5298
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5299
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5300
	wp_load_translations_early();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5301
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5302
	// Load custom DB error template, if present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5303
	if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5304
		require_once WP_CONTENT_DIR . '/db-error.php';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5305
		die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5306
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5308
	// If installing or in the admin, provide the verbose message.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5309
	if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5310
		wp_die( $wpdb->error );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5311
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5313
	// Otherwise, be terse.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5314
	wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5315
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5317
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5318
 * Convert a value to non-negative integer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5319
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5320
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5321
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5322
 * @param mixed $maybeint Data you wish to have converted to a non-negative integer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5323
 * @return int A non-negative integer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5324
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5325
function absint( $maybeint ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5326
	return abs( (int) $maybeint );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5327
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5329
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5330
 * Mark a function as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5331
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5332
 * There is a {@see 'hook deprecated_function_run'} that will be called that can be used
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5333
 * to get the backtrace up to what file and function called the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5334
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5335
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5336
 * The current behavior is to trigger a user error if `WP_DEBUG` is true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5337
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5338
 * This function is to be used in every function that is deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5339
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5340
 * @since 2.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5341
 * @since 5.4.0 This function is no longer marked as "private".
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5342
 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5343
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5344
 * @param string $function    The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5345
 * @param string $version     The version of WordPress that deprecated the function.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5346
 * @param string $replacement Optional. The function that should have been called. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5347
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5348
function _deprecated_function( $function, $version, $replacement = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5349
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5350
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5351
	 * Fires when a deprecated function is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5352
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5353
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5354
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5355
	 * @param string $function    The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5356
	 * @param string $replacement The function that should have been called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5357
	 * @param string $version     The version of WordPress that deprecated the function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5358
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5359
	do_action( 'deprecated_function_run', $function, $replacement, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5360
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5361
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5362
	 * Filters whether to trigger an error for deprecated functions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5363
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5364
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5365
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5366
	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5367
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5368
	if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5369
		if ( function_exists( '__' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5370
			if ( $replacement ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5371
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5372
					sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5373
						/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5374
						__( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5375
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5376
						$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5377
						$replacement
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5378
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5379
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5380
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5381
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5382
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5383
					sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5384
						/* translators: 1: PHP function name, 2: Version number. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5385
						__( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5386
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5387
						$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5388
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5389
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5390
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5391
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5392
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5393
			if ( $replacement ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5394
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5395
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5396
						'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5397
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5398
						$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5399
						$replacement
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5400
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5401
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5402
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5403
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5404
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5405
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5406
						'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5407
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5408
						$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5409
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5410
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5411
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5412
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5413
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5414
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5415
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5417
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5418
 * Marks a constructor as deprecated and informs when it has been used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5419
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5420
 * Similar to _deprecated_function(), but with different strings. Used to
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5421
 * remove PHP4 style constructors.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5422
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5423
 * The current behavior is to trigger a user error if `WP_DEBUG` is true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5424
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5425
 * This function is to be used in every PHP4 style constructor method that is deprecated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5426
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5427
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5428
 * @since 4.5.0 Added the `$parent_class` parameter.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5429
 * @since 5.4.0 This function is no longer marked as "private".
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5430
 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5431
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5432
 * @param string $class        The class containing the deprecated constructor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5433
 * @param string $version      The version of WordPress that deprecated the function.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5434
 * @param string $parent_class Optional. The parent class calling the deprecated constructor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5435
 *                             Default empty string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5436
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5437
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5438
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5439
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5440
	 * Fires when a deprecated constructor is called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5441
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5442
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5443
	 * @since 4.5.0 Added the `$parent_class` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5444
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5445
	 * @param string $class        The class containing the deprecated constructor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5446
	 * @param string $version      The version of WordPress that deprecated the function.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5447
	 * @param string $parent_class The parent class calling the deprecated constructor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5448
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5449
	do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5450
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5451
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5452
	 * Filters whether to trigger an error for deprecated functions.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5453
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5454
	 * `WP_DEBUG` must be true in addition to the filter evaluating to true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5455
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5456
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5457
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5458
	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5459
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5460
	if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5461
		if ( function_exists( '__' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5462
			if ( $parent_class ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5463
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5464
					sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5465
						/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5466
						__( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5467
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5468
						$parent_class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5469
						$version,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5470
						'<code>__construct()</code>'
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5471
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5472
					E_USER_DEPRECATED
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5473
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5474
			} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5475
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5476
					sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5477
						/* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5478
						__( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5479
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5480
						$version,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5481
						'<code>__construct()</code>'
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5482
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5483
					E_USER_DEPRECATED
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5484
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5485
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5486
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5487
			if ( $parent_class ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5488
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5489
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5490
						'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5491
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5492
						$parent_class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5493
						$version,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5494
						'<code>__construct()</code>'
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5495
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5496
					E_USER_DEPRECATED
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5497
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5498
			} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5499
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5500
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5501
						'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5502
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5503
						$version,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5504
						'<code>__construct()</code>'
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5505
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5506
					E_USER_DEPRECATED
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5507
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5508
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5509
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5510
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5511
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5512
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5513
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5514
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5515
 * Mark a file as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5516
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5517
 * There is a hook {@see 'deprecated_file_included'} that will be called that can be used
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5518
 * to get the backtrace up to what file and function included the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5519
 * file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5520
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5521
 * The current behavior is to trigger a user error if `WP_DEBUG` is true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5522
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5523
 * This function is to be used in every file that is deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5524
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5525
 * @since 2.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5526
 * @since 5.4.0 This function is no longer marked as "private".
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5527
 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5528
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5529
 * @param string $file        The file that was included.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5530
 * @param string $version     The version of WordPress that deprecated the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5531
 * @param string $replacement Optional. The file that should have been included based on ABSPATH.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5532
 *                            Default empty.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5533
 * @param string $message     Optional. A message regarding the change. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5534
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5535
function _deprecated_file( $file, $version, $replacement = '', $message = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5536
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5537
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5538
	 * Fires when a deprecated file is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5539
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5540
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5541
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5542
	 * @param string $file        The file that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5543
	 * @param string $replacement The file that should have been included based on ABSPATH.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5544
	 * @param string $version     The version of WordPress that deprecated the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5545
	 * @param string $message     A message regarding the change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5546
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5547
	do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5548
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5549
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5550
	 * Filters whether to trigger an error for deprecated files.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5551
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5552
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5553
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5554
	 * @param bool $trigger Whether to trigger the error for deprecated files. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5555
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5556
	if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5557
		$message = empty( $message ) ? '' : ' ' . $message;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5558
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5559
		if ( function_exists( '__' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5560
			if ( $replacement ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5561
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5562
					sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5563
						/* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5564
						__( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5565
						$file,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5566
						$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5567
						$replacement
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5568
					) . $message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5569
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5570
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5571
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5572
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5573
					sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5574
						/* translators: 1: PHP file name, 2: Version number. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5575
						__( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5576
						$file,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5577
						$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5578
					) . $message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5579
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5580
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5581
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5582
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5583
			if ( $replacement ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5584
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5585
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5586
						'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5587
						$file,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5588
						$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5589
						$replacement
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5590
					) . $message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5591
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5592
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5593
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5594
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5595
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5596
						'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5597
						$file,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5598
						$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5599
					) . $message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5600
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5601
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5602
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5603
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5604
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5605
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5606
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5607
 * Mark a function argument as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5608
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5609
 * This function is to be used whenever a deprecated function argument is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5610
 * Before this function is called, the argument must be checked for whether it was
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5611
 * used by comparing it to its default value or evaluating whether it is empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5612
 * For example:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5613
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5614
 *     if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5615
 *         _deprecated_argument( __FUNCTION__, '3.0.0' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5616
 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5617
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5618
 * There is a hook deprecated_argument_run that will be called that can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5619
 * to get the backtrace up to what file and function used the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5620
 * argument.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5621
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5622
 * The current behavior is to trigger a user error if WP_DEBUG is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5624
 * @since 3.0.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5625
 * @since 5.4.0 This function is no longer marked as "private".
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5626
 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5627
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5628
 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5629
 * @param string $version  The version of WordPress that deprecated the argument used.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5630
 * @param string $message  Optional. A message regarding the change. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5631
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5632
function _deprecated_argument( $function, $version, $message = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5633
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5634
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5635
	 * Fires when a deprecated argument is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5636
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5637
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5638
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5639
	 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5640
	 * @param string $message  A message regarding the change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5641
	 * @param string $version  The version of WordPress that deprecated the argument used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5642
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5643
	do_action( 'deprecated_argument_run', $function, $message, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5644
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5645
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5646
	 * Filters whether to trigger an error for deprecated arguments.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5647
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5648
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5649
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5650
	 * @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5651
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5652
	if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5653
		if ( function_exists( '__' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5654
			if ( $message ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5655
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5656
					sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5657
						/* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5658
						__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5659
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5660
						$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5661
						$message
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5662
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5663
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5664
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5665
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5666
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5667
					sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5668
						/* translators: 1: PHP function name, 2: Version number. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5669
						__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5670
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5671
						$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5672
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5673
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5674
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5675
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5676
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5677
			if ( $message ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5678
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5679
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5680
						'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5681
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5682
						$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5683
						$message
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5684
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5685
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5686
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5687
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5688
				trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5689
					sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5690
						'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5691
						$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5692
						$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5693
					),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5694
					E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5695
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5696
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5697
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5698
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5699
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5700
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5701
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5702
 * Marks a deprecated action or filter hook as deprecated and throws a notice.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5703
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5704
 * Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5705
 * the deprecated hook was called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5706
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5707
 * Default behavior is to trigger a user error if `WP_DEBUG` is true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5708
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5709
 * This function is called by the do_action_deprecated() and apply_filters_deprecated()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5710
 * functions, and so generally does not need to be called directly.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5711
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5712
 * @since 4.6.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5713
 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5714
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5715
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5716
 * @param string $hook        The hook that was used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5717
 * @param string $version     The version of WordPress that deprecated the hook.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5718
 * @param string $replacement Optional. The hook that should have been used. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5719
 * @param string $message     Optional. A message regarding the change. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5720
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5721
function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5722
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5723
	 * Fires when a deprecated hook is called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5724
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5725
	 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5726
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5727
	 * @param string $hook        The hook that was called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5728
	 * @param string $replacement The hook that should be used as a replacement.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5729
	 * @param string $version     The version of WordPress that deprecated the argument used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5730
	 * @param string $message     A message regarding the change.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5731
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5732
	do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5733
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5734
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5735
	 * Filters whether to trigger deprecated hook errors.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5736
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5737
	 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5738
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5739
	 * @param bool $trigger Whether to trigger deprecated hook errors. Requires
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5740
	 *                      `WP_DEBUG` to be defined true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5741
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5742
	if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5743
		$message = empty( $message ) ? '' : ' ' . $message;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5744
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5745
		if ( $replacement ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5746
			trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5747
				sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5748
					/* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5749
					__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5750
					$hook,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5751
					$version,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5752
					$replacement
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5753
				) . $message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5754
				E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5755
			);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5756
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5757
			trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5758
				sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5759
					/* translators: 1: WordPress hook name, 2: Version number. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5760
					__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5761
					$hook,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5762
					$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5763
				) . $message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5764
				E_USER_DEPRECATED
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5765
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5766
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5767
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5768
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5770
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5771
 * Mark something as being incorrectly called.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5772
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5773
 * There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5774
 * to get the backtrace up to what file and function called the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5775
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5776
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5777
 * The current behavior is to trigger a user error if `WP_DEBUG` is true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5778
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5779
 * @since 3.1.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5780
 * @since 5.4.0 This function is no longer marked as "private".
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5781
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5782
 * @param string $function The function that was called.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5783
 * @param string $message  A message explaining what has been done incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5784
 * @param string $version  The version of WordPress where the message was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5785
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5786
function _doing_it_wrong( $function, $message, $version ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5787
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5788
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5789
	 * Fires when the given function is being used incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5790
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5791
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5792
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5793
	 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5794
	 * @param string $message  A message explaining what has been done incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5795
	 * @param string $version  The version of WordPress where the message was added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5796
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5797
	do_action( 'doing_it_wrong_run', $function, $message, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5798
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5799
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5800
	 * Filters whether to trigger an error for _doing_it_wrong() calls.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5801
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5802
	 * @since 3.1.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5803
	 * @since 5.1.0 Added the $function, $message and $version parameters.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5804
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5805
	 * @param bool   $trigger  Whether to trigger the error for _doing_it_wrong() calls. Default true.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5806
	 * @param string $function The function that was called.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5807
	 * @param string $message  A message explaining what has been done incorrectly.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5808
	 * @param string $version  The version of WordPress where the message was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5809
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5810
	if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5811
		if ( function_exists( '__' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5812
			if ( $version ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5813
				/* translators: %s: Version number. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5814
				$version = sprintf( __( '(This message was added in version %s.)' ), $version );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5815
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5816
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5817
			$message .= ' ' . sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5818
				/* translators: %s: Documentation URL. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5819
				__( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5820
				__( 'https://wordpress.org/support/article/debugging-in-wordpress/' )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5821
			);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5822
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5823
			trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5824
				sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5825
					/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5826
					__( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5827
					$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5828
					$message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5829
					$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5830
				),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5831
				E_USER_NOTICE
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5832
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5833
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5834
			if ( $version ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5835
				$version = sprintf( '(This message was added in version %s.)', $version );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5836
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5837
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5838
			$message .= sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5839
				' Please see <a href="%s">Debugging in WordPress</a> for more information.',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5840
				'https://wordpress.org/support/article/debugging-in-wordpress/'
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5841
			);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5842
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5843
			trigger_error(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5844
				sprintf(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5845
					'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5846
					$function,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5847
					$message,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5848
					$version
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5849
				),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5850
				E_USER_NOTICE
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5851
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5852
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5853
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5854
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5855
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5856
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5857
 * Is the server running earlier than 1.5.0 version of lighttpd?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5858
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5859
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5860
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5861
 * @return bool Whether the server is running lighttpd < 1.5.0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5862
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5863
function is_lighttpd_before_150() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5864
	$server_parts    = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5865
	$server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5866
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5867
	return ( 'lighttpd' === $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5868
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5869
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5870
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5871
 * Does the specified module exist in the Apache config?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5872
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5873
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5874
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5875
 * @global bool $is_apache
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5876
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5877
 * @param string $mod     The module, e.g. mod_rewrite.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5878
 * @param bool   $default Optional. The default return value if the module is not found. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5879
 * @return bool Whether the specified module is loaded.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5880
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5881
function apache_mod_loaded( $mod, $default = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5882
	global $is_apache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5883
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5884
	if ( ! $is_apache ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5885
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5886
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5887
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5888
	if ( function_exists( 'apache_get_modules' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5889
		$mods = apache_get_modules();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5890
		if ( in_array( $mod, $mods, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5891
			return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5892
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5893
	} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5894
			ob_start();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5895
			phpinfo( 8 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5896
			$phpinfo = ob_get_clean();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5897
		if ( false !== strpos( $phpinfo, $mod ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5898
			return true;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5899
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5900
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5901
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5902
	return $default;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5903
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5904
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5905
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5906
 * Check if IIS 7+ supports pretty permalinks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5907
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5908
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5909
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5910
 * @global bool $is_iis7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5911
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5912
 * @return bool Whether IIS7 supports permalinks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5913
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5914
function iis7_supports_permalinks() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5915
	global $is_iis7;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5916
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5917
	$supports_permalinks = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5918
	if ( $is_iis7 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5919
		/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5920
		 * easily update the xml configuration file, hence we just bail out and tell user that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5921
		 * pretty permalinks cannot be used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5922
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5923
		 * Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5924
		 * URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5925
		 * Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5926
		 * via ISAPI then pretty permalinks will not work.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5927
		 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5928
		$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5929
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5930
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5931
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5932
	 * Filters whether IIS 7+ supports pretty permalinks.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5933
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5934
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5935
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5936
	 * @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5937
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5938
	return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5939
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5940
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5941
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5942
 * Validates a file name and path against an allowed set of rules.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5943
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5944
 * A return value of `1` means the file path contains directory traversal.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5945
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5946
 * A return value of `2` means the file path contains a Windows drive path.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5947
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5948
 * A return value of `3` means the file is not in the allowed files list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5949
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5950
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5951
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5952
 * @param string   $file          File path.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5953
 * @param string[] $allowed_files Optional. Array of allowed files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5954
 * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5955
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5956
function validate_file( $file, $allowed_files = array() ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5957
	if ( ! is_scalar( $file ) || '' === $file ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5958
		return 0;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5959
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5960
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5961
	// `../` on its own is not allowed:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5962
	if ( '../' === $file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5963
		return 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5964
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5965
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  5966
	// More than one occurrence of `../` is not allowed:
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5967
	if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5968
		return 1;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5969
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5970
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5971
	// `../` which does not occur at the end of the path is not allowed:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5972
	if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5973
		return 1;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5974
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5975
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5976
	// Files not in the allowed file list are not allowed:
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5977
	if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5978
		return 3;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5979
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5980
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5981
	// Absolute Windows drive paths are not allowed:
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  5982
	if ( ':' === substr( $file, 1, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5983
		return 2;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5984
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5986
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5987
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5988
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5989
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5990
 * Whether to force SSL used for the Administration Screens.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5991
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5992
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5993
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5994
 * @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5995
 * @return bool True if forced, false if not forced.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5996
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5997
function force_ssl_admin( $force = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5998
	static $forced = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5999
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6000
	if ( ! is_null( $force ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6001
		$old_forced = $forced;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6002
		$forced     = $force;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6003
		return $old_forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6004
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6005
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6006
	return $forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6007
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6008
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6009
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6010
 * Guess the URL for the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6011
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6012
 * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6013
 * directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6014
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6015
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6016
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6017
 * @return string The guessed URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6018
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6019
function wp_guess_url() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6020
	if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6021
		$url = WP_SITEURL;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6022
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6023
		$abspath_fix         = str_replace( '\\', '/', ABSPATH );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6024
		$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6025
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6026
		// The request is for the admin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6027
		if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6028
			$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6029
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6030
			// The request is for a file in ABSPATH.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6031
		} elseif ( $script_filename_dir . '/' === $abspath_fix ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6032
			// Strip off any file/query params in the path.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6033
			$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6034
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6035
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6036
			if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6037
				// Request is hitting a file inside ABSPATH.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6038
				$directory = str_replace( ABSPATH, '', $script_filename_dir );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6039
				// Strip off the subdirectory, and any file/query params.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6040
				$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6041
			} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6042
				// Request is hitting a file above ABSPATH.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6043
				$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6044
				// Strip off any file/query params from the path, appending the subdirectory to the installation.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6045
				$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6046
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6047
				$path = $_SERVER['REQUEST_URI'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6048
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6049
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6050
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6051
		$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6052
		$url    = $schema . $_SERVER['HTTP_HOST'] . $path;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6053
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6054
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6055
	return rtrim( $url, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6056
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6057
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6058
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6059
 * Temporarily suspend cache additions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6060
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6061
 * Stops more data being added to the cache, but still allows cache retrieval.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6062
 * This is useful for actions, such as imports, when a lot of data would otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6063
 * be almost uselessly added to the cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6064
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6065
 * Suspension lasts for a single page load at most. Remember to call this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6066
 * function again if you wish to re-enable cache adds earlier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6067
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6068
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6069
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6070
 * @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6071
 * @return bool The current suspend setting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6072
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6073
function wp_suspend_cache_addition( $suspend = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6074
	static $_suspend = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6075
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6076
	if ( is_bool( $suspend ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6077
		$_suspend = $suspend;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6078
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6079
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6080
	return $_suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6081
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6082
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6083
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6084
 * Suspend cache invalidation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6085
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6086
 * Turns cache invalidation on and off. Useful during imports where you don't want to do
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6087
 * invalidations every time a post is inserted. Callers must be sure that what they are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6088
 * doing won't lead to an inconsistent cache when invalidation is suspended.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6089
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6090
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6091
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6092
 * @global bool $_wp_suspend_cache_invalidation
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6093
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6094
 * @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6095
 * @return bool The current suspend setting.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6096
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6097
function wp_suspend_cache_invalidation( $suspend = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6098
	global $_wp_suspend_cache_invalidation;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6099
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6100
	$current_suspend                = $_wp_suspend_cache_invalidation;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6101
	$_wp_suspend_cache_invalidation = $suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6102
	return $current_suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6103
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6105
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6106
 * Determine whether a site is the main site of the current network.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6107
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6108
 * @since 3.0.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6109
 * @since 4.9.0 The `$network_id` parameter was added.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6110
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6111
 * @param int $site_id    Optional. Site ID to test. Defaults to current site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6112
 * @param int $network_id Optional. Network ID of the network to check for.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6113
 *                        Defaults to current network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6114
 * @return bool True if $site_id is the main site of the network, or if not
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6115
 *              running Multisite.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6116
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6117
function is_main_site( $site_id = null, $network_id = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6118
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6119
		return true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6120
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6121
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6122
	if ( ! $site_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6123
		$site_id = get_current_blog_id();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6124
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6125
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6126
	$site_id = (int) $site_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6127
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6128
	return get_main_site_id( $network_id ) === $site_id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6129
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6131
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6132
 * Gets the main site ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6133
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6134
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6135
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6136
 * @param int $network_id Optional. The ID of the network for which to get the main site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6137
 *                        Defaults to the current network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6138
 * @return int The ID of the main site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6139
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6140
function get_main_site_id( $network_id = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6141
	if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6142
		return get_current_blog_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6143
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6144
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6145
	$network = get_network( $network_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6146
	if ( ! $network ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6147
		return 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6148
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6149
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6150
	return $network->site_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6151
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6152
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6153
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6154
 * Determine whether a network is the main network of the Multisite installation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6155
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6156
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6157
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6158
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6159
 * @return bool True if $network_id is the main network, or if not running Multisite.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6160
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6161
function is_main_network( $network_id = null ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6162
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6163
		return true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6164
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6165
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6166
	if ( null === $network_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6167
		$network_id = get_current_network_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6168
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6169
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6170
	$network_id = (int) $network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6171
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6172
	return ( get_main_network_id() === $network_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6173
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6174
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6175
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6176
 * Get the main network ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6177
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6178
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6179
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6180
 * @return int The ID of the main network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6181
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6182
function get_main_network_id() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6183
	if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6184
		return 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6185
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6186
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6187
	$current_network = get_network();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6188
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6189
	if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6190
		$main_network_id = PRIMARY_NETWORK_ID;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6191
	} elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6192
		// If the current network has an ID of 1, assume it is the main network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6193
		$main_network_id = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6194
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6195
		$_networks       = get_networks(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6196
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6197
				'fields' => 'ids',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6198
				'number' => 1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6199
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6200
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6201
		$main_network_id = array_shift( $_networks );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6202
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6203
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6204
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6205
	 * Filters the main network ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6206
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6207
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6208
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6209
	 * @param int $main_network_id The ID of the main network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6210
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6211
	return (int) apply_filters( 'get_main_network_id', $main_network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6212
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6214
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6215
 * Determine whether global terms are enabled.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6216
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6217
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6218
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6219
 * @return bool True if multisite and global terms enabled.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6220
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6221
function global_terms_enabled() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6222
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6223
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6224
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6225
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6226
	static $global_terms = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6227
	if ( is_null( $global_terms ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6228
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6229
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6230
		 * Filters whether global terms are enabled.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6231
		 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6232
		 * Returning a non-null value from the filter will effectively short-circuit the function
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6233
		 * and return the value of the 'global_terms_enabled' site option instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6234
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6235
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6236
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6237
		 * @param null $enabled Whether global terms are enabled.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6238
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6239
		$filter = apply_filters( 'global_terms_enabled', null );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6240
		if ( ! is_null( $filter ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6241
			$global_terms = (bool) $filter;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6242
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6243
			$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6244
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6245
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6246
	return $global_terms;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6247
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6249
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6250
 * Determines whether site meta is enabled.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6251
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6252
 * This function checks whether the 'blogmeta' database table exists. The result is saved as
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6253
 * a setting for the main network, making it essentially a global setting. Subsequent requests
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6254
 * will refer to this setting instead of running the query.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6255
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6256
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6257
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6258
 * @global wpdb $wpdb WordPress database abstraction object.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6259
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6260
 * @return bool True if site meta is supported, false otherwise.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6261
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6262
function is_site_meta_supported() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6263
	global $wpdb;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6264
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6265
	if ( ! is_multisite() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6266
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6267
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6268
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6269
	$network_id = get_main_network_id();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6270
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6271
	$supported = get_network_option( $network_id, 'site_meta_supported', false );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6272
	if ( false === $supported ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6273
		$supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6274
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6275
		update_network_option( $network_id, 'site_meta_supported', $supported );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6276
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6277
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6278
	return (bool) $supported;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6279
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6280
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6281
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6282
 * gmt_offset modification for smart timezone handling.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6284
 * Overrides the gmt_offset option if we have a timezone_string available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6285
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6286
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6287
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6288
 * @return float|false Timezone GMT offset, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6289
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6290
function wp_timezone_override_offset() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6291
	$timezone_string = get_option( 'timezone_string' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6292
	if ( ! $timezone_string ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6293
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6294
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6296
	$timezone_object = timezone_open( $timezone_string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6297
	$datetime_object = date_create();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6298
	if ( false === $timezone_object || false === $datetime_object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6299
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6300
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6301
	return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6302
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6303
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6304
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6305
 * Sort-helper for timezones.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6306
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6307
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6308
 * @access private
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6309
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6310
 * @param array $a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6311
 * @param array $b
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6312
 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6313
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6314
function _wp_timezone_choice_usort_callback( $a, $b ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6315
	// Don't use translated versions of Etc.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6316
	if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6317
		// Make the order of these more like the old dropdown.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6318
		if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6319
			return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6320
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6321
		if ( 'UTC' === $a['city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6322
			if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6323
				return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6324
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6325
			return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6326
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6327
		if ( 'UTC' === $b['city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6328
			if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6329
				return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6330
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6331
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6332
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6333
		return strnatcasecmp( $a['city'], $b['city'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6334
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6335
	if ( $a['t_continent'] == $b['t_continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6336
		if ( $a['t_city'] == $b['t_city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6337
			return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6338
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6339
		return strnatcasecmp( $a['t_city'], $b['t_city'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6340
	} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6341
		// Force Etc to the bottom of the list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6342
		if ( 'Etc' === $a['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6343
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6344
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6345
		if ( 'Etc' === $b['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6346
			return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6347
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6348
		return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6349
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6350
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6352
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6353
 * Gives a nicely-formatted list of timezone strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6354
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6355
 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6356
 * @since 4.7.0 Added the `$locale` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6357
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6358
 * @param string $selected_zone Selected timezone.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6359
 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6360
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6361
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6362
function wp_timezone_choice( $selected_zone, $locale = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6363
	static $mo_loaded = false, $locale_loaded = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6364
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6365
	$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6366
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6367
	// Load translations for continents and cities.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6368
	if ( ! $mo_loaded || $locale !== $locale_loaded ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6369
		$locale_loaded = $locale ? $locale : get_locale();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6370
		$mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6371
		unload_textdomain( 'continents-cities' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6372
		load_textdomain( 'continents-cities', $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6373
		$mo_loaded = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6374
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6376
	$zonen = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6377
	foreach ( timezone_identifiers_list() as $zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6378
		$zone = explode( '/', $zone );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6379
		if ( ! in_array( $zone[0], $continents, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6380
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6381
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6382
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6383
		// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6384
		$exists    = array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6385
			0 => ( isset( $zone[0] ) && $zone[0] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6386
			1 => ( isset( $zone[1] ) && $zone[1] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6387
			2 => ( isset( $zone[2] ) && $zone[2] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6388
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6389
		$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6390
		$exists[4] = ( $exists[1] && $exists[3] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6391
		$exists[5] = ( $exists[2] && $exists[3] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6392
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6393
		// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6394
		$zonen[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6395
			'continent'   => ( $exists[0] ? $zone[0] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6396
			'city'        => ( $exists[1] ? $zone[1] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6397
			'subcity'     => ( $exists[2] ? $zone[2] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6398
			't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6399
			't_city'      => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6400
			't_subcity'   => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6401
		);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6402
		// phpcs:enable
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6403
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6404
	usort( $zonen, '_wp_timezone_choice_usort_callback' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6406
	$structure = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6408
	if ( empty( $selected_zone ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6409
		$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6410
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6412
	foreach ( $zonen as $key => $zone ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6413
		// Build value in an array to join later.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6414
		$value = array( $zone['continent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6416
		if ( empty( $zone['city'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6417
			// It's at the continent level (generally won't happen).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6418
			$display = $zone['t_continent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6419
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6420
			// It's inside a continent group.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6421
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6422
			// Continent optgroup.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6423
			if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6424
				$label       = $zone['t_continent'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6425
				$structure[] = '<optgroup label="' . esc_attr( $label ) . '">';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6426
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6427
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6428
			// Add the city to the value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6429
			$value[] = $zone['city'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6431
			$display = $zone['t_city'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6432
			if ( ! empty( $zone['subcity'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6433
				// Add the subcity to the value.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6434
				$value[]  = $zone['subcity'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6435
				$display .= ' - ' . $zone['t_subcity'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6436
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6437
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6438
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6439
		// Build the value.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6440
		$value    = implode( '/', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6441
		$selected = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6442
		if ( $value === $selected_zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6443
			$selected = 'selected="selected" ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6444
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6445
		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6446
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6447
		// Close continent optgroup.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6448
		if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6449
			$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6450
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6451
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6452
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6453
	// Do UTC.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6454
	$structure[] = '<optgroup label="' . esc_attr__( 'UTC' ) . '">';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6455
	$selected    = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6456
	if ( 'UTC' === $selected_zone ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6457
		$selected = 'selected="selected" ';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6458
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6459
	$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __( 'UTC' ) . '</option>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6460
	$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6461
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6462
	// Do manual UTC offsets.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6463
	$structure[]  = '<optgroup label="' . esc_attr__( 'Manual Offsets' ) . '">';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6464
	$offset_range = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6465
		-12,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6466
		-11.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6467
		-11,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6468
		-10.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6469
		-10,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6470
		-9.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6471
		-9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6472
		-8.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6473
		-8,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6474
		-7.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6475
		-7,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6476
		-6.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6477
		-6,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6478
		-5.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6479
		-5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6480
		-4.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6481
		-4,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6482
		-3.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6483
		-3,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6484
		-2.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6485
		-2,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6486
		-1.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6487
		-1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6488
		-0.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6489
		0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6490
		0.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6491
		1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6492
		1.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6493
		2,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6494
		2.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6495
		3,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6496
		3.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6497
		4,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6498
		4.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6499
		5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6500
		5.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6501
		5.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6502
		6,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6503
		6.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6504
		7,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6505
		7.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6506
		8,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6507
		8.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6508
		8.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6509
		9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6510
		9.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6511
		10,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6512
		10.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6513
		11,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6514
		11.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6515
		12,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6516
		12.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6517
		13,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6518
		13.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6519
		14,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6520
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6521
	foreach ( $offset_range as $offset ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6522
		if ( 0 <= $offset ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6523
			$offset_name = '+' . $offset;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6524
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6525
			$offset_name = (string) $offset;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6526
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6528
		$offset_value = $offset_name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6529
		$offset_name  = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $offset_name );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6530
		$offset_name  = 'UTC' . $offset_name;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6531
		$offset_value = 'UTC' . $offset_value;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6532
		$selected     = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6533
		if ( $offset_value === $selected_zone ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6534
			$selected = 'selected="selected" ';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6535
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6536
		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . '</option>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6538
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6539
	$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6540
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6541
	return implode( "\n", $structure );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6542
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6544
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6545
 * Strip close comment and close php tags from file headers used by WP.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6546
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6547
 * @since 2.8.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6548
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6549
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6550
 * @see https://core.trac.wordpress.org/ticket/8497
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6551
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6552
 * @param string $str Header comment to clean up.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6553
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6554
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6555
function _cleanup_header_comment( $str ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6556
	return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6557
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6558
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6559
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6560
 * Permanently delete comments or posts of any type that have held a status
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6561
 * of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6562
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6563
 * The default value of `EMPTY_TRASH_DAYS` is 30 (days).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6564
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6565
 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6566
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6567
 * @global wpdb $wpdb WordPress database abstraction object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6568
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6569
function wp_scheduled_delete() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6570
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6571
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6572
	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6573
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6574
	$posts_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6576
	foreach ( (array) $posts_to_delete as $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6577
		$post_id = (int) $post['post_id'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6578
		if ( ! $post_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6579
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6580
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6581
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6582
		$del_post = get_post( $post_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6583
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6584
		if ( ! $del_post || 'trash' !== $del_post->post_status ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6585
			delete_post_meta( $post_id, '_wp_trash_meta_status' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6586
			delete_post_meta( $post_id, '_wp_trash_meta_time' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6587
		} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6588
			wp_delete_post( $post_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6589
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6590
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6591
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6592
	$comments_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6594
	foreach ( (array) $comments_to_delete as $comment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6595
		$comment_id = (int) $comment['comment_id'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6596
		if ( ! $comment_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6597
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6598
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6599
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6600
		$del_comment = get_comment( $comment_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6601
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6602
		if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6603
			delete_comment_meta( $comment_id, '_wp_trash_meta_time' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6604
			delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6605
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6606
			wp_delete_comment( $del_comment );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6607
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6608
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6609
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6611
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6612
 * Retrieve metadata from a file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6613
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6614
 * Searches for metadata in the first 8 KB of a file, such as a plugin or theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6615
 * Each piece of metadata must be on its own line. Fields can not span multiple
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6616
 * lines, the value will get cut at the end of the first line.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6617
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6618
 * If the file data is not within that first 8 KB, then the author should correct
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6619
 * their plugin file and move the data headers to the top.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6620
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6621
 * @link https://codex.wordpress.org/File_Header
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6622
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6623
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6624
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6625
 * @param string $file            Absolute path to the file.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6626
 * @param array  $default_headers List of headers, in the format `array( 'HeaderKey' => 'Header Name' )`.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6627
 * @param string $context         Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6628
 *                                Default empty.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6629
 * @return string[] Array of file header values keyed by header name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6630
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6631
function get_file_data( $file, $default_headers, $context = '' ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6632
	// Pull only the first 8 KB of the file in.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6633
	$file_data = file_get_contents( $file, false, null, 0, 8 * KB_IN_BYTES );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6634
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6635
	if ( false === $file_data ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6636
		$file_data = '';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6637
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6639
	// Make sure we catch CR-only line endings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6640
	$file_data = str_replace( "\r", "\n", $file_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6641
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6642
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6643
	 * Filters extra file headers by context.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6644
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6645
	 * The dynamic portion of the hook name, `$context`, refers to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6646
	 * the context where extra headers might be loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6647
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6648
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6649
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6650
	 * @param array $extra_context_headers Empty array by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6651
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6652
	$extra_headers = $context ? apply_filters( "extra_{$context}_headers", array() ) : array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6653
	if ( $extra_headers ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6654
		$extra_headers = array_combine( $extra_headers, $extra_headers ); // Keys equal values.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6655
		$all_headers   = array_merge( $extra_headers, (array) $default_headers );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6656
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6657
		$all_headers = $default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6658
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6659
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6660
	foreach ( $all_headers as $field => $regex ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6661
		if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6662
			$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6663
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6664
			$all_headers[ $field ] = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6665
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6666
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6668
	return $all_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6669
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6670
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6671
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6672
 * Returns true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6673
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6674
 * Useful for returning true to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6675
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6676
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6677
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6678
 * @see __return_false()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6679
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6680
 * @return true True.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6681
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6682
function __return_true() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6683
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6684
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6686
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6687
 * Returns false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6688
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6689
 * Useful for returning false to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6690
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6691
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6692
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6693
 * @see __return_true()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6694
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6695
 * @return false False.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6696
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6697
function __return_false() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6698
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6699
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6701
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6702
 * Returns 0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6703
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6704
 * Useful for returning 0 to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6705
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6706
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6707
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6708
 * @return int 0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6709
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6710
function __return_zero() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6711
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6712
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6713
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6714
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6715
 * Returns an empty array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6716
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6717
 * Useful for returning an empty array to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6718
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6719
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6720
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6721
 * @return array Empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6722
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6723
function __return_empty_array() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6724
	return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6725
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6726
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6727
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6728
 * Returns null.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6729
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6730
 * Useful for returning null to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6731
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6732
 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6733
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6734
 * @return null Null value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6735
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6736
function __return_null() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6737
	return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6738
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6739
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6740
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6741
 * Returns an empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6742
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6743
 * Useful for returning an empty string to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6744
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6745
 * @since 3.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6746
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6747
 * @see __return_null()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6748
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6749
 * @return string Empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6750
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6751
function __return_empty_string() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6752
	return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6753
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6755
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6756
 * Send a HTTP header to disable content type sniffing in browsers which support it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6757
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6758
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6759
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6760
 * @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6761
 * @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6762
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6763
function send_nosniff_header() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6764
	header( 'X-Content-Type-Options: nosniff' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6765
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6766
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6767
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6768
 * Return a MySQL expression for selecting the week number based on the start_of_week option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6769
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6770
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6771
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6772
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6773
 * @param string $column Database column.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6774
 * @return string SQL clause.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6775
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6776
function _wp_mysql_week( $column ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6777
	$start_of_week = (int) get_option( 'start_of_week' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6778
	switch ( $start_of_week ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6779
		case 1:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6780
			return "WEEK( $column, 1 )";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6781
		case 2:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6782
		case 3:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6783
		case 4:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6784
		case 5:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6785
		case 6:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6786
			return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6787
		case 0:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6788
		default:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6789
			return "WEEK( $column, 0 )";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6790
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6791
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6793
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6794
 * Find hierarchy loops using a callback function that maps object IDs to parent IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6795
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6796
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6797
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6798
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6799
 * @param callable $callback      Function that accepts ( ID, $callback_args ) and outputs parent_ID.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6800
 * @param int      $start         The ID to start the loop check at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6801
 * @param int      $start_parent  The parent_ID of $start to use instead of calling $callback( $start ).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6802
 *                                Use null to always use $callback
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6803
 * @param array    $callback_args Optional. Additional arguments to send to $callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6804
 * @return array IDs of all members of loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6805
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6806
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6807
	$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6808
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6809
	$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6810
	if ( ! $arbitrary_loop_member ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6811
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6812
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6814
	return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6815
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6816
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6817
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6818
 * Use the "The Tortoise and the Hare" algorithm to detect loops.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6819
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6820
 * For every step of the algorithm, the hare takes two steps and the tortoise one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6821
 * If the hare ever laps the tortoise, there must be a loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6822
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6823
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6824
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6825
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6826
 * @param callable $callback      Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6827
 * @param int      $start         The ID to start the loop check at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6828
 * @param array    $override      Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6829
 *                                Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6830
 * @param array    $callback_args Optional. Additional arguments to send to $callback. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6831
 * @param bool     $_return_loop  Optional. Return loop members or just detect presence of loop? Only set
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6832
 *                                to true if you already know the given $start is part of a loop (otherwise
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6833
 *                                the returned array might include branches). Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6834
 * @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6835
 *               $_return_loop
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6836
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6837
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6838
	$tortoise        = $start;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6839
	$hare            = $start;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6840
	$evanescent_hare = $start;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6841
	$return          = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6842
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6843
	// Set evanescent_hare to one past hare.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6844
	// Increment hare two steps.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6845
	while (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6846
		$tortoise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6847
	&&
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6848
		( $evanescent_hare = isset( $override[ $hare ] ) ? $override[ $hare ] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6849
	&&
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6850
		( $hare = isset( $override[ $evanescent_hare ] ) ? $override[ $evanescent_hare ] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6851
	) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6852
		if ( $_return_loop ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6853
			$return[ $tortoise ]        = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6854
			$return[ $evanescent_hare ] = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6855
			$return[ $hare ]            = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6856
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6857
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6858
		// Tortoise got lapped - must be a loop.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6859
		if ( $tortoise == $evanescent_hare || $tortoise == $hare ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6860
			return $_return_loop ? $return : $tortoise;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6861
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6862
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6863
		// Increment tortoise by one step.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6864
		$tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6865
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6867
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6868
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6869
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6870
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6871
 * Send a HTTP header to limit rendering of pages to same origin iframes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6872
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6873
 * @since 3.1.3
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6874
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6875
 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6876
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6877
function send_frame_options_header() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6878
	header( 'X-Frame-Options: SAMEORIGIN' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6879
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6880
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6881
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6882
 * Retrieve a list of protocols to allow in HTML attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6883
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6884
 * @since 3.3.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6885
 * @since 4.3.0 Added 'webcal' to the protocols array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6886
 * @since 4.7.0 Added 'urn' to the protocols array.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6887
 * @since 5.3.0 Added 'sms' to the protocols array.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6888
 * @since 5.6.0 Added 'irc6' and 'ircs' to the protocols array.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6889
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6890
 * @see wp_kses()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6891
 * @see esc_url()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6892
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6893
 * @return string[] Array of allowed protocols. Defaults to an array containing 'http', 'https',
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6894
 *                  'ftp', 'ftps', 'mailto', 'news', 'irc', 'irc6', 'ircs', 'gopher', 'nntp', 'feed',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6895
 *                  'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6896
 *                  This covers all common link protocols, except for 'javascript' which should not
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6897
 *                  be allowed for untrusted users.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6898
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6899
function wp_allowed_protocols() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6900
	static $protocols = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6902
	if ( empty( $protocols ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6903
		$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'irc6', 'ircs', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6904
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6905
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6906
	if ( ! did_action( 'wp_loaded' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6907
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6908
		 * Filters the list of protocols allowed in HTML attributes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6909
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6910
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6911
		 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6912
		 * @param string[] $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6913
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6914
		$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6915
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6916
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6917
	return $protocols;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6918
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6919
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6920
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6921
 * Returns a comma-separated string or array of functions that have been called to get
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6922
 * to the current point in code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6923
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6924
 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6925
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6926
 * @see https://core.trac.wordpress.org/ticket/19589
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6927
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6928
 * @param string $ignore_class Optional. A class to ignore all function calls within - useful
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6929
 *                             when you want to just give info about the callee. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6930
 * @param int    $skip_frames  Optional. A number of stack frames to skip - useful for unwinding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6931
 *                             back to the source of the issue. Default 0.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6932
 * @param bool   $pretty       Optional. Whether you want a comma separated string instead of
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  6933
 *                             the raw array returned. Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6934
 * @return string|array Either a string containing a reversed comma separated trace or an array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6935
 *                      of individual calls.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6936
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6937
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6938
	static $truncate_paths;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6939
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6940
	$trace       = debug_backtrace( false );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6941
	$caller      = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6942
	$check_class = ! is_null( $ignore_class );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6943
	$skip_frames++; // Skip this function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6944
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6945
	if ( ! isset( $truncate_paths ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6946
		$truncate_paths = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6947
			wp_normalize_path( WP_CONTENT_DIR ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6948
			wp_normalize_path( ABSPATH ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6949
		);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6950
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6951
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6952
	foreach ( $trace as $call ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6953
		if ( $skip_frames > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6954
			$skip_frames--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6955
		} elseif ( isset( $call['class'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6956
			if ( $check_class && $ignore_class == $call['class'] ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6957
				continue; // Filter out calls.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6958
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6960
			$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6961
		} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6962
			if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ), true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6963
				$caller[] = "{$call['function']}('{$call['args'][0]}')";
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6964
			} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6965
				$filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6966
				$caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6967
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6968
				$caller[] = $call['function'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6969
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6970
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6971
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6972
	if ( $pretty ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  6973
		return implode( ', ', array_reverse( $caller ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6974
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6975
		return $caller;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6976
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6977
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6978
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6979
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6980
 * Retrieve IDs that are not already present in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6981
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6982
 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6983
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6984
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6985
 * @param int[]  $object_ids Array of IDs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6986
 * @param string $cache_key  The cache bucket to check against.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6987
 * @return int[] Array of IDs not present in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6988
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6989
function _get_non_cached_ids( $object_ids, $cache_key ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6990
	$non_cached_ids = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6991
	$cache_values   = wp_cache_get_multiple( $object_ids, $cache_key );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6992
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6993
	foreach ( $cache_values as $id => $value ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6994
		if ( ! $value ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6995
			$non_cached_ids[] = (int) $id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6996
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6997
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6998
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  6999
	return $non_cached_ids;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7000
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7001
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7002
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7003
 * Test if the current device has the capability to upload files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7004
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7005
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7006
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7007
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7008
 * @return bool Whether the device is able to upload files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7009
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7010
function _device_can_upload() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7011
	if ( ! wp_is_mobile() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7012
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7013
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7015
	$ua = $_SERVER['HTTP_USER_AGENT'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7016
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7017
	if ( strpos( $ua, 'iPhone' ) !== false
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7018
		|| strpos( $ua, 'iPad' ) !== false
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7019
		|| strpos( $ua, 'iPod' ) !== false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7020
			return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7021
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7022
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7023
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7024
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7025
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7026
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7027
 * Test if a given path is a stream URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7028
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7029
 * @since 3.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7030
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7031
 * @param string $path The resource path or URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7032
 * @return bool True if the path is a stream URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7033
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7034
function wp_is_stream( $path ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7035
	$scheme_separator = strpos( $path, '://' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7036
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7037
	if ( false === $scheme_separator ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7038
		// $path isn't a stream.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7039
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7040
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7041
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7042
	$stream = substr( $path, 0, $scheme_separator );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7043
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7044
	return in_array( $stream, stream_get_wrappers(), true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7045
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7046
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7047
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7048
 * Test if the supplied date is valid for the Gregorian calendar.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7049
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7050
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7051
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7052
 * @link https://www.php.net/manual/en/function.checkdate.php
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7053
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7054
 * @param int    $month       Month number.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7055
 * @param int    $day         Day number.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7056
 * @param int    $year        Year number.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7057
 * @param string $source_date The date to filter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7058
 * @return bool True if valid date, false if not valid date.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7059
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7060
function wp_checkdate( $month, $day, $year, $source_date ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7061
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7062
	 * Filters whether the given date is valid for the Gregorian calendar.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7063
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7064
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7065
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7066
	 * @param bool   $checkdate   Whether the given date is valid.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7067
	 * @param string $source_date Date to check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7068
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7069
	return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7070
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7071
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7072
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7073
 * Load the auth check for monitoring whether the user is still logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7074
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7075
 * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7076
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7077
 * This is disabled for certain screens where a login screen could cause an
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7078
 * inconvenient interruption. A filter called {@see 'wp_auth_check_load'} can be used
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7079
 * for fine-grained control.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7080
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7081
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7082
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7083
function wp_auth_check_load() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7084
	if ( ! is_admin() && ! is_user_logged_in() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7085
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7086
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7087
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7088
	if ( defined( 'IFRAME_REQUEST' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7089
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7090
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7092
	$screen = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7093
	$hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7094
	$show   = ! in_array( $screen->id, $hidden, true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7095
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7096
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7097
	 * Filters whether to load the authentication check.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7098
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7099
	 * Returning a falsey value from the filter will effectively short-circuit
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7100
	 * loading the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7101
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7102
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7103
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7104
	 * @param bool      $show   Whether to load the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7105
	 * @param WP_Screen $screen The current screen object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7106
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7107
	if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7108
		wp_enqueue_style( 'wp-auth-check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7109
		wp_enqueue_script( 'wp-auth-check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7111
		add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7112
		add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7113
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7114
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7116
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7117
 * Output the HTML that shows the wp-login dialog when the user is no longer logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7119
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7120
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7121
function wp_auth_check_html() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7122
	$login_url      = wp_login_url();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7123
	$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7124
	$same_domain    = ( strpos( $login_url, $current_domain ) === 0 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7125
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7126
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7127
	 * Filters whether the authentication check originated at the same domain.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7128
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7129
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7130
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7131
	 * @param bool $same_domain Whether the authentication check originated at the same domain.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7132
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7133
	$same_domain = apply_filters( 'wp_auth_check_same_domain', $same_domain );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7134
	$wrap_class  = $same_domain ? 'hidden' : 'hidden fallback';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7136
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7137
	<div id="wp-auth-check-wrap" class="<?php echo $wrap_class; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7138
	<div id="wp-auth-check-bg"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7139
	<div id="wp-auth-check">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7140
	<button type="button" class="wp-auth-check-close button-link"><span class="screen-reader-text"><?php _e( 'Close dialog' ); ?></span></button>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7141
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7143
	if ( $same_domain ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7144
		$login_src = add_query_arg(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7145
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7146
				'interim-login' => '1',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7147
				'wp_lang'       => get_user_locale(),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7148
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7149
			$login_url
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7150
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7151
		?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7152
		<div id="wp-auth-check-form" class="loading" data-src="<?php echo esc_url( $login_src ); ?>"></div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7153
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7154
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7156
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7157
	<div class="wp-auth-fallback">
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7158
		<p><b class="wp-auth-fallback-expired" tabindex="0"><?php _e( 'Session expired' ); ?></b></p>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7159
		<p><a href="<?php echo esc_url( $login_url ); ?>" target="_blank"><?php _e( 'Please log in again.' ); ?></a>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7160
		<?php _e( 'The login page will open in a new tab. After logging in you can close it and return to this page.' ); ?></p>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7161
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7162
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7163
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7164
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7165
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7167
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7168
 * Check whether a user is still logged in, for the heartbeat.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7169
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7170
 * Send a result that shows a log-in box if the user is no longer logged in,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7171
 * or if their cookie is within the grace period.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7172
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7173
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7174
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7175
 * @global int $login_grace_period
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7176
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7177
 * @param array $response  The Heartbeat response.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7178
 * @return array The Heartbeat response with 'wp-auth-check' value set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7179
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7180
function wp_auth_check( $response ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7181
	$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7182
	return $response;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7183
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7185
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7186
 * Return RegEx body to liberally match an opening HTML tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7187
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7188
 * Matches an opening HTML tag that:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7189
 * 1. Is self-closing or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7190
 * 2. Has no body but has a closing tag of the same name or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7191
 * 3. Contains a body and a closing tag of the same name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7192
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7193
 * Note: this RegEx does not balance inner tags and does not attempt
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7194
 * to produce valid HTML
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7195
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7196
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7197
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7198
 * @param string $tag An HTML tag name. Example: 'video'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7199
 * @return string Tag RegEx.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7200
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7201
function get_tag_regex( $tag ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7202
	if ( empty( $tag ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7203
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7204
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7205
	return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7206
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7208
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7209
 * Retrieve a canonical form of the provided charset appropriate for passing to PHP
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7210
 * functions such as htmlspecialchars() and charset HTML attributes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7212
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7213
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7214
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7215
 * @see https://core.trac.wordpress.org/ticket/23688
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7216
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7217
 * @param string $charset A charset name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7218
 * @return string The canonical form of the charset.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7219
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7220
function _canonical_charset( $charset ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7221
	if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7222
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7223
		return 'UTF-8';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7224
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7225
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7226
	if ( 'iso-8859-1' === strtolower( $charset ) || 'iso8859-1' === strtolower( $charset ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7227
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7228
		return 'ISO-8859-1';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7229
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7231
	return $charset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7232
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7234
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7235
 * Set the mbstring internal encoding to a binary safe encoding when func_overload
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7236
 * is enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7237
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7238
 * When mbstring.func_overload is in use for multi-byte encodings, the results from
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7239
 * strlen() and similar functions respect the utf8 characters, causing binary data
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7240
 * to return incorrect lengths.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7241
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7242
 * This function overrides the mbstring encoding to a binary-safe encoding, and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7243
 * resets it to the users expected encoding afterwards through the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7244
 * `reset_mbstring_encoding` function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7245
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7246
 * It is safe to recursively call this function, however each
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7247
 * `mbstring_binary_safe_encoding()` call must be followed up with an equal number
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7248
 * of `reset_mbstring_encoding()` calls.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7249
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7250
 * @since 3.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7251
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7252
 * @see reset_mbstring_encoding()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7253
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7254
 * @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7255
 *                    Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7256
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7257
function mbstring_binary_safe_encoding( $reset = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7258
	static $encodings  = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7259
	static $overloaded = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7260
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7261
	if ( is_null( $overloaded ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7262
		if ( function_exists( 'mb_internal_encoding' )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7263
			&& ( (int) ini_get( 'mbstring.func_overload' ) & 2 ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7264
		) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7265
			$overloaded = true;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7266
		} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7267
			$overloaded = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7268
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7269
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7270
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7271
	if ( false === $overloaded ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7272
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7273
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7275
	if ( ! $reset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7276
		$encoding = mb_internal_encoding();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7277
		array_push( $encodings, $encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7278
		mb_internal_encoding( 'ISO-8859-1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7279
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7280
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7281
	if ( $reset && $encodings ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7282
		$encoding = array_pop( $encodings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7283
		mb_internal_encoding( $encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7284
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7285
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7287
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7288
 * Reset the mbstring internal encoding to a users previously set encoding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7289
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7290
 * @see mbstring_binary_safe_encoding()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7291
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7292
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7293
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7294
function reset_mbstring_encoding() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7295
	mbstring_binary_safe_encoding( true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  7296
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7297
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7298
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7299
 * Filter/validate a variable as a boolean.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7300
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7301
 * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7302
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7303
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7304
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7305
 * @param mixed $var Boolean value to validate.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7306
 * @return bool Whether the value is validated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7307
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7308
function wp_validate_boolean( $var ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7309
	if ( is_bool( $var ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7310
		return $var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7311
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7312
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7313
	if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7314
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7315
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7316
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7317
	return (bool) $var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7318
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7319
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7320
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7321
 * Delete a file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7322
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7323
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7324
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7325
 * @param string $file The path to the file to delete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7326
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7327
function wp_delete_file( $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7328
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7329
	 * Filters the path of the file to delete.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7330
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7331
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7332
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7333
	 * @param string $file Path to the file to delete.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7334
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7335
	$delete = apply_filters( 'wp_delete_file', $file );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7336
	if ( ! empty( $delete ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7337
		@unlink( $delete );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7338
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  7339
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7340
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7341
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7342
 * Deletes a file if its path is within the given directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7343
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7344
 * @since 4.9.7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7345
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7346
 * @param string $file      Absolute path to the file to delete.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7347
 * @param string $directory Absolute path to a directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7348
 * @return bool True on success, false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7349
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7350
function wp_delete_file_from_directory( $file, $directory ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7351
	if ( wp_is_stream( $file ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7352
		$real_file      = $file;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7353
		$real_directory = $directory;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7354
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7355
		$real_file      = realpath( wp_normalize_path( $file ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7356
		$real_directory = realpath( wp_normalize_path( $directory ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7357
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7358
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7359
	if ( false !== $real_file ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7360
		$real_file = wp_normalize_path( $real_file );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7361
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7362
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7363
	if ( false !== $real_directory ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7364
		$real_directory = wp_normalize_path( $real_directory );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7365
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7366
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7367
	if ( false === $real_file || false === $real_directory || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7368
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7369
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7370
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7371
	wp_delete_file( $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7372
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7373
	return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7374
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7375
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7376
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7377
 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7378
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7379
 * This prevents reusing the same tab for a preview when the user has navigated away.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7380
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7381
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7382
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7383
 * @global WP_Post $post Global post object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7384
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7385
function wp_post_preview_js() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7386
	global $post;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7387
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7388
	if ( ! is_preview() || empty( $post ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7389
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7390
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7391
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7392
	// Has to match the window name used in post_submit_meta_box().
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7393
	$name = 'wp-preview-' . (int) $post->ID;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7394
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7395
	?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7396
	<script>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7397
	( function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7398
		var query = document.location.search;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7399
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7400
		if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7401
			window.name = '<?php echo $name; ?>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7402
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7403
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7404
		if ( window.addEventListener ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7405
			window.addEventListener( 'unload', function() { window.name = ''; }, false );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7406
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7407
	}());
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7408
	</script>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7409
	<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7410
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7411
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7412
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7413
 * Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7414
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7415
 * Explicitly strips timezones, as datetimes are not saved with any timezone
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7416
 * information. Including any information on the offset could be misleading.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7417
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7418
 * Despite historical function name, the output does not conform to RFC3339 format,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7419
 * which must contain timezone.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7420
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7421
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7422
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7423
 * @param string $date_string Date string to parse and format.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7424
 * @return string Date formatted for ISO8601 without time zone.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7425
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7426
function mysql_to_rfc3339( $date_string ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7427
	return mysql2date( 'Y-m-d\TH:i:s', $date_string, false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7428
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7429
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7430
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7431
 * Attempts to raise the PHP memory limit for memory intensive processes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7432
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7433
 * Only allows raising the existing limit and prevents lowering it.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7434
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7435
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7436
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7437
 * @param string $context Optional. Context in which the function is called. Accepts either 'admin',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7438
 *                        'image', or an arbitrary other context. If an arbitrary context is passed,
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7439
 *                        the similarly arbitrary {@see '$context_memory_limit'} filter will be
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7440
 *                        invoked. Default 'admin'.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7441
 * @return int|string|false The limit that was set or false on failure.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7442
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7443
function wp_raise_memory_limit( $context = 'admin' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7444
	// Exit early if the limit cannot be changed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7445
	if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7446
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7447
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7448
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7449
	$current_limit     = ini_get( 'memory_limit' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7450
	$current_limit_int = wp_convert_hr_to_bytes( $current_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7451
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7452
	if ( -1 === $current_limit_int ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7453
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7454
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7455
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7456
	$wp_max_limit     = WP_MAX_MEMORY_LIMIT;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7457
	$wp_max_limit_int = wp_convert_hr_to_bytes( $wp_max_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7458
	$filtered_limit   = $wp_max_limit;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7459
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7460
	switch ( $context ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7461
		case 'admin':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7462
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7463
			 * Filters the maximum memory limit available for administration screens.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7464
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7465
			 * This only applies to administrators, who may require more memory for tasks
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7466
			 * like updates. Memory limits when processing images (uploaded or edited by
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7467
			 * users of any role) are handled separately.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7468
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7469
			 * The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7470
			 * limit available when in the administration back end. The default is 256M
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7471
			 * (256 megabytes of memory) or the original `memory_limit` php.ini value if
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7472
			 * this is higher.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7473
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7474
			 * @since 3.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7475
			 * @since 4.6.0 The default now takes the original `memory_limit` into account.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7476
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7477
			 * @param int|string $filtered_limit The maximum WordPress memory limit. Accepts an integer
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7478
			 *                                   (bytes), or a shorthand string notation, such as '256M'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7479
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7480
			$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7481
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7482
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7483
		case 'image':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7484
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7485
			 * Filters the memory limit allocated for image manipulation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7486
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7487
			 * @since 3.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7488
			 * @since 4.6.0 The default now takes the original `memory_limit` into account.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7489
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7490
			 * @param int|string $filtered_limit Maximum memory limit to allocate for images.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7491
			 *                                   Default `WP_MAX_MEMORY_LIMIT` or the original
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7492
			 *                                   php.ini `memory_limit`, whichever is higher.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7493
			 *                                   Accepts an integer (bytes), or a shorthand string
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7494
			 *                                   notation, such as '256M'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7495
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7496
			$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7497
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7498
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7499
		default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7500
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7501
			 * Filters the memory limit allocated for arbitrary contexts.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7502
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7503
			 * The dynamic portion of the hook name, `$context`, refers to an arbitrary
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7504
			 * context passed on calling the function. This allows for plugins to define
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7505
			 * their own contexts for raising the memory limit.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7506
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7507
			 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7508
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7509
			 * @param int|string $filtered_limit Maximum memory limit to allocate for images.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7510
			 *                                   Default '256M' or the original php.ini `memory_limit`,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7511
			 *                                   whichever is higher. Accepts an integer (bytes), or a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7512
			 *                                   shorthand string notation, such as '256M'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7513
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7514
			$filtered_limit = apply_filters( "{$context}_memory_limit", $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7515
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7516
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7517
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7518
	$filtered_limit_int = wp_convert_hr_to_bytes( $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7519
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7520
	if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7521
		if ( false !== ini_set( 'memory_limit', $filtered_limit ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7522
			return $filtered_limit;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7523
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7524
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7525
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7526
	} elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7527
		if ( false !== ini_set( 'memory_limit', $wp_max_limit ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7528
			return $wp_max_limit;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7529
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7530
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7531
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7532
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7533
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7534
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7535
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7536
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7537
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7538
 * Generate a random UUID (version 4).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7539
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7540
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7541
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7542
 * @return string UUID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7543
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7544
function wp_generate_uuid4() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7545
	return sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7546
		'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7547
		mt_rand( 0, 0xffff ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7548
		mt_rand( 0, 0xffff ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7549
		mt_rand( 0, 0xffff ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7550
		mt_rand( 0, 0x0fff ) | 0x4000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7551
		mt_rand( 0, 0x3fff ) | 0x8000,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7552
		mt_rand( 0, 0xffff ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7553
		mt_rand( 0, 0xffff ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7554
		mt_rand( 0, 0xffff )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7555
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7556
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7557
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7558
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7559
 * Validates that a UUID is valid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7560
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7561
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7562
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7563
 * @param mixed $uuid    UUID to check.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7564
 * @param int   $version Specify which version of UUID to check against. Default is none,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7565
 *                       to accept any UUID version. Otherwise, only version allowed is `4`.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7566
 * @return bool The string is a valid UUID or false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7567
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7568
function wp_is_uuid( $uuid, $version = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7569
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7570
	if ( ! is_string( $uuid ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7571
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7572
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7573
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7574
	if ( is_numeric( $version ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7575
		if ( 4 !== (int) $version ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7576
			_doing_it_wrong( __FUNCTION__, __( 'Only UUID V4 is supported at this time.' ), '4.9.0' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7577
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7578
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7579
		$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7580
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7581
		$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7582
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7583
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7584
	return (bool) preg_match( $regex, $uuid );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7585
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7586
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7587
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7588
 * Gets unique ID.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7589
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7590
 * This is a PHP implementation of Underscore's uniqueId method. A static variable
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7591
 * contains an integer that is incremented with each call. This number is returned
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7592
 * with the optional prefix. As such the returned value is not universally unique,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7593
 * but it is unique across the life of the PHP process.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7594
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7595
 * @since 5.0.3
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7596
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7597
 * @param string $prefix Prefix for the returned ID.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7598
 * @return string Unique ID.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7599
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7600
function wp_unique_id( $prefix = '' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7601
	static $id_counter = 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7602
	return $prefix . (string) ++$id_counter;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7603
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7604
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7605
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7606
 * Gets last changed date for the specified cache group.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7607
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7608
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7609
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7610
 * @param string $group Where the cache contents are grouped.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7611
 * @return string UNIX timestamp with microseconds representing when the group was last changed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7612
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7613
function wp_cache_get_last_changed( $group ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7614
	$last_changed = wp_cache_get( 'last_changed', $group );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7615
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7616
	if ( ! $last_changed ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7617
		$last_changed = microtime();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7618
		wp_cache_set( 'last_changed', $last_changed, $group );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7619
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7620
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7621
	return $last_changed;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7622
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7623
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7624
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7625
 * Send an email to the old site admin email address when the site admin email address changes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7626
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7627
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7628
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7629
 * @param string $old_email   The old site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7630
 * @param string $new_email   The new site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7631
 * @param string $option_name The relevant database option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7632
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7633
function wp_site_admin_email_change_notification( $old_email, $new_email, $option_name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7634
	$send = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7635
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7636
	// Don't send the notification to the default 'admin_email' value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7637
	if ( 'you@example.com' === $old_email ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7638
		$send = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7639
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7640
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7641
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7642
	 * Filters whether to send the site admin email change notification email.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7643
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7644
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7645
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7646
	 * @param bool   $send      Whether to send the email notification.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7647
	 * @param string $old_email The old site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7648
	 * @param string $new_email The new site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7649
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7650
	$send = apply_filters( 'send_site_admin_email_change_email', $send, $old_email, $new_email );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7651
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7652
	if ( ! $send ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7653
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7654
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7655
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7656
	/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7657
	$email_change_text = __(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7658
		'Hi,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7659
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7660
This notice confirms that the admin email address was changed on ###SITENAME###.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7661
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7662
The new admin email address is ###NEW_EMAIL###.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7663
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7664
This email has been sent to ###OLD_EMAIL###
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7665
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7666
Regards,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7667
All at ###SITENAME###
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7668
###SITEURL###'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7669
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7670
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7671
	$email_change_email = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7672
		'to'      => $old_email,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7673
		/* translators: Site admin email change notification email subject. %s: Site title. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7674
		'subject' => __( '[%s] Admin Email Changed' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7675
		'message' => $email_change_text,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7676
		'headers' => '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7677
	);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7678
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7679
	// Get site name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7680
	$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7681
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7682
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7683
	 * Filters the contents of the email notification sent when the site admin email address is changed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7684
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7685
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7686
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7687
	 * @param array $email_change_email {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7688
	 *     Used to build wp_mail().
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7689
	 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7690
	 *     @type string $to      The intended recipient.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7691
	 *     @type string $subject The subject of the email.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7692
	 *     @type string $message The content of the email.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7693
	 *         The following strings have a special meaning and will get replaced dynamically:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7694
	 *         - ###OLD_EMAIL### The old site admin email address.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7695
	 *         - ###NEW_EMAIL### The new site admin email address.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7696
	 *         - ###SITENAME###  The name of the site.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7697
	 *         - ###SITEURL###   The URL to the site.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7698
	 *     @type string $headers Headers.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7699
	 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7700
	 * @param string $old_email The old site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7701
	 * @param string $new_email The new site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7702
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7703
	$email_change_email = apply_filters( 'site_admin_email_change_email', $email_change_email, $old_email, $new_email );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7704
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7705
	$email_change_email['message'] = str_replace( '###OLD_EMAIL###', $old_email, $email_change_email['message'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7706
	$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $new_email, $email_change_email['message'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7707
	$email_change_email['message'] = str_replace( '###SITENAME###', $site_name, $email_change_email['message'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7708
	$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7709
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7710
	wp_mail(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7711
		$email_change_email['to'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7712
		sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7713
			$email_change_email['subject'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7714
			$site_name
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7715
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7716
		$email_change_email['message'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7717
		$email_change_email['headers']
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7718
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7719
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7720
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7721
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7722
 * Return an anonymized IPv4 or IPv6 address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7723
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7724
 * @since 4.9.6 Abstracted from `WP_Community_Events::get_unsafe_client_ip()`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7725
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7726
 * @param string $ip_addr       The IPv4 or IPv6 address to be anonymized.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7727
 * @param bool   $ipv6_fallback Optional. Whether to return the original IPv6 address if the needed functions
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7728
 *                              to anonymize it are not present. Default false, return `::` (unspecified address).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7729
 * @return string  The anonymized IP address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7730
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7731
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  7732
	if ( empty( $ip_addr ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  7733
		return '0.0.0.0';
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  7734
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  7735
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7736
	// Detect what kind of IP address this is.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7737
	$ip_prefix = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7738
	$is_ipv6   = substr_count( $ip_addr, ':' ) > 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7739
	$is_ipv4   = ( 3 === substr_count( $ip_addr, '.' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7740
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7741
	if ( $is_ipv6 && $is_ipv4 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7742
		// IPv6 compatibility mode, temporarily strip the IPv6 part, and treat it like IPv4.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7743
		$ip_prefix = '::ffff:';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7744
		$ip_addr   = preg_replace( '/^\[?[0-9a-f:]*:/i', '', $ip_addr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7745
		$ip_addr   = str_replace( ']', '', $ip_addr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7746
		$is_ipv6   = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7747
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7748
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7749
	if ( $is_ipv6 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7750
		// IPv6 addresses will always be enclosed in [] if there's a port.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7751
		$left_bracket  = strpos( $ip_addr, '[' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7752
		$right_bracket = strpos( $ip_addr, ']' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7753
		$percent       = strpos( $ip_addr, '%' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7754
		$netmask       = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7755
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7756
		// Strip the port (and [] from IPv6 addresses), if they exist.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7757
		if ( false !== $left_bracket && false !== $right_bracket ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7758
			$ip_addr = substr( $ip_addr, $left_bracket + 1, $right_bracket - $left_bracket - 1 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7759
		} elseif ( false !== $left_bracket || false !== $right_bracket ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7760
			// The IP has one bracket, but not both, so it's malformed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7761
			return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7762
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7763
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7764
		// Strip the reachability scope.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7765
		if ( false !== $percent ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7766
			$ip_addr = substr( $ip_addr, 0, $percent );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7767
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7768
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7769
		// No invalid characters should be left.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7770
		if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7771
			return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7772
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7773
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7774
		// Partially anonymize the IP by reducing it to the corresponding network ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7775
		if ( function_exists( 'inet_pton' ) && function_exists( 'inet_ntop' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7776
			$ip_addr = inet_ntop( inet_pton( $ip_addr ) & inet_pton( $netmask ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7777
			if ( false === $ip_addr ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7778
				return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7779
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7780
		} elseif ( ! $ipv6_fallback ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7781
			return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7782
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7783
	} elseif ( $is_ipv4 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7784
		// Strip any port and partially anonymize the IP.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7785
		$last_octet_position = strrpos( $ip_addr, '.' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7786
		$ip_addr             = substr( $ip_addr, 0, $last_octet_position ) . '.0';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7787
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7788
		return '0.0.0.0';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7789
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7790
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7791
	// Restore the IPv6 prefix to compatibility mode addresses.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7792
	return $ip_prefix . $ip_addr;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7793
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7794
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7795
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7796
 * Return uniform "anonymous" data by type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7797
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7798
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7799
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7800
 * @param string $type The type of data to be anonymized.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7801
 * @param string $data Optional The data to be anonymized.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7802
 * @return string The anonymous data for the requested type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7803
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7804
function wp_privacy_anonymize_data( $type, $data = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7805
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7806
	switch ( $type ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7807
		case 'email':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7808
			$anonymous = 'deleted@site.invalid';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7809
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7810
		case 'url':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7811
			$anonymous = 'https://site.invalid';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7812
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7813
		case 'ip':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7814
			$anonymous = wp_privacy_anonymize_ip( $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7815
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7816
		case 'date':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7817
			$anonymous = '0000-00-00 00:00:00';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7818
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7819
		case 'text':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7820
			/* translators: Deleted text. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7821
			$anonymous = __( '[deleted]' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7822
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7823
		case 'longtext':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7824
			/* translators: Deleted long text. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7825
			$anonymous = __( 'This content was deleted by the author.' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7826
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7827
		default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7828
			$anonymous = '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7829
			break;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7830
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7831
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7832
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7833
	 * Filters the anonymous data for each type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7834
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7835
	 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7836
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7837
	 * @param string $anonymous Anonymized data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7838
	 * @param string $type      Type of the data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7839
	 * @param string $data      Original data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7840
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7841
	return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7842
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7843
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7844
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7845
 * Returns the directory used to store personal data export files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7846
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7847
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7848
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7849
 * @see wp_privacy_exports_url
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7850
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7851
 * @return string Exports directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7852
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7853
function wp_privacy_exports_dir() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7854
	$upload_dir  = wp_upload_dir();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7855
	$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7856
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7857
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7858
	 * Filters the directory used to store personal data export files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7859
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7860
	 * @since 4.9.6
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7861
	 * @since 5.5.0 Exports now use relative paths, so changes to the directory
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7862
	 *              via this filter should be reflected on the server.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7863
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7864
	 * @param string $exports_dir Exports directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7865
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7866
	return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7867
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7868
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7869
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7870
 * Returns the URL of the directory used to store personal data export files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7871
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7872
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7873
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7874
 * @see wp_privacy_exports_dir
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7875
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7876
 * @return string Exports directory URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7877
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7878
function wp_privacy_exports_url() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7879
	$upload_dir  = wp_upload_dir();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7880
	$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7881
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7882
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7883
	 * Filters the URL of the directory used to store personal data export files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7884
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7885
	 * @since 4.9.6
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7886
	 * @since 5.5.0 Exports now use relative paths, so changes to the directory URL
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7887
	 *              via this filter should be reflected on the server.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7888
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7889
	 * @param string $exports_url Exports directory URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7890
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7891
	return apply_filters( 'wp_privacy_exports_url', $exports_url );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7892
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7893
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7894
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7895
 * Schedule a `WP_Cron` job to delete expired export files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7896
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7897
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7898
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7899
function wp_schedule_delete_old_privacy_export_files() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7900
	if ( wp_installing() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7901
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7902
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7903
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7904
	if ( ! wp_next_scheduled( 'wp_privacy_delete_old_export_files' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7905
		wp_schedule_event( time(), 'hourly', 'wp_privacy_delete_old_export_files' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7906
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7907
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7908
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7909
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7910
 * Cleans up export files older than three days old.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7911
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7912
 * The export files are stored in `wp-content/uploads`, and are therefore publicly
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7913
 * accessible. A CSPRN is appended to the filename to mitigate the risk of an
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7914
 * unauthorized person downloading the file, but it is still possible. Deleting
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7915
 * the file after the data subject has had a chance to delete it adds an additional
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7916
 * layer of protection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7917
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7918
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7919
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7920
function wp_privacy_delete_old_export_files() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7921
	$exports_dir = wp_privacy_exports_dir();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7922
	if ( ! is_dir( $exports_dir ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7923
		return;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7924
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7925
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  7926
	require_once ABSPATH . 'wp-admin/includes/file.php';
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  7927
	$export_files = list_files( $exports_dir, 100, array( 'index.php' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7928
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7929
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7930
	 * Filters the lifetime, in seconds, of a personal data export file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7931
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7932
	 * By default, the lifetime is 3 days. Once the file reaches that age, it will automatically
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7933
	 * be deleted by a cron job.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7934
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7935
	 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7936
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7937
	 * @param int $expiration The expiration age of the export, in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7938
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7939
	$expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7940
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7941
	foreach ( (array) $export_files as $export_file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7942
		$file_age_in_seconds = time() - filemtime( $export_file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7943
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7944
		if ( $expiration < $file_age_in_seconds ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7945
			unlink( $export_file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7946
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7947
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  7948
}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7949
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7950
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7951
 * Gets the URL to learn more about updating the PHP version the site is running on.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7952
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7953
 * This URL can be overridden by specifying an environment variable `WP_UPDATE_PHP_URL` or by using the
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7954
 * {@see 'wp_update_php_url'} filter. Providing an empty string is not allowed and will result in the
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7955
 * default URL being used. Furthermore the page the URL links to should preferably be localized in the
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7956
 * site language.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7957
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7958
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7959
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7960
 * @return string URL to learn more about updating PHP.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7961
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7962
function wp_get_update_php_url() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7963
	$default_url = wp_get_default_update_php_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7964
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7965
	$update_url = $default_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7966
	if ( false !== getenv( 'WP_UPDATE_PHP_URL' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7967
		$update_url = getenv( 'WP_UPDATE_PHP_URL' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7968
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7969
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7970
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7971
	 * Filters the URL to learn more about updating the PHP version the site is running on.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7972
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7973
	 * Providing an empty string is not allowed and will result in the default URL being used. Furthermore
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7974
	 * the page the URL links to should preferably be localized in the site language.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7975
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7976
	 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7977
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7978
	 * @param string $update_url URL to learn more about updating PHP.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7979
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7980
	$update_url = apply_filters( 'wp_update_php_url', $update_url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7981
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7982
	if ( empty( $update_url ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7983
		$update_url = $default_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7984
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7985
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7986
	return $update_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7987
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7988
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7989
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7990
 * Gets the default URL to learn more about updating the PHP version the site is running on.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7991
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7992
 * Do not use this function to retrieve this URL. Instead, use {@see wp_get_update_php_url()} when relying on the URL.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7993
 * This function does not allow modifying the returned URL, and is only used to compare the actually used URL with the
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7994
 * default one.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7995
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7996
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7997
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7998
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7999
 * @return string Default URL to learn more about updating PHP.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8000
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8001
function wp_get_default_update_php_url() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8002
	return _x( 'https://wordpress.org/support/update-php/', 'localized PHP upgrade information page' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8003
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8004
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8005
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8006
 * Prints the default annotation for the web host altering the "Update PHP" page URL.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8007
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8008
 * This function is to be used after {@see wp_get_update_php_url()} to display a consistent
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8009
 * annotation if the web host has altered the default "Update PHP" page URL.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8010
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8011
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8012
 * @since 5.2.0 Added the `$before` and `$after` parameters.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8013
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8014
 * @param string $before Markup to output before the annotation. Default `<p class="description">`.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8015
 * @param string $after  Markup to output after the annotation. Default `</p>`.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8016
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8017
function wp_update_php_annotation( $before = '<p class="description">', $after = '</p>' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8018
	$annotation = wp_get_update_php_annotation();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8019
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8020
	if ( $annotation ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8021
		echo $before . $annotation . $after;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8022
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8023
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8024
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8025
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8026
 * Returns the default annotation for the web hosting altering the "Update PHP" page URL.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8027
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8028
 * This function is to be used after {@see wp_get_update_php_url()} to return a consistent
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8029
 * annotation if the web host has altered the default "Update PHP" page URL.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8030
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8031
 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8032
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8033
 * @return string Update PHP page annotation. An empty string if no custom URLs are provided.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8034
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8035
function wp_get_update_php_annotation() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8036
	$update_url  = wp_get_update_php_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8037
	$default_url = wp_get_default_update_php_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8038
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8039
	if ( $update_url === $default_url ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8040
		return '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8041
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8042
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8043
	$annotation = sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8044
		/* translators: %s: Default Update PHP page URL. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8045
		__( 'This resource is provided by your web host, and is specific to your site. For more information, <a href="%s" target="_blank">see the official WordPress documentation</a>.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8046
		esc_url( $default_url )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8047
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8048
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8049
	return $annotation;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8050
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8051
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8052
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8053
 * Gets the URL for directly updating the PHP version the site is running on.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8054
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8055
 * A URL will only be returned if the `WP_DIRECT_UPDATE_PHP_URL` environment variable is specified or
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8056
 * by using the {@see 'wp_direct_php_update_url'} filter. This allows hosts to send users directly to
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8057
 * the page where they can update PHP to a newer version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8058
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8059
 * @since 5.1.1
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8060
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8061
 * @return string URL for directly updating PHP or empty string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8062
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8063
function wp_get_direct_php_update_url() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8064
	$direct_update_url = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8065
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8066
	if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8067
		$direct_update_url = getenv( 'WP_DIRECT_UPDATE_PHP_URL' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8068
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8069
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8070
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8071
	 * Filters the URL for directly updating the PHP version the site is running on from the host.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8072
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8073
	 * @since 5.1.1
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8074
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8075
	 * @param string $direct_update_url URL for directly updating PHP.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8076
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8077
	$direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8078
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8079
	return $direct_update_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8080
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8081
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8082
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8083
 * Display a button directly linking to a PHP update process.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8084
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8085
 * This provides hosts with a way for users to be sent directly to their PHP update process.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8086
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8087
 * The button is only displayed if a URL is returned by `wp_get_direct_php_update_url()`.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8088
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8089
 * @since 5.1.1
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8090
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8091
function wp_direct_php_update_button() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8092
	$direct_update_url = wp_get_direct_php_update_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8093
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8094
	if ( empty( $direct_update_url ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8095
		return;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8096
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8097
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8098
	echo '<p class="button-container">';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8099
	printf(
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8100
		'<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>',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8101
		esc_url( $direct_update_url ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8102
		__( 'Update PHP' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8103
		/* translators: Accessibility text. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8104
		__( '(opens in a new tab)' )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8105
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8106
	echo '</p>';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8107
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8108
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8109
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8110
 * Gets the URL to learn more about updating the site to use HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8111
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8112
 * This URL can be overridden by specifying an environment variable `WP_UPDATE_HTTPS_URL` or by using the
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8113
 * {@see 'wp_update_https_url'} filter. Providing an empty string is not allowed and will result in the
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8114
 * default URL being used. Furthermore the page the URL links to should preferably be localized in the
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8115
 * site language.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8116
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8117
 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8118
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8119
 * @return string URL to learn more about updating to HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8120
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8121
function wp_get_update_https_url() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8122
	$default_url = wp_get_default_update_https_url();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8123
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8124
	$update_url = $default_url;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8125
	if ( false !== getenv( 'WP_UPDATE_HTTPS_URL' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8126
		$update_url = getenv( 'WP_UPDATE_HTTPS_URL' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8127
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8128
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8129
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8130
	 * Filters the URL to learn more about updating the HTTPS version the site is running on.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8131
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8132
	 * Providing an empty string is not allowed and will result in the default URL being used. Furthermore
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8133
	 * the page the URL links to should preferably be localized in the site language.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8134
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8135
	 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8136
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8137
	 * @param string $update_url URL to learn more about updating HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8138
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8139
	$update_url = apply_filters( 'wp_update_https_url', $update_url );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8140
	if ( empty( $update_url ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8141
		$update_url = $default_url;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8142
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8143
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8144
	return $update_url;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8145
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8146
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8147
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8148
 * Gets the default URL to learn more about updating the site to use HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8149
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8150
 * Do not use this function to retrieve this URL. Instead, use {@see wp_get_update_https_url()} when relying on the URL.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8151
 * This function does not allow modifying the returned URL, and is only used to compare the actually used URL with the
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8152
 * default one.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8153
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8154
 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8155
 * @access private
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8156
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8157
 * @return string Default URL to learn more about updating to HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8158
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8159
function wp_get_default_update_https_url() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8160
	/* translators: Documentation explaining HTTPS and why it should be used. */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8161
	return __( 'https://wordpress.org/support/article/why-should-i-use-https/' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8162
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8163
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8164
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8165
 * Gets the URL for directly updating the site to use HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8166
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8167
 * A URL will only be returned if the `WP_DIRECT_UPDATE_HTTPS_URL` environment variable is specified or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8168
 * by using the {@see 'wp_direct_update_https_url'} filter. This allows hosts to send users directly to
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8169
 * the page where they can update their site to use HTTPS.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8170
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8171
 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8172
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8173
 * @return string URL for directly updating to HTTPS or empty string.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8174
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8175
function wp_get_direct_update_https_url() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8176
	$direct_update_url = '';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8177
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8178
	if ( false !== getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8179
		$direct_update_url = getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8180
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8181
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8182
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8183
	 * Filters the URL for directly updating the PHP version the site is running on from the host.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8184
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8185
	 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8186
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8187
	 * @param string $direct_update_url URL for directly updating PHP.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8188
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8189
	$direct_update_url = apply_filters( 'wp_direct_update_https_url', $direct_update_url );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8190
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8191
	return $direct_update_url;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8192
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8193
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8194
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8195
 * Get the size of a directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8196
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8197
 * A helper function that is used primarily to check whether
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8198
 * a blog has exceeded its allowed upload space.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8199
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8200
 * @since MU (3.0.0)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8201
 * @since 5.2.0 $max_execution_time parameter added.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8202
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8203
 * @param string $directory Full path of a directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8204
 * @param int    $max_execution_time Maximum time to run before giving up. In seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8205
 *                                   The timeout is global and is measured from the moment WordPress started to load.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8206
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8207
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8208
function get_dirsize( $directory, $max_execution_time = null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8209
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8210
	// Exclude individual site directories from the total when checking the main site of a network,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8211
	// as they are subdirectories and should not be counted.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8212
	if ( is_multisite() && is_main_site() ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8213
		$size = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8214
	} else {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8215
		$size = recurse_dirsize( $directory, null, $max_execution_time );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8216
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8217
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8218
	return $size;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8219
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8220
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8221
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8222
 * Get the size of a directory recursively.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8223
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8224
 * Used by get_dirsize() to get a directory size when it contains other directories.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8225
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8226
 * @since MU (3.0.0)
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8227
 * @since 4.3.0 The `$exclude` parameter was added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8228
 * @since 5.2.0 The `$max_execution_time` parameter was added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8229
 * @since 5.6.0 The `$directory_cache` parameter was added.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8230
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8231
 * @param string          $directory          Full path of a directory.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8232
 * @param string|string[] $exclude            Optional. Full path of a subdirectory to exclude from the total,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8233
 *                                            or array of paths. Expected without trailing slash(es).
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8234
 * @param int             $max_execution_time Optional. Maximum time to run before giving up. In seconds.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8235
 *                                            The timeout is global and is measured from the moment
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8236
 *                                            WordPress started to load.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8237
 * @param array           $directory_cache    Optional. Array of cached directory paths.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8238
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8239
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8240
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8241
function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null, &$directory_cache = null ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8242
	$directory  = untrailingslashit( $directory );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8243
	$save_cache = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8244
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8245
	if ( ! isset( $directory_cache ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8246
		$directory_cache = get_transient( 'dirsize_cache' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8247
		$save_cache      = true;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8248
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8249
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8250
	if ( isset( $directory_cache[ $directory ] ) && is_int( $directory_cache[ $directory ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8251
		return $directory_cache[ $directory ];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8252
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8253
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8254
	if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8255
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8256
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8257
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8258
	if (
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8259
		( is_string( $exclude ) && $directory === $exclude ) ||
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8260
		( is_array( $exclude ) && in_array( $directory, $exclude, true ) )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8261
	) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8262
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8263
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8264
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8265
	if ( null === $max_execution_time ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8266
		// Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8267
		if ( function_exists( 'ini_get' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8268
			$max_execution_time = ini_get( 'max_execution_time' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8269
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8270
			// Disable...
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8271
			$max_execution_time = 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8272
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8273
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8274
		// Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8275
		if ( $max_execution_time > 10 ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8276
			$max_execution_time -= 1;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8277
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8278
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8279
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8280
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8281
	 * Filters the amount of storage space used by one directory and all its children, in megabytes.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8282
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8283
	 * Return the actual used space to short-circuit the recursive PHP file size calculation
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8284
	 * and use something else, like a CDN API or native operating system tools for better performance.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8285
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8286
	 * @since 5.6.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8287
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8288
	 * @param int|false            $space_used         The amount of used space, in bytes. Default false.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8289
	 * @param string               $directory          Full path of a directory.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8290
	 * @param string|string[]|null $exclude            Full path of a subdirectory to exclude from the total,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8291
	 *                                                 or array of paths.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8292
	 * @param int                  $max_execution_time Maximum time to run before giving up. In seconds.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8293
	 * @param array                $directory_cache    Array of cached directory paths.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8294
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8295
	$size = apply_filters( 'pre_recurse_dirsize', false, $directory, $exclude, $max_execution_time, $directory_cache );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8296
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8297
	if ( false === $size ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8298
		$size = 0;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8299
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8300
		$handle = opendir( $directory );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8301
		if ( $handle ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8302
			while ( ( $file = readdir( $handle ) ) !== false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8303
				$path = $directory . '/' . $file;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8304
				if ( '.' !== $file && '..' !== $file ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8305
					if ( is_file( $path ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8306
						$size += filesize( $path );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8307
					} elseif ( is_dir( $path ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8308
						$handlesize = recurse_dirsize( $path, $exclude, $max_execution_time, $directory_cache );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8309
						if ( $handlesize > 0 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8310
							$size += $handlesize;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8311
						}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8312
					}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8313
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8314
					if ( $max_execution_time > 0 &&
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8315
						( microtime( true ) - WP_START_TIMESTAMP ) > $max_execution_time
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8316
					) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8317
						// Time exceeded. Give up instead of risking a fatal timeout.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8318
						$size = null;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8319
						break;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8320
					}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8321
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8322
			}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8323
			closedir( $handle );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8324
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8325
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8326
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8327
	if ( ! is_array( $directory_cache ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8328
		$directory_cache = array();
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8329
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8330
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8331
	$directory_cache[ $directory ] = $size;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8332
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8333
	// Only write the transient on the top level call and not on recursive calls.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8334
	if ( $save_cache ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8335
		set_transient( 'dirsize_cache', $directory_cache );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8336
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8337
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8338
	return $size;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8339
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8340
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8341
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8342
 * Cleans directory size cache used by recurse_dirsize().
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8343
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8344
 * Removes the current directory and all parent directories from the `dirsize_cache` transient.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8345
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8346
 * @since 5.6.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8347
 * @since 5.9.0 Added input validation with a notice for invalid input.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8348
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8349
 * @param string $path Full path of a directory or file.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8350
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8351
function clean_dirsize_cache( $path ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8352
	if ( ! is_string( $path ) || empty( $path ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8353
		trigger_error(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8354
			sprintf(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8355
				/* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8356
				__( '%1$s only accepts a non-empty path string, received %2$s.' ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8357
				'<code>clean_dirsize_cache()</code>',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8358
				'<code>' . gettype( $path ) . '</code>'
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8359
			)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8360
		);
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8361
		return;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8362
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8363
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8364
	$directory_cache = get_transient( 'dirsize_cache' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8365
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8366
	if ( empty( $directory_cache ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8367
		return;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8368
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8369
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8370
	if (
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8371
		strpos( $path, '/' ) === false &&
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8372
		strpos( $path, '\\' ) === false
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8373
	) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8374
		unset( $directory_cache[ $path ] );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8375
		set_transient( 'dirsize_cache', $directory_cache );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8376
		return;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8377
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8378
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8379
	$last_path = null;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8380
	$path      = untrailingslashit( $path );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8381
	unset( $directory_cache[ $path ] );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8382
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8383
	while (
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8384
		$last_path !== $path &&
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8385
		DIRECTORY_SEPARATOR !== $path &&
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8386
		'.' !== $path &&
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8387
		'..' !== $path
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8388
	) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8389
		$last_path = $path;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8390
		$path      = dirname( $path );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8391
		unset( $directory_cache[ $path ] );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8392
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8393
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8394
	set_transient( 'dirsize_cache', $directory_cache );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8395
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8396
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  8397
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8398
 * Checks compatibility with the current WordPress version.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8399
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8400
 * @since 5.2.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8401
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8402
 * @global string $wp_version The WordPress version string.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8403
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8404
 * @param string $required Minimum required WordPress version.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8405
 * @return bool True if required version is compatible or empty, false if not.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8406
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8407
function is_wp_version_compatible( $required ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8408
	global $wp_version;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8409
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8410
	// Strip off any -alpha, -RC, -beta, -src suffixes.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8411
	list( $version ) = explode( '-', $wp_version );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8412
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8413
	return empty( $required ) || version_compare( $version, $required, '>=' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8414
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8415
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8416
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8417
 * Checks compatibility with the current PHP version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8418
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8419
 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8420
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8421
 * @param string $required Minimum required PHP version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8422
 * @return bool True if required version is compatible or empty, false if not.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8423
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8424
function is_php_version_compatible( $required ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8425
	return empty( $required ) || version_compare( phpversion(), $required, '>=' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  8426
}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8427
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8428
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8429
 * Checks if two numbers are nearly the same.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8430
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8431
 * This is similar to using `round()` but the precision is more fine-grained.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8432
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8433
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8434
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8435
 * @param int|float $expected  The expected value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8436
 * @param int|float $actual    The actual number.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8437
 * @param int|float $precision The allowed variation.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8438
 * @return bool Whether the numbers match within the specified precision.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8439
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8440
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8441
	return abs( (float) $expected - (float) $actual ) <= $precision;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
  8442
}
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8443
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8444
/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8445
 * Sorts the keys of an array alphabetically.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8446
 * The array is passed by reference so it doesn't get returned
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8447
 * which mimics the behaviour of ksort.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8448
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8449
 * @since 6.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8450
 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8451
 * @param array $array The array to sort, passed by reference.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8452
 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8453
function wp_recursive_ksort( &$array ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8454
	foreach ( $array as &$value ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8455
		if ( is_array( $value ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8456
			wp_recursive_ksort( $value );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8457
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8458
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8459
	ksort( $array );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  8460
}