wp/wp-includes/functions.php
author ymh <ymh.work@gmail.com>
Tue, 15 Oct 2019 15:48:13 +0200
changeset 13 d255fe9cd479
parent 9 177826044cd9
child 16 a86126ab1dd4
permissions -rw-r--r--
Upgrade wordpress again
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
require( ABSPATH . WPINC . '/option.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
 * Convert given date string into a different format.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * $format should be either a PHP date format string, e.g. 'U' for a Unix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * If $translate is true then the given date and format string will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * be passed to date_i18n() for translation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @param string $format    Format of the date to return.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 * @param string $date      Date string to convert.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
 * @param bool   $translate Whether the return date should be translated. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
 * @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
function mysql2date( $format, $date, $translate = true ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    27
	if ( empty( $date ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    29
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    30
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    31
	if ( 'G' == $format ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		return strtotime( $date . ' +0000' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    33
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	$i = strtotime( $date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    37
	if ( 'U' == $format ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		return $i;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    39
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    40
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    41
	if ( $translate ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		return date_i18n( $format, $i );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    43
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		return date( $format, $i );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    45
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * Retrieve the current time based on specified type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
 * The 'mysql' type will return the time in the format for MySQL DATETIME field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 * The 'timestamp' type will return the current timestamp.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
 * Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 * If $gmt is set to either '1' or 'true', then both types will use GMT time.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
 * @param string   $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
 *                       format string (e.g. 'Y-m-d').
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
 * @param int|bool $gmt  Optional. Whether to use GMT timezone. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
 * @return int|string Integer if $type is 'timestamp', string otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
function current_time( $type, $gmt = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	switch ( $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		case 'mysql':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
			return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		case 'timestamp':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
			return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
		default:
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    72
			return ( $gmt ) ? gmdate( $type ) : gmdate( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    73
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    74
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    75
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    76
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    77
 * Retrieve the date in localized format, based on a sum of Unix timestamp and
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    78
 * timezone offset in seconds.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 * If the locale specifies the locale month and weekday, then the locale will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 * 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
    82
 * will be used instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    86
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    87
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    88
 * @param string   $dateformatstring      Format to display the date.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    89
 * @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset in seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    90
 *                                        Default false.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    91
 * @param bool     $gmt                   Optional. Whether to use GMT timezone. Only applies if timestamp is
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    92
 *                                        not provided. Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
 * @return string The date, translated if locale specifies it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    96
function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	global $wp_locale;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    98
	$i = $timestamp_with_offset;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	if ( false === $i ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
		$i = current_time( 'timestamp', $gmt );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
	 * Store original value for language with untypical grammars.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	 * See https://core.trac.wordpress.org/ticket/9396
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	$req_format = $dateformatstring;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   110
	$dateformatstring = preg_replace( '/(?<!\\\\)c/', DATE_W3C, $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   111
	$dateformatstring = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   112
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   113
	if ( ( ! empty( $wp_locale->month ) ) && ( ! empty( $wp_locale->weekday ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   114
		$datemonth            = $wp_locale->get_month( date( 'm', $i ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   115
		$datemonth_abbrev     = $wp_locale->get_month_abbrev( $datemonth );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   116
		$dateweekday          = $wp_locale->get_weekday( date( 'w', $i ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   117
		$dateweekday_abbrev   = $wp_locale->get_weekday_abbrev( $dateweekday );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   118
		$datemeridiem         = $wp_locale->get_meridiem( date( 'a', $i ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   119
		$datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   120
		$dateformatstring     = ' ' . $dateformatstring;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   121
		$dateformatstring     = preg_replace( '/([^\\\])D/', "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   122
		$dateformatstring     = preg_replace( '/([^\\\])F/', "\\1" . backslashit( $datemonth ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   123
		$dateformatstring     = preg_replace( '/([^\\\])l/', "\\1" . backslashit( $dateweekday ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   124
		$dateformatstring     = preg_replace( '/([^\\\])M/', "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   125
		$dateformatstring     = preg_replace( '/([^\\\])a/', "\\1" . backslashit( $datemeridiem ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   126
		$dateformatstring     = preg_replace( '/([^\\\])A/', "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   127
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   128
		$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   129
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   130
	$timezone_formats    = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	$timezone_formats_re = implode( '|', $timezone_formats );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		$timezone_string = get_option( 'timezone_string' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   134
		if ( false === $timestamp_with_offset && $gmt ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   135
			$timezone_string = 'UTC';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   136
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
		if ( $timezone_string ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
			$timezone_object = timezone_open( $timezone_string );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   139
			$date_object     = date_create( null, $timezone_object );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   140
			foreach ( $timezone_formats as $timezone_format ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
				if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   142
					$formatted        = date_format( $date_object, $timezone_format );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   143
					$dateformatstring = ' ' . $dateformatstring;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
					$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   145
					$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   146
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   147
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   148
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   149
			$offset = get_option( 'gmt_offset' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   150
			foreach ( $timezone_formats as $timezone_format ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   151
				if ( 'I' === $timezone_format ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   152
					continue;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   153
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   154
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   155
				if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   156
					if ( 'Z' === $timezone_format ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   157
						$formatted = (string) ( $offset * HOUR_IN_SECONDS );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   158
					} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   159
						$prefix    = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   160
						$hours     = (int) $offset;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   161
						$separator = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   162
						$minutes   = abs( ( $offset - $hours ) * 60 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   163
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   164
						if ( 'T' === $timezone_format ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   165
							$prefix = 'GMT';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   166
						} elseif ( 'e' === $timezone_format || 'P' === $timezone_format ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   167
							$separator = ':';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   168
						}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   169
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   170
						$formatted = sprintf( '%s%+03d%s%02d', $prefix, $hours, $separator, $minutes );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   171
					}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   172
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   173
					$dateformatstring = ' ' . $dateformatstring;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   174
					$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   175
					$dateformatstring = substr( $dateformatstring, 1 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
	$j = @date( $dateformatstring, $i );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
	 * Filters the date formatted based on the locale.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	 * @param string $j          Formatted date string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
	 * @param string $req_format Format to display the date.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   189
	 * @param int    $i          A sum of Unix timestamp and timezone offset in seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   190
	 * @param bool   $gmt        Whether to use GMT timezone. Only applies if timestamp was
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   191
	 *                           not provided. Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
	$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	return $j;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
 * Determines if the date should be declined.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
 * 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
   201
 * 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
   202
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   207
 * @param string $date Formatted date string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
 * @return string The date, declined if locale specifies it.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   209
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   210
function wp_maybe_decline_date( $date ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
	global $wp_locale;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   213
	// i18n functions are not available in SHORTINIT mode
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
	if ( ! function_exists( '_x' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
		return $date;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
	/* translators: If months in your language require a genitive case,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   219
	 * 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
   220
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   221
	if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   222
		// Match a format like 'j F Y' or 'j. F'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
		if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   224
			$months          = $wp_locale->month;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
			$months_genitive = $wp_locale->month_genitive;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   227
			foreach ( $months as $key => $month ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
				$months[ $key ] = '# ' . $month . '( |$)#u';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   230
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   231
			foreach ( $months_genitive as $key => $month ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
				$months_genitive[ $key ] = ' ' . $month . '$1';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   234
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   235
			$date = preg_replace( $months, $months_genitive, $date );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   236
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   239
	// Used for locale-specific rules
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   240
	$locale = get_locale();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   241
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   242
	if ( 'ca' === $locale ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   243
		// " 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
   244
		$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   245
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   246
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   247
	return $date;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   248
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   249
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   250
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
 * Convert float number to format based on the locale.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   256
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
 * @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
   258
 * @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
   259
 * @return string Converted number in string format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
function number_format_i18n( $number, $decimals = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	global $wp_locale;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   263
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   264
	if ( isset( $wp_locale ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   265
		$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
   266
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
		$formatted = number_format( $number, absint( $decimals ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
	 * Filters the number formatted based on the locale.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   273
	 * @since 2.8.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   274
	 * @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
   275
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
	 * @param string $formatted Converted number in string format.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   277
	 * @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
   278
	 * @param int    $decimals  Precision of the number of decimal places.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   280
	return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * Convert number of bytes largest unit bytes will fit into.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   286
 * 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
   287
 * number of bytes to human readable number by taking the number of that unit
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
 * that the bytes will go into it. Supports TB value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
 * 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
   291
 * 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
   292
 * 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
   293
 * be converted to a double, which should always have 64 bit length.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * Technically the correct unit names for powers of 1024 are KiB, MiB etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
 * @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
   300
 * @param int        $decimals Optional. Precision of number of decimal places. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
 * @return string|false False on failure. Number string on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
function size_format( $bytes, $decimals = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	$quant = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   305
		'TB' => TB_IN_BYTES,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
		'GB' => GB_IN_BYTES,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
		'MB' => MB_IN_BYTES,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   308
		'KB' => KB_IN_BYTES,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   309
		'B'  => 1,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   312
	if ( 0 === $bytes ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   313
		return number_format_i18n( 0, $decimals ) . ' B';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
	foreach ( $quant as $unit => $mag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
		if ( doubleval( $bytes ) >= $mag ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
			return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   326
 * Convert a duration to human readable format.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   327
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   328
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   329
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   330
 * @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
   331
 *                         with a possible prepended negative sign (-).
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   332
 * @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
   333
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   334
function human_readable_duration( $duration = '' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   335
	if ( ( empty( $duration ) || ! is_string( $duration ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   336
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   337
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   338
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   339
	$duration = trim( $duration );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   340
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   341
	// Remove prepended negative sign.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   342
	if ( '-' === substr( $duration, 0, 1 ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   343
		$duration = substr( $duration, 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   344
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   345
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   346
	// Extract duration parts.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   347
	$duration_parts = array_reverse( explode( ':', $duration ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   348
	$duration_count = count( $duration_parts );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   349
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   350
	$hour   = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   351
	$minute = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   352
	$second = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   353
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   354
	if ( 3 === $duration_count ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   355
		// Validate HH:ii:ss duration format.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   356
		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
   357
			return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   358
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   359
		// Three parts: hours, minutes & seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   360
		list( $second, $minute, $hour ) = $duration_parts;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   361
	} elseif ( 2 === $duration_count ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   362
		// Validate ii:ss duration format.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   363
		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
   364
			return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   365
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   366
		// Two parts: minutes & seconds.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   367
		list( $second, $minute ) = $duration_parts;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   368
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   369
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   370
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   371
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   372
	$human_readable_duration = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   373
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   374
	// Add the hour part to the string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   375
	if ( is_numeric( $hour ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   376
		/* translators: Time duration in hour or hours. */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   377
		$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
   378
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   379
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   380
	// Add the minute part to the string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   381
	if ( is_numeric( $minute ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   382
		/* translators: Time duration in minute or minutes. */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   383
		$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
   384
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   385
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   386
	// Add the second part to the string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   387
	if ( is_numeric( $second ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   388
		/* translators: Time duration in second or seconds. */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   389
		$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
   390
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   391
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   392
	return implode( ', ', $human_readable_duration );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   393
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   394
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   395
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
 * 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
   397
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
 * @param string     $mysqlstring   Date or datetime field type from MySQL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
 * @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 * @return array Keys are 'start' and 'end'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
	// MySQL string year.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
	$my = substr( $mysqlstring, 0, 4 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
	// MySQL string month.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
	$mm = substr( $mysqlstring, 8, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	// MySQL string day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	$md = substr( $mysqlstring, 5, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	// The timestamp for MySQL string day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	$day = mktime( 0, 0, 0, $md, $mm, $my );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
	// The day of the week from the timestamp.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
	$weekday = date( 'w', $day );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   420
	if ( ! is_numeric( $start_of_week ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		$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
   422
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   423
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   424
	if ( $weekday < $start_of_week ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		$weekday += 7;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   426
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	// The most recent week start day on or before $day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
	$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
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
	// $start + 1 week - 1 second.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   432
	$end = $start + WEEK_IN_SECONDS - 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	return compact( 'start', 'end' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
 * Unserialize value only if it was serialized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
 * @param string $original Maybe unserialized original, if is needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
 * @return mixed Unserialized data can be any type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
function maybe_unserialize( $original ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   445
	if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		return @unserialize( $original );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   447
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	return $original;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
 * Check value to find if it was serialized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
 * If $data is not an string, then returned value will always be false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
 * Serialized data is always a string.
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.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
 * @param string $data   Value to check to see if was serialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
 * @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
   461
 * @return bool False if not serialized and true if it was.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
function is_serialized( $data, $strict = true ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
	// if it isn't a string, it isn't serialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
	if ( ! is_string( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	$data = trim( $data );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   469
	if ( 'N;' == $data ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
	if ( strlen( $data ) < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
	if ( ':' !== $data[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	if ( $strict ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
		$lastc = substr( $data, -1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
		if ( ';' !== $lastc && '}' !== $lastc ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
		$semicolon = strpos( $data, ';' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		$brace     = strpos( $data, '}' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
		// Either ; or } must exist.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   487
		if ( false === $semicolon && false === $brace ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   489
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
		// 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
   491
		if ( false !== $semicolon && $semicolon < 3 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   493
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   494
		if ( false !== $brace && $brace < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   496
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	$token = $data[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	switch ( $token ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   500
		case 's':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
			if ( $strict ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
				if ( '"' !== substr( $data, -2, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
					return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
			} elseif ( false === strpos( $data, '"' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			// or else fall through
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   509
		case 'a':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   510
		case 'O':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
			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
   512
		case 'b':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   513
		case 'i':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   514
		case 'd':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
			$end = $strict ? '$' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
			return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
 * Check whether serialized data is of string type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
 * @param string $data Serialized data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
 * @return bool False if not a serialized string, true if it is.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
function is_serialized_string( $data ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
	// 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
   531
	if ( ! is_string( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	$data = trim( $data );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
	if ( strlen( $data ) < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	} elseif ( ':' !== $data[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
	} elseif ( ';' !== substr( $data, -1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
	} elseif ( $data[0] !== 's' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
	} elseif ( '"' !== substr( $data, -2, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
 * Serialize data, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
 * @param string|array|object $data Data that might be serialized.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
 * @return mixed A scalar data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
function maybe_serialize( $data ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   559
	if ( is_array( $data ) || is_object( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		return serialize( $data );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   561
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	// Double serialization is required for backward compatibility.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
	// See https://core.trac.wordpress.org/ticket/12930
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   565
	// Also the world will end. See WP 3.6.1.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   566
	if ( is_serialized( $data, false ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		return serialize( $data );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   568
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
 * Retrieve post title from XMLRPC XML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
 * 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
   577
 * the $post_default_title will be used instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
 * @global string $post_default_title Default XML-RPC post title.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
 * @param string $content XMLRPC XML Request content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
 * @return string Post title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
function xmlrpc_getposttitle( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	global $post_default_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
		$post_title = $matchtitle[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
		$post_title = $post_default_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	return $post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
 * Retrieve the post category or categories from XMLRPC XML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
 * 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
   600
 * used. The return type then would be what $post_default_category. If the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
 * category is found, then it will always be an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
 * @global string $post_default_category Default XML-RPC post category.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
 * @param string $content XMLRPC XML Request content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
 * @return string|array List of categories or category name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
function xmlrpc_getpostcategory( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	global $post_default_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
		$post_category = trim( $matchcat[1], ',' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
		$post_category = explode( ',', $post_category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		$post_category = $post_default_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	return $post_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 * XMLRPC XML content without title and category elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   626
 * @param string $content XML-RPC XML Request content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
 * @return string XMLRPC XML Request content without title and category elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
function xmlrpc_removepostdata( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	$content = trim( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
 * Use RegEx to extract URLs from arbitrary content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   641
 * @param string $content Content to extract URLs from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
 * @return array URLs found in passed string.
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
function wp_extract_urls( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	preg_match_all(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
		"#([\"']?)("
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   647
			. '(?:([\w-]+:)?//?)'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   648
			. '[^\s()<>]+'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   649
			. '[.]'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   650
			. '(?:'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   651
				. '\([\w\d]+\)|'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   652
				. '(?:'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
					. "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|"
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   654
					. '(?:[:]\d+)?/?'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   655
				. ')+'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   656
			. ')'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   657
		. ")\\1#",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
		$content,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
		$post_links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   662
	$post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	return array_values( $post_links );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 * Check content for video and audio links to add as enclosures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
 * Will not add enclosures that have already been added and will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
 * remove enclosures that are no longer in the post. This is called as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
 * pingbacks and trackbacks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   676
 * @global wpdb $wpdb WordPress database abstraction object.
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
 * @param string $content Post Content.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   679
 * @param int    $post_ID Post ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
function do_enclose( $content, $post_ID ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	//TODO: Tidy this ghetto code up and make the debug code optional
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	include_once( ABSPATH . WPINC . '/class-IXR.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	$post_links = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	$pung = get_enclosed( $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	$post_links_temp = wp_extract_urls( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
	foreach ( $pung as $link_test ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
		if ( ! in_array( $link_test, $post_links_temp ) ) { // link no longer in post
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   695
			$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 ) . '%' ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   696
			foreach ( $mids as $mid ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
				delete_metadata_by_mid( 'post', $mid );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   698
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
	foreach ( (array) $post_links_temp as $link_test ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   703
		if ( ! in_array( $link_test, $pung ) ) { // If we haven't pung it already
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
			$test = @parse_url( $link_test );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   705
			if ( false === $test ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
				continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   707
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   708
			if ( isset( $test['query'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
				$post_links[] = $link_test;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   710
			} elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
				$post_links[] = $link_test;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   712
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   716
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   717
	 * 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
   718
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   719
	 * 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
   720
	 * to postmeta before checking the database for existing enclosures.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   722
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   723
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   724
	 * @param array $post_links An array of enclosure links.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   725
	 * @param int   $post_ID    Post ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   726
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   727
	$post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   728
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	foreach ( (array) $post_links as $url ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   730
		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 ) . '%' ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   731
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   732
			if ( $headers = wp_get_http_headers( $url ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   733
				$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
   734
				$type          = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
				$allowed_types = array( 'video', 'audio' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
				// Check to see if we can figure out the mime type from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
				// the extension
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
				$url_parts = @parse_url( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
				if ( false !== $url_parts ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
					$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   742
					if ( ! empty( $extension ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
						foreach ( wp_get_mime_types() as $exts => $mime ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
							if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
								$type = $mime;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
								break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   752
				if ( in_array( substr( $type, 0, strpos( $type, '/' ) ), $allowed_types ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
					add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
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
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 * Retrieve HTTP Headers from URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
 * @since 1.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   765
 * @param string $url        URL to retrieve HTTP headers from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
 * @param bool   $deprecated Not Used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
 * @return bool|string False on failure, headers on success.
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 wp_get_http_headers( $url, $deprecated = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   770
	if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   771
		_deprecated_argument( __FUNCTION__, '2.7.0' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   772
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
	$response = wp_safe_remote_head( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   776
	if ( is_wp_error( $response ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   778
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
	return wp_remote_retrieve_headers( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   784
 * 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
   785
 * 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
   786
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   787
 * 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
   788
 * 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
   789
 * Conditional Tags} article in the Theme Developer Handbook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
 * @since 0.71
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
 * @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
   794
 * @global string $previousday The day of the previous post in the loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
 * @return int 1 when new day, 0 if not a new day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
function is_new_day() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	global $currentday, $previousday;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   800
	if ( $currentday != $previousday ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
		return 1;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   802
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		return 0;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   804
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 * Build URL query based on an associative and, or indexed array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 * This is a convenient function for easily building url queries. It sets the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
 * separator to '&' and uses _http_build_query() function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   814
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
 * @see _http_build_query() Used to build the query
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   816
 * @link https://secure.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
   817
 *       http_build_query() does.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
 * @param array $data URL-encode key/value pairs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
 * @return string URL-encoded string.
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
function build_query( $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
	return _http_build_query( $data, null, '&', '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
 * 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
   828
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
 * @since 3.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   832
 * @see https://secure.php.net/manual/en/function.http-build-query.php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
 * @param array|object  $data       An array or object of data. Converted to array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
 * @param string        $prefix     Optional. Numeric index. If set, start parameter numbering with it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
 *                                  Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
 * @param string        $sep        Optional. Argument separator; defaults to 'arg_separator.output'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
 *                                  Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
 * @param string        $key        Optional. Used to prefix key name. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
 * @param bool          $urlencode  Optional. Whether to use urlencode() in the result. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
 * @return string The query string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   843
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   844
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
	$ret = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
	foreach ( (array) $data as $k => $v ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   848
		if ( $urlencode ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   849
			$k = urlencode( $k );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   850
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   851
		if ( is_int( $k ) && $prefix != null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   852
			$k = $prefix . $k;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   853
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   854
		if ( ! empty( $key ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
			$k = $key . '%5B' . $k . '%5D';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   856
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   857
		if ( $v === null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   859
		} elseif ( $v === false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
			$v = '0';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   861
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   862
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   863
		if ( is_array( $v ) || is_object( $v ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   864
			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
   865
		} elseif ( $urlencode ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   866
			array_push( $ret, $k . '=' . urlencode( $v ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   867
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   868
			array_push( $ret, $k . '=' . $v );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   869
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   870
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   871
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   872
	if ( null === $sep ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   873
		$sep = ini_get( 'arg_separator.output' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   874
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   875
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   876
	return implode( $sep, $ret );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   880
 * Retrieves a modified URL query string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   881
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   882
 * 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
   883
 * 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
   884
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   885
 * Using a single key and value:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   886
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   887
 *     add_query_arg( 'key', 'value', 'http://example.com' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   888
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   889
 * Using an associative array:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   890
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   891
 *     add_query_arg( array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   892
 *         'key1' => 'value1',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   893
 *         'key2' => 'value2',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   894
 *     ), 'http://example.com' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   895
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   896
 * 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
   897
 * (the value of `$_SERVER['REQUEST_URI']`).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   898
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   899
 * 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
   900
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   901
 * 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
   902
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   903
 * 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
   904
 * 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
   905
 * (XSS) attacks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   909
 * @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
   910
 * @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
   911
 * @param string       $url   Optional. A URL to act upon.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   912
 * @return string New URL query string (unescaped).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
function add_query_arg() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
	$args = func_get_args();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
	if ( is_array( $args[0] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   917
		if ( count( $args ) < 2 || false === $args[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
			$uri = $_SERVER['REQUEST_URI'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   919
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
			$uri = $args[1];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   921
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   923
		if ( count( $args ) < 3 || false === $args[2] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
			$uri = $_SERVER['REQUEST_URI'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   925
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
			$uri = $args[2];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   927
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   928
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   929
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   930
	if ( $frag = strstr( $uri, '#' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		$uri = substr( $uri, 0, -strlen( $frag ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   932
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		$frag = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   934
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
	if ( 0 === stripos( $uri, 'http://' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
		$protocol = 'http://';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   938
		$uri      = substr( $uri, 7 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
	} elseif ( 0 === stripos( $uri, 'https://' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
		$protocol = 'https://';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   941
		$uri      = substr( $uri, 8 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		$protocol = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	if ( strpos( $uri, '?' ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		list( $base, $query ) = explode( '?', $uri, 2 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   948
		$base                .= '?';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   950
		$base  = $uri . '?';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
		$query = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   953
		$base  = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
		$query = $uri;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
	wp_parse_str( $query, $qs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
	$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	if ( is_array( $args[0] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
		foreach ( $args[0] as $k => $v ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
			$qs[ $k ] = $v;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
		$qs[ $args[0] ] = $args[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	foreach ( $qs as $k => $v ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   968
		if ( $v === false ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   969
			unset( $qs[ $k ] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   970
		}
0
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
	$ret = build_query( $qs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
	$ret = trim( $ret, '?' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
	$ret = preg_replace( '#=(&|$)#', '$1', $ret );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	$ret = $protocol . $base . $ret . $frag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
	$ret = rtrim( $ret, '?' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
	return $ret;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   982
 * Removes an item or items from a query string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
 * @param string|array $key   Query key or keys to remove.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   987
 * @param bool|string  $query Optional. When false uses the current URL. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
 * @return string New URL query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
function remove_query_arg( $key, $query = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
	if ( is_array( $key ) ) { // removing multiple keys
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   992
		foreach ( $key as $k ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
			$query = add_query_arg( $k, false, $query );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   994
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
		return $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
	return add_query_arg( $key, false, $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1001
 * 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
  1002
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1003
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1004
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1005
 * @return array An array of parameters to remove from the URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1006
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1007
function wp_removable_query_args() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1008
	$removable_query_args = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1009
		'activate',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1010
		'activated',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1011
		'approved',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1012
		'deactivate',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1013
		'deleted',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1014
		'disabled',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1015
		'enabled',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1016
		'error',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1017
		'hotkeys_highlight_first',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1018
		'hotkeys_highlight_last',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1019
		'locked',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1020
		'message',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1021
		'same',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1022
		'saved',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1023
		'settings-updated',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1024
		'skipped',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1025
		'spammed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1026
		'trashed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1027
		'unspammed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1028
		'untrashed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1029
		'update',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1030
		'updated',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1031
		'wp-post-new-reload',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1032
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1033
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1034
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1035
	 * Filters the list of query variables to remove.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1036
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1037
	 * @since 4.2.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1038
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1039
	 * @param array $removable_query_args An array of query variables to remove from a URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1040
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1041
	return apply_filters( 'removable_query_args', $removable_query_args );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1042
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1043
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1044
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
 * Walks the array while sanitizing the contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
 * @param array $array Array to walk while sanitizing contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
 * @return array Sanitized $array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
function add_magic_quotes( $array ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
	foreach ( (array) $array as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
		if ( is_array( $v ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1055
			$array[ $k ] = add_magic_quotes( $v );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
		} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1057
			$array[ $k ] = addslashes( $v );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
	return $array;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
 * HTTP request for URI to retrieve content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
 * @since 1.5.1
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1068
 * @see wp_safe_remote_get()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
 * @param string $uri URI/URL of web page to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
 * @return false|string HTTP content. False on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
function wp_remote_fopen( $uri ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
	$parsed_url = @parse_url( $uri );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1076
	if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1078
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1079
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1080
	$options            = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
	$options['timeout'] = 10;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	$response = wp_safe_remote_get( $uri, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1085
	if ( is_wp_error( $response ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1087
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
	return wp_remote_retrieve_body( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
 * Set up the WordPress query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
 * @global WP       $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
 * @global WP_Query $wp_query
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
 * @global WP_Query $wp_the_query
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1101
 * @param string|array $query_vars Default WP_Query arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
function wp( $query_vars = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	global $wp, $wp_query, $wp_the_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
	$wp->main( $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1107
	if ( ! isset( $wp_the_query ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
		$wp_the_query = $wp_query;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1109
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
 * Retrieve the description for the HTTP status.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
 * @since 2.3.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1116
 * @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
  1117
 * @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
  1118
 * @since 5.1.0 Added status code 103.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
 * @global array $wp_header_to_desc
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1121
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
 * @param int $code HTTP status code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
 * @return string Empty string if not found, or description if found.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
function get_status_header_desc( $code ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
	global $wp_header_to_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	$code = absint( $code );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1130
	if ( ! isset( $wp_header_to_desc ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
		$wp_header_to_desc = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
			100 => 'Continue',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
			101 => 'Switching Protocols',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
			102 => 'Processing',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1135
			103 => 'Early Hints',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
			200 => 'OK',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
			201 => 'Created',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
			202 => 'Accepted',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
			203 => 'Non-Authoritative Information',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
			204 => 'No Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
			205 => 'Reset Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
			206 => 'Partial Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
			207 => 'Multi-Status',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
			226 => 'IM Used',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
			300 => 'Multiple Choices',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
			301 => 'Moved Permanently',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
			302 => 'Found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
			303 => 'See Other',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
			304 => 'Not Modified',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
			305 => 'Use Proxy',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
			306 => 'Reserved',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
			307 => 'Temporary Redirect',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1155
			308 => 'Permanent Redirect',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
			400 => 'Bad Request',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
			401 => 'Unauthorized',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
			402 => 'Payment Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
			403 => 'Forbidden',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
			404 => 'Not Found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
			405 => 'Method Not Allowed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
			406 => 'Not Acceptable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
			407 => 'Proxy Authentication Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
			408 => 'Request Timeout',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
			409 => 'Conflict',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
			410 => 'Gone',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
			411 => 'Length Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
			412 => 'Precondition Failed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
			413 => 'Request Entity Too Large',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
			414 => 'Request-URI Too Long',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
			415 => 'Unsupported Media Type',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
			416 => 'Requested Range Not Satisfiable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
			417 => 'Expectation Failed',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
			418 => 'I\'m a teapot',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1176
			421 => 'Misdirected Request',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
			422 => 'Unprocessable Entity',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
			423 => 'Locked',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
			424 => 'Failed Dependency',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
			426 => 'Upgrade Required',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
			428 => 'Precondition Required',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
			429 => 'Too Many Requests',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
			431 => 'Request Header Fields Too Large',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1184
			451 => 'Unavailable For Legal Reasons',
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
			500 => 'Internal Server Error',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
			501 => 'Not Implemented',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
			502 => 'Bad Gateway',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
			503 => 'Service Unavailable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
			504 => 'Gateway Timeout',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
			505 => 'HTTP Version Not Supported',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
			506 => 'Variant Also Negotiates',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
			507 => 'Insufficient Storage',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1194
			510 => 'Not Extended',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1195
			511 => 'Network Authentication Required',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1199
	if ( isset( $wp_header_to_desc[ $code ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1200
		return $wp_header_to_desc[ $code ];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1201
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1203
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
 * Set HTTP status header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1210
 * @since 4.4.0 Added the `$description` parameter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
 * @see get_status_header_desc()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1214
 * @param int    $code        HTTP status code.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1215
 * @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
  1216
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1217
function status_header( $code, $description = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1218
	if ( ! $description ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1219
		$description = get_status_header_desc( $code );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1220
	}
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
	if ( empty( $description ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
		return;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1224
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1225
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1226
	$protocol      = wp_get_server_protocol();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
	$status_header = "$protocol $code $description";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1228
	if ( function_exists( 'apply_filters' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1231
		 * Filters an HTTP status header.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
		 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
		 * @param string $status_header HTTP status header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
		 * @param int    $code          HTTP status code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
		 * @param string $description   Description for the status code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
		 * @param string $protocol      Server protocol.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1240
		$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
  1241
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1242
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
	@header( $status_header, true, $code );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1247
 * Get the header information to prevent caching.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1248
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1249
 * The several different headers cover the different ways cache prevention
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1250
 * is handled by different browsers
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
 * @return array The associative array of header names and field values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
function wp_get_nocache_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
	$headers = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1258
		'Expires'       => 'Wed, 11 Jan 1984 05:00:00 GMT',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
		'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1262
	if ( function_exists( 'apply_filters' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1264
		 * Filters the cache-controlling headers.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1265
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1266
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
		 * @see wp_get_nocache_headers()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
		 * @param array $headers {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
		 *     Header names and field values.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1272
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1273
		 *     @type string $Expires       Expires header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
		 *     @type string $Cache-Control Cache-Control header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1275
		 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1276
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1277
		$headers = (array) apply_filters( 'nocache_headers', $headers );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
	$headers['Last-Modified'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
	return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1284
 * Set the headers to prevent caching for the different browsers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1286
 * Different browsers support different nocache headers, so several
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1287
 * 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
  1288
 * caching should occur.
0
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 2.0.0
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_get_nocache_headers()
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
function nocache_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
	$headers = wp_get_nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
	unset( $headers['Last-Modified'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
	// In PHP 5.3+, make sure we are not sending a Last-Modified header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
	if ( function_exists( 'header_remove' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
		@header_remove( 'Last-Modified' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		// In PHP 5.2, send an empty Last-Modified header, but only as a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
		// last resort to override a header already sent. #WP23021
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
		foreach ( headers_list() as $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
			if ( 0 === stripos( $header, 'Last-Modified' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
				$headers['Last-Modified'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1313
	foreach ( $headers as $name => $field_value ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1314
		@header( "{$name}: {$field_value}" );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1315
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
 * Set the headers for caching for 10 days with JavaScript content type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
function cache_javascript_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
	$expiresOffset = 10 * DAY_IN_SECONDS;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1325
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1326
	header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1327
	header( 'Vary: Accept-Encoding' ); // Handle proxies
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1328
	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
  1329
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
 * Retrieve the number of database queries during the WordPress execution.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1336
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1337
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1338
 * @return int Number of database queries.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
function get_num_queries() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
	return $wpdb->num_queries;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1346
 * Whether input is yes or no.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1347
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1348
 * Must be 'y' to be true.
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
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1352
 * @param string $yn Character string containing either 'y' (yes) or 'n' (no).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1353
 * @return bool True if yes, false on anything else.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
function bool_from_yn( $yn ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
	return ( strtolower( $yn ) == 'y' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1360
 * Load the feed template from the use of an action hook.
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
 * 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
  1363
 * message telling the visitor that the feed is not valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
 * It is better to only have one hook for each feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1368
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1369
 * @global WP_Query $wp_query Used to tell if the use a comment feed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
function do_feed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
	$feed = get_query_var( 'feed' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
	// Remove the pad, if present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
	$feed = preg_replace( '/^_+/', '', $feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1379
	if ( $feed == '' || $feed == 'feed' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
		$feed = get_default_feed();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1381
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1383
	if ( ! has_action( "do_feed_{$feed}" ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
		wp_die( __( 'ERROR: 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
  1385
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
	 * Fires once the given feed is loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1390
	 * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1391
	 * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
	 * @since 2.1.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1394
	 * @since 4.4.0 The `$feed` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1396
	 * @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
  1397
	 * @param string $feed            The feed name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1398
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1399
	do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
 * Load the RDF RSS 0.91 Feed template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
 * @see load_template()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
function do_feed_rdf() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
	load_template( ABSPATH . WPINC . '/feed-rdf.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
 * Load the RSS 1.0 Feed Template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1417
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1418
 * @see load_template()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
function do_feed_rss() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
	load_template( ABSPATH . WPINC . '/feed-rss.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
 * Load either the RSS2 comment feed or the RSS2 posts feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
 * @see load_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
 * @param bool $for_comments True for the comment feed, false for normal feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
function do_feed_rss2( $for_comments ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1434
	if ( $for_comments ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
		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
  1436
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
		load_template( ABSPATH . WPINC . '/feed-rss2.php' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1438
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
 * Load either Atom comment feed or Atom posts feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
 * @see load_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
 * @param bool $for_comments True for the comment feed, false for normal feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
function do_feed_atom( $for_comments ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1451
	if ( $for_comments ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1452
		load_template( ABSPATH . WPINC . '/feed-atom-comments.php' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1453
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
		load_template( ABSPATH . WPINC . '/feed-atom.php' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1455
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
 * Display the robots.txt file content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
 * The echo content should be with usage of the permalinks or for creating the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
 * robots.txt file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
function do_robots() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	header( 'Content-Type: text/plain; charset=utf-8' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
	 * Fires when displaying the robots.txt file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1472
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1473
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
	do_action( 'do_robotstxt' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
	$output = "User-agent: *\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
	$public = get_option( 'blog_public' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
	if ( '0' == $public ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
		$output .= "Disallow: /\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
		$site_url = parse_url( site_url() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1482
		$path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1483
		$output  .= "Disallow: $path/wp-admin/\n";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1484
		$output  .= "Allow: $path/wp-admin/admin-ajax.php\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1488
	 * Filters the robots.txt output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
	 * @param string $output Robots.txt output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
	 * @param bool   $public Whether the site is considered "public".
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
	echo apply_filters( 'robots_txt', $output, $public );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1499
 * Determines whether WordPress is already installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
 * 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
  1502
 * 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
  1503
 * cache, and the database goes away, then you might have problems.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
 * Checks for the 'siteurl' option for whether WordPress is installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1507
 * 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
  1508
 * 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
  1509
 * Conditional Tags} article in the Theme Developer Handbook.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1510
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
 * @since 2.1.0
5
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
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1515
 * @return bool Whether the site is already installed.
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
function is_blog_installed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1520
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1521
	 * 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
  1522
	 * cached, oh well.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1524
	if ( wp_cache_get( 'is_blog_installed' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1526
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	$suppress = $wpdb->suppress_errors();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1529
	if ( ! wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
		$alloptions = wp_load_alloptions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
	// 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
  1533
	if ( ! isset( $alloptions['siteurl'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
		$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
  1535
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
		$installed = $alloptions['siteurl'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1537
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
	$wpdb->suppress_errors( $suppress );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1540
	$installed = ! empty( $installed );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
	wp_cache_set( 'is_blog_installed', $installed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1543
	if ( $installed ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1545
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
	// 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
  1548
	if ( defined( 'WP_REPAIRING' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1550
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
	$suppress = $wpdb->suppress_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1554
	/*
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1555
	 * 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
  1556
	 * 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
  1557
	 * options table could not be accessed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1558
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
	$wp_tables = $wpdb->tables();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
	foreach ( $wp_tables as $table ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1561
		// The existence of custom user tables shouldn't suggest an insane state or prevent a clean installation.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1562
		if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1564
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1565
		if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1567
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1568
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1569
		if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1571
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
		// One or more tables exist. We are insane.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
		wp_load_translations_early();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
		// Die with a DB error.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1578
		$wpdb->error = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1579
			/* translators: %s: database repair URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1580
			__( '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
  1581
			'maint/repair.php?referrer=is_blog_installed'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1582
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1583
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
		dead_db();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
	$wpdb->suppress_errors( $suppress );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
	wp_cache_set( 'is_blog_installed', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
 * Retrieve URL with nonce added to URL query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
 * @param string     $actionurl URL to add nonce action.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
 * @param int|string $action    Optional. Nonce action name. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1601
 * @param string     $name      Optional. Nonce name. Default '_wpnonce'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1602
 * @return string Escaped URL with nonce action added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
function wp_nonce_url( $actionurl, $action = -1, $name = '_wpnonce' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
	$actionurl = str_replace( '&amp;', '&', $actionurl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
	return esc_html( add_query_arg( $name, wp_create_nonce( $action ), $actionurl ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
 * Retrieve or display nonce hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
 * 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
  1613
 * 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
  1614
 * offer absolute protection, but should protect against most cases. It is very
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
 * important to use nonce field in forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
 * 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
  1618
 * 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
  1619
 * call the function without any parameters, because validation of the nonce
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
 * doesn't require any parameters, but since crackers know what the default is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
 * 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
  1622
 * damage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
 * 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
  1625
 * the nonce creation value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1629
 * @param int|string $action  Optional. Action name. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1630
 * @param string     $name    Optional. Nonce name. Default '_wpnonce'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1631
 * @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
  1632
 * @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
  1633
 * @return string Nonce field HTML markup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1635
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
  1636
	$name        = esc_attr( $name );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
	$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
  1638
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1639
	if ( $referer ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
		$nonce_field .= wp_referer_field( false );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1641
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1642
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1643
	if ( $echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
		echo $nonce_field;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1645
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
	return $nonce_field;
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
 * Retrieve or display referer hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
 * 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
  1654
 * input name is '_wp_http_referer', in case you wanted to check manually.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1658
 * @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
  1659
 * @return string Referer field HTML markup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
function wp_referer_field( $echo = true ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1662
	$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
  1663
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1664
	if ( $echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
		echo $referer_field;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1666
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
	return $referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
 * Retrieve or display original referer hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
 * 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
  1674
 * 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
  1675
 * current page, if it doesn't exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1676
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1679
 * @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
  1680
 * @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
  1681
 *                             Default 'current'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
 * @return string Original referer field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
	if ( ! $ref = wp_get_original_referer() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
		$ref = 'previous' == $jump_back_to ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
	$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1689
	if ( $echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
		echo $orig_referer_field;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1691
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
	return $orig_referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1696
 * Retrieve referer from '_wp_http_referer' or HTTP referer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1697
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1698
 * 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
  1699
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1702
 * @return false|string False on failure. Referer URL on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
function wp_get_referer() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1705
	if ( ! function_exists( 'wp_validate_redirect' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1707
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1708
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1709
	$ref = wp_get_raw_referer();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1710
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1711
	if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) && $ref !== home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
		return wp_validate_redirect( $ref, false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1713
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1714
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1715
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1716
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1717
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1718
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1719
 * 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
  1720
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1721
 * 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
  1722
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1723
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1724
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1725
 * @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
  1726
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1727
function wp_get_raw_referer() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1728
	if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1729
		return wp_unslash( $_REQUEST['_wp_http_referer'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1730
	} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1731
		return wp_unslash( $_SERVER['HTTP_REFERER'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1732
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1733
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
 * Retrieve original referer that was posted, if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
 * @return string|false False if no original referer or original referer if set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
function wp_get_original_referer() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1745
	if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
		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
  1747
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
 * Recursive directory creation based on full path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
 * Will attempt to set permissions on folders.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
 * @since 2.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
 * @param string $target Full path to attempt to create.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
 * @return bool Whether the path was created. True if path already exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
function wp_mkdir_p( $target ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
	$wrapper = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1764
	// Strip the protocol.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1765
	if ( wp_is_stream( $target ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
		list( $wrapper, $target ) = explode( '://', $target, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1769
	// From php.net/mkdir user contributed notes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
	$target = str_replace( '//', '/', $target );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1772
	// Put the wrapper back on the target.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1773
	if ( $wrapper !== null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
		$target = $wrapper . '://' . $target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1777
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1778
	 * Safe mode fails with a trailing slash under certain PHP versions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1779
	 * Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1780
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1781
	$target = rtrim( $target, '/' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1782
	if ( empty( $target ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
		$target = '/';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1784
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1785
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1786
	if ( file_exists( $target ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
		return @is_dir( $target );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1788
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
13
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1790
	// Do not allow path traversals.
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1791
	if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1792
		return false;
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1793
	}
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1794
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
	// 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
  1796
	$target_parent = dirname( $target );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1797
	while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
		$target_parent = dirname( $target_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
	// Get the permission bits.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1802
	if ( $stat = @stat( $target_parent ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
		$dir_perms = $stat['mode'] & 0007777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
		$dir_perms = 0777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
	if ( @mkdir( $target, $dir_perms, true ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1809
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1810
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1811
		 * 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
  1812
		 * the $dir_perms correctly with chmod()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1813
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1814
		if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1815
			$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1816
			for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1817
				@chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1818
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1819
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1820
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1828
 * Test if a given filesystem path is absolute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1829
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1830
 * For example, '/foo/bar', or 'c:\windows'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1834
 * @param string $path File path.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
 * @return bool True if path is absolute, false is not absolute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
function path_is_absolute( $path ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1838
	/*
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1839
	 * 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
  1840
	 * 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
  1841
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1842
	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
  1843
		return true;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1844
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1845
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1846
	/*
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1847
	 * 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
  1848
	 * a symbolic link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1849
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1850
	if ( realpath( $path ) == $path ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1852
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1853
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1854
	if ( strlen( $path ) == 0 || $path[0] == '.' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1856
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1858
	// Windows allows absolute paths like this.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1859
	if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1861
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1863
	// A path starting with / or \ is absolute; anything else is relative.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
	return ( $path[0] == '/' || $path[0] == '\\' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1868
 * Join two filesystem paths together.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1869
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1870
 * 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
  1871
 * then it the full path is returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1875
 * @param string $base Base path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1876
 * @param string $path Path relative to $base.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
 * @return string The path with the base or absolute path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
function path_join( $base, $path ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1880
	if ( path_is_absolute( $path ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
		return $path;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1882
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1883
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1884
	return rtrim( $base, '/' ) . '/' . ltrim( $path, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1888
 * Normalize a filesystem path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1889
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1890
 * On windows systems, replaces backslashes with forward slashes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1891
 * and forces upper-case drive letters.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1892
 * 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
  1893
 * 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
  1894
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1895
 * @since 3.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1896
 * @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
  1897
 * @since 4.5.0 Allows for Windows network shares.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1898
 * @since 4.9.7 Allows for PHP file wrappers.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1899
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1900
 * @param string $path Path to normalize.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1901
 * @return string Normalized path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1903
function wp_normalize_path( $path ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1904
	$wrapper = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1905
	if ( wp_is_stream( $path ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1906
		list( $wrapper, $path ) = explode( '://', $path, 2 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1907
		$wrapper               .= '://';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1908
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1909
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1910
	// Standardise all paths to use /
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1911
	$path = str_replace( '\\', '/', $path );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1912
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1913
	// 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
  1914
	$path = preg_replace( '|(?<=.)/+|', '/', $path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1915
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1916
	// Windows paths should uppercase the drive letter
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1917
	if ( ':' === substr( $path, 1, 1 ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1918
		$path = ucfirst( $path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1919
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1920
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1921
	return $wrapper . $path;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1922
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1923
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1924
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1925
 * Determine a writable directory for temporary files.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1926
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
 * Function's preference is the return value of sys_get_temp_dir(),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
 * before finally defaulting to /tmp/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
 * 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
  1932
 * 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
  1933
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1936
 * @staticvar string $temp
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1937
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1938
 * @return string Writable temporary directory.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
function get_temp_dir() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1941
	static $temp = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1942
	if ( defined( 'WP_TEMP_DIR' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1943
		return trailingslashit( WP_TEMP_DIR );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1944
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1945
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1946
	if ( $temp ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1947
		return trailingslashit( $temp );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1948
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1949
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1950
	if ( function_exists( 'sys_get_temp_dir' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
		$temp = sys_get_temp_dir();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1952
		if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
			return trailingslashit( $temp );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1954
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1955
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1956
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1957
	$temp = ini_get( 'upload_tmp_dir' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1958
	if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1959
		return trailingslashit( $temp );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1960
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
	$temp = WP_CONTENT_DIR . '/';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1963
	if ( is_dir( $temp ) && wp_is_writable( $temp ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
		return $temp;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1965
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1967
	return '/tmp/';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
 * Determine if a directory is writable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1973
 * 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
  1974
 * affecting Windows Servers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1975
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1976
 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
 * @see win_is_writable()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1980
 * @param string $path Path to check for write-ability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1981
 * @return bool Whether the path is writable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
function wp_is_writable( $path ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1984
	if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
		return win_is_writable( $path );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1986
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
		return @is_writable( $path );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1988
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
 * Workaround for Windows bug in is_writable() function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
 * PHP has issues with Windows ACL's for determine if a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
 * directory is writable or not, this works around them by
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
 * checking the ability to open files rather than relying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
 * upon PHP to interprate the OS ACL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2001
 * @see https://bugs.php.net/bug.php?id=27609
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2002
 * @see https://bugs.php.net/bug.php?id=30931
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2003
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2004
 * @param string $path Windows path to check for write-ability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2005
 * @return bool Whether the path is writable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
function win_is_writable( $path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2009
	if ( $path[ strlen( $path ) - 1 ] == '/' ) { // if it looks like a directory, check a random file within the directory
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2010
		return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2011
	} elseif ( is_dir( $path ) ) { // 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
  2012
		return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2013
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
	// check tmp file for read/write capabilities
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2015
	$should_delete_tmp_file = ! file_exists( $path );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2016
	$f                      = @fopen( $path, 'a' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2017
	if ( $f === false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2019
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
	fclose( $f );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2021
	if ( $should_delete_tmp_file ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
		unlink( $path );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2023
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2028
 * Retrieves uploads directory information.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2029
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2030
 * 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
  2031
 * 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
  2032
 * when not uploading files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2033
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2034
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2035
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2036
 * @see wp_upload_dir()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2037
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2038
 * @return array See wp_upload_dir() for description.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2039
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2040
function wp_get_upload_dir() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2041
	return wp_upload_dir( null, false );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2042
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2043
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2044
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
 * Get an array containing the current upload directory's path and url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
 * Checks the 'upload_path' option, which should be from the web root folder,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
 * 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
  2049
 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
 * 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
  2053
 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
 * 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
  2056
 * the administration settings panel), then the time will be used. The format
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
 * will be year first and then month.
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 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
  2060
 * 'error' containing the error message. The error suggests that the parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
 * directory is not writable by the server.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
 * On success, the returned array will have many indices:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
 * 'path' - base directory and sub directory or full path to upload directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
 * 'url' - base url and sub directory or absolute URL to upload directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
 * 'subdir' - sub directory if uploads use year/month folders option is on.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
 * 'basedir' - path without subdir.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
 * 'baseurl' - URL path without subdir.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2069
 * 'error' - false or error message.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2072
 * @uses _wp_upload_dir()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2073
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2074
 * @staticvar array $cache
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2075
 * @staticvar array $tested_paths
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2076
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2077
 * @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
  2078
 * @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
  2079
 *                           Default true for backward compatibility.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2080
 * @param bool   $refresh_cache Optional. Whether to refresh the cache. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
 * @return array See above for description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2083
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
  2084
	static $cache = array(), $tested_paths = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2085
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2086
	$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
  2087
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2088
	if ( $refresh_cache || empty( $cache[ $key ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2089
		$cache[ $key ] = _wp_upload_dir( $time );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2090
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2091
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2092
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2093
	 * Filters the uploads directory data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2094
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2095
	 * @since 2.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2096
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2097
	 * @param array $uploads Array of upload directory data with keys of 'path',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2098
	 *                       'url', 'subdir, 'basedir', and 'error'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2099
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2100
	$uploads = apply_filters( 'upload_dir', $cache[ $key ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2101
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2102
	if ( $create_dir ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2103
		$path = $uploads['path'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2104
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2105
		if ( array_key_exists( $path, $tested_paths ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2106
			$uploads['error'] = $tested_paths[ $path ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2107
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2108
			if ( ! wp_mkdir_p( $path ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2109
				if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2110
					$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2111
				} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2112
					$error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2113
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2114
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2115
				$uploads['error'] = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2116
					/* translators: %s: directory path */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2117
					__( '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
  2118
					esc_html( $error_path )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2119
				);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2120
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2121
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2122
			$tested_paths[ $path ] = $uploads['error'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2123
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2124
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2125
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2126
	return $uploads;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2127
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2128
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2129
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2130
 * 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
  2131
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2132
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2133
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2134
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2135
 * @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
  2136
 * @return array See wp_upload_dir()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2137
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2138
function _wp_upload_dir( $time = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2139
	$siteurl     = get_option( 'siteurl' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
	$upload_path = trim( get_option( 'upload_path' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
	if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
		$dir = WP_CONTENT_DIR . '/uploads';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
	} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2145
		// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
		$dir = path_join( ABSPATH, $upload_path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2148
		$dir = $upload_path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2151
	if ( ! $url = get_option( 'upload_url_path' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2152
		if ( empty( $upload_path ) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
			$url = WP_CONTENT_URL . '/uploads';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2154
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
			$url = trailingslashit( $siteurl ) . $upload_path;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2156
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2159
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2160
	 * 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
  2161
	 * 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
  2162
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
	if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
		$dir = ABSPATH . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
		$url = trailingslashit( $siteurl ) . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
	// If multisite (and if not the main site in a post-MU network)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
	if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
		if ( ! get_site_option( 'ms_files_rewriting' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2172
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2173
			 * 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
  2174
			 * 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
  2175
			 * 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
  2176
			 * 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
  2177
			 * 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
  2178
			 * had wp-content/uploads for the main site.)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2179
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2181
			if ( defined( 'MULTISITE' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
				$ms_dir = '/sites/' . get_current_blog_id();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2183
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
				$ms_dir = '/' . get_current_blog_id();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2185
			}
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
			$dir .= $ms_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
			$url .= $ms_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
		} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2191
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2192
			 * 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
  2193
			 * 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
  2194
			 * 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
  2195
			 *    there, and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2196
			 * 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
  2197
			 *    the original blog ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2198
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2199
			 * 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
  2200
			 * (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
  2201
			 * 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
  2202
			 * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2203
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2205
			if ( defined( 'BLOGUPLOADDIR' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
				$dir = untrailingslashit( BLOGUPLOADDIR );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2207
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
				$dir = ABSPATH . UPLOADS;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2209
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
			$url = trailingslashit( $siteurl ) . 'files';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
	$basedir = $dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
	$baseurl = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
	$subdir = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2218
	if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
		// Generate the yearly and monthly dirs
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2220
		if ( ! $time ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
			$time = current_time( 'mysql' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2222
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2223
		$y      = substr( $time, 0, 4 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2224
		$m      = substr( $time, 5, 2 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
		$subdir = "/$y/$m";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
	$dir .= $subdir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
	$url .= $subdir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2231
	return array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2232
		'path'    => $dir,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2233
		'url'     => $url,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2234
		'subdir'  => $subdir,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2235
		'basedir' => $basedir,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2236
		'baseurl' => $baseurl,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2237
		'error'   => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2238
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
}
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
 * Get a filename that is sanitized and unique for the given directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
 * If the filename is not unique, then a number will be added to the filename
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
 * before the extension, and will continue adding numbers until the filename is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
 * unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2248
 * The callback is passed three parameters, the first one is the directory, the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
 * second is the filename, and the third is the extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2253
 * @param string   $dir                      Directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2254
 * @param string   $filename                 File name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2255
 * @param callable $unique_filename_callback Callback. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2256
 * @return string New filename, if given wasn't unique.
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 wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2259
	// 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
  2260
	$filename = sanitize_file_name( $filename );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2261
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2262
	// 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
  2263
	$ext  = pathinfo( $filename, PATHINFO_EXTENSION );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2264
	$name = pathinfo( $filename, PATHINFO_BASENAME );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2265
	if ( $ext ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2266
		$ext = '.' . $ext;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2267
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2269
	// 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
  2270
	if ( $name === $ext ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
		$name = '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2272
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2274
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2275
	 * 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
  2276
	 * Use callback if supplied.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2277
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
	if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
		$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
		$number = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2283
		// Change '.ext' to lower case.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2284
		if ( $ext && strtolower( $ext ) != $ext ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2285
			$ext2      = strtolower( $ext );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2286
			$filename2 = preg_replace( '|' . preg_quote( $ext ) . '$|', $ext2, $filename );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2288
			// Check for both lower and upper case extension or image sub-sizes may be overwritten.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2289
			while ( file_exists( $dir . "/$filename" ) || file_exists( $dir . "/$filename2" ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2290
				$new_number = (int) $number + 1;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2291
				$filename   = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2292
				$filename2  = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2293
				$number     = $new_number;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2294
			}
7
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
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2297
			 * Filters the result when generating a unique file name.
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
			 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2300
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2301
			 * @param string        $filename                 Unique file name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2302
			 * @param string        $ext                      File extension, eg. ".png".
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2303
			 * @param string        $dir                      Directory path.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2304
			 * @param callable|null $unique_filename_callback Callback function that generates the unique file name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2305
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2306
			return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
		while ( file_exists( $dir . "/$filename" ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2310
			$new_number = (int) $number + 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2311
			if ( '' == "$number$ext" ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2312
				$filename = "$filename-" . $new_number;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2313
			} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2314
				$filename = str_replace( array( "-$number$ext", "$number$ext" ), '-' . $new_number . $ext, $filename );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2315
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2316
			$number = $new_number;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2320
	/** This filter is documented in wp-includes/functions.php */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2321
	return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2322
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
 * Create a file in the upload folder with given content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
 * 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
  2328
 * 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
  2329
 * 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
  2330
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
 * 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
  2332
 * 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
  2333
 * 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
  2334
 * filename and content to this function, which will add it to the upload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
 * folder.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
 * The permissions will be set on the new file automatically by this function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2341
 * @param string       $name       Filename.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2342
 * @param null|string  $deprecated Never used. Set to null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2343
 * @param mixed        $bits       File content
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2344
 * @param string       $time       Optional. Time formatted in 'yyyy/mm'. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
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
  2348
	if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2349
		_deprecated_argument( __FUNCTION__, '2.0.0' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2350
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2351
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2352
	if ( empty( $name ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2353
		return array( 'error' => __( 'Empty filename' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2354
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2356
	$wp_filetype = wp_check_filetype( $name );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2357
	if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2358
		return array( 'error' => __( 'Sorry, this file type is not permitted for security reasons.' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2359
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
	$upload = wp_upload_dir( $time );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2363
	if ( $upload['error'] !== false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
		return $upload;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2365
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2367
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2368
	 * Filters whether to treat the upload bits as an error.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2369
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2370
	 * Passing a non-array to the filter will effectively short-circuit preparing
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2371
	 * the upload bits, returning that value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2372
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2373
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2374
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2375
	 * @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2376
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2377
	$upload_bits_error = apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2378
		'wp_upload_bits',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2379
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2380
			'name' => $name,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2381
			'bits' => $bits,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2382
			'time' => $time,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2383
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2384
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2385
	if ( ! is_array( $upload_bits_error ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2386
		$upload['error'] = $upload_bits_error;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2387
		return $upload;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2388
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2390
	$filename = wp_unique_filename( $upload['path'], $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2392
	$new_file = $upload['path'] . "/$filename";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2393
	if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2394
		if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2395
			$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
  2396
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2397
			$error_path = wp_basename( $upload['basedir'] ) . $upload['subdir'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2398
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2399
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2400
		$message = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2401
			/* translators: %s: directory path */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2402
			__( '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
  2403
			$error_path
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2404
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
		return array( 'error' => $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
	$ifp = @ fopen( $new_file, 'wb' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2409
	if ( ! $ifp ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
		return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2411
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
	@fwrite( $ifp, $bits );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
	fclose( $ifp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
	// Set correct file permissions
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2418
	$stat  = @ stat( dirname( $new_file ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
	$perms = $stat['mode'] & 0007777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
	$perms = $perms & 0000666;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
	@ chmod( $new_file, $perms );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
	// Compute the URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
	$url = $upload['url'] . "/$filename";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2427
	/** 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
  2428
	return apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2429
		'wp_handle_upload',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2430
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2431
			'file'  => $new_file,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2432
			'url'   => $url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2433
			'type'  => $wp_filetype['type'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2434
			'error' => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2435
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2436
		'sideload'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2437
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2440
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2441
 * Retrieve the file type based on the extension name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2443
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2444
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
 * @param string $ext The extension to search.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2446
 * @return string|void The file type, example: audio, video, document, spreadsheet, etc.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
function wp_ext2type( $ext ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
	$ext = strtolower( $ext );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2450
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2451
	$ext2type = wp_get_ext_types();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2452
	foreach ( $ext2type as $type => $exts ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2453
		if ( in_array( $ext, $exts ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
			return $type;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2455
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2456
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2457
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2459
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
 * Retrieve the file type from the file name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2461
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2462
 * You can optionally define the mime array, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
 * @param string $filename File name or path.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2467
 * @param array  $mimes    Optional. Key is the file extension with value as the mime type.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
 * @return array Values with extension first and mime type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
function wp_check_filetype( $filename, $mimes = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2471
	if ( empty( $mimes ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
		$mimes = get_allowed_mime_types();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2473
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
	$type = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2475
	$ext  = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
	foreach ( $mimes as $ext_preg => $mime_match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
		$ext_preg = '!\.(' . $ext_preg . ')$!i';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
		if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
			$type = $mime_match;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2481
			$ext  = $ext_matches[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
	return compact( 'ext', 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
 * Attempt to determine the real file type of a file.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2491
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
 * If unable to, the file name extension will be used to determine type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2494
 * 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
  2495
 * 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
  2496
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2497
 * 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
  2498
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2501
 * @param string $file     Full path to the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2502
 * @param string $filename The name of the file (may differ from $file due to $file being
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2503
 *                         in a tmp directory).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2504
 * @param array   $mimes   Optional. Key is the file extension with value as the mime type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2505
 * @return array Values for the extension, MIME, and either a corrected filename or false
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2506
 *               if original $filename is valid.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
	$proper_filename = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2511
	// Do basic extension validation and MIME mapping
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
	$wp_filetype = wp_check_filetype( $filename, $mimes );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2513
	$ext         = $wp_filetype['ext'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2514
	$type        = $wp_filetype['type'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
	// 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
  2517
	if ( ! file_exists( $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
		return compact( 'ext', 'type', 'proper_filename' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2519
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2521
	$real_mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2522
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2523
	// Validate image types.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2524
	if ( $type && 0 === strpos( $type, 'image/' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
		// 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
  2527
		$real_mime = wp_get_image_mime( $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2528
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2529
		if ( $real_mime && $real_mime != $type ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2530
			/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2531
			 * 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
  2532
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2533
			 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2534
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2535
			 * @param  array $mime_to_ext Array of image mime types and their matching extensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2536
			 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2537
			$mime_to_ext = apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2538
				'getimagesize_mimes_to_exts',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2539
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2540
					'image/jpeg' => 'jpg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2541
					'image/png'  => 'png',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2542
					'image/gif'  => 'gif',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2543
					'image/bmp'  => 'bmp',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2544
					'image/tiff' => 'tif',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2545
				)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2546
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
			// 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
  2549
			if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
				$filename_parts = explode( '.', $filename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2551
				array_pop( $filename_parts );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2552
				$filename_parts[] = $mime_to_ext[ $real_mime ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2553
				$new_filename     = implode( '.', $filename_parts );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2555
				if ( $new_filename != $filename ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
					$proper_filename = $new_filename; // Mark that it changed
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2557
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
				// Redefine the extension / MIME
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
				$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
  2560
				$ext         = $wp_filetype['ext'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2561
				$type        = $wp_filetype['type'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2562
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2563
				// Reset $real_mime and try validating again.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2564
				$real_mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2565
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2566
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2567
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2568
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2569
	// 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
  2570
	if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2571
		$finfo     = finfo_open( FILEINFO_MIME_TYPE );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2572
		$real_mime = finfo_file( $finfo, $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2573
		finfo_close( $finfo );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2574
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2575
		// fileinfo often misidentifies obscure files as one of these types
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2576
		$nonspecific_types = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2577
			'application/octet-stream',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2578
			'application/encrypted',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2579
			'application/CDFV2-encrypted',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2580
			'application/zip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2581
		);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2582
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2583
		/*
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2584
		 * 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
  2585
		 * 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
  2586
		 * 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
  2587
		 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2588
		if ( in_array( $real_mime, $nonspecific_types, true ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2589
			// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2590
			if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2591
				$type = $ext = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2592
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2593
		} 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
  2594
			/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2595
			 * 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
  2596
			 * 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
  2597
			 * 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
  2598
			 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2599
			if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2600
				$type = $ext = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2602
		} elseif ( 'text/plain' === $real_mime ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2603
			// 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
  2604
			if ( ! in_array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2605
				$type,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2606
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2607
					'text/plain',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2608
					'text/csv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2609
					'text/richtext',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2610
					'text/tsv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2611
					'text/vtt',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2612
				)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2613
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2614
			) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2615
				$type = $ext = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2616
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2617
		} elseif ( 'text/rtf' === $real_mime ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2618
			// Special casing for RTF files.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2619
			if ( ! in_array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2620
				$type,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2621
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2622
					'text/rtf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2623
					'text/plain',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2624
					'application/rtf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2625
				)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2626
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2627
			) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2628
				$type = $ext = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2629
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2630
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2631
			if ( $type !== $real_mime ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2632
				/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2633
				 * Everything else including image/* and application/*:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2634
				 * 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
  2635
				 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2636
				$type = $ext = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2637
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2638
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2639
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2640
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2641
	// The mime type must be allowed
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2642
	if ( $type ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2643
		$allowed = get_allowed_mime_types();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2644
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2645
		if ( ! in_array( $type, $allowed ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2646
			$type = $ext = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2647
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2648
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2649
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2650
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2651
	 * Filters the "real" file type of the given file.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2652
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2653
	 * @since 3.0.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2654
	 * @since 5.1.0 The $real_mime parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2655
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2656
	 * @param array       $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2657
	 *                                               'proper_filename' keys.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2658
	 * @param string      $file                      Full path to the file.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2659
	 * @param string      $filename                  The name of the file (may differ from $file due to
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2660
	 *                                               $file being in a tmp directory).
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2661
	 * @param array       $mimes                     Key is the file extension with value as the mime type.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2662
	 * @param string|bool $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
  2663
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2664
	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
  2665
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2667
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2668
 * Returns the real mime type of an image file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2669
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2670
 * 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
  2671
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2672
 * @since 4.7.1
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2673
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2674
 * @param string $file Full path to the file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2675
 * @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
  2676
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2677
function wp_get_image_mime( $file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2678
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2679
	 * Use exif_imagetype() to check the mimetype if available or fall back to
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2680
	 * getimagesize() if exif isn't avaialbe. If either function throws an Exception
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2681
	 * we assume the file could not be validated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2682
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2683
	try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2684
		if ( is_callable( 'exif_imagetype' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2685
			$imagetype = exif_imagetype( $file );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2686
			$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
  2687
		} elseif ( function_exists( 'getimagesize' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2688
			$imagesize = getimagesize( $file );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2689
			$mime      = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2690
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2691
			$mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2692
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2693
	} catch ( Exception $e ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2694
		$mime = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2695
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2696
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2697
	return $mime;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2698
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2699
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2700
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2701
 * Retrieve list of mime types and file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2702
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2703
 * @since 3.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2704
 * @since 4.2.0 Support was added for GIMP (xcf) files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2705
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2706
 * @return array Array of mime types keyed by the file extension regex corresponding to those types.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2707
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2708
function wp_get_mime_types() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2709
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2710
	 * Filters the list of mime types and file extensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2712
	 * 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
  2713
	 * mime types, use the {@see 'upload_mimes'} filter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2714
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2715
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2716
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2717
	 * @param array $wp_get_mime_types Mime types keyed by the file extension regex
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2718
	 *                                 corresponding to those types.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2719
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2720
	return apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2721
		'mime_types',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2722
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2723
			// Image formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2724
			'jpg|jpeg|jpe'                 => 'image/jpeg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2725
			'gif'                          => 'image/gif',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2726
			'png'                          => 'image/png',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2727
			'bmp'                          => 'image/bmp',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2728
			'tiff|tif'                     => 'image/tiff',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2729
			'ico'                          => 'image/x-icon',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2730
			// Video formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2731
			'asf|asx'                      => 'video/x-ms-asf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2732
			'wmv'                          => 'video/x-ms-wmv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2733
			'wmx'                          => 'video/x-ms-wmx',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2734
			'wm'                           => 'video/x-ms-wm',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2735
			'avi'                          => 'video/avi',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2736
			'divx'                         => 'video/divx',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2737
			'flv'                          => 'video/x-flv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2738
			'mov|qt'                       => 'video/quicktime',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2739
			'mpeg|mpg|mpe'                 => 'video/mpeg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2740
			'mp4|m4v'                      => 'video/mp4',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2741
			'ogv'                          => 'video/ogg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2742
			'webm'                         => 'video/webm',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2743
			'mkv'                          => 'video/x-matroska',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2744
			'3gp|3gpp'                     => 'video/3gpp', // Can also be audio
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2745
			'3g2|3gp2'                     => 'video/3gpp2', // Can also be audio
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2746
			// Text formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2747
			'txt|asc|c|cc|h|srt'           => 'text/plain',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2748
			'csv'                          => 'text/csv',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2749
			'tsv'                          => 'text/tab-separated-values',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2750
			'ics'                          => 'text/calendar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2751
			'rtx'                          => 'text/richtext',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2752
			'css'                          => 'text/css',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2753
			'htm|html'                     => 'text/html',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2754
			'vtt'                          => 'text/vtt',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2755
			'dfxp'                         => 'application/ttaf+xml',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2756
			// Audio formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2757
			'mp3|m4a|m4b'                  => 'audio/mpeg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2758
			'aac'                          => 'audio/aac',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2759
			'ra|ram'                       => 'audio/x-realaudio',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2760
			'wav'                          => 'audio/wav',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2761
			'ogg|oga'                      => 'audio/ogg',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2762
			'flac'                         => 'audio/flac',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2763
			'mid|midi'                     => 'audio/midi',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2764
			'wma'                          => 'audio/x-ms-wma',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2765
			'wax'                          => 'audio/x-ms-wax',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2766
			'mka'                          => 'audio/x-matroska',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2767
			// Misc application formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2768
			'rtf'                          => 'application/rtf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2769
			'js'                           => 'application/javascript',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2770
			'pdf'                          => 'application/pdf',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2771
			'swf'                          => 'application/x-shockwave-flash',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2772
			'class'                        => 'application/java',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2773
			'tar'                          => 'application/x-tar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2774
			'zip'                          => 'application/zip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2775
			'gz|gzip'                      => 'application/x-gzip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2776
			'rar'                          => 'application/rar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2777
			'7z'                           => 'application/x-7z-compressed',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2778
			'exe'                          => 'application/x-msdownload',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2779
			'psd'                          => 'application/octet-stream',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2780
			'xcf'                          => 'application/octet-stream',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2781
			// MS Office formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2782
			'doc'                          => 'application/msword',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2783
			'pot|pps|ppt'                  => 'application/vnd.ms-powerpoint',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2784
			'wri'                          => 'application/vnd.ms-write',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2785
			'xla|xls|xlt|xlw'              => 'application/vnd.ms-excel',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2786
			'mdb'                          => 'application/vnd.ms-access',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2787
			'mpp'                          => 'application/vnd.ms-project',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2788
			'docx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2789
			'docm'                         => 'application/vnd.ms-word.document.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2790
			'dotx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2791
			'dotm'                         => 'application/vnd.ms-word.template.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2792
			'xlsx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2793
			'xlsm'                         => 'application/vnd.ms-excel.sheet.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2794
			'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
  2795
			'xltx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2796
			'xltm'                         => 'application/vnd.ms-excel.template.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2797
			'xlam'                         => 'application/vnd.ms-excel.addin.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2798
			'pptx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2799
			'pptm'                         => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2800
			'ppsx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2801
			'ppsm'                         => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2802
			'potx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.template',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2803
			'potm'                         => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2804
			'ppam'                         => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2805
			'sldx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2806
			'sldm'                         => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2807
			'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2808
			'oxps'                         => 'application/oxps',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2809
			'xps'                          => 'application/vnd.ms-xpsdocument',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2810
			// OpenOffice formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2811
			'odt'                          => 'application/vnd.oasis.opendocument.text',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2812
			'odp'                          => 'application/vnd.oasis.opendocument.presentation',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2813
			'ods'                          => 'application/vnd.oasis.opendocument.spreadsheet',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2814
			'odg'                          => 'application/vnd.oasis.opendocument.graphics',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2815
			'odc'                          => 'application/vnd.oasis.opendocument.chart',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2816
			'odb'                          => 'application/vnd.oasis.opendocument.database',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2817
			'odf'                          => 'application/vnd.oasis.opendocument.formula',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2818
			// WordPerfect formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2819
			'wp|wpd'                       => 'application/wordperfect',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2820
			// iWork formats.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2821
			'key'                          => 'application/vnd.apple.keynote',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2822
			'numbers'                      => 'application/vnd.apple.numbers',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2823
			'pages'                        => 'application/vnd.apple.pages',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2824
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2825
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2827
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2828
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2829
 * 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
  2830
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2831
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2832
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2833
 * @return array Array of file extensions types keyed by the type of file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2834
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2835
function wp_get_ext_types() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2836
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2837
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2838
	 * Filters file type based on the extension name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2839
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2840
	 * @since 2.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2841
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2842
	 * @see wp_ext2type()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2843
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2844
	 * @param array $ext2type Multi-dimensional array with extensions for a default set
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2845
	 *                        of file types.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2846
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2847
	return apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2848
		'ext2type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2849
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2850
			'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2851
			'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
  2852
			'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
  2853
			'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
  2854
			'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2855
			'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
  2856
			'text'        => array( 'asc', 'csv', 'tsv', 'txt' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2857
			'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
  2858
			'code'        => array( 'css', 'htm', 'html', 'php', 'js' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2859
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2860
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2861
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2862
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2863
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2864
 * Retrieve list of allowed mime types and file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2865
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2866
 * @since 2.8.6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2867
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2868
 * @param int|WP_User $user Optional. User to check. Defaults to current user.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2869
 * @return array Array of mime types keyed by the file extension regex corresponding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2870
 *               to those types.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2871
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2872
function get_allowed_mime_types( $user = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2873
	$t = wp_get_mime_types();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2875
	unset( $t['swf'], $t['exe'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2876
	if ( function_exists( 'current_user_can' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2877
		$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
  2878
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2879
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2880
	if ( empty( $unfiltered ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2881
		unset( $t['htm|html'], $t['js'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2882
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2883
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2884
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2885
	 * Filters list of allowed mime types and file extensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2886
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2887
	 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2888
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2889
	 * @param array            $t    Mime types keyed by the file extension regex corresponding to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2890
	 *                               those types. 'swf' and 'exe' removed from full list. 'htm|html' also
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2891
	 *                               removed depending on '$user' capabilities.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2892
	 * @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
  2893
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2894
	return apply_filters( 'upload_mimes', $t, $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2895
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2897
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2898
 * Display "Are You Sure" message to confirm the action being taken.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2899
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2900
 * 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
  2901
 * along with the "Are you sure?" message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2902
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2903
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2904
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
 * @param string $action The nonce action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2906
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
function wp_nonce_ays( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
	if ( 'log-out' == $action ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2909
		$html = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2910
			/* translators: %s: site name */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2911
			__( 'You are attempting to log out of %s' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2912
			get_bloginfo( 'name' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2913
		);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2914
		$html       .= '</p><p>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2915
		$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
  2916
		$html       .= sprintf(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2917
			/* translators: %s: logout URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2918
			__( '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
  2919
			wp_logout_url( $redirect_to )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2920
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2921
	} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2922
		$html = __( 'The link you followed has expired.' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2923
		if ( wp_get_referer() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2924
			$html .= '</p><p>';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2925
			$html .= sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2926
				'<a href="%s">%s</a>',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2927
				esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2928
				__( 'Please try again.' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2929
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2930
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2931
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2932
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2933
	wp_die( $html, __( 'Something went wrong.' ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2934
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2935
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2936
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2937
 * Kills WordPress execution and displays HTML page with an error message.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2938
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2939
 * This function complements the `die()` PHP function. The difference is that
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
 * 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
  2941
 * 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
  2942
 * 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
  2943
 * silently or more gracefully.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2944
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2945
 * 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
  2946
 * the `$title` parameter (the default title would apply) or the `$args` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2947
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2948
 * @since 2.0.4
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2949
 * @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
  2950
 *              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
  2951
 * @since 5.1.0 The `$link_url`, `$link_text`, and `$exit` arguments were added.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2952
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2953
 * @global WP_Query $wp_query Global WP_Query instance.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2954
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2955
 * @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
  2956
 *                                  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
  2957
 *                                  Default empty.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2958
 * @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
  2959
 *                                  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
  2960
 *                                  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
  2961
 *                                  code. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2962
 * @param string|array|int $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2963
 *     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
  2964
 *     as the response code. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2965
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2966
 *     @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
  2967
 *     @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
  2968
 *                                  Default empty string.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2969
 *     @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
  2970
 *                                  Default empty string.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2971
 *     @type bool   $back_link      Whether to include a link to go back. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2972
 *     @type string $text_direction The text direction. This is only useful internally, when WordPress
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2973
 *                                  is still loading and the site's locale is not set up yet. Accepts 'rtl'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2974
 *                                  Default is the value of is_rtl().
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2975
 *     @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
  2976
 *                                  is a WP_Error.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2977
 *     @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
  2978
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2979
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2980
function wp_die( $message = '', $title = '', $args = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2981
	global $wp_query;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2982
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2983
	if ( is_int( $args ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2984
		$args = array( 'response' => $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2985
	} elseif ( is_int( $title ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2986
		$args  = array( 'response' => $title );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2987
		$title = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2988
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2989
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2990
	if ( wp_doing_ajax() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2991
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2992
		 * Filters the callback for killing WordPress execution for Ajax requests.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2993
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2994
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2995
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2996
		 * @param callable $function Callback function name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2997
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2998
		$function = 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
  2999
	} elseif ( wp_is_json_request() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3000
		/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3001
		 * 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
  3002
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3003
		 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3004
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3005
		 * @param callable $function Callback function name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3006
		 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3007
		$function = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3008
	} elseif ( wp_is_jsonp_request() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3009
		/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3010
		 * Filters the callback for killing WordPress execution for JSONP requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3011
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3012
		 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3013
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3014
		 * @param callable $function Callback function name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3015
		 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3016
		$function = apply_filters( 'wp_die_jsonp_handler', '_jsonp_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3017
	} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3018
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3019
		 * 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
  3020
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3021
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3022
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3023
		 * @param callable $function Callback function name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3024
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3025
		$function = 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
  3026
	} elseif ( wp_is_xml_request()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3027
		|| isset( $wp_query ) &&
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3028
			( function_exists( 'is_feed' ) && is_feed()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3029
			|| function_exists( 'is_comment_feed' ) && is_comment_feed()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3030
			|| function_exists( 'is_trackback' ) && is_trackback() ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3031
		/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3032
		 * 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
  3033
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3034
		 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3035
		 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3036
		 * @param callable $function Callback function name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3037
		 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3038
		$function = apply_filters( 'wp_die_xml_handler', '_xml_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3039
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3040
		/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3041
		 * 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
  3042
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3043
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3044
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3045
		 * @param callable $function Callback function name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3046
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3047
		$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3048
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3050
	call_user_func( $function, $message, $title, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3051
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3052
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3054
 * 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
  3055
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3056
 * 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
  3057
 * 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
  3058
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3059
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3060
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3061
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3062
 * @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
  3063
 * @param string          $title   Optional. Error title. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3064
 * @param string|array    $args    Optional. Arguments to control behavior. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3065
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3066
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3067
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3068
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3069
	if ( is_string( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3070
		if ( ! empty( $r['additional_errors'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3071
			$message = array_merge(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3072
				array( $message ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3073
				wp_list_pluck( $r['additional_errors'], 'message' )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3074
			);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3075
			$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $message ) . "</li>\n\t</ul>";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3076
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3077
			$message = "<p>$message</p>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3079
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3080
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3081
	$have_gettext = function_exists( '__' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3082
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3083
	if ( ! empty( $r['link_url'] ) && ! empty( $r['link_text'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3084
		$link_url = $r['link_url'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3085
		if ( function_exists( 'esc_url' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3086
			$link_url = esc_url( $link_url );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3087
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3088
		$link_text = $r['link_text'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3089
		$message  .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3090
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3092
	if ( isset( $r['back_link'] ) && $r['back_link'] ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3093
		$back_text = $have_gettext ? __( '&laquo; Back' ) : '&laquo; Back';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3094
		$message  .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3095
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
	if ( ! did_action( 'admin_head' ) ) :
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3098
		if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3099
			header( 'Content-Type: text/html; charset=utf-8' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
			status_header( $r['response'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
			nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3102
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3103
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3104
		$text_direction = $r['text_direction'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3105
		if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3106
			$dir_attr = get_language_attributes();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3107
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3108
			$dir_attr = "dir='$text_direction'";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3109
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3110
		?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3111
<!DOCTYPE html>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3112
<html xmlns="http://www.w3.org/1999/xhtml" <?php echo $dir_attr; ?>>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3113
<head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3114
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3115
	<meta name="viewport" content="width=device-width">
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3116
		<?php
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3117
		if ( function_exists( 'wp_no_robots' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3118
			wp_no_robots();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3119
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3120
		?>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3121
	<title><?php echo $title; ?></title>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3122
	<style type="text/css">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3123
		html {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3124
			background: #f1f1f1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3125
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3126
		body {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3127
			background: #fff;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3128
			color: #444;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3129
			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
  3130
			margin: 2em auto;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3131
			padding: 1em 2em;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3132
			max-width: 700px;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3133
			-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3134
			box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3135
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3136
		h1 {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3137
			border-bottom: 1px solid #dadada;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3138
			clear: both;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3139
			color: #666;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3140
			font-size: 24px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3141
			margin: 30px 0 0 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3142
			padding: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3143
			padding-bottom: 7px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3144
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3145
		#error-page {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
			margin-top: 50px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3148
		#error-page p {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3149
			font-size: 14px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3150
			line-height: 1.5;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3151
			margin: 25px 0 20px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3152
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
		#error-page code {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3154
			font-family: Consolas, Monaco, monospace;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3155
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3156
		ul li {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
			margin-bottom: 10px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3158
			font-size: 14px ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3159
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3160
		a {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3161
			color: #0073aa;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3162
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3163
		a:hover,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3164
		a:active {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3165
			color: #00a0d2;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3166
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3167
		a:focus {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3168
			color: #124964;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3169
			-webkit-box-shadow:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3170
				0 0 0 1px #5b9dd9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3171
				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
  3172
			box-shadow:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3173
				0 0 0 1px #5b9dd9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3174
				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
  3175
			outline: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3176
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3177
		.button {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3178
			background: #f7f7f7;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3179
			border: 1px solid #ccc;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3180
			color: #555;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3181
			display: inline-block;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3182
			text-decoration: none;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3183
			font-size: 13px;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3184
			line-height: 26px;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3185
			height: 28px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3186
			margin: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3187
			padding: 0 10px 1px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3188
			cursor: pointer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3189
			-webkit-border-radius: 3px;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3190
			-webkit-appearance: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3191
			border-radius: 3px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3192
			white-space: nowrap;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3193
			-webkit-box-sizing: border-box;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3194
			-moz-box-sizing:    border-box;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3195
			box-sizing:         border-box;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3196
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3197
			-webkit-box-shadow: 0 1px 0 #ccc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3198
			box-shadow: 0 1px 0 #ccc;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3199
			 vertical-align: top;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3200
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3202
		.button.button-large {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3203
			height: 30px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3204
			line-height: 28px;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3205
			padding: 0 12px 2px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3206
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3208
		.button:hover,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3209
		.button:focus {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3210
			background: #fafafa;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3211
			border-color: #999;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3212
			color: #23282d;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3213
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3214
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3215
		.button:focus {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3216
			border-color: #5b9dd9;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3217
			-webkit-box-shadow: 0 0 3px rgba(0, 115, 170, 0.8);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3218
			box-shadow: 0 0 3px rgba(0, 115, 170, 0.8);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3219
			outline: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3220
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3222
		.button:active {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3223
			background: #eee;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3224
			border-color: #999;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3225
			 -webkit-box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3226
			 box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3227
			 -webkit-transform: translateY(1px);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3228
			 -ms-transform: translateY(1px);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3229
			 transform: translateY(1px);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3230
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3231
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3232
		<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3233
		if ( 'rtl' == $text_direction ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3234
			echo 'body { font-family: Tahoma, Arial; }';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3235
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3236
		?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3237
	</style>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3238
</head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3239
<body id="error-page">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3240
<?php endif; // ! did_action( 'admin_head' ) ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3241
	<?php echo $message; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3242
</body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3243
</html>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3244
	<?php
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3245
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3246
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3247
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3248
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3249
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3250
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3251
 * 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
  3252
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3253
 * 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
  3254
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3255
 * @since 3.4.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3256
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3257
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3258
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3259
 * @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
  3260
 * @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
  3261
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3262
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3263
	// Set default 'response' to 200 for AJAX requests.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3264
	$args = wp_parse_args(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3265
		$args,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3266
		array( 'response' => 200 )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3267
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3268
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3269
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3270
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3271
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3272
		// 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
  3273
		if ( null !== $args['response'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3274
			status_header( $r['response'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3275
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3276
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3277
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3278
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3279
	if ( is_scalar( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3280
		$message = (string) $message;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3281
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3282
		$message = '0';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3283
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3284
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3285
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3286
		die( $message );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3287
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3288
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3289
	echo $message;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3290
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3291
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3292
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3293
 * 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
  3294
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3295
 * 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
  3296
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3297
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3298
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3299
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3300
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3301
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3302
 * @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
  3303
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3304
function _json_wp_die_handler( $message, $title = '', $args = array() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3305
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3306
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3307
	$data = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3308
		'code'              => $r['code'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3309
		'message'           => $message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3310
		'data'              => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3311
			'status' => $r['response'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3312
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3313
		'additional_errors' => $r['additional_errors'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3314
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3315
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3316
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3317
		header( 'Content-Type: application/json; charset=utf-8' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3318
		if ( null !== $r['response'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3319
			status_header( $r['response'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3320
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3321
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3322
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3323
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3324
	echo wp_json_encode( $data );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3325
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3326
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3327
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3328
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3329
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3330
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3331
 * 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
  3332
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3333
 * 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
  3334
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3335
 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3336
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3337
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3338
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3339
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3340
 * @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
  3341
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3342
function _jsonp_wp_die_handler( $message, $title = '', $args = array() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3343
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3344
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3345
	$data = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3346
		'code'              => $r['code'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3347
		'message'           => $message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3348
		'data'              => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3349
			'status' => $r['response'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3350
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3351
		'additional_errors' => $r['additional_errors'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3352
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3353
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3354
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3355
		header( 'Content-Type: application/javascript; charset=utf-8' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3356
		header( 'X-Content-Type-Options: nosniff' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3357
		header( 'X-Robots-Tag: noindex' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3358
		if ( null !== $r['response'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3359
			status_header( $r['response'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3360
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3361
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3362
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3363
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3364
	$result         = wp_json_encode( $data );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3365
	$jsonp_callback = $_GET['_jsonp'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3366
	echo '/**/' . $jsonp_callback . '(' . $result . ')';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3367
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3368
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3369
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3370
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3371
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3372
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3373
 * 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
  3374
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3375
 * This is the handler for wp_die() when processing XMLRPC requests.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3376
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3377
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3378
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3379
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3380
 * @global wp_xmlrpc_server $wp_xmlrpc_server
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3381
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3382
 * @param string       $message Error message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3383
 * @param string       $title   Optional. Error title. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3384
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3385
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3386
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3387
	global $wp_xmlrpc_server;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3388
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3389
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3390
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3391
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3392
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3393
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3395
	if ( $wp_xmlrpc_server ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3396
		$error = new IXR_Error( $r['response'], $message );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3397
		$wp_xmlrpc_server->output( $error->getXml() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3398
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3399
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3400
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3401
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3402
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3403
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3404
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3405
 * 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
  3406
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3407
 * 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
  3408
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3409
 * @since 5.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3410
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3411
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3412
 * @param string       $message Error message.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3413
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3414
 * @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
  3415
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3416
function _xml_wp_die_handler( $message, $title = '', $args = array() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3417
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3418
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3419
	$message = htmlspecialchars( $message );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3420
	$title   = htmlspecialchars( $title );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3421
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3422
	$xml = <<<EOD
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3423
<error>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3424
    <code>{$r['code']}</code>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3425
    <title><![CDATA[{$title}]]></title>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3426
    <message><![CDATA[{$message}]]></message>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3427
    <data>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3428
        <status>{$r['response']}</status>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3429
    </data>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3430
</error>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3431
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3432
EOD;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3433
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3434
	if ( ! headers_sent() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3435
		header( 'Content-Type: text/xml; charset=utf-8' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3436
		if ( null !== $r['response'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3437
			status_header( $r['response'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3438
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3439
		nocache_headers();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3440
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3441
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3442
	echo $xml;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3443
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3444
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3445
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3446
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3447
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3448
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3449
 * Kills WordPress execution and displays an error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3450
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3451
 * 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
  3452
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3453
 * @since 3.4.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3454
 * @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
  3455
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3456
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3457
 * @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
  3458
 * @param string       $title   Optional. Error title (unused). Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3459
 * @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
  3460
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3461
function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3462
	list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3463
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3464
	if ( $r['exit'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3465
		if ( is_scalar( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3466
			die( (string) $message );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3467
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3468
		die();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3469
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3470
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3471
	if ( is_scalar( $message ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3472
		echo (string) $message;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3473
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3474
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3475
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3476
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3477
 * 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
  3478
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3479
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3480
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3481
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3482
 * @param string       $message Error message.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3483
 * @param string       $title   Optional. Error title. Default empty.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3484
 * @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
  3485
 * @return array List of processed $message string, $title string, and $args array.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3486
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3487
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
  3488
	$defaults = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3489
		'response'          => 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3490
		'code'              => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3491
		'exit'              => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3492
		'back_link'         => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3493
		'link_url'          => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3494
		'link_text'         => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3495
		'text_direction'    => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3496
		'additional_errors' => array(),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3497
	);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3498
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3499
	$args = wp_parse_args( $args, $defaults );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3500
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3501
	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
  3502
		if ( ! empty( $message->errors ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3503
			$errors = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3504
			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
  3505
				foreach ( (array) $error_messages as $error_message ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3506
					$errors[] = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3507
						'code'    => $error_code,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3508
						'message' => $error_message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3509
						'data'    => $message->get_error_data( $error_code ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3510
					);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3511
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3512
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3513
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3514
			$message = $errors[0]['message'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3515
			if ( empty( $args['code'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3516
				$args['code'] = $errors[0]['code'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3517
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3518
			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
  3519
				$args['response'] = $errors[0]['data']['status'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3520
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3521
			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
  3522
				$title = $errors[0]['data']['title'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3523
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3524
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3525
			unset( $errors[0] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3526
			$args['additional_errors'] = array_values( $errors );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3527
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3528
			$message = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3529
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3530
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3531
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3532
	$have_gettext = function_exists( '__' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3533
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3534
	// 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
  3535
	if ( empty( $args['code'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3536
		$args['code'] = 'wp_die';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3537
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3538
	if ( empty( $args['response'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3539
		$args['response'] = 500;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3540
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3541
	if ( empty( $title ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3542
		$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
  3543
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3544
	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
  3545
		$args['text_direction'] = 'ltr';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3546
		if ( function_exists( 'is_rtl' ) && is_rtl() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3547
			$args['text_direction'] = 'rtl';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3548
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3549
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3550
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3551
	return array( $message, $title, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3552
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3554
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3555
 * Encode a variable into JSON, with some sanity checks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3556
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3557
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3558
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3559
 * @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
  3560
 * @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
  3561
 * @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
  3562
 *                       greater than 0. Default 512.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3563
 * @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
  3564
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3565
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3566
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3567
	 * json_encode() has had extra params added over the years.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3568
	 * $options was added in 5.3, and $depth in 5.5.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3569
	 * We need to make sure we call it with the correct arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3570
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3571
	if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3572
		$args = array( $data, $options, $depth );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3573
	} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3574
		$args = array( $data, $options );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3575
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3576
		$args = array( $data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3577
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3578
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3579
	// Prepare the data for JSON serialization.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3580
	$args[0] = _wp_json_prepare_data( $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3581
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3582
	$json = @call_user_func_array( 'json_encode', $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3583
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3584
	// If json_encode() was successful, no need to do more sanity checking.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3585
	// ... unless we're in an old version of PHP, and json_encode() returned
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3586
	// a string containing 'null'. Then we need to do more sanity checking.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3587
	if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3588
		return $json;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3589
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3590
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3591
	try {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3592
		$args[0] = _wp_json_sanity_check( $data, $depth );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3593
	} catch ( Exception $e ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3594
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3595
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3596
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3597
	return call_user_func_array( 'json_encode', $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3598
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3599
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3600
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3601
 * Perform sanity checks on data that shall be encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3602
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3603
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3604
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3605
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3606
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3607
 * @see wp_json_encode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3608
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3609
 * @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
  3610
 * @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
  3611
 * @return mixed The sanitized data that shall be encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3612
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3613
function _wp_json_sanity_check( $data, $depth ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3614
	if ( $depth < 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3615
		throw new Exception( 'Reached depth limit' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3616
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3617
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3618
	if ( is_array( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3619
		$output = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3620
		foreach ( $data as $id => $el ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3621
			// Don't forget to sanitize the ID!
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3622
			if ( is_string( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3623
				$clean_id = _wp_json_convert_string( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3624
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3625
				$clean_id = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3626
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3627
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3628
			// 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
  3629
			if ( is_array( $el ) || is_object( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3630
				$output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3631
			} elseif ( is_string( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3632
				$output[ $clean_id ] = _wp_json_convert_string( $el );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3633
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3634
				$output[ $clean_id ] = $el;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3635
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3636
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3637
	} elseif ( is_object( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3638
		$output = new stdClass;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3639
		foreach ( $data as $id => $el ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3640
			if ( is_string( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3641
				$clean_id = _wp_json_convert_string( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3642
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3643
				$clean_id = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3644
			}
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_array( $el ) || is_object( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3647
				$output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3648
			} elseif ( is_string( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3649
				$output->$clean_id = _wp_json_convert_string( $el );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3650
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3651
				$output->$clean_id = $el;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3652
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3653
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3654
	} elseif ( is_string( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3655
		return _wp_json_convert_string( $data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3656
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3657
		return $data;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3658
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3659
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3660
	return $output;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3661
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3662
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3663
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3664
 * 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
  3665
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3666
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3667
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3668
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3669
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3670
 * @see _wp_json_sanity_check()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3671
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3672
 * @staticvar bool $use_mb
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3673
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3674
 * @param string $string The string which is to be converted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3675
 * @return string The checked string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3676
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3677
function _wp_json_convert_string( $string ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3678
	static $use_mb = null;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3679
	if ( is_null( $use_mb ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3680
		$use_mb = function_exists( 'mb_convert_encoding' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3681
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3682
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3683
	if ( $use_mb ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3684
		$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3685
		if ( $encoding ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3686
			return mb_convert_encoding( $string, 'UTF-8', $encoding );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3687
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3688
			return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3689
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3690
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3691
		return wp_check_invalid_utf8( $string, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3692
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3693
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3694
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3695
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3696
 * Prepares response data to be serialized to JSON.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3697
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3698
 * 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
  3699
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3700
 * @ignore
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3701
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3702
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3703
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3704
 * @param mixed $data Native representation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3705
 * @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
  3706
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3707
function _wp_json_prepare_data( $data ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3708
	if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3709
		return $data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3710
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3711
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3712
	switch ( gettype( $data ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3713
		case 'boolean':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3714
		case 'integer':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3715
		case 'double':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3716
		case 'string':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3717
		case 'NULL':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3718
			// These values can be passed through.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3719
			return $data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3720
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3721
		case 'array':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3722
			// Arrays must be mapped in case they also return objects.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3723
			return array_map( '_wp_json_prepare_data', $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3724
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3725
		case 'object':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3726
			// If this is an incomplete object (__PHP_Incomplete_Class), bail.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3727
			if ( ! is_object( $data ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3728
				return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3729
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3730
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3731
			if ( $data instanceof JsonSerializable ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3732
				$data = $data->jsonSerialize();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3733
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3734
				$data = get_object_vars( $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3735
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3736
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3737
			// Now, pass the array (or whatever was returned from jsonSerialize through).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3738
			return _wp_json_prepare_data( $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3739
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3740
		default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3741
			return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3742
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3743
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3744
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3745
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3746
 * Send a JSON response back to an Ajax request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3747
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3748
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3749
 * @since 4.7.0 The `$status_code` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3750
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3751
 * @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
  3752
 *                           then print and die.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3753
 * @param int   $status_code The HTTP status code to output.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3754
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3755
function wp_send_json( $response, $status_code = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3756
	@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3757
	if ( null !== $status_code ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3758
		status_header( $status_code );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3759
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3760
	echo wp_json_encode( $response );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3761
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3762
	if ( wp_doing_ajax() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3763
		wp_die(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3764
			'',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3765
			'',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3766
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3767
				'response' => null,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3768
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3769
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3770
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3771
		die;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3772
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3773
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3774
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3775
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3776
 * Send a JSON response back to an Ajax request, indicating success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3777
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3778
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3779
 * @since 4.7.0 The `$status_code` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3780
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3781
 * @param mixed $data        Data to encode as JSON, then print and die.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3782
 * @param int   $status_code The HTTP status code to output.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3783
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3784
function wp_send_json_success( $data = null, $status_code = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3785
	$response = array( 'success' => true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3786
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3787
	if ( isset( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3788
		$response['data'] = $data;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3789
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3790
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3791
	wp_send_json( $response, $status_code );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3792
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3794
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3795
 * Send a JSON response back to an Ajax request, indicating failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3796
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3797
 * 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
  3798
 * 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
  3799
 * codes and corresponding messages. All other types are output
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3800
 * without further processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3801
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3802
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3803
 * @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
  3804
 * @since 4.7.0 The `$status_code` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3805
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3806
 * @param mixed $data        Data to encode as JSON, then print and die.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3807
 * @param int   $status_code The HTTP status code to output.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3808
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3809
function wp_send_json_error( $data = null, $status_code = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3810
	$response = array( 'success' => false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3811
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3812
	if ( isset( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3813
		if ( is_wp_error( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3814
			$result = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3815
			foreach ( $data->errors as $code => $messages ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3816
				foreach ( $messages as $message ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3817
					$result[] = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3818
						'code'    => $code,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3819
						'message' => $message,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3820
					);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3821
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3822
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3823
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3824
			$response['data'] = $result;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3825
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3826
			$response['data'] = $data;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3827
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3828
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3829
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3830
	wp_send_json( $response, $status_code );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3831
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3832
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3833
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3834
 * Checks that a JSONP callback is a valid JavaScript callback.
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
 * 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
  3837
 * 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
  3838
 * outputting user input.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3839
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3840
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3841
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3842
 * @param string $callback Supplied JSONP callback function.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3843
 * @return bool True if valid callback, otherwise false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3844
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3845
function wp_check_jsonp_callback( $callback ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3846
	if ( ! is_string( $callback ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3847
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3848
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3849
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3850
	preg_replace( '/[^\w\.]/', '', $callback, -1, $illegal_char_count );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3851
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3852
	return 0 === $illegal_char_count;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3853
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3855
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3856
 * Retrieve the WordPress home page URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3857
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3858
 * 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
  3859
 * 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
  3860
 * development environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3861
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3862
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3863
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3864
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3865
 * @see WP_HOME
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3866
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3867
 * @param string $url URL for the home location.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3868
 * @return string Homepage location.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3869
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3870
function _config_wp_home( $url = '' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3871
	if ( defined( 'WP_HOME' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3872
		return untrailingslashit( WP_HOME );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3873
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3874
	return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3875
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3877
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3878
 * Retrieve the WordPress site URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3879
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3880
 * 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
  3881
 * 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
  3882
 * 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
  3883
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3884
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3885
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3886
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3887
 * @see WP_SITEURL
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3888
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3889
 * @param string $url URL to set the WordPress site location.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3890
 * @return string The WordPress Site URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3891
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3892
function _config_wp_siteurl( $url = '' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3893
	if ( defined( 'WP_SITEURL' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3894
		return untrailingslashit( WP_SITEURL );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3895
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3896
	return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3897
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3898
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3899
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3900
 * Delete the fresh site option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3901
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3902
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3903
 * @access private
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
function _delete_option_fresh_site() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3906
	update_option( 'fresh_site', '0' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3907
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3908
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3909
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3910
 * Set the localized direction for MCE plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3911
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3912
 * 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
  3913
 * the text direction set to 'rtl'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3914
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3915
 * Fills in the 'directionality' setting, enables the 'directionality'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3916
 * plugin, and adds the 'ltr' button to 'toolbar1', formerly
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3917
 * '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
  3918
 * in the $mce_init (TinyMCE settings) array.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3919
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3920
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3921
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3922
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3923
 * @param array $mce_init MCE settings array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3924
 * @return array Direction set for 'rtl', if needed by locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3925
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3926
function _mce_set_direction( $mce_init ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3927
	if ( is_rtl() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3928
		$mce_init['directionality'] = 'rtl';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3929
		$mce_init['rtl_ui']         = true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3930
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3931
		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
  3932
			$mce_init['plugins'] .= ',directionality';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3933
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3934
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3935
		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
  3936
			$mce_init['toolbar1'] .= ',ltr';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3937
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3938
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3939
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3940
	return $mce_init;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3941
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3942
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3943
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3944
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3945
 * Convert smiley code to the icon graphic file equivalent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3946
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3947
 * 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
  3948
 * 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
  3949
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3950
 * Plugins may override the default smiley list by setting the $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3951
 * 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
  3952
 * image file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3953
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3954
 * The $wp_smiliessearch global is for the regular expression and is set each
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3955
 * time the function is called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3956
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3957
 * 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
  3958
 * 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
  3959
 * available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3960
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3961
 * @global array $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3962
 * @global array $wp_smiliessearch
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3963
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3964
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3965
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3966
function smilies_init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3967
	global $wpsmiliestrans, $wp_smiliessearch;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3968
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3969
	// 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
  3970
	if ( ! get_option( 'use_smilies' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3971
		return;
9
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
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3974
	if ( ! isset( $wpsmiliestrans ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3975
		$wpsmiliestrans = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3976
			':mrgreen:' => 'mrgreen.png',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3977
			':neutral:' => "\xf0\x9f\x98\x90",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3978
			':twisted:' => "\xf0\x9f\x98\x88",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3979
			':arrow:'   => "\xe2\x9e\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3980
			':shock:'   => "\xf0\x9f\x98\xaf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3981
			':smile:'   => "\xf0\x9f\x99\x82",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3982
			':???:'     => "\xf0\x9f\x98\x95",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3983
			':cool:'    => "\xf0\x9f\x98\x8e",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3984
			':evil:'    => "\xf0\x9f\x91\xbf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3985
			':grin:'    => "\xf0\x9f\x98\x80",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3986
			':idea:'    => "\xf0\x9f\x92\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3987
			':oops:'    => "\xf0\x9f\x98\xb3",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3988
			':razz:'    => "\xf0\x9f\x98\x9b",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3989
			':roll:'    => "\xf0\x9f\x99\x84",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3990
			':wink:'    => "\xf0\x9f\x98\x89",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3991
			':cry:'     => "\xf0\x9f\x98\xa5",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3992
			':eek:'     => "\xf0\x9f\x98\xae",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3993
			':lol:'     => "\xf0\x9f\x98\x86",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3994
			':mad:'     => "\xf0\x9f\x98\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3995
			':sad:'     => "\xf0\x9f\x99\x81",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3996
			'8-)'       => "\xf0\x9f\x98\x8e",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3997
			'8-O'       => "\xf0\x9f\x98\xaf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3998
			':-('       => "\xf0\x9f\x99\x81",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3999
			':-)'       => "\xf0\x9f\x99\x82",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4000
			':-?'       => "\xf0\x9f\x98\x95",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4001
			':-D'       => "\xf0\x9f\x98\x80",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4002
			':-P'       => "\xf0\x9f\x98\x9b",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4003
			':-o'       => "\xf0\x9f\x98\xae",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4004
			':-x'       => "\xf0\x9f\x98\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4005
			':-|'       => "\xf0\x9f\x98\x90",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4006
			';-)'       => "\xf0\x9f\x98\x89",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4007
			// This one transformation breaks regular text with frequency.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4008
			//     '8)' => "\xf0\x9f\x98\x8e",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4009
			'8O'        => "\xf0\x9f\x98\xaf",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4010
			':('        => "\xf0\x9f\x99\x81",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4011
			':)'        => "\xf0\x9f\x99\x82",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4012
			':?'        => "\xf0\x9f\x98\x95",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4013
			':D'        => "\xf0\x9f\x98\x80",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4014
			':P'        => "\xf0\x9f\x98\x9b",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4015
			':o'        => "\xf0\x9f\x98\xae",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4016
			':x'        => "\xf0\x9f\x98\xa1",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4017
			':|'        => "\xf0\x9f\x98\x90",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4018
			';)'        => "\xf0\x9f\x98\x89",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4019
			':!:'       => "\xe2\x9d\x97",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4020
			':?:'       => "\xe2\x9d\x93",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4021
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4022
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4023
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4024
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4025
	 * Filters all the smilies.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4026
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4027
	 * 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
  4028
	 * 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
  4029
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4030
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4031
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4032
	 * @param array $wpsmiliestrans List of the smilies.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4033
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4034
	$wpsmiliestrans = apply_filters( 'smilies', $wpsmiliestrans );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4035
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4036
	if ( count( $wpsmiliestrans ) == 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4037
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4038
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4039
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4040
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4041
	 * 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
  4042
	 * we match the longest possible smilie (:???: vs :?) as the regular
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4043
	 * expression used below is first-match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4044
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4045
	krsort( $wpsmiliestrans );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4046
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4047
	$spaces = wp_spaces_regexp();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4048
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4049
	// Begin first "subpattern"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4050
	$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4051
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4052
	$subchar = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4053
	foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4054
		$firstchar = substr( $smiley, 0, 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4055
		$rest      = substr( $smiley, 1 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4056
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4057
		// new subpattern?
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4058
		if ( $firstchar != $subchar ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4059
			if ( $subchar != '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4060
				$wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4061
				$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4062
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4063
			$subchar           = $firstchar;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4064
			$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4065
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4066
			$wp_smiliessearch .= '|';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4067
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4068
		$wp_smiliessearch .= preg_quote( $rest, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4069
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4070
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4071
	$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4072
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4073
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4074
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4075
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4076
 * Merge user defined arguments into defaults array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4077
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4078
 * This function is used throughout WordPress to allow for both string or array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4079
 * to be merged into another array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4080
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4081
 * @since 2.2.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4082
 * @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
  4083
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4084
 * @param string|array|object $args     Value to merge with $defaults.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4085
 * @param array               $defaults Optional. Array that serves as the defaults. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4086
 * @return array Merged user defined values with defaults.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4087
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4088
function wp_parse_args( $args, $defaults = '' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4089
	if ( is_object( $args ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4090
		$r = get_object_vars( $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4091
	} elseif ( is_array( $args ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4092
		$r =& $args;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4093
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4094
		wp_parse_str( $args, $r );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4095
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4096
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4097
	if ( is_array( $defaults ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4098
		return array_merge( $defaults, $r );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4099
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4100
	return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4101
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4103
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4104
 * Cleans up an array, comma- or space-separated list of scalar values.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4105
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4106
 * @since 5.1.0
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
 * @param array|string $list List of values.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4109
 * @return array Sanitized array of values.
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
function wp_parse_list( $list ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4112
	if ( ! is_array( $list ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4113
		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
  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
	return $list;
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
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4119
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4120
 * Clean up an array, comma- or space-separated list of IDs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4121
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4122
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4123
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4124
 * @param array|string $list List of ids.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4125
 * @return array Sanitized array of IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4126
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4127
function wp_parse_id_list( $list ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4128
	$list = wp_parse_list( $list );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4129
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4130
	return array_unique( array_map( 'absint', $list ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4131
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4133
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4134
 * Clean up an array, comma- or space-separated list of slugs.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4135
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4136
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4137
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4138
 * @param  array|string $list List of slugs.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4139
 * @return array Sanitized array of slugs.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4140
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4141
function wp_parse_slug_list( $list ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4142
	$list = wp_parse_list( $list );
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
	return array_unique( array_map( 'sanitize_title', $list ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4145
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4146
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4147
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4148
 * Extract a slice of an array, given a list of keys.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4149
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4150
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4151
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4152
 * @param array $array The original array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4153
 * @param array $keys  The list of keys.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4154
 * @return array The array slice.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4155
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4156
function wp_array_slice_assoc( $array, $keys ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4157
	$slice = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4158
	foreach ( $keys as $key ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4159
		if ( isset( $array[ $key ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4160
			$slice[ $key ] = $array[ $key ];
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
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4164
	return $slice;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4165
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4167
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4168
 * Determines if the variable is a numeric-indexed array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4169
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4170
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4171
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4172
 * @param mixed $data Variable to check.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4173
 * @return bool Whether the variable is a list.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4174
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4175
function wp_is_numeric_array( $data ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4176
	if ( ! is_array( $data ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4177
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4178
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4179
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4180
	$keys        = array_keys( $data );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4181
	$string_keys = array_filter( $keys, 'is_string' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4182
	return count( $string_keys ) === 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4183
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4184
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4185
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4186
 * Filters a list of objects, based on a set of key => value arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4187
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4188
 * @since 3.0.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4189
 * @since 4.7.0 Uses `WP_List_Util` class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4190
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4191
 * @param array       $list     An array of objects to filter
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4192
 * @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
  4193
 *                              against each object. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4194
 * @param string      $operator Optional. The logical operation to perform. 'or' means
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4195
 *                              only one element from the array needs to match; 'and'
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4196
 *                              means all elements must match; 'not' means no elements may
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4197
 *                              match. Default 'and'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4198
 * @param bool|string $field    A field from the object to place instead of the entire object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4199
 *                              Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4200
 * @return array A list of objects or object fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4201
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4202
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
  4203
	if ( ! is_array( $list ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4204
		return array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4205
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4206
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4207
	$util = new WP_List_Util( $list );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4208
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4209
	$util->filter( $args, $operator );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4210
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4211
	if ( $field ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4212
		$util->pluck( $field );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4213
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4214
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4215
	return $util->get_output();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4216
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4218
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4219
 * Filters a list of objects, based on a set of key => value arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4220
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4221
 * @since 3.1.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4222
 * @since 4.7.0 Uses `WP_List_Util` class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4223
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4224
 * @param array  $list     An array of objects to filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4225
 * @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
  4226
 *                         against each object. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4227
 * @param string $operator Optional. The logical operation to perform. 'AND' means
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4228
 *                         all elements from the array must match. 'OR' means only
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4229
 *                         one element needs to match. 'NOT' means no elements may
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4230
 *                         match. Default 'AND'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4231
 * @return array Array of found values.
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
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4234
	if ( ! is_array( $list ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4235
		return array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4236
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4237
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4238
	$util = new WP_List_Util( $list );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4239
	return $util->filter( $args, $operator );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4240
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4242
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4243
 * Pluck a certain field out of each object in a list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4244
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4245
 * This has the same functionality and prototype of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4246
 * array_column() (PHP 5.5) but also supports objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4247
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4248
 * @since 3.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4249
 * @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
  4250
 * @since 4.7.0 Uses `WP_List_Util` class.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4251
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4252
 * @param array      $list      List of objects or arrays
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4253
 * @param int|string $field     Field from the object to place instead of the entire object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4254
 * @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
  4255
 *                              Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4256
 * @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
  4257
 *               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
  4258
 *               `$list` will be preserved in the results.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4259
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4260
function wp_list_pluck( $list, $field, $index_key = null ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4261
	$util = new WP_List_Util( $list );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4262
	return $util->pluck( $field, $index_key );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4263
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4264
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4265
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4266
 * Sorts a list of objects, based on one or more orderby arguments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4267
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4268
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4269
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4270
 * @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
  4271
 * @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
  4272
 *                                    of multiple orderby fields as $orderby => $order.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4273
 * @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
  4274
 *                                    is a string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4275
 * @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
  4276
 * @return array The sorted array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4277
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4278
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
  4279
	if ( ! is_array( $list ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4280
		return array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4281
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4282
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4283
	$util = new WP_List_Util( $list );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4284
	return $util->sort( $orderby, $order, $preserve_keys );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4285
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4287
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4288
 * Determines if Widgets library should be loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4289
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4290
 * 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
  4291
 * 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
  4292
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4293
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4294
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4295
function wp_maybe_load_widgets() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4296
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4297
	 * Filters whether to load the Widgets library.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4298
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4299
	 * Passing a falsey value to the filter will effectively short-circuit
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4300
	 * the Widgets library from loading.
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
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4303
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4304
	 * @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
  4305
	 *                                    Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4306
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4307
	if ( ! apply_filters( 'load_default_widgets', true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4308
		return;
5
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
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4311
	require_once( ABSPATH . WPINC . '/default-widgets.php' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4312
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4313
	add_action( '_admin_menu', 'wp_widgets_add_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4314
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4316
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4317
 * Append the Widgets menu to the themes main menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4319
 * @since 2.2.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4320
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4321
 * @global array $submenu
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4322
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4323
function wp_widgets_add_menu() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4324
	global $submenu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4325
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4326
	if ( ! current_theme_supports( 'widgets' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4327
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4328
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4330
	$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4331
	ksort( $submenu['themes.php'], SORT_NUMERIC );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4332
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4334
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4335
 * Flush all output buffers for PHP 5.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4336
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4337
 * Make sure all output buffers are flushed before our singletons are destroyed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4338
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4339
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4340
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4341
function wp_ob_end_flush_all() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4342
	$levels = ob_get_level();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4343
	for ( $i = 0; $i < $levels; $i++ ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4344
		ob_end_flush();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4345
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4346
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4348
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4349
 * Load custom DB error or display WordPress DB error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4350
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4351
 * 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
  4352
 * 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
  4353
 * then the WordPress DB error will be displayed instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4354
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4355
 * 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
  4356
 * search engines from caching the message. Custom DB messages should do the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4357
 * same.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4359
 * This function was backported to WordPress 2.3.2, but originally was added
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4360
 * in WordPress 2.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4361
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4362
 * @since 2.3.2
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4363
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4364
 * @global wpdb $wpdb WordPress database abstraction object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4365
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4366
function dead_db() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4367
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4368
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4369
	wp_load_translations_early();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4370
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4371
	// Load custom DB error template, if present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4372
	if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4373
		require_once( WP_CONTENT_DIR . '/db-error.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4374
		die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4375
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4377
	// 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
  4378
	if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4379
		wp_die( $wpdb->error );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4380
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4382
	// Otherwise, be terse.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4383
	wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4384
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4385
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4386
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4387
 * Convert a value to non-negative integer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4388
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4389
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4390
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4391
 * @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
  4392
 * @return int A non-negative integer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4393
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4394
function absint( $maybeint ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4395
	return abs( intval( $maybeint ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4396
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4398
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4399
 * Mark a function as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4400
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4401
 * 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
  4402
 * to get the backtrace up to what file and function called the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4403
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4404
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4405
 * 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
  4406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4407
 * This function is to be used in every function that is deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4408
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4409
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4410
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4411
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4412
 * @param string $function    The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4413
 * @param string $version     The version of WordPress that deprecated the function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4414
 * @param string $replacement Optional. The function that should have been called. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4415
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4416
function _deprecated_function( $function, $version, $replacement = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4417
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4418
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4419
	 * Fires when a deprecated function is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4420
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4421
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4422
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4423
	 * @param string $function    The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4424
	 * @param string $replacement The function that should have been called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4425
	 * @param string $version     The version of WordPress that deprecated the function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4426
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4427
	do_action( 'deprecated_function_run', $function, $replacement, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4428
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4429
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4430
	 * Filters whether to trigger an error for deprecated functions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4431
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4432
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4433
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4434
	 * @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
  4435
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4436
	if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4437
		if ( function_exists( '__' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4438
			if ( ! is_null( $replacement ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4439
				/* translators: 1: PHP function name, 2: version number, 3: alternative function name */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4440
				trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4441
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4442
				/* translators: 1: PHP function name, 2: version number */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4443
				trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4444
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4445
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4446
			if ( ! is_null( $replacement ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4447
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4448
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4449
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4450
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4451
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4452
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4453
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4455
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4456
 * 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
  4457
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4458
 * 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
  4459
 * remove PHP4 style constructors.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4460
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4461
 * 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
  4462
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4463
 * 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
  4464
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4465
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4466
 * @since 4.5.0 Added the `$parent_class` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4467
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4468
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4469
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4470
 * @param string $class        The class containing the deprecated constructor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4471
 * @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
  4472
 * @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
  4473
 *                             Default empty string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4474
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4475
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4476
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4477
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4478
	 * Fires when a deprecated constructor is called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4479
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4480
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4481
	 * @since 4.5.0 Added the `$parent_class` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4482
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4483
	 * @param string $class        The class containing the deprecated constructor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4484
	 * @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
  4485
	 * @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
  4486
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4487
	do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4488
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
	 * Filters whether to trigger an error for deprecated functions.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4491
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4492
	 * `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
  4493
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4494
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4495
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4496
	 * @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
  4497
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4498
	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
  4499
		if ( function_exists( '__' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4500
			if ( ! empty( $parent_class ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4501
				/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4502
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4503
					sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4504
						__( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4505
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4506
						$parent_class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4507
						$version,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4508
						'<pre>__construct()</pre>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4509
					)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4510
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4511
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4512
				/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4513
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4514
					sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4515
						__( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4516
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4517
						$version,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4518
						'<pre>__construct()</pre>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4519
					)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4520
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4521
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4522
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4523
			if ( ! empty( $parent_class ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4524
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4525
					sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4526
						'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4527
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4528
						$parent_class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4529
						$version,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4530
						'<pre>__construct()</pre>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4531
					)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4532
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4533
			} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4534
				trigger_error(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4535
					sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4536
						'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4537
						$class,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4538
						$version,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4539
						'<pre>__construct()</pre>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4540
					)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4541
				);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4542
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4543
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4544
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4545
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4546
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4547
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4548
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4549
 * Mark a file as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4550
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4551
 * 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
  4552
 * to get the backtrace up to what file and function included the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4553
 * file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4554
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4555
 * 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
  4556
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4557
 * This function is to be used in every file that is deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4558
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4559
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4560
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4561
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4562
 * @param string $file        The file that was included.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4563
 * @param string $version     The version of WordPress that deprecated the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4564
 * @param string $replacement Optional. The file that should have been included based on ABSPATH.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4565
 *                            Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4566
 * @param string $message     Optional. A message regarding the change. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4567
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4568
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4569
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4570
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4571
	 * Fires when a deprecated file is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4572
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4573
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4574
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4575
	 * @param string $file        The file that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4576
	 * @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
  4577
	 * @param string $version     The version of WordPress that deprecated the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4578
	 * @param string $message     A message regarding the change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4579
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4580
	do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4581
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4582
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4583
	 * Filters whether to trigger an error for deprecated files.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4584
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4585
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4586
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4587
	 * @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
  4588
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4589
	if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4590
		$message = empty( $message ) ? '' : ' ' . $message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4591
		if ( function_exists( '__' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4592
			if ( ! is_null( $replacement ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4593
				/* translators: 1: PHP file name, 2: version number, 3: alternative file name */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4594
				trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $file, $version, $replacement ) . $message );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4595
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4596
				/* translators: 1: PHP file name, 2: version number */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4597
				trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $file, $version ) . $message );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4598
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4599
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4600
			if ( ! is_null( $replacement ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4601
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4602
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4603
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4604
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4605
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4606
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4607
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4608
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4609
 * 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
  4610
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4611
 * This function is to be used whenever a deprecated function argument is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4612
 * 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
  4613
 * 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
  4614
 * For example:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4615
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4616
 *     if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4617
 *         _deprecated_argument( __FUNCTION__, '3.0.0' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4618
 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4619
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4620
 * 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
  4621
 * to get the backtrace up to what file and function used the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4622
 * argument.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4624
 * 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
  4625
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4626
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4627
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4628
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4629
 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4630
 * @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
  4631
 * @param string $message  Optional. A message regarding the change. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4632
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4633
function _deprecated_argument( $function, $version, $message = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4634
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
	 * Fires when a deprecated argument is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4637
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4638
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4639
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4640
	 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4641
	 * @param string $message  A message regarding the change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4642
	 * @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
  4643
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4644
	do_action( 'deprecated_argument_run', $function, $message, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4645
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4646
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4647
	 * Filters whether to trigger an error for deprecated arguments.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4648
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4649
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4650
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4651
	 * @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
  4652
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4653
	if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4654
		if ( function_exists( '__' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4655
			if ( ! is_null( $message ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4656
				/* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4657
				trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), $function, $version, $message ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4658
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4659
				/* translators: 1: PHP function name, 2: version number */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4660
				trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4661
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4662
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4663
			if ( ! is_null( $message ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4664
				trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4665
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4666
				trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4667
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4668
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4669
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4670
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4671
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4672
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4673
 * 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
  4674
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4675
 * 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
  4676
 * the deprecated hook was called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4677
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4678
 * 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
  4679
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4680
 * 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
  4681
 * 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
  4682
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4683
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4684
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4685
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4686
 * @param string $hook        The hook that was used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4687
 * @param string $version     The version of WordPress that deprecated the hook.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4688
 * @param string $replacement Optional. The hook that should have been used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4689
 * @param string $message     Optional. A message regarding the change.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4690
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4691
function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4692
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4693
	 * Fires when a deprecated hook is called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4694
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4695
	 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4696
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4697
	 * @param string $hook        The hook that was called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4698
	 * @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
  4699
	 * @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
  4700
	 * @param string $message     A message regarding the change.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4701
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4702
	do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4703
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4704
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4705
	 * Filters whether to trigger deprecated hook errors.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4706
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4707
	 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4708
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4709
	 * @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
  4710
	 *                      `WP_DEBUG` to be defined true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4711
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4712
	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
  4713
		$message = empty( $message ) ? '' : ' ' . $message;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4714
		if ( ! is_null( $replacement ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4715
			/* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4716
			trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4717
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4718
			/* translators: 1: WordPress hook name, 2: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4719
			trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4720
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4721
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4722
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4723
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4724
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4725
 * Mark something as being incorrectly called.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4726
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4727
 * 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
  4728
 * to get the backtrace up to what file and function called the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4729
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4730
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4731
 * 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
  4732
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4733
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4734
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4735
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4736
 * @param string $function The function that was called.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4737
 * @param string $message  A message explaining what has been done incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4738
 * @param string $version  The version of WordPress where the message was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4739
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4740
function _doing_it_wrong( $function, $message, $version ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4741
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4742
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4743
	 * Fires when the given function is being used incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4744
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4745
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4746
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4747
	 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4748
	 * @param string $message  A message explaining what has been done incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4749
	 * @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
  4750
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4751
	do_action( 'doing_it_wrong_run', $function, $message, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4752
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4753
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4754
	 * 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
  4755
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4756
	 * @since 3.1.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4757
	 * @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
  4758
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4759
	 * @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
  4760
	 * @param string $function The function that was called.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4761
	 * @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
  4762
	 * @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
  4763
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4764
	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
  4765
		if ( function_exists( '__' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4766
			if ( is_null( $version ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4767
				$version = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4768
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4769
				/* translators: %s: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4770
				$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
  4771
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4772
			/* translators: %s: Codex URL */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4773
			$message .= ' ' . sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4774
				__( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4775
				__( 'https://codex.wordpress.org/Debugging_in_WordPress' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4776
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4777
			/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4778
			trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4779
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4780
			if ( is_null( $version ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4781
				$version = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4782
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4783
				$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
  4784
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4785
			$message .= sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4786
				' Please see <a href="%s">Debugging in WordPress</a> for more information.',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4787
				'https://codex.wordpress.org/Debugging_in_WordPress'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4788
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4789
			trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4790
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4791
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4792
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4794
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4795
 * Is the server running earlier than 1.5.0 version of lighttpd?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4796
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4797
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4798
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4799
 * @return bool Whether the server is running lighttpd < 1.5.0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4800
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4801
function is_lighttpd_before_150() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4802
	$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
  4803
	$server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4804
	return  'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4805
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4807
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4808
 * Does the specified module exist in the Apache config?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4809
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4810
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4811
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4812
 * @global bool $is_apache
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4813
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4814
 * @param string $mod     The module, e.g. mod_rewrite.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4815
 * @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
  4816
 * @return bool Whether the specified module is loaded.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4817
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4818
function apache_mod_loaded( $mod, $default = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4819
	global $is_apache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4820
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4821
	if ( ! $is_apache ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4822
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4823
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4824
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4825
	if ( function_exists( 'apache_get_modules' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4826
		$mods = apache_get_modules();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4827
		if ( in_array( $mod, $mods ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4828
			return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4829
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4830
	} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4831
			ob_start();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4832
			phpinfo( 8 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4833
			$phpinfo = ob_get_clean();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4834
		if ( false !== strpos( $phpinfo, $mod ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4835
			return true;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4836
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4837
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4838
	return $default;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4839
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4841
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4842
 * Check if IIS 7+ supports pretty permalinks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4843
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4844
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4845
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4846
 * @global bool $is_iis7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4847
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4848
 * @return bool Whether IIS7 supports permalinks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4849
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4850
function iis7_supports_permalinks() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4851
	global $is_iis7;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4852
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4853
	$supports_permalinks = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4854
	if ( $is_iis7 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4855
		/* 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
  4856
		 * 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
  4857
		 * pretty permalinks cannot be used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4858
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4859
		 * 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
  4860
		 * 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
  4861
		 * 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
  4862
		 * via ISAPI then pretty permalinks will not work.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4863
		 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4864
		$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( PHP_SAPI == 'cgi-fcgi' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4865
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4866
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4867
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4868
	 * Filters whether IIS 7+ supports pretty permalinks.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4869
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4870
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4871
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4872
	 * @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4873
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4874
	return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4875
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4877
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4878
 * 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
  4879
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4880
 * 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
  4881
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4882
 * 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
  4883
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4884
 * 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
  4885
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4886
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4887
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4888
 * @param string $file          File path.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4889
 * @param array  $allowed_files Optional. List of allowed files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4890
 * @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
  4891
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4892
function validate_file( $file, $allowed_files = array() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4893
	// `../` on its own is not allowed:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4894
	if ( '../' === $file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4895
		return 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4896
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4897
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4898
	// More than one occurence of `../` is not allowed:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4899
	if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4900
		return 1;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4901
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4902
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4903
	// `../` 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
  4904
	if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4905
		return 1;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4906
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4907
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4908
	// Files not in the allowed file list are not allowed:
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4909
	if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4910
		return 3;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4911
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4912
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4913
	// Absolute Windows drive paths are not allowed:
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4914
	if ( ':' == substr( $file, 1, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4915
		return 2;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4916
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4917
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4918
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4919
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4921
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4922
 * Whether to force SSL used for the Administration Screens.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4923
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4924
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4925
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4926
 * @staticvar bool $forced
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4927
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4928
 * @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
  4929
 * @return bool True if forced, false if not forced.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4930
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4931
function force_ssl_admin( $force = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4932
	static $forced = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4933
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4934
	if ( ! is_null( $force ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4935
		$old_forced = $forced;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4936
		$forced     = $force;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4937
		return $old_forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4938
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4940
	return $forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4941
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4942
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4943
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4944
 * Guess the URL for the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4945
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4946
 * 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
  4947
 * directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4948
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4949
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4950
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4951
 * @return string The guessed URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4952
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4953
function wp_guess_url() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4954
	if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4955
		$url = WP_SITEURL;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4956
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4957
		$abspath_fix         = str_replace( '\\', '/', ABSPATH );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4958
		$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4960
		// The request is for the admin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4961
		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
  4962
			$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4963
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4964
			// The request is for a file in ABSPATH
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4965
		} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4966
			// Strip off any file/query params in the path
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4967
			$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4968
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4969
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4970
			if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4971
				// Request is hitting a file inside ABSPATH
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4972
				$directory = str_replace( ABSPATH, '', $script_filename_dir );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4973
				// Strip off the sub directory, and any file/query params
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4974
				$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4975
			} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4976
				// Request is hitting a file above ABSPATH
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4977
				$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4978
				// Strip off any file/query params from the path, appending the sub directory to the installation
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4979
				$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4980
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4981
				$path = $_SERVER['REQUEST_URI'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4982
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4983
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4985
		$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
  4986
		$url    = $schema . $_SERVER['HTTP_HOST'] . $path;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4987
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4988
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4989
	return rtrim( $url, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4990
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4992
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4993
 * Temporarily suspend cache additions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4994
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4995
 * Stops more data being added to the cache, but still allows cache retrieval.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4996
 * 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
  4997
 * be almost uselessly added to the cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4998
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4999
 * Suspension lasts for a single page load at most. Remember to call this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5000
 * function again if you wish to re-enable cache adds earlier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5001
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5002
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5003
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5004
 * @staticvar bool $_suspend
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5005
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5006
 * @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5007
 * @return bool The current suspend setting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5008
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5009
function wp_suspend_cache_addition( $suspend = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5010
	static $_suspend = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5011
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5012
	if ( is_bool( $suspend ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5013
		$_suspend = $suspend;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5014
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5015
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5016
	return $_suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5017
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5018
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5019
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5020
 * Suspend cache invalidation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5021
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5022
 * 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
  5023
 * 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
  5024
 * doing won't lead to an inconsistent cache when invalidation is suspended.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5025
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5026
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5027
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5028
 * @global bool $_wp_suspend_cache_invalidation
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5029
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5030
 * @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
  5031
 * @return bool The current suspend setting.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5032
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5033
function wp_suspend_cache_invalidation( $suspend = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5034
	global $_wp_suspend_cache_invalidation;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5035
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5036
	$current_suspend                = $_wp_suspend_cache_invalidation;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5037
	$_wp_suspend_cache_invalidation = $suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5038
	return $current_suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5039
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5040
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5041
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5042
 * Determine whether a site is the main site of the current network.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5043
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5044
 * @since 3.0.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5045
 * @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
  5046
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5047
 * @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
  5048
 * @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
  5049
 *                        Defaults to current network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5050
 * @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
  5051
 *              running Multisite.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5052
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5053
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
  5054
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5055
		return true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5056
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5057
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5058
	if ( ! $site_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5059
		$site_id = get_current_blog_id();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5060
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5061
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5062
	$site_id = (int) $site_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5063
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5064
	return $site_id === get_main_site_id( $network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5065
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5066
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5067
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5068
 * Gets the main site ID.
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.9.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 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
  5073
 *                        Defaults to the current network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5074
 * @return int The ID of the main site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5075
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5076
function get_main_site_id( $network_id = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5077
	if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5078
		return get_current_blog_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5079
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5080
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5081
	$network = get_network( $network_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5082
	if ( ! $network ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5083
		return 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
	return $network->site_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5087
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5088
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5089
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5090
 * Determine whether a network is the main network of the Multisite installation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5091
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5092
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5093
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5094
 * @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
  5095
 * @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
  5096
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5097
function is_main_network( $network_id = null ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5098
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5099
		return true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5100
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5101
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5102
	if ( null === $network_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5103
		$network_id = get_current_network_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5104
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5105
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5106
	$network_id = (int) $network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5107
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5108
	return ( $network_id === get_main_network_id() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5109
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5110
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5111
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5112
 * Get the main network ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5113
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5114
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5115
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5116
 * @return int The ID of the main network.
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
function get_main_network_id() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5119
	if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5120
		return 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5121
	}
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
	$current_network = get_network();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5124
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5125
	if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5126
		$main_network_id = PRIMARY_NETWORK_ID;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5127
	} 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
  5128
		// 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
  5129
		$main_network_id = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5130
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5131
		$_networks       = get_networks(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5132
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5133
				'fields' => 'ids',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5134
				'number' => 1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5135
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5136
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5137
		$main_network_id = array_shift( $_networks );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5138
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5139
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5140
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5141
	 * Filters the main network ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5142
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5143
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5144
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5145
	 * @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
  5146
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5147
	return (int) apply_filters( 'get_main_network_id', $main_network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5148
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5150
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5151
 * Determine whether global terms are enabled.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5152
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5153
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5154
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5155
 * @staticvar bool $global_terms
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5156
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5157
 * @return bool True if multisite and global terms enabled.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5158
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5159
function global_terms_enabled() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5160
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5161
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5162
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5164
	static $global_terms = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5165
	if ( is_null( $global_terms ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5166
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5167
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5168
		 * Filters whether global terms are enabled.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5169
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5170
		 * Passing a non-null value to the filter will effectively short-circuit the function,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5171
		 * returning the value of the 'global_terms_enabled' site option instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5172
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5173
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5174
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5175
		 * @param null $enabled Whether global terms are enabled.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5176
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5177
		$filter = apply_filters( 'global_terms_enabled', null );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5178
		if ( ! is_null( $filter ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5179
			$global_terms = (bool) $filter;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5180
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5181
			$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
  5182
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5183
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5184
	return $global_terms;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5185
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5187
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5188
 * Determines whether site meta is enabled.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5189
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5190
 * 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
  5191
 * 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
  5192
 * 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
  5193
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5194
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5195
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5196
 * @global wpdb $wpdb WordPress database abstraction object.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5197
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5198
 * @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
  5199
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5200
function is_site_meta_supported() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5201
	global $wpdb;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5202
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5203
	if ( ! is_multisite() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5204
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5205
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5206
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5207
	$network_id = get_main_network_id();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5208
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5209
	$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
  5210
	if ( false === $supported ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5211
		$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
  5212
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5213
		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
  5214
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5215
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5216
	return (bool) $supported;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5217
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5218
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5219
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5220
 * gmt_offset modification for smart timezone handling.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5221
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5222
 * Overrides the gmt_offset option if we have a timezone_string available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5223
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5224
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5225
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5226
 * @return float|false Timezone GMT offset, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5227
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5228
function wp_timezone_override_offset() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5229
	if ( ! $timezone_string = get_option( 'timezone_string' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5230
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5231
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5233
	$timezone_object = timezone_open( $timezone_string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5234
	$datetime_object = date_create();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5235
	if ( false === $timezone_object || false === $datetime_object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5236
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5237
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5238
	return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5242
 * Sort-helper for timezones.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5244
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5245
 * @access private
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5246
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5247
 * @param array $a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5248
 * @param array $b
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5249
 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5250
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5251
function _wp_timezone_choice_usort_callback( $a, $b ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5252
	// Don't use translated versions of Etc
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5253
	if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5254
		// Make the order of these more like the old dropdown
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5255
		if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5256
			return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5257
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5258
		if ( 'UTC' === $a['city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5259
			if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5260
				return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5261
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5262
			return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5263
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5264
		if ( 'UTC' === $b['city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5265
			if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5266
				return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5267
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5268
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5269
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5270
		return strnatcasecmp( $a['city'], $b['city'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5271
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5272
	if ( $a['t_continent'] == $b['t_continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5273
		if ( $a['t_city'] == $b['t_city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5274
			return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5275
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5276
		return strnatcasecmp( $a['t_city'], $b['t_city'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5277
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5278
		// Force Etc to the bottom of the list
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5279
		if ( 'Etc' === $a['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5280
			return 1;
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 ( 'Etc' === $b['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5283
			return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5284
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5285
		return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5286
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5287
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5288
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5289
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5290
 * Gives a nicely-formatted list of timezone strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5291
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5292
 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5293
 * @since 4.7.0 Added the `$locale` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5294
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5295
 * @staticvar bool $mo_loaded
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5296
 * @staticvar string $locale_loaded
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5297
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5298
 * @param string $selected_zone Selected timezone.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5299
 * @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
  5300
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5301
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5302
function wp_timezone_choice( $selected_zone, $locale = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5303
	static $mo_loaded = false, $locale_loaded = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5304
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5305
	$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5306
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5307
	// Load translations for continents and cities.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5308
	if ( ! $mo_loaded || $locale !== $locale_loaded ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5309
		$locale_loaded = $locale ? $locale : get_locale();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5310
		$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
  5311
		unload_textdomain( 'continents-cities' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5312
		load_textdomain( 'continents-cities', $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5313
		$mo_loaded = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5314
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5316
	$zonen = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5317
	foreach ( timezone_identifiers_list() as $zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5318
		$zone = explode( '/', $zone );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5319
		if ( ! in_array( $zone[0], $continents ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5320
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5321
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5323
		// 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
  5324
		$exists    = array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5325
			0 => ( isset( $zone[0] ) && $zone[0] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5326
			1 => ( isset( $zone[1] ) && $zone[1] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5327
			2 => ( isset( $zone[2] ) && $zone[2] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5328
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5329
		$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5330
		$exists[4] = ( $exists[1] && $exists[3] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5331
		$exists[5] = ( $exists[2] && $exists[3] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5332
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5333
		// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5334
		$zonen[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5335
			'continent'   => ( $exists[0] ? $zone[0] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5336
			'city'        => ( $exists[1] ? $zone[1] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5337
			'subcity'     => ( $exists[2] ? $zone[2] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5338
			't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5339
			'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
  5340
			't_subcity'   => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5341
		);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5342
		// phpcs:enable
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5343
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5344
	usort( $zonen, '_wp_timezone_choice_usort_callback' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5346
	$structure = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5348
	if ( empty( $selected_zone ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5349
		$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5350
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5352
	foreach ( $zonen as $key => $zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5353
		// Build value in an array to join later
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5354
		$value = array( $zone['continent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5356
		if ( empty( $zone['city'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5357
			// It's at the continent level (generally won't happen)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5358
			$display = $zone['t_continent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5359
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5360
			// It's inside a continent group
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5362
			// Continent optgroup
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5363
			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
  5364
				$label       = $zone['t_continent'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5365
				$structure[] = '<optgroup label="' . esc_attr( $label ) . '">';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5366
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5368
			// Add the city to the value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5369
			$value[] = $zone['city'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5370
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5371
			$display = $zone['t_city'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5372
			if ( ! empty( $zone['subcity'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5373
				// Add the subcity to the value
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5374
				$value[]  = $zone['subcity'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5375
				$display .= ' - ' . $zone['t_subcity'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5376
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5377
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5378
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5379
		// Build the value
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5380
		$value    = join( '/', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5381
		$selected = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5382
		if ( $value === $selected_zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5383
			$selected = 'selected="selected" ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5384
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5385
		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5387
		// Close continent optgroup
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5388
		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
  5389
			$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5390
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5391
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5392
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5393
	// Do UTC
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5394
	$structure[] = '<optgroup label="' . esc_attr__( 'UTC' ) . '">';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5395
	$selected    = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5396
	if ( 'UTC' === $selected_zone ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5397
		$selected = 'selected="selected" ';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5398
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5399
	$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __( 'UTC' ) . '</option>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5400
	$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5402
	// Do manual UTC offsets
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5403
	$structure[]  = '<optgroup label="' . esc_attr__( 'Manual Offsets' ) . '">';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5404
	$offset_range = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5405
		-12,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5406
		-11.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5407
		-11,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5408
		-10.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5409
		-10,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5410
		-9.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5411
		-9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5412
		-8.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5413
		-8,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5414
		-7.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5415
		-7,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5416
		-6.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5417
		-6,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5418
		-5.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5419
		-5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5420
		-4.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5421
		-4,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5422
		-3.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5423
		-3,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5424
		-2.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5425
		-2,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5426
		-1.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5427
		-1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5428
		-0.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5429
		0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5430
		0.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5431
		1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5432
		1.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5433
		2,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5434
		2.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5435
		3,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5436
		3.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5437
		4,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5438
		4.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5439
		5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5440
		5.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5441
		5.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5442
		6,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5443
		6.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5444
		7,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5445
		7.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5446
		8,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5447
		8.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5448
		8.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5449
		9,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5450
		9.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5451
		10,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5452
		10.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5453
		11,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5454
		11.5,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5455
		12,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5456
		12.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5457
		13,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5458
		13.75,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5459
		14,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5460
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5461
	foreach ( $offset_range as $offset ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5462
		if ( 0 <= $offset ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5463
			$offset_name = '+' . $offset;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5464
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5465
			$offset_name = (string) $offset;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5466
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5467
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5468
		$offset_value = $offset_name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5469
		$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
  5470
		$offset_name  = 'UTC' . $offset_name;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5471
		$offset_value = 'UTC' . $offset_value;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5472
		$selected     = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5473
		if ( $offset_value === $selected_zone ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5474
			$selected = 'selected="selected" ';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5475
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5476
		$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
  5477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5478
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5479
	$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5481
	return join( "\n", $structure );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5482
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5484
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5485
 * Strip close comment and close php tags from file headers used by WP.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5486
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5487
 * @since 2.8.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5488
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5489
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5490
 * @see https://core.trac.wordpress.org/ticket/8497
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5491
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5492
 * @param string $str Header comment to clean up.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5493
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5494
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5495
function _cleanup_header_comment( $str ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5496
	return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5497
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5498
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5499
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5500
 * 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
  5501
 * 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
  5502
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5503
 * The default value of `EMPTY_TRASH_DAYS` is 30 (days).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5504
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5505
 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5506
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5507
 * @global wpdb $wpdb WordPress database abstraction object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5508
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5509
function wp_scheduled_delete() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5510
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5512
	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5513
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5514
	$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
  5515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5516
	foreach ( (array) $posts_to_delete as $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5517
		$post_id = (int) $post['post_id'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5518
		if ( ! $post_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5519
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5520
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5521
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5522
		$del_post = get_post( $post_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5523
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5524
		if ( ! $del_post || 'trash' != $del_post->post_status ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5525
			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
  5526
			delete_post_meta( $post_id, '_wp_trash_meta_time' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5527
		} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5528
			wp_delete_post( $post_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5529
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5530
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5531
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5532
	$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
  5533
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5534
	foreach ( (array) $comments_to_delete as $comment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5535
		$comment_id = (int) $comment['comment_id'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5536
		if ( ! $comment_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5537
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5538
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5539
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5540
		$del_comment = get_comment( $comment_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5541
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5542
		if ( ! $del_comment || 'trash' != $del_comment->comment_approved ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5543
			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
  5544
			delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5545
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5546
			wp_delete_comment( $del_comment );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5547
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5548
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5549
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5550
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5551
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5552
 * Retrieve metadata from a file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5553
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5554
 * Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5555
 * 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
  5556
 * lines, the value will get cut at the end of the first line.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5557
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5558
 * If the file data is not within that first 8kiB, then the author should correct
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5559
 * their plugin file and move the data headers to the top.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5560
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5561
 * @link https://codex.wordpress.org/File_Header
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5562
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5563
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5564
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5565
 * @param string $file            Absolute path to the file.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5566
 * @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
  5567
 * @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
  5568
 *                                Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5569
 * @return array Array of file headers in `HeaderKey => Header Value` format.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5570
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5571
function get_file_data( $file, $default_headers, $context = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5572
	// We don't need to write to the file, so just open for reading.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5573
	$fp = fopen( $file, 'r' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5575
	// Pull only the first 8kiB of the file in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5576
	$file_data = fread( $fp, 8192 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5578
	// PHP will close file handle, but we are good citizens.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5579
	fclose( $fp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5580
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5581
	// Make sure we catch CR-only line endings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5582
	$file_data = str_replace( "\r", "\n", $file_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5583
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5584
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5585
	 * Filters extra file headers by context.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5586
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5587
	 * The dynamic portion of the hook name, `$context`, refers to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5588
	 * the context where extra headers might be loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5589
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5590
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5591
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5592
	 * @param array $extra_context_headers Empty array by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5593
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5594
	if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5595
		$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
  5596
		$all_headers   = array_merge( $extra_headers, (array) $default_headers );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5597
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5598
		$all_headers = $default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5599
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5601
	foreach ( $all_headers as $field => $regex ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5602
		if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5603
			$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
  5604
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5605
			$all_headers[ $field ] = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5606
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5607
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5608
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5609
	return $all_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5610
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5611
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5612
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5613
 * Returns true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5614
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5615
 * Useful for returning true to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5616
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5617
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5618
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5619
 * @see __return_false()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5620
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5621
 * @return true True.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5622
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5623
function __return_true() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5624
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5625
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5626
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5627
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5628
 * Returns false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5629
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5630
 * Useful for returning false to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5631
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5632
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5633
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5634
 * @see __return_true()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5635
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5636
 * @return false False.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5637
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5638
function __return_false() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5639
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5640
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5642
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5643
 * Returns 0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5644
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5645
 * Useful for returning 0 to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5646
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5647
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5648
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5649
 * @return int 0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5650
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5651
function __return_zero() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5652
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5653
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5654
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5655
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5656
 * Returns an empty array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5657
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5658
 * Useful for returning an empty array to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5659
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5660
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5661
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5662
 * @return array Empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5663
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5664
function __return_empty_array() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5665
	return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5666
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5668
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5669
 * Returns null.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5670
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5671
 * Useful for returning null to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5672
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5673
 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5674
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5675
 * @return null Null value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5676
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5677
function __return_null() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5678
	return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5679
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5680
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5681
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5682
 * Returns an empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5683
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5684
 * Useful for returning an empty string to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5685
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5686
 * @since 3.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5687
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5688
 * @see __return_null()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5689
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5690
 * @return string Empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5691
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5692
function __return_empty_string() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5693
	return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5694
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5696
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5697
 * 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
  5698
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5699
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5700
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5701
 * @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
  5702
 * @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5703
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5704
function send_nosniff_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5705
	@header( 'X-Content-Type-Options: nosniff' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5706
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5708
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5709
 * 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
  5710
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5711
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5712
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5713
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5714
 * @param string $column Database column.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5715
 * @return string SQL clause.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5716
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5717
function _wp_mysql_week( $column ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5718
	switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5719
		case 1:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5720
			return "WEEK( $column, 1 )";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5721
		case 2:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5722
		case 3:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5723
		case 4:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5724
		case 5:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5725
		case 6:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5726
			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
  5727
		case 0:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5728
		default:
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5729
			return "WEEK( $column, 0 )";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5730
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5731
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5732
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5733
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5734
 * 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
  5735
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5736
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5737
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5738
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5739
 * @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
  5740
 * @param int      $start         The ID to start the loop check at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5741
 * @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
  5742
 *                                Use null to always use $callback
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5743
 * @param array    $callback_args Optional. Additional arguments to send to $callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5744
 * @return array IDs of all members of loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5745
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5746
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5747
	$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5748
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5749
	if ( ! $arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5750
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5751
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5752
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5753
	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
  5754
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5755
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5756
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5757
 * Use the "The Tortoise and the Hare" algorithm to detect loops.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5758
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5759
 * 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
  5760
 * If the hare ever laps the tortoise, there must be a loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5761
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5762
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5763
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5764
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5765
 * @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
  5766
 * @param int      $start         The ID to start the loop check at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5767
 * @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
  5768
 *                                Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5769
 * @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
  5770
 * @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
  5771
 *                                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
  5772
 *                                the returned array might include branches). Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5773
 * @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
  5774
 *               $_return_loop
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5775
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5776
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5777
	$tortoise = $hare = $evanescent_hare = $start;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5778
	$return   = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5780
	// Set evanescent_hare to one past hare
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5781
	// Increment hare two steps
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5782
	while (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5783
		$tortoise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5784
	&&
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5785
		( $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
  5786
	&&
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5787
		( $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
  5788
	) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5789
		if ( $_return_loop ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5790
			$return[ $tortoise ] = $return[ $evanescent_hare ] = $return[ $hare ] = true;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5791
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5793
		// tortoise got lapped - must be a loop
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5794
		if ( $tortoise == $evanescent_hare || $tortoise == $hare ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5795
			return $_return_loop ? $return : $tortoise;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5796
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5798
		// Increment tortoise by one step
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5799
		$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
  5800
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5801
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5802
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5803
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5805
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5806
 * Send a HTTP header to limit rendering of pages to same origin iframes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5807
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5808
 * @since 3.1.3
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5809
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5810
 * @see https://developer.mozilla.org/en/the_x-frame-options_response_header
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5811
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5812
function send_frame_options_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5813
	@header( 'X-Frame-Options: SAMEORIGIN' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5814
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5815
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5816
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5817
 * Retrieve a list of protocols to allow in HTML attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5818
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5819
 * @since 3.3.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5820
 * @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
  5821
 * @since 4.7.0 Added 'urn' to the protocols array.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5822
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5823
 * @see wp_kses()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5824
 * @see esc_url()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5825
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5826
 * @staticvar array $protocols
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5827
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5828
 * @return string[] Array of allowed protocols. Defaults to an array containing 'http', 'https',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5829
 *                  'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5830
 *                  'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'. This covers
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5831
 *                  all common link protocols, except for 'javascript' which should not be
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5832
 *                  allowed for untrusted users.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5833
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5834
function wp_allowed_protocols() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5835
	static $protocols = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5836
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5837
	if ( empty( $protocols ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5838
		$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5839
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5840
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5841
	if ( ! did_action( 'wp_loaded' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5842
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5843
		 * Filters the list of protocols allowed in HTML attributes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5844
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5845
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5846
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5847
		 * @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5848
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5849
		$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5850
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5851
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5852
	return $protocols;
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
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5856
 * Return a comma-separated string of functions that have been called to get
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5857
 * to the current point in code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5858
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5859
 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5860
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5861
 * @see https://core.trac.wordpress.org/ticket/19589
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5862
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5863
 * @staticvar array $truncate_paths Array of paths to truncate.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5864
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5865
 * @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
  5866
 *                             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
  5867
 * @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
  5868
 *                             back to the source of the issue. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5869
 * @param bool   $pretty       Optional. Whether or not you want a comma separated string or raw
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5870
 *                             array returned. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5871
 * @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
  5872
 *                      of individual calls.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5873
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5874
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
  5875
	static $truncate_paths;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5876
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5877
	if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5878
		$trace = debug_backtrace( false );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5879
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5880
		$trace = debug_backtrace();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5881
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5882
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5883
	$caller      = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5884
	$check_class = ! is_null( $ignore_class );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5885
	$skip_frames++; // skip this function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5886
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5887
	if ( ! isset( $truncate_paths ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5888
		$truncate_paths = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5889
			wp_normalize_path( WP_CONTENT_DIR ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5890
			wp_normalize_path( ABSPATH ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5891
		);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5892
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5893
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5894
	foreach ( $trace as $call ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5895
		if ( $skip_frames > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5896
			$skip_frames--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5897
		} elseif ( isset( $call['class'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5898
			if ( $check_class && $ignore_class == $call['class'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5899
				continue; // Filter out calls
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5900
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5902
			$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5903
		} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5904
			if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5905
				$caller[] = "{$call['function']}('{$call['args'][0]}')";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5906
			} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5907
				$filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5908
				$caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5909
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5910
				$caller[] = $call['function'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5911
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5912
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5913
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5914
	if ( $pretty ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5915
		return join( ', ', array_reverse( $caller ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5916
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5917
		return $caller;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5918
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5919
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5920
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5921
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5922
 * Retrieve IDs that are not already present in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5923
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5924
 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5925
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5926
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5927
 * @param int[]  $object_ids Array of IDs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5928
 * @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
  5929
 * @return int[] Array of IDs not present in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5930
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5931
function _get_non_cached_ids( $object_ids, $cache_key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5932
	$clean = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5933
	foreach ( $object_ids as $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5934
		$id = (int) $id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5935
		if ( ! wp_cache_get( $id, $cache_key ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5936
			$clean[] = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5937
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5938
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5940
	return $clean;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5941
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5942
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5943
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5944
 * Test if the current device has the capability to upload files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5945
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5946
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5947
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5948
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5949
 * @return bool Whether the device is able to upload files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5950
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5951
function _device_can_upload() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5952
	if ( ! wp_is_mobile() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5953
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5954
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5955
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5956
	$ua = $_SERVER['HTTP_USER_AGENT'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5957
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5958
	if ( strpos( $ua, 'iPhone' ) !== false
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5959
		|| strpos( $ua, 'iPad' ) !== false
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5960
		|| strpos( $ua, 'iPod' ) !== false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5961
			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
  5962
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5963
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5964
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5965
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5967
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5968
 * Test if a given path is a stream URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5969
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5970
 * @since 3.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5971
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5972
 * @param string $path The resource path or URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5973
 * @return bool True if the path is a stream URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5974
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5975
function wp_is_stream( $path ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5976
	$scheme_separator = strpos( $path, '://' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5977
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5978
	if ( false === $scheme_separator ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5979
		// $path isn't a stream
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5980
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5981
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5982
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5983
	$stream = substr( $path, 0, $scheme_separator );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5984
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5985
	return in_array( $stream, stream_get_wrappers(), true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5986
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5987
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5988
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5989
 * Test if the supplied date is valid for the Gregorian calendar.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5990
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5991
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  5992
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  5993
 * @link https://secure.php.net/manual/en/function.checkdate.php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5994
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5995
 * @param  int    $month       Month number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5996
 * @param  int    $day         Day number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5997
 * @param  int    $year        Year number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5998
 * @param  string $source_date The date to filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  5999
 * @return bool True if valid date, false if not valid date.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6000
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6001
function wp_checkdate( $month, $day, $year, $source_date ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6002
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6003
	 * 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
  6004
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6005
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6006
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6007
	 * @param bool   $checkdate   Whether the given date is valid.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6008
	 * @param string $source_date Date to check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6009
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6010
	return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6011
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6012
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6013
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6014
 * Load the auth check for monitoring whether the user is still logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6015
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6016
 * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6017
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6018
 * 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
  6019
 * 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
  6020
 * for fine-grained control.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6021
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6022
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6023
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6024
function wp_auth_check_load() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6025
	if ( ! is_admin() && ! is_user_logged_in() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6026
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6027
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6028
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6029
	if ( defined( 'IFRAME_REQUEST' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6030
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6031
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6033
	$screen = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6034
	$hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6035
	$show   = ! in_array( $screen->id, $hidden );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6036
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6037
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6038
	 * Filters whether to load the authentication check.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6039
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6040
	 * Passing a falsey value to the filter will effectively short-circuit
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6041
	 * loading the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6042
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6043
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6044
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6045
	 * @param bool      $show   Whether to load the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6046
	 * @param WP_Screen $screen The current screen object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6047
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6048
	if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6049
		wp_enqueue_style( 'wp-auth-check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6050
		wp_enqueue_script( 'wp-auth-check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6051
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6052
		add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6053
		add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6054
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6055
}
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
 * 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
  6059
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6060
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6061
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6062
function wp_auth_check_html() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6063
	$login_url      = wp_login_url();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6064
	$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
  6065
	$same_domain    = ( strpos( $login_url, $current_domain ) === 0 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6066
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6067
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6068
	 * Filters whether the authentication check originated at the same domain.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6069
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6070
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6071
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6072
	 * @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
  6073
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6074
	$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
  6075
	$wrap_class  = $same_domain ? 'hidden' : 'hidden fallback';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6076
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6077
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6078
	<div id="wp-auth-check-wrap" class="<?php echo $wrap_class; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6079
	<div id="wp-auth-check-bg"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6080
	<div id="wp-auth-check">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6081
	<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
  6082
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6083
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6084
	if ( $same_domain ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6085
		$login_src = add_query_arg(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6086
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6087
				'interim-login' => '1',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6088
				'wp_lang'       => get_user_locale(),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6089
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6090
			$login_url
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6091
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6092
		?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6093
		<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
  6094
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6095
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6097
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6098
	<div class="wp-auth-fallback">
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6099
		<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
  6100
		<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
  6101
		<?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
  6102
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6103
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6104
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6105
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6106
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6108
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6109
 * Check whether a user is still logged in, for the heartbeat.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6110
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6111
 * 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
  6112
 * or if their cookie is within the grace period.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6113
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6114
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6115
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6116
 * @global int $login_grace_period
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6117
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6118
 * @param array $response  The Heartbeat response.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6119
 * @return array $response The Heartbeat response with 'wp-auth-check' value set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6120
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6121
function wp_auth_check( $response ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6122
	$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6123
	return $response;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6124
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6126
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6127
 * Return RegEx body to liberally match an opening HTML tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6128
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6129
 * Matches an opening HTML tag that:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6130
 * 1. Is self-closing or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6131
 * 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
  6132
 * 3. Contains a body and a closing tag of the same name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6133
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6134
 * 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
  6135
 * to produce valid HTML
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6136
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6137
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6138
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6139
 * @param string $tag An HTML tag name. Example: 'video'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6140
 * @return string Tag RegEx.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6141
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6142
function get_tag_regex( $tag ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6143
	if ( empty( $tag ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6144
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6145
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6146
	return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6147
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6149
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6150
 * Retrieve a canonical form of the provided charset appropriate for passing to PHP
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6151
 * functions such as htmlspecialchars() and charset html attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6152
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6153
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6154
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6155
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6156
 * @see https://core.trac.wordpress.org/ticket/23688
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6157
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6158
 * @param string $charset A charset name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6159
 * @return string The canonical form of the charset.
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 _canonical_charset( $charset ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6162
	if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6163
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6164
		return 'UTF-8';
7
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6167
	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
  6168
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6169
		return 'ISO-8859-1';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6170
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6171
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6172
	return $charset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6173
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6175
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6176
 * 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
  6177
 * is enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6178
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6179
 * 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
  6180
 * strlen() and similar functions respect the utf8 characters, causing binary data
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6181
 * to return incorrect lengths.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6182
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6183
 * 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
  6184
 * resets it to the users expected encoding afterwards through the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6185
 * `reset_mbstring_encoding` function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6186
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6187
 * It is safe to recursively call this function, however each
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6188
 * `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
  6189
 * of `reset_mbstring_encoding()` calls.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6190
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6191
 * @since 3.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6192
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6193
 * @see reset_mbstring_encoding()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6194
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6195
 * @staticvar array $encodings
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6196
 * @staticvar bool  $overloaded
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6197
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6198
 * @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
  6199
 *                    Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6200
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6201
function mbstring_binary_safe_encoding( $reset = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6202
	static $encodings  = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6203
	static $overloaded = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6204
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6205
	if ( is_null( $overloaded ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6206
		$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6207
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6208
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6209
	if ( false === $overloaded ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6210
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6211
	}
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
	if ( ! $reset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6214
		$encoding = mb_internal_encoding();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6215
		array_push( $encodings, $encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6216
		mb_internal_encoding( 'ISO-8859-1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6217
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6219
	if ( $reset && $encodings ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6220
		$encoding = array_pop( $encodings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6221
		mb_internal_encoding( $encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6222
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6223
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6225
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6226
 * Reset the mbstring internal encoding to a users previously set encoding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6227
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6228
 * @see mbstring_binary_safe_encoding()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6229
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6230
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6231
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6232
function reset_mbstring_encoding() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6233
	mbstring_binary_safe_encoding( true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  6234
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6235
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6236
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6237
 * Filter/validate a variable as a boolean.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6238
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6239
 * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6240
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6241
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6242
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6243
 * @param mixed $var Boolean value to validate.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6244
 * @return bool Whether the value is validated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6245
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6246
function wp_validate_boolean( $var ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6247
	if ( is_bool( $var ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6248
		return $var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6249
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6250
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6251
	if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6252
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6253
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6254
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6255
	return (bool) $var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6256
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6257
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6258
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6259
 * Delete a file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6260
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6261
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6262
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6263
 * @param string $file The path to the file to delete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6264
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6265
function wp_delete_file( $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6266
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6267
	 * Filters the path of the file to delete.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6268
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6269
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6270
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6271
	 * @param string $file Path to the file to delete.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6272
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6273
	$delete = apply_filters( 'wp_delete_file', $file );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6274
	if ( ! empty( $delete ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6275
		@unlink( $delete );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6276
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  6277
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6278
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6279
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6280
 * 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
  6281
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6282
 * @since 4.9.7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6283
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6284
 * @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
  6285
 * @param string $directory Absolute path to a directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6286
 * @return bool True on success, false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6287
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6288
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
  6289
	if ( wp_is_stream( $file ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6290
		$real_file      = $file;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6291
		$real_directory = $directory;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6292
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6293
		$real_file      = realpath( wp_normalize_path( $file ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6294
		$real_directory = realpath( wp_normalize_path( $directory ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6295
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6296
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6297
	if ( false !== $real_file ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6298
		$real_file = wp_normalize_path( $real_file );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6299
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6300
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6301
	if ( false !== $real_directory ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6302
		$real_directory = wp_normalize_path( $real_directory );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6303
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6304
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6305
	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
  6306
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6307
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6308
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6309
	wp_delete_file( $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6310
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6311
	return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6312
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6313
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6314
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6315
 * 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
  6316
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6317
 * 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
  6318
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6319
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6320
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6321
 * @global WP_Post $post
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6322
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6323
function wp_post_preview_js() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6324
	global $post;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6325
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6326
	if ( ! is_preview() || empty( $post ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6327
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6328
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6329
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6330
	// Has to match the window name used in post_submit_meta_box()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6331
	$name = 'wp-preview-' . (int) $post->ID;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6332
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6333
	?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6334
	<script>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6335
	( function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6336
		var query = document.location.search;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6337
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6338
		if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6339
			window.name = '<?php echo $name; ?>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6340
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6341
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6342
		if ( window.addEventListener ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6343
			window.addEventListener( 'unload', function() { window.name = ''; }, false );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6344
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6345
	}());
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6346
	</script>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6347
	<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6348
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6349
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6350
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6351
 * 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
  6352
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6353
 * 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
  6354
 * 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
  6355
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6356
 * 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
  6357
 * which must contain timezone.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6358
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6359
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6360
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6361
 * @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
  6362
 * @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
  6363
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6364
function mysql_to_rfc3339( $date_string ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6365
	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
  6366
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6367
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6368
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6369
 * 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
  6370
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6371
 * 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
  6372
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6373
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6374
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6375
 * @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
  6376
 *                        'image', or an arbitrary other context. If an arbitrary context is passed,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6377
 *                        the similarly arbitrary {@see '{$context}_memory_limit'} filter will be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6378
 *                        invoked. Default 'admin'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6379
 * @return bool|int|string The limit that was set or false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6380
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6381
function wp_raise_memory_limit( $context = 'admin' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6382
	// Exit early if the limit cannot be changed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6383
	if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6384
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6385
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6386
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6387
	$current_limit     = @ini_get( 'memory_limit' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6388
	$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
  6389
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6390
	if ( -1 === $current_limit_int ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6391
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6392
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6393
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6394
	$wp_max_limit     = WP_MAX_MEMORY_LIMIT;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6395
	$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
  6396
	$filtered_limit   = $wp_max_limit;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6397
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6398
	switch ( $context ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6399
		case 'admin':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6400
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6401
			 * Filters the maximum memory limit available for administration screens.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6402
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6403
			 * 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
  6404
			 * 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
  6405
			 * users of any role) are handled separately.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6406
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6407
			 * 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
  6408
			 * 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
  6409
			 * (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
  6410
			 * this is higher.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6411
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6412
			 * @since 3.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6413
			 * @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
  6414
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6415
			 * @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
  6416
			 *                                   (bytes), or a shorthand string notation, such as '256M'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6417
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6418
			$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6419
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6420
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6421
		case 'image':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6422
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6423
			 * Filters the memory limit allocated for image manipulation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6424
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6425
			 * @since 3.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6426
			 * @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
  6427
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6428
			 * @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
  6429
			 *                                   Default `WP_MAX_MEMORY_LIMIT` or the original
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6430
			 *                                   php.ini `memory_limit`, whichever is higher.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6431
			 *                                   Accepts an integer (bytes), or a shorthand string
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6432
			 *                                   notation, such as '256M'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6433
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6434
			$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6435
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6436
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6437
		default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6438
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6439
			 * Filters the memory limit allocated for arbitrary contexts.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6440
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6441
			 * 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
  6442
			 * 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
  6443
			 * their own contexts for raising the memory limit.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6444
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6445
			 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6446
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6447
			 * @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
  6448
			 *                                   Default '256M' or the original php.ini `memory_limit`,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6449
			 *                                   whichever is higher. Accepts an integer (bytes), or a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6450
			 *                                   shorthand string notation, such as '256M'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6451
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6452
			$filtered_limit = apply_filters( "{$context}_memory_limit", $filtered_limit );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6453
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6454
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6455
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6456
	$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
  6457
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6458
	if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6459
		if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6460
			return $filtered_limit;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6461
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6462
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6463
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6464
	} elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6465
		if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6466
			return $wp_max_limit;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6467
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6468
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6469
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6470
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6471
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6472
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6473
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6474
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6475
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6476
 * Generate a random UUID (version 4).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6477
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6478
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6479
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6480
 * @return string UUID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6481
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6482
function wp_generate_uuid4() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6483
	return sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6484
		'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6485
		mt_rand( 0, 0xffff ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6486
		mt_rand( 0, 0xffff ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6487
		mt_rand( 0, 0xffff ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6488
		mt_rand( 0, 0x0fff ) | 0x4000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6489
		mt_rand( 0, 0x3fff ) | 0x8000,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6490
		mt_rand( 0, 0xffff ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6491
		mt_rand( 0, 0xffff ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6492
		mt_rand( 0, 0xffff )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6493
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6494
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6495
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6496
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6497
 * Validates that a UUID is valid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6498
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6499
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6500
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6501
 * @param mixed $uuid    UUID to check.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6502
 * @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
  6503
 *                       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
  6504
 * @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
  6505
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6506
function wp_is_uuid( $uuid, $version = null ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6507
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6508
	if ( ! is_string( $uuid ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6509
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6510
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6511
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6512
	if ( is_numeric( $version ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6513
		if ( 4 !== (int) $version ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6514
			_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
  6515
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6516
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6517
		$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
  6518
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6519
		$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
  6520
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6521
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6522
	return (bool) preg_match( $regex, $uuid );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6523
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6524
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6525
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6526
 * Get unique ID.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6527
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6528
 * 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
  6529
 * 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
  6530
 * 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
  6531
 * 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
  6532
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6533
 * @since 5.0.3
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6534
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6535
 * @staticvar int $id_counter
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6536
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6537
 * @param string $prefix Prefix for the returned ID.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6538
 * @return string Unique ID.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6539
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6540
function wp_unique_id( $prefix = '' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6541
	static $id_counter = 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6542
	return $prefix . (string) ++$id_counter;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6543
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6544
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6545
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6546
 * Get last changed date for the specified cache group.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6547
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6548
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6549
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6550
 * @param string $group Where the cache contents are grouped.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6551
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6552
 * @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6553
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6554
function wp_cache_get_last_changed( $group ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6555
	$last_changed = wp_cache_get( 'last_changed', $group );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6556
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6557
	if ( ! $last_changed ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6558
		$last_changed = microtime();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6559
		wp_cache_set( 'last_changed', $last_changed, $group );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6560
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6561
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6562
	return $last_changed;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6563
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6564
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6565
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6566
 * 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
  6567
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6568
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6569
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6570
 * @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
  6571
 * @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
  6572
 * @param string $option_name The relevant database option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6573
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6574
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
  6575
	$send = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6576
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6577
	// 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
  6578
	if ( 'you@example.com' === $old_email ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6579
		$send = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6580
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6581
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6582
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6583
	 * 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
  6584
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6585
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6586
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6587
	 * @param bool   $send      Whether to send the email notification.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6588
	 * @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
  6589
	 * @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
  6590
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6591
	$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
  6592
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6593
	if ( ! $send ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6594
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6595
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6596
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6597
	/* 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
  6598
	$email_change_text = __(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6599
		'Hi,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6600
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6601
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
  6602
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6603
The new admin email address is ###NEW_EMAIL###.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6604
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6605
This email has been sent to ###OLD_EMAIL###
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6606
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6607
Regards,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6608
All at ###SITENAME###
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6609
###SITEURL###'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6610
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6611
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6612
	$email_change_email = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6613
		'to'      => $old_email,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6614
		/* 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
  6615
		'subject' => __( '[%s] Admin Email Changed' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6616
		'message' => $email_change_text,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6617
		'headers' => '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6618
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6619
	// get site name
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6620
	$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
  6621
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6622
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6623
	 * 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
  6624
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6625
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6626
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6627
	 * @param array $email_change_email {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6628
	 *            Used to build wp_mail().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6629
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6630
	 *            @type string $to      The intended recipient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6631
	 *            @type string $subject The subject of the email.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6632
	 *            @type string $message The content of the email.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6633
	 *                The following strings have a special meaning and will get replaced dynamically:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6634
	 *                - ###OLD_EMAIL### The old site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6635
	 *                - ###NEW_EMAIL### The new site admin email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6636
	 *                - ###SITENAME###  The name of the site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6637
	 *                - ###SITEURL###   The URL to the site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6638
	 *            @type string $headers Headers.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6639
	 *        }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6640
	 * @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
  6641
	 * @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
  6642
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6643
	$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
  6644
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6645
	$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
  6646
	$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
  6647
	$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
  6648
	$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
  6649
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6650
	wp_mail(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6651
		$email_change_email['to'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6652
		sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6653
			$email_change_email['subject'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6654
			$site_name
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6655
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6656
		$email_change_email['message'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6657
		$email_change_email['headers']
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6658
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6659
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6660
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6661
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6662
 * Return an anonymized IPv4 or IPv6 address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6663
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6664
 * @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
  6665
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6666
 * @param  string $ip_addr        The IPv4 or IPv6 address to be anonymized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6667
 * @param  bool   $ipv6_fallback  Optional. Whether to return the original IPv6 address if the needed functions
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6668
 *                                to anonymize it are not present. Default false, return `::` (unspecified address).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6669
 * @return string  The anonymized IP address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6670
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6671
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6672
	// Detect what kind of IP address this is.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6673
	$ip_prefix = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6674
	$is_ipv6   = substr_count( $ip_addr, ':' ) > 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6675
	$is_ipv4   = ( 3 === substr_count( $ip_addr, '.' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6676
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6677
	if ( $is_ipv6 && $is_ipv4 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6678
		// 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
  6679
		$ip_prefix = '::ffff:';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6680
		$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
  6681
		$ip_addr   = str_replace( ']', '', $ip_addr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6682
		$is_ipv6   = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6683
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6684
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6685
	if ( $is_ipv6 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6686
		// 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
  6687
		$left_bracket  = strpos( $ip_addr, '[' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6688
		$right_bracket = strpos( $ip_addr, ']' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6689
		$percent       = strpos( $ip_addr, '%' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6690
		$netmask       = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6691
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6692
		// 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
  6693
		if ( false !== $left_bracket && false !== $right_bracket ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6694
			$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
  6695
		} elseif ( false !== $left_bracket || false !== $right_bracket ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6696
			// 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
  6697
			return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6698
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6699
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6700
		// Strip the reachability scope.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6701
		if ( false !== $percent ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6702
			$ip_addr = substr( $ip_addr, 0, $percent );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6703
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6704
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6705
		// No invalid characters should be left.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6706
		if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6707
			return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6708
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6709
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6710
		// 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
  6711
		if ( function_exists( 'inet_pton' ) && function_exists( 'inet_ntop' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6712
			$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
  6713
			if ( false === $ip_addr ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6714
				return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6715
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6716
		} elseif ( ! $ipv6_fallback ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6717
			return '::';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6718
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6719
	} elseif ( $is_ipv4 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6720
		// Strip any port and partially anonymize the IP.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6721
		$last_octet_position = strrpos( $ip_addr, '.' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6722
		$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
  6723
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6724
		return '0.0.0.0';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6725
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6726
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6727
	// Restore the IPv6 prefix to compatibility mode addresses.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6728
	return $ip_prefix . $ip_addr;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6729
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6730
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6731
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6732
 * Return uniform "anonymous" data by type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6733
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6734
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6735
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6736
 * @param  string $type The type of data to be anonymized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6737
 * @param  string $data Optional The data to be anonymized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6738
 * @return string The anonymous data for the requested type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6739
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6740
function wp_privacy_anonymize_data( $type, $data = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6741
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6742
	switch ( $type ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6743
		case 'email':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6744
			$anonymous = 'deleted@site.invalid';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6745
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6746
		case 'url':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6747
			$anonymous = 'https://site.invalid';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6748
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6749
		case 'ip':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6750
			$anonymous = wp_privacy_anonymize_ip( $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6751
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6752
		case 'date':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6753
			$anonymous = '0000-00-00 00:00:00';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6754
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6755
		case 'text':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6756
			/* translators: deleted text */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6757
			$anonymous = __( '[deleted]' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6758
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6759
		case 'longtext':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6760
			/* translators: deleted long text */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6761
			$anonymous = __( 'This content was deleted by the author.' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6762
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6763
		default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6764
			$anonymous = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6765
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6766
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6767
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6768
	 * Filters the anonymous data for each type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6769
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6770
	 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6771
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6772
	 * @param string $anonymous Anonymized data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6773
	 * @param string $type      Type of the data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6774
	 * @param string $data      Original data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6775
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6776
	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
  6777
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6778
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6779
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6780
 * 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
  6781
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6782
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6783
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6784
 * @see wp_privacy_exports_url
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6785
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6786
 * @return string Exports directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6787
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6788
function wp_privacy_exports_dir() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6789
	$upload_dir  = wp_upload_dir();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6790
	$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
  6791
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6792
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6793
	 * 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
  6794
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6795
	 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6796
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6797
	 * @param string $exports_dir Exports directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6798
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6799
	return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6800
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6801
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6802
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6803
 * 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
  6804
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6805
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6806
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6807
 * @see wp_privacy_exports_dir
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6808
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6809
 * @return string Exports directory URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6810
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6811
function wp_privacy_exports_url() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6812
	$upload_dir  = wp_upload_dir();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6813
	$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
  6814
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6815
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6816
	 * 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
  6817
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6818
	 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6819
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6820
	 * @param string $exports_url Exports directory URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6821
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6822
	return apply_filters( 'wp_privacy_exports_url', $exports_url );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6823
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6824
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6825
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6826
 * 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
  6827
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6828
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6829
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6830
function wp_schedule_delete_old_privacy_export_files() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6831
	if ( wp_installing() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6832
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6833
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6834
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6835
	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
  6836
		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
  6837
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6838
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6839
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6840
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6841
 * Cleans up export files older than three days old.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6842
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6843
 * 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
  6844
 * 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
  6845
 * 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
  6846
 * 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
  6847
 * layer of protection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6848
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6849
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6850
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6851
function wp_privacy_delete_old_export_files() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6852
	$exports_dir = wp_privacy_exports_dir();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6853
	if ( ! is_dir( $exports_dir ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6854
		return;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6855
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6856
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6857
	require_once( ABSPATH . 'wp-admin/includes/file.php' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6858
	$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6859
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6860
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6861
	 * 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
  6862
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6863
	 * 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
  6864
	 * be deleted by a cron job.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6865
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6866
	 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6867
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6868
	 * @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
  6869
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6870
	$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
  6871
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6872
	foreach ( (array) $export_files as $export_file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6873
		$file_age_in_seconds = time() - filemtime( $export_file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6874
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6875
		if ( $expiration < $file_age_in_seconds ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6876
			unlink( $export_file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6877
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6878
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  6879
}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6880
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6881
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6882
 * 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
  6883
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6884
 * 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
  6885
 * {@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
  6886
 * 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
  6887
 * site language.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6888
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6889
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6890
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6891
 * @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
  6892
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6893
function wp_get_update_php_url() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6894
	$default_url = wp_get_default_update_php_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6895
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6896
	$update_url = $default_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6897
	if ( false !== getenv( 'WP_UPDATE_PHP_URL' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6898
		$update_url = getenv( 'WP_UPDATE_PHP_URL' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6899
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6900
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6901
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6902
	 * 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
  6903
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6904
	 * 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
  6905
	 * 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
  6906
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6907
	 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6908
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6909
	 * @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
  6910
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6911
	$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
  6912
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6913
	if ( empty( $update_url ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6914
		$update_url = $default_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6915
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6916
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6917
	return $update_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6918
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6919
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6920
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6921
 * 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
  6922
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6923
 * 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
  6924
 * 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
  6925
 * default one.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6926
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6927
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6928
 * @access private
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6929
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6930
 * @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
  6931
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6932
function wp_get_default_update_php_url() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6933
	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
  6934
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6935
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6936
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6937
 * 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
  6938
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6939
 * 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
  6940
 * 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
  6941
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6942
 * @since 5.1.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6943
 * @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
  6944
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6945
 * @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
  6946
 * @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
  6947
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6948
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
  6949
	$annotation = wp_get_update_php_annotation();
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
	if ( $annotation ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6952
		echo $before . $annotation . $after;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6953
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6954
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6955
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6956
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6957
 * 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
  6958
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6959
 * 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
  6960
 * 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
  6961
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6962
 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6963
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6964
 * @return string $message Update PHP page annotation. An empty string if no custom URLs are provided.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6965
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6966
function wp_get_update_php_annotation() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6967
	$update_url  = wp_get_update_php_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6968
	$default_url = wp_get_default_update_php_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6969
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6970
	if ( $update_url === $default_url ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6971
		return '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6972
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6973
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6974
	$annotation = sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6975
		/* translators: %s: default Update PHP page URL */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6976
		__( '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
  6977
		esc_url( $default_url )
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
	return $annotation;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6981
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6982
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6983
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6984
 * 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
  6985
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6986
 * 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
  6987
 * 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
  6988
 * 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
  6989
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6990
 * @since 5.1.1
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6991
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6992
 * @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
  6993
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6994
function wp_get_direct_php_update_url() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6995
	$direct_update_url = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6996
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6997
	if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  6998
		$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
  6999
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7000
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7001
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7002
	 * 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
  7003
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7004
	 * @since 5.1.1
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7005
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7006
	 * @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
  7007
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7008
	$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
  7009
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7010
	return $direct_update_url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7011
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7012
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7013
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7014
 * 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
  7015
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7016
 * 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
  7017
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7018
 * 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
  7019
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7020
 * @since 5.1.1
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7021
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7022
function wp_direct_php_update_button() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7023
	$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
  7024
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7025
	if ( empty( $direct_update_url ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7026
		return;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7027
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7028
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7029
	echo '<p class="button-container">';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7030
	printf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7031
		'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7032
		esc_url( $direct_update_url ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7033
		__( 'Update PHP' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7034
		/* translators: accessibility text */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7035
		__( '(opens in a new tab)' )
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
	echo '</p>';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7038
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7039
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7040
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7041
 * Get the size of a directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7042
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7043
 * 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
  7044
 * a blog has exceeded its allowed upload space.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7045
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7046
 * @since MU (3.0.0)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7047
 * @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
  7048
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7049
 * @param string $directory Full path of a directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7050
 * @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
  7051
 *                                   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
  7052
 * @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
  7053
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7054
function get_dirsize( $directory, $max_execution_time = null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7055
	$dirsize = get_transient( 'dirsize_cache' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7056
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7057
	if ( is_array( $dirsize ) && isset( $dirsize[ $directory ]['size'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7058
		return $dirsize[ $directory ]['size'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7059
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7060
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7061
	if ( ! is_array( $dirsize ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7062
		$dirsize = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7063
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7064
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7065
	// Exclude individual site directories from the total when checking the main site of a network
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7066
	// 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
  7067
	if ( is_multisite() && is_main_site() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7068
		$dirsize[ $directory ]['size'] = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7069
	} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7070
		$dirsize[ $directory ]['size'] = recurse_dirsize( $directory, null, $max_execution_time );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7071
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7072
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7073
	set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7074
	return $dirsize[ $directory ]['size'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7075
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7076
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7077
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7078
 * Get the size of a directory recursively.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7079
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7080
 * Used by get_dirsize() to get a directory's size when it contains
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7081
 * other directories.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7082
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7083
 * @since MU (3.0.0)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7084
 * @since 4.3.0 $exclude parameter added.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7085
 * @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
  7086
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7087
 * @param string $directory       Full path of a directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7088
 * @param string|array $exclude   Optional. Full path of a subdirectory to exclude from the total, or array of paths.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7089
 *                                Expected without trailing slash(es).
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7090
 * @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
  7091
 *                                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
  7092
 * @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
  7093
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7094
function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7095
	$size = 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7096
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7097
	$directory = untrailingslashit( $directory );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7098
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7099
	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
  7100
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7101
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7102
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7103
	if (
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7104
		( is_string( $exclude ) && $directory === $exclude ) ||
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7105
		( is_array( $exclude ) && in_array( $directory, $exclude, true ) )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7106
	) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7107
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7108
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7109
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7110
	if ( $max_execution_time === null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7111
		// 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
  7112
		if ( function_exists( 'ini_get' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7113
			$max_execution_time = ini_get( 'max_execution_time' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7114
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7115
			// Disable...
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7116
			$max_execution_time = 0;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7117
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7118
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7119
		// 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
  7120
		if ( $max_execution_time > 10 ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7121
			$max_execution_time -= 1;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7122
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7123
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7124
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7125
	if ( $handle = opendir( $directory ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7126
		while ( ( $file = readdir( $handle ) ) !== false ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7127
			$path = $directory . '/' . $file;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7128
			if ( $file != '.' && $file != '..' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7129
				if ( is_file( $path ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7130
					$size += filesize( $path );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7131
				} elseif ( is_dir( $path ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7132
					$handlesize = recurse_dirsize( $path, $exclude, $max_execution_time );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7133
					if ( $handlesize > 0 ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7134
						$size += $handlesize;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7135
					}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7136
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7137
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7138
				if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7139
					// Time exceeded. Give up instead of risking a fatal timeout.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7140
					$size = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7141
					break;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7142
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7143
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7144
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7145
		closedir( $handle );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7146
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7147
	return $size;
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
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7150
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7151
* Checks compatibility with the current WordPress version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7152
*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7153
* @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7154
*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7155
* @param string $required Minimum required WordPress version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7156
* @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
  7157
*/
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7158
function is_wp_version_compatible( $required ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7159
	return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7160
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7161
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7162
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7163
 * Checks compatibility with the current PHP version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7164
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7165
 * @since 5.2.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7166
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7167
 * @param string $required Minimum required PHP version.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7168
 * @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
  7169
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7170
function is_php_version_compatible( $required ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7171
	return empty( $required ) || version_compare( phpversion(), $required, '>=' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  7172
}