__( 'AdSense In-feed', 'advanced-ads-adsense-in-feed' ), 'description' => __( 'Display an AdSense In-feed ad between posts', 'advanced-ads-adsense-in-feed' ), 'image' => plugin_dir_url( __FILE__ ) . 'adsense-in-feed.png', 'options' => array( 'show_position' => true, 'show_lazy_load' => true ) ); return $types; } /** * echo ad before/after posts in loops on archive pages * * @since 1.0 * @param arr $post post object * @param WP_Query $wp_query query object */ public function inject_in_feed( $post, $wp_query = null ) { if ( ! $wp_query instanceof WP_Query || is_feed() || is_admin() || $wp_query->is_singular() || ! $wp_query->in_the_loop || ! isset( $wp_query->current_post ) || ! $wp_query->is_main_query() ){ return; } $curr_index = $wp_query->current_post + 1; // normalize index // handle the situation when wp_reset_postdata() is used after secondary query inside main query static $handled_indexes = array(); if ( isset( $handled_indexes[ $curr_index ] ) ) { return; } $handled_indexes[] = $curr_index; $placements = get_option( 'advads-ads-placements', array() ); if( is_array( $placements ) ){ foreach ( $placements as $_placement_id => $_placement ){ if ( empty($_placement['item']) ) { continue; } if ( isset($_placement['type']) && 'adsense_in_feed' === $_placement['type'] ){ $_options = isset( $_placement['options'] ) ? $_placement['options'] : array(); $ad_index = isset( $_options['adsense_in_feed_pages_index'] ) ? absint( ( $_options['adsense_in_feed_pages_index'] ) ) : 1; if( $ad_index === $curr_index ){ $_options['placement']['type'] = $_placement['type']; if( isset( $_placement['item'] ) && $this->is_infeed_ad_item( $_placement['item'] ) ) { echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options ); } } } } } } /** * check if the current ad is indeed an infeed item * * @param str item ID from a placement * @return bool true if it is an infeed ad */ private function is_infeed_ad_item( $item_id ){ $_item = explode( '_', $item_id ); if ( 'ad' !== $_item[0] || ! isset( $_item[1] ) || empty( $_item[1] ) ) { return false; } // load the ad $ad = new Advanced_Ads_Ad( $_item[1] ); if( isset( $ad->type ) && 'adsense' === $ad->type && isset( $ad->content) && strpos( $ad->content, 'in-feed' ) ){ return true; } return false; } public function show_advads_version_notice() { $plugin_data = get_plugin_data(__FILE__); $plugins = get_plugins(); if( isset( $plugins['advanced-ads/advanced-ads.php'] ) ){ // is installed, but not active $link = ''. __('Activate Now', 'advanced-ads-adsense-in-feed') .''; } else { $link = ''. __('Install Now', 'advanced-ads-adsense-in-feed') .''; } echo '
'.sprintf(__('%s requires the Advanced Ads plugin to be installed and activated on your site.', 'advanced-ads-adsense-in-feed'), $plugin_data['Name']) . ' ' . $link . '