wp/wp-includes/rewrite.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
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
 * Add a straight rewrite rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @see WP_Rewrite::add_rule() for long description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @param string $regex Regular Expression to match request against.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @param string $redirect Page to redirect to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @param string $after Optional, default is 'bottom'. Where to add rule, can also be 'top'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	$wp_rewrite->add_rule($regex, $redirect, $after);
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 * Add a new rewrite tag (like %postname%).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
 * The $query parameter is optional. If it is omitted you must ensure that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
 * you call this on, or before, the 'init' hook. This is because $query defaults
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 * to "$tag=", and for this to work a new query var has to be added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 * @see WP_Rewrite::add_rewrite_tag()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 * @param string $tag Name of the new rewrite tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 * @param string $regex Regular expression to substitute the tag for in rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 * @param string $query String to append to the rewritten query. Must end in '='. Optional.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
function add_rewrite_tag( $tag, $regex, $query = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	// validate the tag's name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	global $wp_rewrite, $wp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	if ( empty( $query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		$qv = trim( $tag, '%' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		$wp->add_query_var( $qv );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$query = $qv . '=';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 * Add permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 * @see WP_Rewrite::add_permastruct()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * @param string $name Name for permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 * @param string $struct Permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 * @param array $args Optional configuration for building the rules from the permalink structure,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 *     see {@link WP_Rewrite::add_permastruct()} for full details.
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 add_permastruct( $name, $struct, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	// backwards compatibility for the old parameters: $with_front and $ep_mask
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	if ( ! is_array( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		$args = array( 'with_front' => $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	if ( func_num_args() == 4 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		$args['ep_mask'] = func_get_arg( 3 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	return $wp_rewrite->add_permastruct( $name, $struct, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
 * Add a new feed type like /atom1/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 * @param string $feedname
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 * @param callback $function Callback to run on feed display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
 * @return string Feed action name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
function add_feed($feedname, $function) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	if ( ! in_array($feedname, $wp_rewrite->feeds) ) //override the file if it is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		$wp_rewrite->feeds[] = $feedname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	$hook = 'do_feed_' . $feedname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	// Remove default function hook
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	remove_action($hook, $hook);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	add_action($hook, $function, 10, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	return $hook;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
 * Remove rewrite rules and then recreate rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * @see WP_Rewrite::flush_rules()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 * @since 3.0.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
 * @param bool $hard Whether to update .htaccess (hard flush) or just update
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * 	rewrite_rules transient (soft flush). Default is true (hard).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
function flush_rewrite_rules( $hard = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	$wp_rewrite->flush_rules( $hard );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 * Endpoint Mask for default, which is nothing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
define('EP_NONE', 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 * Endpoint Mask for Permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
define('EP_PERMALINK', 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
 * Endpoint Mask for Attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
define('EP_ATTACHMENT', 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 * Endpoint Mask for date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
define('EP_DATE', 4);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 * Endpoint Mask for year
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
define('EP_YEAR', 8);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 * Endpoint Mask for month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
define('EP_MONTH', 16);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 * Endpoint Mask for day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
define('EP_DAY', 32);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 * Endpoint Mask for root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
define('EP_ROOT', 64);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 * Endpoint Mask for comments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
define('EP_COMMENTS', 128);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
 * Endpoint Mask for searches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
define('EP_SEARCH', 256);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 * Endpoint Mask for categories.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
define('EP_CATEGORIES', 512);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * Endpoint Mask for tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
define('EP_TAGS', 1024);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 * Endpoint Mask for authors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
define('EP_AUTHORS', 2048);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
 * Endpoint Mask for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
define('EP_PAGES', 4096);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * Endpoint Mask for all archive views.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
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
   215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 * Endpoint Mask for everything.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
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
   222
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 * Add an endpoint, like /trackback/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 * Adding an endpoint creates extra rewrite rules for each of the matching
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 * places specified by the provided bitmask. For example:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
 *     add_rewrite_endpoint( 'json', EP_PERMALINK | EP_PAGES );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 * will add a new rewrite rule ending with "json(/(.*))?/?$" for every permastruct
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 * that describes a permalink (post) or page. This is rewritten to "json=$match"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 * 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
   234
 * "[permalink]/json/foo/").
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * 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
   237
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 * When specifying $places ensure that you are using the EP_* constants (or a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 * 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
   240
 * guaranteed to remain static (especially `EP_ALL`).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
 * 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
   243
 * activated and deactivated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 * @see WP_Rewrite::add_endpoint()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 * @global object $wp_rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 * @param string $name Name of the endpoint.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 * @param int $places Endpoint mask describing the places the endpoint should be added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
 * @param string $query_var Name of the corresponding query variable. Defaults to $name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
function add_rewrite_endpoint( $name, $places, $query_var = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	global $wp_rewrite;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
	$wp_rewrite->add_endpoint( $name, $places, $query_var );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 * Filter the URL base for taxonomies.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
 * To remove any manually prepended /index.php/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 * @param string $base The taxonomy base that we're going to filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
function _wp_filter_taxonomy_base( $base ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
	if ( !empty( $base ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
		$base = preg_replace( '|^/index\.php/|', '', $base );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		$base = trim( $base, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	return $base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 * Examine a url and try to determine the post ID it represents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 * Checks are supposedly from the hosted site blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * @param string $url Permalink to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 * @return int Post ID, or 0 on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
function url_to_postid($url) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
	 * Filter the URL to derive the post ID from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
	 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
	 * @param string $url The URL to derive the post ID from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
	$url = apply_filters( 'url_to_postid', $url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	// First, check to see if there is a 'p=N' or 'page_id=N' to match against
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) )	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
		$id = absint($values[2]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
		if ( $id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
			return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	// Check to see if we are using rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	$rewrite = $wp_rewrite->wp_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	if ( empty($rewrite) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
	// Get rid of the #anchor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	$url_split = explode('#', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	$url = $url_split[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
	// Get rid of URL ?query=string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	$url_split = explode('?', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	$url = $url_split[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	// Add 'www.' if it is absent and should be there
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
		$url = str_replace('://', '://www.', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	// Strip 'www.' if it is present and shouldn't be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	if ( false === strpos(home_url(), '://www.') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		$url = str_replace('://www.', '://', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	// Strip 'index.php/' if we're not using path info permalinks
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	if ( !$wp_rewrite->using_index_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		$url = str_replace( $wp_rewrite->index . '/', '', $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		// Chop off http://domain.com/[path]
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		$url = str_replace(home_url(), '', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
		// Chop off /path/to/blog
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
		$home_path = parse_url( home_url( '/' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
		$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
		$url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	// Trim leading and lagging slashes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
	$url = trim($url, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	$request = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	$post_type_query_vars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		if ( ! empty( $t->query_var ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
			$post_type_query_vars[ $t->query_var ] = $post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	// Look for matches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	$request_match = $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	foreach ( (array)$rewrite as $match => $query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		// If the requesting file is the anchor of the match, prepend it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		// to the path info.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
			$request_match = $url . '/' . $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
		if ( preg_match("#^$match#", $request_match, $matches) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
			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
   366
				// This is a verbose page match, let's check to be sure about it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
				if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
			// Got a match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
			// Trim the query of everything up to the '?'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
			$query = preg_replace("!^.+\?!", '', $query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			// Substitute the substring matches into the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
			$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
			// Filter out non-public query vars
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			global $wp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
			parse_str( $query, $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			$query = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
			foreach ( (array) $query_vars as $key => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
				if ( in_array( $key, $wp->public_query_vars ) ){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
					$query[$key] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
					if ( isset( $post_type_query_vars[$key] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
						$query['post_type'] = $post_type_query_vars[$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
						$query['name'] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
			// Do the query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			$query = new WP_Query( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
			if ( ! empty( $query->posts ) && $query->is_singular )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
				return $query->post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
				return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
 * WordPress Rewrite Component.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 * The WordPress Rewrite class writes the rewrite module rules to the .htaccess
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 * file. It also handles parsing the request to get the correct setup for the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * WordPress Query class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 * The Rewrite along with WP class function as a front controller for WordPress.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
 * You can add rules to trigger your page view and processing using this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
 * component. The full functionality of a front controller does not exist,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
 * meaning you can't define how the template files load based on the rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
 * rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
class WP_Rewrite {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	 * Permalink structure for posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	public $permalink_structure;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	 * Whether to add trailing slashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
	public $use_trailing_slashes;
0
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
	 * Base for the author permalink structure (example.com/$author_base/authorname).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	var $author_base = 'author';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	 * Permalink structure for author archives.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	var $author_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 * Permalink structure for date archives.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	var $date_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	 * Permalink structure for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	var $page_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
	 * Base of the search permalink structure (example.com/$search_base/query).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	var $search_base = 'search';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	 * Permalink structure for searches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	var $search_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	 * Comments permalink base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	var $comments_base = 'comments';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	 * Pagination permalink base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	 * @since 3.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
	 * @var string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	public $pagination_base = 'page';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
	 * Comments pagination permalink base.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
	 * @since 4.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
	var $comments_pagination_base = 'comment-page';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	 * Feed permalink base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	var $feed_base = 'feed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	 * Comments feed permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
	var $comment_feed_structure;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	 * Feed request permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	var $feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	 * The static portion of the post permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	 * If the permalink structure is "/archive/%post_id%" then the front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 * is "/archive/". If the permalink structure is "/%year%/%postname%/"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 * then the front is "/".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	 * @see WP_Rewrite::init()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
	public $front;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	 * The prefix for all permalink structures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
	 * If PATHINFO/index permalinks are in use then the root is the value of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
	 * {@link WP_Rewrite::$index} with a trailing slash appended. Otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	 * the root will be empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	 * @see WP_Rewrite::init()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	 * @see WP_Rewrite::using_index_permalinks()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
	public $root = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	 * The name of the index file which is the entry point to all requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
	public $index = 'index.php';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	 * Variable name to use for regex matches in the rewritten query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
	var $matches = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	 * Rewrite rules to match against the request to find the redirect or query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	var $rules;
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
	 * Additional rules added external to the rewrite class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
	 * Those not generated by the class, see add_rewrite_rule().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	var $extra_rules = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	 * Additional rules that belong at the beginning to match first.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	 * Those not generated by the class, see add_rewrite_rule().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
	var $extra_rules_top = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
	 * Rules that don't redirect to WordPress' index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
	 * These rules are written to the mod_rewrite portion of the .htaccess,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
	 * and are added by {@link add_external_rule()}.
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 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	var $non_wp_rules = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	 * Extra permalink structures, e.g. categories, added by {@link add_permastruct()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
	var $extra_permastructs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	 * Endpoints (like /trackback/) added by {@link add_rewrite_endpoint()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	var $endpoints;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	 * Whether to write every mod_rewrite rule for WordPress into the .htaccess file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	 * This is off by default, turning it on might print a lot of rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	 * to the .htaccess file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	 * @see WP_Rewrite::mod_rewrite_rules()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   659
	public $use_verbose_rules = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	 * Could post permalinks be confused with those of pages?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	 * If the first rewrite tag in the post permalink structure is one that could
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	 * also match a page name (e.g. %postname% or %author%) then this flag is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	 * set to true. Prior to WordPress 3.3 this flag indicated that every page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
	 * would have a set of rules added to the top of the rewrite rules array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	 * Now it tells {@link WP::parse_request()} to check if a URL matching the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	 * page permastruct is actually a page before accepting it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
	 * @link https://core.trac.wordpress.org/ticket/16687
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
	 * @see WP_Rewrite::init()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
	public $use_verbose_page_rules = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	 * Rewrite tags that can be used in permalink structures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
	 * These are translated into the regular expressions stored in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
	 * {@link WP_Rewrite::$rewritereplace} and are rewritten to the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	 * query variables listed in {@link WP_Rewrite::$queryreplace}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	 * Additional tags can be added with {@link add_rewrite_tag()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	var $rewritecode = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
		'%year%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
		'%monthnum%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
		'%day%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
		'%hour%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
		'%minute%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		'%second%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
		'%postname%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
		'%post_id%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		'%author%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
		'%pagename%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
		'%search%'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 * Regular expressions to be substituted into rewrite rules in place
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	 * of rewrite tags, see {@link WP_Rewrite::$rewritecode}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	var $rewritereplace = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		'([0-9]{4})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		'([^/]+)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
		'([0-9]+)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
		'([^/]+)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
		'([^/]+?)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
		'(.+)'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	 * Query variables that rewrite tags map to, see {@link WP_Rewrite::$rewritecode}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
	var $queryreplace = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
		'year=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
		'monthnum=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
		'day=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
		'hour=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		'minute=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
		'second=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
		'name=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
		'p=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		'author_name=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
		'pagename=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		's='
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
	 * Supported default feeds.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
	public $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
0
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
	 * Whether permalinks are being used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
	 * This can be either rewrite module or permalink in the HTTP query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
	 * @return bool True, if permalinks are enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
	public function using_permalinks() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
		return ! empty($this->permalink_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	 * Whether permalinks are being used and rewrite module is not enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
	 * Means that permalink links are enabled and index.php is in the URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
	public function using_index_permalinks() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		if ( empty($this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
		// If the index is not in the permalink, we're using mod_rewrite.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
		if ( preg_match('#^/*' . $this->index . '#', $this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
	 * Whether permalinks are being used and rewrite module is enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
	 * Using permalinks and index.php is not in the URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   802
	public function using_mod_rewrite_permalinks() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		if ( $this->using_permalinks() && ! $this->using_index_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
	 * Index for matches for usage in preg_*() functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
	 * The format of the string is, with empty matches property value, '$NUM'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	 * The 'NUM' will be replaced with the value in the $number parameter. With
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	 * the matches property not empty, the value of the returned string will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	 * contain that value of the matches property. The format then will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	 * '$MATCHES[NUM]', with MATCHES as the value in the property and NUM the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
	 * value of the $number parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
	 * @param int $number Index number.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
	public function preg_index($number) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
		$match_prefix = '$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
		$match_suffix = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
		if ( ! empty($this->matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
			$match_prefix = '$' . $this->matches . '[';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
			$match_suffix = ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
		return "$match_prefix$number$match_suffix";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
	 * Retrieve all page and attachments for pages URIs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
	 * The attachments are for those that have pages as parents and will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
	 * retrieved.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	 * @return array Array of page URIs as first element and attachment URIs as second element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   848
	public function page_uri_index() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
		//get pages in order of hierarchy, i.e. children after parents
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
		$pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
		$posts = get_page_hierarchy( $pages );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		// If we have no pages get out quick
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
		if ( !$posts )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
			return array( array(), array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
		//now reverse it, because we need parents after children for rewrite rules to work properly
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
		$posts = array_reverse($posts, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
		$page_uris = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
		$page_attachment_uris = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
		foreach ( $posts as $id => $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
			// URL => page name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
			$uri = get_page_uri($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
			$attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
			if ( !empty($attachments) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
				foreach ( $attachments as $attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
					$attach_uri = get_page_uri($attachment->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
					$page_attachment_uris[$attach_uri] = $attachment->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
			$page_uris[$uri] = $id;
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
		return array( $page_uris, $page_attachment_uris );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
	 * Retrieve all of the rewrite rules for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   890
	public function page_rewrite_rules() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
		// the extra .? at the beginning prevents clashes with other regular expressions in the rules array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		$this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
		return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 * Retrieve date permalink structure, with year, month, and day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
	 * The permalink structure for the date, if not set already depends on the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	 * permalink structure. It can be one of three formats. The first is year,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	 * month, day; the second is day, month, year; and the last format is month,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
	 * day, year. These are matched against the permalink structure for which
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
	 * one is used. If none matches, then the default will be used, which is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
	 * year, month, day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
	 * Prevents post ID and date permalinks from overlapping. In the case of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	 * post_id, the date permalink will be prepended with front permalink with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	 * 'date/' before the actual permalink to form the complete date permalink
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	 * structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
	 * @return string|false False on no permalink structure. Date permalink structure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
	public function get_date_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
		if ( isset($this->date_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
			return $this->date_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
			$this->date_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
		// The date permalink must have year, month, and day separated by slashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
		$endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
		$this->date_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
		$date_endian = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
		foreach ( $endians as $endian ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
			if ( false !== strpos($this->permalink_structure, $endian) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
				$date_endian= $endian;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
		if ( empty($date_endian) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
			$date_endian = '%year%/%monthnum%/%day%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
		// Do not allow the date tags and %post_id% to overlap in the permalink
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		// structure. If they do, move the date tags to $front/date/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
		$front = $this->front;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		$tok_index = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		foreach ( (array) $tokens[0] as $token) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
			if ( '%post_id%' == $token && ($tok_index <= 3) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
				$front = $front . 'date/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
			$tok_index++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
		$this->date_structure = $front . $date_endian;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
		return $this->date_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	 * Retrieve the year permalink structure without month and day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	 * Gets the date permalink structure and strips out the month and day
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	 * permalink structures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   969
	 * @return false|string False on failure. Year structure on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   971
	public function get_year_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		$structure = $this->get_date_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
		if ( empty($structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		$structure = str_replace('%monthnum%', '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
		$structure = str_replace('%day%', '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
		$structure = preg_replace('#/+#', '/', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
		return $structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	 * Retrieve the month permalink structure without day and with year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
	 * Gets the date permalink structure and strips out the day permalink
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
	 * structures. Keeps the year permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
	 * @return false|string False on failure. Year/Month structure on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   996
	public function get_month_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
		$structure = $this->get_date_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
		if ( empty($structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		$structure = str_replace('%day%', '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		$structure = preg_replace('#/+#', '/', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
		return $structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	 * Retrieve the day permalink structure with month and year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	 * Keeps date permalink structure with all year, month, and day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1017
	 * @return string|false False on failure. Year/Month/Day structure on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1019
	public function get_day_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
		return $this->get_date_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	 * Retrieve the permalink structure for categories.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
	 * If the category_base property has no value, then the category structure
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
	 * will have the front property value, followed by 'category', and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
	 * '%category%'. If it does, then the root property will be used, along with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
	 * the category_base property value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
	 * @return bool|string False on failure. Category permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
	public function get_category_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
		return $this->get_extra_permastruct('category');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	 * Retrieve the permalink structure for tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
	 * If the tag_base property has no value, then the tag structure will have
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
	 * the front property value, followed by 'tag', and finally '%tag%'. If it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
	 * does, then the root property will be used, along with the tag_base
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	 * property value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
	 * @return bool|string False on failure. Tag permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
	public function get_tag_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
		return $this->get_extra_permastruct('post_tag');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
	 * Retrieve extra permalink structure by name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
	 * @param string $name Permalink structure name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
	public function get_extra_permastruct($name) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
		if ( empty($this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
		if ( isset($this->extra_permastructs[$name]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
			return $this->extra_permastructs[$name]['struct'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
	 * Retrieve the author permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
	 * The permalink structure is front property, author base, and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
	 * '/%author%'. Will set the author_structure property and then return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
	 * without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
	 * @return string|false False if not found. Permalink structure string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1088
	public function get_author_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
		if ( isset($this->author_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
			return $this->author_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
			$this->author_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
		$this->author_structure = $this->front . $this->author_base . '/%author%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
		return $this->author_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
	 * Retrieve the search permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
	 * The permalink structure is root property, search base, and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
	 * '/%search%'. Will set the search_structure property and then return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
	 * without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1112
	 * @return string|false False if not found. Permalink structure string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1114
	public function get_search_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
		if ( isset($this->search_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
			return $this->search_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
			$this->search_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
		$this->search_structure = $this->root . $this->search_base . '/%search%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
		return $this->search_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
	 * Retrieve the page permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
	 * The permalink structure is root property, and '%pagename%'. Will set the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
	 * page_structure property and then return it without attempting to set the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
	 * value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
	 * @return string|false False if not found. Permalink structure string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
	public function get_page_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
		if ( isset($this->page_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
			return $this->page_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
		if (empty($this->permalink_structure)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
			$this->page_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
		$this->page_structure = $this->root . '%pagename%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
		return $this->page_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
	 * Retrieve the feed permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
	 * The permalink structure is root property, feed base, and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
	 * '/%feed%'. Will set the feed_structure property and then return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
	 * without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
	 * @return string|false False if not found. Permalink structure string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
	public function get_feed_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
		if ( isset($this->feed_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
			return $this->feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
			$this->feed_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
		$this->feed_structure = $this->root . $this->feed_base . '/%feed%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
		return $this->feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
	 * Retrieve the comment feed permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
	 * The permalink structure is root property, comment base property, feed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
	 * base and finally '/%feed%'. Will set the comment_feed_structure property
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
	 * and then return it without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
	public function get_comment_feed_permastruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
		if ( isset($this->comment_feed_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
			return $this->comment_feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
		if (empty($this->permalink_structure)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
			$this->comment_feed_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
		$this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
		return $this->comment_feed_structure;
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
	 * Add or update existing rewrite tags (e.g. %postname%).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
	 * If the tag already exists, replace the existing pattern and query for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
	 * that tag, otherwise add the new tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
	 * @see WP_Rewrite::$rewritecode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
	 * @see WP_Rewrite::$rewritereplace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
	 * @see WP_Rewrite::$queryreplace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
	 * @param string $tag Name of the rewrite tag to add or update.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
	 * @param string $regex Regular expression to substitute the tag for in rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
	 * @param string $query String to append to the rewritten query. Must end in '='.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
	public function add_rewrite_tag( $tag, $regex, $query ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
		$position = array_search( $tag, $this->rewritecode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
		if ( false !== $position && null !== $position ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
			$this->rewritereplace[ $position ] = $regex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
			$this->queryreplace[ $position ] = $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
			$this->rewritecode[] = $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
			$this->rewritereplace[] = $regex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
			$this->queryreplace[] = $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
	 * Generate rewrite rules from a permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
	 * The main WP_Rewrite function for building the rewrite rule list. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
	 * contents of the function is a mix of black magic and regular expressions,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
	 * so best just ignore the contents and move to the parameters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	 * @param string $permalink_structure The permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
	 * @param int $ep_mask Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
	 * @param bool $paged Should archive pagination rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
	 * @param bool $feed Should feed rewrite rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
	 * @param bool $forcomments Should the feed rules be a query for a comments feed? Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
	 * @param bool $walk_dirs Should the 'directories' making up the structure be walked over and rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
	 *                        built for each in turn? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
	 * @param bool $endpoints Should endpoints be applied to the generated rewrite rules? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
	 * @return array Rewrite rule list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1254
	public function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
		//build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
		$feedregex2 = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
		foreach ( (array) $this->feeds as $feed_name)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
			$feedregex2 .= $feed_name . '|';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
		$feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
		//$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
		//and <permalink>/atom are both possible
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
		$feedregex = $this->feed_base . '/' . $feedregex2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
		//build a regex to match the trackback and page/xx parts of URLs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
		$trackbackregex = 'trackback/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
		$pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
		$commentregex = $this->comments_pagination_base . '-([0-9]{1,})/?$';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
		//build up an array of endpoint regexes to append => queries to append
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
		if ( $endpoints ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
			$ep_query_append = array ();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
			foreach ( (array) $this->endpoints as $endpoint) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
				//match everything after the endpoint name, but allow for nothing to appear there
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
				$epmatch = $endpoint[1] . '(/(.*))?/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
				//this will be appended on to the rest of the query for each dir
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1277
				$epquery = '&' . $endpoint[2] . '=';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
				$ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
		//get everything up to the first rewrite tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
		$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
		//build an array of the tags (note that said array ends up being in $tokens[0])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
		preg_match_all('/%.+?%/', $permalink_structure, $tokens);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
		$num_tokens = count($tokens[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
		$index = $this->index; //probably 'index.php'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
		$feedindex = $index;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
		$trackbackindex = $index;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
		//build a list from the rewritecode and queryreplace arrays, that will look something like
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
		//tagname=$matches[i] where i is the current $i
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
		$queries = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
		for ( $i = 0; $i < $num_tokens; ++$i ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
			if ( 0 < $i )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
				$queries[$i] = $queries[$i - 1] . '&';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
				$queries[$i] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
			$query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
			$queries[$i] .= $query_token;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
		//get the structure, minus any cruft (stuff that isn't tags) at the front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
		$structure = $permalink_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
		if ( $front != '/' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
			$structure = str_replace($front, '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
		//create a list of dirs to walk over, making rewrite rules for each level
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
		//so for example, a $structure of /%year%/%monthnum%/%postname% would create
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
		//rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
		$structure = trim($structure, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
		$dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
		$num_dirs = count($dirs);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
		//strip slashes from the front of $front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		$front = preg_replace('|^/+|', '', $front);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
		//the main workhorse loop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		$post_rewrite = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
		$struct = $front;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
		for ( $j = 0; $j < $num_dirs; ++$j ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
			//get the struct for this dir, and trim slashes off the front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
			$struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
			$struct = ltrim($struct, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
			//replace tags with regexes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
			$match = str_replace($this->rewritecode, $this->rewritereplace, $struct);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
			//make a list of tags, and store how many there are in $num_toks
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
			$num_toks = preg_match_all('/%.+?%/', $struct, $toks);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
			//get the 'tagname=$matches[i]'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1335
			$query = ( ! empty( $num_toks ) && isset( $queries[$num_toks - 1] ) ) ? $queries[$num_toks - 1] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
			//set up $ep_mask_specific which is used to match more specific URL types
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
			switch ( $dirs[$j] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
				case '%year%':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
					$ep_mask_specific = EP_YEAR;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
				case '%monthnum%':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
					$ep_mask_specific = EP_MONTH;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
				case '%day%':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
					$ep_mask_specific = EP_DAY;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
				default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
					$ep_mask_specific = EP_NONE;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
			//create query for /page/xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
			$pagematch = $match . $pageregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
			$pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
			//create query for /comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
			$commentmatch = $match . $commentregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			$commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
			if ( get_option('page_on_front') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
				//create query for Root /comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
				$rootcommentmatch = $match . $commentregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
				$rootcommentquery = $index . '?' . $query . '&page_id=' . get_option('page_on_front') . '&cpage=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
			//create query for /feed/(feed|atom|rss|rss2|rdf)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
			$feedmatch = $match . $feedregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			$feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
			//create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
			$feedmatch2 = $match . $feedregex2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
			$feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
			//if asked to, turn the feed queries into comment feed ones
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
			if ( $forcomments ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
				$feedquery .= '&withcomments=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
				$feedquery2 .= '&withcomments=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
			//start creating the array of rewrites for this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
			$rewrite = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
			if ( $feed ) //...adding on /feed/ regexes => queries
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
				$rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
			if ( $paged ) //...and /page/xx ones
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
				$rewrite = array_merge($rewrite, array($pagematch => $pagequery));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
			//only on pages with comments add ../comment-page-xx/
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
			if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
				$rewrite = array_merge($rewrite, array($commentmatch => $commentquery));
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
			} elseif ( EP_ROOT & $ep_mask && get_option('page_on_front') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
				$rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery));
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
			//do endpoints
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
			if ( $endpoints ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
				foreach ( (array) $ep_query_append as $regex => $ep) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
					//add the endpoints on if the mask fits
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
					if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
						$rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
				}
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
			//if we've got some tags in this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
			if ( $num_toks ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
				$post = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
				$page = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
				//check to see if this dir is permalink-level: i.e. the structure specifies an
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
				//individual post. Do this by checking it contains at least one of 1) post name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
				//2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
				//minute all present). Set these flags now as we need them for the endpoints.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
				if ( strpos($struct, '%postname%') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
						|| strpos($struct, '%post_id%') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
						|| strpos($struct, '%pagename%') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
						|| (strpos($struct, '%year%') !== false && strpos($struct, '%monthnum%') !== false && strpos($struct, '%day%') !== false && strpos($struct, '%hour%') !== false && strpos($struct, '%minute%') !== false && strpos($struct, '%second%') !== false)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
						) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
					$post = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
					if ( strpos($struct, '%pagename%') !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
						$page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
				if ( ! $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
					// For custom post types, we need to add on endpoints as well.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
					foreach ( get_post_types( array('_builtin' => false ) ) as $ptype ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
						if ( strpos($struct, "%$ptype%") !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
							$post = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
							$page = is_post_type_hierarchical( $ptype ); // This is for page style attachment url's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
							break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
				//if we're creating rules for a permalink, do all the endpoints like attachments etc
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
				if ( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
					//create query and regex for trackback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
					$trackbackmatch = $match . $trackbackregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
					$trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
					//trim slashes from the end of the regex for this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
					$match = rtrim($match, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
					//get rid of brackets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
					$submatchbase = str_replace( array('(', ')'), '', $match);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
					//add a rule for at attachments, which take the form of <permalink>/some-text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
					$sub1 = $submatchbase . '/([^/]+)/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
					$sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
					$sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
					$sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
					$sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
					//add another rule to match attachments in the explicit form:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
					//<permalink>/attachment/some-text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
					$sub2 = $submatchbase . '/attachment/([^/]+)/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
					$sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
					$sub2feed = $sub2 . $feedregex;    //feeds, <permalink>/attachment/feed/(atom|...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
					$sub2feed2 = $sub2 . $feedregex2;  //and feeds again on to this <permalink>/attachment/(feed|atom...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
					$sub2comment = $sub2 . $commentregex; //and <permalink>/comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
					//create queries for these extra tag-ons we've just dealt with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
					$subquery = $index . '?attachment=' . $this->preg_index(1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
					$subtbquery = $subquery . '&tb=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
					$subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
					$subcommentquery = $subquery . '&cpage=' . $this->preg_index(2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
					//do endpoints for attachments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
					if ( !empty($endpoints) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
						foreach ( (array) $ep_query_append as $regex => $ep ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
							if ( $ep[0] & EP_ATTACHMENT ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
								$rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this->preg_index(3);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
								$rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this->preg_index(3);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
					//now we've finished with endpoints, finish off the $sub1 and $sub2 matches
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
					//add a ? as we don't have to match that last slash, and finally a $ so we
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
					//match to the end of the URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
					$sub1 .= '?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
					$sub2 .= '?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
					//post pagination, e.g. <permalink>/2/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
					$match = $match . '(/[0-9]+)?/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
					$query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
				} else { //not matching a permalink so this is a lot simpler
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
					//close the match and finalise the query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
					$match .= '?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
					$query = $index . '?' . $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
				//create the final array for this dir by joining the $rewrite array (which currently
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
				//only contains rules/queries for trackback, pages etc) to the main regex/query for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
				//this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
				$rewrite = array_merge($rewrite, array($match => $query));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
				//if we're matching a permalink, add those extras (attachments etc) on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
				if ( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
					//add trackback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
					$rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
					//add regexes/queries for attachments, attachment trackbacks and so on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
					if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
						$rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
					$rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
			} //if($num_toks)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
			//add the rules for this dir to the accumulating $post_rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
			$post_rewrite = array_merge($rewrite, $post_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
		} //foreach ($dir)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
		return $post_rewrite; //the finished rules. phew!
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
	 * Generate Rewrite rules with permalink structure and walking directory only.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
	 * Shorten version of {@link WP_Rewrite::generate_rewrite_rules()} that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
	 * allows for shorter list of parameters. See the method for longer
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
	 * description of what generating rewrite rules does.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
	 * @uses WP_Rewrite::generate_rewrite_rules() See for long description and rest of parameters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
	 * @param string $permalink_structure The permalink structure to generate rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
	 * @param bool $walk_dirs Optional, default is false. Whether to create list of directories to walk over.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
	public function generate_rewrite_rule($permalink_structure, $walk_dirs = false) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
		return $this->generate_rewrite_rules($permalink_structure, EP_NONE, false, false, false, $walk_dirs);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
	 * Construct rewrite matches and queries from permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
	 * Runs the action 'generate_rewrite_rules' with the parameter that is an
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
	 * reference to the current WP_Rewrite instance to further manipulate the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
	 * permalink structures and rewrite rules. Runs the 'rewrite_rules_array'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
	 * filter on the full rewrite rule array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
	 * There are two ways to manipulate the rewrite rules, one by hooking into
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
	 * the 'generate_rewrite_rules' action and gaining full control of the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
	 * object or just manipulating the rewrite rule array before it is passed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
	 * from the function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
	 * @return array An associate array of matches and queries.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1547
	public function rewrite_rules() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
		$rewrite = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
		if ( empty($this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
			return $rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
		// robots.txt -only if installed at the root
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
		$home_path = parse_url( home_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
		$robots_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
		// Old feed and service files
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
		$deprecated_files = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
			'.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
			'.*wp-app\.php(/.*)?$' => $this->index . '?error=403',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
		// Registration rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
		$registration_pages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
		if ( is_multisite() && is_main_site() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
			$registration_pages['.*wp-signup.php$'] = $this->index . '?signup=true';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
			$registration_pages['.*wp-activate.php$'] = $this->index . '?activate=true';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
		$registration_pages['.*wp-register.php$'] = $this->index . '?register=true'; // Deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1571
		// Post rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
		$post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1573
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1574
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1575
		 * Filter rewrite rules used for "post" archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1576
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1577
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1578
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1579
		 * @param array $post_rewrite The rewrite rules for posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1580
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1581
		$post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1583
		// Date rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
		$date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1585
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1586
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
		 * Filter rewrite rules used for date archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1588
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1589
		 * Likely date archives would include /yyyy/, /yyyy/mm/, and /yyyy/mm/dd/.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1590
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1591
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1592
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1593
		 * @param array $date_rewrite The rewrite rules for date archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1594
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1595
		$date_rewrite = apply_filters( 'date_rewrite_rules', $date_rewrite );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1597
		// Root-level rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
		$root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1601
		 * Filter rewrite rules used for root-level archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1602
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1603
		 * Likely root-level archives would include pagination rules for the homepage
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1604
		 * as well as site-wide post feeds (e.g. /feed/, and /feed/atom/).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1605
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1606
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1607
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1608
		 * @param array $root_rewrite The root-level rewrite rules.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1609
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1610
		$root_rewrite = apply_filters( 'root_rewrite_rules', $root_rewrite );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1612
		// Comments rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
		$comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, false, true, true, false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1615
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1616
		 * Filter rewrite rules used for comment feed archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1617
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1618
		 * Likely comments feed archives include /comments/feed/, and /comments/feed/atom/.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1619
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1620
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1621
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1622
		 * @param array $comments_rewrite The rewrite rules for the site-wide comments feeds.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1623
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1624
		$comments_rewrite = apply_filters( 'comments_rewrite_rules', $comments_rewrite );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1625
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1626
		// Search rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
		$search_structure = $this->get_search_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
		$search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1630
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1631
		 * Filter rewrite rules used for search archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1632
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1633
		 * Likely search-related archives include /search/search+query/ as well as
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1634
		 * pagination and feed paths for a search.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1635
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1636
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1637
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1638
		 * @param array $search_rewrite The rewrite rules for search queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1639
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1640
		$search_rewrite = apply_filters( 'search_rewrite_rules', $search_rewrite );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1641
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1642
		// Author rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
		$author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1645
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1646
		 * Filter rewrite rules used for author archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1647
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1648
		 * Likely author archives would include /author/author-name/, as well as
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1649
		 * pagination and feed paths for author archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1650
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1651
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1652
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1653
		 * @param array $author_rewrite The rewrite rules for author archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1655
		$author_rewrite = apply_filters( 'author_rewrite_rules', $author_rewrite );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1656
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1657
		// Pages rewrite rules.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
		$page_rewrite = $this->page_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1660
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1661
		 * Filter rewrite rules used for "page" post type archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1662
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1663
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1664
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1665
		 * @param array $page_rewrite The rewrite rules for the "page" post type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1666
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1667
		$page_rewrite = apply_filters( 'page_rewrite_rules', $page_rewrite );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1668
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
		// Extra permastructs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
		foreach ( $this->extra_permastructs as $permastructname => $struct ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
			if ( is_array( $struct ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
				if ( count( $struct ) == 2 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
					$rules = $this->generate_rewrite_rules( $struct[0], $struct[1] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
					$rules = $this->generate_rewrite_rules( $struct['struct'], $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
				$rules = $this->generate_rewrite_rules( $struct );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1680
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1681
			 * Filter rewrite rules used for individual permastructs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1682
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1683
			 * The dynamic portion of the hook name, `$permastructname`, refers
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1684
			 * to the name of the registered permastruct, e.g. 'post_tag' (tags),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1685
			 * 'category' (categories), etc.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1686
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1687
			 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1688
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1689
			 * @param array $rules The rewrite rules generated for the current permastruct.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1690
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1691
			$rules = apply_filters( $permastructname . '_rewrite_rules', $rules );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1692
			if ( 'post_tag' == $permastructname ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1693
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1694
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1695
				 * Filter rewrite rules used specifically for Tags.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1696
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1697
				 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1698
				 * @deprecated 3.1.0 Use 'post_tag_rewrite_rules' instead
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1699
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1700
				 * @param array $rules The rewrite rules generated for tags.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1701
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1702
				$rules = apply_filters( 'tag_rewrite_rules', $rules );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1703
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
			$this->extra_rules_top = array_merge($this->extra_rules_top, $rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
		// Put them together.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
		if ( $this->use_verbose_page_rules )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1714
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1715
		 * Fires after the rewrite rules are generated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1716
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1717
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1718
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1719
		 * @param WP_Rewrite $this Current WP_Rewrite instance, passed by reference.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1720
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1721
		do_action_ref_array( 'generate_rewrite_rules', array( &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1722
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1723
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1724
		 * Filter the full set of generated rewrite rules.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1725
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1726
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1727
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1728
		 * @param array $this->rules The compiled array of rewrite rules.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1729
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1730
		$this->rules = apply_filters( 'rewrite_rules_array', $this->rules );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
		return $this->rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
	 * Retrieve the rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
	 * The difference between this method and {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
	 * WP_Rewrite::rewrite_rules()} is that this method stores the rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
	 * in the 'rewrite_rules' option and retrieves it. This prevents having to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
	 * process all of the permalinks to get the rewrite rules in the form of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
	 * caching.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
	 * @return array Rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1749
	public function wp_rewrite_rules() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
		$this->rules = get_option('rewrite_rules');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
		if ( empty($this->rules) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
			$this->matches = 'matches';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
			$this->rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
			update_option('rewrite_rules', $this->rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
		return $this->rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
	 * Retrieve mod_rewrite formatted rewrite rules to write to .htaccess.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
	 * Does not actually write to the .htaccess file, but creates the rules for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
	 * the process that will.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
	 * Will add the non_wp_rules property rules to the .htaccess file before
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
	 * the WordPress rewrite rules one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1774
	public function mod_rewrite_rules() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
		if ( ! $this->using_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
		$site_root = parse_url( site_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
		if ( isset( $site_root['path'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
			$site_root = trailingslashit($site_root['path']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
		$home_root = parse_url(home_url());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
		if ( isset( $home_root['path'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
			$home_root = trailingslashit($home_root['path']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
			$home_root = '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
		$rules = "<IfModule mod_rewrite.c>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
		$rules .= "RewriteEngine On\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
		$rules .= "RewriteBase $home_root\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
		$rules .= "RewriteRule ^index\.php$ - [L]\n"; // Prevent -f checks on index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
		//add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
		foreach ( (array) $this->non_wp_rules as $match => $query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
			// Apache 1.3 does not support the reluctant (non-greedy) modifier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
			$match = str_replace('.+?', '.+', $match);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
			// If the match is unanchored and greedy, prepend rewrite conditions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
			// to avoid infinite redirects and eclipsing of real files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
			//if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
				//nada.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
			//}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
			$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
		if ( $this->use_verbose_rules ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
			$this->matches = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
			$rewrite = $this->rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
			$num_rules = count($rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
			$rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
				"RewriteCond %{REQUEST_FILENAME} -d\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
				"RewriteRule ^.*$ - [S=$num_rules]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
			foreach ( (array) $rewrite as $match => $query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
				// Apache 1.3 does not support the reluctant (non-greedy) modifier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
				$match = str_replace('.+?', '.+', $match);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
				// If the match is unanchored and greedy, prepend rewrite conditions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
				// to avoid infinite redirects and eclipsing of real files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
				//if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
					//nada.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
				//}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
				if ( strpos($query, $this->index) !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
					$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
					$rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
			$rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
				"RewriteCond %{REQUEST_FILENAME} !-d\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
				"RewriteRule . {$home_root}{$this->index} [L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
		$rules .= "</IfModule>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1838
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1839
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1840
		 * Filter the list of rewrite rules formatted for output to an .htaccess file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1841
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1842
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1843
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1844
		 * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1845
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1846
		$rules = apply_filters( 'mod_rewrite_rules', $rules );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1847
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1848
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1849
		 * Filter the list of rewrite rules formatted for output to an .htaccess file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1850
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1851
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1852
		 * @deprecated 1.5.0 Use the mod_rewrite_rules filter instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1853
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1854
		 * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1855
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1856
		$rules = apply_filters( 'rewrite_rules', $rules );  // Deprecated
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
		return $rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
	 * Retrieve IIS7 URL Rewrite formatted rewrite rules to write to web.config file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
	 * Does not actually write to the web.config file, but creates the rules for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
	 * the process that will.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1869
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1872
	public function iis7_url_rewrite_rules( $add_parent_tags = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
		if ( ! $this->using_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
		$rules = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
		if ( $add_parent_tags ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
			$rules .= '<configuration>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
	<system.webServer>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
		<rewrite>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
			<rules>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
		$rules .= '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
			<rule name="wordpress" patternSyntax="Wildcard">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
				<match url="*" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
					<conditions>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
						<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
					</conditions>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
				<action type="Rewrite" url="index.php" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
			</rule>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
		if ( $add_parent_tags ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
			$rules .= '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
			</rules>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
		</rewrite>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
	</system.webServer>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
</configuration>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
5
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
		 * Filter the list of rewrite rules formatted for output to a web.config.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1904
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1905
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1906
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1907
		 * @param string $rules Rewrite rules formatted for IIS web.config.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1908
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1909
		$rules = apply_filters( 'iis7_url_rewrite_rules', $rules );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
		return $rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
	 * Add a straight rewrite rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
	 * Any value in the $after parameter that isn't 'bottom' will be placed at
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
	 * the top of the rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
	 * @param string $regex Regular expression to match against request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
	 * @param string $redirect URL regex redirects to when regex matches request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
	 * @param string $after Optional, default is bottom. Location to place rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
	public function add_rule($regex, $redirect, $after = 'bottom') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
		//get everything up to the first ?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
		$index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
		$front = substr($redirect, 0, $index);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
		if ( $front != $this->index ) { //it doesn't redirect to WP's index.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
			$this->add_external_rule($regex, $redirect);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
			if ( 'bottom' == $after)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
				$this->extra_rules = array_merge($this->extra_rules, array($regex => $redirect));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
				$this->extra_rules_top = array_merge($this->extra_rules_top, array($regex => $redirect));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
			//$this->extra_rules[$regex] = $redirect;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
	 * Add a rule that doesn't redirect to index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
	 * Can redirect to any place.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
	 * @param string $regex Regular expression to match against request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
	 * @param string $redirect URL regex redirects to when regex matches request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
	public function add_external_rule($regex, $redirect) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
		$this->non_wp_rules[$regex] = $redirect;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
	 * Add an endpoint, like /trackback/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1960
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1961
	 * @since 3.9.0 $query_var parameter added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1962
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1964
	 * @see add_rewrite_endpoint() for full documentation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
	 * @uses WP::add_query_var()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1967
	 * @param string $name      Name of the endpoint.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1968
	 * @param int    $places    Endpoint mask describing the places the endpoint should be added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1969
	 * @param string $query_var Name of the corresponding query variable. Default is value of $name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1971
	public function add_endpoint( $name, $places, $query_var = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
		global $wp;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1973
		if ( null === $query_var ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1974
			$query_var = $name;
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
		$this->endpoints[] = array( $places, $name, $query_var );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1977
		$wp->add_query_var( $query_var );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
	 * Add a new permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
	 * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
	 * is an easy way of expressing a set of regular expressions that rewrite to a set of query strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
	 * The new permastruct is added to the {@link WP_Rewrite::$extra_permastructs} array. When the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
	 * rewrite rules are built by {@link WP_Rewrite::rewrite_rules()} all of these extra permastructs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
	 * are passed to {@link WP_Rewrite::generate_rewrite_rules()} which transforms them into the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
	 * regular expressions that many love to hate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
	 * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
	 * works on the new permastruct.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
	 * @param string $name Name for permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
	 * @param string $struct Permalink structure (e.g. category/%category%)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
	 * @param array $args Optional configuration for building the rules from the permalink structure:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
	 *     - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
	 *     - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
	 *     - paged (bool) - Should archive pagination rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
	 *     - feed (bool) - Should feed rewrite rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
	 *     - forcomments (bool) - Should the feed rules be a query for a comments feed? Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
	 *     - walk_dirs (bool) - Should the 'directories' making up the structure be walked over and rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
	 *                          rules built for each in turn? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
	 *     - endpoints (bool) - Should endpoints be applied to the generated rewrite rules? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2008
	public function add_permastruct( $name, $struct, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
		// backwards compatibility for the old parameters: $with_front and $ep_mask
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
		if ( ! is_array( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
			$args = array( 'with_front' => $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
		if ( func_num_args() == 4 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
			$args['ep_mask'] = func_get_arg( 3 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
		$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
			'with_front' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
			'ep_mask' => EP_NONE,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
			'paged' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
			'feed' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
			'forcomments' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
			'walk_dirs' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
			'endpoints' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
		$args = array_intersect_key( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
		$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
		if ( $args['with_front'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
			$struct = $this->front . $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
			$struct = $this->root . $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
		$args['struct'] = $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
		$this->extra_permastructs[ $name ] = $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
	 * Remove rewrite rules and then recreate rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
	 * Calls {@link WP_Rewrite::wp_rewrite_rules()} after removing the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
	 * 'rewrite_rules' option. If the function named 'save_mod_rewrite_rules'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
	 * exists, it will be called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
	 * @since 2.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
	 * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2047
	public function flush_rules( $hard = true ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2048
		static $do_hard_later;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2049
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2050
		// Prevent this action from running before everyone has registered their rewrites
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2051
		if ( ! did_action( 'wp_loaded' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2052
			add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2053
			$do_hard_later = ( isset( $do_hard_later ) ) ? $do_hard_later || $hard : $hard;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2054
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2055
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2056
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2057
		if ( isset( $do_hard_later ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2058
			$hard = $do_hard_later;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2059
			unset( $do_hard_later );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2060
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2061
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
		delete_option('rewrite_rules');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
		$this->wp_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
		 * Filter whether a "hard" rewrite rule flush should be performed when requested.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
		 * A "hard" flush updates .htaccess (Apache) or web.config (IIS).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
		 * @since 3.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2070
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2071
		 * @param bool $hard Whether to flush rewrite rules "hard". Default true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2073
		if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2075
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
		if ( function_exists( 'save_mod_rewrite_rules' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
			save_mod_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
		if ( function_exists( 'iis7_save_url_rewrite_rules' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
			iis7_save_url_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
	 * Sets up the object's properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
	 * The 'use_verbose_page_rules' object property will be set to true if the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
	 * permalink structure begins with one of the following: '%postname%', '%category%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
	 * '%tag%', or '%author%'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2092
	public function init() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
		$this->extra_rules = $this->non_wp_rules = $this->endpoints = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
		$this->permalink_structure = get_option('permalink_structure');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
		$this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
		$this->root = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
		if ( $this->using_index_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
			$this->root = $this->index . '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
		unset($this->author_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
		unset($this->date_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
		unset($this->page_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
		unset($this->search_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
		unset($this->feed_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
		unset($this->comment_feed_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
		$this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
		// Enable generic rules for pages if permalink structure doesn't begin with a wildcard.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
		if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
			 $this->use_verbose_page_rules = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2110
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
			$this->use_verbose_page_rules = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
	 * Set the main permalink structure for the blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
	 * Will update the 'permalink_structure' option, if there is a difference
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
	 * between the current permalink structure and the parameter value. Calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
	 * {@link WP_Rewrite::init()} after the option is updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
	 * Fires the 'permalink_structure_changed' action once the init call has
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
	 * processed passing the old and new values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
	 * @param string $permalink_structure Permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2129
	public function set_permalink_structure($permalink_structure) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
		if ( $permalink_structure != $this->permalink_structure ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
			$old_permalink_structure = $this->permalink_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
			update_option('permalink_structure', $permalink_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
			$this->init();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2134
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2135
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2136
			 * Fires after the permalink structure is updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2137
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2138
			 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2139
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2140
			 * @param string $old_permalink_structure The previous permalink structure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2141
			 * @param string $permalink_structure     The new permalink structure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2142
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2143
			do_action( 'permalink_structure_changed', $old_permalink_structure, $permalink_structure );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2145
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2148
	 * Set the category base for the category permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
	 * Will update the 'category_base' option, if there is a difference between
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2151
	 * the current category base and the parameter value. Calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2152
	 * {@link WP_Rewrite::init()} after the option is updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
	 * @param string $category_base Category permalink structure base.
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
	public function set_category_base($category_base) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
		if ( $category_base != get_option('category_base') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
			update_option('category_base', $category_base);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
			$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
	 * Set the tag base for the tag permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
	 * Will update the 'tag_base' option, if there is a difference between the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
	 * current tag base and the parameter value. Calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
	 * {@link WP_Rewrite::init()} after the option is updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2174
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
	 * @param string $tag_base Tag permalink structure base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2178
	public function set_tag_base( $tag_base ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
		if ( $tag_base != get_option( 'tag_base') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
			update_option( 'tag_base', $tag_base );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
			$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
	 * Constructor - Calls init(), which runs setup.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2192
	public function __construct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
		$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
}