Page 1 of 1

Problem with Plugin (EVENT & USER)

Posted: 24 Jan 2024, 11:10
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? :/

Re: Problem with Plugin (EVENT & USER)

Posted: 24 Jan 2024, 13:11
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
    }

Re: Problem with Plugin (EVENT & USER)

Posted: 26 Jan 2024, 11:39
by soft177
working, thank you:)