ACF_Admin_UI_Options_Page::get_parent_page_choices │ public │ ACF 6.2

Iterates through the registered options pages and finds eligible parent pages.

Метод класса: ACF_Admin_UI_Options_Page{}

Хуков нет.

Возвращает

array.

Использование

$ACF_Admin_UI_Options_Page = new ACF_Admin_UI_Options_Page();
$ACF_Admin_UI_Options_Page->get_parent_page_choices( $post_id );
$post_id(int)
The post ID of a current ACF UI options page used to prevent selection of itself as a child.

Список изменений

С версии 6.2 Введена.

Код ACF_Admin_UI_Options_Page::get_parent_page_choices() ACF 6.8.8

public function get_parent_page_choices( int $post_id = 0 ) {
	global $menu;
	$acf_all_options_pages   = acf_get_options_pages();
	$acf_parent_page_choices = array( 'None' => array( 'none' => __( 'No Parent', 'acf' ) ) );
	$self_slug               = false;

	if ( is_array( $acf_all_options_pages ) ) {
		foreach ( $acf_all_options_pages as $options_page ) {
			// Can't assign to child pages.
			if ( ! empty( $options_page['parent_slug'] ) ) {
				continue;
			}

			// Can't be a child of itself.
			if ( isset( $options_page['ID'] ) && $post_id === $options_page['ID'] ) {
				$self_slug = $options_page['menu_slug'];
				continue;
			}

			$acf_parent_menu_slug = ! empty( $options_page['menu_slug'] ) ? $options_page['menu_slug'] : '';

			// ACF overrides the `menu_slug` of parent pages with one child so they redirect to the child.
			if ( ! empty( $options_page['_menu_slug'] ) ) {
				$acf_parent_menu_slug = $options_page['_menu_slug'];
			}

			$acf_parent_page_choices['acfOptionsPages'][ $acf_parent_menu_slug ] = ! empty( $options_page['page_title'] ) ? $options_page['page_title'] : $options_page['menu_slug'];
		}
	}

	foreach ( $menu as $item ) {
		if ( ! empty( $item[0] ) ) {
			$page_name      = $item[0];
			$markup         = '/<[^>]+>.*<\/[^>]+>/';
			$sanitized_name = preg_replace( $markup, '', $page_name );

			// Prevent options pages being parents of themselves.
			if ( ! empty( $item[2] ) && $item[2] === $self_slug ) {
				continue;
			}

			// If the current item is not an ACF-created options page, add it to the "Others" list.
			if ( empty( $acf_parent_page_choices['acfOptionsPages'][ $item[2] ] ) ) {
				$acf_parent_page_choices['Others'][ $item[2] ] = acf_esc_html( $sanitized_name );
			}
		}
	}
	return $acf_parent_page_choices;
}