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 |