| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | use YayMail\Abstracts\BaseController; |
| 6 | 6 | use YayMail\Models\AddonModel; |
| 7 | 7 | use YayMail\Models\SettingModel; |
| 8 | -use YayMail\Utils\Helpers; | |
| 9 | 8 | use YayMail\Utils\SingletonTrait; |
| 10 | 9 | |
| 11 | 10 | /** |
| 12 | 11 | * Settings Controller |
| @@ -73,83 +72,10 @@ | ||
| 73 | 72 | public function exec_deactivate_addon( \WP_REST_Request $request ) { |
| 74 | 73 | return $this->exec( [ $this, 'deactivate_addon' ], $request ); |
| 75 | 74 | } |
| 76 | 75 | |
| 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 ); | |
| 82 | - | |
| 83 | - return array_values( $data ); | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * Keep Addons REST list aligned with active YayMail Woo vs Yay WP Pro (same idea as addons_platform in localize). | |
| 88 | - * | |
| 89 | - * @param array<string, array<string, mixed>> $data Addon rows keyed by namespace. | |
| 90 | - * @return array<string, array<string, mixed>> | |
| 91 | - */ | |
| 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; | |
| 97 | - | |
| 98 | - return array_filter( | |
| 99 | - $data, | |
| 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 | |
| 106 | - } | |
| 107 | - } | |
| 108 | - ); | |
| 109 | - } | |
| 110 | - | |
| 111 | - /** | |
| 112 | - * Pin core Woo addons first; append all others in original order (WordPress-catalog addons follow). | |
| 113 | - * | |
| 114 | - * @param array<string, array<string, mixed>> $data Addon rows keyed by namespace. | |
| 115 | - * @return array<string, array<string, mixed>> | |
| 116 | - */ | |
| 117 | - private function reorder_addons_for_catalog( array $data ): array { | |
| 118 | - $pinned_keys = [ | |
| 119 | - 'YayMailAddonConditionalLogic', | |
| 120 | - 'YayMailAddonWcSubscription', | |
| 121 | - 'YayMailAddonYITHWishlist', | |
| 122 | - ]; | |
| 123 | - | |
| 124 | - $pinned_set = array_flip( $pinned_keys ); | |
| 125 | - | |
| 126 | - $head = []; | |
| 127 | - $wordpress = []; | |
| 128 | - $others = []; | |
| 129 | - | |
| 130 | - foreach ( $pinned_keys as $key ) { | |
| 131 | - if ( isset( $data[ $key ] ) ) { | |
| 132 | - $head[ $key ] = $data[ $key ]; | |
| 133 | - } | |
| 134 | - } | |
| 135 | - | |
| 136 | - foreach ( $data as $key => $addon ) { | |
| 137 | - if ( isset( $pinned_set[ $key ] ) ) { | |
| 138 | - continue; | |
| 139 | - } | |
| 140 | - | |
| 141 | - $categories = isset( $addon['categories'] ) && is_array( $addon['categories'] ) ? $addon['categories'] : []; | |
| 142 | - $is_wordpress = in_array( 'WordPress', $categories, true ); | |
| 143 | - | |
| 144 | - if ( $is_wordpress ) { | |
| 145 | - $wordpress[ $key ] = $addon; | |
| 146 | - } else { | |
| 147 | - $others[ $key ] = $addon; | |
| 148 | - } | |
| 149 | - } | |
| 150 | - | |
| 151 | - return $head + $wordpress + $others; | |
| 76 | + public function get_addons() { | |
| 77 | + return array_values( AddonModel::get_all() ); | |
| 152 | 78 | } |
| 153 | 79 | |
| 154 | 80 | public function activate_addon( \WP_REST_Request $request ) { |
| 155 | 81 | $addon = $request->get_param( 'addon' ); |