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 ) {
689689 *
690690 * @param string $nonce The nonce to check.
691691 * @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.
692693 * @return boolean
693694 */
694- function acf_verify_ajax ( $ nonce = '' , $ action = '' ) {
695+ function acf_verify_ajax ( $ nonce = '' , $ action = '' , $ action_is_field = false ) {
696+
695697 // Bail early if we don't have a nonce to check.
696698 if ( empty ( $ nonce ) && empty ( $ _REQUEST ['nonce ' ] ) ) {
697699 return false ;
698700 }
699701
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+
700717 $ nonce_to_check = ! empty ( $ nonce ) ? $ nonce : $ _REQUEST ['nonce ' ]; // phpcs:ignore WordPress.Security -- We're verifying a nonce here.
701718 $ nonce_action = ! empty ( $ action ) ? $ action : 'acf_nonce ' ;
702719
Original file line number Diff line number Diff line change @@ -1058,7 +1058,7 @@ public function ajax_get_rows() {
10581058 )
10591059 );
10601060
1061- if ( ! acf_verify_ajax ( $ args ['nonce ' ], $ args ['field_key ' ] ) ) {
1061+ if ( ! acf_verify_ajax ( $ args ['nonce ' ], $ args ['field_key ' ], true ) ) {
10621062 $ error = array ( 'error ' => __ ( 'Invalid nonce. ' , 'secure-custom-fields ' ) );
10631063 wp_send_json_error ( $ error , 401 );
10641064 }
You can’t perform that action at this time.
0 commit comments