id = 'thinkrank/send-email-report-test'; $this->label = __( 'Send ThinkRank Test Email Report', 'thinkrank' ); $this->description = __( 'Send an immediate one-off test of the ThinkRank Email Report to the configured recipients using the current saved settings. Does not change the schedule. Fails if no recipients are configured. update-email-report-settings changes what it sends.', 'thinkrank' ); } /** * {@inheritDoc} * * @return array */ public function get_annotations() { return [ 'readonly' => false, 'destructive' => false, 'idempotent' => false, 'priority' => 2.0, 'openWorldHint' => false, ]; } /** * {@inheritDoc} * * @return array */ public function get_input_schema() { return [ 'type' => 'object', 'additionalProperties' => false, 'properties' => self::empty_properties(), ]; } /** * {@inheritDoc} * * @return array */ public function get_output_schema() { return [ 'type' => 'object', 'properties' => [ 'success' => [ 'type' => 'boolean' ], 'message' => [ 'type' => 'string' ], 'result' => [ 'type' => 'object', 'description' => __( 'Raw generator result (send status, error, or skip reason).', 'thinkrank' ), 'additionalProperties' => true, ], ], ]; } /** * Execute ability. * * @param array $input Ability input payload. * @return array|\WP_Error */ public function execute( $input ) { $manager = $this->resolve_manager(); if ( ! $manager instanceof Email_Report_Manager ) { return new \WP_Error( 'thinkrank_email_report_unavailable', __( 'Email Report Manager is unavailable.', 'thinkrank' ), [ 'status' => 500 ] ); } $result = $manager->generator()->generate_test(); $success = ! empty( $result['success'] ); if ( ! $success ) { $message = isset( $result['error'] ) && is_string( $result['error'] ) ? (string) $result['error'] : __( 'The test report could not be sent.', 'thinkrank' ); return new \WP_Error( 'thinkrank_email_report_test_send_failed', $message, [ 'status' => 400, 'result' => $result, ] ); } return [ 'success' => true, 'message' => __( 'Test email report sent.', 'thinkrank' ), 'result' => $result, ]; } /** * Resolve the shared Email_Report_Manager from the plugin container. * * @return Email_Report_Manager|null */ private function resolve_manager() { if ( ! function_exists( 'thinkrank' ) ) { return null; } $component = thinkrank()->get_component( 'email_report' ); return $component instanceof Email_Report_Manager ? $component : null; } }