@@ -1902,17 +1902,20 @@ private static function should_active_pay_button( $order, $show_pay_button ) {
19021902 * Retrieves statements for a specific user.
19031903 *
19041904 * @since 3.5.0
1905+ * @since 4.0.0 Added $order_by and $order option.
19051906 *
1906- * @param string $post_type_in_clause SQL clause to filter the course post types.
1907- * @param string $course_query SQL query string to further filter the courses .
1908- * @param string $date_query SQL query string to filter by date range.
1909- * @param int $user_id The user ID for which the statements are being retrieved.
1910- * @param int $offset The offset for pagination.
1911- * @param int $limit The number of rows to return.
1907+ * @param string $post_type_in_clause Prepared SQL IN clause containing allowed course post types.
1908+ * @param string $course_query Optional SQL fragment to filter by course ID.
1909+ * @param string $date_query Optional SQL fragment to filter by statement date.
1910+ * @param int $user_id User (instructor) ID.
1911+ * @param int $offset Number of records to skip (pagination offset).
1912+ * @param int $limit Maximum number of records to return.
1913+ * @param string $order_by Column name to order results by.
1914+ * @param string $order Sort direction. Accepts 'ASC' or 'DESC'.
19121915 *
19131916 * @return array
19141917 */
1915- public function get_statements ( $ post_type_in_clause , $ course_query , $ date_query , $ user_id , $ offset , $ limit ): array {
1918+ public function get_statements ( $ post_type_in_clause , $ course_query , $ date_query , $ user_id , $ offset , $ limit, $ order_by , $ order ): array {
19161919 global $ wpdb ;
19171920
19181921 //phpcs:disable
@@ -1936,9 +1939,8 @@ public function get_statements( $post_type_in_clause, $course_query, $date_query
19361939 WHERE statements.user_id = %d
19371940 {$ course_query }
19381941 {$ date_query }
1939- ORDER BY statements.created_at DESC
1940- LIMIT %d, %d
1941- " ,
1942+ ORDER BY {$ order_by } {$ order }
1943+ LIMIT %d, %d " ,
19421944 $ user_id ,
19431945 $ offset ,
19441946 $ limit
@@ -1953,8 +1955,7 @@ public function get_statements( $post_type_in_clause, $course_query, $date_query
19531955 AND course.post_type IN ( {$ post_type_in_clause })
19541956 WHERE statements.user_id = %d
19551957 {$ course_query }
1956- {$ date_query }
1957- " ,
1958+ {$ date_query }" ,
19581959 $ user_id
19591960 )
19601961 );
0 commit comments