'; } public function end_lvl( &$output, $depth = 0, $args = null ): void { $output .= ''; } public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ): void { $user_roles = (array) wp_get_current_user()->roles; $roles = array_filter( (array) get_post_meta( $item->ID, '_dashbread_roles', true ) ); if ( $roles && ! array_intersect( $roles, $user_roles ) ) { return; } // A menu item that points at a hosted page can narrow access, never widen it: the page's own // "Visible to roles" (set in the meta box or the Hosted pages screen) always applies too. if ( 'post_type' === $item->type && (int) $item->object_id > 0 && get_post_meta( (int) $item->object_id, \Dashbread\Core\HostedPages::META_IN_APP, true ) ) { $page_roles = array_filter( (array) get_post_meta( (int) $item->object_id, \Dashbread\Core\HostedPages::META_ROLES, true ) ); if ( $page_roles && ! array_intersect( $page_roles, $user_roles ) ) { return; } // Link to the page inside the app, not its public permalink. $post = get_post( (int) $item->object_id ); if ( $post instanceof \WP_Post ) { $item->url = \Dashbread\Core\Settings::app_url( $post->post_name ); /** Same gate as HostedPages::visible(): a page an add-on hides is not linked either. */ if ( ! apply_filters( 'dashbread_hosted_visible', true, $post, wp_get_current_user() ) ) { return; } } } $icon = (string) get_post_meta( $item->ID, '_dashbread_icon', true ); if ( '' === $icon && 'post_type' === $item->type ) { $icon = (string) get_post_meta( (int) $item->object_id, '_dashbread_icon', true ); } $classes = array( 'sui-nav-item' ); if ( in_array( 'current-menu-item', (array) $item->classes, true ) || ( isset( $args->dashbread_current ) && $args->dashbread_current === (string) $item->url ) ) { $classes[] = 'is-active'; } /** @param string $badge HTML for a badge on this menu item, e.g. an unread count. */ $badge = (string) apply_filters( 'dashbread_nav_badge', '', $item ); $output .= 'target ? ' target="' . esc_attr( $item->target ) . '"' : '' ) . '>' . Icons::svg( '' !== $icon ? $icon : 'circle' ) . '' . esc_html( (string) $item->title ) . '' . ( '' !== $badge ? '' . wp_kses_post( $badge ) . '' : '' ); } public function end_el( &$output, $item, $depth = 0, $args = null ): void { $output .= ''; } }