| @@ -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 | - $integration::instance(); | |
| 46 | - // Add Source types from all integrations | |
| 47 | - if (property_exists($integration, 'source_types')) { | |
| 48 | - self::$source_types = array_merge(self::$source_types, $integration::$source_types); | |
| 49 | - } | |
| 50 | - // Add prefix and label from all integrations | |
| 51 | - if (property_exists($integration, 'source_type_prefix') && property_exists($integration, 'label')) { | |
| 52 | - self::$source_labels[$integration::$source_type_prefix] = $integration::$label; | |
| 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; |
| @@ -157,19 +199,29 @@ | ||
| 157 | 199 | } |
| 158 | 200 | |
| 159 | 201 | /** |
| 160 | 202 | * Clear all meta |
| 203 | + * | |
| 204 | + * @param bool $flush_cache Whether to flush the plugin object cache after each table clear. | |
| 161 | 205 | */ |
| 162 | - public static function clear_all_meta() { | |
| 206 | + public static function clear_all_meta($flush_cache = true) { | |
| 163 | 207 | if (!empty(self::$source_types)) { |
| 164 | 208 | foreach (self::$source_types as $source_type => $source_type_data) { |
| 165 | 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 | + | |
| 166 | 218 | switch($table) { |
| 167 | - case 'posts': | |
| 168 | - Utils::clear_all_meta(false, 'postmeta'); | |
| 219 | + case 'posts': | |
| 220 | + Utils::clear_all_meta(false, 'postmeta', $flush_cache); | |
| 169 | 221 | break; |
| 170 | 222 | case 'users': |
| 171 | - Utils::clear_all_meta(false, 'usermeta'); | |
| 223 | + Utils::clear_all_meta(false, 'usermeta', $flush_cache); | |
| 172 | 224 | break; |
| 173 | 225 | default: null; |
| 174 | 226 | } |
| 175 | 227 | } |