PluginProbe
Media Cloud Sync / trunk
Media Cloud Sync vtrunk
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 1.2.9 1.3.0 All 34 releases
← All changes | includes/integrations/acf.php +17 -17 1.2.12trunk 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,9 +53,9 @@
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=link', array( $this, 'filter_link_server' ) );
54 58 add_filter( 'acf/update_value/type=text', array( $this->content_filter, 'filter_post_backward' ) );
55 59 add_filter( 'acf/update_value/type=textarea', array( $this->content_filter, 'filter_post_backward' ) );
56 60 add_filter( 'acf/update_value/type=wysiwyg', array( $this->content_filter, 'filter_post_backward' ) );
57 61 add_filter( 'acf/update_value/type=url', array( $this->content_filter, 'filter_post_backward' ) );
@@ -73,9 +77,9 @@
73 77 add_filter( 'acf/load_field_group', array( $this, 'acf_load_config' ) );
74 78 }
75 79
76 80 /**
77 - * Rewrites URLs from local to remote inside ACF field and field group config. If the
81 + * Rewrites URLs from server to remote inside ACF field and field group config. If the
78 82 * rewriting process fails, it will return the original config.
79 83 *
80 84 * @handles acf/load_fields
81 85 * @handles acf/load_field_group
@@ -85,9 +89,9 @@
85 89 * @return array
86 90 */
87 91 public function acf_load_config( array $config ): array {
88 92 try {
89 - $filtered_config = Utils::maybe_unserialize( $this->content_filter->filter_post( serialize( $config ) ) );
93 + $filtered_config = Utils::maybe_unserialize( $this->content_filter->filter_post( Utils::maybe_serialize( $config ) ) );
90 94 } catch ( Exception $e ) {
91 95 return $config;
92 96 }
93 97
@@ -130,14 +134,14 @@
130 134 return false; //Attachment not offloaded
131 135 }
132 136
133 137 if ( ! Utils::get_meta($original_attachment_id, 'acf_cropped_to_remove', false) ) {
134 - // Original attachment should exist locally, no need to delete
138 + // Original attachment should exist serverly, no need to delete
135 139 return false; //Attachment not to be removed from server
136 140 }
137 141
138 142 // Remove the original file from the server
139 - Item::instance()->may_be_delete_server_files_by_id($original_attachment_id, true);
143 + Item::instance()->may_be_delete_server_files_by_id($original_attachment_id, 'media_library', true);
140 144
141 145 // Remove marker
142 146 Utils::delete_meta($original_attachment_id, 'acf_cropped_to_remove');
143 147
@@ -208,15 +212,15 @@
208 212 }
209 213
210 214
211 215 /**
212 - * Filter a link field's URL from local to provider.
216 + * Filter a link field's URL from server to provider.
213 217 *
214 218 * @param array $link
215 219 *
216 220 * @return array
217 221 */
218 - public function filter_link_local( $link ) {
222 + public function filter_link_server( $link ) {
219 223 if ( is_array( $link ) && ! empty( $link['url'] ) ) {
220 224 $url = $this->content_filter->filter_post( $link['url'] );
221 225
222 226 if ( ! empty( $url ) ) {
@@ -228,9 +232,9 @@
228 232 }
229 233
230 234
231 235 /**
232 - * Filter a link field's URL from provider to local.
236 + * Filter a link field's URL from provider to server.
233 237 *
234 238 * @param array $link
235 239 *
236 240 * @return array
@@ -253,13 +257,9 @@
253 257 *
254 258 * @return bool
255 259 */
256 260 public static function is_installed(): bool {
257 - if ( class_exists( 'acf', false ) ) {
258 - return true;
259 - }
260 -
261 - return false;
261 + return class_exists( 'acf', false );
262 262 }
263 263
264 264 /**
265 265 * Singleton instance