@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | |
19 | 19 | |
20 | 20 | public function __construct() { |
21 | - $this->options = get_option( 'imgix_settings', [] ); |
|
22 | - add_action( 'admin_init', [ $this, 'imgix_register_settings' ] ); |
|
23 | - add_action( 'admin_menu', [ $this, 'imgix_add_options_link' ] ); |
|
21 | + $this->options = get_option('imgix_settings', []); |
|
22 | + add_action('admin_init', [$this, 'imgix_register_settings']); |
|
23 | + add_action('admin_menu', [$this, 'imgix_add_options_link']); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return Imgix_Options_page |
30 | 30 | */ |
31 | 31 | public static function instance() { |
32 | - if ( ! isset( self::$instance ) ) { |
|
32 | + if ( ! isset(self::$instance)) { |
|
33 | 33 | self::$instance = new self; |
34 | 34 | } |
35 | 35 | |
@@ -44,62 +44,62 @@ discard block |
||
44 | 44 | <div class="wrap"> |
45 | 45 | |
46 | 46 | <h1> |
47 | - <img src="<?php echo plugins_url( 'assets/images/imgix-logo.png', __DIR__ ); ?>" alt="imgix Logo"> |
|
47 | + <img src="<?php echo plugins_url('assets/images/imgix-logo.png', __DIR__); ?>" alt="imgix Logo"> |
|
48 | 48 | </h1> |
49 | 49 | |
50 | 50 | <p><strong>Need help getting started?</strong> It's easy! Check out our |
51 | 51 | <a href="https://github.com/imgix-wordpress/imgix-wordpress#getting-started" target="_blank">instructions.</a> |
52 | 52 | </p> |
53 | 53 | |
54 | - <form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> |
|
55 | - <?php settings_fields( 'imgix_settings_group' ); ?> |
|
54 | + <form method="post" action="<?php echo admin_url('options.php'); ?>"> |
|
55 | + <?php settings_fields('imgix_settings_group'); ?> |
|
56 | 56 | <table class="form-table"> |
57 | 57 | <tbody> |
58 | 58 | <tr> |
59 | 59 | <th> |
60 | - <label class="description" for="imgix_settings[cdn_link]"><?php esc_html_e( 'imgix Source', 'imgix' ); ?> |
|
60 | + <label class="description" for="imgix_settings[cdn_link]"><?php esc_html_e('imgix Source', 'imgix'); ?> |
|
61 | 61 | </th> |
62 | 62 | <td> |
63 | - <input id="imgix_settings[cdn_link]" type="url" name="imgix_settings[cdn_link]" placeholder="https://yourcompany.imgix.net" value="<?php echo $this->get_option( 'cdn_link' ); ?>" class="regular-text code"/> |
|
63 | + <input id="imgix_settings[cdn_link]" type="url" name="imgix_settings[cdn_link]" placeholder="https://yourcompany.imgix.net" value="<?php echo $this->get_option('cdn_link'); ?>" class="regular-text code"/> |
|
64 | 64 | </td> |
65 | 65 | </tr> |
66 | 66 | <tr> |
67 | 67 | <th> |
68 | - <label class="description" for="imgix_settings[auto_format]"><?php esc_html_e( 'Auto Format Images', 'imgix' ); ?></label> |
|
68 | + <label class="description" for="imgix_settings[auto_format]"><?php esc_html_e('Auto Format Images', 'imgix'); ?></label> |
|
69 | 69 | </th> |
70 | 70 | <td> |
71 | - <input id="imgix_settings[auto_format]" type="checkbox" name="imgix_settings[auto_format]" value="1" <?php checked( $this->get_option( 'auto_format' ) ) ?> /> |
|
71 | + <input id="imgix_settings[auto_format]" type="checkbox" name="imgix_settings[auto_format]" value="1" <?php checked($this->get_option('auto_format')) ?> /> |
|
72 | 72 | </td> |
73 | 73 | </tr> |
74 | 74 | <tr> |
75 | 75 | <th> |
76 | - <label class="description" for="imgix_settings[auto_enhance]"><?php esc_html_e( 'Auto Enhance Images', 'imgix' ); ?></label> |
|
76 | + <label class="description" for="imgix_settings[auto_enhance]"><?php esc_html_e('Auto Enhance Images', 'imgix'); ?></label> |
|
77 | 77 | </th> |
78 | 78 | <td> |
79 | - <input id="imgix_settings[auto_enhance]" type="checkbox" name="imgix_settings[auto_enhance]" value="1" <?php checked( $this->get_option( 'auto_enhance' ) ) ?> /> |
|
79 | + <input id="imgix_settings[auto_enhance]" type="checkbox" name="imgix_settings[auto_enhance]" value="1" <?php checked($this->get_option('auto_enhance')) ?> /> |
|
80 | 80 | </td> |
81 | 81 | </tr> |
82 | 82 | <tr> |
83 | 83 | <th> |
84 | - <label class="description" for="imgix_settings[auto_compress]"><?php esc_html_e( 'Auto Compress Images', 'imgix' ); ?></label> |
|
84 | + <label class="description" for="imgix_settings[auto_compress]"><?php esc_html_e('Auto Compress Images', 'imgix'); ?></label> |
|
85 | 85 | </th> |
86 | 86 | <td> |
87 | - <input id="imgix_settings[auto_compress]" type="checkbox" name="imgix_settings[auto_compress]" value="1" <?php checked( $this->get_option( 'auto_compress' ) ) ?> /> |
|
87 | + <input id="imgix_settings[auto_compress]" type="checkbox" name="imgix_settings[auto_compress]" value="1" <?php checked($this->get_option('auto_compress')) ?> /> |
|
88 | 88 | </td> |
89 | 89 | </tr> |
90 | 90 | <tr> |
91 | 91 | <th> |
92 | - <label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e( 'Automatically add retina images using srcset', 'imgix' ); ?></label> |
|
92 | + <label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e('Automatically add retina images using srcset', 'imgix'); ?></label> |
|
93 | 93 | </th> |
94 | 94 | <td> |
95 | - <input id="imgix_settings[add_dpi2_srcset]" type="checkbox" name="imgix_settings[add_dpi2_srcset]" value="1" <?php checked( $this->get_option( 'add_dpi2_srcset' ) ) ?> /> |
|
95 | + <input id="imgix_settings[add_dpi2_srcset]" type="checkbox" name="imgix_settings[add_dpi2_srcset]" value="1" <?php checked($this->get_option('add_dpi2_srcset')) ?> /> |
|
96 | 96 | </td> |
97 | 97 | </tr> |
98 | 98 | </tbody> |
99 | 99 | </table> |
100 | 100 | |
101 | 101 | <p class="submit"> |
102 | - <input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Options', 'imgix' ); ?>"/> |
|
102 | + <input type="submit" class="button-primary" value="<?php esc_html_e('Save Options', 'imgix'); ?>"/> |
|
103 | 103 | </p> |
104 | 104 | </form> |
105 | 105 | |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | * Adds link to options page in Admin > Settings menu. |
117 | 117 | */ |
118 | 118 | public function imgix_add_options_link() { |
119 | - add_options_page( 'imgix', 'imgix', 'manage_options', 'imgix-options', [ $this, 'imgix_options_page' ] ); |
|
119 | + add_options_page('imgix', 'imgix', 'manage_options', 'imgix-options', [$this, 'imgix_options_page']); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Creates our settings in the options table. |
124 | 124 | */ |
125 | 125 | public function imgix_register_settings() { |
126 | - register_setting( 'imgix_settings_group', 'imgix_settings' ); |
|
126 | + register_setting('imgix_settings_group', 'imgix_settings'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return mixed |
135 | 135 | */ |
136 | - protected function get_option( $key ) { |
|
137 | - return isset( $this->options[ $key ] ) ? $this->options[ $key ] : ''; |
|
136 | + protected function get_option($key) { |
|
137 | + return isset($this->options[$key]) ? $this->options[$key] : ''; |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 |
@@ -27,17 +27,17 @@ discard block |
||
27 | 27 | * ImagesViaImgix constructor. |
28 | 28 | */ |
29 | 29 | public function __construct() { |
30 | - $this->options = get_option( 'imgix_settings', [] ); |
|
30 | + $this->options = get_option('imgix_settings', []); |
|
31 | 31 | |
32 | - add_filter( 'wp_get_attachment_url', [ $this, 'replace_image_url' ] ); |
|
33 | - add_filter( 'imgix/add-image-url', [ $this, 'replace_image_url' ] ); |
|
32 | + add_filter('wp_get_attachment_url', [$this, 'replace_image_url']); |
|
33 | + add_filter('imgix/add-image-url', [$this, 'replace_image_url']); |
|
34 | 34 | |
35 | - add_filter( 'wp_calculate_image_srcset', [ $this, 'replace_host_in_srcset' ], 10 ); |
|
36 | - add_filter( 'the_content', [ $this, 'replace_images_in_content' ] ); |
|
37 | - add_action( 'wp_head', [ $this, 'prefetch_cdn' ], 1 ); |
|
35 | + add_filter('wp_calculate_image_srcset', [$this, 'replace_host_in_srcset'], 10); |
|
36 | + add_filter('the_content', [$this, 'replace_images_in_content']); |
|
37 | + add_action('wp_head', [$this, 'prefetch_cdn'], 1); |
|
38 | 38 | |
39 | - add_action( 'after_setup_theme', [ $this, 'buffer_start_for_retina' ] ); |
|
40 | - add_action( 'shutdown', [ $this, 'buffer_end_for_retina' ] ); |
|
39 | + add_action('after_setup_theme', [$this, 'buffer_start_for_retina']); |
|
40 | + add_action('shutdown', [$this, 'buffer_end_for_retina']); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return Images_Via_Imgix |
47 | 47 | */ |
48 | 48 | public static function instance() { |
49 | - if ( ! isset( self::$instance ) ) { |
|
49 | + if ( ! isset(self::$instance)) { |
|
50 | 50 | self::$instance = new self; |
51 | 51 | } |
52 | 52 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param array $options |
61 | 61 | */ |
62 | - public function set_options( $options ) { |
|
62 | + public function set_options($options) { |
|
63 | 63 | $this->options = $options; |
64 | 64 | } |
65 | 65 | |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return string Content with retina-enriched image tags. |
74 | 74 | */ |
75 | - public function add_retina( $content ) { |
|
75 | + public function add_retina($content) { |
|
76 | 76 | $pattern = '/<img((?![^>]+srcset )([^>]*)'; |
77 | 77 | $pattern .= 'src=[\'"]([^\'"]*imgix.net[^\'"]*\?[^\'"]*w=[^\'"]*)[\'"]([^>]*)*?)>/i'; |
78 | 78 | $repl = '<img$2src="$3" srcset="${3}, ${3}&dpr=2 2x, ${3}&dpr=3 3x,"$4>'; |
79 | - $content = preg_replace( $pattern, $repl, $content ); |
|
79 | + $content = preg_replace($pattern, $repl, $content); |
|
80 | 80 | |
81 | - return preg_replace( $pattern, $repl, $content ); |
|
81 | + return preg_replace($pattern, $repl, $content); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,39 +88,39 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - public function replace_image_url( $url ) { |
|
92 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
93 | - $pathinfo = pathinfo( $url ); |
|
91 | + public function replace_image_url($url) { |
|
92 | + if ( ! empty ($this->options['cdn_link'])) { |
|
93 | + $pathinfo = pathinfo($url); |
|
94 | 94 | |
95 | - if ( isset( $pathinfo['extension'] ) && in_array( $pathinfo['extension'], [ |
|
95 | + if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], [ |
|
96 | 96 | 'jpg', |
97 | 97 | 'gif', |
98 | 98 | 'png', |
99 | 99 | 'jpeg' |
100 | - ] ) |
|
100 | + ]) |
|
101 | 101 | ) { |
102 | - $parsed_url = parse_url( $url ); |
|
103 | - if ( isset( $parsed_url['host'] ) && $parsed_url['host'] === parse_url( home_url( '/' ), PHP_URL_HOST ) ) { |
|
104 | - $cdn = parse_url( $this->options['cdn_link'] ); |
|
105 | - foreach ( [ 'scheme', 'host', 'port' ] as $url_part ) { |
|
106 | - if ( isset( $cdn[ $url_part ] ) ) { |
|
107 | - $parsed_url[ $url_part ] = $cdn[ $url_part ]; |
|
102 | + $parsed_url = parse_url($url); |
|
103 | + if (isset($parsed_url['host']) && $parsed_url['host'] === parse_url(home_url('/'), PHP_URL_HOST)) { |
|
104 | + $cdn = parse_url($this->options['cdn_link']); |
|
105 | + foreach (['scheme', 'host', 'port'] as $url_part) { |
|
106 | + if (isset($cdn[$url_part])) { |
|
107 | + $parsed_url[$url_part] = $cdn[$url_part]; |
|
108 | 108 | } else { |
109 | - unset( $parsed_url[ $url_part ] ); |
|
109 | + unset($parsed_url[$url_part]); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - list( $filename, $arguments ) = $this->convert_filename_to_size_args( $pathinfo['basename'] ); |
|
113 | + list($filename, $arguments) = $this->convert_filename_to_size_args($pathinfo['basename']); |
|
114 | 114 | |
115 | - $arguments = array_merge( $arguments, $this->get_global_params() ); |
|
115 | + $arguments = array_merge($arguments, $this->get_global_params()); |
|
116 | 116 | |
117 | - $parsed_url['path'] = trailingslashit( dirname( $parsed_url['path'] ) ) . $filename; |
|
117 | + $parsed_url['path'] = trailingslashit(dirname($parsed_url['path'])) . $filename; |
|
118 | 118 | |
119 | - if ( ! empty( $arguments ) ) { |
|
120 | - $parsed_url['query'] = empty( $parsed_url['query'] ) ? build_query( $arguments ) : $parsed_url['query'] . '&' . build_query( $arguments ); |
|
119 | + if ( ! empty($arguments)) { |
|
120 | + $parsed_url['query'] = empty($parsed_url['query']) ? build_query($arguments) : $parsed_url['query'] . '&' . build_query($arguments); |
|
121 | 121 | } |
122 | 122 | |
123 | - $url = http_build_url( $parsed_url ); |
|
123 | + $url = http_build_url($parsed_url); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return array $sources |
137 | 137 | */ |
138 | - public function replace_host_in_srcset( $sources ) { |
|
139 | - foreach ( $sources as $source ) { |
|
140 | - $sources[ $source['value'] ]['url'] = apply_filters( 'imgix/add-image-url', $sources[ $source['value'] ]['url'] ); |
|
138 | + public function replace_host_in_srcset($sources) { |
|
139 | + foreach ($sources as $source) { |
|
140 | + $sources[$source['value']]['url'] = apply_filters('imgix/add-image-url', $sources[$source['value']]['url']); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return $sources; |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function replace_images_in_content( $content ) { |
|
154 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
155 | - $content = preg_replace_callback( '/(?<=\shref="|\ssrc="|\shref=\'|\ssrc=\').*(?=\'|")/', function ( $match ) { |
|
156 | - return esc_url( apply_filters( 'imgix/add-image-url', $match[0] ) ); |
|
157 | - }, $content ); |
|
153 | + public function replace_images_in_content($content) { |
|
154 | + if ( ! empty ($this->options['cdn_link'])) { |
|
155 | + $content = preg_replace_callback('/(?<=\shref="|\ssrc="|\shref=\'|\ssrc=\').*(?=\'|")/', function($match) { |
|
156 | + return esc_url(apply_filters('imgix/add-image-url', $match[0])); |
|
157 | + }, $content); |
|
158 | 158 | |
159 | 159 | } |
160 | 160 | |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | * Add tag to dns prefetch cdn host |
166 | 166 | */ |
167 | 167 | public function prefetch_cdn() { |
168 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
169 | - $host = parse_url( $this->options['cdn_link'], PHP_URL_HOST ); |
|
168 | + if ( ! empty ($this->options['cdn_link'])) { |
|
169 | + $host = parse_url($this->options['cdn_link'], PHP_URL_HOST); |
|
170 | 170 | |
171 | 171 | printf( |
172 | 172 | '<link rel="dns-prefetch" href="%s"/>', |
173 | - esc_attr( '//' . $host ) |
|
173 | + esc_attr('//' . $host) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | } |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * Start output buffer if auto retina is enabled |
180 | 180 | */ |
181 | 181 | public function buffer_start_for_retina() { |
182 | - if ( ! empty ( $this->options['add_dpi2_srcset'] ) ) { |
|
182 | + if ( ! empty ($this->options['add_dpi2_srcset'])) { |
|
183 | 183 | $this->buffer_started = true; |
184 | - ob_start( [ $this, 'add_retina' ] ); |
|
184 | + ob_start([$this, 'add_retina']); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Stop output buffer if it was enabled by the plugin |
190 | 190 | */ |
191 | 191 | public function buffer_end_for_retina() { |
192 | - if ( $this->buffer_started === true ) { |
|
192 | + if ($this->buffer_started === true) { |
|
193 | 193 | ob_end_flush(); |
194 | 194 | } |
195 | 195 | } |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | |
206 | 206 | // For now, only "auto" is supported. |
207 | 207 | $auto = []; |
208 | - if ( ! empty ( $this->options['auto_format'] ) ) { |
|
209 | - array_push( $auto, 'format' ); |
|
208 | + if ( ! empty ($this->options['auto_format'])) { |
|
209 | + array_push($auto, 'format'); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( ! empty ( $this->options['auto_enhance'] ) ) { |
|
213 | - array_push( $auto, 'enhance' ); |
|
212 | + if ( ! empty ($this->options['auto_enhance'])) { |
|
213 | + array_push($auto, 'enhance'); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( ! empty ( $this->options['auto_compress'] ) ) { |
|
217 | - array_push( $auto, 'compress' ); |
|
216 | + if ( ! empty ($this->options['auto_compress'])) { |
|
217 | + array_push($auto, 'compress'); |
|
218 | 218 | } |
219 | 219 | |
220 | - if ( ! empty( $auto ) ) { |
|
221 | - $params['auto'] = implode( ',', $auto ); |
|
220 | + if ( ! empty($auto)) { |
|
221 | + $params['auto'] = implode(',', $auto); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return $params; |
@@ -232,19 +232,19 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @return array with filename and size arguments. |
234 | 234 | */ |
235 | - protected function convert_filename_to_size_args( $filename ) { |
|
235 | + protected function convert_filename_to_size_args($filename) { |
|
236 | 236 | $arguments = []; |
237 | 237 | |
238 | - $filename = preg_replace_callback( '/-(?<width>\d+)x(?<height>\d+)(?<extension>\.\w{3,4}$)/', function ( $match ) use ( &$arguments ) { |
|
238 | + $filename = preg_replace_callback('/-(?<width>\d+)x(?<height>\d+)(?<extension>\.\w{3,4}$)/', function($match) use (&$arguments) { |
|
239 | 239 | $arguments = [ |
240 | 240 | 'w' => $match['width'], |
241 | 241 | 'h' => $match['height'] |
242 | 242 | ]; |
243 | 243 | |
244 | 244 | return $match['extension']; |
245 | - }, $filename ); |
|
245 | + }, $filename); |
|
246 | 246 | |
247 | - return [ $filename, $arguments ]; |
|
247 | + return [$filename, $arguments]; |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 |