| 1 |
<?php |
| 2 |
|
| 3 |
add_action( 'init', 'bogo_add_rewrite_tags' ); |
| 4 |
|
| 5 |
function bogo_add_rewrite_tags() { |
| 6 |
$regex = bogo_get_lang_regex(); |
| 7 |
|
| 8 |
if ( empty( $regex ) ) |
| 9 |
return; |
| 10 |
|
| 11 |
add_rewrite_tag( '%lang%', $regex, 'lang=' ); |
| 12 |
|
| 13 |
$old_regex = bogo_get_prop( 'lang_rewrite_regex' ); |
| 14 |
|
| 15 |
if ( $regex != $old_regex ) { |
| 16 |
bogo_set_prop( 'lang_rewrite_regex', $regex ); |
| 17 |
flush_rewrite_rules(); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
add_filter( 'root_rewrite_rules', 'bogo_root_rewrite_rules' ); |
| 22 |
|
| 23 |
function bogo_root_rewrite_rules( $root_rewrite ) { |
| 24 |
global $wp_rewrite; |
| 25 |
|
| 26 |
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/'; |
| 27 |
|
| 28 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 29 |
'ep_mask' => EP_ROOT ) ); |
| 30 |
|
| 31 |
return array_merge( $extra, $root_rewrite ); |
| 32 |
} |
| 33 |
|
| 34 |
add_filter( 'post_rewrite_rules', 'bogo_post_rewrite_rules' ); |
| 35 |
|
| 36 |
function bogo_post_rewrite_rules( $post_rewrite ) { |
| 37 |
global $wp_rewrite; |
| 38 |
|
| 39 |
$permastruct = $wp_rewrite->permalink_structure; |
| 40 |
|
| 41 |
// from wp-admin/includes/misc.php |
| 42 |
$got_rewrite = apply_filters( 'got_rewrite', |
| 43 |
apache_mod_loaded( 'mod_rewrite', true ) ); |
| 44 |
$got_url_rewrite = apply_filters( 'got_url_rewrite', |
| 45 |
$got_rewrite || $GLOBALS['is_nginx'] || iis7_supports_permalinks() ); |
| 46 |
|
| 47 |
if ( ! $got_url_rewrite ) { |
| 48 |
$permastruct = preg_replace( |
| 49 |
'#^/index\.php#', '/index.php/%lang%', $permastruct ); |
| 50 |
} elseif ( is_multisite() && ! is_subdomain_install() && is_main_site() ) { |
| 51 |
$permastruct = preg_replace( |
| 52 |
'#^/blog#', '/%lang%/blog', $permastruct ); |
| 53 |
} else { |
| 54 |
$permastruct = preg_replace( |
| 55 |
'#^/#', '/%lang%/', $permastruct ); |
| 56 |
} |
| 57 |
|
| 58 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 59 |
'ep_mask' => EP_PERMALINK, |
| 60 |
'paged' => false ) ); |
| 61 |
|
| 62 |
return array_merge( $extra, $post_rewrite ); |
| 63 |
} |
| 64 |
|
| 65 |
add_filter( 'date_rewrite_rules', 'bogo_date_rewrite_rules' ); |
| 66 |
|
| 67 |
function bogo_date_rewrite_rules( $date_rewrite ) { |
| 68 |
global $wp_rewrite; |
| 69 |
|
| 70 |
$permastruct = $wp_rewrite->get_date_permastruct(); |
| 71 |
|
| 72 |
$permastruct = preg_replace( |
| 73 |
'#^' . $wp_rewrite->front . '#', |
| 74 |
'/%lang%' . $wp_rewrite->front, |
| 75 |
$permastruct ); |
| 76 |
|
| 77 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 78 |
'ep_mask' => EP_DATE ) ); |
| 79 |
|
| 80 |
return array_merge( $extra, $date_rewrite ); |
| 81 |
} |
| 82 |
|
| 83 |
add_filter( 'comments_rewrite_rules', 'bogo_comments_rewrite_rules' ); |
| 84 |
|
| 85 |
function bogo_comments_rewrite_rules( $comments_rewrite ) { |
| 86 |
global $wp_rewrite; |
| 87 |
|
| 88 |
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/' . $wp_rewrite->comments_base; |
| 89 |
|
| 90 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 91 |
'ep_mask' => EP_COMMENTS, |
| 92 |
'forcomments' => true, |
| 93 |
'walk_dirs' => false ) ); |
| 94 |
|
| 95 |
return array_merge( $extra, $comments_rewrite ); |
| 96 |
} |
| 97 |
|
| 98 |
add_filter( 'search_rewrite_rules', 'bogo_search_rewrite_rules' ); |
| 99 |
|
| 100 |
function bogo_search_rewrite_rules( $search_rewrite ) { |
| 101 |
global $wp_rewrite; |
| 102 |
|
| 103 |
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/' |
| 104 |
. $wp_rewrite->search_base . '/%search%'; |
| 105 |
|
| 106 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 107 |
'ep_mask' => EP_SEARCH ) ); |
| 108 |
|
| 109 |
return array_merge( $extra, $search_rewrite ); |
| 110 |
} |
| 111 |
|
| 112 |
add_filter( 'author_rewrite_rules', 'bogo_author_rewrite_rules' ); |
| 113 |
|
| 114 |
function bogo_author_rewrite_rules( $author_rewrite ) { |
| 115 |
global $wp_rewrite; |
| 116 |
|
| 117 |
$permastruct = $wp_rewrite->get_author_permastruct(); |
| 118 |
|
| 119 |
$permastruct = preg_replace( |
| 120 |
'#^' . $wp_rewrite->front . '#', |
| 121 |
'/%lang%' . $wp_rewrite->front, |
| 122 |
$permastruct ); |
| 123 |
|
| 124 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 125 |
'ep_mask' => EP_AUTHORS ) ); |
| 126 |
|
| 127 |
return array_merge( $extra, $author_rewrite ); |
| 128 |
} |
| 129 |
|
| 130 |
add_filter( 'page_rewrite_rules', 'bogo_page_rewrite_rules' ); |
| 131 |
|
| 132 |
function bogo_page_rewrite_rules( $page_rewrite ) { |
| 133 |
global $wp_rewrite; |
| 134 |
|
| 135 |
$wp_rewrite->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' ); |
| 136 |
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/%pagename%'; |
| 137 |
|
| 138 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 139 |
'ep_mask' => EP_PAGES, |
| 140 |
'walk_dirs' => false ) ); |
| 141 |
|
| 142 |
return array_merge( $extra, $page_rewrite ); |
| 143 |
} |
| 144 |
|
| 145 |
add_filter( 'category_rewrite_rules', 'bogo_category_rewrite_rules' ); |
| 146 |
|
| 147 |
function bogo_category_rewrite_rules( $category_rewrite ) { |
| 148 |
return bogo_taxonomy_rewrite_rules( $category_rewrite, 'category', EP_CATEGORIES ); |
| 149 |
} |
| 150 |
|
| 151 |
add_filter( 'post_tag_rewrite_rules', 'bogo_post_tag_rewrite_rules' ); |
| 152 |
|
| 153 |
function bogo_post_tag_rewrite_rules( $post_tag_rewrite ) { |
| 154 |
return bogo_taxonomy_rewrite_rules( $post_tag_rewrite, 'post_tag', EP_TAGS ); |
| 155 |
} |
| 156 |
|
| 157 |
add_filter( 'post_format_rewrite_rules', 'bogo_post_format_rewrite_rules' ); |
| 158 |
|
| 159 |
function bogo_post_format_rewrite_rules( $post_format_rewrite ) { |
| 160 |
return bogo_taxonomy_rewrite_rules( $post_format_rewrite, 'post_format' ); |
| 161 |
} |
| 162 |
|
| 163 |
function bogo_taxonomy_rewrite_rules( $taxonomy_rewrite, $taxonomy, $ep_mask = EP_NONE ) { |
| 164 |
global $wp_rewrite; |
| 165 |
|
| 166 |
$permastruct = $wp_rewrite->get_extra_permastruct( $taxonomy ); |
| 167 |
|
| 168 |
$permastruct = preg_replace( |
| 169 |
'#^' . $wp_rewrite->front . '#', |
| 170 |
'/%lang%' . $wp_rewrite->front, |
| 171 |
$permastruct ); |
| 172 |
|
| 173 |
$extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 174 |
'ep_mask' => $ep_mask ) ); |
| 175 |
|
| 176 |
return array_merge( $extra, $taxonomy_rewrite ); |
| 177 |
} |
| 178 |
|
| 179 |
add_filter( 'rewrite_rules_array', 'bogo_rewrite_rules_array' ); |
| 180 |
|
| 181 |
function bogo_rewrite_rules_array( $rules ) { |
| 182 |
global $wp_rewrite; |
| 183 |
|
| 184 |
$post_types = array_diff( |
| 185 |
(array) bogo_localizable_post_types(), |
| 186 |
get_post_types( array( '_builtin' => true ) ) ); |
| 187 |
|
| 188 |
if ( empty( $post_types ) ) |
| 189 |
return $rules; |
| 190 |
|
| 191 |
$lang_regex = bogo_get_lang_regex(); |
| 192 |
|
| 193 |
foreach ( $post_types as $post_type ) { |
| 194 |
if ( ! $post_type_obj = get_post_type_object( $post_type ) ) |
| 195 |
continue; |
| 196 |
|
| 197 |
if ( false === $post_type_obj->rewrite ) |
| 198 |
continue; |
| 199 |
|
| 200 |
$permastruct = $wp_rewrite->get_extra_permastruct( $post_type ); |
| 201 |
|
| 202 |
if ( $post_type_obj->rewrite['with_front'] ) { |
| 203 |
$permastruct = preg_replace( |
| 204 |
'#^' . $wp_rewrite->front . '#', |
| 205 |
'/%lang%' . $wp_rewrite->front, |
| 206 |
$permastruct ); |
| 207 |
} else { |
| 208 |
$permastruct = preg_replace( |
| 209 |
'#^' . $wp_rewrite->root . '#', |
| 210 |
'/%lang%/' . $wp_rewrite->root, |
| 211 |
$permastruct ); |
| 212 |
} |
| 213 |
|
| 214 |
$rules = array_merge( |
| 215 |
bogo_generate_rewrite_rules( $permastruct, $post_type_obj->rewrite ), |
| 216 |
$rules ); |
| 217 |
|
| 218 |
if ( $post_type_obj->has_archive ) { |
| 219 |
if ( $post_type_obj->has_archive === true ) |
| 220 |
$archive_slug = $post_type_obj->rewrite['slug']; |
| 221 |
else |
| 222 |
$archive_slug = $post_type_obj->has_archive; |
| 223 |
|
| 224 |
if ( $post_type_obj->rewrite['with_front'] ) |
| 225 |
$archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; |
| 226 |
else |
| 227 |
$archive_slug = $wp_rewrite->root . $archive_slug; |
| 228 |
|
| 229 |
$extra_rules = array( |
| 230 |
"{$lang_regex}/{$archive_slug}/?$" |
| 231 |
=> 'index.php?lang=$matches[1]&post_type=' . $post_type ); |
| 232 |
|
| 233 |
$rules = $extra_rules + $rules; |
| 234 |
|
| 235 |
if ( $post_type_obj->rewrite['feeds'] && $wp_rewrite->feeds ) { |
| 236 |
$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; |
| 237 |
|
| 238 |
$extra_rules = array( |
| 239 |
"{$lang_regex}/{$archive_slug}/feed/$feeds/?$" |
| 240 |
=> 'index.php?lang=$matches[1]&post_type=' . $post_type . '&feed=$matches[2]', |
| 241 |
"{$lang_regex}/{$archive_slug}/$feeds/?$" |
| 242 |
=> 'index.php?lang=$matches[1]&post_type=' . $post_type . '&feed=$matches[2]' ); |
| 243 |
|
| 244 |
$rules = $extra_rules + $rules; |
| 245 |
} |
| 246 |
|
| 247 |
if ( $post_type_obj->rewrite['pages'] ) { |
| 248 |
$extra_rules = array( |
| 249 |
"{$lang_regex}/{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$" => 'index.php?lang=$matches[1]&post_type=' . $post_type . '&paged=$matches[2]' ); |
| 250 |
|
| 251 |
$rules = $extra_rules + $rules; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
foreach ( get_object_taxonomies( $post_type ) as $tax ) { |
| 256 |
if ( ! $tax_obj = get_taxonomy( $tax ) ) |
| 257 |
continue; |
| 258 |
|
| 259 |
if ( false === $tax_obj->rewrite ) |
| 260 |
continue; |
| 261 |
|
| 262 |
$permastruct = $wp_rewrite->get_extra_permastruct( $tax ); |
| 263 |
|
| 264 |
if ( $tax_obj->rewrite['with_front'] ) { |
| 265 |
$permastruct = preg_replace( |
| 266 |
'#^' . $wp_rewrite->front . '#', |
| 267 |
'/%lang%' . $wp_rewrite->front, |
| 268 |
$permastruct ); |
| 269 |
} else { |
| 270 |
$permastruct = preg_replace( |
| 271 |
'#^' . $wp_rewrite->root . '#', |
| 272 |
'/%lang%/' . $wp_rewrite->root, |
| 273 |
$permastruct ); |
| 274 |
} |
| 275 |
|
| 276 |
$rules = array_merge( |
| 277 |
bogo_generate_rewrite_rules( $permastruct, $tax_obj->rewrite ), |
| 278 |
$rules ); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
return $rules; |
| 283 |
} |
| 284 |
|
| 285 |
function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { |
| 286 |
global $wp_rewrite; |
| 287 |
|
| 288 |
$defaults = array( |
| 289 |
'ep_mask' => EP_NONE, |
| 290 |
'paged' => true, |
| 291 |
'feed' => true, |
| 292 |
'forcomments' => false, |
| 293 |
'walk_dirs' => true, |
| 294 |
'endpoints' => true ); |
| 295 |
|
| 296 |
$args = wp_parse_args( $args, $defaults ); |
| 297 |
|
| 298 |
extract( $args, EXTR_SKIP ); |
| 299 |
|
| 300 |
$feedregex2 = '(' . implode( '|', $wp_rewrite->feeds ) . ')/?$'; |
| 301 |
$feedregex = $wp_rewrite->feed_base . '/' . $feedregex2; |
| 302 |
$trackbackregex = 'trackback/?$'; |
| 303 |
$pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'; |
| 304 |
$commentregex = 'comment-page-([0-9]{1,})/?$'; |
| 305 |
|
| 306 |
if ( $endpoints ) { |
| 307 |
$ep_query_append = array(); |
| 308 |
|
| 309 |
foreach ( (array) $wp_rewrite->endpoints as $endpoint ) { |
| 310 |
$epmatch = $endpoint[1] . '(/(.*))?/?$'; |
| 311 |
$epquery = '&' . $endpoint[1] . '='; |
| 312 |
$ep_query_append[$epmatch] = array( $endpoint[0], $epquery ); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
$front = substr( $permalink_structure, 0, strpos( $permalink_structure, '%' ) ); |
| 317 |
preg_match_all( '/%.+?%/', $permalink_structure, $tokens ); |
| 318 |
$num_tokens = count( $tokens[0] ); |
| 319 |
$index = $wp_rewrite->index; |
| 320 |
$feedindex = $index; |
| 321 |
$trackbackindex = $index; |
| 322 |
|
| 323 |
for ( $i = 0; $i < $num_tokens; ++$i ) { |
| 324 |
if ( 0 < $i ) |
| 325 |
$queries[$i] = $queries[$i - 1] . '&'; |
| 326 |
else |
| 327 |
$queries[$i] = ''; |
| 328 |
|
| 329 |
$query_token = |
| 330 |
str_replace( $wp_rewrite->rewritecode, $wp_rewrite->queryreplace, $tokens[0][$i] ) |
| 331 |
. $wp_rewrite->preg_index( $i + 1 ); |
| 332 |
|
| 333 |
$queries[$i] .= $query_token; |
| 334 |
} |
| 335 |
|
| 336 |
$structure = $permalink_structure; |
| 337 |
|
| 338 |
if ( $front != '/' ) |
| 339 |
$structure = str_replace( $front, '', $structure ); |
| 340 |
|
| 341 |
$structure = trim( $structure, '/' ); |
| 342 |
|
| 343 |
$dirs = $walk_dirs ? explode( '/', $structure ) : array( $structure ); |
| 344 |
$num_dirs = count( $dirs ); |
| 345 |
|
| 346 |
$front = preg_replace( '|^/+|', '', $front ); |
| 347 |
|
| 348 |
$post_rewrite = array(); |
| 349 |
$struct = $front; |
| 350 |
|
| 351 |
for ( $j = 0; $j < $num_dirs; ++$j ) { |
| 352 |
$struct .= $dirs[$j] . '/'; |
| 353 |
$struct = ltrim( $struct, '/' ); |
| 354 |
$match = str_replace( $wp_rewrite->rewritecode, $wp_rewrite->rewritereplace, $struct); |
| 355 |
$num_toks = preg_match_all( '/%.+?%/', $struct, $toks ); |
| 356 |
|
| 357 |
$query = ( isset( $queries ) && is_array( $queries ) && ! empty( $num_toks ) ) |
| 358 |
? $queries[$num_toks - 1] : ''; |
| 359 |
|
| 360 |
switch ( $dirs[$j] ) { |
| 361 |
case '%year%': |
| 362 |
$ep_mask_specific = EP_YEAR; |
| 363 |
break; |
| 364 |
case '%monthnum%': |
| 365 |
$ep_mask_specific = EP_MONTH; |
| 366 |
break; |
| 367 |
case '%day%': |
| 368 |
$ep_mask_specific = EP_DAY; |
| 369 |
break; |
| 370 |
default: |
| 371 |
$ep_mask_specific = EP_NONE; |
| 372 |
} |
| 373 |
|
| 374 |
$pagematch = $match . $pageregex; |
| 375 |
$pagequery = $index . '?' . $query |
| 376 |
. '&paged=' . $wp_rewrite->preg_index( $num_toks + 1 ); |
| 377 |
|
| 378 |
$commentmatch = $match . $commentregex; |
| 379 |
$commentquery = $index . '?' . $query |
| 380 |
. '&cpage=' . $wp_rewrite->preg_index( $num_toks + 1 ); |
| 381 |
|
| 382 |
if ( get_option( 'page_on_front' ) ) { |
| 383 |
$rootcommentmatch = $match . $commentregex; |
| 384 |
$rootcommentquery = $index . '?' . $query |
| 385 |
. '&page_id=' . get_option( 'page_on_front' ) |
| 386 |
. '&cpage=' . $wp_rewrite->preg_index( $num_toks + 1 ); |
| 387 |
} |
| 388 |
|
| 389 |
$feedmatch = $match . $feedregex; |
| 390 |
$feedquery = $feedindex . '?' . $query |
| 391 |
. '&feed=' . $wp_rewrite->preg_index( $num_toks + 1 ); |
| 392 |
|
| 393 |
$feedmatch2 = $match . $feedregex2; |
| 394 |
$feedquery2 = $feedindex . '?' . $query |
| 395 |
. '&feed=' . $wp_rewrite->preg_index( $num_toks + 1 ); |
| 396 |
|
| 397 |
if ( $forcomments ) { |
| 398 |
$feedquery .= '&withcomments=1'; |
| 399 |
$feedquery2 .= '&withcomments=1'; |
| 400 |
} |
| 401 |
|
| 402 |
$rewrite = array(); |
| 403 |
|
| 404 |
if ( $feed ) |
| 405 |
$rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 ); |
| 406 |
|
| 407 |
if ( $paged ) |
| 408 |
$rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) ); |
| 409 |
|
| 410 |
if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) |
| 411 |
$rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) ); |
| 412 |
else if ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) |
| 413 |
$rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) ); |
| 414 |
|
| 415 |
if ( $endpoints ) { |
| 416 |
foreach ( (array) $ep_query_append as $regex => $ep ) { |
| 417 |
if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) |
| 418 |
$rewrite[$match . $regex] = $index . '?' . $query |
| 419 |
. $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 ); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
if ( $num_toks ) { |
| 424 |
$post = false; |
| 425 |
$page = false; |
| 426 |
|
| 427 |
if ( strpos( $struct, '%postname%' ) !== false |
| 428 |
|| strpos( $struct, '%post_id%' ) !== false |
| 429 |
|| strpos( $struct, '%pagename%' ) !== false |
| 430 |
|| ( strpos( $struct, '%year%' ) !== false |
| 431 |
&& strpos( $struct, '%monthnum%' ) !== false |
| 432 |
&& strpos( $struct, '%day%' ) !== false |
| 433 |
&& strpos( $struct, '%hour%' ) !== false |
| 434 |
&& strpos( $struct, '%minute%' ) !== false |
| 435 |
&& strpos( $struct, '%second%' ) !== false ) ) { |
| 436 |
$post = true; |
| 437 |
|
| 438 |
if ( strpos( $struct, '%pagename%' ) !== false ) |
| 439 |
$page = true; |
| 440 |
} |
| 441 |
|
| 442 |
if ( ! $post ) { |
| 443 |
foreach ( get_post_types( array( '_builtin' => false ) ) as $ptype ) { |
| 444 |
if ( strpos( $struct, "%$ptype%" ) !== false ) { |
| 445 |
$post = true; |
| 446 |
$page = is_post_type_hierarchical( $ptype ); |
| 447 |
break; |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
if ( $post ) { |
| 453 |
$trackbackmatch = $match . $trackbackregex; |
| 454 |
$trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; |
| 455 |
$match = rtrim( $match, '/' ); |
| 456 |
$submatchbase = preg_replace( '/\(([^?].+?)\)/', '(?:$1)', $match ); |
| 457 |
|
| 458 |
$sub1 = $submatchbase . '/([^/]+)/'; |
| 459 |
$sub1tb = $sub1 . $trackbackregex; |
| 460 |
$sub1feed = $sub1 . $feedregex; |
| 461 |
$sub1feed2 = $sub1 . $feedregex2; |
| 462 |
$sub1comment = $sub1 . $commentregex; |
| 463 |
|
| 464 |
$sub2 = $submatchbase . '/attachment/([^/]+)/'; |
| 465 |
$sub2tb = $sub2 . $trackbackregex; |
| 466 |
$sub2feed = $sub2 . $feedregex; |
| 467 |
$sub2feed2 = $sub2 . $feedregex2; |
| 468 |
$sub2comment = $sub2 . $commentregex; |
| 469 |
|
| 470 |
$subquery = $index . '?attachment=' . $wp_rewrite->preg_index( 1 ); |
| 471 |
$subtbquery = $subquery . '&tb=1'; |
| 472 |
$subfeedquery = $subquery . '&feed=' . $wp_rewrite->preg_index( 2 ); |
| 473 |
$subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index( 2 ); |
| 474 |
|
| 475 |
if ( ! empty( $endpoints ) ) { |
| 476 |
foreach ( (array) $ep_query_append as $regex => $ep ) { |
| 477 |
if ( $ep[0] & EP_ATTACHMENT ) { |
| 478 |
$rewrite[$sub1 . $regex] = |
| 479 |
$subquery . $ep[1] . $wp_rewrite->preg_index( 2 ); |
| 480 |
$rewrite[$sub2 . $regex] = |
| 481 |
$subquery . $ep[1] . $wp_rewrite->preg_index( 2 ); |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
$sub1 .= '?$'; |
| 487 |
$sub2 .= '?$'; |
| 488 |
|
| 489 |
$match = $match . '(/[0-9]+)?/?$'; |
| 490 |
$query = $index . '?' . $query |
| 491 |
. '&page=' . $wp_rewrite->preg_index( $num_toks + 1 ); |
| 492 |
} else { |
| 493 |
$match .= '?$'; |
| 494 |
$query = $index . '?' . $query; |
| 495 |
} |
| 496 |
|
| 497 |
$rewrite = array_merge( $rewrite, array( $match => $query ) ); |
| 498 |
|
| 499 |
if ( $post ) { |
| 500 |
$rewrite = array_merge( array( $trackbackmatch => $trackbackquery ), $rewrite ); |
| 501 |
|
| 502 |
if ( ! $page ) { |
| 503 |
$rewrite = array_merge( $rewrite, array( |
| 504 |
$sub1 => $subquery, |
| 505 |
$sub1tb => $subtbquery, |
| 506 |
$sub1feed => $subfeedquery, |
| 507 |
$sub1feed2 => $subfeedquery, |
| 508 |
$sub1comment => $subcommentquery ) ); |
| 509 |
} |
| 510 |
|
| 511 |
$rewrite = array_merge( array( |
| 512 |
$sub2 => $subquery, |
| 513 |
$sub2tb => $subtbquery, |
| 514 |
$sub2feed => $subfeedquery, |
| 515 |
$sub2feed2 => $subfeedquery, |
| 516 |
$sub2comment => $subcommentquery ), $rewrite ); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
$post_rewrite = array_merge( $rewrite, $post_rewrite ); |
| 521 |
} |
| 522 |
|
| 523 |
return $post_rewrite; |
| 524 |
} |
| 525 |
|
| 526 |
?> |