methods) ) { $methods = array( 'id' => array( $this, 'get_ad_by_id' ), 'group' => array( $this, 'get_ad_by_group' ), 'placement' => array( $this, 'get_ad_by_placement' ), ); $this->methods = apply_filters( 'advanced-ads-ad-select-methods', $methods ); } return $this->methods; } /** * Advanced ad selection methods should not directly rely on * current environment factors. * Prior to actual ad selection the meta is provided to allow for * serialised, proxied or otherwise defered selection workflows. * * @return array */ public function get_ad_arguments( $method, $id, $args = array() ) { $args = (array) $args; if ( ! isset($args['method']) ) $args['method'] = $method; if ( ! isset($args['id']) ) $args['id'] = $id; $args = apply_filters( 'advanced-ads-ad-select-args', $args ); return $args; } public function get_ad_by_method( $id, $method, $args = array() ) { $methods = $this->get_methods(); if ( ! isset($methods[ $method ]) ) { return ; } if ( ! advads_can_display_ads() ) { return ; } $args = $this->get_ad_arguments( $method, $id, $args ); return call_user_func( $methods[ $method ], $args ); } // internal public function get_ad_by_id($args) { if ( ! isset($args['id']) || $args['id'] == 0 ) { return isset($args['override']) ? $args['override'] : null; } // get ad $ad = new Advads_Ad( (int) $args['id'], $args ); // check conditions if ( $ad->can_display() ) { return $ad->output(); } } // internal public function get_ad_by_group($args) { if ( ! isset($args['id']) || $args['id'] == 0 ) { return isset($args['override']) ? $args['override'] : null; } // get ad $adgroup = new Advads_Ad_Group( (int) $args['id'] ); return $adgroup->output(); } // internal public function get_ad_by_placement($args) { if ( ! isset($args['id']) || $args['id'] == '' ) { return isset($args['override']) ? $args['override'] : null; } // get placement content return Advads_Ad_Placements::output( $args['id'] ); } }