diff --git a/README.md b/README.md index 98b88243..9c94e2e1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **Tags:** uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront **Requires at least:** 4.4 **Tested up to:** 4.6.1 -**Stable tag:** 1.1.1 +**Stable tag:** 1.1.2 **License:** GPLv3 Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery. @@ -69,12 +69,16 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin ## Changelog ## +### WP Offload S3 Lite 1.1.2 - 2016-11-02 ### +* Improvement: Better content filtering support for third party plugins and themes +* Bug fix: PHP Warning: Division by zero + ### WP Offload S3 Lite 1.1.1 - 2016-10-17 ### * New: Filter post excerpts - S3 URLs will no longer be saved to the database * Bug fix: PHP 5.3 Fatal error: Using $this when not in object context * Bug fix: Query string parameters incorrectly encoded for Media Library items -### WP Offload S3 Lite 1.1 - 2016-10-29 ### +### WP Offload S3 Lite 1.1 - 2016-09-29 ### * New: Filter post content. S3 URLs will no longer be saved to the database * New: Upgrade routine to replace all S3 URLs in content with local URLs * New: Support for theme custom logos diff --git a/classes/amazon-s3-and-cloudfront.php b/classes/amazon-s3-and-cloudfront.php index 0b6c7663..e57a91e2 100644 --- a/classes/amazon-s3-and-cloudfront.php +++ b/classes/amazon-s3-and-cloudfront.php @@ -1937,8 +1937,8 @@ protected function maybe_sign_intermediate_size( $url, $attachment_id, $size, $s * @return null|string */ protected function convert_dimensions_to_size_name( $attachment_id, $dimensions ) { - $w = $dimensions[0]; - $h = $dimensions[1]; + $w = ( isset( $dimensions[0] ) && $dimensions[0] > 0 ) ? $dimensions[0] : 1; + $h = ( isset( $dimensions[1] ) && $dimensions[1] > 0 ) ? $dimensions[1] : 1; $original_aspect_ratio = $w / $h; $meta = wp_get_attachment_metadata( $attachment_id ); diff --git a/classes/as3cf-filter.php b/classes/as3cf-filter.php index 1964f47c..8df125fa 100644 --- a/classes/as3cf-filter.php +++ b/classes/as3cf-filter.php @@ -128,6 +128,11 @@ public function filter_post( $content ) { * @return mixed */ protected function process_content( $content, $cache, &$to_cache ) { + if ( empty( $content ) ) { + // Nothing to filter, return + return $content; + } + if ( ! $this->should_filter_content() ) { // Not filtering content, return return $content; diff --git a/classes/filters/as3cf-local-to-s3.php b/classes/filters/as3cf-local-to-s3.php index b019b66b..09f55c60 100644 --- a/classes/filters/as3cf-local-to-s3.php +++ b/classes/filters/as3cf-local-to-s3.php @@ -6,29 +6,66 @@ class AS3CF_Local_To_S3 extends AS3CF_Filter { * Init. */ protected function init() { - // Hot fix for 4.4 responsive images - $priority = 1; - - global $wp_version; - if ( 0 === version_compare( $wp_version, '4.4' ) ) { - $priority = 10; - } - // EDD add_filter( 'edd_download_files', array( $this, 'filter_edd_download_files' ) ); // Customizer add_filter( 'theme_mod_background_image', array( $this, 'filter_customizer_image' ) ); add_filter( 'theme_mod_header_image', array( $this, 'filter_customizer_image' ) ); // Posts - add_filter( 'the_content', array( $this, 'filter_post' ), $priority, 1 ); + add_action( 'the_post', array( $this, 'filter_post_data' ) ); + add_filter( 'content_pagination', array( $this, 'filter_content_pagination' ) ); + add_filter( 'the_content', array( $this, 'filter_post' ), 100 ); + add_filter( 'the_excerpt', array( $this, 'filter_post' ), 100 ); add_filter( 'content_edit_pre', array( $this, 'filter_post' ) ); - add_filter( 'the_excerpt', array( $this, 'filter_post' ) ); add_filter( 'excerpt_edit_pre', array( $this, 'filter_post' ) ); // Widgets add_filter( 'widget_text', array( $this, 'filter_widget' ) ); add_filter( 'widget_form_callback', array( $this, 'filter_widget_form' ), 10, 2 ); } + /** + * Filter post data. + * + * @param WP_Post $post + */ + public function filter_post_data( $post ) { + global $pages; + + $cache = $this->get_post_cache(); + $to_cache = array(); + + if ( count( $pages ) === 1 ) { + // Post already filtered and available on global $page array, continue + $post->post_content = $pages[0]; + } else { + $post->post_content = $this->process_content( $post->post_content, $cache, $to_cache ); + } + + $post->post_excerpt = $this->process_content( $post->post_excerpt, $cache, $to_cache ); + + $this->maybe_update_post_cache( $to_cache ); + } + + /** + * Filter content pagination. + * + * @param array $pages + * + * @return array + */ + public function filter_content_pagination( $pages ) { + $cache = $this->get_post_cache(); + $to_cache = array(); + + foreach ( $pages as $key => $page ) { + $pages[ $key ] = $this->process_content( $page, $cache, $to_cache ); + } + + $this->maybe_update_post_cache( $to_cache ); + + return $pages; + } + /** * Filter widget. * diff --git a/languages/amazon-s3-and-cloudfront-en.pot b/languages/amazon-s3-and-cloudfront-en.pot index d16a8da0..5a59ad5d 100644 --- a/languages/amazon-s3-and-cloudfront-en.pot +++ b/languages/amazon-s3-and-cloudfront-en.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: amazon-s3-and-cloudfront\n" "Report-Msgid-Bugs-To: nom@deliciousbrains.com\n" -"POT-Creation-Date: 2016-10-17 13:06+0100\n" +"POT-Creation-Date: 2016-11-02 13:33+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/readme.txt b/readme.txt index d3ba5e5d..6b5e4b4c 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: bradt, deliciousbrains Tags: uploads, amazon, s3, amazon s3, mirror, admin, media, cdn, cloudfront Requires at least: 4.4 Tested up to: 4.6.1 -Stable tag: 1.1.1 +Stable tag: 1.1.2 License: GPLv3 Copies files to Amazon S3 as they are uploaded to the Media Library. Optionally configure Amazon CloudFront for faster delivery. @@ -65,12 +65,16 @@ This version requires PHP 5.3.3+ and the Amazon Web Services plugin == Changelog == += WP Offload S3 Lite 1.1.2 - 2016-11-02 = +* Improvement: Better content filtering support for third party plugins and themes +* Bug fix: PHP Warning: Division by zero + = WP Offload S3 Lite 1.1.1 - 2016-10-17 = * New: Filter post excerpts - S3 URLs will no longer be saved to the database * Bug fix: PHP 5.3 Fatal error: Using $this when not in object context * Bug fix: Query string parameters incorrectly encoded for Media Library items -= WP Offload S3 Lite 1.1 - 2016-10-29 = += WP Offload S3 Lite 1.1 - 2016-09-29 = * New: Filter post content. S3 URLs will no longer be saved to the database * New: Upgrade routine to replace all S3 URLs in content with local URLs * New: Support for theme custom logos diff --git a/wordpress-s3.php b/wordpress-s3.php index 45b4dfee..aab63525 100644 --- a/wordpress-s3.php +++ b/wordpress-s3.php @@ -4,7 +4,7 @@ Plugin URI: http://wordpress.org/extend/plugins/amazon-s3-and-cloudfront/ Description: Automatically copies media uploads to Amazon S3 for storage and delivery. Optionally configure Amazon CloudFront for even faster delivery. Author: Delicious Brains -Version: 1.1.1 +Version: 1.1.2 Author URI: http://deliciousbrains.com/ Network: True Text Domain: amazon-s3-and-cloudfront @@ -26,7 +26,7 @@ // Then completely rewritten. */ -$GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '1.1.1'; +$GLOBALS['aws_meta']['amazon-s3-and-cloudfront']['version'] = '1.1.2'; $aws_plugin_version_required = '1.0';