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/integrations.php +48 -11 1.2.12trunk View file →
@@ -4,11 +4,8 @@
4 4 defined('ABSPATH') || exit;
5 5
6 6 class Integration {
7 7 private static $instance = null;
8 - private $assets_url;
9 - private $version;
10 - private $token;
11 8
12 9 private $integrations = [];
13 10 public static $source_types = [];
14 11 public static $source_labels = [];
@@ -17,15 +14,13 @@
17 14 * Admin constructor.
18 15 * @since 1.0.0
19 16 */
20 17 public function __construct() {
21 - $this->assets_url = WPMCS_ASSETS_URL;
22 - $this->version = WPMCS_VERSION;
23 - $this->token = WPMCS_TOKEN;
24 -
25 18 $this->integrations = [
26 19 'MediaLibrary',
27 - 'Acf'
20 + 'Acf',
21 + 'Imagify',
22 + 'WooCommerce',
28 23 ];
29 24
30 25 // Initialize setup
31 26 $this->init();
@@ -46,23 +41,36 @@
46 41 if (!empty($this->integrations)) {
47 42 foreach ($this->integrations as $integration) {
48 43 $integration = __NAMESPACE__ . '\\' . $integration;
49 44 if (class_exists($integration) && $integration::is_installed()) {
50 - $integration::instance();
51 - // Add Source types from all integrations
52 45 if (property_exists($integration, 'source_types')) {
53 46 self::$source_types = array_merge(self::$source_types, $integration::$source_types);
54 47 }
55 - // Add prefix and label from all integrations
56 48 if (property_exists($integration, 'source_type_prefix') && property_exists($integration, 'label')) {
57 49 self::$source_labels[$integration::$source_type_prefix] = $integration::$label;
58 50 }
51 + if (Utils::is_service_enabled()) {
52 + $integration::instance();
53 + }
59 54 }
60 55 }
61 56 }
62 57 }
63 58
59 + /**
60 + * Gets the handler class associated with a given source type.
61 + *
62 + * @param string $source_type The source type to look up.
63 + *
64 + * @return string|null The handler class associated with the source type, or null if not found.
65 + */
66 + public static function get_handler_class($source_type = 'media_library') {
67 + return class_exists(__NAMESPACE__ . '\\' . self::$source_types[$source_type]['class'])
68 + ? __NAMESPACE__ . '\\' . self::$source_types[$source_type]['class']
69 + : null;
70 + }
64 71
72 +
65 73 /**
66 74 * Get Item Meta According to Integration
67 75 * @param int $post_id
68 76 * @param string $key
@@ -147,9 +155,38 @@
147 155 }
148 156 }
149 157 }
150 158
159 + /**
160 + * Clear all meta
161 + *
162 + * @param bool $flush_cache Whether to flush the plugin object cache after each table clear.
163 + */
164 + public static function clear_all_meta($flush_cache = true) {
165 + if (!empty(self::$source_types)) {
166 + foreach (self::$source_types as $source_type => $source_type_data) {
167 + $table = isset($source_type_data['table']) ? $source_type_data['table'] : false;
168 + switch($table) {
169 + case 'posts':
170 + Utils::clear_all_meta(false, 'postmeta', $flush_cache);
171 + break;
172 + case 'users':
173 + Utils::clear_all_meta(false, 'usermeta', $flush_cache);
174 + break;
175 + default: null;
176 + }
177 + }
178 + }
179 + }
180 +
181 +
151 182
183 + /**
184 + * Return an instance of the class.
185 + *
186 + * @return Integration
187 + * @since 1.0.0
188 + */
152 189 public static function instance(){
153 190 if (is_null(self::$instance)) {
154 191 self::$instance = new self();
155 192 }