/** * injected ad into content (before and after) * displays ALL ads * * @since 1.1.0 * @param str $content post content */ public function inject_content($content = '') { // run only within the loop on single pages of public post types $public_post_types = get_post_types(array('public' => true, 'publicly_queryable' => true), 'names', 'or'); // check if admin allows injection in all places $options = $this->plugin->options(); if (!isset($options['content-injection-everywhere'])) { // check if this is a singular page within the loop if (!is_singular($public_post_types) || !in_the_loop()) { return $content; } } $placements = get_option('advads-ads-placements', array()); if (!apply_filters('advanced-ads-can-inject-into-content', true, $content, $placements)) { return $content; } foreach ($placements as $_placement_id => $_placement) { if (empty($_placement['item']) || !isset($_placement['type'])) { continue; } $_options = isset($_placement['options']) ? $_placement['options'] : array(); switch ($_placement['type']) { case 'post_top': // TODO broken: does not serve placement but serves ad directly $content = Advanced_Ads_Select::get_instance()->get_ad_by_method($_placement_id, Advanced_Ads_Select::PLACEMENT, $_options) . $content; break; case 'post_bottom': $content .= Advanced_Ads_Select::get_instance()->get_ad_by_method($_placement_id, Advanced_Ads_Select::PLACEMENT, $_options); break; case 'post_content': $content = Advanced_Ads_Placements::inject_in_content($_placement_id, $_options, $content); break; } } return $content; }