-
-
Save cyberwani/b1ad118f6bbf763af710523af4bbdf7b to your computer and use it in GitHub Desktop.
Revisions
-
matzeeable revised this gist
May 31, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,6 @@ function is_rest() { // (#4) $rest_url = wp_parse_url( trailingslashit( rest_url( ) ) ); $current_url = wp_parse_url( add_query_arg( array( ) ) ); return strpos( $current_url['path'] ?? '/', $rest_url['path'], 0 ) === 0; } } -
matzeeable revised this gist
Aug 24, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ function is_rest() { if (defined('REST_REQUEST') && REST_REQUEST // (#1) || isset($_GET['rest_route']) // (#2) && strpos( $_GET['rest_route'] , '/', 0 ) === 0) return true; // (#3) -
matzeeable revised this gist
Aug 24, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ * Checks if the current request is a WP REST API request. * * Case #1: After WP_REST_Request initialisation * Case #2: Support "plain" permalink settings and check if `rest_route` starts with `/` * Case #3: It can happen that WP_Rewrite is not yet initialized, * so do this (wp-settings.php) * Case #4: URL Path begins with wp-json/ (your REST prefix) @@ -17,7 +17,7 @@ function is_rest() { if (defined('REST_REQUEST') && REST_REQUEST // (#1) || isset($_GET['rest_route']) // (#2) && strpos( $_GET['rest_route'] ), '/', 0 ) === 0) return true; // (#3) -
matzeeable revised this gist
Sep 9, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,10 +15,9 @@ * @author matzeeable */ function is_rest() { if (defined('REST_REQUEST') && REST_REQUEST // (#1) || isset($_GET['rest_route']) // (#2) && strpos( trim( $_GET['rest_route'], '\\/' ), rest_get_url_prefix( ) , 0 ) === 0) return true; // (#3) -
matzeeable revised this gist
Aug 27, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ * Case #1: After WP_REST_Request initialisation * Case #2: Support "plain" permalink settings * Case #3: It can happen that WP_Rewrite is not yet initialized, * so do this (wp-settings.php) * Case #4: URL Path begins with wp-json/ (your REST prefix) * Also supports WP installations in subfolders * -
matzeeable revised this gist
Aug 27, 2019 . 1 changed file with 31 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,33 @@ <?php if ( !function_exists( 'is_rest' ) ) { /** * Checks if the current request is a WP REST API request. * * Case #1: After WP_REST_Request initialisation * Case #2: Support "plain" permalink settings * Case #3: It can happen that WP_Rewrite is not yet initialized, * so do this (wp-settings.php) * Case #4: URL Path begins with wp-json/ (your REST prefix) * Also supports WP installations in subfolders * * @returns boolean * @author matzeeable */ function is_rest() { $prefix = rest_get_url_prefix( ); if (defined('REST_REQUEST') && REST_REQUEST // (#1) || isset($_GET['rest_route']) // (#2) && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0) return true; // (#3) global $wp_rewrite; if ($wp_rewrite === null) $wp_rewrite = new WP_Rewrite(); // (#4) $rest_url = wp_parse_url( trailingslashit( rest_url( ) ) ); $current_url = wp_parse_url( add_query_arg( array( ) ) ); return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0; } } -
Matthias Günter revised this gist
Oct 20, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ function is_rest() { // (#3) $rest_url = wp_parse_url( site_url( $prefix ) ); $current_url = wp_parse_url( add_query_arg( array( ) ) ); return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0; } } -
Matthias Günter revised this gist
Oct 18, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php if (!function_exists('is_rest')) { /** * Checks if the current request is a WP REST API request. -
Matthias Günter revised this gist
Oct 18, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ * Case #1: After WP_REST_Request initialisation * Case #2: Support "plain" permalink settings * Case #3: URL Path begins with wp-json/ (your REST prefix) * Also supports WP installations in subfolders * * @returns boolean * @author matzeeable -
Matthias Günter created this gist
Oct 18, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ if (!function_exists('is_rest')) { /** * Checks if the current request is a WP REST API request. * * Case #1: After WP_REST_Request initialisation * Case #2: Support "plain" permalink settings * Case #3: URL Path begins with wp-json/ (your REST prefix) * * @returns boolean * @author matzeeable */ function is_rest() { $prefix = rest_get_url_prefix( ); if (defined('REST_REQUEST') && REST_REQUEST // (#1) || isset($_GET['rest_route']) // (#2) && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0) return true; // (#3) $rest_url = wp_parse_url( site_url( $prefix ) ); $current_url = wp_parse_url( home_url( add_query_arg( array( ) ) ) ); return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0; } }