public function init()
 {
     if (!current_user_can(Advanced_Ads_Plugin::user_cap('advanced_ads_place_ads'))) {
         return;
     }
     if ('true' == get_user_option('rich_editing')) {
         add_filter('mce_external_plugins', array($this, 'add_plugin'));
         add_filter('mce_buttons', array($this, 'register_buttons'));
         add_filter('mce_external_languages', array($this, 'add_l10n'));
         add_action('wp_ajax_advads_content_for_shortcode_creator', array($this, 'get_content_for_shortcode_creator'));
     }
 }
 /**
  * update placements if sent
  *
  * @since 1.5.2
  */
 static function update_placements()
 {
     // check user permissions
     if (!current_user_can(Advanced_Ads_Plugin::user_cap('advanced_ads_manage_placements'))) {
         return;
     }
     remove_query_arg('message');
     if (isset($_POST['advads']['placement']) && check_admin_referer('advads-placement', 'advads_placement')) {
         $success = self::save_new_placement($_POST['advads']['placement']);
     }
     // save placement data
     if (isset($_POST['advads']['placements']) && check_admin_referer('advads-placement', 'advads_placement')) {
         $success = self::save_placements($_POST['advads']['placements']);
     }
     if (isset($success)) {
         $message = $success ? 'updated' : 'error';
         wp_redirect(add_query_arg(array('message' => $message)));
     }
 }
 /**
  * load interface for single visitor condition
  *
  * @since 1.5.4
  */
 public function load_visitor_condition()
 {
     if (!current_user_can(Advanced_Ads_Plugin::user_cap('advanced_ads_edit_ads'))) {
         return;
     }
     // get visitor condition types
     $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
     $condition = array();
     $condition['type'] = isset($_POST['type']) ? $_POST['type'] : '';
     $condition['connector'] = isset($_POST['connector']) ? $_POST['connector'] : '';
     $index = isset($_POST['index']) ? $_POST['index'] : 0;
     if (isset($visitor_conditions[$condition['type']])) {
         $metabox = $visitor_conditions[$condition['type']]['metabox'];
     } else {
         die;
     }
     if (method_exists($metabox[0], $metabox[1])) {
         call_user_func(array($metabox[0], $metabox[1]), $condition, $index);
     }
     die;
 }
 /**
  * bulk update groups
  *
  */
 public function update_groups()
 {
     // check nonce
     if (!isset($_POST['advads-group-update-nonce']) || !wp_verify_nonce($_POST['advads-group-update-nonce'], 'update-advads-groups')) {
         return new WP_Error('invalid_ad_group', __('Invalid Ad Group', 'advanced-ads'));
     }
     // check user rights
     if (!current_user_can(Advanced_Ads_Plugin::user_cap('advanced_ads_edit_ads'))) {
         return new WP_Error('invalid_ad_group_rights', __('You don’t have permission to change the ad groups', 'advanced-ads'));
     }
     // iterate through groups
     if (isset($_POST['advads-groups']) && count($_POST['advads-groups'])) {
         // empty group settings
         update_option('advads-ad-groups', array());
         foreach ($_POST['advads-groups'] as $_group_id => $_group) {
             // save basic wp term
             wp_update_term($_group_id, Advanced_Ads::AD_GROUP_TAXONOMY, $_group);
             // save ad weights
             $group = new Advanced_Ads_Group($_group['id']);
             if (isset($_group['ads'])) {
                 $group->save_ad_weights($_group['ads']);
             }
             // save other attributes
             $type = isset($_group['type']) ? $_group['type'] : 'default';
             $ad_count = isset($_group['ad_count']) ? $_group['ad_count'] : 1;
             $options = isset($_group['options']) ? $_group['options'] : array();
             // allow other add-ons to save their own group attributes
             $atts = apply_filters('advanced-ads-group-save-atts', array('type' => $type, 'ad_count' => $ad_count, 'options' => $options), $_group);
             $group->save($atts);
         }
     }
     // reload groups
     $this->load_groups();
     return true;
 }
 /**
  * initiate the admin notices class
  *
  * @since 1.5.3
  */
 public function admin_notices()
 {
     // display ad block warning to everyone who can edit ads
     if (current_user_can(Advanced_Ads_Plugin::user_cap('advanced_ads_edit_ads'))) {
         if ($this->screen_belongs_to_advanced_ads()) {
             include ADVADS_BASE_PATH . 'admin/views/notices/adblock.php';
         }
     }
     if (current_user_can(Advanced_Ads_Plugin::user_cap('advanced_ads_edit_ads'))) {
         $this->notices = Advanced_Ads_Admin_Notices::get_instance();
     }
 }