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