Problem with Plugin (EVENT & USER)

General discussion about MantisBT Plugins

Moderators: Developer, Contributor

Post Reply
soft177
Posts: 2
Joined: 24 Jan 2024, 11:05

Problem with Plugin (EVENT & USER)

Post by soft177 »

hello everyone,

i have problem with custom plugin

i have hook:

Code: Select all

  function hooks() {
      return array(
          'EVENT_LAYOUT_RESOURCES' => 'process_load_css',
      );
  }
  
function process_load_css($p_event) {

    $user_id = auth_get_current_user_id(); // <------ here crash application if user is not logged
    
    if ($user_id === null ) {
    	// not logged
    	$user_color_theme = 'default';
    } else {
    	// logged
    	$user_color_theme = plugin_config_get('color_theme', 'default', false, $user_id); // load color theme for specific user
    }
         
 }
 
can anyone help me how to get user_id only if user is logged in? :/
cas
Posts: 1622
Joined: 11 Mar 2006, 16:08
Contact:

Re: Problem with Plugin (EVENT & USER)

Post by cas »

Try this code:

Code: Select all

if( !auth_is_user_authenticated() ) {
	$user_color_theme = 'default';
   } else {
   	// logged in
	$user_id = auth_get_current_user_id();
    	$user_color_theme = plugin_config_get('color_theme', 'default', false, $user_id); // load color theme for specific user
    }
soft177
Posts: 2
Joined: 24 Jan 2024, 11:05

Re: Problem with Plugin (EVENT & USER)

Post by soft177 »

working, thank you:)
Post Reply