Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active October 7, 2020 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalfy/9128e03dfbd2b36f92af9c4edc950cd9 to your computer and use it in GitHub Desktop.
Save ronalfy/9128e03dfbd2b36f92af9c4edc950cd9 to your computer and use it in GitHub Desktop.
PMPro - Add Tab to ProfileGrid Plugin Profile Page
<?php
/**
* Add a membership tab to the ProfileGrid plugin. Show profile edit information.
*
* @plugin https://wordpress.org/plugins/profilegrid-user-profiles-groups-and-communities/
* @plugin https://wordpress.org/plugins/paid-memberships-pro/
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/**
* Add a tab placeholder so PMPro can integrate with ProfileGrid
*
* @param array $pm_profile_tabs_order_status Current tabs on the profile page.
*
* @return array Updated tabs for the profile page.
*/
function pmpro_pm_profile_tab( $pm_profile_tabs_order_status ) {
if ( is_array( $pm_profile_tabs_order_status ) ) {
$pm_profile_tabs_order_status['pg-pmpro'] = array(
'id' => 'pg-pmpro',
'title' => 'Memberships',
'status' => 1,
'class' => 'pg-pmpro-tab',
);
}
return $pm_profile_tabs_order_status;
}
add_filter( 'pm_profile_tabs', 'pmpro_pm_profile_tab', 10, 1 );
/**
* Add a membership tab to the profile page.
*
* @param string $id Unique tab ID.
* @param string $tab Current tab.
* @param string $uid Current UID.
* @param string $gid Current GID.
* @param string $primary_gid Primary GID.
*/
function pmpro_pm_profile_tab_link( $id, $tab, $uid, $gid, $primary_gid ) {
if ( 'pg-pmpro' !== $id ) {
return;
}
?>
<li class="pm-profile-tab pm-pad10 pg-pmpro-tab"><a class="pm-dbfl" href="#pg-pmpro">Memberships</a></li>
<?php
}
add_action( 'profile_magic_profile_tab_link', 'pmpro_pm_profile_tab_link', 10, 5 );
/**
* Show content in the memberships tab.
*
* @param string $id Unique tab ID.
* @param string $tab Current tab.
* @param string $uid Current UID.
* @param string $gid Current GID.
* @param string $primary_gid Primary GID.
*/
function pmpro_pm_profile_tab_content( $id, $tab, $uid, $gid, $primary_gid ) {
if ( 'pg-pmpro' !== $id ) {
return;
}
?>
<div id="pg-pmpro" class="pm-dbfl pg-pmpro-tab pg-profile-tab-content" style="display: none;">
<div class="pm-group-view">
<h2>Memberships</h2>
<?php echo do_shortcode( '[pmpro_member_profile_edit]' ); ?>
</div>
</div>
<?php
}
add_action( 'profile_magic_profile_tab_extension_content', 'pmpro_pm_profile_tab_content', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment