adding another dual menu option for register | your profile
-
So I wanted to change the register button to a dual register | your profile button similar to the way the login | logout button works. After a bit of experimenting, I managed to get it working and thought I’d share. This modification simply makes the register button that would normally disappear when a user is logged in change to a link to the user’s profile. Just a note, I am also using the theme-my-login plugin to facilitate front-end login, registration, and profile pages. Hope someone finds this useful
(changed on the back-end page)
function bawllm_nav_menu_metabox( $object ) { global $nav_menu_selected_id; $elems = array( '#bawlogin#' => __( 'Log In' ), '#bawlogout#' => __( 'Log Out' ), '#bawloginout#' => __( 'Log In' ).'|'.__( 'Log Out' ), '#bawregister#' => __( 'Register' ).'|'.__( 'Your Profile' ) ); class bawlogItems { public $db_id = 0; public $object = 'bawlog'; public $object_id; public $menu_item_parent = 0; public $type = 'custom'; public $title; public $url; public $target = ''; public $attr_title = ''; public $classes = array(); public $xfn = ''; }
(changed on the front-end page near the top)
/* Used to return the correct title for the double register/your profile menu item */ function bawllm_register_title( $title ) { $titles = explode( '|', $title ); if ( ! is_user_logged_in() ) return esc_html( isset( $titles[0] ) ? $titles[0] : $title ); else return esc_html( isset( $titles[1] ) ? $titles[1] : $title ); }
(replace the original #bawregister# case)
case '#bawregister#' : $item_redirect = explode( '|', $item_redirect ); if( count( $item_redirect ) != 2 ) $item_redirect[1] = $item_redirect[0]; for( $i = 0; $i <= 1; $i++ ): if( $item_redirect[$i] == '%actualpage%') $item_redirect[$i] = $_SERVER['REQUEST_URI']; endfor; $item->url = is_user_logged_in() ? site_url( 'your-profile') : site_url( 'wp-login.php?action=register', 'login' ); $item->title = bawllm_register_title( $item->title ) ; break; } $item->url = esc_url( $item->url ); } return $item;
(change the original [register] shortcode)
/* [register] shortcode */ add_shortcode( 'register', 'bawllm_shortcode_register' ); function bawllm_shortcode_register( $atts, $content = null ) { extract(shortcode_atts(array( "edit_tag" => "", "redirect" => $_SERVER['REQUEST_URI'] ), $atts ) ); $edit_tag = strip_tags( $edit_tag ); $href = is_user_logged_in() ? site_url( 'your-profile') : site_url( 'wp-login.php?action=register', 'login' ); if( $content && strstr( $content, '|' ) != '' ) { // the "|" char is used to split titles $content = explode( '|', $content ); $content = is_user_logged_in() ? $content[1] : $content[0]; }else{ $content = is_user_logged_in() ? __( 'Your Profile' ) : __( 'Register' ); } return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>'; }
- The topic ‘adding another dual menu option for register | your profile’ is closed to new replies.