$ids List of identifiers. * * @return string Parenthesised list of integers, or empty string. */ public static function in_clause_int( array $ids ): string { $cleaned = array(); foreach ( $ids as $id ) { $id = (int) $id; if ( $id > 0 ) { $cleaned[] = $id; } } if ( array() === $cleaned ) { return ''; } return '(' . implode( ',', $cleaned ) . ')'; } /** * Builds a parenthesised IN clause from a list of strings, escaped via $wpdb->prepare. * * @since 1.0.0 * * @param \wpdb $wpdb WordPress database instance. * @param array $values Values to escape and join. * * @return string Parenthesised list of quoted strings, or empty string. */ public static function in_clause_string( \wpdb $wpdb, array $values ): string { $cleaned = array(); foreach ( $values as $value ) { $value = (string) $value; if ( '' !== $value ) { $cleaned[] = $value; } } if ( array() === $cleaned ) { return ''; } $placeholders = implode( ',', array_fill( 0, count( $cleaned ), '%s' ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Placeholders constructed locally; values pass through prepare(). $prepared = $wpdb->prepare( $placeholders, $cleaned ); return '(' . $prepared . ')'; } /** * Returns the standard list of "public-ish" post statuses to scan. * * Excludes `trash`, `auto-draft`, and `inherit`. Reasonable default for * link reports — most callers want to see anything that's published or * actively being worked on, but not posts in the trash. * * @since 1.0.0 * * @return array Status slugs. */ public static function default_post_statuses(): array { return array( 'publish', 'pending', 'draft', 'future', 'private' ); } /** * Coerces a list of mixed-type IDs to a clean list of positive integers. * * Drops zero, negative, and non-numeric entries. Preserves order and * does not deduplicate (callers who want unique IDs can `array_unique` * the result). * * @since 1.0.0 * * @param array $ids Raw ID list. * * @return array Sanitised list of positive integers. */ public static function sanitise_int_ids( array $ids ): array { $out = array(); foreach ( $ids as $id ) { $id = (int) $id; if ( $id > 0 ) { $out[] = $id; } } return $out; } }