Created
February 16, 2018 00:22
-
-
Save timelsass/c9f0ceb38b3f5b1fd17f334eadf48b41 to your computer and use it in GitHub Desktop.
Filter AJAX Requests and WP calls to BGAPI to Dev.
This file contains 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 characters
<?php | |
/** | |
* Plugin name: BoldGrid Filter to Dev | |
* Description: Filter AJAX Requests and WP calls to BGAPI to Dev. | |
* Plugin URI: https://github.com/timelsass | |
* Author: Tim Elsass | |
* Author URI: https://tim.ph | |
*/ | |
// Filter BoldGrid HTTP Requests made via WordPress. | |
function bg_filter_wp_to_dev( $preempt, $r, $url ) { | |
$regex = '/(wp-(?:assets|staging|preview)|api)+(?!-dev)(.*\.boldgrid\.com)+/i'; | |
if ( preg_match( $regex, $url ) ) { | |
$url = preg_replace( $regex, '$1-dev$2', $url ); | |
wp_remote_request( $url, $r ); | |
$preempt = true; | |
} | |
return $preempt; | |
} | |
add_action( 'pre_http_request', 'bg_filter_wp_to_dev', 10, 3 ); | |
// Filter BoldGrid HTTP Requests made via AJAX. | |
function bg_filter_js_to_dev() { ?> | |
<script>(function($){$.ajaxPrefilter(function(o){o.url=o.url.replace(/(wp-(?:assets|staging|preview)|api)+(?!-dev)(.*\.boldgrid\.com)+/i,'$1-dev$2')})})(jQuery)</script><?php | |
} | |
add_action( 'admin_head', 'bg_filter_js_to_dev' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment