-
-
Save anonymous/21a44de272258fc30253 to your computer and use it in GitHub Desktop.
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
/* First we need to extend main profile tabs */ | |
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 ); | |
function add_custom_profile_tab( $tabs ) { | |
$tabs['mycustomtab'] = array( | |
'name' => 'Your Portfolio', | |
'icon' => 'um-faicon-comments', | |
); | |
return $tabs; | |
} | |
function userInvestments() { | |
// Make the Wordpress database a global: | |
global $wpdb; | |
global $current_user; | |
// Get the current user: | |
get_currentuserinfo(); | |
$userID = $current_user->ID; | |
if( !empty($userID) ) | |
{ | |
// Run the query to get the Post IDs: | |
$results = $wpdb->get_results("SELECT DISTINCT(post_id) FROM wp_postmeta WHERE meta_key = 'investors_attach' AND meta_value LIKE '%\"$userID\"%'" ); | |
// $results now contains an array as follows: | |
// [ | |
// { post_id: 1 }, | |
// { post_id: 2 }, | |
// ... | |
// { post_id: 19 }, | |
// ] | |
// You will need to output the results as follows: | |
foreach( $results as $post ) | |
{ | |
echo $post->post_id; | |
} | |
} | |
} | |
/* add new tab called "mytab" */ | |
add_filter('um_account_page_default_tabs_hook', 'my_portfolio_tab_in_um', 100 ); | |
function my_portfolio_tab_in_um( $tabs ) { | |
$tabs[800]['myportfolio']['icon'] = 'um-faicon-pencil'; | |
$tabs[800]['myportfolio']['title'] = 'My Portfolio'; | |
$tabs[800]['myportfolio']['custom'] = true; | |
return $tabs; | |
} | |
/* make our new tab hookable */ | |
add_action('um_account_tab__myportfolio', 'um_account_tab__myportfolio'); | |
function um_account_tab__myportfolio( $info ) { | |
global $ultimatemember; | |
extract( $info ); | |
$output = $ultimatemember->account->get_tab_output('myportfolio'); | |
if ( $output ) { echo $output; } | |
} | |
/* Finally we add some content in the tab */ | |
add_filter('um_account_content_hook_myportfolio', 'um_account_content_hook_myportfolio'); | |
function um_account_content_hook_myportfolio( $output ){ | |
ob_start(); | |
?> | |
<div class="um-field"> | |
<h2>My Portfolio</h2> Debug | |
<?php userInvestments(); ?> | |
</div> | |
<?php | |
$output .= ob_get_contents(); | |
ob_end_clean(); | |
retur |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment