/
plugin.php
69 lines (44 loc) · 1.3 KB
/
plugin.php
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
<?php
/*
Plugin Name: Fix SSL Please
Plugin URI: https://github.com/kasparsd/ssl-fix
GitHub URI: https://github.com/kasparsd/ssl-fix
Description: Ensure that everything works over SSL
Version: 0.1.1
Author: Kaspars Dambis
Author URI: http://kaspars.net
*/
add_action( 'plugins_loaded', array( FixSSLPlease::instance(), 'init' ) );
class FixSSLPlease {
protected function __construct() {}
public function init() {
if ( ! is_ssl() ) {
return;
}
add_filter( 'wp_calculate_image_srcset', array( $this, 'image_src' ) );
add_filter( 'the_content', array( $this, 'content_src' ) );
add_filter( 'comment_text', array( $this, 'content_src' ) );
add_filter( 'style_loader_tag', array( $this, 'script_src' ) );
add_filter( 'script_loader_tag', array( $this, 'script_src' ) );
add_filter( 'get_site_icon_url', 'set_url_scheme' );
}
public function instance() {
static $instance;
if ( ! isset( $instance ) ) {
$instance = new self;
}
return $instance;
}
function image_src( $sources ) {
foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'] );
}
return $sources;
}
function content_src( $comment ) {
return str_replace( 'src="http://', 'src="//', $comment );
}
function script_src( $tag ) {
return str_replace( 'http://', '//', $tag );
}
}