Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Help in PHP Code

  1. #1
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help in PHP Code

    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:

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    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;
    		
    	}
    }
    
    	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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    yes it return an error

    Code:
    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

  4. #4
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    This is the complete code if it helps thanks John

    Code:
    <?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);
    	}

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

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

    Code:
    else {
    		
    		function add_custom_profile_tab3( $downloadtab ) {
     
    		$downloadtab['download'] = array(
    			'name' => ' ',
    			'icon' => ' ',
    		);
    		
    		return $downloadtab;
    		
    	}	
    		
     }
    or just:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Roberto Sousa (04-21-2015)

  7. #6
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #7
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    with this code

    Code:
    else {
    		
    		function add_custom_profile_tab3( $downloadtab ) {
    		
    		return null;
    		
    	}	
    		
     }
    disappears all the tabs

  9. #8
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    do you think we can use ?

    Code:
    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/2...merce-products

    thanks
    Last edited by Roberto Sousa; 04-20-2015 at 08:15 PM.

  10. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Maybe. I think you should be asking these questions here:

    https://ultimatemember.com/forums/
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Roberto Sousa (04-21-2015)

  12. #10
    Join Date
    Apr 2015
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    thanks John

    they don't help for custom stuff

    kind regards

    Roberto Sousa

Similar Threads

  1. Replies: 3
    Last Post: 05-12-2011, 03:43 AM
  2. Secret code / hidden message / obfuscated code - ???
    By newbie01.others in forum JavaScript
    Replies: 2
    Last Post: 01-14-2011, 11:29 AM
  3. Replies: 15
    Last Post: 06-11-2009, 12:27 PM
  4. Replies: 2
    Last Post: 10-27-2008, 05:16 AM
  5. Help - Code discrepency - Full Screen code
    By kurson in forum Dynamic Drive scripts help
    Replies: 17
    Last Post: 05-23-2006, 05:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •