| @@ -4,10 +4,11 @@ | ||
| 4 | 4 | |
| 5 | 5 | function bogo_add_rewrite_tags() { |
| 6 | 6 | $regex = bogo_get_lang_regex(); |
| 7 | 7 | |
| 8 | - if ( empty( $regex ) ) | |
| 8 | + if ( empty( $regex ) ) { | |
| 9 | 9 | return; |
| 10 | + } | |
| 10 | 11 | |
| 11 | 12 | add_rewrite_tag( '%lang%', $regex, 'lang=' ); |
| 12 | 13 | |
| 13 | 14 | $old_regex = bogo_get_prop( 'lang_rewrite_regex' ); |
| @@ -37,15 +38,25 @@ | ||
| 37 | 38 | global $wp_rewrite; |
| 38 | 39 | |
| 39 | 40 | $permastruct = $wp_rewrite->permalink_structure; |
| 40 | 41 | |
| 41 | - if ( ! apache_mod_loaded( 'mod_rewrite', true ) && ! iis7_supports_permalinks() ) | |
| 42 | - $permastruct = preg_replace( '#^/index\.php#', '/index.php/%lang%', $permastruct ); | |
| 43 | - elseif ( is_multisite() && ! is_subdomain_install() && is_main_site() ) | |
| 44 | - $permastruct = preg_replace( '#^/blog#', '/%lang%/blog', $permastruct ); | |
| 45 | - else | |
| 46 | - $permastruct = preg_replace( '#^/#', '/%lang%/', $permastruct ); | |
| 42 | + // from wp-admin/includes/misc.php | |
| 43 | + $got_rewrite = apply_filters( 'got_rewrite', | |
| 44 | + apache_mod_loaded( 'mod_rewrite', true ) ); | |
| 45 | + $got_url_rewrite = apply_filters( 'got_url_rewrite', | |
| 46 | + $got_rewrite || $GLOBALS['is_nginx'] || iis7_supports_permalinks() ); | |
| 47 | 47 | |
| 48 | + if ( ! $got_url_rewrite ) { | |
| 49 | + $permastruct = preg_replace( | |
| 50 | + '#^/index\.php#', '/index.php/%lang%', $permastruct ); | |
| 51 | + } elseif ( is_multisite() && ! is_subdomain_install() && is_main_site() ) { | |
| 52 | + $permastruct = preg_replace( | |
| 53 | + '#^/blog#', '/%lang%/blog', $permastruct ); | |
| 54 | + } else { | |
| 55 | + $permastruct = preg_replace( | |
| 56 | + '#^/#', '/%lang%/', $permastruct ); | |
| 57 | + } | |
| 58 | + | |
| 48 | 59 | $extra = bogo_generate_rewrite_rules( $permastruct, array( |
| 49 | 60 | 'ep_mask' => EP_PERMALINK, |
| 50 | 61 | 'paged' => false ) ); |
| 51 | 62 | |
| @@ -170,17 +181,29 @@ | ||
| 170 | 181 | |
| 171 | 182 | function bogo_rewrite_rules_array( $rules ) { |
| 172 | 183 | global $wp_rewrite; |
| 173 | 184 | |
| 185 | + $lang_regex = bogo_get_lang_regex(); | |
| 186 | + | |
| 187 | + // REST rewrite rules | |
| 188 | + $rest_url_prefix = rest_get_url_prefix(); | |
| 189 | + | |
| 190 | + $extra_rules = array( | |
| 191 | + "^{$lang_regex}/{$rest_url_prefix}/?$" | |
| 192 | + => 'index.php?lang=$matches[1]&rest_route=/', | |
| 193 | + "^{$lang_regex}/{$rest_url_prefix}/(.*)?" | |
| 194 | + => 'index.php?lang=$matches[1]&rest_route=/$matches[2]' ); | |
| 195 | + | |
| 196 | + $rules = $extra_rules + $rules; | |
| 197 | + | |
| 174 | 198 | $post_types = array_diff( |
| 175 | 199 | (array) bogo_localizable_post_types(), |
| 176 | 200 | get_post_types( array( '_builtin' => true ) ) ); |
| 177 | 201 | |
| 178 | - if ( empty( $post_types ) ) | |
| 202 | + if ( empty( $post_types ) ) { | |
| 179 | 203 | return $rules; |
| 204 | + } | |
| 180 | 205 | |
| 181 | - $lang_regex = bogo_get_lang_regex(); | |
| 182 | - | |
| 183 | 206 | foreach ( $post_types as $post_type ) { |
| 184 | 207 | if ( ! $post_type_obj = get_post_type_object( $post_type ) ) |
| 185 | 208 | continue; |
| 186 | 209 | |
| @@ -291,8 +314,9 @@ | ||
| 291 | 314 | $feedregex = $wp_rewrite->feed_base . '/' . $feedregex2; |
| 292 | 315 | $trackbackregex = 'trackback/?$'; |
| 293 | 316 | $pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'; |
| 294 | 317 | $commentregex = 'comment-page-([0-9]{1,})/?$'; |
| 318 | + $embedregex = 'embed/?$'; | |
| 295 | 319 | |
| 296 | 320 | if ( $endpoints ) { |
| 297 | 321 | $ep_query_append = array(); |
| 298 | 322 | |
| @@ -308,14 +332,16 @@ | ||
| 308 | 332 | $num_tokens = count( $tokens[0] ); |
| 309 | 333 | $index = $wp_rewrite->index; |
| 310 | 334 | $feedindex = $index; |
| 311 | 335 | $trackbackindex = $index; |
| 336 | + $embedindex = $index; | |
| 312 | 337 | |
| 313 | 338 | for ( $i = 0; $i < $num_tokens; ++$i ) { |
| 314 | - if ( 0 < $i ) | |
| 339 | + if ( 0 < $i ) { | |
| 315 | 340 | $queries[$i] = $queries[$i - 1] . '&'; |
| 316 | - else | |
| 341 | + } else { | |
| 317 | 342 | $queries[$i] = ''; |
| 343 | + } | |
| 318 | 344 | |
| 319 | 345 | $query_token = |
| 320 | 346 | str_replace( $wp_rewrite->rewritecode, $wp_rewrite->queryreplace, $tokens[0][$i] ) |
| 321 | 347 | . $wp_rewrite->preg_index( $i + 1 ); |
| @@ -324,10 +350,11 @@ | ||
| 324 | 350 | } |
| 325 | 351 | |
| 326 | 352 | $structure = $permalink_structure; |
| 327 | 353 | |
| 328 | - if ( $front != '/' ) | |
| 354 | + if ( $front != '/' ) { | |
| 329 | 355 | $structure = str_replace( $front, '', $structure ); |
| 356 | + } | |
| 330 | 357 | |
| 331 | 358 | $structure = trim( $structure, '/' ); |
| 332 | 359 | |
| 333 | 360 | $dirs = $walk_dirs ? explode( '/', $structure ) : array( $structure ); |
| @@ -390,24 +417,28 @@ | ||
| 390 | 417 | } |
| 391 | 418 | |
| 392 | 419 | $rewrite = array(); |
| 393 | 420 | |
| 394 | - if ( $feed ) | |
| 421 | + if ( $feed ) { | |
| 395 | 422 | $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 ); |
| 423 | + } | |
| 396 | 424 | |
| 397 | - if ( $paged ) | |
| 425 | + if ( $paged ) { | |
| 398 | 426 | $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) ); |
| 427 | + } | |
| 399 | 428 | |
| 400 | - if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) | |
| 429 | + if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) { | |
| 401 | 430 | $rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) ); |
| 402 | - else if ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) | |
| 431 | + } elseif ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) { | |
| 403 | 432 | $rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) ); |
| 433 | + } | |
| 404 | 434 | |
| 405 | 435 | if ( $endpoints ) { |
| 406 | 436 | foreach ( (array) $ep_query_append as $regex => $ep ) { |
| 407 | - if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) | |
| 437 | + if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) { | |
| 408 | 438 | $rewrite[$match . $regex] = $index . '?' . $query |
| 409 | 439 | . $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 ); |
| 440 | + } | |
| 410 | 441 | } |
| 411 | 442 | } |
| 412 | 443 | |
| 413 | 444 | if ( $num_toks ) { |
| @@ -424,10 +455,11 @@ | ||
| 424 | 455 | && strpos( $struct, '%minute%' ) !== false |
| 425 | 456 | && strpos( $struct, '%second%' ) !== false ) ) { |
| 426 | 457 | $post = true; |
| 427 | 458 | |
| 428 | - if ( strpos( $struct, '%pagename%' ) !== false ) | |
| 459 | + if ( strpos( $struct, '%pagename%' ) !== false ) { | |
| 429 | 460 | $page = true; |
| 461 | + } | |
| 430 | 462 | } |
| 431 | 463 | |
| 432 | 464 | if ( ! $post ) { |
| 433 | 465 | foreach ( get_post_types( array( '_builtin' => false ) ) as $ptype ) { |
| @@ -441,8 +473,12 @@ | ||
| 441 | 473 | |
| 442 | 474 | if ( $post ) { |
| 443 | 475 | $trackbackmatch = $match . $trackbackregex; |
| 444 | 476 | $trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; |
| 477 | + | |
| 478 | + $embedmatch = $match . $embedregex; | |
| 479 | + $embedquery = $embedindex . '?' . $query . '&embed=true'; | |
| 480 | + | |
| 445 | 481 | $match = rtrim( $match, '/' ); |
| 446 | 482 | $submatchbase = preg_replace( '/\(([^?].+?)\)/', '(?:$1)', $match ); |
| 447 | 483 | |
| 448 | 484 | $sub1 = $submatchbase . '/([^/]+)/'; |
| @@ -449,8 +485,9 @@ | ||
| 449 | 485 | $sub1tb = $sub1 . $trackbackregex; |
| 450 | 486 | $sub1feed = $sub1 . $feedregex; |
| 451 | 487 | $sub1feed2 = $sub1 . $feedregex2; |
| 452 | 488 | $sub1comment = $sub1 . $commentregex; |
| 489 | + $sub1embed = $sub1 . $embedregex; | |
| 453 | 490 | |
| 454 | 491 | $sub2 = $submatchbase . '/attachment/([^/]+)/'; |
| 455 | 492 | $sub2tb = $sub2 . $trackbackregex; |
| 456 | 493 | $sub2feed = $sub2 . $feedregex; |
| @@ -455,13 +492,15 @@ | ||
| 455 | 492 | $sub2tb = $sub2 . $trackbackregex; |
| 456 | 493 | $sub2feed = $sub2 . $feedregex; |
| 457 | 494 | $sub2feed2 = $sub2 . $feedregex2; |
| 458 | 495 | $sub2comment = $sub2 . $commentregex; |
| 496 | + $sub2embed = $sub2 . $embedregex; | |
| 459 | 497 | |
| 460 | 498 | $subquery = $index . '?attachment=' . $wp_rewrite->preg_index( 1 ); |
| 461 | 499 | $subtbquery = $subquery . '&tb=1'; |
| 462 | 500 | $subfeedquery = $subquery . '&feed=' . $wp_rewrite->preg_index( 2 ); |
| 463 | 501 | $subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index( 2 ); |
| 502 | + $subembedquery = $subquery . '&embed=true'; | |
| 464 | 503 | |
| 465 | 504 | if ( ! empty( $endpoints ) ) { |
| 466 | 505 | foreach ( (array) $ep_query_append as $regex => $ep ) { |
| 467 | 506 | if ( $ep[0] & EP_ATTACHMENT ) { |
| @@ -488,8 +527,10 @@ | ||
| 488 | 527 | |
| 489 | 528 | if ( $post ) { |
| 490 | 529 | $rewrite = array_merge( array( $trackbackmatch => $trackbackquery ), $rewrite ); |
| 491 | 530 | |
| 531 | + $rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite ); | |
| 532 | + | |
| 492 | 533 | if ( ! $page ) { |
| 493 | 534 | $rewrite = array_merge( $rewrite, array( |
| 494 | 535 | $sub1 => $subquery, |
| 495 | 536 | $sub1tb => $subtbquery, |
| @@ -494,9 +535,10 @@ | ||
| 494 | 535 | $sub1 => $subquery, |
| 495 | 536 | $sub1tb => $subtbquery, |
| 496 | 537 | $sub1feed => $subfeedquery, |
| 497 | 538 | $sub1feed2 => $subfeedquery, |
| 498 | - $sub1comment => $subcommentquery ) ); | |
| 539 | + $sub1comment => $subcommentquery, | |
| 540 | + $sub1embed => $subembedquery ) ); | |
| 499 | 541 | } |
| 500 | 542 | |
| 501 | 543 | $rewrite = array_merge( array( |
| 502 | 544 | $sub2 => $subquery, |
| @@ -502,9 +544,10 @@ | ||
| 502 | 544 | $sub2 => $subquery, |
| 503 | 545 | $sub2tb => $subtbquery, |
| 504 | 546 | $sub2feed => $subfeedquery, |
| 505 | 547 | $sub2feed2 => $subfeedquery, |
| 506 | - $sub2comment => $subcommentquery ), $rewrite ); | |
| 548 | + $sub2comment => $subcommentquery, | |
| 549 | + $sub2embed => $subembedquery ), $rewrite ); | |
| 507 | 550 | } |
| 508 | 551 | } |
| 509 | 552 | |
| 510 | 553 | $post_rewrite = array_merge( $rewrite, $post_rewrite ); |
| @@ -511,6 +554,4 @@ | ||
| 511 | 554 | } |
| 512 | 555 | |
| 513 | 556 | return $post_rewrite; |
| 514 | 557 | } |
| 515 | - | |
| 516 | -?> | |