@@ -179,7 +179,7 @@ public function add_for_page_template( $display, $meta_box ) {
179179 public function show () {
180180 global $ post ;
181181 // Use nonce for verification.
182- echo '<input type="hidden" name="wp_meta_box_nonce" value=" ' , esc_attr ( wp_create_nonce ( basename ( __FILE__ ) ) ), '" /> ' ;
182+ echo '<input type="hidden" name="wp_meta_box_nonce" value=" ' , esc_attr ( wp_create_nonce ( ' bsf_meta_box_nonce_action ' ) ), '" /> ' ;
183183 echo '<table class="form-table bsf_metabox"> ' ;
184184 foreach ( $ this ->_meta_box ['fields ' ] as $ field ) {
185185 // Set up blank or default values for empty ones.
@@ -452,7 +452,7 @@ public function show() {
452452 */
453453 public function save ( $ post_id ) {
454454 // verify nonce.
455- if ( ! isset ( $ _POST ['wp_meta_box_nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _POST ['wp_meta_box_nonce ' ] ) ), basename ( __FILE__ ) ) ) {
455+ if ( ! isset ( $ _POST ['wp_meta_box_nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _POST ['wp_meta_box_nonce ' ] ) ), ' bsf_meta_box_nonce_action ' ) ) {
456456 return $ post_id ;
457457 }
458458 // check autosave.
@@ -555,8 +555,8 @@ function bsf_scripts( $hook ) {
555555 'bsf-scripts ' ,
556556 'bsf_ajax_data ' ,
557557 array (
558- 'ajax_nonce ' => wp_create_nonce ( 'ajax_nonce ' ),
559- 'post_id ' => get_the_ID (),
558+ 'bsf_meta_box_ajax_nonce ' => wp_create_nonce ( 'bsf_meta_box_ajax_nonce ' ),
559+ 'post_id ' => get_the_ID (),
560560 )
561561 );
562562 wp_enqueue_script ( 'bsf-timepicker ' );
@@ -571,7 +571,7 @@ function bsf_scripts( $hook ) {
571571 */
572572function bsf_editor_footer_scripts () { ?>
573573 <?php
574- if ( isset ( $ _GET ['bsf_force_send ' ] ) && isset ( $ _GET ['bsf_file_upload_nonce ' ] ) && wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _GET ['bsf_file_upload_nonce ' ] ) ), 'ajax_nonce ' ) && 'true ' == sanitize_text_field ( wp_unslash ( $ _GET ['bsf_force_send ' ] ) ) ) {
574+ if ( isset ( $ _GET ['bsf_force_send ' ] ) && isset ( $ _GET ['bsf_file_upload_nonce ' ] ) && wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _GET ['bsf_file_upload_nonce ' ] ) ), 'bsf_meta_box_ajax_nonce ' ) && 'true ' == sanitize_text_field ( wp_unslash ( $ _GET ['bsf_force_send ' ] ) ) ) {
575575 $ label = sanitize_text_field ( wp_unslash ( $ _GET ['bsf_send_label ' ] ) );
576576 if ( empty ( $ label ) ) {
577577 $ label = 'Select File ' ;
@@ -595,7 +595,7 @@ function bsf_editor_footer_scripts() { ?>
595595 */
596596function bsf_force_send ( $ args ) {
597597
598- if ( ! isset ( $ _GET ['bsf_file_upload_nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _GET ['bsf_file_upload_nonce ' ] ) ), 'ajax_nonce ' ) ) {
598+ if ( ! isset ( $ _GET ['bsf_file_upload_nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _GET ['bsf_file_upload_nonce ' ] ) ), 'bsf_meta_box_ajax_nonce ' ) ) {
599599 return $ args ;
600600 }
601601 // if the Gallery tab is opened from a custom meta box field, add Insert Into Post button.
@@ -644,15 +644,15 @@ function cmbGetParameterByNameInline(name) {
644644 */
645645function bsf_oembed_ajax_results () {
646646 // verify our nonce.
647- if ( ! ( isset ( $ _REQUEST ['bsf_ajax_nonce ' ], $ _REQUEST ['oembed_url ' ] ) && wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _REQUEST ['bsf_ajax_nonce ' ] ) ), 'ajax_nonce ' ) ) ) {
648- die ( );
647+ if ( ! ( isset ( $ _REQUEST ['bsf_ajax_nonce ' ], $ _REQUEST ['oembed_url ' ] ) && wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _REQUEST ['bsf_ajax_nonce ' ] ) ), 'bsf_meta_box_ajax_nonce ' ) ) ) {
648+ wp_send_json_error ( __ ( ' Security check failed. ' , ' rich-snippets ' ), 403 );
649649 }
650650 // verify capability.
651651 if ( ! current_user_can ( 'edit_posts ' ) ) {
652- die ( );
652+ wp_send_json_error ( __ ( ' Unauthorized access. ' , ' rich-snippets ' ), 403 );
653653 }
654654 // sanitize our search string.
655- $ oembed_string = sanitize_text_field ( $ _REQUEST ['oembed_url ' ] );
655+ $ oembed_string = sanitize_text_field ( wp_unslash ( $ _REQUEST ['oembed_url ' ] ) );
656656 if ( empty ( $ oembed_string ) ) {
657657 $ return = '<p class="ui-state-error-text"> ' . __ ( 'Please Try Again ' , 'rich-snippets ' ) . '</p> ' ;
658658 $ found = 'not found ' ;
@@ -669,7 +669,8 @@ function bsf_oembed_ajax_results() {
669669 $ fallback = $ wp_embed ->maybe_make_link ( $ oembed_url );
670670 if ( $ check_embed && $ check_embed != $ fallback ) {
671671 // Embed data.
672- $ return = '<div class="embed_status"> ' . $ check_embed . '<a href="#" class="bsf_remove_file_button" rel=" ' . esc_attr ( sanitize_text_field ( wp_unslash ( $ _REQUEST ['field_id ' ] ) ) ) . '"> ' . __ ( 'Remove Embed ' , 'rich-snippets ' ) . '</a></div> ' ;
672+ $ field_id = isset ( $ _REQUEST ['field_id ' ] ) ? sanitize_text_field ( wp_unslash ( $ _REQUEST ['field_id ' ] ) ) : '' ;
673+ $ return = '<div class="embed_status"> ' . $ check_embed . '<a href="#" class="bsf_remove_file_button" rel=" ' . esc_attr ( $ field_id ) . '"> ' . __ ( 'Remove Embed ' , 'rich-snippets ' ) . '</a></div> ' ;
673674 // set our response id.
674675 $ found = 'found ' ;
675676 } else {
@@ -687,7 +688,7 @@ function bsf_oembed_ajax_results() {
687688 'id ' => $ found ,
688689 )
689690 );
690- die ();
691+ wp_die ();
691692}
692693// End. That's it, folks! //.
693694?>
0 commit comments