pages[ $id ] ) && isset( $this->pages[ $id ]['path'] ) ) { return $this->pages[ $id ]['path']; } return null; } /** * Adds a JS powered page to wc-admin. * * @param array $options { * Array describing the page. * * @type string id Id to reference the page. * @type string title Page title. Used in menus and breadcrumbs. * @type string|null parent Parent ID. Null for new top level page. * @type string path Path for this page, full path in app context; ex /analytics/report * @type string capability Capability needed to access the page. * @type string icon Icon. Dashicons helper class, base64-encoded SVG, or 'none'. * @type int position Menu item position. * } */ public function register_page( $options ) { $defaults = array( 'id' => null, 'parent' => null, 'title' => '', 'capability' => 'manage_options', 'path' => '', 'icon' => '', 'position' => null, ); $options = wp_parse_args( $options, $defaults ); $options['path'] = self::PAGE_ROOT . $options['path']; // TODO: check for null ID, or collision. $this->pages[ $options['id'] ] = $options; 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' ) ); } } /** * Set up a div for the app to render into. */ public static function page_wrapper() { ?>