Created
January 11, 2015 00:58
-
-
Save logichub/ef4bc9fc5961ba1c634a to your computer and use it in GitHub Desktop.
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
The HTTP requests made by the premium plugins are really a huge pain. While I understand the purpose, I still don't get why they need to happen so often. | |
I have been struggling during a long time with this issue. Woo plugins, affiliate, etc. they all send requests even on page, post or custom posts pages. When their server is loaded, sit can easily take between 500ms to 2s. | |
Puneet, the only way to fix this has been to block all http request on specific pages by adding a filter 'pre_http_request'. | |
Here is a sample code: http://pastebin.com/5bji3rQG | |
This is not pretty but this should give you a starting point. | |
Before experimenting with this, you can always test by adding | |
define( 'WP_HTTP_BLOCK_EXTERNAL', TRUE ); | |
in your wp-config. This will block ALL external HTTP requests on ALL pages. This should tell you if you're on a good track before going any further. | |
On a side note, WP_HTTP_BLOCK_EXTERNAL can be also be customized this way: | |
// block external requests except the white-list hosts | |
define('WP_HTTP_BLOCK_EXTERNAL', true); | |
// allow external requests | |
define('WP_HTTP_BLOCK_EXTERNAL', false); | |
// white-list hosts comma separated | |
define('WP_ACCESSIBLE_HOSTS', 'api.wordpress.org '); | |
Remember this one will affect all pages. While it's good for specific purpose, it didn't do the trick for me/ | |
Source: | |
https://www.facebook.com/groups/advancedwp/permalink/885292874866261/?comment_id=885456564849892&offset=0&total_comments=74 |
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
function block_api_calls() { | |
global $pagenow; | |
if (( $pagenow == 'plugins.php' ) || | |
( $pagenow == 'plugin-install.php' ) || | |
( $pagenow == 'themes.php' ) || | |
( $pagenow == 'update.php' ) || | |
( $pagenow == 'index.php' ) || | |
( $pagenow == 'admin.php' ) || | |
( $pagenow == 'update-core.php' )){ | |
add_filter( 'pre_http_request', '__return_false', 100 ); | |
} | |
else{ | |
add_filter( 'pre_http_request', '__return_true', 100 ); | |
} | |
} | |
add_action( 'admin_init', 'block_api_calls', 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment