@@ -56,13 +56,9 @@ public function get_posts( \WP_REST_Request $request ) {
5656 }
5757
5858 $ page_number = absint ( $ request ['page_number ' ] );
59- if ( $ page_number > 100 ) {
60- return new \WP_REST_Response ( '' );
61- }
62-
63- $ query_args = $ request ->get_body ();
64- $ args = json_decode ( $ query_args , true );
65- $ per_page = get_option ( 'posts_per_page ' );
59+ $ query_args = $ request ->get_body ();
60+ $ args = json_decode ( $ query_args , true );
61+ $ per_page = get_option ( 'posts_per_page ' );
6662 if ( $ per_page > 100 ) {
6763 $ per_page = 100 ;
6864 }
@@ -344,10 +340,11 @@ private function sanitize_infinite_scroll_query_args( $args ) {
344340 $ sanitized ['s ' ] = sanitize_text_field ( $ sanitized ['s ' ] );
345341 }
346342 if ( isset ( $ sanitized ['order ' ] ) ) {
347- $ sanitized ['order ' ] = in_array ( strtoupper ( $ sanitized ['order ' ] ), array ( 'ASC ' , 'DESC ' ), true ) ? $ sanitized ['order ' ] : 'DESC ' ;
343+ $ order_upper = is_string ( $ sanitized ['order ' ] ) ? strtoupper ( $ sanitized ['order ' ] ) : '' ;
344+ $ sanitized ['order ' ] = in_array ( $ order_upper , array ( 'ASC ' , 'DESC ' ), true ) ? $ order_upper : 'DESC ' ;
348345 }
349346 if ( isset ( $ sanitized ['orderby ' ] ) ) {
350- $ safe_orderby = array ( 'date ' , 'title ' , 'author ' , 'modified ' , 'comment_count ' , ' rand ' );
347+ $ safe_orderby = array ( 'date ' , 'title ' , 'author ' , 'modified ' , 'comment_count ' );
351348 $ sanitized ['orderby ' ] = in_array ( $ sanitized ['orderby ' ], $ safe_orderby , true ) ? $ sanitized ['orderby ' ] : 'date ' ;
352349 }
353350 if ( isset ( $ sanitized ['author ' ] ) ) {
@@ -366,7 +363,7 @@ private function sanitize_infinite_scroll_query_args( $args ) {
366363 $ sanitized ['day ' ] = absint ( $ sanitized ['day ' ] );
367364 }
368365
369- $ post_type = ! empty ( $ args ['post_type ' ] ) ? $ args ['post_type ' ] : 'post ' ;
366+ $ post_type = ( ! empty ( $ args ['post_type ' ] ) && is_string ( $ args [ ' post_type ' ] ) ) ? sanitize_key ( $ args ['post_type ' ] ) : 'post ' ;
370367 $ post_type_obj = get_post_type_object ( $ post_type );
371368
372369 // Only allow if post type exists and is publicly queryable.
0 commit comments