ACF_UI_Options_Page::ajax_validate_values
Validates options page values before allowing save from the global $_POST object. Errors are added to the form using acf_add_internal_post_type_validation_error().
Метод класса: ACF_UI_Options_Page{}
Хуки из метода
Возвращает
true|false. validity status
Использование
$ACF_UI_Options_Page = new ACF_UI_Options_Page(); $ACF_UI_Options_Page->ajax_validate_values();
Список изменений
| С версии 6.2 | Введена. |
Код ACF_UI_Options_Page::ajax_validate_values() ACF UI Options Page::ajax validate values ACF 6.4.2
public function ajax_validate_values() {
if ( empty( $_POST['acf_ui_options_page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified elsewhere.
return false;
}
$to_validate = acf_sanitize_request_args( wp_unslash( $_POST['acf_ui_options_page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified elsewhere.
$post_id = acf_request_arg( 'post_id' );
$valid = true;
$menu_slug = (string) $to_validate['menu_slug'];
if ( preg_match( '/^[a-z0-9_-]*$/', $menu_slug ) !== 1 ) {
$valid = false;
acf_add_internal_post_type_validation_error( 'menu_slug', __( 'The menu slug must only contain lower case alphanumeric characters, underscores or dashes.', 'acf' ) );
}
// Check for duplicate menu_slug.
$options_pages = acf_get_options_pages();
$options_pages = is_array( $options_pages ) ? $options_pages : array();
$duplicates = array_filter(
$options_pages,
function ( $options_page ) use ( $post_id, $menu_slug ) {
// Current post is not a duplicate.
if ( isset( $options_page['ID'] ) && (int) $post_id === (int) $options_page['ID'] ) {
return false;
}
// Menu slugs match, could be a duplicate.
if ( $menu_slug === $options_page['menu_slug'] ) {
// Unless the matching slug is a parent page redirecting to the child page.
if ( isset( $options_page['_menu_slug'] ) && $options_page['_menu_slug'] !== $menu_slug ) {
return false;
}
return true;
}
return false;
}
);
if ( ! empty( $duplicates ) ) {
$valid = false;
acf_add_internal_post_type_validation_error(
'menu_slug',
__( 'This Menu Slug is already in use by another ACF Options Page.', 'acf' ),
'acf-ui-options-page'
);
}
return apply_filters( "acf/{$this->hook_name}/ajax_validate_values", $valid, $_POST['acf_ui_options_page'] ); // phpcs:ignore WordPress.Security -- Raw input send to hook for validation.
}