@@ -16,17 +16,17 @@ |
||
| 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); |
|
@@ -5,7 +5,7 @@ discard block |
||
| 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,22 +13,22 @@ discard block |
||
| 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 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | -if ( ! function_exists( 'wp_get_additional_image_sizes' ) ) { |
|
| 31 | +if ( ! function_exists('wp_get_additional_image_sizes')) { |
|
| 32 | 32 | /** |
| 33 | 33 | * Retrieve additional image sizes. |
| 34 | 34 | * |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function wp_get_additional_image_sizes() { |
| 42 | 42 | global $_wp_additional_image_sizes; |
| 43 | - if ( ! $_wp_additional_image_sizes ) { |
|
| 43 | + if ( ! $_wp_additional_image_sizes) { |
|
| 44 | 44 | $_wp_additional_image_sizes = []; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -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,70 +44,70 @@ 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[external_cdn_link]"><?php esc_html_e( 'CDN URL', 'imgix' ); ?> |
|
| 68 | + <label class="description" for="imgix_settings[external_cdn_link]"><?php esc_html_e('CDN URL', 'imgix'); ?> |
|
| 69 | 69 | </th> |
| 70 | 70 | <td> |
| 71 | - <input id="imgix_settings[external_cdn_link]" type="url" name="imgix_settings[external_cdn_link]" placeholder="http://s3-eu-west-2.amazonaws.com/your-bucket" value="<?php echo $this->get_option( 'external_cdn_link' ); ?>" class="regular-text code"/> |
|
| 71 | + <input id="imgix_settings[external_cdn_link]" type="url" name="imgix_settings[external_cdn_link]" placeholder="http://s3-eu-west-2.amazonaws.com/your-bucket" value="<?php echo $this->get_option('external_cdn_link'); ?>" class="regular-text code"/> |
|
| 72 | 72 | </td> |
| 73 | 73 | </tr> |
| 74 | 74 | <tr> |
| 75 | 75 | <th> |
| 76 | - <label class="description" for="imgix_settings[auto_format]"><?php esc_html_e( 'Auto Format Images', 'imgix' ); ?></label> |
|
| 76 | + <label class="description" for="imgix_settings[auto_format]"><?php esc_html_e('Auto Format Images', 'imgix'); ?></label> |
|
| 77 | 77 | </th> |
| 78 | 78 | <td> |
| 79 | - <input id="imgix_settings[auto_format]" type="checkbox" name="imgix_settings[auto_format]" value="1" <?php checked( $this->get_option( 'auto_format' ) ) ?> /> |
|
| 79 | + <input id="imgix_settings[auto_format]" type="checkbox" name="imgix_settings[auto_format]" value="1" <?php checked($this->get_option('auto_format')) ?> /> |
|
| 80 | 80 | </td> |
| 81 | 81 | </tr> |
| 82 | 82 | <tr> |
| 83 | 83 | <th> |
| 84 | - <label class="description" for="imgix_settings[auto_enhance]"><?php esc_html_e( 'Auto Enhance Images', 'imgix' ); ?></label> |
|
| 84 | + <label class="description" for="imgix_settings[auto_enhance]"><?php esc_html_e('Auto Enhance Images', 'imgix'); ?></label> |
|
| 85 | 85 | </th> |
| 86 | 86 | <td> |
| 87 | - <input id="imgix_settings[auto_enhance]" type="checkbox" name="imgix_settings[auto_enhance]" value="1" <?php checked( $this->get_option( 'auto_enhance' ) ) ?> /> |
|
| 87 | + <input id="imgix_settings[auto_enhance]" type="checkbox" name="imgix_settings[auto_enhance]" value="1" <?php checked($this->get_option('auto_enhance')) ?> /> |
|
| 88 | 88 | </td> |
| 89 | 89 | </tr> |
| 90 | 90 | <tr> |
| 91 | 91 | <th> |
| 92 | - <label class="description" for="imgix_settings[auto_compress]"><?php esc_html_e( 'Auto Compress Images', 'imgix' ); ?></label> |
|
| 92 | + <label class="description" for="imgix_settings[auto_compress]"><?php esc_html_e('Auto Compress Images', 'imgix'); ?></label> |
|
| 93 | 93 | </th> |
| 94 | 94 | <td> |
| 95 | - <input id="imgix_settings[auto_compress]" type="checkbox" name="imgix_settings[auto_compress]" value="1" <?php checked( $this->get_option( 'auto_compress' ) ) ?> /> |
|
| 95 | + <input id="imgix_settings[auto_compress]" type="checkbox" name="imgix_settings[auto_compress]" value="1" <?php checked($this->get_option('auto_compress')) ?> /> |
|
| 96 | 96 | </td> |
| 97 | 97 | </tr> |
| 98 | 98 | <tr> |
| 99 | 99 | <th> |
| 100 | - <label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e( 'Automatically add retina images using srcset', 'imgix' ); ?></label> |
|
| 100 | + <label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e('Automatically add retina images using srcset', 'imgix'); ?></label> |
|
| 101 | 101 | </th> |
| 102 | 102 | <td> |
| 103 | - <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' ) ) ?> /> |
|
| 103 | + <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')) ?> /> |
|
| 104 | 104 | </td> |
| 105 | 105 | </tr> |
| 106 | 106 | </tbody> |
| 107 | 107 | </table> |
| 108 | 108 | |
| 109 | 109 | <p class="submit"> |
| 110 | - <input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Options', 'imgix' ); ?>"/> |
|
| 110 | + <input type="submit" class="button-primary" value="<?php esc_html_e('Save Options', 'imgix'); ?>"/> |
|
| 111 | 111 | </p> |
| 112 | 112 | </form> |
| 113 | 113 | |
@@ -124,14 +124,14 @@ discard block |
||
| 124 | 124 | * Adds link to options page in Admin > Settings menu. |
| 125 | 125 | */ |
| 126 | 126 | public function imgix_add_options_link() { |
| 127 | - add_options_page( 'imgix', 'imgix', 'manage_options', 'imgix-options', [ $this, 'imgix_options_page' ] ); |
|
| 127 | + add_options_page('imgix', 'imgix', 'manage_options', 'imgix-options', [$this, 'imgix_options_page']); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * Creates our settings in the options table. |
| 132 | 132 | */ |
| 133 | 133 | public function imgix_register_settings() { |
| 134 | - register_setting( 'imgix_settings_group', 'imgix_settings' ); |
|
| 134 | + register_setting('imgix_settings_group', 'imgix_settings'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | * |
| 142 | 142 | * @return mixed |
| 143 | 143 | */ |
| 144 | - protected function get_option( $key ) { |
|
| 145 | - return isset( $this->options[ $key ] ) ? $this->options[ $key ] : ''; |
|
| 144 | + protected function get_option($key) { |
|
| 145 | + return isset($this->options[$key]) ? $this->options[$key] : ''; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -259,11 +259,11 @@ |
||
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( preg_match_all('/url\(([\s])?([\"|\'])?(.*?)([\"|\'])?([\s])?\)/i', $content, $matches ) ) { |
|
| 263 | - foreach ( $matches[3] as $image_src ) { |
|
| 264 | - $content = str_replace( $image_src, apply_filters( 'wp_get_attachment_url', $image_src, null ), $content ); |
|
| 265 | - } |
|
| 266 | - } |
|
| 262 | + if ( preg_match_all('/url\(([\s])?([\"|\'])?(.*?)([\"|\'])?([\s])?\)/i', $content, $matches ) ) { |
|
| 263 | + foreach ( $matches[3] as $image_src ) { |
|
| 264 | + $content = str_replace( $image_src, apply_filters( 'wp_get_attachment_url', $image_src, null ), $content ); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | } |
| 268 | 268 | return $content; |
| 269 | 269 | } |
@@ -27,21 +27,21 @@ 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 | 32 | // Change filter load order to ensure it loads after other CDN url transformations i.e. Amazon S3 which loads at position 99. |
| 33 | - add_filter( 'wp_get_attachment_url', [ $this, 'replace_image_url' ], 100 ); |
|
| 34 | - add_filter( 'imgix/add-image-url', [ $this, 'replace_image_url' ] ); |
|
| 33 | + add_filter('wp_get_attachment_url', [$this, 'replace_image_url'], 100); |
|
| 34 | + add_filter('imgix/add-image-url', [$this, 'replace_image_url']); |
|
| 35 | 35 | |
| 36 | - add_filter( 'image_downsize', [ $this, 'image_downsize' ], 10, 3 ); |
|
| 36 | + add_filter('image_downsize', [$this, 'image_downsize'], 10, 3); |
|
| 37 | 37 | |
| 38 | - add_filter( 'wp_calculate_image_srcset', [ $this, 'calculate_image_srcset' ], 10, 5 ); |
|
| 38 | + add_filter('wp_calculate_image_srcset', [$this, 'calculate_image_srcset'], 10, 5); |
|
| 39 | 39 | |
| 40 | - add_filter( 'the_content', [ $this, 'replace_images_in_content' ] ); |
|
| 41 | - add_action( 'wp_head', [ $this, 'prefetch_cdn' ], 1 ); |
|
| 40 | + add_filter('the_content', [$this, 'replace_images_in_content']); |
|
| 41 | + add_action('wp_head', [$this, 'prefetch_cdn'], 1); |
|
| 42 | 42 | |
| 43 | - add_action( 'after_setup_theme', [ $this, 'buffer_start_for_retina' ] ); |
|
| 44 | - add_action( 'shutdown', [ $this, 'buffer_end_for_retina' ], 0 ); |
|
| 43 | + add_action('after_setup_theme', [$this, 'buffer_start_for_retina']); |
|
| 44 | + add_action('shutdown', [$this, 'buffer_end_for_retina'], 0); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @return Images_Via_Imgix |
| 51 | 51 | */ |
| 52 | 52 | public static function instance() { |
| 53 | - if ( ! isset( self::$instance ) ) { |
|
| 53 | + if ( ! isset(self::$instance)) { |
|
| 54 | 54 | self::$instance = new self; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param string $key |
| 64 | 64 | * @param mixed $value |
| 65 | 65 | */ |
| 66 | - public function set_option( $key, $value ) { |
|
| 67 | - $this->options[ $key ] = $value; |
|
| 66 | + public function set_option($key, $value) { |
|
| 67 | + $this->options[$key] = $value; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @param mixed $default |
| 75 | 75 | * @return mixed |
| 76 | 76 | */ |
| 77 | - public function get_option( $key, $default = '' ) { |
|
| 78 | - return array_key_exists( $key, $this->options ) ? $this->options[ $key ] : $default; |
|
| 77 | + public function get_option($key, $default = '') { |
|
| 78 | + return array_key_exists($key, $this->options) ? $this->options[$key] : $default; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @param array $options |
| 86 | 86 | */ |
| 87 | - public function set_options( $options ) { |
|
| 87 | + public function set_options($options) { |
|
| 88 | 88 | $this->options = $options; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return string Content with retina-enriched image tags. |
| 99 | 99 | */ |
| 100 | - public function add_retina( $content ) { |
|
| 100 | + public function add_retina($content) { |
|
| 101 | 101 | $pattern = '/<img((?![^>]+srcset )([^>]*)'; |
| 102 | 102 | $pattern .= 'src=[\'"]([^\'"]*imgix.net[^\'"]*\?[^\'"]*w=[^\'"]*)[\'"]([^>]*)*?)>/i'; |
| 103 | 103 | $repl = '<img$2src="$3" srcset="${3}, ${3}&dpr=2 2x, ${3}&dpr=3 3x,"$4>'; |
| 104 | - $content = preg_replace( $pattern, $repl, $content ); |
|
| 104 | + $content = preg_replace($pattern, $repl, $content); |
|
| 105 | 105 | |
| 106 | - return preg_replace( $pattern, $repl, $content ); |
|
| 106 | + return preg_replace($pattern, $repl, $content); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -113,37 +113,37 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - public function replace_image_url( $url ) { |
|
| 117 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
| 118 | - $parsed_url = parse_url( $url ); |
|
| 116 | + public function replace_image_url($url) { |
|
| 117 | + if ( ! empty ($this->options['cdn_link'])) { |
|
| 118 | + $parsed_url = parse_url($url); |
|
| 119 | 119 | |
| 120 | 120 | //Check if image is hosted on current site url -OR- the CDN url specified. Using strpos because we're comparing the host to a full CDN url. |
| 121 | 121 | if ( |
| 122 | - isset( $parsed_url['host'], $parsed_url['path'] ) |
|
| 123 | - && ($parsed_url['host'] === parse_url( home_url( '/' ), PHP_URL_HOST ) || ( isset($this->options['external_cdn_link']) && ! empty($this->options['external_cdn_link']) && strpos( $this->options['external_cdn_link'], $parsed_url['host']) !== false ) ) |
|
| 124 | - && preg_match( '/\.(jpg|jpeg|gif|png)$/i', $parsed_url['path'] ) |
|
| 122 | + isset($parsed_url['host'], $parsed_url['path']) |
|
| 123 | + && ($parsed_url['host'] === parse_url(home_url('/'), PHP_URL_HOST) || (isset($this->options['external_cdn_link']) && ! empty($this->options['external_cdn_link']) && strpos($this->options['external_cdn_link'], $parsed_url['host']) !== false)) |
|
| 124 | + && preg_match('/\.(jpg|jpeg|gif|png)$/i', $parsed_url['path']) |
|
| 125 | 125 | ) { |
| 126 | - $cdn = parse_url( $this->options['cdn_link'] ); |
|
| 126 | + $cdn = parse_url($this->options['cdn_link']); |
|
| 127 | 127 | |
| 128 | - foreach ( [ 'scheme', 'host', 'port' ] as $url_part ) { |
|
| 129 | - if ( isset( $cdn[ $url_part ] ) ) { |
|
| 130 | - $parsed_url[ $url_part ] = $cdn[ $url_part ]; |
|
| 128 | + foreach (['scheme', 'host', 'port'] as $url_part) { |
|
| 129 | + if (isset($cdn[$url_part])) { |
|
| 130 | + $parsed_url[$url_part] = $cdn[$url_part]; |
|
| 131 | 131 | } else { |
| 132 | - unset( $parsed_url[ $url_part ] ); |
|
| 132 | + unset($parsed_url[$url_part]); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if ( ! empty( $this->options['external_cdn_link'] ) ) { |
|
| 137 | - $cdn_path = parse_url( $this->options['external_cdn_link'], PHP_URL_PATH ); |
|
| 136 | + if ( ! empty($this->options['external_cdn_link'])) { |
|
| 137 | + $cdn_path = parse_url($this->options['external_cdn_link'], PHP_URL_PATH); |
|
| 138 | 138 | |
| 139 | - if ( isset( $cdn_path, $parsed_url['path'] ) && $cdn_path !== '/' && ! empty( $parsed_url['path'] ) ) { |
|
| 140 | - $parsed_url['path'] = str_replace( $cdn_path, '', $parsed_url['path'] ); |
|
| 139 | + if (isset($cdn_path, $parsed_url['path']) && $cdn_path !== '/' && ! empty($parsed_url['path'])) { |
|
| 140 | + $parsed_url['path'] = str_replace($cdn_path, '', $parsed_url['path']); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $url = http_build_url( $parsed_url ); |
|
| 144 | + $url = http_build_url($parsed_url); |
|
| 145 | 145 | |
| 146 | - $url = add_query_arg( $this->get_global_params(), $url ); |
|
| 146 | + $url = add_query_arg($this->get_global_params(), $url); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -159,40 +159,40 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return false|array |
| 161 | 161 | */ |
| 162 | - public function image_downsize( $return, $attachment_id, $size ) { |
|
| 163 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
| 164 | - $img_url = wp_get_attachment_url( $attachment_id ); |
|
| 162 | + public function image_downsize($return, $attachment_id, $size) { |
|
| 163 | + if ( ! empty ($this->options['cdn_link'])) { |
|
| 164 | + $img_url = wp_get_attachment_url($attachment_id); |
|
| 165 | 165 | |
| 166 | 166 | $params = []; |
| 167 | - if ( is_array( $size ) ) { |
|
| 168 | - $params['w'] = $width = isset( $size[0] ) ? $size[0] : 0; |
|
| 169 | - $params['h'] = $height = isset( $size[1] ) ? $size[1] : 0; |
|
| 167 | + if (is_array($size)) { |
|
| 168 | + $params['w'] = $width = isset($size[0]) ? $size[0] : 0; |
|
| 169 | + $params['h'] = $height = isset($size[1]) ? $size[1] : 0; |
|
| 170 | 170 | } else { |
| 171 | 171 | $available_sizes = $this->get_all_defined_sizes(); |
| 172 | - if ( isset( $available_sizes[ $size ] ) ) { |
|
| 173 | - $size = $available_sizes[ $size ]; |
|
| 172 | + if (isset($available_sizes[$size])) { |
|
| 173 | + $size = $available_sizes[$size]; |
|
| 174 | 174 | $params['w'] = $width = $size['width']; |
| 175 | 175 | $params['h'] = $height = $size['height']; |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $params = array_filter( $params ); |
|
| 179 | + $params = array_filter($params); |
|
| 180 | 180 | |
| 181 | - $img_url = add_query_arg( $params, $img_url ); |
|
| 181 | + $img_url = add_query_arg($params, $img_url); |
|
| 182 | 182 | |
| 183 | - if ( ! isset( $width ) || ! isset( $height ) ) { |
|
| 183 | + if ( ! isset($width) || ! isset($height)) { |
|
| 184 | 184 | // any other type: use the real image |
| 185 | - $meta = wp_get_attachment_metadata( $attachment_id ); |
|
| 185 | + $meta = wp_get_attachment_metadata($attachment_id); |
|
| 186 | 186 | |
| 187 | 187 | // Image sizes is missing for pdf thumbnails |
| 188 | - $meta['width'] = isset( $meta['width'] ) ? $meta['width'] : 0; |
|
| 189 | - $meta['height'] = isset( $meta['height'] ) ? $meta['height'] : 0; |
|
| 188 | + $meta['width'] = isset($meta['width']) ? $meta['width'] : 0; |
|
| 189 | + $meta['height'] = isset($meta['height']) ? $meta['height'] : 0; |
|
| 190 | 190 | |
| 191 | - $width = isset( $width ) ? $width : $meta['width']; |
|
| 192 | - $height = isset( $height ) ? $height : $meta['height']; |
|
| 191 | + $width = isset($width) ? $width : $meta['width']; |
|
| 192 | + $height = isset($height) ? $height : $meta['height']; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - $return = [ $img_url, $width, $height, true ]; |
|
| 195 | + $return = [$img_url, $width, $height, true]; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | return $return; |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | - public function calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) { |
|
| 213 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
| 214 | - foreach ( $sources as $i => $image_size ) { |
|
| 215 | - if ( $image_size['descriptor'] === 'w' ) { |
|
| 216 | - if ( $attachment_id ) { |
|
| 217 | - $image_src = wp_get_attachment_url( $attachment_id ); |
|
| 212 | + public function calculate_image_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id) { |
|
| 213 | + if ( ! empty ($this->options['cdn_link'])) { |
|
| 214 | + foreach ($sources as $i => $image_size) { |
|
| 215 | + if ($image_size['descriptor'] === 'w') { |
|
| 216 | + if ($attachment_id) { |
|
| 217 | + $image_src = wp_get_attachment_url($attachment_id); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - $image_src = remove_query_arg( 'h', $image_src ); |
|
| 221 | - $sources[ $i ]['url'] = add_query_arg( 'w', $image_size['value'], $image_src ); |
|
| 220 | + $image_src = remove_query_arg('h', $image_src); |
|
| 221 | + $sources[$i]['url'] = add_query_arg('w', $image_size['value'], $image_src); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -233,35 +233,35 @@ discard block |
||
| 233 | 233 | * |
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | - public function replace_images_in_content( $content ) { |
|
| 236 | + public function replace_images_in_content($content) { |
|
| 237 | 237 | // Added null to apply filters wp_get_attachment_url to improve compatibility with https://en-gb.wordpress.org/plugins/amazon-s3-and-cloudfront/ - does not break wordpress if the plugin isn't present. |
| 238 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
| 239 | - if ( preg_match_all( '/<img\s[^>]*src=([\"\']??)([^\" >]*?)\1[^>]*>/iU', $content, $matches ) ) { |
|
| 240 | - foreach ( $matches[2] as $image_src ) { |
|
| 241 | - $content = str_replace( $image_src, apply_filters( 'wp_get_attachment_url', $image_src, null ), $content ); |
|
| 238 | + if ( ! empty ($this->options['cdn_link'])) { |
|
| 239 | + if (preg_match_all('/<img\s[^>]*src=([\"\']??)([^\" >]*?)\1[^>]*>/iU', $content, $matches)) { |
|
| 240 | + foreach ($matches[2] as $image_src) { |
|
| 241 | + $content = str_replace($image_src, apply_filters('wp_get_attachment_url', $image_src, null), $content); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if ( preg_match_all( '/<img\s[^>]*srcset=([\"\']??)([^\">]*?)\1[^>]*\/?>/iU', $content, $matches ) ) { |
|
| 245 | + if (preg_match_all('/<img\s[^>]*srcset=([\"\']??)([^\">]*?)\1[^>]*\/?>/iU', $content, $matches)) { |
|
| 246 | 246 | |
| 247 | - foreach ( $matches[2] as $image_srcset ) { |
|
| 248 | - $new_image_srcset = preg_replace_callback( '/(\S+)(\s\d+\w)/', function ( $srcset_matches ) { |
|
| 249 | - return apply_filters( 'wp_get_attachment_url', $srcset_matches[1], null ) . $srcset_matches[2]; |
|
| 250 | - }, $image_srcset ); |
|
| 247 | + foreach ($matches[2] as $image_srcset) { |
|
| 248 | + $new_image_srcset = preg_replace_callback('/(\S+)(\s\d+\w)/', function($srcset_matches) { |
|
| 249 | + return apply_filters('wp_get_attachment_url', $srcset_matches[1], null) . $srcset_matches[2]; |
|
| 250 | + }, $image_srcset); |
|
| 251 | 251 | |
| 252 | - $content = str_replace( $image_srcset, $new_image_srcset, $content ); |
|
| 252 | + $content = str_replace($image_srcset, $new_image_srcset, $content); |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - if ( preg_match_all( '/<a\s[^>]*href=([\"\']??)([^\" >]*?)\1[^>]*>(.*)<\/a>/iU', $content, $matches ) ) { |
|
| 257 | - foreach ( $matches[0] as $link ) { |
|
| 258 | - $content = str_replace( $link[2], apply_filters( 'wp_get_attachment_url', $link[2], null ), $content ); |
|
| 256 | + if (preg_match_all('/<a\s[^>]*href=([\"\']??)([^\" >]*?)\1[^>]*>(.*)<\/a>/iU', $content, $matches)) { |
|
| 257 | + foreach ($matches[0] as $link) { |
|
| 258 | + $content = str_replace($link[2], apply_filters('wp_get_attachment_url', $link[2], null), $content); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( preg_match_all('/url\(([\s])?([\"|\'])?(.*?)([\"|\'])?([\s])?\)/i', $content, $matches ) ) { |
|
| 263 | - foreach ( $matches[3] as $image_src ) { |
|
| 264 | - $content = str_replace( $image_src, apply_filters( 'wp_get_attachment_url', $image_src, null ), $content ); |
|
| 262 | + if (preg_match_all('/url\(([\s])?([\"|\'])?(.*?)([\"|\'])?([\s])?\)/i', $content, $matches)) { |
|
| 263 | + foreach ($matches[3] as $image_src) { |
|
| 264 | + $content = str_replace($image_src, apply_filters('wp_get_attachment_url', $image_src, null), $content); |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -272,12 +272,12 @@ discard block |
||
| 272 | 272 | * Add tag to dns prefetch cdn host |
| 273 | 273 | */ |
| 274 | 274 | public function prefetch_cdn() { |
| 275 | - if ( ! empty ( $this->options['cdn_link'] ) ) { |
|
| 276 | - $host = parse_url( $this->options['cdn_link'], PHP_URL_HOST ); |
|
| 275 | + if ( ! empty ($this->options['cdn_link'])) { |
|
| 276 | + $host = parse_url($this->options['cdn_link'], PHP_URL_HOST); |
|
| 277 | 277 | |
| 278 | 278 | printf( |
| 279 | 279 | '<link rel="dns-prefetch" href="%s"/>', |
| 280 | - esc_attr( '//' . $host ) |
|
| 280 | + esc_attr('//' . $host) |
|
| 281 | 281 | ); |
| 282 | 282 | } |
| 283 | 283 | } |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | * Start output buffer if auto retina is enabled |
| 287 | 287 | */ |
| 288 | 288 | public function buffer_start_for_retina() { |
| 289 | - if ( ! empty ( $this->options['add_dpi2_srcset'] ) ) { |
|
| 290 | - $this->buffer_started = ob_start( [ $this, 'add_retina' ] ); |
|
| 289 | + if ( ! empty ($this->options['add_dpi2_srcset'])) { |
|
| 290 | + $this->buffer_started = ob_start([$this, 'add_retina']); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * Stop output buffer if it was enabled by the plugin |
| 296 | 296 | */ |
| 297 | 297 | public function buffer_end_for_retina() { |
| 298 | - if ( $this->buffer_started && ob_get_level() ) { |
|
| 298 | + if ($this->buffer_started && ob_get_level()) { |
|
| 299 | 299 | ob_end_flush(); |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -311,20 +311,20 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | // For now, only "auto" is supported. |
| 313 | 313 | $auto = []; |
| 314 | - if ( ! empty ( $this->options['auto_format'] ) ) { |
|
| 315 | - array_push( $auto, 'format' ); |
|
| 314 | + if ( ! empty ($this->options['auto_format'])) { |
|
| 315 | + array_push($auto, 'format'); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - if ( ! empty ( $this->options['auto_enhance'] ) ) { |
|
| 319 | - array_push( $auto, 'enhance' ); |
|
| 318 | + if ( ! empty ($this->options['auto_enhance'])) { |
|
| 319 | + array_push($auto, 'enhance'); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( ! empty ( $this->options['auto_compress'] ) ) { |
|
| 323 | - array_push( $auto, 'compress' ); |
|
| 322 | + if ( ! empty ($this->options['auto_compress'])) { |
|
| 323 | + array_push($auto, 'compress'); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if ( ! empty( $auto ) ) { |
|
| 327 | - $params['auto'] = implode( '%2C', $auto ); |
|
| 326 | + if ( ! empty($auto)) { |
|
| 327 | + $params['auto'] = implode('%2C', $auto); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | return $params; |
@@ -340,18 +340,18 @@ discard block |
||
| 340 | 340 | $theme_image_sizes = wp_get_additional_image_sizes(); |
| 341 | 341 | |
| 342 | 342 | $sizes = []; |
| 343 | - foreach ( get_intermediate_image_sizes() as $s ) { |
|
| 344 | - $sizes[ $s ] = [ 'width' => '', 'height' => '', 'crop' => false ]; |
|
| 345 | - if ( isset( $theme_image_sizes[ $s ] ) ) { |
|
| 343 | + foreach (get_intermediate_image_sizes() as $s) { |
|
| 344 | + $sizes[$s] = ['width' => '', 'height' => '', 'crop' => false]; |
|
| 345 | + if (isset($theme_image_sizes[$s])) { |
|
| 346 | 346 | // For theme-added sizes |
| 347 | - $sizes[ $s ]['width'] = intval( $theme_image_sizes[ $s ]['width'] ); |
|
| 348 | - $sizes[ $s ]['height'] = intval( $theme_image_sizes[ $s ]['height'] ); |
|
| 349 | - $sizes[ $s ]['crop'] = $theme_image_sizes[ $s ]['crop']; |
|
| 347 | + $sizes[$s]['width'] = intval($theme_image_sizes[$s]['width']); |
|
| 348 | + $sizes[$s]['height'] = intval($theme_image_sizes[$s]['height']); |
|
| 349 | + $sizes[$s]['crop'] = $theme_image_sizes[$s]['crop']; |
|
| 350 | 350 | } else { |
| 351 | 351 | // For default sizes set in options |
| 352 | - $sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); |
|
| 353 | - $sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); |
|
| 354 | - $sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); |
|
| 352 | + $sizes[$s]['width'] = get_option("{$s}_size_w"); |
|
| 353 | + $sizes[$s]['height'] = get_option("{$s}_size_h"); |
|
| 354 | + $sizes[$s]['crop'] = get_option("{$s}_crop"); |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |