PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
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 1.2.9 All 35 releases
← All changes | includes/integrations/integrations.php +67 -17 1.3.111.4.1 View file →
@@ -39,25 +39,54 @@
39 39 public function init() {
40 40 // Init all integrations
41 41 if (!empty($this->integrations)) {
42 42 foreach ($this->integrations as $integration) {
43 - $integration = __NAMESPACE__ . '\\' . $integration;
44 - if (class_exists($integration) && $integration::is_installed()) {
45 - if (property_exists($integration, 'source_types')) {
46 - self::$source_types = array_merge(self::$source_types, $integration::$source_types);
47 - }
48 - if (property_exists($integration, 'source_type_prefix') && property_exists($integration, 'label')) {
49 - self::$source_labels[$integration::$source_type_prefix] = $integration::$label;
50 - }
51 - if (Utils::is_service_enabled()) {
52 - $integration::instance();
53 - }
54 - }
43 + $this->process_integration($integration);
55 44 }
56 45 }
57 46 }
58 47
59 48 /**
49 + * Processes a single integration: registers its source types/labels and
50 + * instantiates it if installed and the service is enabled.
51 + *
52 + * @param string $integration Unqualified integration class name.
53 + * @since 1.4.1
54 + */
55 + private function process_integration($integration) {
56 + $integration = __NAMESPACE__ . '\\' . $integration;
57 + if (class_exists($integration) && $integration::is_installed()) {
58 + if (property_exists($integration, 'source_types')) {
59 + self::$source_types = array_merge(self::$source_types, $integration::$source_types);
60 + }
61 + // get_label() (not a $label property) because a static property default can't
62 + // call __() — PHP only allows constant expressions there.
63 + if (property_exists($integration, 'source_type_prefix') && method_exists($integration, 'get_label')) {
64 + self::$source_labels[$integration::$source_type_prefix] = $integration::get_label();
65 + }
66 + if (Utils::is_service_enabled()) {
67 + $integration::instance();
68 + }
69 + }
70 + }
71 +
72 + /**
73 + * Registers additional integration classes after construction, mirroring
74 + * Sync::add_sync_classes() — lets Pro register a new integration whenever,
75 + * regardless of load order relative to this class's own construction.
76 + *
77 + * @param array $classes Unqualified integration class names to add.
78 + * @since 1.4.1
79 + */
80 + public function add_integrations($classes = []) {
81 + $new_classes = array_diff($classes, $this->integrations);
82 + $this->integrations = array_merge($this->integrations, $new_classes);
83 + foreach ($new_classes as $integration) {
84 + $this->process_integration($integration);
85 + }
86 + }
87 +
88 + /**
60 89 * Gets the handler class associated with a given source type.
61 90 *
62 91 * @param string $source_type The source type to look up.
63 92 *
@@ -87,15 +116,19 @@
87 116 $source_type_data = self::$source_types[$source_type];
88 117 $meta_key = (isset($source_type_data['meta_prefix']) ? $source_type_data['meta_prefix'].'_' : '') . $key;
89 118 $table = isset($source_type_data['table']) ? $source_type_data['table'] : false;
90 119
120 + if (is_array($table)) {
121 + return Utils::get_custom_meta($post_id, $meta_key, $default, $meta_name, $expire, $table);
122 + }
123 +
91 124 // Update it - handle in seperate integration by calling common function
92 125 switch($table) {
93 - case 'posts':
126 + case 'posts':
94 127 return Utils::get_meta($post_id, $meta_key, $default, $meta_name, $expire);
95 128 case 'users':
96 129 return Utils::get_user_meta($post_id, $meta_key, $default, $meta_name, $expire);
97 - default: null;
130 + default: return $default;
98 131 }
99 132 }
100 133 }
101 134
@@ -116,10 +149,14 @@
116 149 $source_type_data = self::$source_types[$source_type];
117 150 $meta_key = (isset($source_type_data['meta_prefix']) ? $source_type_data['meta_prefix'].'_' : '') . $key;
118 151 $table = isset($source_type_data['table']) ? $source_type_data['table'] : false;
119 152
153 + if (is_array($table)) {
154 + return Utils::update_custom_meta($post_id, $meta_key, $options, $meta_name, $expire, $table);
155 + }
156 +
120 157 switch($table) {
121 - case 'posts':
158 + case 'posts':
122 159 return Utils::update_meta($post_id, $meta_key, $options, $meta_name, $expire);
123 160 case 'users':
124 161 return Utils::update_user_meta($post_id, $meta_key, $options, $meta_name, $expire);
125 162 default: null;
@@ -145,10 +182,15 @@
145 182 } else {
146 183 $meta_key = false;
147 184 }
148 185 $table = isset($source_type_data['table']) ? $source_type_data['table'] : false;
186 +
187 + if (is_array($table)) {
188 + return Utils::delete_custom_meta($post_id, $meta_key, $meta_name, $table);
189 + }
190 +
149 191 switch($table) {
150 - case 'posts':
192 + case 'posts':
151 193 return Utils::delete_meta($post_id, $meta_key, $meta_name);
152 194 case 'users':
153 195 return Utils::delete_user_meta($post_id, $meta_key, $meta_name);
154 196 default: null;
@@ -164,10 +206,18 @@
164 206 public static function clear_all_meta($flush_cache = true) {
165 207 if (!empty(self::$source_types)) {
166 208 foreach (self::$source_types as $source_type => $source_type_data) {
167 209 $table = isset($source_type_data['table']) ? $source_type_data['table'] : false;
210 +
211 + if (is_array($table)) {
212 + // Custom backends (e.g. BuddyBoss groupmeta) aren't bulk-cleared here —
213 + // no generic raw table name to target; individual keys are still
214 + // cleaned up as their owning items are deleted.
215 + continue;
216 + }
217 +
168 218 switch($table) {
169 - case 'posts':
219 + case 'posts':
170 220 Utils::clear_all_meta(false, 'postmeta', $flush_cache);
171 221 break;
172 222 case 'users':
173 223 Utils::clear_all_meta(false, 'usermeta', $flush_cache);