' . PHP_EOL; echo '' . PHP_EOL; }, 0); /** * Add client script */ add_action('wp_footer', function(){ echo '' . PHP_EOL; }); /** * Register widgets */ add_action('widgets_init', function() { require WP_PLUGIN_DIR . '/adsinserter/widgets/placement.php'; register_widget( 'AdsInserter_Placement_Widget' ); }); /** * Add options page in admin dashboard */ if ( is_admin() ) { $aiOptionsPage = new AdsInserter_Options(); } /** * In text placement */ add_filter('the_content', function($content){ if (is_feed()) { return $content; } if (function_exists('is_amp_endpoint') && is_amp_endpoint()) { return $content; } $options = get_option(AdsInserter_Options::OPTIONS); if (!$options) { return $content; } $options = array_merge([ AdsInserter_Options::OPTION_INTEXT_ENABLED => false, AdsInserter_Options::OPTION_INTEXT_PLACEMENT_ID => 0, AdsInserter_Options::OPTION_INTEXT_START => 1, AdsInserter_Options::OPTION_INTEXT_DENSITY => 3, ], $options); if (!$options[AdsInserter_Options::OPTION_INTEXT_ENABLED]) { return $content; } if (!$options[AdsInserter_Options::OPTION_INTEXT_PLACEMENT_ID]) { return $content; } if (!$options[AdsInserter_Options::OPTION_INTEXT_DENSITY]) { return $content; } $p_array = explode('
', $content); $p_count = count($p_array); $out_content = ''; $counter = 0; $aiPlacementCode = sprintf( '', $options[AdsInserter_Options::OPTION_INTEXT_PLACEMENT_ID] ); for ($i = 0; $i < $p_count; $i++) { $out_content .= $p_array[ $i ] . ''; if (function_exists('mb_strlen')) { if (!mb_strlen(trim($p_array[ $i ]))) { continue; } } else { if (!strlen(trim($p_array[ $i ]))) { continue; } } if ($i >= $options[ AdsInserter_Options::OPTION_INTEXT_START ]) { if (! ( $counter % $options[ AdsInserter_Options::OPTION_INTEXT_DENSITY ] )) { $out_content .= $aiPlacementCode; } $counter++; } } return $out_content; }, 20);