PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/integrations/acf.php +34 -18 1.2.12 → 1.4.2 View file →
@@ -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' ) );
53 - add_filter( 'acf/load_value/type=link', array( $this, 'filter_link_local' ) );
57 + add_filter( 'acf/load_value/type=oembed', array( $this->content_filter, 'filter_post' ) );
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.
@@ -73,9 +80,9 @@
73 80 add_filter( 'acf/load_field_group', array( $this, 'acf_load_config' ) );
74 81 }
75 82
76 83 /**
77 - * Rewrites URLs from local to remote inside ACF field and field group config. If the
84 + * Rewrites URLs from server to remote inside ACF field and field group config. If the
78 85 * rewriting process fails, it will return the original config.
79 86 *
80 87 * @handles acf/load_fields
81 88 * @handles acf/load_field_group
@@ -85,9 +92,9 @@
85 92 * @return array
86 93 */
87 94 public function acf_load_config( array $config ): array {
88 95 try {
89 - $filtered_config = Utils::maybe_unserialize( $this->content_filter->filter_post( serialize( $config ) ) );
96 + $filtered_config = Utils::maybe_unserialize( $this->content_filter->filter_post( Utils::maybe_serialize( $config ) ) );
90 97 } catch ( Exception $e ) {
91 98 return $config;
92 99 }
93 100
@@ -130,14 +137,14 @@
130 137 return false; //Attachment not offloaded
131 138 }
132 139
133 140 if ( ! Utils::get_meta($original_attachment_id, 'acf_cropped_to_remove', false) ) {
134 - // Original attachment should exist locally, no need to delete
141 + // Original attachment should exist serverly, no need to delete
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
@@ -208,15 +228,15 @@
208 228 }
209 229
210 230
211 231 /**
212 - * Filter a link field's URL from local to provider.
232 + * Filter a link field's URL from server to provider.
213 233 *
214 234 * @param array $link
215 235 *
216 236 * @return array
217 237 */
218 - public function filter_link_local( $link ) {
238 + public function filter_link_server( $link ) {
219 239 if ( is_array( $link ) && ! empty( $link['url'] ) ) {
220 240 $url = $this->content_filter->filter_post( $link['url'] );
221 241
222 242 if ( ! empty( $url ) ) {
@@ -228,9 +248,9 @@
228 248 }
229 249
230 250
231 251 /**
232 - * Filter a link field's URL from provider to local.
252 + * Filter a link field's URL from provider to server.
233 253 *
234 254 * @param array $link
235 255 *
236 256 * @return array
@@ -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