id = 'thinkrank/get-performance-data'; $this->label = __( 'Get Performance Data', 'thinkrank' ); $this->description = __( 'Retrieve the site Core Web Vitals / performance snapshot (LCP, INP, CLS, FCP), performance score and grade, and SEO correlation. Requires a connected Google account for real data; otherwise returns an empty snapshot with a not-connected marker. get-integrations-status reports whether that account is connected.', 'thinkrank' ); } /** * {@inheritDoc} * * @return array */ public function get_annotations() { return [ 'readonly' => true, 'destructive' => false, 'idempotent' => true, 'priority' => 1.0, 'openWorldHint' => false, ]; } /** * {@inheritDoc} * * @return array */ public function get_input_schema() { return [ 'type' => 'object', 'additionalProperties' => false, 'properties' => [ 'device_type' => [ 'type' => 'string', 'description' => __( 'The device profile to report.', 'thinkrank' ), 'enum' => [ 'mobile', 'desktop' ], 'default' => 'mobile', ], ], ]; } /** * {@inheritDoc} * * @return array */ public function get_output_schema() { return [ 'type' => 'object', 'additionalProperties' => true, 'properties' => [ 'success' => [ 'type' => 'boolean' ], 'data' => [ 'type' => 'object', 'additionalProperties' => true, ], 'message' => [ 'type' => 'string' ], ], ]; } /** * Execute ability. * * @param array $input Ability input payload. * @return array|\WP_Error */ public function execute( $input ) { $device_type = isset( $input['device_type'] ) ? sanitize_key( (string) $input['device_type'] ) : 'mobile'; if ( ! in_array( $device_type, [ 'mobile', 'desktop' ], true ) ) { $device_type = 'mobile'; } try { $manager = new Performance_Monitoring_Manager(); return $manager->get_performance_snapshot( $device_type ); } catch ( \Throwable $e ) { return new \WP_Error( 'thinkrank_performance_data_failed', $e->getMessage(), [ 'status' => 500 ] ); } } }