ctools_modal_render() in a condition I have the following code in my custom.module (using it in hook_init()):

if ($js) {
  // Required includes for ctools to work:
  ctools_include('modal');
  ctools_include('ajax');
}

if (user_is_logged_in()) {
  $title = 'hello';
  $output = 'more hellos';
  ctools_modal_render($title, $output);
} else {
  return NULL;
}


Problem is if even i'm not logged it shows to me a modal windows with infinite loading text. How to unset ctools_modal_render() if i am not logged in?
You can use below code to redirect anonymous user to user login page.

if ($js) {
  // Required includes for ctools to work:
  ctools_include('modal');
  ctools_include('ajax');
}

if (user_is_logged_in()) {
  $title = 'hello';
  $output = 'more hellos';
  ctools_modal_render($title, $output);
} else {

  ctools_ajax_command_redirect('user/login');
  ctools_modal_command_dismiss();

}


Or, If you do not want to display popup to anonymous user, then you need to check user is anonymous or not before redering the ctools popup link.

&lt;?php if (user_is_logged_in()): ?&gt;
&lt;a href="your_link" class="ctools-use-modal ctools-modal-[yourpopupclass]"&gt;Link 1&lt;/a&gt;
&lt;?php else: ?&gt;
&lt;a href="user/login"&gt;Login&lt;/a&gt;
&lt;?php endif; ?&gt;