| @@ -5,8 +5,15 @@ | ||
| 5 | 5 | |
| 6 | 6 | use DirectoryIterator; |
| 7 | 7 | use Exception; |
| 8 | 8 | |
| 9 | +/** | |
| 10 | + * ACF Compatibility. | |
| 11 | + * | |
| 12 | + * Loaded by the autoloader; activation is gated via `is_installed()` in Integration::init(). | |
| 13 | + * | |
| 14 | + * @since 1.0.0 | |
| 15 | + */ | |
| 9 | 16 | class Acf { |
| 10 | 17 | private static $instance = null; |
| 11 | 18 | private $assets_url; |
| 12 | 19 | private $version; |
| @@ -27,12 +34,9 @@ | ||
| 27 | 34 | $this->settings = Utils::get_settings(); |
| 28 | 35 | $this->content_filter = FilterContent::instance(); |
| 29 | 36 | $this->compatibility = Compatibility::instance(); |
| 30 | 37 | |
| 31 | - if (self::is_installed()) { | |
| 32 | - // Register actions | |
| 33 | - $this->registerActions(); | |
| 34 | - } | |
| 38 | + $this->registerActions(); | |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | 41 | /** |
| 38 | 42 | * Register integration access |
| @@ -49,13 +53,15 @@ | ||
| 49 | 53 | add_filter( 'acf/load_value/type=text', array( $this->content_filter, 'filter_post' ) ); |
| 50 | 54 | add_filter( 'acf/load_value/type=textarea', array( $this->content_filter, 'filter_post' ) ); |
| 51 | 55 | add_filter( 'acf/load_value/type=wysiwyg', array( $this->content_filter, 'filter_post' ) ); |
| 52 | 56 | add_filter( 'acf/load_value/type=url', array( $this->content_filter, 'filter_post' ) ); |
| 57 | + add_filter( 'acf/load_value/type=oembed', array( $this->content_filter, 'filter_post' ) ); | |
| 53 | 58 | add_filter( 'acf/load_value/type=link', array( $this, 'filter_link_server' ) ); |
| 54 | 59 | add_filter( 'acf/update_value/type=text', array( $this->content_filter, 'filter_post_backward' ) ); |
| 55 | 60 | add_filter( 'acf/update_value/type=textarea', array( $this->content_filter, 'filter_post_backward' ) ); |
| 56 | 61 | add_filter( 'acf/update_value/type=wysiwyg', array( $this->content_filter, 'filter_post_backward' ) ); |
| 57 | 62 | add_filter( 'acf/update_value/type=url', array( $this->content_filter, 'filter_post_backward' ) ); |
| 63 | + add_filter( 'acf/update_value/type=oembed', array( $this->content_filter, 'filter_post_backward' ) ); | |
| 58 | 64 | add_filter( 'acf/update_value/type=link', array( $this, 'filter_link_provider' ) ); |
| 59 | 65 | |
| 60 | 66 | /* |
| 61 | 67 | * Image Crop Add-on |
| @@ -63,8 +69,9 @@ | ||
| 63 | 69 | */ |
| 64 | 70 | if ( class_exists( 'acf_field_image_crop' ) ) { |
| 65 | 71 | add_filter( 'wp_get_attachment_metadata', array( $this, 'download_image' ), 10, 2 ); |
| 66 | 72 | add_filter( 'sanitize_file_name', array( $this, 'remove_original_after_download' ) ); |
| 73 | + add_filter( 'wpmcs_do_reupload_media', array( $this, 'force_reupload_during_crop' ), 10, 3 ); | |
| 67 | 74 | } |
| 68 | 75 | |
| 69 | 76 | /* |
| 70 | 77 | * Rewrite URLs in field and field group config. |
| @@ -135,9 +142,9 @@ | ||
| 135 | 142 | return false; //Attachment not to be removed from server |
| 136 | 143 | } |
| 137 | 144 | |
| 138 | 145 | // Remove the original file from the server |
| 139 | - Item::instance()->may_be_delete_server_files_by_id($original_attachment_id, true); | |
| 146 | + Item::instance()->may_be_delete_server_files_by_id($original_attachment_id, 'media_library', true); | |
| 140 | 147 | |
| 141 | 148 | // Remove marker |
| 142 | 149 | Utils::delete_meta($original_attachment_id, 'acf_cropped_to_remove'); |
| 143 | 150 | |
| @@ -142,11 +149,24 @@ | ||
| 142 | 149 | Utils::delete_meta($original_attachment_id, 'acf_cropped_to_remove'); |
| 143 | 150 | |
| 144 | 151 | return true; |
| 145 | 152 | } |
| 146 | - | |
| 147 | 153 | |
| 154 | + /** | |
| 155 | + * ACF Image Crop Add-on always crops to the field's one fixed configured | |
| 156 | + * size, so declared dimensions never change between crops — the same blind | |
| 157 | + * spot shouldForceReupload() has for a flip/180° rotate. Force it explicitly. | |
| 158 | + * @since 1.4.3 | |
| 159 | + */ | |
| 160 | + public function force_reupload_during_crop( $do_reupload, $attachment_id, $source_type ) { | |
| 161 | + if ( $do_reupload ) { | |
| 162 | + return $do_reupload; | |
| 163 | + } | |
| 164 | + return $this->compatibility->maybe_process_on_action( 'acf_image_crop_perform_crop', true ) ? true : $do_reupload; | |
| 165 | + } | |
| 148 | 166 | |
| 167 | + | |
| 168 | + | |
| 149 | 169 | /** |
| 150 | 170 | * Copy back the S3 image for cropping |
| 151 | 171 | * |
| 152 | 172 | * @param array $data |
| @@ -253,13 +273,9 @@ | ||
| 253 | 273 | * |
| 254 | 274 | * @return bool |
| 255 | 275 | */ |
| 256 | 276 | public static function is_installed(): bool { |
| 257 | - if ( class_exists( 'acf', false ) ) { | |
| 258 | - return true; | |
| 259 | - } | |
| 260 | - | |
| 261 | - return false; | |
| 277 | + return class_exists( 'acf', false ); | |
| 262 | 278 | } |
| 263 | 279 | |
| 264 | 280 | /** |
| 265 | 281 | * Singleton instance |