Hi-
I had a custom plugin built for me two years ago that creates a login link as well as a user profile menu in the header. It worked well with the latest version of X but it does not work with the new Header builder in Pro. Could someone take a look at the code below and see what I might need to change for it work in Pro? Thank you!
<?php
/*
Plugin Name: Matt User Menu
Plugin URI: http://www.easy-development.com
Description: The User Menu that Matt needed
Version: 1.0
Author: Andrei-Robert Rusu
Author URI: http://www.easy-development.com
*/
class MattUserMenu {
protected static $_instance;
public static function getInstance() {
if(self::$_instance === null)
self::$_instance = new self();
return self::$_instance;
}
public static function resetInstance() {
self::$_instance = null;
}
public $settingUserPhotoDimension = 42;
public $settingUserHello = "Hello %s"; // %s will be replaced by the "user call name"
/**
* This is how we address the user, chose from :
* Username: user_login
* User first name: user_firstname
* User last name: user_lastname
* User display name: display_name
* @var string
*/
public $settingUserCallName = "display_name";
public function __construct() {
add_filter('wp_nav_menu_items', array($this, 'wpNavMenuItemsFilter'), 10, 2);
add_action("init", array($this, "init"));
}
public function init() {
wp_enqueue_style('matt-user-menu', plugins_url( 'matt-user-menu.css', __FILE__));
}
public function wpNavMenuItemsFilter($items, $args) {
if( strpos($args->theme_location, 'primary') === false)
return $items;
return is_user_logged_in() ? $this->_navMenuLoggedIn($items, $args) : $this->_navMenuLoggedOut($items, $args);
}
private function _navMenuLoggedIn($items, $args) {
$loginLogoutLink = $this->_getLoginLogoutLink();
$currentUser = wp_get_current_user();
$userCallName = $this->settingUserCallName;
$items .= '<li class="component-matt-user-menu user-box ' . strtolower(str_replace(array(" ", ":"), "", wp_get_theme())) . '">';
$items .= '<a class="user-box">';
$items .= get_avatar( $currentUser->ID, $this->settingUserPhotoDimension );
$items .= '</a>';
$items .= '<ul>';
$items .= '<li class="hello">' . sprintf($this->settingUserHello, $currentUser->$userCallName) . '</li>';
$items .= '<li><a href="' . get_site_url() . '/wpufprofile/">Edit Profile</li>';
$items .= '<li><a href="http://yciw.sites.noteflight.com/" target="_blank">Noteflight</li>';
$items .= '<li><a href="http://community.yciw.net/" target="_blank">Community</li>';
$items .= '<li>' . $loginLogoutLink . '</li>';
$items .= '</ul>';
$items .= '</li>';
return $items;
}
private function _navMenuLoggedOut($items, $args) {
$loginLogoutLink = $this->_getLoginLogoutLink();
$items .= '<li>'. $loginLogoutLink .'</li>';
return $items;
}
private function _getLoginLogoutLink() {
ob_start();
wp_loginout('index.php');
$loginLink = ob_get_contents();
ob_end_clean();
return $loginLink;
}
}
MattUserMenu::getInstance();