Jump to content

Help on PHP Code


RobertoSousa

Recommended Posts

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

	else {
		
		function add_custom_profile_tab3( $downloadtab ) {
 
		$downloadtab['download'] = array(
			'name' => 'Downloads',
			'icon' => 'um-faicon-bookmark',
		);
		
		return $downloadtab;
		
	}

section of the code to hide the tab for user with the name client?

i will appreciate the help

kind regards 

Roberto Sousa

Edited by RobertoSousa
Link to comment
Share on other sites

I'm probably missing something, but it sounds like you only want to show a tab if the user's role is "docotor". Is that correct?

 

If so, you could just remove the "else" portion. So basically you would have something like this:

<?php
//...
 
if($role=='doctor'){
    function add_custom_profile_tab3( $downloadtab ) {
        $downloadtab['download'] = array(
            'name' => 'Downloads',
            'icon' => 'um-faicon-bookmark',
        );
        
        return $downloadtab;
    }
}
 
//...
?>
Edited by cyberRobot
Link to comment
Share on other sites

for what i can see is that wen i use 

    function add_custom_profile_tab3( $downloadtab )

it register the tab

 

but if i use the code to show only for user doctor

if($role=='doctor'){
    function add_custom_profile_tab3( $downloadtab ) {
        $downloadtab['download'] = array(
            'name' => 'Downloads',
            'icon' => 'um-faicon-bookmark',
        );
        
        return $downloadtab;
    }
}

on the doctor profile i can see the tab and is content

 

and the error message only shows if im login with user client 

 

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

 

and the complete code of this php file is 

<?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);
	}
Link to comment
Share on other sites

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

 

It looks like you're trying to call a function that doesn't exist. If you only plan to define the function when $role is set to "doctor", you'll need to also suppress the function call. You could use function_exists(), for example, to see if the function is defined before calling it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.