PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.5
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.5
0.5.7 0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 All 33 releases
← All changes | common/helpers.php +23 -27 0.3.70.4.5 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2
3 -if ( !class_exists( 'MeowCommon_Helpers' ) ) {
3 +if ( !class_exists( 'MeowKit_MWCODE_Helpers' ) ) {
4 4
5 - class MeowCommon_Helpers {
6 - //public static $version = MeowCommon_Admin::version;
5 + class MeowKit_MWCODE_Helpers {
6 + //public static $version = MeowKit_MWCODE_Admin::version;
7 7 private static $startTimes = [];
8 8 private static $startQueries = [];
9 9
10 10 public static function is_divi_builder() {
@@ -97,21 +97,21 @@
97 97 public static function is_rest() {
98 98
99 99 // WP 6.5+: only reliable after parse_request; otherwise skip this branch.
100 100 if ( function_exists( 'wp_is_serving_rest_request' ) && did_action( 'parse_request' ) && wp_is_serving_rest_request() ) {
101 - MeowCommon_Rest::init_once();
101 + MeowKit_MWCODE_Rest::init_once();
102 102 return true;
103 103 }
104 104
105 105 // Classic flag set during REST bootstrap (safe at any time).
106 106 if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
107 - MeowCommon_Rest::init_once();
107 + MeowKit_MWCODE_Rest::init_once();
108 108 return true;
109 109 }
110 110
111 111 // Plain permalinks: ?rest_route=/... (route does NOT include the prefix).
112 112 if ( isset( $_GET['rest_route'] ) ) {
113 - MeowCommon_Rest::init_once();
113 + MeowKit_MWCODE_Rest::init_once();
114 114 return true;
115 115 }
116 116
117 117 // Pretty permalinks: compare request PATH to the site's REST base path, without using rest_url().
@@ -117,22 +117,18 @@
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 - $home_path = wp_parse_url( home_url( '/' ), PHP_URL_PATH ); // e.g. '/' or '/blog/'
122 - $home_path = trailingslashit( $home_path ? $home_path : '/' );
121 + $prefix = rest_get_url_prefix(); // e.g. 'wp-json' or custom
123 122
124 - $prefix = trim( rest_get_url_prefix(), '/' ); // e.g. 'wp-json' or custom
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/
125 + $path = trailingslashit( $req_path );
126 + $rest_pattern = '/' . trim( $prefix, '/' ) . '/';
127 + $rest_pattern_index = '/index.php/' . trim( $prefix, '/' ) . '/';
125 128
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 -
132 - $path = trailingslashit( $req_path );
133 - if ( strpos( $path, $base ) === 0 || strpos( $path, $base_index ) === 0 ) {
134 - MeowCommon_Rest::init_once();
129 + if ( strpos( $path, $rest_pattern ) !== false || strpos( $path, $rest_pattern_index ) !== false ) {
130 + MeowKit_MWCODE_Rest::init_once();
135 131 return true;
136 132 }
137 133 }
138 134
@@ -144,9 +140,9 @@
144 140
145 141 // // WP_REST_Request init.
146 142 // $is_rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
147 143 // if ( $is_rest_request ) {
148 - // MeowCommon_Rest::init_once();
144 + // MeowKit_MWCODE_Rest::init_once();
149 145 // return true;
150 146 // }
151 147
152 148 // // Plain permalinks.
@@ -152,9 +148,9 @@
152 148 // // Plain permalinks.
153 149 // $prefix = rest_get_url_prefix();
154 150 // $request_contains_rest = isset( $_GET['rest_route'] ) && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix, 0 ) === 0;
155 151 // if ( $request_contains_rest ) {
156 - // MeowCommon_Rest::init_once();
152 + // MeowKit_MWCODE_Rest::init_once();
157 153 // return true;
158 154 // }
159 155
160 156 // // It can happen that WP_Rewrite is not yet initialized, so better to do it.
@@ -171,9 +167,9 @@
171 167 // // URL Path begins with wp-json.
172 168 // if ( !empty( $current_url['path'] ) && !empty( $rest_url['path'] ) ) {
173 169 // $request_contains_rest = strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
174 170 // if ( $request_contains_rest ) {
175 - // MeowCommon_Rest::init_once();
171 + // MeowKit_MWCODE_Rest::init_once();
176 172 // return true;
177 173 // }
178 174 // }
179 175
@@ -280,19 +276,19 @@
280 276 // }
281 277 }
282 278
283 279 public static function timer_start( $timerName = 'default' ) {
284 - MeowCommon_Helpers::$startQueries[ $timerName ] = get_num_queries();
285 - MeowCommon_Helpers::$startTimes[ $timerName ] = microtime( true );
280 + MeowKit_MWCODE_Helpers::$startQueries[ $timerName ] = get_num_queries();
281 + MeowKit_MWCODE_Helpers::$startTimes[ $timerName ] = microtime( true );
286 282 }
287 283
288 284 public static function timer_elapsed( $timerName = 'default' ) {
289 - return microtime( true ) - MeowCommon_Helpers::$startTimes[ $timerName ];
285 + return microtime( true ) - MeowKit_MWCODE_Helpers::$startTimes[ $timerName ];
290 286 }
291 287
292 288 public static function timer_log_elapsed( $timerName = 'default' ) {
293 - $elapsed = MeowCommon_Helpers::timer_elapsed( $timerName );
294 - $queries = get_num_queries() - MeowCommon_Helpers::$startQueries[ $timerName ];
289 + $elapsed = MeowKit_MWCODE_Helpers::timer_elapsed( $timerName );
290 + $queries = get_num_queries() - MeowKit_MWCODE_Helpers::$startQueries[ $timerName ];
295 291 error_log( $timerName . ': ' . $elapsed . 'ms (' . $queries . ' queries)' );
296 292 }
297 293 }
298 294
@@ -297,8 +293,8 @@
297 293 }
298 294
299 295 // Asked by WP Security Team to remove this.
300 296
301 - // if ( MeowCommon_Helpers::is_rest() ) {
297 + // if ( MeowKit_MWCODE_Helpers::is_rest() ) {
302 298 // ini_set( 'display_errors', 0 );
303 299 // }
304 300 }