| @@ -117,17 +117,21 @@ | ||
| 117 | 117 | // Pretty permalinks: compare request PATH to the site's REST base path, without using rest_url(). |
| 118 | 118 | // This works early in the bootstrap (no dependency on $wp_rewrite). |
| 119 | 119 | $req_path = isset( $_SERVER['REQUEST_URI'] ) ? wp_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) : null; |
| 120 | 120 | if ( $req_path ) { |
| 121 | - $prefix = rest_get_url_prefix(); // e.g. 'wp-json' or custom | |
| 121 | + $home_path = wp_parse_url( home_url( '/' ), PHP_URL_PATH ); // e.g. '/' or '/blog/' | |
| 122 | + $home_path = trailingslashit( $home_path ? $home_path : '/' ); | |
| 122 | 123 | |
| 123 | - // Check if the path contains /wp-json/ or /index.php/wp-json/ | |
| 124 | - // This handles multilingual plugins (WPML, Polylang) that add language prefixes like /fr/wp-json/ | |
| 124 | + $prefix = trim( rest_get_url_prefix(), '/' ); // e.g. 'wp-json' or custom | |
| 125 | + | |
| 126 | + // /wp-json/ or /blog/wp-json/ | |
| 127 | + $base = $home_path . trailingslashit( $prefix ); | |
| 128 | + | |
| 129 | + // /index.php/wp-json/ or /blog/index.php/wp-json/ (index permalinks) | |
| 130 | + $base_index = $home_path . 'index.php/' . trailingslashit( $prefix ); | |
| 131 | + | |
| 125 | 132 | $path = trailingslashit( $req_path ); |
| 126 | - $rest_pattern = '/' . trim( $prefix, '/' ) . '/'; | |
| 127 | - $rest_pattern_index = '/index.php/' . trim( $prefix, '/' ) . '/'; | |
| 128 | - | |
| 129 | - if ( strpos( $path, $rest_pattern ) !== false || strpos( $path, $rest_pattern_index ) !== false ) { | |
| 133 | + if ( strpos( $path, $base ) === 0 || strpos( $path, $base_index ) === 0 ) { | |
| 130 | 134 | MeowKit_MWCODE_Rest::init_once(); |
| 131 | 135 | return true; |
| 132 | 136 | } |
| 133 | 137 | } |