Automattic\WooCommerce\Admin

PageController::get_breadcrumbs()publicWC 1.0

Get breadcrumbs for WooCommerce Admin Page navigation.

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

Хуки из метода

Возвращает

Массив. Navigation pieces (breadcrumbs).

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

$PageController = new PageController();
$PageController->get_breadcrumbs();

Код PageController::get_breadcrumbs() WC 9.4.2

public function get_breadcrumbs() {
	$current_page = $this->get_current_page();

	// Bail if this isn't a page registered with this controller.
	if ( false === $current_page ) {
		// Filter documentation below.
		return apply_filters( 'woocommerce_navigation_get_breadcrumbs', array( '' ), $current_page );
	}

	$page_title = ! empty( $current_page['page_title'] ) ? $current_page['page_title'] : $current_page['title'];
	$page_title = (array) $page_title;
	if ( 1 === count( $page_title ) ) {
		$breadcrumbs = $page_title;
	} else {
		// If this page has multiple title pieces, only link the first one.
		$breadcrumbs = array_merge(
			array(
				array( $current_page['path'], reset( $page_title ) ),
			),
			array_slice( $page_title, 1 )
		);
	}

	if ( isset( $current_page['parent'] ) ) {
		$parent_id = $current_page['parent'];

		while ( $parent_id ) {
			if ( isset( $this->pages[ $parent_id ] ) ) {
				$parent = $this->pages[ $parent_id ];

				if ( 0 === strpos( $parent['path'], self::PAGE_ROOT ) ) {
					$parent['path'] = 'admin.php?page=' . $parent['path'];
				}

				array_unshift( $breadcrumbs, array( $parent['path'], reset( $parent['title'] ) ) );
				$parent_id = isset( $parent['parent'] ) ? $parent['parent'] : false;
			} else {
				$parent_id = false;
			}
		}
	}

	$woocommerce_breadcrumb = array( 'admin.php?page=' . self::PAGE_ROOT, __( 'WooCommerce', 'woocommerce' ) );

	array_unshift( $breadcrumbs, $woocommerce_breadcrumb );

	/**
	 * The navigation breadcrumbs for the current page.
	 *
	 * @param array         $breadcrumbs Navigation pieces (breadcrumbs).
	 * @param array|boolean $current_page The connected page data or false if not identified.
	 */
	return apply_filters( 'woocommerce_navigation_get_breadcrumbs', $breadcrumbs, $current_page );
}