Completed
Pull Request — master (#16)
by Rasmus
04:25
created
imgix.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@
 block discarded – undo
16 16
  * Author URI:  http://github.com/imgix-wordpress
17 17
  */
18 18
 
19
-include( 'includes/compability.php' );
20
-include( 'includes/class-images-via-imgix.php' );
21
-include( 'includes/options-page.php' );
19
+include('includes/compability.php');
20
+include('includes/class-images-via-imgix.php');
21
+include('includes/options-page.php');
22 22
 
23
-function imgix_plugin_admin_action_links( $links, $file ) {
24
-	if ( $file === plugin_basename( __FILE__ ) ) {
23
+function imgix_plugin_admin_action_links($links, $file) {
24
+	if ($file === plugin_basename(__FILE__)) {
25 25
 		$settings_link = '<a href="options-general.php?page=imgix-options">Settings</a>';
26
-		array_unshift( $links, $settings_link );
26
+		array_unshift($links, $settings_link);
27 27
 	}
28 28
 
29 29
 	return $links;
30 30
 }
31 31
 
32
-add_filter( 'plugin_action_links', 'imgix_plugin_admin_action_links', 10, 2 );
32
+add_filter('plugin_action_links', 'imgix_plugin_admin_action_links', 10, 2);
Please login to merge, or discard this patch.
includes/options-page.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,54 +44,54 @@  discard block
 block discarded – undo
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[add_dpi2_srcset]"><?php esc_html_e( 'Automatically add retina images using srcset', 'imgix' ); ?></label>
84
+								<label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e('Automatically add retina images using srcset', 'imgix'); ?></label>
85 85
 							</th>
86 86
 							<td>
87
-								<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' ) ) ?> />
87
+								<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')) ?> />
88 88
 							</td>
89 89
 						</tr>
90 90
 					</tbody>
91 91
 				</table>
92 92
 
93 93
 				<p class="submit">
94
-					<input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Options', 'imgix' ); ?>"/>
94
+					<input type="submit" class="button-primary" value="<?php esc_html_e('Save Options', 'imgix'); ?>"/>
95 95
 				</p>
96 96
 			</form>
97 97
 
@@ -108,14 +108,14 @@  discard block
 block discarded – undo
108 108
 	 *  Adds link to options page in Admin > Settings menu.
109 109
 	 */
110 110
 	public function imgix_add_options_link() {
111
-		add_options_page( 'imgix', 'imgix', 'manage_options', 'imgix-options', [ $this, 'imgix_options_page' ] );
111
+		add_options_page('imgix', 'imgix', 'manage_options', 'imgix-options', [$this, 'imgix_options_page']);
112 112
 	}
113 113
 
114 114
 	/**
115 115
 	 *  Creates our settings in the options table.
116 116
 	 */
117 117
 	public function imgix_register_settings() {
118
-		register_setting( 'imgix_settings_group', 'imgix_settings' );
118
+		register_setting('imgix_settings_group', 'imgix_settings');
119 119
 	}
120 120
 
121 121
 	/**
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 	 *
126 126
 	 * @return mixed
127 127
 	 */
128
-	protected function get_option( $key ) {
129
-		return isset( $this->options[ $key ] ) ? $this->options[ $key ] : '';
128
+	protected function get_option($key) {
129
+		return isset($this->options[$key]) ? $this->options[$key] : '';
130 130
 	}
131 131
 }
132 132
 
Please login to merge, or discard this patch.
includes/compability.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @package imgix
6 6
  */
7 7
 
8
-if ( ! function_exists( 'http_build_url' ) ) {
8
+if ( ! function_exists('http_build_url')) {
9 9
 	/**
10 10
 	 * This is a simplified version of http_build_url if pecl_http is missing
11 11
 	 *
@@ -13,16 +13,16 @@  discard block
 block discarded – undo
13 13
 	 *
14 14
 	 * @return string
15 15
 	 */
16
-	function http_build_url( $parsed_url ) {
17
-		$scheme   = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
18
-		$host     = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
19
-		$port     = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
20
-		$user     = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
21
-		$pass     = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
22
-		$pass     = ( $user || $pass ) ? "$pass@" : '';
23
-		$path     = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
24
-		$query    = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
25
-		$fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
16
+	function http_build_url($parsed_url) {
17
+		$scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
18
+		$host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
19
+		$port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
20
+		$user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
21
+		$pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
22
+		$pass     = ($user || $pass) ? "$pass@" : '';
23
+		$path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
24
+		$query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
25
+		$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
26 26
 
27 27
 		return "$scheme$user$pass$host$port$path$query$fragment";
28 28
 	}
Please login to merge, or discard this patch.
includes/class-images-via-imgix.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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}&amp;dpr=2 2x, ${3}&amp;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,33 +88,33 @@  discard block
 block discarded – undo
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 );
94
-
95
-			if ( in_array( $pathinfo['extension'], [ 'jpg', 'gif', 'png', 'jpeg' ] ) ) {
96
-				$parsed_url = parse_url( $url );
97
-				if ( isset( $parsed_url['host'] ) && $parsed_url['host'] === parse_url( home_url( '/' ), PHP_URL_HOST ) ) {
98
-					$cdn = parse_url( $this->options['cdn_link'] );
99
-					foreach ( [ 'scheme', 'host', 'port' ] as $url_part ) {
100
-						if ( isset( $cdn[ $url_part ] ) ) {
101
-							$parsed_url[ $url_part ] = $cdn[ $url_part ];
91
+	public function replace_image_url($url) {
92
+		if ( ! empty ($this->options['cdn_link'])) {
93
+			$pathinfo = pathinfo($url);
94
+
95
+			if (in_array($pathinfo['extension'], ['jpg', 'gif', 'png', 'jpeg'])) {
96
+				$parsed_url = parse_url($url);
97
+				if (isset($parsed_url['host']) && $parsed_url['host'] === parse_url(home_url('/'), PHP_URL_HOST)) {
98
+					$cdn = parse_url($this->options['cdn_link']);
99
+					foreach (['scheme', 'host', 'port'] as $url_part) {
100
+						if (isset($cdn[$url_part])) {
101
+							$parsed_url[$url_part] = $cdn[$url_part];
102 102
 						} else {
103
-							unset( $parsed_url[ $url_part ] );
103
+							unset($parsed_url[$url_part]);
104 104
 						}
105 105
 					}
106 106
 
107
-					list( $filename, $arguments ) = $this->convert_filename_to_size_args( $pathinfo['basename'] );
107
+					list($filename, $arguments) = $this->convert_filename_to_size_args($pathinfo['basename']);
108 108
 
109
-					$arguments = array_merge( $arguments, $this->get_global_params() );
109
+					$arguments = array_merge($arguments, $this->get_global_params());
110 110
 
111
-					$parsed_url['path'] = trailingslashit( dirname( $parsed_url['path'] ) ) . $filename;
111
+					$parsed_url['path'] = trailingslashit(dirname($parsed_url['path'])) . $filename;
112 112
 
113
-					if ( ! empty( $arguments ) ) {
114
-						$parsed_url['query'] = empty( $parsed_url['query'] ) ? build_query( $arguments ) : $parsed_url['query'] . '&' . build_query( $arguments );
113
+					if ( ! empty($arguments)) {
114
+						$parsed_url['query'] = empty($parsed_url['query']) ? build_query($arguments) : $parsed_url['query'] . '&' . build_query($arguments);
115 115
 					}
116 116
 
117
-					$url = http_build_url( $parsed_url );
117
+					$url = http_build_url($parsed_url);
118 118
 				}
119 119
 			}
120 120
 		}
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return array $sources
131 131
 	 */
132
-	public function replace_host_in_srcset( $sources ) {
133
-		foreach ( $sources as $source ) {
134
-			$sources[ $source['value'] ]['url'] = apply_filters( 'imgix/add-image-url', $sources[ $source['value'] ]['url'] );
132
+	public function replace_host_in_srcset($sources) {
133
+		foreach ($sources as $source) {
134
+			$sources[$source['value']]['url'] = apply_filters('imgix/add-image-url', $sources[$source['value']]['url']);
135 135
 		}
136 136
 
137 137
 		return $sources;
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @return string
146 146
 	 */
147
-	public function replace_images_in_content( $content ) {
148
-		if ( ! empty ( $this->options['cdn_link'] ) ) {
149
-			$content = preg_replace_callback( '/(?<=\shref="|\ssrc="|\shref=\'|\ssrc=\').*(?=\'|")/', function ( $match ) {
150
-				return esc_url( apply_filters( 'imgix/add-image-url', $match[0] ) );
151
-			}, $content );
147
+	public function replace_images_in_content($content) {
148
+		if ( ! empty ($this->options['cdn_link'])) {
149
+			$content = preg_replace_callback('/(?<=\shref="|\ssrc="|\shref=\'|\ssrc=\').*(?=\'|")/', function($match) {
150
+				return esc_url(apply_filters('imgix/add-image-url', $match[0]));
151
+			}, $content);
152 152
 
153 153
 		}
154 154
 
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 	 * Add tag to dns prefetch cdn host
160 160
 	 */
161 161
 	public function prefetch_cdn() {
162
-		if ( ! empty ( $this->options['cdn_link'] ) ) {
163
-			$host = parse_url( $this->options['cdn_link'], PHP_URL_HOST );
162
+		if ( ! empty ($this->options['cdn_link'])) {
163
+			$host = parse_url($this->options['cdn_link'], PHP_URL_HOST);
164 164
 
165 165
 			printf(
166 166
 				'<link rel="dns-prefetch" href="%s"/>',
167
-				esc_attr( '//' . $host )
167
+				esc_attr('//' . $host)
168 168
 			);
169 169
 		}
170 170
 	}
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
 	 * Start output buffer if auto retina is enabled
174 174
 	 */
175 175
 	public function buffer_start_for_retina() {
176
-		if ( ! empty ( $this->options['add_dpi2_srcset'] ) ) {
176
+		if ( ! empty ($this->options['add_dpi2_srcset'])) {
177 177
 			$this->buffer_started = true;
178
-			ob_start( [ $this, 'add_retina' ] );
178
+			ob_start([$this, 'add_retina']);
179 179
 		}
180 180
 	}
181 181
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * Stop output buffer if it was enabled by the plugin
184 184
 	 */
185 185
 	public function buffer_end_for_retina() {
186
-		if ( $this->buffer_started === true ) {
186
+		if ($this->buffer_started === true) {
187 187
 			ob_end_flush();
188 188
 		}
189 189
 	}
@@ -199,16 +199,16 @@  discard block
 block discarded – undo
199 199
 
200 200
 		// For now, only "auto" is supported.
201 201
 		$auto = [];
202
-		if ( ! empty ( $this->options['auto_format'] ) ) {
203
-			array_push( $auto, 'format' );
202
+		if ( ! empty ($this->options['auto_format'])) {
203
+			array_push($auto, 'format');
204 204
 		}
205 205
 
206
-		if ( ! empty ( $this->options['auto_enhance'] ) ) {
207
-			array_push( $auto, 'enhance' );
206
+		if ( ! empty ($this->options['auto_enhance'])) {
207
+			array_push($auto, 'enhance');
208 208
 		}
209 209
 
210
-		if ( ! empty( $auto ) ) {
211
-			$params['auto'] = implode( ',', $auto );
210
+		if ( ! empty($auto)) {
211
+			$params['auto'] = implode(',', $auto);
212 212
 		}
213 213
 
214 214
 		return $params;
@@ -222,19 +222,19 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @return array with filename and size arguments.
224 224
 	 */
225
-	protected function convert_filename_to_size_args( $filename ) {
225
+	protected function convert_filename_to_size_args($filename) {
226 226
 		$arguments = [];
227 227
 
228
-		$filename = preg_replace_callback( '/-(?<width>\d+)x(?<height>\d+)(?<extension>\.\w{3,4}$)/', function ( $match ) use ( &$arguments ) {
228
+		$filename = preg_replace_callback('/-(?<width>\d+)x(?<height>\d+)(?<extension>\.\w{3,4}$)/', function($match) use (&$arguments) {
229 229
 			$arguments = [
230 230
 				'w' => $match['width'],
231 231
 				'h' => $match['height']
232 232
 			];
233 233
 
234 234
 			return $match['extension'];
235
-		}, $filename );
235
+		}, $filename);
236 236
 
237
-		return [ $filename, $arguments ];
237
+		return [$filename, $arguments];
238 238
 	}
239 239
 }
240 240
 
Please login to merge, or discard this patch.