| @@ -1,19 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * AI Insights API endpoints. |
| 4 | 4 | * |
| 5 | - * Admin REST surface for the AI Insights screen (#248 P1 trio): | |
| 5 | + * Admin REST surface for the AI Insights screen (#248 P1): | |
| 6 | 6 | * |
| 7 | 7 | * GET /ai-insights/traffic — AI referral/crawler dashboard summary |
| 8 | - * GET /ai-insights/auto-ai — auto-optimization settings + last run | |
| 9 | - * POST /ai-insights/auto-ai — save auto-optimization settings | |
| 10 | 8 | * |
| 11 | - * Brand visibility used to live here too (`/ai-insights/brand*`). Those routes | |
| 12 | - * were removed in 1.30.0: the v2 rebuild moved the feature to | |
| 13 | - * `/thinkrank/v1/brand-visibility/*` with a queued runner, and the v1 routes | |
| 14 | - * outlived their only UI consumer while still being able to start a | |
| 15 | - * synchronous batch of paid AI probes in a single request (#301). | |
| 9 | + * Automatic AI metadata on publish, the other tab on this screen, is a | |
| 10 | + * ThinkRank Pro feature and registers its own routes there (#673). Brand | |
| 11 | + * Visibility used to live in this section too; its v1 routes here were removed | |
| 12 | + * in 1.30.0 (#301), and the feature itself was removed later. | |
| 16 | 13 | * |
| 17 | 14 | * @package ThinkRank |
| 18 | 15 | * @subpackage API |
| 19 | 16 | * @since 1.27.0 |
| @@ -22,11 +19,9 @@ | ||
| 22 | 19 | declare(strict_types=1); |
| 23 | 20 | |
| 24 | 21 | namespace ThinkRank\API; |
| 25 | 22 | |
| 26 | -use ThinkRank\Core\Settings; | |
| 27 | 23 | use ThinkRank\SEO\Ai_Traffic_Tracker; |
| 28 | -use ThinkRank\SEO\Auto_Ai_Optimizer; | |
| 29 | 24 | use WP_REST_Controller; |
| 30 | 25 | use WP_REST_Request; |
| 31 | 26 | use WP_REST_Response; |
| 32 | 27 | |
| @@ -35,9 +30,9 @@ | ||
| 35 | 30 | exit; |
| 36 | 31 | } |
| 37 | 32 | |
| 38 | 33 | /** |
| 39 | - * REST controller for AI traffic and auto AI settings. | |
| 34 | + * REST controller for AI traffic. | |
| 40 | 35 | */ |
| 41 | 36 | class Ai_Insights_Endpoint extends WP_REST_Controller { |
| 42 | 37 | |
| 43 | 38 | /** |
| @@ -73,42 +68,8 @@ | ||
| 73 | 68 | 'maximum' => 180, |
| 74 | 69 | ], |
| 75 | 70 | ], |
| 76 | 71 | ]); |
| 77 | - | |
| 78 | - register_rest_route($this->namespace, '/' . $this->rest_base . '/auto-ai', [ | |
| 79 | - [ | |
| 80 | - 'methods' => 'GET', | |
| 81 | - 'callback' => [$this, 'get_auto_ai'], | |
| 82 | - 'permission_callback' => [$this, 'check_admin_permissions'], | |
| 83 | - ], | |
| 84 | - [ | |
| 85 | - 'methods' => 'POST', | |
| 86 | - 'callback' => [$this, 'save_auto_ai'], | |
| 87 | - 'permission_callback' => [$this, 'check_admin_permissions'], | |
| 88 | - 'args' => [ | |
| 89 | - 'enabled' => [ | |
| 90 | - 'required' => false, | |
| 91 | - 'type' => 'boolean', | |
| 92 | - ], | |
| 93 | - 'post_types' => [ | |
| 94 | - 'required' => false, | |
| 95 | - 'type' => 'array', | |
| 96 | - 'items' => ['type' => 'string'], | |
| 97 | - 'sanitize_callback' => static function ($value) { | |
| 98 | - if (!is_array($value)) { | |
| 99 | - return []; | |
| 100 | - } | |
| 101 | - // Only real, public post types survive. | |
| 102 | - return array_values(array_filter( | |
| 103 | - array_map('sanitize_key', $value), | |
| 104 | - static fn($t) => post_type_exists($t) | |
| 105 | - )); | |
| 106 | - }, | |
| 107 | - ], | |
| 108 | - ], | |
| 109 | - ], | |
| 110 | - ]); | |
| 111 | 72 | } |
| 112 | 73 | |
| 113 | 74 | /** |
| 114 | 75 | * Admin permission gate (matches the other admin-only endpoints). |
| @@ -131,57 +92,6 @@ | ||
| 131 | 92 | return new WP_REST_Response([ |
| 132 | 93 | 'success' => true, |
| 133 | 94 | 'data' => $tracker->summary((int) $request->get_param('days')), |
| 134 | 95 | ], 200); |
| 135 | - } | |
| 136 | - | |
| 137 | - /** | |
| 138 | - * Auto AI settings + last run outcome. | |
| 139 | - * | |
| 140 | - * @return WP_REST_Response | |
| 141 | - */ | |
| 142 | - public function get_auto_ai(): WP_REST_Response { | |
| 143 | - $settings = Settings::instance(); | |
| 144 | - | |
| 145 | - return new WP_REST_Response([ | |
| 146 | - 'success' => true, | |
| 147 | - 'data' => [ | |
| 148 | - 'enabled' => (bool) $settings->get('auto_ai_meta_enabled', false), | |
| 149 | - 'post_types' => (array) $settings->get('auto_ai_meta_post_types', ['post']), | |
| 150 | - 'last_run' => get_option(Auto_Ai_Optimizer::LAST_RUN_OPTION, null), | |
| 151 | - // Pro-gated: the UI locks the toggle and shows the upsell. | |
| 152 | - 'available' => \ThinkRank\Core\Plan_Config::can('auto_ai_meta', 'ai_visibility'), | |
| 153 | - ], | |
| 154 | - ], 200); | |
| 155 | - } | |
| 156 | - | |
| 157 | - /** | |
| 158 | - * Save auto AI settings. | |
| 159 | - * | |
| 160 | - * @param WP_REST_Request $request Request. | |
| 161 | - * @return WP_REST_Response | |
| 162 | - */ | |
| 163 | - public function save_auto_ai(WP_REST_Request $request): WP_REST_Response { | |
| 164 | - $settings = Settings::instance(); | |
| 165 | - | |
| 166 | - if (null !== $request->get_param('enabled')) { | |
| 167 | - $enabled = rest_sanitize_boolean($request->get_param('enabled')); | |
| 168 | - | |
| 169 | - // Pro capability. Turning it OFF always works — a lapsed licence | |
| 170 | - // must never trap the setting in the on position. | |
| 171 | - if ($enabled && !\ThinkRank\Core\Plan_Config::can('auto_ai_meta', 'ai_visibility')) { | |
| 172 | - return new WP_REST_Response([ | |
| 173 | - 'success' => false, | |
| 174 | - 'message' => __('Automatic AI metadata is a ThinkRank Pro feature.', 'thinkrank'), | |
| 175 | - 'data' => ['requires_pro' => true], | |
| 176 | - ], 403); | |
| 177 | - } | |
| 178 | - | |
| 179 | - $settings->set('auto_ai_meta_enabled', $enabled); | |
| 180 | - } | |
| 181 | - if (null !== $request->get_param('post_types')) { | |
| 182 | - $settings->set('auto_ai_meta_post_types', (array) $request->get_param('post_types')); | |
| 183 | - } | |
| 184 | - | |
| 185 | - return $this->get_auto_ai(); | |
| 186 | 96 | } |
| 187 | 97 | } |