Skip to content

Commit

Permalink
1.3.5 fix send_through_proxy; add pre_http_request
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepm committed Jan 5, 2020
1 parent 040fdfd commit 7416631
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
40 changes: 31 additions & 9 deletions class-wp-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct() {
if ( $options ) {
$this->options = $options;
if ( $options['enable'] ) {
add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
add_filter( 'pre_http_send_through_proxy', array( $this, 'send_through_proxy' ), 10, 4 );
defined( 'WP_PROXY_HOST' ) ? '' : define( 'WP_PROXY_HOST', $options['proxy_host'] );
defined( 'WP_PROXY_PORT' ) ? '' : define( 'WP_PROXY_PORT', $options['proxy_port'] );
Expand All @@ -49,11 +50,13 @@ public function __construct() {
} else {
add_option( 'wp_proxy_options', $this->defualt_options() );
}
add_action( 'admin_menu', array( $this, 'options_page' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
if ( is_admin() ) {
add_action( 'admin_menu', array( $this, 'options_page' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
}
add_filter( 'plugin_row_meta', array( $this, 'plugin_details_links' ), 10, 2 );
}

Expand Down Expand Up @@ -230,6 +233,21 @@ public function admin_bar_menu( $wp_admin_bar ) {
}
}

/**
* Set request arg
*
* @param bool $false is pre.
* @param array $parsed_args args.
* @param string $url url.
*/
public function pre_http_request( $false, $parsed_args, $url ) {
if ( $this->send_through_proxy( null, $url, $url, '' ) ) {
$parsed_args['timeout'] = $parsed_args['timeout'] + 1200;
@set_time_limit( $parsed_args['timeout'] + 60 );
}
return $parsed_args;
}

/**
* Check URL
*
Expand All @@ -240,22 +258,26 @@ public function admin_bar_menu( $wp_admin_bar ) {
* @since 1.0
*/
public function send_through_proxy( $null, $url, $check, $home ) {
$rules = explode( '\n', $this->options['domains'] );
$rules = explode( "\n", $this->options['domains'] );
$host = false;
if ( ! is_array( $check ) ) {
$check = wp_parse_url( $check );
}
if ( isset( $check['host'] ) ) {
$host = $check['host'];
}
$regex = array();
foreach ( $rules as $rule ) {
$rule = str_replace( '*.', '(.*)\.', $rule );
if ( $rule === $host ) {
return true;
} elseif ( preg_match( '#' . $rule . '#i', $host ) ) {
return true;
} else {
$regex[] = str_replace( '\*', '.+', preg_quote( $rule, '/' ) );
}
}
if ( ! empty( $regex ) ) {
$regex = '^(' . implode( '|', $regex ) . ')$';
return preg_match( '#' . $regex . '#i', $host );
}
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# WordPress 代理访问
# WP Proxy
Contributors: sdffamt
Donate link: https://xn--vkuk.org/blog/wp-proxy
Tags: proxy
Requires at least: 3.0.1
Tested up to: 5.3.2
Stable tag: 1.3.4
Stable tag: 1.3.5
Requires PHP: 5.2.4
License: GPLv2 or later

Expand Down
3 changes: 2 additions & 1 deletion wp-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Plugin Name: WP Proxy
* Plugin URI: https://xn--vkuk.org/blog/wp-proxy
* Description: manage proxy for WordPress
* Version: 1.3.4
* Version: 1.3.5
* Author: sleepm
* Author URI: https://xn--vkuk.org/blog/
* Text Domain: wp-proxy
* Domain Path: /languages
* License: GPLv2 or later
Expand Down

0 comments on commit 7416631

Please sign in to comment.