acf_verify_ajax()
Returns true if the current AJAX request is valid. It's action will also allow WPML to set the lang and avoid AJAX get_posts issues
Хуки из функции
Возвращает
true|false
.
Использование
acf_verify_ajax( $nonce, $action, $action_is_field );
- $nonce(строка)
- The nonce to check.
По умолчанию: '' - $action(строка)
- The action of the nonce.
По умолчанию: '' - $action_is_field(true|false)
- If the action is a field, modify the action to match validate the field type.
По умолчанию: false
Список изменений
С версии 5.2.3 | Введена. |
Код acf_verify_ajax() acf verify ajax ACF 6.4.2
function acf_verify_ajax( $nonce = '', $action = '', $action_is_field = false ) { // Bail early if we don't have a nonce to check. if ( empty( $nonce ) && empty( $_REQUEST['nonce'] ) ) { return false; } // Build the action if we're trying to validate a specific field nonce. if ( $action_is_field ) { if ( ! acf_is_field_key( $action ) ) { return false; } $field = acf_get_field( $action ); if ( empty( $field['type'] ) ) { return false; } $action = 'acf_field_' . $field['type'] . '_' . $action; } $nonce_to_check = ! empty( $nonce ) ? $nonce : $_REQUEST['nonce']; // phpcs:ignore WordPress.Security -- We're verifying a nonce here. $nonce_action = ! empty( $action ) ? $action : 'acf_nonce'; // Bail if nonce can't be verified. if ( ! wp_verify_nonce( sanitize_text_field( $nonce_to_check ), $nonce_action ) ) { return false; } // Action for 3rd party customization (WPML). do_action( 'acf/verify_ajax' ); return true; }