is_main_query() ) { add_filter( 'the_content', 'adredux_insert_adonpage', 99 ); } } ); // remove the filter when main loop ends add_action( 'loop_end', function( WP_Query $query ) { if ( has_filter( 'the_content', 'adredux_insert_adonpage' ) ) { remove_filter( 'the_content', 'adredux_insert_adonpage' ); } } ); } public function adredux_load_scripts() { $stylesheet = adredux_get_option('adredux_stylesheet')[0]; if ( isset ($stylesheet) && ($stylesheet == 'no') ) return; wp_register_style( 'adredux-adstyles', plugins_url( '/css/adstyles.css', __FILE__ ) ); wp_enqueue_style( 'adredux-adstyles' ); } public function adredux_header_codes() { $headercode = adredux_get_option('adredux_header_codes', ''); if ( isset ($headercode) && ($headercode != '') ){ _e ( '', 'adredux'); echo $headercode; } } public function adredux_footer_codes() { $footercode = adredux_get_option('adredux_footer_codes'); if ( !isset ($footercode) || ($footercode == '') ) return; _e ( '', 'adredux'); echo $footercode; } public function adredux_pagelevel_adcode() { $pagelevelad = adredux_get_option('adredux_pagelevel_adcode', ''); if ( !isset ($pagelevelad) || ($pagelevelad == '') ){ return; } else { $showads = adredux_get_option('adredux_showads')[0]; if ( isset ($showads) && ($showads == '0') ) { return; } elseif ( isset ($showads) && ($showads == '1') && is_user_logged_in() ) { return; } elseif ( isset ($showads) && ($showads == '2') && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { return; } else { $ad_page = adredux_get_option('ad_page')[0]; $exclude_categories = adredux_get_option('exclude_categories', array('0')); $exclude_tags = adredux_get_option('exclude_tags', array('0')); if ( (is_singular()) && ( ($ad_page == 'posts') || ($ad_page == 'both') ) && (!in_category($exclude_categories)) && (!has_tag($exclude_tags)) ){ _e ( '', 'adredux'); echo $pagelevelad; } elseif ( (is_page()) && ( ($ad_page == 'pages') || ($ad_page == 'both') ) ) { _e ( '', 'adredux'); echo $pagelevelad; } else { return; } } } } public function adredux_create_settings_page() { // Add the menu item and page $page_title = __('Ad Redux', 'adredux'); $menu_title = __('Ad Redux', 'adredux'); $capability = 'manage_options'; $slug = 'adredux_settings'; $callback = array( $this, 'adredux_settings_page_content' ); $icon = 'dashicons-admin-plugins'; $position = 100; add_menu_page( $page_title, $menu_title, $capability, $slug, $callback, $icon, $position ); add_submenu_page( $slug, __('Ad Redux Settings', 'adredux'), __('General Settings', 'adredux'), $capability, $slug, $callback ); add_submenu_page( $slug, __('About Ad Redux', 'adredux'), __('About Ad Redux', 'adredux'), $capability, 'adredux_settings_ads', array( $this, 'adredux_settings_adpage_content' ) ); } public function adredux_settings_page_content() {?>

adredux_admin_notice(); } ?>
Set up your advertisements and display preferences for the website.

', 'adredux'); ?>
Set up your advertisements and display preferences for the website.', 'adredux'); ?> <?php echo $plugininfo['Name'];?>

adredux_admin_notice(); } ?>
<?php echo $plugininfo['Name'];?>
  • Use Adsense or Other Custom Codes
  • Insert advertisements at effective locations
    • Above content
    • After first/second para
    • Middle of posts
    • End of content
  • Define ad alignment styles: left, right, center or random
  • Set ad section width to make responsive advertisement codes show large rectangle box for better visibility
  • Exclude posts in certain categories from ads
  • Saves all the settings in serialized form in just one adredux_settings option in WordPress settings to avoid clutter
  • No clutter in database: the plugin data is deleted from your website when you deactive and delete the plugin

  • Ad Redux Settings Data

    Here is the raw data as saved in the WordPress options settings of your website. All of your Ad Redux settings are saved in WordPress options, in the adredux_settings option.

    ','adredux'); ?>

    ', 'adredux'); break; case 'adredux_pagelevel_ads': case 'adredux_adcode_one': case 'adredux_adcode_two': case 'adredux_adcode_three': case 'adredux_adcode_four': case 'adredux_adcode_five': case 'adredux_adcode_six': case 'adredux_adcode_seven': case 'adredux_adcode_eight': echo __('Please add the advertisement codes to start showing the ads.
    ', 'adredux'); break; } } public function adredux_setup_fields() { //Settings Name Must Be Same As Below $adredux_settings_name = 'adredux_settings'; // WordPress Categories via an Array $adredux_categories = array(); $categories = get_categories('hide_empty=0&orderby=name'); $adredux_categories[0] = __(' - Select - ', 'adredux'); foreach ($categories as $category_list) { $adredux_categories[$category_list->cat_ID] = $category_list->cat_name; } // WordPress Tags via an Array $adredux_tags = array(); $tags = get_tags('hide_empty=0&orderby=name'); $adredux_tags[0] = __(' - Select - ', 'adredux'); foreach ($tags as $tag_list) { $adredux_tags[$tag_list->term_id] = $tag_list->name; } $fields = array( array( 'uid' => 'ad_page', 'label' => __('Display Ads On:', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'select', 'options' => array( 'posts' => __('Posts', 'adredux'), 'pages' => __('Pages', 'adredux'), 'both' => __('Both Posts & Pages', 'adredux'), ), 'placeholder' => '', 'helper' => '', 'supplimental' => '', 'default' => array('posts') ), array( 'uid' => 'min_words', 'label' => __('Words for Mid Content Ad', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'text', 'placeholder' => '300', 'helper' => '', 'supplimental' => __('Set the minimum word count for displaying ads in the middle of the articles. By default, we use 300 words.', 'adredux'), 'default' => '300' ), array( 'uid' => 'min_paras', 'label' => __('Paras for Mid Content Ad', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'text', 'placeholder' => '5', 'helper' => '', 'supplimental' => __('Set the minimum number of paragraphs for displaying ads in the middle of the articles. By default, we use 5 paras.', 'adredux'), 'default' => '5' ), array( 'uid' => 'exclude_categories', 'label' => __('Hide Ads - Categories', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'multiselect', 'options' => $adredux_categories, 'placeholder' => '', 'helper' => '', 'supplimental' => __('Select the post categories to exclude from displaying ads.', 'adredux'), 'default' => array('') ), array( 'uid' => 'exclude_tags', 'label' => __('Hide Ads - Tags', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'multiselect', 'options' => $adredux_tags, 'placeholder' => '', 'helper' => '', 'supplimental' => __('Select the post tags to exclude from displaying ads.', 'adredux'), 'default' => array('') ), array( 'uid' => 'exclude_postids', 'label' => __('Hide Ads on Specific Post & Page IDs', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'text', 'placeholder' => '1,2,3', 'helper' => '', 'supplimental' => __('Add comma-separated list of post & page IDs to exclude from displaying ads.', 'adredux'), 'default' => '' ), array( 'uid' => 'adredux_stylesheet', 'label' => __('Ad Style', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'radio', 'options' => array( 'no' => __('Disable Plugin Styles', 'adredux'), 'yes' => __('Enable Plugin Styles', 'adredux'), ), 'placeholder' => '', 'helper' => '', 'supplimental' => __('Select the disable option if you want to use custom styles your advertisement blocks.', 'adredux'), 'default' => array('yes') ), array( 'uid' => 'adredux_header_codes', 'label' => __('Header Insert (Scripts/Styles)', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'textarea', 'placeholder' => '', 'helper' => '', 'supplimental' => __('Insert common styles and scripts across the website in the <head>.', 'adredux'), 'default' => '' ), array( 'uid' => 'adredux_footer_codes', 'label' => __('Footer Insert (Scripts)', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'textarea', 'placeholder' => '', 'helper' => '', 'supplimental' => __('Insert common scripts for output in the HTML code, just before the closing </body>.', 'adredux'), 'default' => '' ), array( 'uid' => 'adredux_showads', 'label' => __('Auto-Insert Ads', 'adredux'), 'section' => 'adredux_general_settings', 'type' => 'radio', 'options' => array( '0' => __('Disable Ads', 'adredux'), '1' => __('Disable Ads for All Logged-in Users', 'adredux'), '2' => __('Disable Ads for Authors, Editors & Admin Users (Subscribers Excluded)', 'adredux'), '3' => __('Show Ads for Everyone', 'adredux'), ), 'placeholder' => '', 'helper' => '', 'supplimental' => __('By default, ads not shown to logged-in users, including subscribers, authors, editors & admins.', 'adredux'), 'default' => array('1') ), ); foreach( $fields as $field ){ add_settings_field( $adredux_settings_name.'['.$field['uid'].']', $field['label'], array( $this, 'field_callback' ), 'adredux_settings', $field['section'], $field ); } //Adsense Page_level Ad Code Field $adfields[] = array( 'uid' => 'adredux_pagelevel_adcode', 'label' => __('Page-Level Ads', 'adredux'), 'section' => 'adredux_pagelevel_ads', 'type' => 'textarea', 'placeholder' => '', 'helper' => '', 'supplimental' => __('Insert Google Adsense Page-Level Ads code to be included within <head>.', 'adredux'), 'default' => '' ); // Define the Number of Ad Slots Via Array // Must Be Same Number As the Number of Sections Defined Earlier $adslots = array('one','two','three','four', 'five','six','seven', 'eight'); foreach ($adslots as $adslot) { $adfields[] = array( 'uid' => 'adcode_'.$adslot, 'label' => __('Ad Code', 'adredux'), 'section' => 'adredux_adcode_'.$adslot, 'type' => 'textarea', 'placeholder' => '', 'helper' => '', 'supplimental' => __('Add the advertisement code here. Do NOT include <p></p> in any of the ad codes when using the second para ad location.', 'adredux'), 'default' => '', ); $adfields[] = array( 'uid' => 'adcode_location_'.$adslot, 'label' => __('Display Location', 'adredux'), 'section' => 'adredux_adcode_'.$adslot, 'type' => 'select', 'options' => array( 'before-content' => __('Before Content', 'adredux'), 'after-para-one' => __('Content - After First Paragraph', 'adredux'), 'after-para-two' => __('Content - After Second Paragraph', 'adredux'), 'after-para-three' => __('Content - After Third Paragraph', 'adredux'), 'after-para-secondlast' => __('Content - After Second Last Paragraph', 'adredux'), 'mid-content' => __('Mid Content', 'adredux'), 'after-content' => __('After Content', 'adredux'), ), 'placeholder' => '', 'helper' => '', 'supplimental' => '', 'default' => array('before-content') ); $adfields[] = array( 'uid' => 'adcode_align_'.$adslot, 'label' => __('Alignment', 'adredux'), 'section' => 'adredux_adcode_'.$adslot, 'type' => 'select', 'options' => array( 'alignleft' => __('Left', 'adredux'), 'alignright' => __('Right', 'adredux'), 'aligncenter' => __('Center', 'adredux'), 'leftright' => __('Random (Left/Right)', 'adredux'), 'random' => __('Random (All)', 'adredux'), ), 'placeholder' => '', 'helper' => '', 'supplimental' => '', 'default' => array('center') ); $adfields[] = array( 'uid' => 'adcode_maxwidth_'.$adslot, 'label' => __('Max Width', 'adredux'), 'section' => 'adredux_adcode_'.$adslot, 'type' => 'text', 'placeholder' => '', 'helper' => __('Pixels', 'adredux'), 'supplimental' => __('Set the maximum width (400px recommended) for responsive ads. Leave blank to use container width.', 'adredux'), 'default' => '' ); } //var_dump($adfields); foreach( $adfields as $key=>$adfield ){ add_settings_field( $adredux_settings_name.'['.$adfield['uid'].']', $adfield['label'], array( $this, 'field_callback' ), 'adredux_settings', $adfield['section'], $adfield ); } register_setting( 'adredux_settings', $adredux_settings_name ); register_setting( 'adredux_settings_ads', $adredux_settings_name ); } public function field_callback( $arguments ) { //Settings Name Must Be Same As Above $adredux_settings_name = 'adredux_settings'; $settings = get_option( $adredux_settings_name ); if ( isset( $settings[$arguments['uid']] ) ) { $value = $settings[$arguments['uid']]; } else { $value = $arguments['default']; } switch( $arguments['type'] ){ case 'password': case 'text': printf( '', $adredux_settings_name.'['.$arguments['uid'].']', $arguments['type'], $arguments['placeholder'], $value ); break; case 'number': printf( '', $adredux_settings_name.'['.$arguments['uid'].']', $arguments['type'], $arguments['placeholder'], $value ); break; case 'textarea': printf( '', $adredux_settings_name.'['.$arguments['uid'].']', $arguments['placeholder'], $value ); break; case 'select': case 'multiselect': if( ! empty ( $arguments['options'] ) && is_array( $arguments['options'] ) ){ $attributes = ''; $options_markup = ''; foreach( $arguments['options'] as $key => $label ){ $options_markup .= sprintf( '', $key, selected( $value[ array_search( $key, $value, false ) ], $key, false ), $label ); } if( $arguments['type'] === 'multiselect' ){ $attributes = ' multiple="multiple" '; } printf( '', $adredux_settings_name.'['.$arguments['uid'].']', $attributes, $options_markup ); } break; case 'radio': case 'checkbox': if( ! empty ( $arguments['options'] ) && is_array( $arguments['options'] ) ){ $options_markup = ''; $iterator = 0; foreach( $arguments['options'] as $key => $label ){ $iterator++; $options_markup .= sprintf( '
    ', $adredux_settings_name.'['.$arguments['uid'].']', $arguments['type'], $key, checked( $value[ array_search( $key, $value, true ) ], $key, false ), $label, $iterator ); } printf( '
    %s
    ', $options_markup ); } break; } if( $helper = $arguments['helper'] ){ printf( ' %s', $helper ); } if( $supplimental = $arguments['supplimental'] ){ printf( '

    %s

    ', $supplimental ); } } } new Adredux_Plugin();