diff --git a/includes/functions/_helpers-templates.php b/includes/functions/_helpers-templates.php index 1f95b6c5..5b11e156 100644 --- a/includes/functions/_helpers-templates.php +++ b/includes/functions/_helpers-templates.php @@ -2247,8 +2247,6 @@ function fictioneer_get_oauth2_login_links( $label = false, $classes = '', $anch /** * Returns the HTML of the bullet separator * - * Note: - * * @since 5.23.0 * * @param string|null $context Optional. The render context. @@ -2265,3 +2263,127 @@ function fictioneer_get_bullet_separator( $context = null, $blank = false ) { $context ); } + +// ============================================================================= +// ICON MENU +// ============================================================================= + +/** + * Renders the icon menu + * + * @since 5.25.0 + * + * @param array $args['location'] Either 'in-navigation' or 'in-mobile-menu'. + */ + +function fictioneer_render_icon_menu( $args ) { + // Setup + $output = []; + $location = $args['location'] ?? 'location-missing'; + $bookmarks_link = fictioneer_get_assigned_page_link( 'fictioneer_bookmarks_page' ); + $discord_invite_link = get_option( 'fictioneer_discord_invite_link' ); + $profile_link = get_edit_profile_url(); + $profile_page_id = intval( get_option( 'fictioneer_user_profile_page', -1 ) ?: -1 ); + + if ( ! empty( $profile_page_id ) && $profile_page_id > 0 ) { + $profile_link = fictioneer_get_assigned_page_link( 'fictioneer_user_profile_page' ); + } + + // Build items + if ( fictioneer_show_login() ) { + $output['login'] = sprintf( + '
', + esc_attr__( 'Login', 'fictioneer' ), + esc_attr__( 'Open login modal', 'fictioneer' ), + fictioneer_get_icon( 'fa-login' ) + ); + } + + if ( fictioneer_show_auth_content() ) { + $output['profile'] = sprintf( + ' ', + esc_url( $profile_link ), + esc_attr__( 'User Profile', 'fictioneer' ), + esc_attr__( 'Link to user profile', 'fictioneer' ), + fictioneer_user_menu_items() + ); + } + + if ( ! empty( $bookmarks_link ) ) { + $output['bookmarks'] = sprintf( + ' ', + esc_url( $bookmarks_link ), + esc_attr__( 'Bookmarks Page', 'fictioneer' ), + esc_attr__( 'Link to bookmarks page', 'fictioneer' ) + ); + } + + if ( ! empty( $discord_invite_link ) ) { + $output['discord'] = sprintf( + ' ', + esc_url( $discord_invite_link ), + esc_attr__( 'Join Discord', 'fictioneer' ), + esc_attr__( 'Discord invite link', 'fictioneer' ) + ); + } + + if ( + $location === 'in-navigation' && + get_option( 'fictioneer_enable_follows' ) && + fictioneer_show_auth_content() + ) { + $output['follows'] = sprintf( + ' ', + esc_attr__( 'Mark follows as read', 'fictioneer' ), + fictioneer_get_icon( 'fa-bell' ), + _x( 'Read', 'Mark as read button.', 'fictioneer' ), + __( 'Looking for updates...', 'fictioneer' ) + ); + } + + if ( $location === 'in-navigation' && FICTIONEER_SHOW_SEARCH_IN_MENUS ) { + $output['search'] = sprintf( + ' ', + esc_url( home_url( '/?s=' ) ), + esc_attr__( 'Search Page', 'fictioneer' ), + esc_attr__( 'Link to search page', 'fictioneer' ) + ); + } + + $output['lightswitch'] = sprintf( + '', + esc_attr__( 'Toggle Dark/Light Mode', 'fictioneer' ), + esc_attr__( 'Toggle between dark mode and light mode', 'fictioneer' ), + fictioneer_get_icon( 'fa-sun', 'only-darkmode' ) . fictioneer_get_icon( 'fa-moon', 'only-lightmode' ) + ); + + $output['settings'] = sprintf( + '', + esc_attr__( 'Site Settings', 'fictioneer' ), + esc_attr__( 'Open site settings modal', 'fictioneer' ), + fictioneer_get_icon( 'fa-tools' ) + ); + + if ( get_option( 'fictioneer_enable_theme_rss' ) ) { + $output['rss'] = sprintf( + ' ', + esc_url( home_url( 'feed' ) ), + esc_attr__( 'Site RSS', 'fictioneer' ), + esc_attr__( 'Link to site RSS feed', 'fictioneer' ), + fictioneer_get_icon( 'fa-rss' ) + ); + } + + if ( $location === 'in-mobile-menu' && fictioneer_show_auth_content() ) { + $output['logout'] = sprintf( + ' ', + fictioneer_get_logout_url(), + esc_attr__( 'Logout', 'fictioneer' ), + esc_attr__( 'Click to log out', 'fictioneer' ), + fictioneer_get_icon( 'fa-logout' ) + ); + } + + // Render + echo ' '; +} diff --git a/includes/functions/hooks/_mobile_menu_hooks.php b/includes/functions/hooks/_mobile_menu_hooks.php index 3965a3c1..2cdab688 100644 --- a/includes/functions/hooks/_mobile_menu_hooks.php +++ b/includes/functions/hooks/_mobile_menu_hooks.php @@ -59,7 +59,7 @@ add_action( 'fictioneer_body', 'fictioneer_output_mobile_menu', 20 ); */ function fictioneer_mobile_user_icon_menu() { - get_template_part( 'partials/_icon-menu', null, array( 'location' => 'in-mobile-menu' ) ); + fictioneer_render_icon_menu( array( 'location' => 'in-mobile-menu' ) ); } add_action( 'fictioneer_mobile_menu_top', 'fictioneer_mobile_user_icon_menu', 10 ); diff --git a/partials/_icon-menu.php b/partials/_icon-menu.php deleted file mode 100644 index bb762ab3..00000000 --- a/partials/_icon-menu.php +++ /dev/null @@ -1,153 +0,0 @@ - 0 ) { - $profile_link = fictioneer_get_assigned_page_link( 'fictioneer_user_profile_page' ); -} - -?> - - diff --git a/partials/_navigation.php b/partials/_navigation.php index 452ced88..99657c59 100644 --- a/partials/_navigation.php +++ b/partials/_navigation.php @@ -99,7 +99,7 @@ if ( $header_style === 'wide' ) {