@@ -234,9 +234,9 @@ public function action_get_prebuilt_layouts() {
234234 // Get any layouts that the current user could edit.
235235 header ( 'content-type: application/json ' );
236236
237- $ type = ! empty ( $ _REQUEST ['type ' ] ) ? $ _REQUEST ['type ' ] : 'directory-siteorigin ' ;
238- $ search = ! empty ( $ _REQUEST ['search ' ] ) ? trim ( strtolower ( $ _REQUEST ['search ' ] ) ) : '' ;
239- $ page_num = ! empty ( $ _REQUEST ['page ' ] ) ? ( int ) $ _REQUEST ['page ' ] : 1 ;
237+ $ type = ! empty ( $ _REQUEST ['type ' ] ) ? sanitize_key ( $ _REQUEST ['type ' ] ) : 'directory-siteorigin ' ;
238+ $ search = ! empty ( $ _REQUEST ['search ' ] ) ? sanitize_text_field ( wp_unslash ( $ _REQUEST ['search ' ] ) ) : '' ;
239+ $ page_num = ! empty ( $ _REQUEST ['page ' ] ) ? intval ( $ _REQUEST ['page ' ] ) : 1 ;
240240
241241 $ return = array (
242242 'title ' => '' ,
@@ -426,11 +426,14 @@ public function decode_panels_data( $data, $file = null ) {
426426 * Ajax handler to get an individual prebuilt layout
427427 */
428428 public function action_get_prebuilt_layout () {
429- if ( empty ( $ _REQUEST ['type ' ] ) ) {
429+ $ type = isset ( $ _REQUEST ['type ' ] ) ? sanitize_key ( $ _REQUEST ['type ' ] ) : '' ;
430+ $ layout_id = isset ( $ _REQUEST ['lid ' ] ) ? sanitize_text_field ( wp_unslash ( $ _REQUEST ['lid ' ] ) ) : '' ;
431+
432+ if ( empty ( $ type ) ) {
430433 wp_die ();
431434 }
432435
433- if ( ! isset ( $ _REQUEST [ ' lid ' ] ) ) {
436+ if ( empty ( $ layout_id ) ) {
434437 wp_die ();
435438 }
436439
@@ -442,20 +445,20 @@ public function action_get_prebuilt_layout() {
442445 $ panels_data = array ();
443446 $ raw_panels_data = false ;
444447
445- if ( $ _REQUEST [ ' type ' ] == 'prebuilt ' ) {
448+ if ( $ type == 'prebuilt ' ) {
446449 $ layouts = apply_filters ( 'siteorigin_panels_prebuilt_layouts ' , array () );
447450
448451 if (
449- ! is_numeric ( $ _REQUEST [ ' lid ' ] ) &&
450- empty ( $ layouts [ $ _REQUEST [ ' lid ' ] ] )
452+ ! is_numeric ( $ layout_id ) &&
453+ empty ( $ layouts [ $ layout_id ] )
451454 ) {
452455 wp_send_json_error ( array (
453456 'error ' => true ,
454457 'message ' => __ ( 'Missing layout ID or no such layout exists ' , 'siteorigin-panels ' ),
455458 ) );
456459 }
457460
458- $ layout = $ layouts [ $ _REQUEST [ ' lid ' ] ];
461+ $ layout = $ layouts [ $ layout_id ];
459462
460463 // Fix the format of this layout
461464 if ( ! empty ( $ layout [ 'filename ' ] ) ) {
@@ -470,7 +473,7 @@ public function action_get_prebuilt_layout() {
470473 }
471474
472475 // A theme or plugin could use this to change the data in the layout
473- $ panels_data = apply_filters ( 'siteorigin_panels_prebuilt_layout ' , $ layout , $ _REQUEST [ ' lid ' ] );
476+ $ panels_data = apply_filters ( 'siteorigin_panels_prebuilt_layout ' , $ layout , $ layout_id );
474477
475478 // Remove all the layout specific attributes
476479 if ( isset ( $ panels_data ['name ' ] ) ) {
@@ -486,14 +489,14 @@ public function action_get_prebuilt_layout() {
486489 }
487490
488491 $ raw_panels_data = true ;
489- } elseif ( substr ( $ _REQUEST [ ' type ' ] , 0 , 10 ) == 'directory- ' ) {
490- $ directory_id = str_replace ( 'directory- ' , '' , $ _REQUEST [ ' type ' ] );
492+ } elseif ( substr ( $ type , 0 , 10 ) == 'directory- ' ) {
493+ $ directory_id = str_replace ( 'directory- ' , '' , $ type );
491494
492495 $ directories = $ this ->get_directories ();
493496 $ directory = ! empty ( $ directories [ $ directory_id ] ) ? $ directories [ $ directory_id ] : false ;
494497
495498 if ( ! empty ( $ directory ) ) {
496- $ url = $ directory [ 'url ' ] . 'layout/ ' . urlencode ( $ _REQUEST [ ' lid ' ] ) . '/?action=download ' ;
499+ $ url = $ directory [ 'url ' ] . 'layout/ ' . urlencode ( $ layout_id ) . '/?action=download ' ;
497500
498501 if ( ! empty ( $ directory [ 'args ' ] ) && is_array ( $ directory [ 'args ' ] ) ) {
499502 $ url = add_query_arg ( $ directory [ 'args ' ], $ url );
@@ -512,8 +515,8 @@ public function action_get_prebuilt_layout() {
512515 }
513516 }
514517 $ raw_panels_data = true ;
515- } elseif ( current_user_can ( 'edit_post ' , $ _REQUEST [ ' lid ' ] ) ) {
516- $ panels_data = get_post_meta ( $ _REQUEST [ ' lid ' ] , 'panels_data ' , true );
518+ } elseif ( current_user_can ( 'edit_post ' , $ layout_id ) ) {
519+ $ panels_data = get_post_meta ( $ layout_id , 'panels_data ' , true );
517520
518521 // Clear id and timestamp for SO widgets to prevent 'newer content version' notification in widget forms.
519522 foreach ( $ panels_data ['widgets ' ] as &$ widget ) {
0 commit comments