array( 'type' => 'string', 'description' => __( 'Exact form title.', 'acrossai-abilities-manager' ), ), 'hash' => array( 'type' => 'string', 'description' => __( 'Form hash, as it appears in the shortcode.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'form' => array( 'type' => array( 'object', 'null' ) ), ); } protected function required_input(): array { return array(); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true, ); } protected function run( array $input ) { $title = isset( $input['title'] ) ? sanitize_text_field( (string) $input['title'] ) : ''; $hash = isset( $input['hash'] ) ? sanitize_text_field( (string) $input['hash'] ) : ''; if ( '' === $title && '' === $hash ) { return new WP_Error( 'invalid_input', __( 'Provide either a title or a hash.', 'acrossai-abilities-manager' ) ); } $found = null; foreach ( Form_Repository::list_all( '', 500, 0 ) as $summary ) { if ( ( '' !== $title && $summary['title'] === $title ) || ( '' !== $hash && 0 === strpos( $summary['hash'], $hash ) ) ) { $found = $summary; break; } } if ( null === $found ) { return array( 'form' => null, 'message' => __( 'No form matched.', 'acrossai-abilities-manager' ), ); } return array( 'form' => $found, 'message' => sprintf( /* translators: 1: form title, 2: form id */ __( 'Found "%1$s" (id %2$d).', 'acrossai-abilities-manager' ), $found['title'], $found['form_id'] ), ); } }