allowed_providers; } /** * Get allowed statuses. * * @since 1.0.0 * * @return array List of allowed status names. */ public function get_allowed_statuses(): array { return $this->allowed_statuses; } /** * Check if a provider is allowed. * * @since 1.0.0 * * @param string $provider Provider name to check. * * @return bool True if provider is allowed, false otherwise. */ public function is_allowed_provider( string $provider ): bool { return in_array( $provider, $this->allowed_providers, true ); } /** * Check if a status is allowed. * * @since 1.0.0 * * @param string $status Status name to check. * * @return bool True if status is allowed, false otherwise. */ public function is_allowed_status( string $status ): bool { return in_array( $status, $this->allowed_statuses, true ); } /** * Normalize arguments for submissions queries. * * @since 1.0.0 * * @param array $args Raw query arguments. * * @return array Normalized arguments (status, provider, search, limit, offset, exclude_trash) with limit clamped to 1-200 and offset floored at 0. */ public function normalize_args( array $args ): array { $status = isset( $args['status'] ) ? sanitize_key( (string) $args['status'] ) : ''; $provider = isset( $args['provider'] ) ? sanitize_text_field( (string) $args['provider'] ) : ''; $search = isset( $args['search'] ) ? sanitize_text_field( (string) $args['search'] ) : ''; $limit = (int) ( $args['limit'] ?? 50 ); $offset = (int) ( $args['offset'] ?? 0 ); $exclude_trash = ! empty( $args['exclude_trash'] ); $limit = max( 1, min( 200, $limit ) ); $offset = max( 0, $offset ); return [ 'status' => $status, 'provider' => $provider, 'search' => $search, 'limit' => $limit, 'offset' => $offset, 'exclude_trash' => $exclude_trash, ]; } /** * Build parameterized WHERE clause for submissions queries. * * Returns a clause template with %s/%d placeholders and a separate values * array so callers can pass both into $wpdb->prepare() for proper escaping. * * @since 1.0.0 * @since 1.1.0 Returns array with 'clause' and 'values' keys instead of pre-interpolated string. * * @param array $args Query arguments. * * @return array{clause: string, values: array} SQL fragment with placeholders and corresponding values. */ public function build_where_clause( array $args ): array { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh $templates = []; $values = []; $status = isset( $args['status'] ) ? sanitize_key( (string) $args['status'] ) : ''; if ( $status !== '' ) { $templates[] = 'status = %s'; $values[] = $status; } if ( ! empty( $args['exclude_trash'] ) ) { $templates[] = 'status != %s'; $values[] = 'trash'; } $provider = isset( $args['provider'] ) ? sanitize_text_field( (string) $args['provider'] ) : ''; if ( $provider !== '' ) { $templates[] = 'provider = %s'; $values[] = $provider; } $search = isset( $args['search'] ) ? sanitize_text_field( (string) $args['search'] ) : ''; if ( $search !== '' ) { global $wpdb; $templates[] = 'form_data LIKE %s'; $values[] = '%' . $wpdb->esc_like( $search ) . '%'; } return [ 'clause' => $templates ? 'WHERE ' . implode( ' AND ', $templates ) : '', 'values' => $values, ]; } }