Using Wordpress top menu bar on the Discourse side?

Hi,

We are using BuddyPress + Wordpress and Discourse. We configured SSO settings. We set WordPress instance as the SSO provider.

We have user profile menu on Wordpress top menu bar. I wonder, is this possible to use top menu bar on Discourse side too with dynamic links like user profile menu?

You could try recreating the WordPress menu bar with HTML and CSS. It can be added to your Discourse theme Header section. For a logged in user on WordPress http://example.com/wp-admin/profile.php will link the user to their profile page. Since you are using SSO, if you only show that link to logged in users, it will work. That can be done by adding and removing a class with some javascript that checks for the presence of a user.

// CSS
.wp-profile-link {
    display: none;
}

.wp-profile-link.current-user {
    display: block;
}

Added to the /head section of a theme:

<script type="text/discourse-plugin" version="0.8.18">
if (api.getCurrentUser()) {
    $('.wp-profile-link').addClass('current-user');
} else {
    $('.wp-profile-link').removeClass('current-user');
}
</script>
2 Likes