/*

Plugin Name: WP-China-Yes

Description: 此插件将全面替换WP访问官方服务的链接为高速稳定的中国大陆节点,以此加快站点更新版本、安装升级插件主题的速度,并彻底解决429报错问题。

Author: 孙锡源

Version: 1.0.0

Author URI:https://www.ibadboy.net/

*/

define('WP_CHINA_YES_PATH', __DIR__);

define('WP_CHINA_YES_BASE_FILE', __FILE__);

define('WP_CHINA_YES_VERSION', '1.0.0');

WP_CHINA_YES::init();

class WP_CHINA_YES {

public static function init() {

if (is_admin()) {

add_filter('pre_http_request', array(

__CLASS__,

'pre_http_request'

), 10, 3);

add_filter('plugin_row_meta', array(

__CLASS__,

'plugin_row_meta'

), 10, 2);

}

}

public static function pre_http_request($preempt, $r, $url) {

if ( ! stristr($url, 'api.wordpress.org') && ! stristr($url, 'downloads.wordpress.org')) {

return false;

}

$url = str_replace('api.wordpress.org', 'api.w.org.ibadboy.net', $url);

$url = str_replace('downloads.wordpress.org', 'd.w.org.ibadboy.net', $url);

if (function_exists('wp_kses_bad_protocol')) {

if ($r['reject_unsafe_urls']) {

$url = wp_http_validate_url($url);

}

if ($url) {

$url = wp_kses_bad_protocol($url, array(

'http',

'https',

'ssl'

));

}

}

$arrURL = @parse_url($url);

if (empty($url) || empty($arrURL['scheme'])) {

return new WP_Error('http_request_failed', __('A valid URL was not provided.'));

}

// If we are streaming to a file but no filename was given drop it in the WP temp dir

// and pick its name using the basename of the $url

if ($r['stream']) {

if (empty($r['filename'])) {

$r['filename'] = get_temp_dir() . basename($url);

}

// Force some settings if we are streaming to a file and check for existence and perms of destination directory

$r['blocking'] = true;

if ( ! wp_is_writable(dirname($r['filename']))) {

return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.'));

}

}

if (is_null($r['headers'])) {

$r['headers'] = array();

}

// WP allows passing in headers as a string, weirdly.

if ( ! is_array($r['headers'])) {

$processedHeaders = WP_Http::processHeaders($r['headers']);

$r['headers'] = $processedHeaders['headers'];

}

// Setup arguments

$headers = $r['headers'];

$data = $r['body'];

$type = $r['method'];

$options = array(

'timeout' => $r['timeout'],

'useragent' => $r['user-agent'],

'blocking' => $r['blocking'],

'hooks' => new WP_HTTP_Requests_Hooks($url, $r),

);

if ($r['stream']) {

$options['filename'] = $r['filename'];

}

if (empty($r['redirection'])) {

$options['follow_redirects'] = false;

} else {

$options['redirects'] = $r['redirection'];

}

// Use byte limit, if we can

if (isset($r['limit_response_size'])) {

$options['max_bytes'] = $r['limit_response_size'];

}

// If we've got cookies, use and convert them to Requests_Cookie.

if ( ! empty($r['cookies'])) {

$options['cookies'] = WP_Http::normalize_cookies($r['cookies']);

}

// SSL certificate handling

if ( ! $r['sslverify']) {

$options['verify'] = false;

$options['verifyname'] = false;

} else {

$options['verify'] = $r['sslcertificates'];

}

// All non-GET/HEAD requests should put the arguments in the form body.

if ('HEAD' !== $type && 'GET' !== $type) {

$options['data_format'] = 'body';

}

/**

* Filters whether SSL should be verified for non-local requests.

*

* @param bool $ssl_verify Whether to verify the SSL connection. Default true.

* @param string $url The request URL.

*

* @since 2.8.0

* @since 5.1.0 The `$url` parameter was added.

*

*/

$options['verify'] = apply_filters('https_ssl_verify', $options['verify'], $url);

// Check for proxies.

$proxy = new WP_HTTP_Proxy();

if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) {

$options['proxy'] = new Requests_Proxy_HTTP($proxy->host() . ':' . $proxy->port());

if ($proxy->use_authentication()) {

$options['proxy']->use_authentication = true;

$options['proxy']->user = $proxy->username();

$options['proxy']->pass = $proxy->password();

}

}

// Avoid issues where mbstring.func_overload is enabled

mbstring_binary_safe_encoding();

try {

$requests_response = Requests::request($url, $headers, $data, $type, $options);

// Convert the response into an array

$http_response = new WP_HTTP_Requests_Response($requests_response, $r['filename']);

$response = $http_response->to_array();

// Add the original object to the array.

$response['http_response'] = $http_response;

} catch (Requests_Exception $e) {

$response = new WP_Error('http_request_failed', $e->getMessage());

}

reset_mbstring_encoding();

/**

* Fires after an HTTP API response is received and before the response is returned.

*

* @param array|WP_Error $response HTTP response or WP_Error object.

* @param string $context Context under which the hook is fired.

* @param string $class HTTP transport used.

* @param array $r HTTP request arguments.

* @param string $url The request URL.

*

* @since 2.8.0

*

*/

do_action('http_api_debug', $response, 'response', 'Requests', $r, $url);

if (is_wp_error($response)) {

return $response;

}

if ( ! $r['blocking']) {

return array(

'headers' => array(),

'body' => '',

'response' => array(

'code' => false,

'message' => false,

),

'cookies' => array(),

'http_response' => null,

);

}

/**

* Filters the HTTP API response immediately before the response is returned.

*

* @param array $response HTTP response.

* @param array $r HTTP request arguments.

* @param string $url The request URL.

*

* @since 2.9.0

*

*/

return apply_filters('http_response', $response, $r, $url);

}

public static function plugin_row_meta($links, $file) {

$base = plugin_basename(WP_CHINA_YES_BASE_FILE);

if ($file == $base) {

$links[] = '插件发布页';

}

return $links;

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

http91spwp index.php,index.php相关推荐

  1. mysql ignore index,mysql强制索引FORCE INDEX/IGNORE INDEX忽略索引

    FORCE INDEX 通常用来对查询强制使用一个或者多个索引. MySQL 通常会根据统计信息选择正确的索引,但是当查询优化器选择了错误的索引或者根本没有使用索引的时候,这个提示将非常有用. IGN ...

  2. :/index.php,http://localhost/my/INDEX.PHP/INDEX/INDEX无法正常运行:解决时找不到Options FollowSymLinks谢谢...

    源自:2-3 路由类 http://localhost/my/INDEX.PHP/INDEX/INDEX无法正常运行:解决时找不到Options FollowSymLinks谢谢 打不到: Optio ...

  3. url(r'^index/$',views.index)的含义解释

    已知: urls.py中的代码是: from django.contrib import admin from django.urls import path from django import u ...

  4. php_self include,PHP_SELF返回/index.php/index.php

    为什么$_SERVER ['PHP_SELF']会返回/index.php/index.php ?? 请求 http://example.com 产量 /index.php/index.php 的in ...

  5. Python中[index for index, value in enumerate(a) if value > 3]

    并不是index for index,这段代码应该这么看.(大括号内视为一个整体) [{index} for {index, value} in {enumerate(x)} if {value == ...

  6. html中index函数,INDEX函数.doc

    INDEX函数 INDEX函数(有数组和引用两种用法.) 贡献者:HYPERLINK "/space-uid-1450717.html"843211 日期:2008-07-22 阅 ...

  7. TP6 控制器不存在:app\index\controller\Index

    今天把网站部署到服务器碰到一个大坑,代码本地运行没有问题,但是放到服务器就一直报错 控制器不存在:app\index\controller\Index 然后各种找原因,百度了说是Linux对大小写要求 ...

  8. Cordova工程index.html/index.css/index.js结构及关键代码

    Cordova工程index.html/index.css/index.js结构及关键代码 1. index.html 2. index.css (1)横竖屏的判断方法: (2)深色模式适配 3. i ...

  9. index++和++index区别

    下面两个例子简单明了 实例1: int index=0; System.out.println("index = " + ++index); 输出结果为: index = 1 实例 ...

  10. index++和index+1严重区别

    大家好!这个index++和index+1看似非常简单的理解,也许会认为就算发生错误,我也可以很容易的发现,但是当这样用的时候,就会出现逻辑错误了. self.noLabel.text = [NSSt ...

最新文章

  1. 玩转Android之二维码生成与识别
  2. android 魅族扫码,魅族Flyme8扫码快传太实用,轻松实现文件高速传输
  3. SAP QM 样品废弃后如何删除physical samples记录?
  4. 基于BootStrap,FortAweSome,Ajax的学生管理系统
  5. Java是否支持默认参数值?
  6. Hadoop Eclipse开发环境设置
  7. SM37job状态意义
  8. 被判赔联想525万,常程方回应:提起诉讼;百度自动驾驶出租车在京全面开放;VS Code 1.50版发布|极客头条
  9. Java集合框架介绍
  10. Golang1.71.3下载以及安装(Linux Mac Windows)
  11. Julia : 1亿条记录读取测试,及几个优化点
  12. globeimposter 解密工具_WinRAR加密和压缩伪装成GlobeImposter勒索软件,易于安全专家解密...
  13. 初学Godot笔记(二)(认真开凿版)
  14. 求职应聘时面试常见问题2
  15. 联想Y7000驱动黑苹果的耳机口
  16. Fishermen(2018 ICPC SouthEastern European)
  17. 台式机开机黑屏一直闪小横杠,键盘灯鼠标均正常,主板亮
  18. 查找新式BADI的方法
  19. 黑马头条项目 8.4 推荐系统接口定义
  20. 系统分析和设计方法之信息系统构件

热门文章

  1. 12星座绝情榜,你的绝情指数是多少呢?
  2. 光荣特库摩游戏《莱莎的炼金工房》宣布动画化,2023 年 7 月开播
  3. 哪个软件测试手机电池续航好,6款手机电池续航测试排名:iPhone12mini险些垫底,第1名是小米10...
  4. 湖北师范大学计信计科2018届期末实训EduCoder习题 (参考答案)
  5. 【笔记】Jenkins- 解决 “Error 403 No valid crumb was included in the request“
  6. 微信小程序转码机器人❤️免费无水印❤️
  7. 提高教育效率:教师如何制作智能学生成绩在线查询系统?
  8. 安卓玩机搞机技巧综合资源-----修改rom 制作rom 解包rom的一些问题解析【二十一】
  9. qt高亮快捷键_Qt常用快捷键
  10. 取整取余(模)知多少?