-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-local-flywheel-https.php
More file actions
94 lines (84 loc) · 3.07 KB
/
fix-local-flywheel-https.php
File metadata and controls
94 lines (84 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
Plugin Name: Fix Local SSL Requests
Plugin URI: https://local.getflywheel.com/community/t/wp-cron-not-working-on-secured-sites/147/2
Description: Makes WordPress URLs non-secure for certain SSL requests.
Version: 1.1.0
Author: Morgan Estes
Author URI: https://morganestes.com
License: GPLv2 or later
*/
namespace Morgan_Estes\Fix_Local_HTTPS;
/**
* Forces non-SSL REST API URLs in development environments.
*
* Fix just for Local by Flywheel, which doesn't provide container-level SSL.
*
* @since 1.0.0
* @link https://local.getflywheel.com/community/t/wp-cron-not-working-on-secured-sites/147/2
* @internal Fires on 'rest_url' filter.
*
* @param string $url REST URL.
* @param string $path REST route.
* @param int $blog_id Blog ID.
* @param string $scheme Sanitization scheme.
* @return string The (maybe) filtered REST URL with 'http' scheme.
*/
function make_rest_url_http( $url, $path, $blog_id, $scheme ) {
if ( is_ssl() ) {
$url = set_url_scheme( $url, 'http' );
}
return $url;
}
add_filter( 'rest_url', __NAMESPACE__ . '\\make_rest_url_http', 10, 4 );
/**
* Forces non-SSL site URLs in development environments.
*
* Fix just for Local by Flywheel, which doesn't provide container-level SSL.
*
* @since 1.0.0
* @link https://local.getflywheel.com/community/t/wp-cron-not-working-on-secured-sites/147/2
* @internal Fires on 'cron_request' filter.
*
* @param array $cron_request_array {
* An array of cron request URL arguments.
*
* @type string $url The cron request URL.
* @type int $key The 22 digit GMT microtime.
* @type array $args {
* An array of cron request arguments.
*
* @type int $timeout The request timeout in seconds. Default .01 seconds.
* @type bool $blocking Whether to set blocking for the request. Default false.
* @type bool $sslverify Whether SSL should be verified for the request. Default false.
* }
* }
* @param string $doing_wp_cron The unix timestamp of the cron lock.
* @return array The (maybe) filtered cron request with 'http' URL scheme.
*/
function make_cron_url_http( $cron_request_array, $doing_wp_cron ) {
if ( is_ssl() ) {
$cron_request_array['url'] = set_url_scheme( $cron_request_array['url'], 'http' );
}
return $cron_request_array;
}
add_filter( 'cron_request', __NAMESPACE__ . '\\make_cron_url_http', 10, 2 );
/**
* Filter the admin URL for in-network requests between sites.
*
* @since 1.1.0
*
* @param string $url The complete admin area URL including scheme and path.
* @param string $path Path relative to the admin area URL. Blank string if no path is specified.
* @param int|null $blog_id Site ID, or null for the current site.
* @return string The filtered admin_url.
*/
function fix_network_upgrades( $url, $path, $blog_id ) {
if ( is_multisite() && is_ssl() ) {
if ( SITE_ID_CURRENT_SITE !== $blog_id && 'upgrade.php?step=upgrade_db' === $path ) {
$url = set_url_scheme( $url, 'http' );
}
}
return $url;
}
add_filter( 'admin_url', __NAMESPACE__ . '\\fix_network_upgrades', 10, 3 );