I have a class which loads the image sliders on some add_action. There is a function/method "render_slider" which renders the sliders on the page based on the slider selected. The theme tries to get the image slider object before the sliders are loaded.

I tried with init,plugins_loaded,to load the slider.

But still I get the error object not found

class Sliders {
  public function __construct() {
    add_filter( 'add_sliders', array( $this, 'add_sliders' ) );
  public function add_sliders($sliders) {
  public function  load_sliders() {  
     $sliders_to_load = apply_filters( 'add_sliders', array() );
     foreach ( $sliders_to_load as $slider )
        $this->sliders[ $slider->id ] = $slider;
  public function render_slider($slider_type = ''){  
          case 'rotator' : $rotator = $this->sliders[$slider_type];break; //Object Not Found
          default: break;
  • when you construct the class? i.e. when you call new Sliders? – gmazzap Apr 1 '14 at 16:49
  • Instance is created by the action init – B L Praveen Apr 1 '14 at 17:07
  • 1
    That's your problem. 'plugins_loaded' is triggered before than 'init'. So when you create an the Slider instance and add hook to 'plugins_loaded' it does nothing: you can't add a function to an hook that have been already fired... use 'plugins_loaded' to create the instance, and inside __construct use add_filter('after_setup_theme',array($this,'load_sliders'),10); – gmazzap Apr 1 '14 at 17:28
  • I created instanse on action plugins_loaded and then I load the sliders on action after_theme_setup. Till here it works fine. It loads the slider. Then again I get the object not found. I checked the code it loads the slider only once. Dont know where I am missing? – B L Praveen Apr 2 '14 at 7:58
  • You should load the slides once, and then use all the times you need. You don't say how are you using the slider (from a shortcode? from template tag?) nor what the add_slider method actually does... – gmazzap Apr 2 '14 at 15:33

setup_theme run on init theme, before after_setup_theme.

The follow order on frontend, was fired in my test:

  1. load_textdomain
  2. plugins_loaded
  3. auth_cookie_valid
  4. set_current_user
  5. sanitize_comment_cookies
  6. setup_theme
  7. after_setup_theme
  8. init
  • Thanks in listing the actions trigger list in sequence. I instance the slider using plugins_loaded and the load the slider using after_setup_theme. but still the object is not found. while rendering the slider. (Sliders are loaded after_setup_theme and again intialized to empty). – B L Praveen Apr 2 '14 at 8:02
  • If you want to be sure, than trigger the same hook with different priority, like slider via priority 10 on after_setup_theme and render slider via priority 11 on after_setup_theme. – bueltge Apr 2 '14 at 13:06
  • when the admin_enqueue_scripts action is triggerd? – B L Praveen Apr 3 '14 at 9:44
  • Is after_setup_theme is triggerd in ajax call? – B L Praveen Apr 3 '14 at 9:55
  • Maybe, but the right hook is wp_ajax_* – bueltge Apr 4 '14 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.