Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active January 23, 2024 22:39
Show Gist options
  • Save cartpauj/26c89ee92965817eaa10 to your computer and use it in GitHub Desktop.
Save cartpauj/26c89ee92965817eaa10 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: MemberPress Account Page Nav
Plugin URI: http://www.memberpress.com/
Description: Allows developers to add more nav menu links/pages to their members account page
Version: 1.0.0
Author: Caseproof, LLC
Author URI: http://caseproof.com/
Copyright: 2004-2013, Caseproof, LLC
*/
//COPY FROM THE LINE BELOW TO THE END, IF YOU PLAN TO PASTE THIS CODE INTO A THEME'S functions.php FILE OR INTO A PLUGIN LIKE My Custom Functions
//ADD A SUPPORT TAB TO THE NAV MENU
function mepr_add_some_tabs($user) {
$support_active = (isset($_GET['action']) && $_GET['action'] == 'premium-support')?'mepr-active-nav-tab':'';
?>
<span class="mepr-nav-item premium-support <?php echo $support_active; ?>">
<a href="/account/?action=premium-support">Premium Support</a>
</span>
<?php
}
add_action('mepr_account_nav', 'mepr_add_some_tabs');
//YOU CAN DELETE EVERYTHING BELOW THIS LINE -- IF YOU PLAN TO REDIRECT
//THE USER TO A DIFFERENT PAGE INSTEAD OF KEEPING THEM ON THE SAME PAGE
//ADD THE CONTENT FOR THE NEW SUPPORT TAB ABOVE
function mepr_add_tabs_content($action) {
if($action == 'premium-support'): //Update this 'premium-support' to match what you put above (?action=premium-support)
?>
<div id="custom-support-form">
<form action="" method="post">
<label for="subject">Enter Subject:</label><br/>
<input type="text" name="subject" id="subject" />
<br/><br/>
<label for="content">Enter Content:</label><br/>
<input type="text" name="content" id="content" />
<br/><br/>
<input type="submit" name="premium-support-submit" value="Submit" />
</form>
</div>
<?php
endif;
}
add_action('mepr_account_nav_content', 'mepr_add_tabs_content');
@cartpauj
Copy link
Author

cartpauj commented Jul 27, 2017

Line #24 and down can be deleted if you're just redirecting the user to an existing page somewhere else on the site.

@littlered23
Copy link

This is great, thanks! A bit of a noob here, but is it possible to render a specific custom field on a new nav? I have been messing around with MeprUsersHelper::render_custom_fields(null, 'account'); MeprHooks::do_action('mepr-account-home-fields', $mepr_current_user); but I can't get it to display a specific checkboxes field.

@modsnap
Copy link

modsnap commented Jan 27, 2019

I'm using MemberPress in conjunction with Toolset to be able to have a visible Business Directory for our members. I would like the Account page to have a tab for a member to be able to edit their business directory listing - in much the same way that they can edit their member user account info. I have used the code above to create the tab, however, I need code to incorporate the Toolset CRED form shortcode into the functions.php file. Is it possible and if so, can you help?

@cartpauj
Copy link
Author

FYI - there's now a 3rd party plugin that does this without any coding necessary: https://meprtoolbox.com/product/account-navigation-tabs/

@ravasheen
Copy link

FYI - there's now a 3rd party plugin that does this without any coding necessary: https://meprtoolbox.com/product/account-navigation-tabs/

This company seems to be no longer active but they are supporting previous purchases :( But your code is a godsend! thank you!

@AnitaLobban
Copy link

How or where do I insert the php code into my accounts page via the plug in? Thanks
I'm new to all this php stuff

@Tri-Ryuzaki
Copy link

@AnitaLobban You will need to install and active code snippet plugin (https://wordpress.org/plugins/code-snippets/). ---> Create a new snippet and copy-paste those codes above to your snippet ---> Check on "Only run on site front-end" then hit Save . Done =)

@umm-wdc
Copy link

umm-wdc commented Feb 17, 2022

@cartpauj , is there a way to hide an existing tab eg: i want to hide the Home tab and set default tab to Subscriptions. Is that possible ?

@nfsarmento
Copy link

Hi @Tri-Ryuzaki & @cartpauj do you know how to order custom memberpress account nav items ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment