Created
February 13, 2023 03:56
-
-
Save ipokkel/c4d2ae67d10c0bb16649eede36ba3e61 to your computer and use it in GitHub Desktop.
Shortcode to display a link to the member's User Page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shortcode to display a link to the member's User Page. | |
* | |
* Usage: [pmpro_user_page_link link_text="Example Link Text"] | |
* | |
* 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/ | |
*/ | |
function my_pmpro_user_page_link_shortcode( $atts ) { | |
extract( | |
shortcode_atts( | |
array( | |
'link_text' => 'My User Page', | |
), | |
$atts | |
) | |
); | |
global $current_user; | |
$user_page_id = get_user_meta( $current_user->ID, 'pmproup_user_page', true ); | |
$user_page_link = ''; | |
if ( ! empty( $user_page_id ) ) { | |
$user_page_link = '<a href=' . get_permalink( $user_page_id ) . '>' . $link_text . '</a>'; | |
} | |
return $user_page_link; | |
} | |
add_shortcode( 'pmpro_user_page_link', 'my_pmpro_user_page_link_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment