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 /** * Class used to force HTTPS for all FooGallery assets * @since 1.6.18 */ if ( ! class_exists( 'FooGallery_ForceHttps' ) ) {
class FooGallery_ForceHttps {
function __construct() { add_filter( 'foogallery_admin_settings_override', array($this, 'add_settings' ) ); add_action( 'plugins_loaded', array( $this, 'enable_force' ) ); }
/** * Enables the force checks based on the setting. This is done here so that the setting is only checked once per page load, rather than multiple times * */ function enable_force() { if ( 'on' === foogallery_get_setting( 'force_https' ) ) { add_filter( 'foogallery_attachment_resize_thumbnail', array( $this, 'force_thumbnail_to_https' ), 99, 3 ); add_filter( 'foogallery_enqueue_style_src', array( $this, 'force_css_to_https'), 99, 2 ); add_filter( 'foogallery_core_gallery_script', array( $this, 'force_js_to_https'), 99 ); } }
/** * Add settings for Force Https * @param $settings * * @return array */ function add_settings( $settings ) { $settings['settings'][] = array( 'id' => 'force_https', 'title' => __( 'Force HTTPS', 'foogallery' ), 'desc' => __( 'Force all assets (thumbnails, javascript, css) to load over the HTTPS protocol. This can help overcome some issues when moving your site across to HTTPS and you get mixed content errors.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'advanced' ); return $settings; }
/** * Helper function that does the replacement and forces Https * * @param $url * * @return string */ function force_https( $url ) { return str_replace( 'http://', 'https://', $url ); }
/** * Force a thumbnail src to Https * * @param $original_image_src * @param $args * @param $thumbnail_object * * @return string */ function force_thumbnail_to_https( $original_image_src, $args, $thumbnail_object ) { $original_image_src = $this->force_https( $original_image_src ); return $original_image_src; }
/** * Force any CSS loaded using the foogallery_enqueue_style function to Https * * @param $src * @param $handle * * @return string */ function force_css_to_https( $src, $handle ) { $src = $this->force_https( $src ); return $src; }
/** * Force the js loaded for the default gallery templates to Https * * @param $src * * @return string */ function force_js_to_https( $src ) { $src = $this->force_https( $src ); return $src; } } }
|