| @@ -73,12 +73,13 @@ | ||
| 73 | 73 | public function exec_deactivate_addon( \WP_REST_Request $request ) { |
| 74 | 74 | return $this->exec( [ $this, 'deactivate_addon' ], $request ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function get_addons() { | |
| 78 | - $data = AddonModel::get_all(); | |
| 79 | - $data = $this->filter_addons_by_platform( $data ); | |
| 80 | - $data = $this->reorder_addons_for_catalog( $data ); | |
| 77 | + public function get_addons( \WP_REST_Request $request ) { | |
| 78 | + $data = AddonModel::get_all(); | |
| 79 | + $platform = $request->get_param( 'platform' ); | |
| 80 | + $data = $this->filter_addons_by_platform( $data, $platform ); | |
| 81 | + $data = $this->reorder_addons_for_catalog( $data ); | |
| 81 | 82 | |
| 82 | 83 | return array_values( $data ); |
| 83 | 84 | } |
| 84 | 85 | |
| @@ -87,32 +88,23 @@ | ||
| 87 | 88 | * |
| 88 | 89 | * @param array<string, array<string, mixed>> $data Addon rows keyed by namespace. |
| 89 | 90 | * @return array<string, array<string, mixed>> |
| 90 | 91 | */ |
| 91 | - private function filter_addons_by_platform( array $data ): array { | |
| 92 | - $plugin_works = Helpers::get_plugin_work_info(); | |
| 92 | + private function filter_addons_by_platform( array $data, string $platform ): array { | |
| 93 | + // Unknown/absent platform falls through to the WordPress catalog, matching | |
| 94 | + // the prior exact-match behavior ( $platform === 'yaymail' ). | |
| 95 | + $platform_obj = '' !== $platform ? \YayMail\Platform\PlatformRegistry::get( $platform ) : null; | |
| 96 | + $is_yaymail = $platform_obj ? $platform_obj->is_woo_product() : false; | |
| 93 | 97 | |
| 94 | - $has_wc = $plugin_works['yaymail']; | |
| 95 | - $has_wp = $plugin_works['yay-wp-email-customizer']; | |
| 96 | - | |
| 97 | - if ( ( $has_wc && $has_wp ) || ( ! $has_wc && ! $has_wp ) ) { | |
| 98 | - return $data; | |
| 99 | - } | |
| 100 | - | |
| 101 | 98 | return array_filter( |
| 102 | 99 | $data, |
| 103 | - function ( $addon ) use ( $has_wc, $has_wp ) { | |
| 104 | - $categories = isset( $addon['categories'] ) && is_array( $addon['categories'] ) ? $addon['categories'] : []; | |
| 105 | - $has_wordpress_category = in_array( 'wordpress', $categories, true ); | |
| 106 | - | |
| 107 | - if ( $has_wc && ! $has_wp ) { | |
| 108 | - return ! $has_wordpress_category; | |
| 100 | + function ( $addon ) use ( $is_yaymail ) { | |
| 101 | + $categories = isset( $addon['categories'] ) && is_array( $addon['categories'] ) ? $addon['categories'] : []; | |
| 102 | + if ( $is_yaymail ) { | |
| 103 | + return ! in_array( 'wordpress', $categories, true ); //phpcs:ignore | |
| 104 | + } else { | |
| 105 | + return in_array( 'wordpress', $categories, true ); //phpcs:ignore | |
| 109 | 106 | } |
| 110 | - if ( $has_wp && ! $has_wc ) { | |
| 111 | - return $has_wordpress_category; | |
| 112 | - } | |
| 113 | - | |
| 114 | - return true; | |
| 115 | 107 | } |
| 116 | 108 | ); |
| 117 | 109 | } |
| 118 | 110 | |