Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_admin_page_parent ›

Seit1.5.0
Veraltetn/v
get_admin_page_parent ( $parent = '' )
Parameter:
  • (string) $parent The slug name for the parent menu (or the file name of a standard WordPress admin page). Default empty string.
    Erforderlich: Nein
    Standard: (leer)
Gibt zurück:
  • (string) The parent file of the current admin page.
Definiert in:
Codex:

Gets the parent file of the current admin page.



Quellcode

function get_admin_page_parent( $parent = '' ) {
	global $parent_file, $menu, $submenu, $pagenow, $typenow,
		$plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv;

	if ( ! empty( $parent ) && 'admin.php' !== $parent ) {
		if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
			$parent = $_wp_real_parent_file[ $parent ];
		}

		return $parent;
	}

	if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) {
		foreach ( (array) $menu as $parent_menu ) {
			if ( $parent_menu[2] === $plugin_page ) {
				$parent_file = $plugin_page;

				if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
					$parent_file = $_wp_real_parent_file[ $parent_file ];
				}

				return $parent_file;
			}
		}
		if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
			$parent_file = $plugin_page;

			if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
					$parent_file = $_wp_real_parent_file[ $parent_file ];
			}

			return $parent_file;
		}
	}

	if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
		$parent_file = $pagenow;

		if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
			$parent_file = $_wp_real_parent_file[ $parent_file ];
		}

		return $parent_file;
	}

	foreach ( array_keys( (array) $submenu ) as $parent ) {
		foreach ( $submenu[ $parent ] as $submenu_array ) {
			if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
				$parent = $_wp_real_parent_file[ $parent ];
			}

			if ( ! empty( $typenow ) && "$pagenow?post_type=$typenow" === $submenu_array[2] ) {
				$parent_file = $parent;
				return $parent;
			} elseif ( empty( $typenow ) && $pagenow === $submenu_array[2]
				&& ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) )
			) {
				$parent_file = $parent;
				return $parent;
			} elseif ( isset( $plugin_page ) && $plugin_page === $submenu_array[2] ) {
				$parent_file = $parent;
				return $parent;
			}
		}
	}

	if ( empty( $parent_file ) ) {
		$parent_file = '';
	}
	return '';
}