PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.22.0
Advanced Ads – Ad Manager & AdSense v1.22.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 / admin / class-advanced-ads-admin.php
advanced-ads / admin Last commit date
assets 5 years ago includes 5 years ago views 5 years ago class-advanced-ads-admin.php 5 years ago
class-advanced-ads-admin.php
742 lines
1 <?php
2 /**
3 * Advanced Ads main admin class
4 *
5 * @package Advanced_Ads_Admin
6 * @author Thomas Maier <support@wpadvancedads.com>
7 * @license GPL-2.0+
8 * @link https://wpadvancedads.com
9 * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10 *
11 * Plugin class. This class should ideally be used to work with the
12 * administrative side of the WordPress site.
13 */
14 class Advanced_Ads_Admin {
15
16 /**
17 * Instance of this class.
18 *
19 * @var object
20 */
21 protected static $instance = null;
22
23 /**
24 * Instance of admin notice class.
25 *
26 * @var object $notices
27 */
28 protected $notices = null;
29
30 /**
31 * Slug of the settings page
32 *
33 * @var string $plugin_screen_hook_suffix
34 */
35 public $plugin_screen_hook_suffix = null;
36
37 /**
38 * General plugin slug
39 *
40 * @var string
41 */
42 protected $plugin_slug = '';
43
44 /**
45 * Admin settings.
46 *
47 * @var array
48 */
49 protected static $admin_settings = null;
50
51 /**
52 * Initialize the plugin by loading admin scripts & styles and adding a
53 * settings page and menu.
54 */
55 private function __construct() {
56 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
57 new Advanced_Ads_Ad_Ajax_Callbacks();
58 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded_ajax' ) );
59 } else {
60 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
61 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 100 );
62 Advanced_Ads_Ad_List_Filters::get_instance();
63 }
64 // add shortcode creator to TinyMCE.
65 Advanced_Ads_Shortcode_Creator::get_instance();
66 Advanced_Ads_Admin_Licenses::get_instance();
67 }
68
69 /**
70 * License handling legacy code after moving license handling code to Advanced_Ads_Admin_Licenses
71 *
72 * @param string $addon slug of the add-on.
73 * @param string $plugin_name name of the add-on.
74 * @param string $options_slug slug of the options the plugin is saving in the options table.
75 *
76 * @return mixed 1 on success or string with error message.
77 * @since version 1.7.16 (early January 2017)
78 */
79 public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) {
80 return Advanced_Ads_Admin_Licenses::get_instance()->deactivate_license( $addon, $plugin_name, $options_slug );
81 }
82
83 /**
84 * Get license status.
85 *
86 * @param string $slug slug of the add-on.
87 *
88 * @return string license status
89 */
90 public function get_license_status( $slug = '' ) {
91 return Advanced_Ads_Admin_Licenses::get_instance()->get_license_status( $slug );
92 }
93
94 /**
95 * Actions and filter available after all plugins are initialized.
96 */
97 public function wp_plugins_loaded() {
98 // call $plugin_slug from public plugin class.
99 $plugin = Advanced_Ads::get_instance();
100 $this->plugin_slug = $plugin->get_plugin_slug();
101
102 add_action( 'current_screen', array( $this, 'current_screen' ) );
103
104 // Load admin style sheet and JavaScript.
105 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
106 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 9 );
107
108 // update placements.
109 add_action( 'admin_init', array( 'Advanced_Ads_Placements', 'update_placements' ) );
110
111 // add Advanced Ads admin notices
112 // removes admin notices from other plugins
113 // `in_admin_header` is the last hook to run before àdmin_notices` according to https://codex.wordpress.org/Plugin_API/Action_Reference.
114 add_action( 'in_admin_header', array( $this, 'register_admin_notices' ) );
115
116 // add links to plugin page.
117 add_filter( 'plugin_action_links_' . ADVADS_BASE, array( $this, 'add_plugin_links' ) );
118
119 // display information when user is going to disable the plugin.
120 add_filter( 'admin_footer', array( $this, 'add_deactivation_logic' ) );
121 // add_filter( 'after_plugin_row_' . ADVADS_BASE, array( $this, 'display_deactivation_message' ) );
122 // disable adding rel="noopener noreferrer" to link added through TinyMCE for rich content ads.
123 add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_allow_unsafe_link_target' ) );
124
125 add_action( 'plugins_api_result', array( $this, 'recommend_suitable_add_ons' ), 11, 3 );
126
127 // register dynamic action to load a starter setup.
128 add_action( 'admin_action_advanced_ads_starter_setup', array( $this, 'import_starter_setup' ) );
129
130 Advanced_Ads_Admin_Meta_Boxes::get_instance();
131 Advanced_Ads_Admin_Menu::get_instance();
132 Advanced_Ads_Admin_Ad_Type::get_instance();
133 Advanced_Ads_Admin_Settings::get_instance();
134 new Advanced_Ads_Admin_Upgrades();
135 }
136
137 /**
138 * Actions and filters that should also be available for ajax
139 */
140 public function wp_plugins_loaded_ajax() {
141 // needed here in order to work with Quick Edit option on ad list page.
142 Advanced_Ads_Admin_Ad_Type::get_instance();
143
144 add_action( 'wp_ajax_advads_send_feedback', array( $this, 'send_feedback' ) );
145 add_action( 'wp_ajax_advads_load_rss_widget_content', array( 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ) );
146 }
147
148 /**
149 * Return an instance of this class.
150 *
151 * @return object A single instance of this class.
152 */
153 public static function get_instance() {
154 // If the single instance hasn't been set, set it now.
155 if ( null === self::$instance ) {
156 self::$instance = new self();
157 }
158
159 return self::$instance;
160 }
161
162 /**
163 * General stuff after page is loaded and screen variable is available
164 */
165 public function current_screen() {
166 $screen = get_current_screen();
167
168 if ( ! isset( $screen->id ) ) {
169 return;
170 }
171
172 switch ( $screen->id ) {
173 case 'edit-advanced_ads': // ad overview page.
174 case 'advanced_ads': // ad edit page.
175 // remove notice about missing first ad.
176 break;
177 }
178 }
179
180 /**
181 * Register and enqueue admin-specific style sheet.
182 */
183 public function enqueue_admin_styles() {
184 wp_enqueue_style( $this->plugin_slug . '-ui-styles', plugins_url( 'assets/css/ui.css', __FILE__ ), array(), ADVADS_VERSION );
185 wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), ADVADS_VERSION );
186 }
187
188 /**
189 * Register and enqueue admin-specific JavaScript.
190 */
191 public function enqueue_admin_scripts() {
192
193 // global js script.
194 wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
195 wp_enqueue_script( $this->plugin_slug . '-admin-find-adblocker', plugins_url( 'assets/js/advertisement.js', __FILE__ ), array(), ADVADS_VERSION, false );
196
197 // register ajax nonce.
198 $params = array(
199 'ajax_nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
200 );
201 wp_localize_script( $this->plugin_slug . '-admin-global-script', 'advadsglobal', $params );
202
203 if ( self::screen_belongs_to_advanced_ads() ) {
204 wp_register_script( $this->plugin_slug . '-ui-scripts', plugins_url( 'assets/js/ui.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
205 wp_register_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', $this->plugin_slug . '-ui-scripts', 'jquery-ui-autocomplete' ), ADVADS_VERSION, false );
206 wp_register_script( $this->plugin_slug . '-conditions-script', plugins_url( 'assets/js/conditions.js', __FILE__ ), array( 'jquery', $this->plugin_slug . '-ui-scripts' ), ADVADS_VERSION, false );
207 wp_register_script( $this->plugin_slug . '-wizard-script', plugins_url( 'assets/js/wizard.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
208
209 // just register this script for later inclusion on ad group list page.
210 wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
211
212 $auto_ads_strings = Advanced_Ads_AdSense_Admin::get_auto_ads_messages();
213
214 // register admin.js translations.
215 $translation_array = array(
216 'condition_or' => __( 'or', 'advanced-ads' ),
217 'condition_and' => __( 'and', 'advanced-ads' ),
218 'after_paragraph_promt' => __( 'After which paragraph?', 'advanced-ads' ),
219 'page_level_ads_enabled' => $auto_ads_strings['enabled'],
220 'today' => __( 'Today', 'advanced-ads' ),
221 'yesterday' => __( 'Yesterday', 'advanced-ads' ),
222 'this_month' => __( 'This Month', 'advanced-ads' ),
223 /* translators: 1: The number of days. */
224 'last_n_days' => __( 'Last %1$d days', 'advanced-ads' ),
225 /* translators: 1: An error message. */
226 'error_message' => __( 'An error occurred: %1$s' ),
227 'all' => __( 'All', 'advanced-ads' ),
228 'no_results' => __( 'There were no results returned for this ad. Please make sure it is active, generating impressions and double check your ad parameters.', 'advanced-ads' ),
229 'show_inactive_ads' => __( 'Show inactive ads', 'advanced-ads' ),
230 'hide_inactive_ads' => __( 'Hide inactive ads', 'advanced-ads' ),
231 'display_conditions_form_name' => Advanced_Ads_Display_Conditions::FORM_NAME, // not meant for translation.
232 );
233
234 wp_localize_script( $this->plugin_slug . '-admin-script', 'advadstxt', $translation_array );
235
236 wp_enqueue_script( $this->plugin_slug . '-admin-script' );
237 wp_enqueue_script( $this->plugin_slug . '-conditions-script' );
238 wp_enqueue_script( $this->plugin_slug . '-wizard-script' );
239 }
240
241 // call media manager for image upload only on ad edit pages.
242 $screen = get_current_screen();
243 if ( isset( $screen->id ) && Advanced_Ads::POST_TYPE_SLUG === $screen->id ) {
244 // the 'wp_enqueue_media' function can be executed only once and should be called with the 'post' parameter
245 // in this case, the '_wpMediaViewsL10n' js object inside html will contain id of the post, that is necessary to view oEmbed priview inside tinyMCE editor.
246 // since other plugins can call the 'wp_enqueue_media' function without the 'post' parameter, Advanced Ads should call it earlier.
247 global $post;
248 wp_enqueue_media( array( 'post' => $post ) );
249 }
250
251 }
252
253 /**
254 * Check if the current screen belongs to Advanced Ads
255 *
256 * @return bool true if screen belongs to Advanced Ads
257 */
258 public static function screen_belongs_to_advanced_ads() {
259
260 if ( ! function_exists( 'get_current_screen' ) ) {
261 return false;
262 }
263
264 $screen = get_current_screen();
265 if ( ! isset( $screen->id ) ) {
266 return false;
267 }
268
269 $advads_pages = apply_filters(
270 'advanced-ads-dashboard-screens',
271 array(
272 'advanced-ads_page_advanced-ads-groups', // ad groups.
273 'edit-advanced_ads', // ads overview.
274 'advanced_ads', // ad edit page.
275 'advanced-ads_page_advanced-ads-placements', // placements.
276 'advanced-ads_page_advanced-ads-settings', // settings.
277 'toplevel_page_advanced-ads', // overview.
278 'admin_page_advanced-ads-debug', // debug.
279 // 'advanced-ads_page_advanced-ads-support', // support.
280 'admin_page_advanced-ads-import-export', // import & export.
281 )
282 );
283
284 if ( in_array( $screen->id, $advads_pages, true ) ) {
285 return true;
286 }
287
288 return false;
289 }
290
291 /**
292 * Get action from the params
293 */
294 public function current_action() {
295 $request = wp_unslash( $_REQUEST );
296 if ( isset( $request['action'] ) && - 1 !== $request['action'] ) {
297 return $request['action'];
298 }
299
300 return false;
301 }
302
303 /**
304 * Get DateTimeZone object for the WP installation
305 *
306 * @return DateTimeZone object set in WP settings.
307 * @see Advanced_Ads_Utils::get_wp_timezone()
308 *
309 * @deprecated This is also used outside of admin as well as other plugins.
310 */
311 public static function get_wp_timezone() {
312 return Advanced_Ads_Utils::get_wp_timezone();
313 }
314
315 /**
316 * Get literal expression of timezone.
317 *
318 * @param DateTimeZone $date_time_zone the DateTimeZone object to get literal value from.
319 *
320 * @return string time zone.
321 * @see Advanced_Ads_Utils::get_timezone_name()
322 *
323 * @deprecated This is also used outside of admin as well as other plugins.
324 */
325 public static function timezone_get_name( DateTimeZone $date_time_zone ) {
326 return Advanced_Ads_Utils::get_timezone_name();
327 }
328
329 /**
330 * Registers Advanced Ads admin notices
331 * prevents other notices from showing up on our own pages
332 */
333 public function register_admin_notices() {
334
335 /**
336 * Remove all registered admin_notices from AA screens
337 * - we need to use this or some users have half or more of their viewports cluttered with unrelated notices
338 */
339 if ( $this->screen_belongs_to_advanced_ads() ) {
340 remove_all_actions( 'admin_notices' );
341 }
342
343 // register our own notices.
344 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
345 }
346
347 /**
348 * Initiate the admin notices class
349 */
350 public function admin_notices() {
351 // display ad block warning to everyone who can edit ads.
352 if ( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
353 if ( $this->screen_belongs_to_advanced_ads() ) {
354 include ADVADS_BASE_PATH . 'admin/views/notices/adblock.php';
355 }
356 }
357
358 // Show success notice after starter setup was imported. Registered here because it will be visible only once.
359 if ( isset( $_GET['message'] ) && 'advanced-ads-starter-setup-success' === $_GET['message'] ) {
360 add_action( 'advanced-ads-admin-notices', array( $this, 'starter_setup_success_message' ) );
361 }
362
363 // register our own notices on Advanced Ads pages, except from the overview page where they should appear in the notices section.
364 $screen = get_current_screen();
365 if ( class_exists( 'Advanced_Ads_Admin_Notices' )
366 && current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) )
367 && ( ! isset( $screen->id ) || 'toplevel_page_advanced-ads' !== $screen->id ) ) {
368 $this->notices = Advanced_Ads_Admin_Notices::get_instance()->notices;
369 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
370
371 // allow other Advanced Ads plugins to show admin notices at this late stage.
372 do_action( 'advanced-ads-admin-notices' );
373 }
374 }
375
376 /**
377 * Add links to the plugins list
378 *
379 * @param array $links array of links for the plugins, adapted when the current plugin is found.
380 *
381 * @return array $links
382 */
383 public function add_plugin_links( $links ) {
384
385 if ( ! is_array( $links ) ) {
386 return $links;
387 }
388
389 // add link to support page.
390 $support_link = '<a href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) ) . '">' . __( 'Support', 'advanced-ads' ) . '</a>';
391 array_unshift( $links, $support_link );
392
393 // add link to add-ons.
394 $extend_link = '<a href="' . ADVADS_URL . 'add-ons/#utm_source=advanced-ads&utm_medium=link&utm_campaign=plugin-page" target="_blank">' . __( 'Add-Ons', 'advanced-ads' ) . '</a>';
395 array_unshift( $links, $extend_link );
396
397 return $links;
398 }
399
400 /**
401 * Display deactivation logic on plugins page
402 *
403 * @since 1.7.14
404 */
405 public function add_deactivation_logic() {
406
407 $screen = get_current_screen();
408 if ( ! isset( $screen->id ) || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
409 return;
410 }
411
412 $current_user = wp_get_current_user();
413 if ( ! ( $current_user instanceof WP_User ) ) {
414 $from = '';
415 $email = '';
416 } else {
417 $from = $current_user->user_nicename . ' <' . trim( $current_user->user_email ) . '>';
418 $email = $current_user->user_email;
419 }
420
421 include ADVADS_BASE_PATH . 'admin/views/feedback-disable.php';
422 }
423
424 /**
425 * Send feedback via email
426 *
427 * @since 1.7.14
428 */
429 public function send_feedback() {
430 /**
431 * We first need to get the form data from the string and can verify the nonce afterwards
432 * This throws an issue with the WP Coding Standards though
433 */
434 if ( isset( $_POST['formdata'] ) ) {
435 parse_str( wp_unslash( $_POST['formdata'] ), $form );
436 }
437
438 if ( ! wp_verify_nonce( $form['advanced_ads_disable_form_nonce'], 'advanced_ads_disable_form' ) ) {
439 die();
440 }
441
442 $text = '';
443 if ( isset( $form['advanced_ads_disable_text'] ) ) {
444 $text = implode( "\n\r", $form['advanced_ads_disable_text'] );
445 }
446
447 // get first version to see if this is a new problem or might be an older on.
448 $options = Advanced_Ads_Plugin::get_instance()->internal_options();
449 $installed = isset( $options['installed'] ) ? date( 'd.m.Y', $options['installed'] ) : '';
450
451 $text .= "\n\n" . home_url() . " ($installed)";
452
453 $headers = array();
454
455 $from = isset( $form['advanced_ads_disable_from'] ) ? $form['advanced_ads_disable_from'] : '';
456 // the user clicked on the "don’t disable" button or if an address is given in the form then use that one.
457 if ( isset( $form['advanced_ads_disable_reason'] )
458 && 'get help' === $form['advanced_ads_disable_reason']
459 && ! empty( $form['advanced_ads_disable_reply_email'] ) ) {
460 $email = isset( $form['advanced_ads_disable_reply_email'] ) ? trim( $form['advanced_ads_disable_reply_email'] ) : $current_user->email;
461 $current_user = wp_get_current_user();
462 $name = ( $current_user instanceof WP_User ) ? $current_user->user_nicename : '';
463 $from = $name . ' <' . $email . '>';
464 $is_german = ( preg_match( '/\.de$/', $from ) || 'de_' === substr( get_locale(), 0, 3 ) || 'de_' === substr( get_user_locale(), 0, 3 ) );
465 if ( isset( $form['advanced_ads_disable_text'][0] )
466 && trim( $form['advanced_ads_disable_text'][0] ) !== '' ) { // is a text given then ask for help.
467 // send German text.
468 if ( $is_german ) {
469 $text .= "\n\n Hilfe ist auf dem Weg.";
470 } else {
471 $text .= "\n\n Help is on its way.";
472 }
473 } else { // if no text is given, just reply.
474 if ( $is_german ) {
475 $text .= "\n\n Vielen Dank für das Feedback.";
476 } else {
477 $text .= "\n\n Thank you for your feedback.";
478 }
479 }
480 }
481 if ( $from ) {
482 $headers[] = "From: $from";
483 $headers[] = "Reply-To: $from";
484 }
485
486 $subject = isset( $form['advanced_ads_disable_reason'] ) ? $form['advanced_ads_disable_reason'] : '(no reason given)';
487 // append plugin name to get a better subject.
488 $subject .= ' (Advanced Ads)';
489
490 $success = wp_mail( 'improve@wpadvancedads.com', $subject, $text, $headers );
491
492 die();
493
494 }
495
496 /**
497 * Configure TinyMCE to allow unsafe link target.
498 *
499 * @param boolean $mce_init the tinyMce initialization array.
500 *
501 * @return boolean
502 */
503 public function tinymce_allow_unsafe_link_target( $mce_init ) {
504
505 // check if we are on the ad edit screen.
506 if ( ! function_exists( 'get_current_screen' ) ) {
507 return $mce_init;
508 }
509
510 $screen = get_current_screen();
511 if ( isset( $screen->id ) && 'advanced_ads' === $screen->id ) {
512 $mce_init['allow_unsafe_link_target'] = true;
513 }
514
515 return $mce_init;
516 }
517
518 /**
519 * Sort visitor and display condition arrays alphabetically by their label.
520 *
521 * @param array $a array to be compared.
522 * @param array $b array to be compared.
523 *
524 * @return mixed
525 */
526 public static function sort_condition_array_by_label( $a, $b ) {
527 if ( ! isset( $a['label'] ) || ! isset( $b['label'] ) ) {
528 return;
529 }
530
531 return strcmp( strtolower( $a['label'] ), strtolower( $b['label'] ) );
532 }
533
534 /**
535 * Recommend additional add-ons
536 *
537 * @param object|WP_Error $result Response object or WP_Error.
538 * @param string $action The type of information being requested from the Plugin Installation API.
539 * @param object $args Plugin API arguments.
540 *
541 * @return object|WP_Error Response object or WP_Error.
542 */
543 public function recommend_suitable_add_ons( $result, $action, $args ) {
544 if ( empty( $args->browse ) ) {
545 return $result;
546 }
547
548 if ( 'featured' !== $args->browse && 'recommended' !== $args->browse && 'popular' !== $args->browse ) {
549 return $result;
550 }
551
552 if ( ! isset( $result->info['page'] ) || 1 < $result->info['page'] ) {
553 return $result;
554 }
555
556 // Recommend AdSense In-Feed add-on.
557 if ( ! is_plugin_active( 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' )
558 && ! is_plugin_active_for_network( 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' ) ) {
559
560 // Grab all slugs from the api results.
561 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
562
563 if ( in_array( 'advanced-ads-adsense-in-feed', $result_slugs, true ) ) {
564 return $result;
565 }
566
567 $query_args = array(
568 'slug' => 'advanced-ads-adsense-in-feed',
569 'fields' => array(
570 'icons' => true,
571 'active_installs' => true,
572 'short_description' => true,
573 'group' => true,
574 ),
575 );
576 $plugin_data = plugins_api( 'plugin_information', $query_args );
577
578 if ( ! is_wp_error( $plugin_data ) ) {
579 if ( 'featured' === $args->browse ) {
580 array_push( $result->plugins, $plugin_data );
581 } else {
582 array_unshift( $result->plugins, $plugin_data );
583 }
584 }
585 }
586
587 // Recommend Genesis Ads add-on.
588 if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME
589 && ! is_plugin_active( 'advanced-ads-genesis/genesis-ads.php' )
590 && ! is_plugin_active_for_network( 'advanced-ads-genesis/genesis-ads.php' ) ) {
591
592 // Grab all slugs from the api results.
593 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
594
595 if ( in_array( 'advanced-ads-genesis', $result_slugs, true ) ) {
596 return $result;
597 }
598
599 $query_args = array(
600 'slug' => 'advanced-ads-genesis',
601 'fields' => array(
602 'icons' => true,
603 'active_installs' => true,
604 'short_description' => true,
605 'group' => true,
606 ),
607 );
608 $plugin_data = plugins_api( 'plugin_information', $query_args );
609
610 if ( ! is_wp_error( $plugin_data ) ) {
611 if ( 'featured' === $args->browse ) {
612 array_push( $result->plugins, $plugin_data );
613 } else {
614 array_unshift( $result->plugins, $plugin_data );
615 }
616 }
617 }
618
619 // Recommend WP Bakery (former Visual Composer) add-on.
620 if ( defined( 'WPB_VC_VERSION' )
621 && ! is_plugin_active( 'ads-for-visual-composer/advanced-ads-vc.php' )
622 && ! is_plugin_active_for_network( 'ads-for-visual-composer/advanced-ads-vc.php' ) ) {
623
624 // Grab all slugs from the api results.
625 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
626
627 if ( in_array( 'ads-for-visual-composer', $result_slugs, true ) ) {
628 return $result;
629 }
630
631 $query_args = array(
632 'slug' => 'ads-for-visual-composer',
633 'fields' => array(
634 'icons' => true,
635 'active_installs' => true,
636 'short_description' => true,
637 'group' => true,
638 ),
639 );
640 $plugin_data = plugins_api( 'plugin_information', $query_args );
641
642 if ( ! is_wp_error( $plugin_data ) ) {
643 if ( 'featured' === $args->browse ) {
644 array_push( $result->plugins, $plugin_data );
645 } else {
646 array_unshift( $result->plugins, $plugin_data );
647 }
648 }
649 }
650
651 return $result;
652 }
653
654 /**
655 * Overrides WordPress text in Footer
656 *
657 * @param String $default_text The default footer text.
658 *
659 * @return string
660 */
661 public function admin_footer_text( $default_text ) {
662 if ( $this->screen_belongs_to_advanced_ads() ) {
663
664 /* translators: %s is the URL to add a new review, https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post */
665 return sprintf( __( 'Thank the developer with a &#9733;&#9733;&#9733;&#9733;&#9733; review on <a href="%s" target="_blank">wordpress.org</a>', 'advanced-ads' ), 'https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post' );
666
667 }
668
669 return $default_text;
670 }
671
672 /**
673 * Import a starter setup for new users
674 */
675 public function import_starter_setup() {
676
677 if (
678 ! isset( $_GET['action'] )
679 || 'advanced_ads_starter_setup' !== $_GET['action']
680 || ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) )
681 ) {
682 return;
683 }
684
685 check_admin_referer( 'advanced-ads-starter-setup' );
686
687 // start importing the ads.
688 $xml = file_get_contents( ADVADS_BASE_PATH . 'admin/assets/xml/starter-setup.xml' );
689
690 Advanced_Ads_Import::get_instance()->import( $xml );
691
692 // redirect to ad overview page.
693 wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads&message=advanced-ads-starter-setup-success' ) );
694 }
695
696 /**
697 * Show success message after starter setup was created.
698 */
699 public function starter_setup_success_message() {
700
701 // load link to latest post.
702
703 $args = array(
704 'numberposts' => 1,
705 );
706 $last_post = get_posts( $args );
707 $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
708
709 include ADVADS_BASE_PATH . 'admin/views/notices/starter-setup-success.php';
710 }
711
712 /**
713 * Get admin settings of the current user.
714 *
715 * @return array
716 */
717 public static function get_admin_settings() {
718 if ( null === self::$admin_settings ) {
719 self::$admin_settings = get_user_meta( get_current_user_id(), 'advanced-ads-admin-settings', true );
720
721 if ( ! is_array( self::$admin_settings ) ) {
722 self::$admin_settings = array();
723 }
724 }
725 return self::$admin_settings;
726 }
727
728 /**
729 * Update admin settings of the current user.
730 *
731 * @param array $new_settings New admin settings.
732 */
733 public static function update_admin_setttings( $new_settings ) {
734 $current = self::get_admin_settings();
735
736 if ( $current !== $new_settings ) {
737 update_user_meta( get_current_user_id(), 'advanced-ads-admin-settings', $new_settings );
738 self::$admin_settings = $new_settings;
739 }
740 }
741 }
742