| 73 | | $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); |
|---|
| 74 | | $paged_redirect['path'] = trailingslashit($paged_redirect['path']); |
|---|
| 75 | | if ( $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) |
|---|
| 76 | | $paged_redirect['path'] .= 'index.php/'; |
|---|
| 77 | | $paged_redirect['path'] .= user_trailingslashit("page/$paged"); |
|---|
| | 73 | $paged_redirect['path'] = preg_replace('|/page/[0-9]+?/?$|', '/', $paged_redirect['path']); // strip off any existing paging |
|---|
| | 74 | $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ |
|---|
| | 75 | if ( $paged > 1 && !is_singular() ) { |
|---|
| | 76 | $paged_redirect['path'] = trailingslashit($paged_redirect['path']); |
|---|
| | 77 | if ( $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) |
|---|
| | 78 | $paged_redirect['path'] .= 'index.php/'; |
|---|
| | 79 | $paged_redirect['path'] .= user_trailingslashit("page/$paged", 'paged'); |
|---|
| | 80 | } elseif ( !is_home() && !is_singular() ){ |
|---|
| | 81 | $paged_redirect['path'] = user_trailingslashit($paged_redirect['path'], 'paged'); |
|---|
| | 82 | } |
|---|
| 84 | | // tack on any additional query vars |
|---|
| 85 | | if ( $redirect_url && $redirect['query'] ) { |
|---|
| 86 | | if ( strpos($redirect_url, '?') !== false ) |
|---|
| 87 | | $redirect_url .= '&'; |
|---|
| 88 | | else |
|---|
| 89 | | $redirect_url .= '?'; |
|---|
| 90 | | $redirect_url .= $redirect['query']; |
|---|
| | 90 | // tack on any additional query vars |
|---|
| | 91 | if ( $redirect_url && $redirect['query'] ) { |
|---|
| | 92 | if ( strpos($redirect_url, '?') !== false ) |
|---|
| | 93 | $redirect_url .= '&'; |
|---|
| | 94 | else |
|---|
| | 95 | $redirect_url .= '?'; |
|---|
| | 96 | $redirect_url .= $redirect['query']; |
|---|
| | 97 | } |
|---|
| | 98 | |
|---|
| | 99 | if ( $redirect_url ) |
|---|
| | 100 | $redirect = @parse_url($redirect_url); |
|---|
| | 101 | |
|---|
| | 102 | // www.example.com vs example.com |
|---|
| | 103 | $user_home = @parse_url(get_option('home')); |
|---|
| | 104 | $redirect['host'] = $user_home['host']; |
|---|
| | 105 | |
|---|
| | 106 | // trailing /index.php or /index.php/ |
|---|
| | 107 | $redirect['path'] = preg_replace('|/index.php/?$|', '/', $redirect['path']); |
|---|
| | 108 | |
|---|
| | 109 | // strip /index.php/ when we're not using PATHINFO permalinks |
|---|
| | 110 | if ( !$wp_rewrite->using_index_permalinks() ) |
|---|
| | 111 | $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); |
|---|
| | 112 | |
|---|
| | 113 | // trailing slashes |
|---|
| | 114 | if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_home() || ( is_home() && (get_query_var('paged') > 1) ) ) ) { |
|---|
| | 115 | $user_ts_type = ''; |
|---|
| | 116 | if ( get_query_var('paged') > 0 ) { |
|---|
| | 117 | $user_ts_type = 'paged'; |
|---|
| | 118 | } else { |
|---|
| | 119 | foreach ( array('single', 'category', 'page', 'day', 'month', 'year') as $type ) { |
|---|
| | 120 | $func = 'is_' . $type; |
|---|
| | 121 | if ( call_user_func($func) ) |
|---|
| | 122 | $user_ts_type = $type; |
|---|
| | 123 | break; |
|---|
| | 124 | } |
|---|
| | 125 | } |
|---|
| | 126 | $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); |
|---|
| 93 | | if ( !$redirect_url ) { // we're only going down this road if we don't have a WP-generated link from above |
|---|
| 94 | | |
|---|
| 95 | | // www.example.com vs example.com |
|---|
| 96 | | $user_home = parse_url(get_option('home')); |
|---|
| 97 | | $redirect['host'] = $user_home['host']; |
|---|
| 98 | | |
|---|
| 99 | | // trailing /index.php or /index.php/ |
|---|
| 100 | | $redirect['path'] = preg_replace('|/index.php/?$|', '/', $redirect['path']); |
|---|
| 101 | | |
|---|
| 102 | | // need to strip off the query string |
|---|
| 103 | | if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_home() || ( is_home() && is_paged() ) ) ) |
|---|
| 104 | | $redirect['path'] = user_trailingslashit($redirect['path']); |
|---|
| 105 | | |
|---|
| 106 | | if ( array($original['host'], $original['path'], $original['query']) !== array($redirect['host'], $redirect['path'], $redirect['query']) ) { |
|---|
| 107 | | $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; |
|---|
| 108 | | if ( $redirect['query'] ) |
|---|
| 109 | | $redirect_url .= '?' . $redirect['query']; |
|---|
| 110 | | } |
|---|
| | 129 | if ( array($original['host'], $original['path'], $original['query']) !== array($redirect['host'], $redirect['path'], $redirect['query']) ) { |
|---|
| | 130 | $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; |
|---|
| | 131 | if ( $redirect['query'] ) |
|---|
| | 132 | $redirect_url .= '?' . $redirect['query']; |
|---|