Automattic\WooCommerce\Admin

PageController::register_page()publicWC 1.0

Adds a JS powered page to wc-admin.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$PageController = new PageController();
$PageController->register_page( $options );
$options(массив) (обязательный)

Array describing the page.

  • id(строка)
    Id to reference the page.

  • title(строка)
    Page title. Used in menus and breadcrumbs.

  • parent(строка|null)
    Parent ID. Null for new top level page.

  • path(строка)
    Path for this page, full path in app context; ex /analytics/report

  • capability(строка)
    Capability needed to access the page.

  • icon(строка)
    Icon. Dashicons helper class, base64-encoded SVG, or 'none'.

  • position(int)
    Menu item position.

  • order(int)
    Navigation item order.

Код PageController::register_page() WC 8.7.0

public function register_page( $options ) {
	$defaults = array(
		'id'         => null,
		'parent'     => null,
		'title'      => '',
		'capability' => 'view_woocommerce_reports',
		'path'       => '',
		'icon'       => '',
		'position'   => null,
		'js_page'    => true,
	);

	$options = wp_parse_args( $options, $defaults );

	if ( 0 !== strpos( $options['path'], self::PAGE_ROOT ) ) {
		$options['path'] = self::PAGE_ROOT . '&path=' . $options['path'];
	}

	if ( null !== $options['position'] ) {
		$options['position'] = intval( round( $options['position'] ) );
	}

	if ( is_null( $options['parent'] ) ) {
		add_menu_page(
			$options['title'],
			$options['title'],
			$options['capability'],
			$options['path'],
			array( __CLASS__, 'page_wrapper' ),
			$options['icon'],
			$options['position']
		);
	} else {
		$parent_path = $this->get_path_from_id( $options['parent'] );
		// @todo check for null path.
		add_submenu_page(
			$parent_path,
			$options['title'],
			$options['title'],
			$options['capability'],
			$options['path'],
			array( __CLASS__, 'page_wrapper' )
		);
	}

	$this->connect_page( $options );
}