PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.10.10
Advanced Ads – Ad Manager & AdSense v1.10.10
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 7 years ago includes 7 years ago views 7 years ago class-advanced-ads-admin.php 7 years ago
class-advanced-ads-admin.php
652 lines
1 <?php
2 /**
3 * Advanced Ads main admin class
4 *
5 * @package Advanced_Ads_Admin
6 * @author Thomas Maier <thomas.maier@webgilde.com>
7 * @license GPL-2.0+
8 * @link https://wpadvancedads.com
9 * @copyright since 2013 Thomas Maier, webgilde GmbH
10 *
11 * Plugin class. This class should ideally be used to work with the
12 * administrative side of the WordPress site.
13 */
14
15 class Advanced_Ads_Admin {
16
17 /**
18 * Instance of this class.
19 *
20 * @since 1.0.0
21 * @var object
22 */
23 protected static $instance = null;
24
25 /**
26 * Instance of admin notice class.
27 *
28 * @since 1.5.2
29 * @var object
30 */
31 protected $notices = null;
32
33 /**
34 * Slug of the settings page
35 *
36 * @since 1.0.0
37 * @var string
38 */
39 public $plugin_screen_hook_suffix = null;
40
41 /**
42 * General plugin slug
43 *
44 * @since 1.0.0
45 * @var string
46 */
47 protected $plugin_slug = '';
48
49 /**
50 * Initialize the plugin by loading admin scripts & styles and adding a
51 * settings page and menu.
52 *
53 * @since 1.0.0
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 * @since version 1.7.16 (early January 2017)
76 */
77 public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) {
78 return Advanced_Ads_Admin_Licenses::get_instance()->deactivate_license( $addon, $plugin_name, $options_slug ); }
79
80 /**
81 * Get license status.
82 *
83 * @param string $slug slug of the add-on.
84 * @return string license status
85 */
86 public function get_license_status( $slug = '' ) {
87 return Advanced_Ads_Admin_Licenses::get_instance()->get_license_status( $slug ); }
88
89 /**
90 * Actions and filter available after all plugins are initialized.
91 */
92 public function wp_plugins_loaded() {
93 /*
94 * Call $plugin_slug from public plugin class.
95 *
96 */
97 $plugin = Advanced_Ads::get_instance();
98 $this->plugin_slug = $plugin->get_plugin_slug();
99
100 add_action( 'current_screen', array( $this, 'current_screen' ) );
101
102 // Load admin style sheet and JavaScript.
103 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
104 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 9 );
105
106 // update placements.
107 add_action( 'admin_init', array( 'Advanced_Ads_Placements', 'update_placements' ) );
108
109 // check for update logic.
110 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
111
112 // add links to plugin page.
113 add_filter( 'plugin_action_links_' . ADVADS_BASE, array( $this, 'add_plugin_links' ) );
114
115 // display information when user is going to disable the plugin.
116 add_filter( 'admin_footer', array( $this, 'add_deactivation_logic' ) );
117 // add_filter( 'after_plugin_row_' . ADVADS_BASE, array( $this, 'display_deactivation_message' ) );
118 // disable adding rel="noopener noreferrer" to link added through TinyMCE for rich content ads.
119 add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_allow_unsafe_link_target' ) );
120
121 add_action( 'plugins_api_result', array( $this, 'recommend_suitable_add_ons' ), 11, 3 );
122
123 Advanced_Ads_Admin_Meta_Boxes::get_instance();
124 Advanced_Ads_Admin_Menu::get_instance();
125 Advanced_Ads_Admin_Ad_Type::get_instance();
126 Advanced_Ads_Admin_Settings::get_instance();
127 }
128
129 /**
130 * Actions and filters that should also be available for ajax
131 */
132 public function wp_plugins_loaded_ajax() {
133 // needed here in order to work with Quick Edit option on ad list page.
134 Advanced_Ads_Admin_Ad_Type::get_instance();
135
136 add_action( 'wp_ajax_advads_send_feedback', array( $this, 'send_feedback' ) );
137 add_action( 'wp_ajax_advads_load_rss_widget_content', array( 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ) );
138 }
139
140 /**
141 * Return an instance of this class.
142 *
143 * @since 1.0.0
144 *
145 * @return object A single instance of this class.
146 */
147 public static function get_instance() {
148 // If the single instance hasn't been set, set it now.
149 if ( null === self::$instance ) {
150 self::$instance = new self();
151 }
152
153 return self::$instance;
154 }
155
156 /**
157 * General stuff after page is loaded and screen variable is available
158 */
159 public function current_screen() {
160 $screen = get_current_screen();
161
162 if ( ! isset( $screen->id ) ) {
163 return;
164 }
165
166 switch ( $screen->id ) {
167 case 'edit-advanced_ads': // ad overview page.
168 case 'advanced_ads': // ad edit page.
169 // remove notice about missing first ad.
170 break;
171 }
172 }
173
174 /**
175 * Register and enqueue admin-specific style sheet.
176 *
177 * @since 1.0.0
178 */
179 public function enqueue_admin_styles() {
180 wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), ADVADS_VERSION );
181 if ( self::screen_belongs_to_advanced_ads() ) {
182 // jQuery ui smoothness style 1.11.4.
183 wp_enqueue_style( $this->plugin_slug . '-jquery-ui-styles', plugins_url( 'assets/jquery-ui/jquery-ui.min.css', __FILE__ ), array(), '1.11.4' );
184 }
185 }
186
187 /**
188 * Register and enqueue admin-specific JavaScript.
189 *
190 * @since 1.0.0
191 */
192 public function enqueue_admin_scripts() {
193
194 // global js script.
195 wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
196 wp_enqueue_script( $this->plugin_slug . '-admin-find-adblocker', plugins_url( 'assets/js/advertisement.js', __FILE__ ), array(), ADVADS_VERSION, false );
197
198 // register ajax nonce.
199 $params = array(
200 'ajax_nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
201 );
202 wp_localize_script( $this->plugin_slug . '-admin-global-script', 'advadsglobal', $params );
203
204 if ( self::screen_belongs_to_advanced_ads() ) {
205 wp_register_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-autocomplete', 'jquery-ui-button' ), ADVADS_VERSION, false );
206 wp_register_script( $this->plugin_slug . '-wizard-script', plugins_url( 'assets/js/wizard.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
207
208 // jquery ui.
209 wp_enqueue_script( 'jquery-ui-accordion' );
210 wp_enqueue_script( 'jquery-ui-button' );
211 wp_enqueue_script( 'jquery-ui-tooltip' );
212
213 // just register this script for later inclusion on ad group list page.
214 wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
215
216 $auto_ads_strings = Advanced_Ads_AdSense_Admin::get_auto_ads_messages();
217
218 // register admin.js translations.
219 $translation_array = array(
220 'condition_or' => __( 'or', 'advanced-ads' ),
221 'condition_and' => __( 'and', 'advanced-ads' ),
222 'after_paragraph_promt' => __( 'After which paragraph?', 'advanced-ads' ),
223 'page_level_ads_enabled' => $auto_ads_strings['enabled'],
224 );
225
226 wp_localize_script( $this->plugin_slug . '-admin-script', 'advadstxt', $translation_array );
227
228 wp_enqueue_script( $this->plugin_slug . '-admin-script' );
229 wp_enqueue_script( $this->plugin_slug . '-wizard-script' );
230 }
231
232 // call media manager for image upload only on ad edit pages.
233 $screen = get_current_screen();
234 if ( isset( $screen->id ) && Advanced_Ads::POST_TYPE_SLUG === $screen->id ) {
235 // the 'wp_enqueue_media' function can be executed only once and should be called with the 'post' parameter
236 // 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.
237 // since other plugins can call the 'wp_enqueue_media' function without the 'post' parameter, Advanced Ads should call it earlier.
238 global $post;
239 wp_enqueue_media( array( 'post' => $post ) );
240 }
241
242 }
243
244 /**
245 * Check if the current screen belongs to Advanced Ads
246 *
247 * @since 1.6.6
248 * @return bool true if screen belongs to Advanced Ads
249 */
250 public static function screen_belongs_to_advanced_ads() {
251
252 if ( ! function_exists( 'get_current_screen' ) ) {
253 return false;
254 }
255
256 $screen = get_current_screen();
257 if ( ! isset( $screen->id ) ) {
258 return false;
259 }
260
261 $advads_pages = apply_filters(
262 'advanced-ads-dashboard-screens', array(
263 'advanced-ads_page_advanced-ads-groups', // ad groups.
264 'edit-advanced_ads', // ads overview.
265 'advanced_ads', // ad edit page.
266 'advanced-ads_page_advanced-ads-placements', // placements.
267 'advanced-ads_page_advanced-ads-settings', // settings.
268 'toplevel_page_advanced-ads', // overview.
269 'admin_page_advanced-ads-debug', // debug.
270 // 'advanced-ads_page_advanced-ads-support', // support.
271 'admin_page_advanced-ads-import-export', // import & export.
272 )
273 );
274
275 if ( in_array( $screen->id, $advads_pages, true ) ) {
276 return true;
277 }
278
279 return false;
280 }
281
282 /**
283 * Get action from the params
284 *
285 * @since 1.0.0
286 */
287 public function current_action() {
288 $request = wp_unslash( $_REQUEST );
289 if ( isset( $request['action'] ) && -1 !== $request['action'] ) {
290 return $request['action'];
291 }
292
293 return false;
294 }
295
296 /**
297 * Get DateTimeZone object for the WP installation
298 */
299 public static function get_wp_timezone() {
300 $_time_zone = get_option( 'timezone_string' );
301 $time_zone = new DateTimeZone( 'UTC' );
302 if ( $_time_zone ) {
303 $time_zone = new DateTimeZone( $_time_zone );
304 } else {
305 $gmt_offset = floatval( get_option( 'gmt_offset' ) );
306 $sign = ( 0 > $gmt_offset ) ? '-' : '+';
307 $int = floor( abs( $gmt_offset ) );
308 $frac = abs( $gmt_offset ) - $int;
309
310 $gmt = '';
311 if ( $gmt_offset ) {
312 $gmt .= $sign . zeroise( $int, 2 ) . ':' . zeroise( 60 * $frac, 2 );
313 $time_zone = date_create( '2017-10-01T12:00:00' . $gmt )->getTimezone();
314 }
315 }
316 return $time_zone;
317 }
318
319 /**
320 * Get literal expression of timezone
321 *
322 * @param DateTimeZone $date_time_zone the DateTimeZone object to get literal value from.
323 */
324 public static function timezone_get_name( $date_time_zone ) {
325 if ( $date_time_zone instanceof DateTimeZone ) {
326 $time_zone = timezone_name_get( $date_time_zone );
327 if ( 'UTC' === $time_zone ) {
328 return 'UTC+0';
329 }
330 if ( false === strpos( $time_zone, '/' ) ) {
331 $time_zone = 'UTC' . $time_zone;
332 } else {
333 // translators: time zone name.
334 $time_zone = sprintf( __( 'time of %s', 'advanced-ads' ), $time_zone );
335 }
336 return $time_zone;
337 }
338 return 'UTC+0';
339 }
340
341 /**
342 * Initiate the admin notices class
343 *
344 * @since 1.5.3
345 */
346 public function admin_notices() {
347 // display ad block warning to everyone who can edit ads.
348 if ( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
349 if ( $this->screen_belongs_to_advanced_ads() ) {
350 include ADVADS_BASE_PATH . 'admin/views/notices/adblock.php';
351 include ADVADS_BASE_PATH . 'admin/views/notices/jqueryui_error.php';
352 }
353 }
354
355 if ( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
356 $this->notices = Advanced_Ads_Admin_Notices::get_instance()->notices;
357 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
358 }
359 }
360
361 /**
362 * Add links to the plugins list
363 *
364 * @since 1.6.14
365 * @param arr $links array of links for the plugins, adapted when the current plugin is found.
366 * @return array $links
367 */
368 public function add_plugin_links( $links ) {
369
370 if ( ! is_array( $links ) ) {
371 return $links;
372 }
373
374 // add link to support page.
375 $support_link = '<a href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) ) . '">' . __( 'Support', 'advanced-ads' ) . '</a>';
376 array_unshift( $links, $support_link );
377
378 // add link to add-ons.
379 $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>';
380 array_unshift( $links, $extend_link );
381
382 return $links;
383 }
384
385 /**
386 * Display deactivation logic on plugins page
387 *
388 * @since 1.7.14
389 */
390 public function add_deactivation_logic() {
391
392 $screen = get_current_screen();
393 if ( ! isset( $screen->id ) || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
394 return;
395 }
396
397 $current_user = wp_get_current_user();
398 if ( ! ( $current_user instanceof WP_User ) ) {
399 $from = '';
400 $email = '';
401 } else {
402 $from = $current_user->user_nicename . ' <' . trim( $current_user->user_email ) . '>';
403 $email = $current_user->user_email;
404 }
405
406 include ADVADS_BASE_PATH . 'admin/views/feedback-disable.php';
407 }
408
409 /**
410 * Send feedback via email
411 *
412 * @since 1.7.14
413 */
414 public function send_feedback() {
415 /**
416 * We first need to get the form data from the string and can verify the nonce afterwards
417 * This throws an issue with the WP Coding Standards though
418 */
419 if ( isset( $_POST['formdata'] ) ) {
420 parse_str( wp_unslash( $_POST['formdata'] ), $form );
421 }
422
423 if ( ! wp_verify_nonce( $form['advanced_ads_disable_form_nonce'], 'advanced_ads_disable_form' ) ) {
424 die();
425 }
426
427 $text = '';
428 if ( isset( $form['advanced_ads_disable_text'] ) ) {
429 $text = implode( "\n\r", $form['advanced_ads_disable_text'] );
430 }
431
432 // get first version to see if this is a new problem or might be an older on.
433 $options = Advanced_Ads_Plugin::get_instance()->internal_options();
434 $installed = isset( $options['installed'] ) ? date( 'd.m.Y', $options['installed'] ) : '';
435
436 $text .= "\n\n" . home_url() . " ($installed)";
437
438 $headers = array();
439
440 $from = isset( $form['advanced_ads_disable_from'] ) ? $form['advanced_ads_disable_from'] : '';
441 // the user clicked on the "don’t disable" button or if an address is given in the form then use that one.
442 if ( isset( $form['advanced_ads_disable_reason'] )
443 && 'get help' === $form['advanced_ads_disable_reason']
444 && ! empty( $form['advanced_ads_disable_reply_email'] ) ) {
445 $email = isset( $form['advanced_ads_disable_reply_email'] ) ? trim( $form['advanced_ads_disable_reply_email'] ) : $current_user->email;
446 $current_user = wp_get_current_user();
447 $name = ( $current_user instanceof WP_User ) ? $current_user->user_nicename : '';
448 $from = $name . ' <' . $email . '>';
449 $is_german = ( preg_match( '/\.de$/', $from ) || "de_" === substr( get_locale(), 0, 3 ) || "de_" === substr( get_user_locale(), 0, 3 ) );
450 if ( isset( $form['advanced_ads_disable_text'][0] )
451 && trim( $form['advanced_ads_disable_text'][0] ) !== '' ) { // is a text given then ask for help.
452 // send German text
453 if( $is_german ){
454 $text .= "\n\n Hilfe ist auf dem Weg.";
455 } else {
456 $text .= "\n\n Help is on its way.";
457 }
458 } else { // if no text is given, just reply.
459 if( $is_german ){
460 $text .= "\n\n Vielen Dank für das Feedback.";
461 } else {
462 $text .= "\n\n Thank you for your feedback.";
463 }
464 }
465 }
466 if ( $from ) {
467 $headers[] = "From: $from";
468 $headers[] = "Reply-To: $from";
469 }
470
471 $subject = isset( $form['advanced_ads_disable_reason'] ) ? $form['advanced_ads_disable_reason'] : '(no reason given)';
472 // append plugin name to get a better subject.
473 $subject .= ' (Advanced Ads)';
474
475 $success = wp_mail( 'improve@wpadvancedads.com', $subject, $text, $headers );
476
477 die();
478
479 }
480
481 /**
482 * Configure TinyMCE to allow unsafe link target.
483 *
484 * @param boolean $mce_init the tinyMce initialization array.
485 * @return boolean
486 */
487 public function tinymce_allow_unsafe_link_target( $mce_init ) {
488
489 // check if we are on the ad edit screen.
490 if ( ! function_exists( 'get_current_screen' ) ) {
491 return $mce_init;
492 }
493
494 $screen = get_current_screen();
495 if ( isset( $screen->id ) && 'advanced_ads' === $screen->id ) {
496 $mce_init['allow_unsafe_link_target'] = true;
497 }
498
499 return $mce_init;
500 }
501
502 /**
503 * Sort visitor and display condition arrays alphabetically by their label.
504 *
505 * @param array $a array to be compared.
506 * @param array $b array to be compared.
507 * @since 1.8.12
508 */
509 public static function sort_condition_array_by_label( $a, $b ) {
510 if ( ! isset( $a['label'] ) || ! isset( $b['label'] ) ) {
511 return;
512 }
513 return strcmp( strtolower( $a['label'] ), strtolower( $b['label'] ) );
514 }
515
516 /**
517 * Recommend additional add-ons
518 *
519 * @param object $result original result object.
520 * @param unknown $action action.
521 * @param object $args additional arguments.
522 */
523 public function recommend_suitable_add_ons( $result, $action, $args ) {
524 if ( empty( $args->browse ) ) {
525 return $result;
526 }
527
528 if ( 'featured' !== $args->browse && 'recommended' !== $args->browse && 'popular' !== $args->browse ) {
529 return $result;
530 }
531
532 if ( ! isset( $result->info['page'] ) || 1 < $result->info['page'] ) {
533 return $result;
534 }
535
536 // Recommend AdSense In-Feed add-on.
537 if ( ! is_plugin_active( 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' )
538 && ! is_plugin_active_for_network( 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' ) ) {
539
540 // Grab all slugs from the api results.
541 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
542
543 if ( in_array( 'advanced-ads-adsense-in-feed', $result_slugs, true ) ) {
544 return $result;
545 }
546
547 $query_args = array(
548 'slug' => 'advanced-ads-adsense-in-feed',
549 'fields' => array(
550 'icons' => true,
551 'active_installs' => true,
552 'short_description' => true,
553 'group' => true,
554 ),
555 );
556 $plugin_data = plugins_api( 'plugin_information', $query_args );
557
558 if ( ! is_wp_error( $plugin_data ) ) {
559 if ( 'featured' === $args->browse ) {
560 array_push( $result->plugins, $plugin_data );
561 } else {
562 array_unshift( $result->plugins, $plugin_data );
563 }
564 }
565 }
566
567 // Recommend Genesis Ads add-on.
568 if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME
569 && ! is_plugin_active( 'advanced-ads-genesis/genesis-ads.php' )
570 && ! is_plugin_active_for_network( 'advanced-ads-genesis/genesis-ads.php' ) ) {
571
572 // Grab all slugs from the api results.
573 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
574
575 if ( in_array( 'advanced-ads-genesis', $result_slugs, true ) ) {
576 return $result;
577 }
578
579 $query_args = array(
580 'slug' => 'advanced-ads-genesis',
581 'fields' => array(
582 'icons' => true,
583 'active_installs' => true,
584 'short_description' => true,
585 'group' => true,
586 ),
587 );
588 $plugin_data = plugins_api( 'plugin_information', $query_args );
589
590 if ( ! is_wp_error( $plugin_data ) ) {
591 if ( 'featured' === $args->browse ) {
592 array_push( $result->plugins, $plugin_data );
593 } else {
594 array_unshift( $result->plugins, $plugin_data );
595 }
596 }
597 }
598
599 // Recommend WP Bakery (former Visual Composer) add-on.
600 if ( defined( 'WPB_VC_VERSION' )
601 && ! is_plugin_active( 'ads-for-visual-composer/advanced-ads-vc.php' )
602 && ! is_plugin_active_for_network( 'ads-for-visual-composer/advanced-ads-vc.php' ) ) {
603
604 // Grab all slugs from the api results.
605 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
606
607 if ( in_array( 'ads-for-visual-composer', $result_slugs, true ) ) {
608 return $result;
609 }
610
611 $query_args = array(
612 'slug' => 'ads-for-visual-composer',
613 'fields' => array(
614 'icons' => true,
615 'active_installs' => true,
616 'short_description' => true,
617 'group' => true,
618 ),
619 );
620 $plugin_data = plugins_api( 'plugin_information', $query_args );
621
622 if ( ! is_wp_error( $plugin_data ) ) {
623 if ( 'featured' === $args->browse ) {
624 array_push( $result->plugins, $plugin_data );
625 } else {
626 array_unshift( $result->plugins, $plugin_data );
627 }
628 }
629 }
630
631 return $result;
632 }
633
634 /**
635 * Overrides WordPress text in Footer
636 *
637 * @param String $default_text The default footer text.
638 *
639 * @return string
640 */
641 public function admin_footer_text( $default_text ) {
642 if ( $this->screen_belongs_to_advanced_ads() ) {
643
644 /* translators: %s is the URL to add a new review, https://wordpress.org/support/plugin/advanced-ads/reviews/?filter=5#new-post */
645 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/?filter=5#new-post' );
646
647 }
648 return $default_text;
649 }
650
651 }
652