PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.10
Advanced Ads – Ad Manager & AdSense v1.10
2.0.26 2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / modules / gadsense / admin / admin.php
advanced-ads / modules / gadsense / admin Last commit date
assets 8 years ago views 8 years ago admin.php 8 years ago
admin.php
412 lines
1 <?php
2
3 class Advanced_Ads_AdSense_Admin {
4
5 private $data;
6 private $nonce;
7 private static $instance = null;
8 protected $notice = null;
9 private $settings_page_hook = 'advanced-ads-adsense-settings-page';
10
11 const ADSENSE_NEW_ACCOUNT_LINK = 'https://www.google.com/adsense/start/?utm_source=AdvancedAdsPlugIn&utm_medium=partnerships&utm_campaign=AdvancedAdsPartner';
12
13 private function __construct() {
14 $this->data = Advanced_Ads_AdSense_Data::get_instance();
15 add_action( 'advanced-ads-settings-init', array($this, 'settings_init') );
16 // add_action( 'advanced-ads-additional-settings-form', array($this, 'settings_init') );
17 add_filter('advanced-ads-setting-tabs', array($this, 'setting_tabs'));
18
19 add_action( 'admin_enqueue_scripts', array($this, 'enqueue_scripts') );
20 add_action( 'admin_print_scripts', array($this, 'print_scripts') );
21 add_filter( 'advanced-ads-list-ad-size', array($this, 'ad_details_column'), 10, 2 );
22 add_filter( 'advanced-ads-ad-settings-pre-save', array($this, 'sanitize_ad_settings') );
23 add_filter( 'advanced-ads-ad-notices', array($this, 'ad_notices'), 10, 3 );
24 }
25
26 public function ad_details_column($size, $the_ad) {
27 if ( 'adsense' == $the_ad->type ) {
28 $content = json_decode( $the_ad->content );
29 if ( $content && 'responsive' == $content->unitType ) { $size = __( 'Responsive', 'advanced-ads' ); }
30 }
31 return $size;
32 }
33
34 public function print_scripts() {
35 global $pagenow, $post_type;
36 if (
37 ('post-new.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type) ||
38 ('post.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type && isset($_GET['action']) && 'edit' == $_GET['action'])
39 ) {
40 $db = Advanced_Ads_AdSense_Data::get_instance();
41 $pub_id = $db->get_adsense_id();
42 ?>
43 <script type="text/javascript">
44 var gadsenseData = {
45 pubId : '<?php echo $pub_id; ?>',
46 pageLevelEnabled: '<?php echo $db->is_page_level_enabled(); ?>',
47 msg : {
48 unknownAd : '<?php esc_attr_e( "The ad details couldn't be retrieved from the ad code", 'advanced-ads' ); ?>',
49 pubIdMismatch : '<?php _e( 'Warning : The AdSense account from this code does not match the one set with the Advanced Ads Plugin. This ad might cause troubles when used in the front end.', 'advanced-ads' ); ?>',
50 pageLevelEnabled: '<?php _e( sprintf(__( 'Page-Level ads are already activated in the <a href="%s">AdSense settings</a>. No need to add them manually.', 'advanced-ads' ), admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ) ); ?>',
51 pageLevelDisabled: '<?php
52 printf( '%s <button id="adsense_enable_pla" type="button" class="button">%s</button>',
53 esc_attr__( 'This type of ad code is set up in the AdSense settings. Click on the following button to enable it now.', 'advanced-ads' ),
54 esc_attr__( 'Activate', 'advanced-ads' ) ); ?>'
55 },
56 pagenow: '<?php echo $pagenow ?>',
57 };
58 </script>
59 <?php
60 }
61 }
62
63 public function enqueue_scripts() {
64 global $gadsense_globals, $pagenow, $post_type;
65 $screen = get_current_screen();
66 $plugin = Advanced_Ads_Admin::get_instance();
67 if (
68 ('post-new.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type) ||
69 ('post.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type && isset($_GET['action']) && 'edit' == $_GET['action'])
70 ) {
71 $default_script = array(
72 'path' => GADSENSE_BASE_URL . 'admin/assets/js/new-ad.js',
73 'dep' => array('jquery'),
74 'version' => null,
75 );
76
77 $scripts = array(
78 'gadsense-new-ad' => $default_script,
79 );
80
81 // Allow modifications of script files to enqueue
82 $scripts = apply_filters( 'advanced-ads-gadsense-ad-param-script', $scripts );
83
84 foreach ( $scripts as $handle => $value ) {
85 if ( empty($handle) ) {
86 continue;
87 }
88 if ( ! empty($handle) && empty($value) ) {
89 // Allow inclusion of WordPress's built-in script like jQuery
90 wp_enqueue_script( $handle );
91 } else {
92 if ( ! isset($value['version']) ) { $value['version'] = null; }
93 wp_enqueue_script( $handle, $value['path'], $value['dep'], $value['version'] );
94 }
95 }
96
97 $styles = array();
98
99 // Allow modifications of default style files to enqueue
100 $styles = apply_filters( 'advanced-ads-gadsense-ad-param-style', $styles );
101
102 foreach ( $styles as $handle => $value ) {
103 if ( ! isset($value['path']) ||
104 ! isset($value['dep']) ||
105 empty($handle)
106 ) {
107 continue;
108 }
109 if ( ! isset($value['version']) ) {
110 $value['version'] = null; }
111 wp_enqueue_style( $handle, $value['path'], $value['dep'], $value['version'] );
112 }
113 }
114 }
115
116 public static function get_instance() {
117 if ( null == self::$instance ) {
118 self::$instance = new self;
119 }
120 return self::$instance;
121 }
122
123 public function settings_init() {
124
125 // get settings page hook
126 $hook = $this->settings_page_hook;
127
128 register_setting( ADVADS_SLUG . '-adsense', ADVADS_SLUG . '-adsense', array($this, 'sanitize_settings') );
129
130 // add new section
131 add_settings_section(
132 'advanced_ads_adsense_setting_section',
133 '', //__( 'AdSense', 'advanced-ads' ),
134 array($this, 'render_settings_section_callback'),
135 $hook
136 );
137
138 // add setting field to disable ads
139 add_settings_field(
140 'adsense-id',
141 __( 'AdSense account', 'advanced-ads' ),
142 array($this, 'render_settings_adsense_id'),
143 $hook,
144 'advanced_ads_adsense_setting_section'
145 );
146
147 // activate AdSense verification code and Auto ads (previously Page-Level ads)
148 add_settings_field(
149 'adsense-page-level',
150 __( 'Verification code & Auto ads', 'advanced-ads' ),
151 array($this, 'render_settings_adsense_page_level'),
152 $hook,
153 'advanced_ads_adsense_setting_section'
154 );
155
156 // add setting field for adsense limit
157 add_settings_field(
158 'adsense-limit',
159 __( 'Limit to 3 ads', 'advanced-ads' ),
160 array($this, 'render_settings_adsense_limit'),
161 $hook,
162 'advanced_ads_adsense_setting_section'
163 );
164
165 // disable AdSense violation warnings
166 add_settings_field(
167 'adsense-warnings-disable',
168 __( 'Disable violation warnings', 'advanced-ads' ),
169 array($this, 'render_settings_adsense_warnings_disable'),
170 $hook,
171 'advanced_ads_adsense_setting_section'
172 );
173
174 add_settings_field(
175 'adsense-background',
176 __( 'Transparent background', 'advanced-ads' ),
177 array( $this, 'render_settings_adsense_background' ),
178 $hook,
179 'advanced_ads_adsense_setting_section'
180 );
181
182 $adsense_id = $this->data->get_adsense_id();
183
184 // if ( !empty( $adsense_id ) ) {
185
186 // add_settings_field(
187 // 'adsense-mapi',
188 // __( 'Google AdSense Management API', 'advanced-ads' ),
189 // array( $this, 'render_settings_management_api' ),
190 // $hook,
191 // 'advanced_ads_adsense_setting_section'
192 // );
193
194 // }
195 // hook for additional settings from add-ons
196 do_action( 'advanced-ads-adsense-settings-init', $hook );
197 }
198
199 /**
200 * render adsense settings section
201 *
202 * @since 1.5.1
203 */
204 public function render_settings_section_callback(){
205 // for whatever purpose there might come
206 }
207
208 /**
209 * render adsense management api setting
210 */
211 public function render_settings_management_api() {
212 require_once GADSENSE_BASE_PATH . 'admin/views/mapi-settings.php';
213 }
214
215 /**
216 * render adsense id setting
217 *
218 * @since 1.5.1
219 */
220 public function render_settings_adsense_id(){
221 require_once GADSENSE_BASE_PATH . 'admin/views/adsense-account.php';
222 }
223
224 /**
225 * render adsense limit setting
226 *
227 * @since 1.5.1
228 */
229 public function render_settings_adsense_limit(){
230 $limit_per_page = $this->data->get_limit_per_page();
231
232 ?><label><input type="checkbox" name="<?php echo GADSENSE_OPT_NAME; ?>[limit-per-page]" value="1" <?php checked( $limit_per_page ); ?> />
233 <?php printf( __( 'Limit to %d AdSense ads', 'advanced-ads' ), 3 ); ?></label>
234 <p class="description">
235 <?php
236 printf(
237 __( 'There is no explicit limit for AdSense ads anymore, but you can still use this setting to prevent too many AdSense ads to show accidentally on your site.', 'advanced-ads' ),
238 esc_url( 'https://www.google.com/adsense/terms' )
239 ); ?></p>
240 <?php if( defined( 'AAP_VERSION' ) ) : /* give warning when cache-busting in Pro is active */ ?>
241 <p class="advads-error-message"><?php _e( 'Due to technical restrictions, the limit does not work on placements with cache-busting enabled.', 'advanced-ads' ); ?></p>
242 <?php endif;
243 }
244
245 /**
246 * render page-level ads setting
247 *
248 * @since 1.6.9
249 */
250 public function render_settings_adsense_page_level(){
251 $options = $this->data->get_options();
252 $page_level = $options['page-level-enabled'];
253
254 ?><label><input type="checkbox" name="<?php echo GADSENSE_OPT_NAME; ?>[page-level-enabled]" value="1" <?php checked( $page_level ); ?> />
255 <?php _e( 'Insert the AdSense header code used for verification and the Auto Ads feature.', 'advanced-ads' ); ?></label>
256 <p class="description"><?php printf(__( 'This code might also activate Auto ads. Please read <a href="%s" target="_blank">this article</a> if <strong>ads appear in random places</strong>.', 'advanced-ads' ), ADVADS_URL . 'adsense-in-random-positions-auto-ads/#utm_source=advanced-ads&utm_medium=link&utm_campaign=backend-autoads-ads' ); ?></p><?php
257 }
258
259 /**
260 * render AdSense violation warnings setting
261 *
262 * @since 1.6.9
263 */
264 public function render_settings_adsense_warnings_disable(){
265 $options = $this->data->get_options();
266 $disable_violation_warnings = isset( $options['violation-warnings-disable'] ) ? 1 : 0;
267
268 ?><label><input type="checkbox" name="<?php echo GADSENSE_OPT_NAME; ?>[violation-warnings-disable]" value="1" <?php checked( 1, $disable_violation_warnings ); ?> />
269 <?php _e( 'Disable warnings about potential violations of the AdSense terms.', 'advanced-ads' ); ?></label>
270 <p class="description"><?php printf(__( 'Our <a href="%s" target="_blank">Ad Health</a> 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' ); ?></p><?php
271 }
272
273 /**
274 * Render transparent background setting.
275 */
276 public function render_settings_adsense_background() {
277 $options = $this->data->get_options();
278 $background = $options['background'];
279
280 ?><label><input type="checkbox" name="<?php echo GADSENSE_OPT_NAME; ?>[background]" value="1" <?php checked( $background ); ?> />
281 <?php _e( 'Enable this option in case your theme adds an unfortunate background color to AdSense ads.', 'advanced-ads' ); ?></label><?php
282 }
283
284 /**
285 * sanitize adsense settings
286 *
287 * @since 1.5.1
288 * @param array $options all the options
289 */
290 public function sanitize_settings($options){
291
292 // sanitize whatever option one wants to sanitize
293 if(isset($options['adsense-id']) && $options['adsense-id'] != ''){
294 // remove "ca-" prefix if it was added by the user
295 if( 0 === strpos( $options['adsense-id'], 'ca-' ) ){
296 $options['adsense-id'] = str_replace( 'ca-', '', $options['adsense-id'] );
297 }
298
299 if( 0 !== strpos( $options['adsense-id'], 'pub-' ) ){
300 // add settings error
301 add_settings_error(
302 'adsense-limit',
303 'settings_updated',
304 __( 'The Publisher ID has an incorrect format. (must start with "pub-")', 'advanced-ads' ));
305 }
306 // trim publisher id
307 $options['adsense-id'] = trim($options['adsense-id']);
308 }
309
310 return $options;
311 }
312
313 /**
314 * add adsense setting tab
315 *
316 * @since 1.5.1
317 * @param arr $tabs existing setting tabs
318 * @return arr $tabs setting tabs with AdSense tab attached
319 */
320 public function setting_tabs(array $tabs){
321
322 $tabs['adsense'] = array(
323 'page' => $this->settings_page_hook,
324 'group' => ADVADS_SLUG . '-adsense',
325 'tabid' => 'adsense',
326 'title' => __( 'AdSense', 'advanced-ads' )
327 );
328
329 return $tabs;
330 }
331
332 /**
333 * sanitize ad settings
334 * save publisher id from new ad unit if not given in main options
335 *
336 * @since 1.6.2
337 * @param arr $ad_settings_post
338 * @return arr $ad_settings_post
339 */
340 public function sanitize_ad_settings( array $ad_settings_post ){
341
342 // check ad type
343 if( ! isset( $ad_settings_post['type'] ) || 'adsense' !== $ad_settings_post['type'] ){
344 return $ad_settings_post;
345 }
346
347 // save AdSense publisher ID if given and remove it from options
348 if ( ! empty($ad_settings_post['output']['adsense-pub-id']) ) {
349 // get options
350 $adsense_options = get_option( 'advanced-ads-adsense', array() );
351 $adsense_options['adsense-id'] = $ad_settings_post['output']['adsense-pub-id'];
352
353 // save adsense options including publisher id
354 update_option( 'advanced-ads-adsense', $adsense_options );
355
356 }
357 unset( $ad_settings_post['output']['adsense-pub-id'] );
358
359 return $ad_settings_post;
360 }
361
362 /**
363 * show AdSense ad specific notices in parameters box
364 *
365 * @since 1.7.22
366 */
367 public function ad_notices( $notices, $box, $post ){
368
369 $ad = new Advanced_Ads_Ad( $post->ID );
370
371 // $content = json_decode( stripslashes( $ad->content ) );
372
373 switch ($box['id']){
374 case 'ad-parameters-box' :
375 // add warning if this is a responsive ad unit without custom sizes and position is set to left or right
376 // hidden by default and made visible with JS
377 $notices[] = array(
378 'text' => sprintf(__( 'Responsive AdSense ads don’t work reliably with <em>Position</em> set to left or right. Either switch the <em>Type</em> to "normal" or follow <a href="%s" target="_blank">this tutorial</a> 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' ),
379 'class' => 'advads-ad-notice-responsive-position error hidden',
380 );
381 // show hint about AdSense In-feed add-on
382 if( ! class_exists( 'Advanced_Ads_In_Feed', false ) ){
383 $notices[] = array(
384 'text' => sprintf(__( '<a href="%s" target="_blank">Install the free AdSense In-feed add-on</a> 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') ),
385 'class' => 'advads-ad-notice-in-feed-add-on hidden',
386 );
387 }
388 // show message about Responsive add-on
389 if ( ! defined( 'AAR_SLUG' ) ) {
390 $notices[] = array(
391 'text' => sprintf( __( 'Use the <a href="%s" target="_blank">Responsive add-on</a> 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' ),
392 'class' => 'advads-ad-notice-responsive-add-on',
393 );
394 }
395
396 // show hint about Content ad, Link unit or Matched content being defined in AdSense account
397 // disabled since it might no longer be needed with the new ad types
398 /* if( 'adsense' === $ad->type ){
399 $notices[] = array(
400 'text' => sprintf( __( 'The type of your AdSense ad unit (content unit, link unit or matched content) needs to be defined in <a href="%s" target="_blank">your AdSense account</a>.', 'advanced-ads' ), 'https://www.google.com/adsense' ),
401 'class' => 'advads-ad-notice-adsense-ad-unit-type',
402 );
403 }*/
404 break;
405 }
406
407
408 return $notices;
409 }
410
411 }
412