wp/wp-includes/rewrite.php
author ymh <ymh.work@gmail.com>
Tue, 15 Dec 2020 13:49:49 +0100
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
permissions -rw-r--r--
update enmi-conf
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
 * WordPress Rewrite 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
 * @subpackage Rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Endpoint Mask for default, which is nothing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    14
define( 'EP_NONE', 0 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * Endpoint Mask for Permalink.
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 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    21
define( 'EP_PERMALINK', 1 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 * Endpoint Mask for Attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    28
define( 'EP_ATTACHMENT', 2 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 * Endpoint Mask for date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    35
define( 'EP_DATE', 4 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 * Endpoint Mask for year
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    42
define( 'EP_YEAR', 8 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
 * Endpoint Mask for month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    49
define( 'EP_MONTH', 16 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 * Endpoint Mask for day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    56
define( 'EP_DAY', 32 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 * Endpoint Mask for root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    63
define( 'EP_ROOT', 64 );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 * Endpoint Mask for comments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    70
define( 'EP_COMMENTS', 128 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 * Endpoint Mask for searches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    77
define( 'EP_SEARCH', 256 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 * Endpoint Mask for categories.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    84
define( 'EP_CATEGORIES', 512 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
 * Endpoint Mask for tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    91
define( 'EP_TAGS', 1024 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
 * Endpoint Mask for authors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    98
define( 'EP_AUTHORS', 2048 );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 * Endpoint Mask for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   105
define( 'EP_PAGES', 4096 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 * Endpoint Mask for all archive views.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
define( 'EP_ALL_ARCHIVES', EP_DATE | EP_YEAR | EP_MONTH | EP_DAY | EP_CATEGORIES | EP_TAGS | EP_AUTHORS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 * Endpoint Mask for everything.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_PAGES | EP_ALL_ARCHIVES );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
 * Adds a rewrite rule that transforms a URL structure to a set of query vars.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
 * Any value in the $after parameter that isn't 'bottom' will result in the rule
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   125
 * being placed at the top of the rewrite rules.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   126
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   127
 * @since 2.1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   128
 * @since 4.4.0 Array support was added to the `$query` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   129
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   130
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   131
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   132
 * @param string       $regex Regular expression to match request against.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   133
 * @param string|array $query The corresponding query vars for this rewrite rule.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   134
 * @param string       $after Optional. Priority of the new rule. Accepts 'top'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   135
 *                            or 'bottom'. Default 'bottom'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   136
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   137
function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
	global $wp_rewrite;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   139
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   140
	$wp_rewrite->add_rule( $regex, $query, $after );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   141
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   142
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   143
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   144
 * Add a new rewrite tag (like %postname%).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   146
 * The $query parameter is optional. If it is omitted you must ensure that
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   147
 * you call this on, or before, the {@see 'init'} hook. This is because $query defaults
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   148
 * to "$tag=", and for this to work a new query var has to be added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
 * @since 2.1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   152
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   153
 * @global WP         $wp         Current WordPress environment instance.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   154
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   155
 * @param string $tag   Name of the new rewrite tag.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   156
 * @param string $regex Regular expression to substitute the tag for in rewrite rules.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   157
 * @param string $query Optional. String to append to the rewritten query. Must end in '='. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   158
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   159
function add_rewrite_tag( $tag, $regex, $query = '' ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   160
	// Validate the tag's name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   161
	if ( strlen( $tag ) < 3 || '%' !== $tag[0] || '%' !== $tag[ strlen( $tag ) - 1 ] ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   163
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   164
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   165
	global $wp_rewrite, $wp;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
	if ( empty( $query ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
		$qv = trim( $tag, '%' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
		$wp->add_query_var( $qv );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   170
		$query = $qv . '=';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   172
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   173
	$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   174
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   175
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   176
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   177
 * Removes an existing rewrite tag (like %postname%).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   178
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   179
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
 * @param string $tag Name of the rewrite tag.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   185
function remove_rewrite_tag( $tag ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   186
	global $wp_rewrite;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   187
	$wp_rewrite->remove_rewrite_tag( $tag );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   189
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
 * Add permalink structure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
 * @since 3.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   194
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
 * @see WP_Rewrite::add_permastruct()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   197
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
 * @param string $name   Name for permalink structure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
 * @param string $struct Permalink structure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
 * @param array  $args   Optional. Arguments for building the rules from the permalink structure,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   201
 *                       see WP_Rewrite::add_permastruct() for full details. Default empty array.
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
function add_permastruct( $name, $struct, $args = array() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
	global $wp_rewrite;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
	// Back-compat for the old parameters: $with_front and $ep_mask.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   207
	if ( ! is_array( $args ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
		$args = array( 'with_front' => $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   209
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   210
	if ( func_num_args() == 4 ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
		$args['ep_mask'] = func_get_arg( 3 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   212
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   213
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
	$wp_rewrite->add_permastruct( $name, $struct, $args );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
}
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
 * Removes a permalink structure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   219
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   220
 * Can only be used to remove permastructs that were added using add_permastruct().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   221
 * Built-in permastructs cannot be removed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   222
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   224
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
 * @see WP_Rewrite::remove_permastruct()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   227
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
 * @param string $name Name for permalink structure.
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
function remove_permastruct( $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   231
	global $wp_rewrite;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
	$wp_rewrite->remove_permastruct( $name );
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
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
 * Add a new feed type like /atom1/.
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
 * @since 2.1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   240
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   241
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   242
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   243
 * @param string   $feedname Feed name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   244
 * @param callable $function Callback to run on feed display.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   245
 * @return string Feed action name.
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
function add_feed( $feedname, $function ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   248
	global $wp_rewrite;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   249
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   250
	if ( ! in_array( $feedname, $wp_rewrite->feeds, true ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
		$wp_rewrite->feeds[] = $feedname;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   252
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   253
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   254
	$hook = 'do_feed_' . $feedname;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   256
	// Remove default function hook.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
	remove_action( $hook, $hook );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   258
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   259
	add_action( $hook, $function, 10, 2 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   260
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   261
	return $hook;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
}
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
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   265
 * Remove rewrite rules and then recreate rewrite rules.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   266
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
 * @since 3.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   269
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   270
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
 * @param bool $hard Whether to update .htaccess (hard flush) or just update
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   272
 *                   rewrite_rules option (soft flush). Default is true (hard).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   273
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   274
function flush_rewrite_rules( $hard = true ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   275
	global $wp_rewrite;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   276
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   277
	if ( is_callable( array( $wp_rewrite, 'flush_rules' ) ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   278
		$wp_rewrite->flush_rules( $hard );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   279
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   280
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   281
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 * Add an endpoint, like /trackback/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 * Adding an endpoint creates extra rewrite rules for each of the matching
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
 * places specified by the provided bitmask. For example:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
 *     add_rewrite_endpoint( 'json', EP_PERMALINK | EP_PAGES );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
 * will add a new rewrite rule ending with "json(/(.*))?/?$" for every permastruct
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
 * that describes a permalink (post) or page. This is rewritten to "json=$match"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 * where $match is the part of the URL matched by the endpoint regex (e.g. "foo" in
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
 * "[permalink]/json/foo/").
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * A new query var with the same name as the endpoint will also be created.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * When specifying $places ensure that you are using the EP_* constants (or a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 * combination of them using the bitwise OR operator) as their values are not
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
 * guaranteed to remain static (especially `EP_ALL`).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   301
 * Be sure to flush the rewrite rules - see flush_rewrite_rules() - when your plugin gets
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 * activated and deactivated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
 * @since 2.1.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   305
 * @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   307
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   309
 * @param string      $name      Name of the endpoint.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   310
 * @param int         $places    Endpoint mask describing the places the endpoint should be added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   311
 * @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering a query_var
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   312
 *                               for this endpoint. Defaults to the value of `$name`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
function add_rewrite_endpoint( $name, $places, $query_var = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	global $wp_rewrite;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
	$wp_rewrite->add_endpoint( $name, $places, $query_var );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   320
 * Filters the URL base for taxonomies.
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
 * To remove any manually prepended /index.php/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
 * @param string $base The taxonomy base that we're going to filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
function _wp_filter_taxonomy_base( $base ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   331
	if ( ! empty( $base ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		$base = preg_replace( '|^/index\.php/|', '', $base );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		$base = trim( $base, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	return $base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   338
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
 * Resolve numeric slugs that collide with date permalinks.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
 * Permalinks of posts with numeric slugs can sometimes look to WP_Query::parse_query()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
 * like a date archive, as when your permalink structure is `/%year%/%postname%/` and
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
 * a post with post_name '05' has the URL `/2015/05/`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
 * This function detects conflicts of this type and resolves them in favor of the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
 * post permalink.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
 * Note that, since 4.3.0, wp_unique_post_slug() prevents the creation of post slugs
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
 * that would result in a date archive conflict. The resolution performed in this
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
 * function is primarily for legacy content, as well as cases when the admin has changed
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
 * the site's permalink structure in a way that introduces URL conflicts.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   353
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   355
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   356
 * @param array $query_vars Optional. Query variables for setting up the loop, as determined in
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   357
 *                          WP::parse_request(). Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
 * @return array Returns the original array of query vars, with date/post conflicts resolved.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
	if ( ! isset( $query_vars['year'] ) && ! isset( $query_vars['monthnum'] ) && ! isset( $query_vars['day'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   362
		return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
	// Identify the 'postname' position in the permastruct array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
	$permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   367
	$postname_index = array_search( '%postname%', $permastructs, true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   368
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   369
	if ( false === $postname_index ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   370
		return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   371
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   373
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   374
	 * A numeric slug could be confused with a year, month, or day, depending on position. To account for
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   375
	 * the possibility of post pagination (eg 2015/2 for the second page of a post called '2015'), our
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   376
	 * `is_*` checks are generous: check for year-slug clashes when `is_year` *or* `is_month`, and check
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   377
	 * for month-slug clashes when `is_month` *or* `is_day`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   378
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   379
	$compare = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   380
	if ( 0 === $postname_index && ( isset( $query_vars['year'] ) || isset( $query_vars['monthnum'] ) ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   381
		$compare = 'year';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   382
	} elseif ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && ( isset( $query_vars['monthnum'] ) || isset( $query_vars['day'] ) ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   383
		$compare = 'monthnum';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   384
	} elseif ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && isset( $query_vars['day'] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   385
		$compare = 'day';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   386
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   387
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   388
	if ( ! $compare ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   389
		return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
	// This is the potentially clashing slug.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   393
	$value = $query_vars[ $compare ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
	$post = get_page_by_path( $value, OBJECT, 'post' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
	if ( ! ( $post instanceof WP_Post ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
		return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
	// If the date of the post doesn't match the date specified in the URL, resolve to the date archive.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   401
	if ( preg_match( '/^([0-9]{4})\-([0-9]{2})/', $post->post_date, $matches ) && isset( $query_vars['year'] ) && ( 'monthnum' === $compare || 'day' === $compare ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
		// $matches[1] is the year the post was published.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
		if ( intval( $query_vars['year'] ) !== intval( $matches[1] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
			return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
		// $matches[2] is the month the post was published.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
		if ( 'day' === $compare && isset( $query_vars['monthnum'] ) && intval( $query_vars['monthnum'] ) !== intval( $matches[2] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
			return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
	 * If the located post contains nextpage pagination, then the URL chunk following postname may be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   415
	 * intended as the page number. Verify that it's a valid page before resolving to it.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   416
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   417
	$maybe_page = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   418
	if ( 'year' === $compare && isset( $query_vars['monthnum'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   419
		$maybe_page = $query_vars['monthnum'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   420
	} elseif ( 'monthnum' === $compare && isset( $query_vars['day'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   421
		$maybe_page = $query_vars['day'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   422
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   423
	// Bug found in #11694 - 'page' was returning '/4'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   424
	$maybe_page = (int) trim( $maybe_page, '/' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   425
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
	$post_page_count = substr_count( $post->post_content, '<!--nextpage-->' ) + 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   427
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   428
	// If the post doesn't have multiple pages, but a 'page' candidate is found, resolve to the date archive.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   429
	if ( 1 === $post_page_count && $maybe_page ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   430
		return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   431
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   432
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
	// If the post has multiple pages and the 'page' number isn't valid, resolve to the date archive.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   434
	if ( $post_page_count > 1 && $maybe_page > $post_page_count ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   435
		return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   436
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
	// If we've gotten to this point, we have a slug/date clash. First, adjust for nextpage.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
	if ( '' !== $maybe_page ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   440
		$query_vars['page'] = intval( $maybe_page );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   441
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   443
	// Next, unset autodetected date-related query vars.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   444
	unset( $query_vars['year'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   445
	unset( $query_vars['monthnum'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
	unset( $query_vars['day'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   447
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   448
	// Then, set the identified post.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   449
	$query_vars['name'] = $post->post_name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   450
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   451
	// Finally, return the modified query vars.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   452
	return $query_vars;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   453
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   454
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   455
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   456
 * Examine a URL and try to determine the post ID it represents.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
 * Checks are supposedly from the hosted site blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   462
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   463
 * @global WP         $wp         Current WordPress environment instance.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   464
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
 * @param string $url Permalink to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
 * @return int Post ID, or 0 on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   468
function url_to_postid( $url ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   472
	 * Filters the URL to derive the post ID from.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
	 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
	 * @param string $url The URL to derive the post ID from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
	$url = apply_filters( 'url_to_postid', $url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   480
	$url_host      = str_replace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   481
	$home_url_host = str_replace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   482
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   483
	// Bail early if the URL does not belong to this site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   484
	if ( $url_host && $url_host !== $home_url_host ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   485
		return 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   486
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   487
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   488
	// First, check to see if there is a 'p=N' or 'page_id=N' to match against.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   489
	if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   490
		$id = absint( $values[2] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   491
		if ( $id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
			return $id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   493
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   496
	// Get rid of the #anchor.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   497
	$url_split = explode( '#', $url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   498
	$url       = $url_split[0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   500
	// Get rid of URL ?query=string.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
	$url_split = explode( '?', $url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   502
	$url       = $url_split[0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   504
	// Set the correct URL scheme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   505
	$scheme = parse_url( home_url(), PHP_URL_SCHEME );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   506
	$url    = set_url_scheme( $url, $scheme );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   507
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   508
	// Add 'www.' if it is absent and should be there.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   509
	if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   510
		$url = str_replace( '://', '://www.', $url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   511
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   513
	// Strip 'www.' if it is present and shouldn't be.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   514
	if ( false === strpos( home_url(), '://www.' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   515
		$url = str_replace( '://www.', '://', $url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   516
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   518
	if ( trim( $url, '/' ) === home_url() && 'page' === get_option( 'show_on_front' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   519
		$page_on_front = get_option( 'page_on_front' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   520
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   521
		if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   522
			return (int) $page_on_front;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   523
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   525
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   526
	// Check to see if we are using rewrite rules.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   527
	$rewrite = $wp_rewrite->wp_rewrite_rules();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   528
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   529
	// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   530
	if ( empty( $rewrite ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   531
		return 0;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   532
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   533
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   534
	// Strip 'index.php/' if we're not using path info permalinks.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   535
	if ( ! $wp_rewrite->using_index_permalinks() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
		$url = str_replace( $wp_rewrite->index . '/', '', $url );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   537
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   540
		// Chop off http://domain.com/[path].
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   541
		$url = str_replace( home_url(), '', $url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   543
		// Chop off /path/to/blog.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		$home_path = parse_url( home_url( '/' ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   545
		$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   546
		$url       = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   549
	// Trim leading and lagging slashes.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   550
	$url = trim( $url, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   552
	$request              = $url;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	$post_type_query_vars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   555
	foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   556
		if ( ! empty( $t->query_var ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
			$post_type_query_vars[ $t->query_var ] = $post_type;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   558
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	// Look for matches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	$request_match = $request;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   563
	foreach ( (array) $rewrite as $match => $query ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   565
		// If the requesting file is the anchor of the match,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   566
		// prepend it to the path info.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   567
		if ( ! empty( $url ) && ( $url != $request ) && ( strpos( $match, $url ) === 0 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
			$request_match = $url . '/' . $request;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   569
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   571
		if ( preg_match( "#^$match#", $request_match, $matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
			if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
				// This is a verbose page match, let's check to be sure about it.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   575
				$page = get_page_by_path( $matches[ $varmatch[1] ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   576
				if ( ! $page ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
					continue;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   578
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   579
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   580
				$post_status_obj = get_post_status_object( $page->post_status );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
				if ( ! $post_status_obj->public && ! $post_status_obj->protected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   582
					&& ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   583
					continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   584
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
			// Got a match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
			// Trim the query of everything up to the '?'.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   589
			$query = preg_replace( '!^.+\?!', '', $query );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
			// Substitute the substring matches into the query.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   592
			$query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   594
			// Filter out non-public query vars.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
			global $wp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
			parse_str( $query, $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
			$query = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
			foreach ( (array) $query_vars as $key => $value ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   599
				if ( in_array( (string) $key, $wp->public_query_vars, true ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   600
					$query[ $key ] = $value;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   601
					if ( isset( $post_type_query_vars[ $key ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   602
						$query['post_type'] = $post_type_query_vars[ $key ];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   603
						$query['name']      = $value;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   608
			// Resolve conflicts between posts with numeric slugs and date archive queries.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   609
			$query = wp_resolve_numeric_slug_conflicts( $query );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   610
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   611
			// Do the query.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
			$query = new WP_Query( $query );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   613
			if ( ! empty( $query->posts ) && $query->is_singular ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
				return $query->post->ID;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   615
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
				return 0;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   617
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
}