ACF_UI_Options_Page::get_options_page_args
Parses ACF options page settings and returns an array of args to be handled by acf_add_options_page().
Omits settings that line up with the defaults to reduce the size of the array passed to acf_add_options_page(), which might be exported.
Метод класса: ACF_UI_Options_Page{}
Хуки из метода
Возвращает
Массив.
Использование
$ACF_UI_Options_Page = new ACF_UI_Options_Page(); $ACF_UI_Options_Page->get_options_page_args( $post );
- $post(массив) (обязательный)
- The main ACF options page settings array.
Список изменений
| С версии 6.2 | Введена. |
Код ACF_UI_Options_Page::get_options_page_args() ACF UI Options Page::get options page args ACF 6.4.2
public function get_options_page_args( $post ) {
$args = array();
$defaults = $this->get_settings_array();
// UI-specific params that don't need to be passed in.
$ui_specific = array(
'key',
'title',
'active',
'menu_order',
'advanced_configuration',
'data_storage',
);
foreach ( $post as $setting => $value ) {
// Don't pass in UI specific or unknown settings.
if ( in_array( $setting, $ui_specific, true ) || ! array_key_exists( $setting, $defaults ) ) {
continue;
}
// Convert types.
$default_type = gettype( $defaults[ $setting ] );
if ( 'boolean' === $default_type ) {
$value = filter_var( $value, FILTER_VALIDATE_BOOLEAN );
}
// Escape HTML.
if ( in_array( $setting, array( 'page_title', 'menu_title' ), true ) ) {
$value = esc_html( $value );
}
// A `parent_slug` value of "none" is only used in the UI.
if ( 'parent_slug' === $setting && 'none' === $value ) {
continue;
}
// UI does not default redirect to child to true, but code does.
if ( 'redirect' === $setting && ! $value ) {
$args[ $setting ] = $value;
continue;
}
// Don't need to include if it's the same as a default.
if ( $value === $defaults[ $setting ] ) {
continue;
}
$args[ $setting ] = $value;
}
// Override the icon_url if the value was saved after the icon picker was added to ACF in 6.3.
if ( ! $this->value_was_saved_prior_to_icon_picker_field( $args ) ) {
if ( $args['menu_icon']['type'] === 'url' ) {
$args['icon_url'] = $args['menu_icon']['value'];
}
if ( $args['menu_icon']['type'] === 'media_library' ) {
$image_url = wp_get_attachment_image_url($args['menu_icon']['value']);
$args['icon_url'] = $image_url;
}
if ( $args['menu_icon']['type'] === 'dashicons' ) {
$args['icon_url'] = $args['menu_icon']['value'];
}
}
return apply_filters( 'acf/ui_options_page/registration_args', $args, $post );
}