Log in

View Full Version : Help in PHP Code



Roberto Sousa
04-20-2015, 05:18 PM
Hey guys

Need help on a php code i want to hide the tab created for the rest of the users and show only to user role doctor.

i have the following code:


// Download Tab
add_filter('um_profile_tabs', 'add_custom_profile_tab3', 4 );
$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if($role=='doctor'){

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => 'Downloads',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}
}
else {

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => 'Downloads',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}

}

add_action('um_profile_content_download_default', 'um_profile_content_download_default');
function um_profile_content_download_default( $args ) {

$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if ($role == 'doctor' ){
echo do_shortcode('[br]');
echo do_shortcode('[job_dashboard]');
}

}



what should i do on the red section of the code to hide the tab for user with the name client?

i will appreciate the help

kind regards

Roberto Sousa

jscheuer1
04-20-2015, 05:30 PM
The red section is not the entire section, the final closing brace (}) for it is almost on the margin. I would first try simply getting rid of all of it. If you already tried that without its final closing brace, that would have made an error. Even with the final closing brace, removing it might cause an error, if it does, we would need to see more of the code in order to suggest further what to do. Change what's in your post to:


// Download Tab
add_filter('um_profile_tabs', 'add_custom_profile_tab3', 4 );
$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if($role=='doctor'){

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => 'Downloads',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}
}

add_action('um_profile_content_download_default', 'um_profile_content_download_default');
function um_profile_content_download_default( $args ) {

$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if ($role == 'doctor' ){
echo do_shortcode('[br]');
echo do_shortcode('[job_dashboard]');
}

}

If there's still a problem, let me know.

Roberto Sousa
04-20-2015, 05:35 PM
yes it return an error


Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'add_custom_profile_tab3' not found or invalid function name in /home/sites/rmmedics.com/public_html/wp-includes/plugin.php on line 213

Roberto Sousa
04-20-2015, 05:36 PM
This is the complete code if it helps thanks John


<?php

/***
*** @Main tabs
***/
add_filter('um_profile_tabs', 'um_profile_tabs', 1 );
function um_profile_tabs( $tabs ) {

$tabs['main'] = array(
'name' => __('About','ultimatemember'),
'icon' => 'um-faicon-user'
);

return $tabs;
}

// Submit Job Tab
add_filter('um_profile_tabs', 'add_custom_profile_tab', 2 );
$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if($role=='client'){

function add_custom_profile_tab( $historytab ) {

$historytab['history'] = array(
'name' => 'Submit Job',
'icon' => 'um-faicon-bookmark'
);

return $historytab;

}

}

else{
function add_custom_profile_tab( $historytab ) {

$historytab['history'] = array(
'name' => 'Jobs',
'icon' => 'um-faicon-bookmark'
);

return $historytab;

}

}

add_action('um_profile_content_history_default', 'um_profile_content_history_default');
function um_profile_content_history_default( $args ) {

$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if ($role == 'client' ){
echo do_shortcode('[br]');
echo do_shortcode('[submit_job_form]');
}

else {
echo do_shortcode('[br]');
echo do_shortcode('[jobs]');
}

}

// Job Dashboard Tab
add_filter('um_profile_tabs', 'add_custom_profile_tab2', 3 );
$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if($role=='client'){

function add_custom_profile_tab2( $bookmarktab ) {

$bookmarktab['lineage'] = array(
'name' => 'Job Dashboard',
'icon' => 'um-faicon-bookmark',
);

return $bookmarktab;

}
}
else{

function add_custom_profile_tab2( $bookmarktab ) {

$bookmarktab['lineage'] = array(
'name' => 'Upload Timesheet',
'icon' => 'um-faicon-bookmark',
);

return $bookmarktab;

}

}

add_action('um_profile_content_lineage_default', 'um_profile_content_lineage_default');
function um_profile_content_lineage_default( $args ) {

$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if ($role == 'client' ){
echo do_shortcode('[br]');
echo do_shortcode('[job_dashboard]');
}

else {
echo do_shortcode('[br]');
echo do_shortcode('[wtf_fu_upload deny_public_uploads="1" accept_file_types="jpg|jpeg|png|pdf|JPG|JPEG|PNG|PDF" deny_file_types="htaccess|php|php3|php4|php5|cgi|aspx|asp|aspx|sh|phtml|shtml|pl|py|pyc|pyo" inline_file_types="jpg|jpeg|png|pdf|JPG|JPEG|PNG|PDF" image_file_types="jpg|jpeg|png|pdf|JPG|JPEG|PNG|PDF" max_file_size="5" max_number_of_files="30" auto_orient="1" create_medium_images="0" medium_width="800" medium_height="600" thumbnail_crop="1" thumbnail_width="50" thumbnail_height="50"]');

}

}

// Download Tab
add_filter('um_profile_tabs', 'add_custom_profile_tab3', 4 );
$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if($role=='doctor'){

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => 'Downloads',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}
}
else {

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => 'Downloads',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}

}

add_action('um_profile_content_download_default', 'um_profile_content_download_default');
function um_profile_content_download_default( $args ) {

$current_user = wp_get_current_user()->id;
$key = 'role';
$single = true;
//print_r($current_user);
$role = get_user_meta( $current_user, $key,$single );

//print_r($role);

if ($role == 'doctor' ){
echo do_shortcode('[br]');
echo do_shortcode('[job_dashboard]');
}

}

/***
*** @dynamic profile page title
***/
add_filter('wp_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
function um_dynamic_user_profile_pagetitle( $title, $sep = '' ) {
global $paged, $page, $ultimatemember;

$profile_title = um_get_option('profile_title');

if ( um_is_core_page('user') && um_get_requested_user() ) {

um_fetch_user( um_get_requested_user() );

$profile_title = $ultimatemember->mail->convert_tags( $profile_title );

$title = $profile_title;

um_reset_user();

}

return $title;
}

/***
*** @try and modify the page title in page
***/
add_filter('the_title', 'um_dynamic_user_profile_title', 100000, 2 );
function um_dynamic_user_profile_title( $title, $id = '' ) {
global $ultimatemember;

if( is_admin() )
return $title;

if ( $id == $ultimatemember->permalinks->core['user'] ) {
if ( um_is_core_page('user') && um_get_requested_user() ) {
$title = um_get_display_name( um_get_requested_user() );
} else if ( um_is_core_page('user') && is_user_logged_in() ) {
$title = um_get_display_name( get_current_user_id() );
}
}

return (strlen($title)!==strlen(utf8_decode($title))) ? $title : utf8_encode($title);
}

jscheuer1
04-20-2015, 06:52 PM
Hmm, that's not the whole code because I don't see the function add_filter. I see it used a lot, but I don't see it. If I could, I might be able to figure out how to have it make a blank tab. I might not.

All the error shows is that we need a function named function add_custom_profile_tab3. We could try one that returns null or an empty array (the others seem to return arrays), or an array with one empty member and another member that might make add_filter happy.

Like maybe:


else {

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => ' ',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}

}

or:


else {

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => ' ',
'icon' => ' ',
);

return $downloadtab;

}

}

or just:


else {

function add_custom_profile_tab3( $downloadtab ) {

return null;

}

}

If none of those work, I would have to see the add_filter function (and perhaps others it uses) to get a better idea what it expects.

Roberto Sousa
04-20-2015, 07:59 PM
im using ultimate member plugin for wordpress and i have created 2 user roles client and doctor

they share the same tabs and with the code that i have done i manage to show different name on the same tab and different content on the same tab

but i have the last tab with the name downloads that i want to show to user doctor and to hide for user client

if i take the else code

it shows the tab wen im login with doctor with no problem

the error message only shows wen im login with user client

Roberto Sousa
04-20-2015, 08:01 PM
with this code


else {

function add_custom_profile_tab3( $downloadtab ) {

return null;

}

}

disappears all the tabs

Roberto Sousa
04-20-2015, 08:08 PM
do you think we can use ?


unset( $tabs['custom_profile_tab3'] );

how can i add this to the code to see if it works?

i saw this comment on the above link and it looks similar to the code i have...

http://stackoverflow.com/questions/26884272/hide-custom-tab-when-no-content-is-present-in-woocommerce-products

thanks

jscheuer1
04-21-2015, 12:48 AM
Maybe. I think you should be asking these questions here:

https://ultimatemember.com/forums/

Roberto Sousa
04-21-2015, 08:06 AM
thanks John

they don't help for custom stuff

kind regards

Roberto Sousa

jscheuer1
04-21-2015, 04:15 PM
They did have help on a construct very similar to what you have there - multiple tabs. I don't think what you're doing is that far off. Have you tried?

Where is this add_filter function? Being unfamiliar with this plug-in, I would need to see at least what it looks like (as I said, and possibly other functions it depends upon) to figure out how to make it happy while also producing no tab or a hidden tab.

If you're sure the forum for this plug-in will not support what you are attempting, perhaps try Stack-Overflow. At least someone there seems somewhat familiar with the plug-in.

I don't think anyone here has that experience, without that we would need to see more code as I've already indicated. As for the unset command, how to write it and where to put it, if I had to guess I would write it and place it like so (addition highlighted):


else {

function add_custom_profile_tab3( $downloadtab ) {

$downloadtab['download'] = array(
'name' => 'Downloads',
'icon' => 'um-faicon-bookmark',
);

return $downloadtab;

}
unset( $downloadtab['download'] );
}

But again, experience with this plug-in would be a big plus in figuring this out. I have no idea if this use of unset would work here.