Skip to content

Commit 26c20bb

Browse files
committed
fix: improve album ID handling in search query for better SQL preparation
1 parent a94b17f commit 26c20bb

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

app/main/controllers/template/rtmedia-filters.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ function rtmedia_search_fillter_where_query( $where, $table_name ) {
772772
if ( ! empty( $search_by ) ) {
773773

774774
if ( ! empty( $rtmedia_current_album ) ) {
775-
$where .= $wpdb->prepare( " $table_name.album_id = %s AND ", $rtmedia_current_album ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
775+
$where .= $wpdb->prepare( " $table_name.album_id = %d AND ", absint( $rtmedia_current_album ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
776776
}
777777

778778
if ( ! empty( $media_type ) && empty( $rtmedia_current_album ) ) {
@@ -798,7 +798,7 @@ function rtmedia_search_fillter_where_query( $where, $table_name ) {
798798
} else {
799799

800800
if ( ! empty( $rtmedia_current_album ) ) {
801-
$where .= $wpdb->prepare( " $table_name.album_id = %s AND ", $rtmedia_current_album ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
801+
$where .= $wpdb->prepare( " $table_name.album_id = %d AND ", absint( $rtmedia_current_album ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
802802
}
803803

804804
if ( ! empty( $media_type ) && empty( $rtmedia_current_album ) ) {
@@ -824,7 +824,7 @@ function rtmedia_search_fillter_where_query( $where, $table_name ) {
824824

825825
// Reset data for album's media.
826826
if ( '' !== $search && ! empty( $rtmedia_current_album ) ) {
827-
$where .= $wpdb->prepare( " AND $table_name.album_id = %s ", $rtmedia_current_album ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
827+
$where .= $wpdb->prepare( " AND $table_name.album_id = %d ", absint( $rtmedia_current_album ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
828828
}
829829

830830
// Reset data for particular media type.
@@ -873,10 +873,13 @@ function rtmedia_search_fillter_join_query( $join, $table_name ) {
873873
$request_uri = rtm_get_server_var( 'REQUEST_URI', 'FILTER_SANITIZE_URL' );
874874
$request_url = explode( '/', $request_uri );
875875
if ( ! empty( $search_by ) && 'attribute' === $search_by && ! in_array( 'attribute', $request_url, true ) ) {
876-
$join .= " INNER JOIN $posts_table ON ( $posts_table.ID = $table_name.media_id AND $posts_table.post_type = '$media_type' )
877-
INNER JOIN $terms_table ON ( $terms_table.slug IN (" . $wpdb->prepare( '%s', $search ) . ") )
876+
$join .= $wpdb->prepare(
877+
" INNER JOIN $posts_table ON ( $posts_table.ID = $table_name.media_id AND $posts_table.post_type = '$media_type' )
878+
INNER JOIN $terms_table ON ( $terms_table.slug IN (%s) )
878879
INNER JOIN $term_taxonomy_table ON ( $term_taxonomy_table.term_id = $terms_table.term_id )
879-
INNER JOIN $term_relationships_table ON ( $term_relationships_table.term_taxonomy_id = $term_taxonomy_table.term_taxonomy_id AND $term_relationships_table.object_id = $posts_table.ID ) ";
880+
INNER JOIN $term_relationships_table ON ( $term_relationships_table.term_taxonomy_id = $term_taxonomy_table.term_taxonomy_id AND $term_relationships_table.object_id = $posts_table.ID ) ",
881+
$search
882+
); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
880883
}
881884
}
882885
}

0 commit comments

Comments
 (0)