How to prevent pager_default_initialize from getting initialized? I'm calling this function pager_default_initialize on a certain condition. But once this function gets called, it initializes default pager everywhere I return theme('pager').

What I want is

if(condition == TRUE)
pager_default_initialize($total, $limit, $element = 0) get executed
theme('pager') works!
if(condition == FALSE)
pager_default_initialize($total, $limit, $element = 0) not get executed
theme('pager') should stop work. I don't want pager when condition is FALSE.


but problem is once condition == TRUE gets satisfied, I got pager everywhere.

Any  way to uninitialize this pager function on certain condition?
The easiest way would be to override theme_pager():

function MYTHEME_pager($variables) {
  if (!pager_is_disabled()) {
    return theme_pager($variables);
  }
  return '';
}


Where pager_is_disabled() is a function you write that determines the current status. You could store that info in static vars, a Drupal variable, database, cache, whatever makes most sense for your use case.