data = Advanced_Ads_AdSense_Data::get_instance(); add_action( 'advanced-ads-settings-init', array($this, 'settings_init') ); // add_action( 'advanced-ads-additional-settings-form', array($this, 'settings_init') ); add_filter('advanced-ads-setting-tabs', array($this, 'setting_tabs')); add_action( 'admin_enqueue_scripts', array($this, 'enqueue_scripts') ); add_action( 'admin_print_scripts', array($this, 'print_scripts') ); add_filter( 'advanced-ads-list-ad-size', array($this, 'ad_details_column'), 10, 2 ); add_filter( 'advanced-ads-ad-settings-pre-save', array($this, 'sanitize_ad_settings') ); add_filter( 'advanced-ads-ad-notices', array($this, 'ad_notices'), 10, 3 ); } public function ad_details_column($size, $the_ad) { if ( 'adsense' == $the_ad->type ) { $content = json_decode( $the_ad->content ); if ( $content && 'responsive' == $content->unitType ) { $size = __( 'Responsive', 'advanced-ads' ); } } return $size; } public function print_scripts() { global $pagenow, $post_type; if ( ('post-new.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type) || ('post.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type && isset($_GET['action']) && 'edit' == $_GET['action']) ) { $db = Advanced_Ads_AdSense_Data::get_instance(); $pub_id = $db->get_adsense_id(); ?> GADSENSE_BASE_URL . 'admin/assets/js/new-ad.js', 'dep' => array('jquery'), 'version' => null, ); $scripts = array( 'gadsense-new-ad' => $default_script, ); // Allow modifications of script files to enqueue $scripts = apply_filters( 'advanced-ads-gadsense-ad-param-script', $scripts ); foreach ( $scripts as $handle => $value ) { if ( empty($handle) ) { continue; } if ( ! empty($handle) && empty($value) ) { // Allow inclusion of WordPress's built-in script like jQuery wp_enqueue_script( $handle ); } else { if ( ! isset($value['version']) ) { $value['version'] = null; } wp_enqueue_script( $handle, $value['path'], $value['dep'], $value['version'] ); } } $styles = array(); // Allow modifications of default style files to enqueue $styles = apply_filters( 'advanced-ads-gadsense-ad-param-style', $styles ); foreach ( $styles as $handle => $value ) { if ( ! isset($value['path']) || ! isset($value['dep']) || empty($handle) ) { continue; } if ( ! isset($value['version']) ) { $value['version'] = null; } wp_enqueue_style( $handle, $value['path'], $value['dep'], $value['version'] ); } } } public static function get_instance() { if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } public function settings_init() { // get settings page hook $hook = $this->settings_page_hook; register_setting( ADVADS_SLUG . '-adsense', ADVADS_SLUG . '-adsense', array($this, 'sanitize_settings') ); // add new section add_settings_section( 'advanced_ads_adsense_setting_section', '', //__( 'AdSense', 'advanced-ads' ), array($this, 'render_settings_section_callback'), $hook ); // add setting field to disable ads add_settings_field( 'adsense-id', __( 'AdSense account', 'advanced-ads' ), array($this, 'render_settings_adsense_id'), $hook, 'advanced_ads_adsense_setting_section' ); // activate AdSense verification code and Auto ads (previously Page-Level ads) add_settings_field( 'adsense-page-level', __( 'Verification code & Auto ads', 'advanced-ads' ), array($this, 'render_settings_adsense_page_level'), $hook, 'advanced_ads_adsense_setting_section' ); // AdSense anchor ad on top of pages. add_settings_field( 'top_anchor_ad', __( 'Auto ads', 'advanced-ads' ) . ': ' . __( 'Disable top anchor ad', 'advanced-ads' ), array( $this, 'render_settings_adsense_top_anchor_ad' ), $hook, 'advanced_ads_adsense_setting_section' ); // add setting field for adsense limit // deprecated of January, 2019; will be removed one year later $limit_per_page = $this->data->get_limit_per_page(); if( $limit_per_page ){ add_settings_field( 'adsense-limit', __( 'Limit to 3 ads', 'advanced-ads' ), array($this, 'render_settings_adsense_limit'), $hook, 'advanced_ads_adsense_setting_section' ); }; // disable AdSense violation warnings add_settings_field( 'adsense-warnings-disable', __( 'Disable violation warnings', 'advanced-ads' ), array($this, 'render_settings_adsense_warnings_disable'), $hook, 'advanced_ads_adsense_setting_section' ); add_settings_field( 'adsense-background', __( 'Transparent background', 'advanced-ads' ), array( $this, 'render_settings_adsense_background' ), $hook, 'advanced_ads_adsense_setting_section' ); $adsense_id = $this->data->get_adsense_id(); // if ( !empty( $adsense_id ) ) { // add_settings_field( // 'adsense-mapi', // __( 'Google AdSense Management API', 'advanced-ads' ), // array( $this, 'render_settings_management_api' ), // $hook, // 'advanced_ads_adsense_setting_section' // ); // } // hook for additional settings from add-ons do_action( 'advanced-ads-adsense-settings-init', $hook ); } /** * render adsense settings section * * @since 1.5.1 */ public function render_settings_section_callback(){ // for whatever purpose there might come } /** * render adsense management api setting */ public function render_settings_management_api() { require_once GADSENSE_BASE_PATH . 'admin/views/mapi-settings.php'; } /** * render adsense id setting * * @since 1.5.1 */ public function render_settings_adsense_id(){ require_once GADSENSE_BASE_PATH . 'admin/views/adsense-account.php'; } /** * render adsense limit setting * * @since 1.5.1 * @deprecated January, 2019 – let’s give users one year until we remove the whole logic completely */ public function render_settings_adsense_limit(){ $limit_per_page = $this->data->get_limit_per_page(); ?>

data->get_options(); $anchor_ad = isset( $options['top-anchor-ad'] )? $options['top-anchor-ad'] : ''; ?> data->get_options(); $page_level = $options['page-level-enabled']; ?>

this article if ads appear in random places.', 'advanced-ads' ), ADVADS_URL . 'adsense-in-random-positions-auto-ads/#utm_source=advanced-ads&utm_medium=link&utm_campaign=backend-autoads-ads' ); ?>

data->get_options(); $disable_violation_warnings = isset( $options['violation-warnings-disable'] ) ? 1 : 0; ?>

Ad Health feature monitors if AdSense is implemented correctly on your site. It also considers ads not managed with Advanced Ads. Enable this option to remove these checks', 'advanced-ads' ), ADVADS_URL . 'manual/ad-health/#utm_source=advanced-ads&utm_medium=link&utm_campaign=backend-autoads-ads' ); ?>

data->get_options(); $background = $options['background']; ?> $this->settings_page_hook, 'group' => ADVADS_SLUG . '-adsense', 'tabid' => 'adsense', 'title' => __( 'AdSense', 'advanced-ads' ) ); return $tabs; } /** * sanitize ad settings * save publisher id from new ad unit if not given in main options * * @since 1.6.2 * @param arr $ad_settings_post * @return arr $ad_settings_post */ public function sanitize_ad_settings( array $ad_settings_post ){ // check ad type if( ! isset( $ad_settings_post['type'] ) || 'adsense' !== $ad_settings_post['type'] ){ return $ad_settings_post; } // save AdSense publisher ID if there is no one stored yet if ( ! empty($ad_settings_post['output']['adsense-pub-id']) ) { // get options $adsense_options = get_option( 'advanced-ads-adsense', array() ); if ( empty( $adsense_options['adsense-id'] ) ) { $adsense_options['adsense-id'] = $ad_settings_post['output']['adsense-pub-id']; update_option( 'advanced-ads-adsense', $adsense_options ); } } unset( $ad_settings_post['output']['adsense-pub-id'] ); return $ad_settings_post; } /** * show AdSense ad specific notices in parameters box * * @since 1.7.22 */ public function ad_notices( $notices, $box, $post ){ $ad = new Advanced_Ads_Ad( $post->ID ); // $content = json_decode( stripslashes( $ad->content ) ); switch ($box['id']){ case 'ad-parameters-box' : // add warning if this is a responsive ad unit without custom sizes and position is set to left or right // hidden by default and made visible with JS $notices[] = array( 'text' => sprintf(__( 'Responsive AdSense ads don’t work reliably with Position set to left or right. Either switch the Type to "normal" or follow this tutorial if you want the ad to be wrapped in text.', 'advanced-ads' ), ADVADS_URL . 'adsense-responsive-custom-sizes/#utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-custom-sizes-tutorial' ), 'class' => 'advads-ad-notice-responsive-position error hidden', ); // show hint about AdSense In-feed add-on if( ! class_exists( 'Advanced_Ads_In_Feed', false ) ){ $notices[] = array( 'text' => sprintf(__( 'Install the free AdSense In-feed add-on in order to place ads between posts.', 'advanced-ads' ), wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . 'advanced-ads-adsense-in-feed'), 'install-plugin_' . 'advanced-ads-adsense-in-feed') ), 'class' => 'advads-ad-notice-in-feed-add-on hidden', ); } // show message about Responsive add-on if ( ! defined( 'AAR_SLUG' ) ) { $notices[] = array( 'text' => sprintf( __( 'Use the Responsive add-on in order to define the exact size for each browser width or choose between horizontal, vertical, or rectangle formats.', 'advanced-ads' ), ADVADS_URL . 'add-ons/responsive-ads/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-adsense' ), 'class' => 'advads-ad-notice-responsive-add-on', ); } // show hint about Content ad, Link unit or Matched content being defined in AdSense account // disabled since it might no longer be needed with the new ad types /* if( 'adsense' === $ad->type ){ $notices[] = array( 'text' => sprintf( __( 'The type of your AdSense ad unit (content unit, link unit or matched content) needs to be defined in your AdSense account.', 'advanced-ads' ), 'https://www.google.com/adsense' ), 'class' => 'advads-ad-notice-adsense-ad-unit-type', ); }*/ break; } return $notices; } /** * Enqueue AdSense connection script. */ public static function enqueue_connect_adsense() { if ( ! wp_script_is( 'advads/connect-adsense', $list = 'registered' ) ) { wp_enqueue_script( 'advads/connect-adsense', GADSENSE_BASE_URL . 'admin/assets/js/connect-adsense.js', array( 'jquery' ), '0.8' ); } if ( ! has_action( 'admin_footer', array( 'Advanced_Ads_AdSense_Admin', 'print_connect_adsense' ) ) ) { add_action( 'admin_footer', array( 'Advanced_Ads_AdSense_Admin', 'print_connect_adsense' ) ); } } /** * Prints AdSense connection markup. */ public static function print_connect_adsense() { require_once GADSENSE_BASE_PATH . 'admin/views/connect-adsense.php'; } /** * Get Auto Ads messages. */ public static function get_auto_ads_messages() { return array( 'enabled' => sprintf(__( 'The AdSense verification and Auto ads code is already activated in the AdSense settings.', 'advanced-ads' ), admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ) . ' ' . __( 'No need to add the code manually here, unless you want to include it into certain pages only.', 'advanced-ads' ), 'disabled' => sprintf( '%s ', sprintf ( __( 'The AdSense verification and Auto ads code should be set up in the AdSense settings. Click on the following button to enable it now.', 'advanced-ads' ), admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ), esc_attr__( 'Activate', 'advanced-ads' ) ) ); } /** * Get the ad selecto markup * * @param type $hide_idle Whether to hide idle ads. */ public static function get_mapi_ad_selector( $hide_idle_ads = true ) { require_once GADSENSE_BASE_PATH . 'admin/views/mapi-ad-selector.php'; } }