array( 'type' => 'string', 'description' => __( 'URL or site-relative path to test. Only the path is matched, as Rank Math matches on paths.', 'acrossai-abilities-manager' ), ), 'active_only' => array( 'type' => 'boolean', 'default' => true, 'description' => __( 'Restrict to active rules. Set false to see inactive or trashed rules that would match if enabled.', 'acrossai-abilities-manager' ), ), 'limit' => array( 'type' => 'integer', 'default' => 20, 'minimum' => 1, 'maximum' => 100, 'description' => __( 'Maximum matches to return.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'url' => array( 'type' => 'string' ), 'path' => array( 'type' => 'string' ), 'matches' => array( 'type' => 'array' ), 'count' => array( 'type' => 'integer' ), 'scanned' => array( 'type' => 'integer' ), ); } protected function required_input(): array { return array( 'url' ); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $url = isset( $input['url'] ) ? trim( (string) $input['url'] ) : ''; if ( '' === $url ) { return new WP_Error( 'invalid_input', __( 'url is required.', 'acrossai-abilities-manager' ) ); } $result = Redirections_Repository::find( $url, array_key_exists( 'active_only', $input ) ? (bool) $input['active_only'] : true, isset( $input['limit'] ) ? max( 1, min( 100, (int) $input['limit'] ) ) : 20 ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = 0 === $result['count'] ? sprintf( /* translators: %s: path tested */ __( 'No redirection matches "%s".', 'acrossai-abilities-manager' ), $result['path'] ) : sprintf( /* translators: 1: number of matches, 2: path tested */ _n( '%1$d redirection matches "%2$s".', '%1$d redirections match "%2$s".', $result['count'], 'acrossai-abilities-manager' ), $result['count'], $result['path'] ); return $result; } }