| @@ -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' ); |
| @@ -180,17 +181,31 @@ | ||
| 180 | 181 | |
| 181 | 182 | function bogo_rewrite_rules_array( $rules ) { |
| 182 | 183 | global $wp_rewrite; |
| 183 | 184 | |
| 185 | + $lang_regex = bogo_get_lang_regex(); | |
| 186 | + | |
| 187 | + // REST rewrite rules | |
| 188 | + if ( function_exists( 'rest_get_url_prefix' ) ) { | |
| 189 | + $rest_url_prefix = rest_get_url_prefix(); | |
| 190 | + | |
| 191 | + $extra_rules = array( | |
| 192 | + "^{$lang_regex}/{$rest_url_prefix}/?$" | |
| 193 | + => 'index.php?lang=$matches[1]&rest_route=/', | |
| 194 | + "^{$lang_regex}/{$rest_url_prefix}/(.*)?" | |
| 195 | + => 'index.php?lang=$matches[1]&rest_route=/$matches[2]' ); | |
| 196 | + | |
| 197 | + $rules = $extra_rules + $rules; | |
| 198 | + } | |
| 199 | + | |
| 184 | 200 | $post_types = array_diff( |
| 185 | 201 | (array) bogo_localizable_post_types(), |
| 186 | 202 | get_post_types( array( '_builtin' => true ) ) ); |
| 187 | 203 | |
| 188 | - if ( empty( $post_types ) ) | |
| 204 | + if ( empty( $post_types ) ) { | |
| 189 | 205 | return $rules; |
| 206 | + } | |
| 190 | 207 | |
| 191 | - $lang_regex = bogo_get_lang_regex(); | |
| 192 | - | |
| 193 | 208 | foreach ( $post_types as $post_type ) { |
| 194 | 209 | if ( ! $post_type_obj = get_post_type_object( $post_type ) ) |
| 195 | 210 | continue; |
| 196 | 211 | |
| @@ -301,8 +316,9 @@ | ||
| 301 | 316 | $feedregex = $wp_rewrite->feed_base . '/' . $feedregex2; |
| 302 | 317 | $trackbackregex = 'trackback/?$'; |
| 303 | 318 | $pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'; |
| 304 | 319 | $commentregex = 'comment-page-([0-9]{1,})/?$'; |
| 320 | + $embedregex = 'embed/?$'; | |
| 305 | 321 | |
| 306 | 322 | if ( $endpoints ) { |
| 307 | 323 | $ep_query_append = array(); |
| 308 | 324 | |
| @@ -318,14 +334,16 @@ | ||
| 318 | 334 | $num_tokens = count( $tokens[0] ); |
| 319 | 335 | $index = $wp_rewrite->index; |
| 320 | 336 | $feedindex = $index; |
| 321 | 337 | $trackbackindex = $index; |
| 338 | + $embedindex = $index; | |
| 322 | 339 | |
| 323 | 340 | for ( $i = 0; $i < $num_tokens; ++$i ) { |
| 324 | - if ( 0 < $i ) | |
| 341 | + if ( 0 < $i ) { | |
| 325 | 342 | $queries[$i] = $queries[$i - 1] . '&'; |
| 326 | - else | |
| 343 | + } else { | |
| 327 | 344 | $queries[$i] = ''; |
| 345 | + } | |
| 328 | 346 | |
| 329 | 347 | $query_token = |
| 330 | 348 | str_replace( $wp_rewrite->rewritecode, $wp_rewrite->queryreplace, $tokens[0][$i] ) |
| 331 | 349 | . $wp_rewrite->preg_index( $i + 1 ); |
| @@ -334,10 +352,11 @@ | ||
| 334 | 352 | } |
| 335 | 353 | |
| 336 | 354 | $structure = $permalink_structure; |
| 337 | 355 | |
| 338 | - if ( $front != '/' ) | |
| 356 | + if ( $front != '/' ) { | |
| 339 | 357 | $structure = str_replace( $front, '', $structure ); |
| 358 | + } | |
| 340 | 359 | |
| 341 | 360 | $structure = trim( $structure, '/' ); |
| 342 | 361 | |
| 343 | 362 | $dirs = $walk_dirs ? explode( '/', $structure ) : array( $structure ); |
| @@ -400,24 +419,28 @@ | ||
| 400 | 419 | } |
| 401 | 420 | |
| 402 | 421 | $rewrite = array(); |
| 403 | 422 | |
| 404 | - if ( $feed ) | |
| 423 | + if ( $feed ) { | |
| 405 | 424 | $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 ); |
| 425 | + } | |
| 406 | 426 | |
| 407 | - if ( $paged ) | |
| 427 | + if ( $paged ) { | |
| 408 | 428 | $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) ); |
| 429 | + } | |
| 409 | 430 | |
| 410 | - if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) | |
| 431 | + if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) { | |
| 411 | 432 | $rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) ); |
| 412 | - else if ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) | |
| 433 | + } elseif ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) { | |
| 413 | 434 | $rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) ); |
| 435 | + } | |
| 414 | 436 | |
| 415 | 437 | if ( $endpoints ) { |
| 416 | 438 | foreach ( (array) $ep_query_append as $regex => $ep ) { |
| 417 | - if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) | |
| 439 | + if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) { | |
| 418 | 440 | $rewrite[$match . $regex] = $index . '?' . $query |
| 419 | 441 | . $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 ); |
| 442 | + } | |
| 420 | 443 | } |
| 421 | 444 | } |
| 422 | 445 | |
| 423 | 446 | if ( $num_toks ) { |
| @@ -434,10 +457,11 @@ | ||
| 434 | 457 | && strpos( $struct, '%minute%' ) !== false |
| 435 | 458 | && strpos( $struct, '%second%' ) !== false ) ) { |
| 436 | 459 | $post = true; |
| 437 | 460 | |
| 438 | - if ( strpos( $struct, '%pagename%' ) !== false ) | |
| 461 | + if ( strpos( $struct, '%pagename%' ) !== false ) { | |
| 439 | 462 | $page = true; |
| 463 | + } | |
| 440 | 464 | } |
| 441 | 465 | |
| 442 | 466 | if ( ! $post ) { |
| 443 | 467 | foreach ( get_post_types( array( '_builtin' => false ) ) as $ptype ) { |
| @@ -451,8 +475,12 @@ | ||
| 451 | 475 | |
| 452 | 476 | if ( $post ) { |
| 453 | 477 | $trackbackmatch = $match . $trackbackregex; |
| 454 | 478 | $trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; |
| 479 | + | |
| 480 | + $embedmatch = $match . $embedregex; | |
| 481 | + $embedquery = $embedindex . '?' . $query . '&embed=true'; | |
| 482 | + | |
| 455 | 483 | $match = rtrim( $match, '/' ); |
| 456 | 484 | $submatchbase = preg_replace( '/\(([^?].+?)\)/', '(?:$1)', $match ); |
| 457 | 485 | |
| 458 | 486 | $sub1 = $submatchbase . '/([^/]+)/'; |
| @@ -459,8 +487,9 @@ | ||
| 459 | 487 | $sub1tb = $sub1 . $trackbackregex; |
| 460 | 488 | $sub1feed = $sub1 . $feedregex; |
| 461 | 489 | $sub1feed2 = $sub1 . $feedregex2; |
| 462 | 490 | $sub1comment = $sub1 . $commentregex; |
| 491 | + $sub1embed = $sub1 . $embedregex; | |
| 463 | 492 | |
| 464 | 493 | $sub2 = $submatchbase . '/attachment/([^/]+)/'; |
| 465 | 494 | $sub2tb = $sub2 . $trackbackregex; |
| 466 | 495 | $sub2feed = $sub2 . $feedregex; |
| @@ -465,13 +494,15 @@ | ||
| 465 | 494 | $sub2tb = $sub2 . $trackbackregex; |
| 466 | 495 | $sub2feed = $sub2 . $feedregex; |
| 467 | 496 | $sub2feed2 = $sub2 . $feedregex2; |
| 468 | 497 | $sub2comment = $sub2 . $commentregex; |
| 498 | + $sub2embed = $sub2 . $embedregex; | |
| 469 | 499 | |
| 470 | 500 | $subquery = $index . '?attachment=' . $wp_rewrite->preg_index( 1 ); |
| 471 | 501 | $subtbquery = $subquery . '&tb=1'; |
| 472 | 502 | $subfeedquery = $subquery . '&feed=' . $wp_rewrite->preg_index( 2 ); |
| 473 | 503 | $subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index( 2 ); |
| 504 | + $subembedquery = $subquery . '&embed=true'; | |
| 474 | 505 | |
| 475 | 506 | if ( ! empty( $endpoints ) ) { |
| 476 | 507 | foreach ( (array) $ep_query_append as $regex => $ep ) { |
| 477 | 508 | if ( $ep[0] & EP_ATTACHMENT ) { |
| @@ -498,8 +529,10 @@ | ||
| 498 | 529 | |
| 499 | 530 | if ( $post ) { |
| 500 | 531 | $rewrite = array_merge( array( $trackbackmatch => $trackbackquery ), $rewrite ); |
| 501 | 532 | |
| 533 | + $rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite ); | |
| 534 | + | |
| 502 | 535 | if ( ! $page ) { |
| 503 | 536 | $rewrite = array_merge( $rewrite, array( |
| 504 | 537 | $sub1 => $subquery, |
| 505 | 538 | $sub1tb => $subtbquery, |
| @@ -504,9 +537,10 @@ | ||
| 504 | 537 | $sub1 => $subquery, |
| 505 | 538 | $sub1tb => $subtbquery, |
| 506 | 539 | $sub1feed => $subfeedquery, |
| 507 | 540 | $sub1feed2 => $subfeedquery, |
| 508 | - $sub1comment => $subcommentquery ) ); | |
| 541 | + $sub1comment => $subcommentquery, | |
| 542 | + $sub1embed => $subembedquery ) ); | |
| 509 | 543 | } |
| 510 | 544 | |
| 511 | 545 | $rewrite = array_merge( array( |
| 512 | 546 | $sub2 => $subquery, |
| @@ -512,9 +546,10 @@ | ||
| 512 | 546 | $sub2 => $subquery, |
| 513 | 547 | $sub2tb => $subtbquery, |
| 514 | 548 | $sub2feed => $subfeedquery, |
| 515 | 549 | $sub2feed2 => $subfeedquery, |
| 516 | - $sub2comment => $subcommentquery ), $rewrite ); | |
| 550 | + $sub2comment => $subcommentquery, | |
| 551 | + $sub2embed => $subembedquery ), $rewrite ); | |
| 517 | 552 | } |
| 518 | 553 | } |
| 519 | 554 | |
| 520 | 555 | $post_rewrite = array_merge( $rewrite, $post_rewrite ); |
| @@ -521,6 +556,4 @@ | ||
| 521 | 556 | } |
| 522 | 557 | |
| 523 | 558 | return $post_rewrite; |
| 524 | 559 | } |
| 525 | - | |
| 526 | -?> | |