PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.39.2
Advanced Ads – Ad Manager & AdSense v1.39.2
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 3 years ago includes 3 years ago views 3 years ago class-advanced-ads-admin.php 3 years ago
class-advanced-ads-admin.php
861 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 ( wp_doing_ajax() ) {
57 new Advanced_Ads_Ad_Ajax_Callbacks();
58 add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded_ajax' ] );
59 } else {
60 add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
61 add_filter( 'admin_footer_text', [ $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', [ $this, 'current_screen' ] );
103
104 // Load admin style sheet and JavaScript.
105 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_styles' ] );
106 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ], 9 );
107
108 // update placements.
109 add_action( 'admin_init', [ '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', [ $this, 'register_admin_notices' ] );
115
116 // add links to plugin page.
117 add_filter( 'plugin_action_links_' . ADVADS_BASE, [ $this, 'add_plugin_links' ] );
118
119 // display information when user is going to disable the plugin.
120 add_filter( 'admin_footer', [ $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', [ $this, 'tinymce_allow_unsafe_link_target' ] );
124
125 add_action( 'plugins_api_result', [ $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', [ $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 Advanced_Ads_Ad_Authors::get_instance();
135 new Advanced_Ads_Admin_Upgrades();
136 }
137
138 /**
139 * Actions and filters that should also be available for ajax
140 */
141 public function wp_plugins_loaded_ajax() {
142 // needed here in order to work with Quick Edit option on ad list page.
143 Advanced_Ads_Admin_Ad_Type::get_instance();
144
145 add_action( 'wp_ajax_advads_send_feedback', [ $this, 'send_feedback' ] );
146 add_action( 'wp_ajax_advads_load_rss_widget_content', [ 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ] );
147 }
148
149 /**
150 * Return an instance of this class.
151 *
152 * @return object A single instance of this class.
153 */
154 public static function get_instance() {
155 // If the single instance hasn't been set, set it now.
156 if ( null === self::$instance ) {
157 self::$instance = new self();
158 }
159
160 return self::$instance;
161 }
162
163 /**
164 * General stuff after page is loaded and screen variable is available
165 */
166 public function current_screen() {
167 $screen = get_current_screen();
168
169 if ( ! isset( $screen->id ) ) {
170 return;
171 }
172
173 switch ( $screen->id ) {
174 case 'edit-advanced_ads': // ad overview page.
175 case 'advanced_ads': // ad edit page.
176 // remove notice about missing first ad.
177 break;
178 }
179 }
180
181 /**
182 * Register and enqueue admin-specific style sheet.
183 */
184 public function enqueue_admin_styles() {
185 wp_enqueue_style( $this->plugin_slug . '-ui-styles', plugins_url( 'assets/css/ui.css', __FILE__ ), [], ADVADS_VERSION );
186 wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), [], ADVADS_VERSION );
187
188 $screen = get_current_screen();
189 if ( ! $screen instanceof \WP_Screen ) {
190 return;
191 }
192
193 if ( $screen->post_type === Advanced_Ads::POST_TYPE_SLUG && $screen->base === 'post' ) {
194 wp_enqueue_style( $this->plugin_slug . '-ad-positioning-styles', ADVADS_BASE_URL . '/modules/ad-positioning/assets/css/ad-positioning.css', [ $this->plugin_slug . '-admin-styles' ], ADVADS_VERSION );
195 }
196 }
197
198 /**
199 * Register and enqueue admin-specific JavaScript.
200 */
201 public function enqueue_admin_scripts() {
202
203 // global js script.
204 wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
205 wp_enqueue_script( $this->plugin_slug . '-admin-find-adblocker', plugins_url( 'assets/js/advertisement.js', __FILE__ ), [], ADVADS_VERSION, false );
206
207 // register ajax nonce.
208 $params = [
209 'ajax_nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
210 ];
211 wp_localize_script( $this->plugin_slug . '-admin-global-script', 'advadsglobal', $params );
212
213 if ( self::screen_belongs_to_advanced_ads() ) {
214 wp_register_script( $this->plugin_slug . '-ui-scripts', plugins_url( 'assets/js/ui.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
215 wp_register_script( $this->plugin_slug . '-conditions-script', plugins_url( 'assets/js/conditions.js', __FILE__ ), [ 'jquery', $this->plugin_slug . '-ui-scripts' ], ADVADS_VERSION, false );
216 wp_register_script( $this->plugin_slug . '-wizard-script', plugins_url( 'assets/js/wizard.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
217
218 $this->enqueue_main_admin_script();
219
220 // just register this script for later inclusion on ad group list page.
221 wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
222
223 // register admin.js translations.
224 $translation_array = [
225 'condition_or' => __( 'or', 'advanced-ads' ),
226 'condition_and' => __( 'and', 'advanced-ads' ),
227 'after_paragraph_promt' => __( 'After which paragraph?', 'advanced-ads' ),
228 'page_level_ads_enabled' => Advanced_Ads_AdSense_Admin::get_auto_ads_messages()['enabled'],
229 'today' => __( 'Today', 'advanced-ads' ),
230 'yesterday' => __( 'Yesterday', 'advanced-ads' ),
231 'this_month' => __( 'This Month', 'advanced-ads' ),
232 /* translators: 1: The number of days. */
233 'last_n_days' => __( 'Last %1$d days', 'advanced-ads' ),
234 /* translators: 1: An error message. */
235 'error_message' => __( 'An error occurred: %1$s' ),
236 'all' => __( 'All', 'advanced-ads' ),
237 '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' ),
238 'show_inactive_ads' => __( 'Show inactive ads', 'advanced-ads' ),
239 'hide_inactive_ads' => __( 'Hide inactive ads', 'advanced-ads' ),
240 'display_conditions_form_name' => Advanced_Ads_Display_Conditions::FORM_NAME, // not meant for translation.
241 'delete_placement_confirmation' => __( 'Permanently delete this placement?', 'advanced-ads' ),
242 'close' => __( 'Close', 'advanced-ads' ),
243 'confirmation' => __( 'Data you have entered has not been saved. Are you sure you want to discard your changes?', 'advanced-ads' ),
244 'placements_allowed_ads' => [
245 'action' => 'advads-placements-allowed-ads',
246 'nonce' => wp_create_nonce( 'advads-placements-allowed-ads' ),
247 ],
248 ];
249
250 wp_localize_script( $this->plugin_slug . '-admin-script', 'advadstxt', $translation_array );
251
252 wp_enqueue_script( $this->plugin_slug . '-admin-script' );
253 wp_enqueue_script( $this->plugin_slug . '-conditions-script' );
254 wp_enqueue_script( $this->plugin_slug . '-wizard-script' );
255 }
256
257 // call media manager for image upload only on ad edit pages.
258 $screen = get_current_screen();
259
260 if ( ! $screen instanceof \WP_Screen ) {
261 return;
262 }
263
264 if ( isset( $screen->id ) && Advanced_Ads::POST_TYPE_SLUG === $screen->id ) {
265 // the 'wp_enqueue_media' function can be executed only once and should be called with the 'post' parameter
266 // 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.
267 // since other plugins can call the 'wp_enqueue_media' function without the 'post' parameter, Advanced Ads should call it earlier.
268 global $post;
269 wp_enqueue_media( [ 'post' => $post ] );
270 }
271
272 // single ad edit screen.
273 if ( $screen->post_type === Advanced_Ads::POST_TYPE_SLUG && $screen->base === 'post' ) {
274 wp_enqueue_script(
275 $this->plugin_slug . '-ad-positioning-script',
276 ADVADS_BASE_URL . '/modules/ad-positioning/assets/js/ad-positioning.js',
277 [],
278 ADVADS_VERSION,
279 true
280 );
281 }
282 }
283
284 /**
285 * Enqueue the minified version of the admin script, or the parts if SCRIPT_DEBUG is defined and true.
286 *
287 * @return void
288 */
289 private function enqueue_main_admin_script() {
290 $dependencies = [ 'jquery', $this->plugin_slug . '-ui-scripts', 'jquery-ui-autocomplete', 'wp-util' ];
291
292 if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
293 wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), $dependencies, ADVADS_VERSION, false );
294 wp_enqueue_script( $this->plugin_slug . '-admin-script-dialog', plugins_url( 'assets/js/dialog-advads-modal.js', __FILE__ ), $dependencies, ADVADS_VERSION, false );
295
296 return;
297 }
298
299 wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.min.js', __FILE__ ), $dependencies, ADVADS_VERSION, false );
300 }
301
302 /**
303 * Check if the current screen belongs to Advanced Ads
304 *
305 * @return bool true if screen belongs to Advanced Ads
306 */
307 public static function screen_belongs_to_advanced_ads() {
308 if ( ! function_exists( 'get_current_screen' ) ) {
309 return false;
310 }
311
312 $screen = get_current_screen();
313 if ( ! isset( $screen->id ) ) {
314 return false;
315 }
316
317 $advads_pages = apply_filters(
318 'advanced-ads-dashboard-screens',
319 [
320 'advanced-ads_page_advanced-ads-groups', // ad groups.
321 'edit-advanced_ads', // ads overview.
322 'advanced_ads', // ad edit page.
323 'advanced-ads_page_advanced-ads-placements', // placements.
324 'advanced-ads_page_advanced-ads-settings', // settings.
325 'toplevel_page_advanced-ads', // overview.
326 'admin_page_advanced-ads-debug', // debug.
327 // 'advanced-ads_page_advanced-ads-support', // support.
328 'admin_page_advanced-ads-import-export', // import & export.
329 ]
330 );
331
332 if ( in_array( $screen->id, $advads_pages, true ) ) {
333 return true;
334 }
335
336 return false;
337 }
338
339 /**
340 * Get action from the params
341 */
342 public function current_action() {
343 $request = wp_unslash( $_REQUEST );
344 if ( isset( $request['action'] ) && - 1 !== $request['action'] ) {
345 return $request['action'];
346 }
347
348 return false;
349 }
350
351 /**
352 * Get DateTimeZone object for the WP installation
353 *
354 * @return DateTimeZone object set in WP settings.
355 * @see Advanced_Ads_Utils::get_wp_timezone()
356 *
357 * @deprecated This is also used outside of admin as well as other plugins.
358 */
359 public static function get_wp_timezone() {
360 return Advanced_Ads_Utils::get_wp_timezone();
361 }
362
363 /**
364 * Get literal expression of timezone.
365 *
366 * @param DateTimeZone $date_time_zone the DateTimeZone object to get literal value from.
367 *
368 * @return string time zone.
369 * @see Advanced_Ads_Utils::get_timezone_name()
370 *
371 * @deprecated This is also used outside of admin as well as other plugins.
372 */
373 public static function timezone_get_name( DateTimeZone $date_time_zone ) {
374 return Advanced_Ads_Utils::get_timezone_name();
375 }
376
377 /**
378 * Registers Advanced Ads admin notices
379 * prevents other notices from showing up on our own pages
380 */
381 public function register_admin_notices() {
382
383 /**
384 * Remove all registered admin_notices from AA screens
385 * we need to use this or some users have half or more of their viewports cluttered with unrelated notices
386 */
387 if ( $this->screen_belongs_to_advanced_ads() ) {
388 remove_all_actions( 'admin_notices' );
389 }
390
391 // register our own notices.
392 add_action( 'admin_notices', [ $this, 'admin_notices' ] );
393 }
394
395 /**
396 * Initiate the admin notices class
397 */
398 public function admin_notices() {
399 // display ad block warning to everyone who can edit ads.
400 if ( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
401 if ( $this->screen_belongs_to_advanced_ads() ) {
402 include ADVADS_BASE_PATH . 'admin/views/notices/adblock.php';
403 }
404 }
405
406 if ( $this->screen_belongs_to_advanced_ads() ) {
407 $this->branded_admin_header();
408 }
409
410 // Show success notice after starter setup was imported. Registered here because it will be visible only once.
411 if ( isset( $_GET['message'] ) && 'advanced-ads-starter-setup-success' === $_GET['message'] ) {
412 add_action( 'advanced-ads-admin-notices', [ $this, 'starter_setup_success_message' ] );
413 }
414
415 // register our own notices on Advanced Ads pages, except from the overview page where they should appear in the notices section.
416 $screen = get_current_screen();
417 if ( class_exists( 'Advanced_Ads_Admin_Notices' )
418 && current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) )
419 && ( ! isset( $screen->id ) || 'toplevel_page_advanced-ads' !== $screen->id ) ) {
420 $this->notices = Advanced_Ads_Admin_Notices::get_instance()->notices;
421
422 echo '<div class="wrap">';
423 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
424
425 // allow other Advanced Ads plugins to show admin notices at this late stage.
426 do_action( 'advanced-ads-admin-notices' );
427 echo '</div>';
428 }
429 }
430
431 /**
432 * Add links to the plugins list
433 *
434 * @param array $links array of links for the plugins, adapted when the current plugin is found.
435 *
436 * @return array $links
437 */
438 public function add_plugin_links( $links ) {
439 if ( ! is_array( $links ) ) {
440 return $links;
441 }
442
443 // add link to support page.
444 $support_link = '<a href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) ) . '">' . __( 'Support', 'advanced-ads' ) . '</a>';
445 array_unshift( $links, $support_link );
446
447 // add link to add-ons.
448 if ( defined( 'AAP_VERSION' ) ) {
449 $extend_link = '<a href="' . ADVADS_URL . 'add-ons/?utm_source=advanced-ads&utm_medium=link&utm_campaign=plugin-page-add-ons" target="_blank">' . __( 'Add-Ons', 'advanced-ads' ) . '</a>';
450 } else {
451 $extend_link = '<a href="' . ADVADS_URL . 'add-ons/all-access/?utm_source=advanced-ads&utm_medium=link&utm_campaign=plugin-page-features" target="_blank" class="aa-get-pro">' . __( 'See Pro Features', 'advanced-ads' ) . '</a>';
452 }
453 array_unshift( $links, $extend_link );
454
455 return $links;
456 }
457
458 /**
459 * Display deactivation logic on plugins page
460 *
461 * @since 1.7.14
462 */
463 public function add_deactivation_logic() {
464 $screen = get_current_screen();
465 if ( ! isset( $screen->id ) || ! in_array( $screen->id, [ 'plugins', 'plugins-network' ], true ) ) {
466 return;
467 }
468
469 $current_user = wp_get_current_user();
470 if ( ! ( $current_user instanceof WP_User ) ) {
471 $from = '';
472 $email = '';
473 } else {
474 $from = $current_user->user_nicename . ' <' . trim( $current_user->user_email ) . '>';
475 $email = $current_user->user_email;
476 }
477
478 include ADVADS_BASE_PATH . 'admin/views/feedback-disable.php';
479 }
480
481 /**
482 * Send feedback via email
483 *
484 * @since 1.7.14
485 */
486 public function send_feedback() {
487 /**
488 * We first need to get the form data from the string and can verify the nonce afterwards
489 * This throws an issue with the WP Coding Standards though
490 */
491 if ( isset( $_POST['formdata'] ) ) {
492 parse_str( wp_unslash( $_POST['formdata'] ), $form );
493 }
494
495 if ( ! wp_verify_nonce( $form['advanced_ads_disable_form_nonce'], 'advanced_ads_disable_form' ) ) {
496 die();
497 }
498
499 $text = '';
500 if ( isset( $form['advanced_ads_disable_text'] ) ) {
501 $text = implode( "\n\r", $form['advanced_ads_disable_text'] );
502 }
503
504 // get first version to see if this is a new problem or might be an older on.
505 $options = Advanced_Ads_Plugin::get_instance()->internal_options();
506 $installed = isset( $options['installed'] ) ? date( 'd.m.Y', $options['installed'] ) : '';
507
508 $text .= "\n\n" . home_url() . " ($installed)";
509
510 $headers = [];
511
512 $from = isset( $form['advanced_ads_disable_from'] ) ? $form['advanced_ads_disable_from'] : '';
513 // the user clicked on the "don’t disable" button or if an address is given in the form then use that one.
514 if ( isset( $form['advanced_ads_disable_reason'] )
515 && 'get help' === $form['advanced_ads_disable_reason']
516 && ! empty( $form['advanced_ads_disable_reply_email'] ) ) {
517 $email = trim( $form['advanced_ads_disable_reply_email'] );
518 if ( ! is_email( $email ) ) {
519 die();
520 }
521
522 $current_user = wp_get_current_user();
523 $name = ( $current_user instanceof WP_User ) ? $current_user->user_nicename : '';
524 $from = $name . ' <' . $email . '>';
525 $is_german = ( preg_match( '/\.de$/', $from ) || 'de_' === substr( get_locale(), 0, 3 ) || 'de_' === substr( get_user_locale(), 0, 3 ) );
526 if ( isset( $form['advanced_ads_disable_text'][0] )
527 && trim( $form['advanced_ads_disable_text'][0] ) !== '' ) { // is a text given then ask for help.
528 // send German text.
529 if ( $is_german ) {
530 $text .= "\n\n Hilfe ist auf dem Weg.";
531 } else {
532 $text .= "\n\n Help is on its way.";
533 }
534 } else { // if no text is given, just reply.
535 if ( $is_german ) {
536 $text .= "\n\n Vielen Dank für das Feedback.";
537 } else {
538 $text .= "\n\n Thank you for your feedback.";
539 }
540 }
541 }
542 if ( $from ) {
543 $headers[] = "From: $from";
544 $headers[] = "Reply-To: $from";
545 }
546
547 $subject = isset( $form['advanced_ads_disable_reason'] ) ? $form['advanced_ads_disable_reason'] : '(no reason given)';
548 // append plugin name to get a better subject.
549 $subject .= ' (Advanced Ads)';
550
551 $success = wp_mail( 'improve@wpadvancedads.com', $subject, $text, $headers );
552
553 die();
554 }
555
556 /**
557 * Configure TinyMCE to allow unsafe link target.
558 *
559 * @param boolean $mce_init the tinyMce initialization array.
560 *
561 * @return boolean
562 */
563 public function tinymce_allow_unsafe_link_target( $mce_init ) {
564
565 // check if we are on the ad edit screen.
566 if ( ! function_exists( 'get_current_screen' ) ) {
567 return $mce_init;
568 }
569
570 $screen = get_current_screen();
571 if ( isset( $screen->id ) && 'advanced_ads' === $screen->id ) {
572 $mce_init['allow_unsafe_link_target'] = true;
573 }
574
575 return $mce_init;
576 }
577
578 /**
579 * Sort visitor and display condition arrays alphabetically by their label.
580 *
581 * @param array $a array to be compared.
582 * @param array $b array to be compared.
583 *
584 * @return mixed
585 */
586 public static function sort_condition_array_by_label( $a, $b ) {
587 if ( ! isset( $a['label'] ) || ! isset( $b['label'] ) ) {
588 return;
589 }
590
591 return strcmp( strtolower( $a['label'] ), strtolower( $b['label'] ) );
592 }
593
594 /**
595 * Recommend additional add-ons
596 *
597 * @param object|WP_Error $result Response object or WP_Error.
598 * @param string $action The type of information being requested from the Plugin Installation API.
599 * @param object $args Plugin API arguments.
600 *
601 * @return object|WP_Error Response object or WP_Error.
602 */
603 public function recommend_suitable_add_ons( $result, $action, $args ) {
604 if ( empty( $args->browse ) ) {
605 return $result;
606 }
607
608 if ( 'featured' !== $args->browse && 'recommended' !== $args->browse && 'popular' !== $args->browse ) {
609 return $result;
610 }
611
612 if ( ! isset( $result->info['page'] ) || 1 < $result->info['page'] ) {
613 return $result;
614 }
615
616 // Recommend AdSense In-Feed add-on.
617 if ( ! is_plugin_active( 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' )
618 && ! is_plugin_active_for_network( 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' ) ) {
619
620 // Grab all slugs from the api results.
621 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
622
623 if ( in_array( 'advanced-ads-adsense-in-feed', $result_slugs, true ) ) {
624 return $result;
625 }
626
627 $query_args = [
628 'slug' => 'advanced-ads-adsense-in-feed',
629 'fields' => [
630 'icons' => true,
631 'active_installs' => true,
632 'short_description' => true,
633 'group' => true,
634 ],
635 ];
636 $plugin_data = plugins_api( 'plugin_information', $query_args );
637
638 if ( ! is_wp_error( $plugin_data ) ) {
639 if ( 'featured' === $args->browse ) {
640 array_push( $result->plugins, $plugin_data );
641 } else {
642 array_unshift( $result->plugins, $plugin_data );
643 }
644 }
645 }
646
647 // Recommend Genesis Ads add-on.
648 if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME
649 && ! is_plugin_active( 'advanced-ads-genesis/genesis-ads.php' )
650 && ! is_plugin_active_for_network( 'advanced-ads-genesis/genesis-ads.php' ) ) {
651
652 // Grab all slugs from the api results.
653 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
654
655 if ( in_array( 'advanced-ads-genesis', $result_slugs, true ) ) {
656 return $result;
657 }
658
659 $query_args = [
660 'slug' => 'advanced-ads-genesis',
661 'fields' => [
662 'icons' => true,
663 'active_installs' => true,
664 'short_description' => true,
665 'group' => true,
666 ],
667 ];
668 $plugin_data = plugins_api( 'plugin_information', $query_args );
669
670 if ( ! is_wp_error( $plugin_data ) ) {
671 if ( 'featured' === $args->browse ) {
672 array_push( $result->plugins, $plugin_data );
673 } else {
674 array_unshift( $result->plugins, $plugin_data );
675 }
676 }
677 }
678
679 // Recommend WP Bakery (former Visual Composer) add-on.
680 if ( defined( 'WPB_VC_VERSION' )
681 && ! is_plugin_active( 'ads-for-visual-composer/advanced-ads-vc.php' )
682 && ! is_plugin_active_for_network( 'ads-for-visual-composer/advanced-ads-vc.php' ) ) {
683
684 // Grab all slugs from the api results.
685 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
686
687 if ( in_array( 'ads-for-visual-composer', $result_slugs, true ) ) {
688 return $result;
689 }
690
691 $query_args = [
692 'slug' => 'ads-for-visual-composer',
693 'fields' => [
694 'icons' => true,
695 'active_installs' => true,
696 'short_description' => true,
697 'group' => true,
698 ],
699 ];
700 $plugin_data = plugins_api( 'plugin_information', $query_args );
701
702 if ( ! is_wp_error( $plugin_data ) ) {
703 if ( 'featured' === $args->browse ) {
704 array_push( $result->plugins, $plugin_data );
705 } else {
706 array_unshift( $result->plugins, $plugin_data );
707 }
708 }
709 }
710
711 return $result;
712 }
713
714 /**
715 * Overrides WordPress text in Footer
716 *
717 * @param String $default_text The default footer text.
718 *
719 * @return string
720 */
721 public function admin_footer_text( $default_text ) {
722 if ( $this->screen_belongs_to_advanced_ads() ) {
723
724 /* translators: %s is the URL to add a new review, https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post */
725 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' );
726 }
727
728 return $default_text;
729 }
730
731 /**
732 * Import a starter setup for new users
733 */
734 public function import_starter_setup() {
735 if (
736 ! isset( $_GET['action'] )
737 || 'advanced_ads_starter_setup' !== $_GET['action']
738 || ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) )
739 ) {
740 return;
741 }
742
743 check_admin_referer( 'advanced-ads-starter-setup' );
744
745 // start importing the ads.
746 $xml = file_get_contents( ADVADS_BASE_PATH . 'admin/assets/xml/starter-setup.xml' );
747
748 Advanced_Ads_Import::get_instance()->import( $xml );
749
750 // redirect to ad overview page.
751 wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads&message=advanced-ads-starter-setup-success' ) );
752 }
753
754 /**
755 * Show success message after starter setup was created.
756 */
757 public function starter_setup_success_message() {
758
759 // load link to latest post.
760
761 $args = [
762 'numberposts' => 1,
763 ];
764 $last_post = get_posts( $args );
765 $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
766
767 include ADVADS_BASE_PATH . 'admin/views/notices/starter-setup-success.php';
768 }
769
770 /**
771 * Get admin settings of the current user.
772 *
773 * @return array
774 */
775 public static function get_admin_settings() {
776 if ( null === self::$admin_settings ) {
777 self::$admin_settings = get_user_meta( get_current_user_id(), 'advanced-ads-admin-settings', true );
778
779 if ( ! is_array( self::$admin_settings ) ) {
780 self::$admin_settings = [];
781 }
782 }
783 return self::$admin_settings;
784 }
785
786 /**
787 * Update admin settings of the current user.
788 *
789 * @param array $new_settings New admin settings.
790 */
791 public static function update_admin_setttings( $new_settings ) {
792 $current = self::get_admin_settings();
793
794 if ( $current !== $new_settings ) {
795 update_user_meta( get_current_user_id(), 'advanced-ads-admin-settings', $new_settings );
796 self::$admin_settings = $new_settings;
797 }
798 }
799
800 /**
801 * Add an Advanced Ads branded header to plugin pages
802 *
803 * @see Advanced_Ads_Admin::screen_belongs_to_advanced_ads()
804 */
805 private function branded_admin_header() {
806 $screen = get_current_screen();
807 $manual_url = 'manual/';
808 $new_button_id = '';
809 $new_button_label = '';
810 $new_button_href = '';
811 $show_filter_button = false;
812 $reset_href = '';
813 $filter_disabled = '';
814 $show_screen_options = false;
815 $title = get_admin_page_title();
816
817 switch ( $screen->id ) {
818 // ad overview
819 case 'advanced_ads':
820 $new_button_label = __( 'New Ad', 'advanced-ads' );
821 $new_button_href = admin_url( 'post-new.php?post_type=advanced_ads' );
822 $manual_url = 'manual/first-ad/';
823 break;
824 case 'edit-advanced_ads':
825 $title = __( 'Your Ads', 'advanced-ads' );
826 $new_button_label = __( 'New Ad', 'advanced-ads' );
827 $new_button_href = admin_url( 'post-new.php?post_type=advanced_ads' );
828 $manual_url = 'manual/first-ad/';
829 $show_filter_button = ! Advanced_Ads_Ad_List_Filters::uses_filter_or_search();
830 $reset_href = ! $show_filter_button ? esc_url( admin_url( 'edit.php?post_type=' . Advanced_Ads::POST_TYPE_SLUG ) ) : '';
831 $filter_disabled = $screen->get_option( 'show-filters' ) ? 'disabled' : '';
832 $show_screen_options = true;
833 break;
834 case 'advanced-ads_page_advanced-ads-groups': // ad groups
835 $title = __( 'Your Groups', 'advanced-ads' );
836 $new_button_label = __( 'New Ad Group', 'advanced-ads' );
837 $new_button_href = '#modal-group-new';
838 $new_button_id = 'advads-new-ad-group-link';
839 $manual_url = 'manual/ad-groups/';
840 $show_filter_button = empty( $_GET['s'] );
841 $reset_href = ! $show_filter_button ? esc_url( admin_url( 'admin.php?page=advanced-ads-groups' ) ) : '';
842 break;
843 case 'advanced-ads_page_advanced-ads-placements':
844 $title = __( 'Your Placements', 'advanced-ads' );
845 $new_button_label = __( 'New Placement', 'advanced-ads' );
846 $new_button_href = '#modal-placement-new';
847 $manual_url = 'manual/placements/';
848 $show_filter_button = true;
849 break;
850 case 'advanced-ads_page_advanced-ads-settings':
851 $title = __( 'Advanced Ads Settings', 'advanced-ads' );
852 $new_button_href = '';
853 break;
854 }
855
856 $manual_url = apply_filters( 'advanced-ads-admin-header-manual-url', $manual_url, $screen->id );
857
858 include ADVADS_BASE_PATH . 'admin/views/header.php';
859 }
860 }
861