My Account Menu – Supreme Theme
This topic contains 6 replies, has 3 voices, and was last updated by Alex Rollin 6 years, 11 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: my account, nav menu, Supreme
-
AuthorPosts
-
January 23, 2018 at 2:41 am #413901
Hello,
I’m Using Supreme Theme and i edited the functions.php to add many more menu items to the My Account in the main menu which works great! I even added Buddypress unread Notification Count (see attached image). All works perfectly except I’m trying to move my edits to code snippets plugin so i don’t risk loosing the changes I’ve made but unfortunately it returns an error
Don't Panic The code snippet you are trying to save produced a fatal error on line 226: Cannot redeclare sd_add_my_account_link() (previously declared in /home/poiaustraliacom/public_html/wp-content/themes/supreme-directory/functions.php:223) The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.
The Following is the code I am trying to add to code snippets including changes
/** * Add My Account link to the main menu. * * @param string $items The HTML list content for the menu items. * @param object $args An object containing wp_nav_menu() arguments. * @return string The menu items HTML. * @since 1.0.0 */ function sd_add_my_account_link($items, $args) { if ($args->theme_location == 'primary-menu') { ob_start(); $menu_slug = $args->menu->slug; ?> <li class="sd-my-account menu-item"> <?php if (is_user_logged_in()) { $current_user = wp_get_current_user(); $avatar = get_avatar($current_user->ID, 60); $redirect_to = apply_filters('sd_logout_redirect_to_link', sd_current_page_url()); ?> <a class="sd-my-account-link" href=""> <?php echo $avatar; if (class_exists('BuddyPress')) { $user_link = bp_get_loggedin_user_link(); } else { $user_link = get_author_posts_url($current_user->ID); } ?> <?php echo __('My Account', 'supreme-directory'); ?> <span style="background:#21759b; padding: 2px 2px 2px 5px; border-radius: 10px; margin-left: 3px;"><?php echo bp_notifications_get_unread_notification_count(bp_loggedin_user_id()); ?> </span> <i class="fa fa-caret-down"></i> </a> <div id="sd-my-account" class="Panel"> <div class="mm-subtitle"><a class="mm-subclose" href="#mm-menu-<?php echo esc_attr($menu_slug);?>"><?php _e('< Back','supreme-directory');?></a></div> <div class="sd-my-account-dd"> <div class="sd-my-account-dd-inner"> <div class="sd-dd-avatar-wrap"> <a href="<?php echo esc_url($user_link); ?>" rel="nofollow"><?php echo $avatar; ?></a> <h4> <a href="<?php echo esc_url($user_link); ?>" rel="nofollow"><?php echo esc_attr($current_user->display_name); ?></a> </h4> </div> <?php if (class_exists('BuddyPress')) { ?> <ul class="sd-my-account-dd-menu-group sd-my-account-dd-menu-bp-group"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link); ?>"> <i class="fa fa-user"></i> <?php echo __('About Me', 'supreme-directory'); ?> </a> <ul class="sub-menu"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . ''); ?>"> <i class="fa fa-clock-o"></i> <?php echo __('Activity', 'supreme-directory'); ?> </a> </ul> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'notifications/'); ?>"> <span style="background:#21759b; padding: 2px 2px 2px 5px; border-radius: 10px; margin-right: 7px; margin-left: -3px;"><?php echo bp_notifications_get_unread_notification_count(bp_loggedin_user_id()); ?> </span> <?php echo __('Notifications', 'supreme-directory'); ?> </a> <ul class="sub-menu"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'messages/'); ?>"> <i class="fa fa-envelope"></i> <?php echo __('Messages', 'supreme-directory'); ?> </a> </ul> </li> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'listings/'); ?>"> <i class="fa fa-map-marker"></i> <?php echo __('Listings', 'supreme-directory'); ?> </a> <ul class="sub-menu"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url('https://poi-australia.com.au/list-with-us/'); ?>"> <i class="fa fa-plus"></i> <?php echo __('Add Listing', 'supreme-directory'); ?> </a> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'invoices/'); ?>"> <i class="fa fa-file-text"></i> <?php echo __('Invoices', 'supreme-directory'); ?> </a> </ul> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'favorites/'); ?>"> <i class="fa fa-heart"></i> <?php echo __('Favourites', 'supreme-directory'); ?> </a> <ul class="sub-menu"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'reviews/'); ?>"> <i class="fa fa-star"></i> <?php echo __('Reviews', 'supreme-directory'); ?> </a> </ul> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'friends/'); ?>"> <i class="fa fa-user"></i> <?php echo __('Friends', 'supreme-directory'); ?> </a> <ul class="sub-menu"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url('https://poi-australia.com.au/members/'); ?>"> <i class="fa fa-user-plus"></i> <?php echo __('Find New Friends', 'supreme-directory'); ?> </a> </ul> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'groups/'); ?>"> <i class="fa fa-users"></i> <?php echo __('Groups', 'supreme-directory'); ?> </a> <ul class="sub-menu"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url('https://poi-australia.com.au/groups/'); ?>"> <i class="fa fa-search-plus"></i> <?php echo __('Search Groups', 'supreme-directory'); ?> </a> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url('https://poi-australia.com.au/groups/create/'); ?>"> <i class="fa fa-plus"></i> <?php echo __('Create a Group', 'supreme-directory'); ?> </a> </ul> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url('https://poi-australia.com.au/affiliate-area/'); ?>"> <i class="fa fa-usd"></i> <?php echo __('Affiliate Program', 'supreme-directory'); ?> </a> </li> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url($user_link . 'settings/'); ?>"> <i class="fa fa-cog"></i> <?php echo __('Account Settings', 'supreme-directory'); ?> </a> </li> </ul> <?php } ?> <?php do_action('sd_my_account_logged_in_extras'); ?> <ul class="sd-my-account-dd-menu-group"> <li class="sd-my-account-dd-menu-link"> <a href="<?php echo esc_url(wp_logout_url($redirect_to)); ?>"> <i class="fa fa-sign-out"></i> <?php echo __('Log Out', 'supreme-directory'); ?> </a> </li> </ul> </div> </div> </div> <?php } else { if (isset($_GET['redirect_to']) && $_GET['redirect_to'] != '') { $redirect_to = $_GET['redirect_to']; } else if (isset($_GET['redirect_add_listing']) && $_GET['redirect_add_listing'] != '') { $redirect_to = $_GET['redirect_add_listing']; } else { $redirect_to = sd_current_page_url(); } $redirect_to = apply_filters('sd_login_redirect_to_link', $redirect_to); ?> <a class="sd-my-account-link" href=""> <?php echo __('My Account', 'supreme-directory'); ?> <i class="fa fa-caret-down"></i> </a> <div id="sd-my-account" class="Panel"> <div class="mm-subtitle"><a class="mm-subclose" href="#mm-menu-<?php echo esc_attr($menu_slug);?>"><?php _e('< Back','supreme-directory');?></a></div> <div class="sd-my-account-dd"> <div class="sd-my-account-dd-inner"> <h4 class="sd-my-account-title"><?php echo __('Sign In', 'supreme-directory'); ?></h4> <?php if (isset($_REQUEST['emsg']) && $_REQUEST['emsg'] == 'fw') { echo "<p class=\"error_msg\"> " . __('Invalid Email, Please check', 'supreme-directory') . " </p>"; } elseif (isset($_REQUEST['logemsg']) && $_REQUEST['logemsg'] == 1) { echo "<p class=\"error_msg\"> " . INVALID_USER_PW_MSG . " </p>"; } if (isset($_REQUEST['checkemail']) && $_REQUEST['checkemail'] == 'confirm') echo '<p class="sucess_msg">' . __('Invalid Username/Password.', 'supreme-directory') . '</p>'; ?> <form name="cus_loginform" method="post" action="<?php echo sd_login_url('');?>" > <div class="form_row clearfix"> <input placeholder='<?php _e('Email', 'supreme-directory'); ?>' type="text" name="log" id="user_login" value="<?php global $user_login; if (!isset($user_login)) { $user_login = ''; } echo esc_attr($user_login); ?>" size="20" class="textfield"/> <span class="user_loginInfo"></span> </div> <div class="form_row clearfix"> <input placeholder='<?php _e('Password', 'supreme-directory'); ?>' type="password" name="pwd" id="user_pass" class="textfield input-text" value="" size="20"/> <span class="user_passInfo"></span> </div> <p class="rember"> <input name="rememberme" type="checkbox" id="rememberme" value="forever" class="fl"/> <?php _e('Remember me on this computer', 'supreme-directory'); ?> </p> <input class="geodir_button" type="submit" value="<?php _e('Sign In', 'supreme-directory'); ?>" name="submit"/> <input type="hidden" name="redirect_to" value="<?php echo esc_url($redirect_to); ?>"/> <input type="hidden" name="testcookie" value="1"/> <input type="hidden" name="action" value="login"/> <p class="sd-register"> <a href="<?php echo esc_url(sd_login_url(array('signup' => true))); ?>" class="goedir-newuser-link"><?php _e('Register', 'supreme-directory'); ?></a> <a href="<?php echo esc_url(sd_login_url(array('forgot' => true))); ?>" class="goedir-forgot-link"><?php _e('Forgot Password?', 'supreme-directory'); ?></a> </p> <?php do_action('login_form'); ?> </form> </div> </div> </div> <?php } ?> </li> <?php $html = ob_get_clean(); $items .= $html; } return $items; } add_filter('wp_nav_menu_items', 'sd_add_my_account_link', 1001, 2); function sd_login_url($params){ if(function_exists('geodir_login_url')){ return geodir_login_url($params); }else{ if(isset($params['signup']) && $params['signup']){ return wp_registration_url(); }elseif(isset($params['forgot']) && $params['forgot']){ return wp_lostpassword_url(); } return wp_login_url(); } }
Maybe I’m doing something wrong??
Thanks Guys
January 23, 2018 at 2:57 am #413905My site is POI Australia
January 23, 2018 at 5:00 am #413907Hi Silks,
Accordingly to the error (Cannot redeclare sd_add_my_account_link() (previously declared in /home/poiaustraliacom/public_html/wp-content/themes/supreme-directory/functions.php:223), it is trying to tell you that you already had this same function in the theme’s functions.php file. Did you remove it from the functions.php file before activating it in Code snippet?
If you’re not sure, share WP temp admin access to your site and we’ll see what we can do to help. You can post the details here using the private reply option below.
Thanks!
January 23, 2018 at 5:33 am #413912Hey Kor,
I assumed that was the issue but I was concerned that if i deleted it from functions.php and an update was released for supreme theme then it would cause a conflict then at the time of the update..
Is this likely to be an issue??
Thanks
January 23, 2018 at 10:50 am #413944Why would there be a conflict in the case of an update?
That does not seem like an issue, no.
For future reference, ‘there can be only one’ function with a name, so, sounds like this is sorted?
Let us know if there’s more!
January 24, 2018 at 11:13 am #414132I thought it might be an issue because that function is part of the standard install of supreme theme therefore if i delete it from functions.php it will reappear if the theme was updated. Then the function would appear in code snippets plugin and functions.php.
From what I understand supreme theme is a child theme therefore you can’t make a child theme of a child theme and that is the reason for using code snippets plugin. So my understanding is that supreme theme can be updated and when it is functions.php will be updated adding the code i have previously deleted which means there would be 2 copies of the same code.
If that is not the case then that is fine but i just wanted to confirm to be on the safe side
Thanks
January 24, 2018 at 12:15 pm #414139Hello,
best practice is to name new functions with a different name.
Yes, you should use code snippets, yes if you update supreme it will be overwritten.
If you need help with your customization you should contact a developer:
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket