File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -689,14 +689,31 @@ function acf_verify_nonce( $value ) {
689
689
*
690
690
* @param string $nonce The nonce to check.
691
691
* @param string $action The action of the nonce.
692
+ * @param bool $action_is_field Whether the action is a field key or not. Defaults to false.
692
693
* @return boolean
693
694
*/
694
- function acf_verify_ajax ( $ nonce = '' , $ action = '' ) {
695
+ function acf_verify_ajax ( $ nonce = '' , $ action = '' , $ action_is_field = false ) {
696
+
695
697
// Bail early if we don't have a nonce to check.
696
698
if ( empty ( $ nonce ) && empty ( $ _REQUEST ['nonce ' ] ) ) {
697
699
return false ;
698
700
}
699
701
702
+ // Build the action if we're trying to validate a specific field nonce.
703
+ if ( $ action_is_field ) {
704
+ if ( ! acf_is_field_key ( $ action ) ) {
705
+ return false ;
706
+ }
707
+
708
+ $ field = acf_get_field ( $ action );
709
+
710
+ if ( empty ( $ field ['type ' ] ) ) {
711
+ return false ;
712
+ }
713
+
714
+ $ action = 'acf_field_ ' . $ field ['type ' ] . '_ ' . $ action ;
715
+ }
716
+
700
717
$ nonce_to_check = ! empty ( $ nonce ) ? $ nonce : $ _REQUEST ['nonce ' ]; // phpcs:ignore WordPress.Security -- We're verifying a nonce here.
701
718
$ nonce_action = ! empty ( $ action ) ? $ action : 'acf_nonce ' ;
702
719
Original file line number Diff line number Diff line change @@ -1058,7 +1058,7 @@ public function ajax_get_rows() {
1058
1058
)
1059
1059
);
1060
1060
1061
- if ( ! acf_verify_ajax ( $ args ['nonce ' ], $ args ['field_key ' ] ) ) {
1061
+ if ( ! acf_verify_ajax ( $ args ['nonce ' ], $ args ['field_key ' ], true ) ) {
1062
1062
$ error = array ( 'error ' => __ ( 'Invalid nonce. ' , 'secure-custom-fields ' ) );
1063
1063
wp_send_json_error ( $ error , 401 );
1064
1064
}
You can’t perform that action at this time.
0 commit comments