PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.31.0
Advanced Ads – Ad Manager & AdSense v1.31.0
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 / classes / ad_ajax_callbacks.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 4 years ago ad-ajax.php 5 years ago ad-debug.php 6 years ago ad-expiration.php 4 years ago ad-health-notices.php 5 years ago ad-model.php 5 years ago ad-select.php 9 years ago ad.php 4 years ago ad_ajax_callbacks.php 5 years ago ad_group.php 4 years ago ad_placements.php 4 years ago ad_type_abstract.php 5 years ago ad_type_content.php 5 years ago ad_type_dummy.php 5 years ago ad_type_group.php 5 years ago ad_type_image.php 5 years ago ad_type_plain.php 4 years ago checks.php 4 years ago compatibility.php 4 years ago display-conditions.php 4 years ago filesystem.php 8 years ago frontend-notices.php 6 years ago frontend_checks.php 4 years ago in-content-injector.php 4 years ago inline-css.php 4 years ago plugin.php 4 years ago upgrades.php 6 years ago utils.php 4 years ago visitor-conditions.php 4 years ago widget.php 4 years ago
ad_ajax_callbacks.php
551 lines
1 <?php
2
3 /**
4 * Advanced Ads.
5 *
6 * @package Advanced_Ads
7 * @author Thomas Maier <support@wpadvancedads.com>
8 * @license GPL-2.0+
9 * @link https://wpadvancedads.com
10 * @copyright 2013-2018 Thomas Maier, Advanced Ads GmbH
11 */
12
13 /**
14 * This class is used to bundle all ajax callbacks
15 *
16 * @package Advanced_Ads_Ajax_Callbacks
17 * @author Thomas Maier <support@wpadvancedads.com>
18 */
19 class Advanced_Ads_Ad_Ajax_Callbacks {
20
21 /**
22 * Advanced_Ads_Ad_Ajax_Callbacks constructor.
23 */
24 public function __construct() {
25
26 // admin only!
27 add_action( 'wp_ajax_load_ad_parameters_metabox', array( $this, 'load_ad_parameters_metabox' ) );
28 add_action( 'wp_ajax_load_visitor_conditions_metabox', array( $this, 'load_visitor_condition' ) );
29 add_action( 'wp_ajax_load_display_conditions_metabox', array( $this, 'load_display_condition' ) );
30 add_action( 'wp_ajax_advads-terms-search', array( $this, 'search_terms' ) );
31 add_action( 'wp_ajax_advads-close-notice', array( $this, 'close_notice' ) );
32 add_action( 'wp_ajax_advads-hide-notice', array( $this, 'hide_notice' ) );
33 add_action( 'wp_ajax_advads-subscribe-notice', array( $this, 'subscribe' ) );
34 add_action( 'wp_ajax_advads-activate-license', array( $this, 'activate_license' ) );
35 add_action( 'wp_ajax_advads-deactivate-license', array( $this, 'deactivate_license' ) );
36 add_action( 'wp_ajax_advads-adblock-rebuild-assets', array( $this, 'adblock_rebuild_assets' ) );
37 add_action( 'wp_ajax_advads-post-search', array( $this, 'post_search' ) );
38 add_action( 'wp_ajax_advads-ad-injection-content', array( $this, 'inject_placement' ) );
39 add_action( 'wp_ajax_advads-save-hide-wizard-state', array( $this, 'save_wizard_state' ) );
40 add_action( 'wp_ajax_advads-adsense-enable-pla', array( $this, 'adsense_enable_pla' ) );
41 add_action( 'wp_ajax_advads-ad-health-notice-display', array( $this, 'ad_health_notice_display' ) );
42 add_action( 'wp_ajax_advads-ad-health-notice-push-adminui', array( $this, 'ad_health_notice_push' ) );
43 add_action( 'wp_ajax_advads-ad-health-notice-hide', array( $this, 'ad_health_notice_hide' ) );
44 add_action( 'wp_ajax_advads-ad-health-notice-unignore', array( $this, 'ad_health_notice_unignore' ) );
45 add_action( 'wp_ajax_advads-ad-health-notice-solved', array( $this, 'ad_health_notice_solved' ) );
46 add_action( 'wp_ajax_advads-update-frontend-element', array( $this, 'update_frontend_element' ) );
47
48 }
49
50 /**
51 * Load content of the ad parameter metabox
52 *
53 * @since 1.0.0
54 */
55 public function load_ad_parameters_metabox() {
56
57 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
58 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
59 return;
60 }
61
62 $types = Advanced_Ads::get_instance()->ad_types;
63 $type_string = $_REQUEST['ad_type'];
64 $ad_id = absint( $_REQUEST['ad_id'] );
65 if ( empty( $ad_id ) ) {
66 die();
67 }
68
69 $ad = new Advanced_Ads_Ad( $ad_id );
70
71 if ( ! empty( $types[ $type_string ] ) && method_exists( $types[ $type_string ], 'render_parameters' ) ) {
72 $type = $types[ $type_string ];
73 $type->render_parameters( $ad );
74
75 $types_without_size = array( 'dummy' );
76 $types_without_size = apply_filters( 'advanced-ads-types-without-size', $types_without_size );
77 if ( ! in_array( $type_string, $types_without_size ) ) {
78 include ADVADS_BASE_PATH . 'admin/views/ad-parameters-size.php';
79 }
80
81 // set the ad type attribute if empty
82 if ( ! isset( $ad->type ) ) {
83 $ad->type = $type_string;
84 }
85
86 // extend the AJAX-loaded parameters form by ad type
87 if ( isset( $types[ $type_string ] ) ) {
88 do_action( "advanced-ads-ad-params-after-{$type_string}", $ad, $types );
89 }
90 }
91
92 die();
93
94 }
95
96 /**
97 * Load interface for single visitor condition
98 *
99 * @since 1.5.4
100 */
101 public function load_visitor_condition() {
102
103 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
104
105 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
106 return;
107 }
108
109 // get visitor condition types.
110 $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
111 $condition = array();
112 $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
113 $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
114
115 $form_name = isset( $_POST['form_name'] ) ? $_POST['form_name'] : Advanced_Ads_Visitor_Conditions::FORM_NAME;
116
117 if ( isset( $visitor_conditions[ $condition['type'] ] ) ) {
118 $metabox = $visitor_conditions[ $condition['type'] ]['metabox'];
119 } else {
120 die();
121 }
122
123 if ( method_exists( $metabox[0], $metabox[1] ) ) {
124 call_user_func( array( $metabox[0], $metabox[1] ), $condition, $index, $form_name );
125 }
126
127 die();
128 }
129
130 /**
131 * Load interface for single display condition
132 *
133 * @since 1.7
134 */
135 public function load_display_condition() {
136
137 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
138
139 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
140 return;
141 }
142
143 // get display condition types.
144 $conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
145 $condition = array();
146 $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
147 $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
148
149 $form_name = isset( $_POST['form_name'] ) ? $_POST['form_name'] : Advanced_Ads_Display_Conditions::FORM_NAME;
150
151 if ( isset( $conditions[ $condition['type'] ] ) ) {
152 $metabox = $conditions[ $condition['type'] ]['metabox'];
153 } else {
154 die();
155 }
156
157 if ( method_exists( $metabox[0], $metabox[1] ) ) {
158 call_user_func( array( $metabox[0], $metabox[1] ), $condition, $index, $form_name );
159 }
160
161 die();
162 }
163
164 /**
165 * Search terms belonging to a specific taxonomy
166 *
167 * @since 1.4.7
168 */
169 public function search_terms() {
170
171 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
172
173 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
174 return;
175 }
176
177 $args = array();
178 $taxonomy = $_POST['tax'];
179 $args = array(
180 'hide_empty' => false,
181 'number' => 20,
182 );
183
184 if ( ! isset( $_POST['search'] ) || '' === $_POST['search'] ) {
185 die();
186 }
187
188 // if search is an id, search for the term id, else do a full text search.
189 if ( 0 !== absint( $_POST['search'] ) && strlen( $_POST['search'] ) === strlen( absint( $_POST['search'] ) ) ) {
190 $args['include'] = array( absint( $_POST['search'] ) );
191 } else {
192 $args['search'] = $_POST['search'];
193 }
194
195 $results = get_terms( $taxonomy, $args );
196 echo wp_json_encode( $results );
197 echo "\n";
198 die();
199 }
200
201 /**
202 * Close a notice for good
203 *
204 * @since 1.5.3
205 */
206 public function close_notice() {
207
208 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
209
210 if (
211 ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) )
212 || empty( $_REQUEST['notice'] )
213 ) {
214 die();
215 }
216
217 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( $_REQUEST['notice'] );
218 if ( isset( $_REQUEST['redirect'] ) ) {
219 wp_safe_redirect( $_REQUEST['redirect'] );
220 exit();
221 }
222 die();
223 }
224
225 /**
226 * Hide a notice for some time (7 days right now)
227 *
228 * @since 1.8.17
229 */
230 public function hide_notice() {
231
232 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
233
234 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) )
235 || empty( $_POST['notice'] )
236 ) {
237 die();
238 }
239
240 Advanced_Ads_Admin_Notices::get_instance()->hide_notice( $_POST['notice'] );
241 die();
242 }
243
244 /**
245 * Subscribe to newsletter
246 *
247 * @since 1.5.3
248 */
249 public function subscribe() {
250
251 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
252
253 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ) ) || empty( $_POST['notice'] )
254 ) {
255 wp_send_json_error(
256 array(
257 // translators: %s is a URL.
258 'message' => sprintf( __( 'An error occurred. Please use <a href="%s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), 'http://eepurl.com/bk4z4P' ),
259 ),
260 400
261 );
262 }
263
264 wp_send_json_success( array( 'message' => Advanced_Ads_Admin_Notices::get_instance()->subscribe( $_POST['notice'] ) ) );
265 }
266
267 /**
268 * Activate license of an add-on
269 *
270 * @since 1.5.7
271 */
272 public function activate_license() {
273 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
274 return;
275 }
276
277 // check nonce.
278 check_ajax_referer( 'advads_ajax_license_nonce', 'security' );
279
280 if ( ! isset( $_POST['addon'] ) || '' === $_POST['addon'] ) {
281 die(); }
282
283 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
284 echo Advanced_Ads_Admin_Licenses::get_instance()->activate_license( $_POST['addon'], $_POST['pluginname'], $_POST['optionslug'], $_POST['license'] );
285 // phpcs:enable
286
287 die();
288 }
289
290 /**
291 * Deactivate license of an add-on
292 *
293 * @since 1.6.11
294 */
295 public function deactivate_license() {
296 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
297 return;
298 }
299
300 // check nonce.
301 check_ajax_referer( 'advads_ajax_license_nonce', 'security' );
302
303 if ( ! isset( $_POST['addon'] ) || '' === $_POST['addon'] ) {
304 die(); }
305
306 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
307 echo Advanced_Ads_Admin_Licenses::get_instance()->deactivate_license( $_POST['addon'], $_POST['pluginname'], $_POST['optionslug'] );
308 // phpcs:enable
309
310 die();
311 }
312
313 /**
314 * Rebuild assets for ad-blocker module
315 */
316 public function adblock_rebuild_assets() {
317
318 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
319
320 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
321 return;
322 }
323
324 Advanced_Ads_Ad_Blocker_Admin::get_instance()->add_asset_rebuild_form();
325 die();
326 }
327
328 /**
329 * Post search (used in Display conditions)
330 */
331 public function post_search() {
332
333 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
334
335 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
336 return;
337 }
338
339 add_filter( 'wp_link_query_args', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search' ) );
340 add_filter( 'posts_search', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search_sql' ) );
341
342 wp_ajax_wp_link_ajax();
343 }
344
345 /**
346 * Inject an ad and a placement
347 *
348 * @since 1.7.3
349 */
350 public function inject_placement() {
351
352 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
353
354 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
355 die();
356 }
357
358 $ad_id = absint( $_REQUEST['ad_id'] );
359 if ( empty( $ad_id ) ) {
360 die(); }
361
362 // use existing placement.
363 if ( isset( $_REQUEST['placement_slug'] ) ) {
364 $xml_array[] = '<placements type="array">';
365 $xml_array[] = '<item key="0" type="array">';
366 $xml_array[] = '<item type="string">ad_' . $ad_id . '</item>';
367 $xml_array[] = '<key type="string">' . $_REQUEST['placement_slug'] . '</key>';
368 $xml_array[] = '<use_existing type="boolean">1</use_existing>';
369 $xml_array[] = '</item>';
370 $xml_array[] = '</placements>';
371
372 $xml = '<advads-export>' . implode( '', $xml_array ) . '</advads-export>';
373
374 Advanced_Ads_Import::get_instance()->import( $xml );
375 if ( count( Advanced_Ads_Import::get_instance()->imported_data['placements'] ) ) {
376 // if the ad was assigned.
377 echo esc_attr( $_REQUEST['placement_slug'] );
378 };
379 die();
380 }
381
382 // create new placement.
383 $placements = Advanced_Ads::get_instance()->get_model()->get_ad_placements_array();
384
385 $type = esc_attr( $_REQUEST['placement_type'] );
386
387 $item = 'ad_' . $ad_id;
388
389 $options = array();
390
391 // check type.
392 $placement_types = Advanced_Ads_Placements::get_placement_types();
393 if ( ! isset( $placement_types[ $type ] ) ) {
394 die();
395 }
396
397 $title = $placement_types[ $type ]['title'];
398
399 $new_placement = array(
400 'type' => $type,
401 'item' => $item,
402 'name' => $title,
403 );
404
405 // set content specific options.
406 if ( 'post_content' === $type ) {
407 $index = isset( $_REQUEST['options']['index'] ) ? absint( $_REQUEST['options']['index'] ) : 1;
408 $new_placement['options'] = array(
409 'position' => 'after',
410 'index' => $index,
411 'tag' => 'p',
412 );
413 }
414
415 $slug = Advanced_Ads_Placements::save_new_placement( $new_placement );
416 // return potential slug.
417 echo esc_attr( $slug );
418
419 die();
420 }
421
422 /**
423 * Save ad wizard state for each user individually
424 *
425 * @since 1.7.4
426 */
427 public function save_wizard_state() {
428
429 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
430
431 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
432 return;
433 }
434
435 $state = ( isset( $_REQUEST['hide_wizard'] ) && 'true' === $_REQUEST['hide_wizard'] ) ? 'true' : 'false';
436
437 // get current user.
438 $user_id = get_current_user_id();
439 if ( ! $user_id ) {
440 die();
441 }
442
443 update_user_meta( $user_id, 'advanced-ads-hide-wizard', $state );
444
445 die();
446 }
447
448 /**
449 * Enable Adsense Auto ads, previously "Page-Level ads"
450 */
451 public function adsense_enable_pla() {
452
453 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
454
455 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
456 return;
457 }
458
459 $options = get_option( GADSENSE_OPT_NAME, array() );
460 $options['page-level-enabled'] = true;
461 update_option( GADSENSE_OPT_NAME, $options );
462 die();
463 }
464
465 /**
466 * Display list of Ad Health notices
467 */
468 public function ad_health_notice_display() {
469
470 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
471
472 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
473 return;
474 }
475
476 Advanced_Ads_Ad_Health_Notices::get_instance()->render_widget();
477 die();
478 }
479
480 /**
481 * Push an Ad Health notice to the queue
482 */
483 public function ad_health_notice_push() {
484
485 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
486
487 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
488 return;
489 }
490
491 $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
492 $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : array();
493
494 // update or new entry?
495 if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
496 Advanced_Ads_Ad_Health_Notices::get_instance()->update( $key, $attr );
497 } else {
498 Advanced_Ads_Ad_Health_Notices::get_instance()->add( $key, $attr );
499 }
500
501 die();
502 }
503
504 /**
505 * Hide Ad Health notice
506 */
507 public function ad_health_notice_hide() {
508 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
509
510 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
511 return;
512 }
513
514 $notice_key = ( ! empty( $_REQUEST['notice'] ) ) ? esc_attr( $_REQUEST['notice'] ) : false;
515
516 Advanced_Ads_Ad_Health_Notices::get_instance()->hide( $notice_key );
517 die();
518 }
519
520 /**
521 * Show all ignored notices of a given type
522 */
523 public function ad_health_notice_unignore() {
524 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
525
526 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) ) ) {
527 return;
528 }
529
530 Advanced_Ads_Ad_Health_Notices::get_instance()->unignore();
531 die();
532 }
533
534 /**
535 * After the user has selected a new frontend element, update the corresponding placement.
536 */
537 public function update_frontend_element() {
538 check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
539
540 if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_placements' ) ) ) {
541 return;
542 }
543
544 if ( isset( $_POST['advads']['placements'] ) ) {
545 Advanced_Ads_Placements::save_placements( $_POST['advads']['placements'] );
546 }
547
548 exit();
549 }
550 }
551