hook_suffix = (string) add_submenu_page(
DashboardPage::SLUG,
__( 'Yangra Conditional Docs', 'yangra-conditional' ),
__( 'Docs', 'yangra-conditional' ),
self::CAPABILITY,
self::SLUG,
array( $this, 'render' )
);
}
/**
* Renders the React mount point, with links to the screens the docs
* mention that the current user can open.
*
* @return void
*/
public function render(): void {
printf(
'
',
esc_attr( (string) wp_json_encode( $this->links() ) )
);
}
/**
* Links to the screens the docs mention, for the current user and theme.
* A screen the user can't open, or the theme doesn't have, is left out.
*
* @return array Keyed by screen: dashboard, settings, scheduledElements, scheduledContent, shortcodes, menus, navigation, widgets, posts.
*/
public function links(): array {
$links = array(
'dashboard' => admin_url( 'admin.php?page=' . DashboardPage::SLUG ),
'posts' => admin_url( 'edit.php' ),
);
if ( current_user_can( SettingsPage::CAPABILITY ) ) {
$links['settings'] = admin_url( 'admin.php?page=' . SettingsPage::SLUG );
}
if ( current_user_can( ScheduledElementsPage::CAPABILITY ) ) {
$links['scheduledElements'] = admin_url( 'admin.php?page=' . ScheduledElementsPage::SLUG );
}
if ( current_user_can( ScheduledContent::CAPABILITY ) ) {
$links['scheduledContent'] = admin_url( ScheduledContentScreens::LIST_SLUG );
}
if ( current_user_can( ShortcodeBuilderPage::CAPABILITY ) ) {
$links['shortcodes'] = ShortcodeBuilderPage::url();
}
if ( current_user_can( 'edit_theme_options' ) ) {
if ( current_theme_supports( 'menus' ) ) {
$links['menus'] = admin_url( 'nav-menus.php' );
}
if ( wp_is_block_theme() ) {
// WordPress 6.8+ redirects this older path to its current Navigation screen.
$links['navigation'] = admin_url( 'site-editor.php?path=/navigation' );
}
if ( current_theme_supports( 'widgets' ) ) {
$links['widgets'] = admin_url( 'widgets.php' );
}
}
/**
* Filters the links to the screens the docs mention, for the current
* user. Pro adds its own screens.
*
* @param mixed $links Screen key => URL. Values that aren't a URL string are dropped.
*/
$filtered = apply_filters( 'yangra_conditional_docs_links', $links );
$clean = array();
foreach ( (array) $filtered as $key => $url ) {
if ( is_string( $url ) && '' !== $url ) {
$clean[ (string) $key ] = $url;
}
}
return $clean;
}
/**
* Enqueues the docs app on this page only.
*
* @param string $hook_suffix Current admin page hook suffix.
* @return void
*/
public function enqueue( string $hook_suffix ): void {
if ( '' === $this->hook_suffix || $hook_suffix !== $this->hook_suffix ) {
return;
}
AdminApp::enqueue( 'docs' );
}
}