PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.7.7
Advanced Ads – Ad Manager & AdSense v1.7.7
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 / classes / plugin.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 9 years ago ad-ajax.php 9 years ago ad-model.php 9 years ago ad-select.php 9 years ago ad.php 9 years ago ad_ajax_callbacks.php 9 years ago ad_group.php 9 years ago ad_placements.php 9 years ago ad_type_abstract.php 11 years ago ad_type_content.php 10 years ago ad_type_group.php 10 years ago ad_type_image.php 10 years ago ad_type_plain.php 10 years ago checks.php 9 years ago display-conditions.php 9 years ago plugin.php 9 years ago upgrades.php 10 years ago visitor-conditions.php 10 years ago widget.php 9 years ago
plugin.php
601 lines
1 <?php
2
3 /**
4 * Wordpress integration and definitions:
5 *
6 * - posttypes
7 * - taxonomy
8 * - textdomain
9 *
10 * @since 1.5.0
11 */
12 class Advanced_Ads_Plugin {
13 /**
14 *
15 * @var Advanced_Ads_Plugin
16 */
17 protected static $instance;
18
19 /**
20 *
21 * @var Advanced_Ads_Model
22 */
23 protected $model;
24
25 /**
26 * plugin options
27 *
28 * @since 1.0.1
29 * @var array (if loaded)
30 */
31 protected $options;
32
33 /**
34 * interal plugin options – set by the plugin
35 *
36 * @since 1.4.5
37 * @var array (if loaded)
38 */
39 protected $internal_options;
40
41 /**
42 * default prefix of selectors (id, class) in the frontend
43 * can be changed by options
44 *
45 * @var Advanced_Ads_Plugin
46 */
47 const DEFAULT_FRONTEND_PREFIX = 'advads-';
48
49 /**
50 *
51 * @var frontend prefix for classes and IDs
52 */
53 private $frontend_prefix;
54
55
56 private function __construct() {
57 register_activation_hook( ADVADS_BASE, array( $this, 'activate' ) );
58 register_deactivation_hook( ADVADS_BASE, array( $this, 'deactivate' ) );
59 register_uninstall_hook( ADVADS_BASE, array( 'Advanced_Ads_Plugin', 'uninstall' ) );
60
61 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
62 }
63
64 /**
65 *
66 * @return Advanced_Ads_Plugin
67 */
68 public static function get_instance() {
69 // If the single instance hasn't been set, set it now.
70 if ( null === self::$instance ) {
71 self::$instance = new self;
72 }
73
74 return self::$instance;
75 }
76
77 /**
78 *
79 * @param Advanced_Ads_Model $model
80 */
81 public function set_model(Advanced_Ads_Model $model) {
82 $this->model = $model;
83 }
84
85 public function wp_plugins_loaded() {
86 // Load plugin text domain
87 $this->load_plugin_textdomain();
88
89 $internal_options = $this->internal_options();
90
91 /**
92 * run upgrades, if this is a new version or version does not exist
93 */
94 if ( ! defined( 'DOING_AJAX' ) && ( ! isset( $internal_options['version'] ) || version_compare( $internal_options['version'], ADVADS_VERSION, '<' ) ) ) {
95 new Advanced_Ads_Upgrades();
96 }
97
98 // activate plugin when new blog is added on multisites // -TODO this is admin-only
99 add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
100
101 // Load public-facing style sheet and JavaScript.
102 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
103 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
104
105 // add short codes
106 add_shortcode( 'the_ad', array( $this, 'shortcode_display_ad' ) );
107 add_shortcode( 'the_ad_group', array( $this, 'shortcode_display_ad_group' ) );
108 add_shortcode( 'the_ad_placement', array( $this, 'shortcode_display_ad_placement' ) );
109
110 // remove default ad group menu item // -TODO only for admin
111 add_action( 'admin_menu', array( $this, 'remove_taxonomy_menu_item' ) );
112 // load widgets
113 add_action( 'widgets_init', array( $this, 'widget_init' ) );
114
115 // load display conditions
116 Advanced_Ads_Display_Conditions::get_instance();
117 }
118
119 /**
120 * Register and enqueue public-facing style sheet.
121 *
122 * @since 1.0.0
123 */
124 public function enqueue_styles() {
125 // wp_enqueue_style( $this->get_plugin_slug() . '-plugin-styles', plugins_url('assets/css/public.css', __FILE__), array(), ADVADS_VERSION);
126 }
127
128 /**
129 * Return the plugin slug.
130 *
131 * @since 1.0.0
132 * @return Plugin slug variable.
133 */
134 public function get_plugin_slug() {
135 return ADVADS_SLUG;
136 }
137
138 /**
139 * Register and enqueues public-facing JavaScript files.
140 *
141 * @since 1.0.0
142 */
143 public function enqueue_scripts() {
144 // wp_enqueue_script( $this->get_plugin_slug() . '-plugin-script', plugins_url('assets/js/public.js', __FILE__), array('jquery'), ADVADS_VERSION);
145 $options = $this->options();
146 $activated_js = apply_filters( 'advanced-ads-activate-advanced-js', isset( $options['advanced-js'] ) );
147 if ( $activated_js ){
148 wp_enqueue_script( $this->get_plugin_slug() . '-advanced-js', ADVADS_BASE_URL . 'public/assets/js/advanced.js', array( 'jquery' ), ADVADS_VERSION );
149 }
150 }
151
152 public function widget_init() {
153 register_widget( 'Advanced_Ads_Widget' );
154 }
155
156 /**
157 * Fired when a new site is activated with a WPMU environment.
158 *
159 * @since 1.0.0
160 * @param int $blog_id ID of the new blog.
161 */
162 public function activate_new_site($blog_id) {
163
164 if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
165 return;
166 }
167
168 switch_to_blog( $blog_id );
169 $this->single_activate();
170 restore_current_blog();
171 }
172
173 /**
174 * Fired for each blog when the plugin is activated.
175 *
176 * @since 1.0.0
177 */
178 protected function single_activate() {
179 // $this->post_types_rewrite_flush();
180 // -TODO inform modules
181 }
182
183 /**
184 * Fired for each blog when the plugin is deactivated.
185 *
186 * @since 1.0.0
187 */
188 protected function single_deactivate() {
189 // -TODO inform modules
190 }
191
192 /**
193 * Load the plugin text domain for translation.
194 *
195 * @since 1.0.0
196 */
197 public function load_plugin_textdomain() {
198 // $locale = apply_filters('advanced-ads-plugin-locale', get_locale(), $domain);
199 load_plugin_textdomain( ADVADS_SLUG, false, ADVADS_BASE_DIR . '/languages' );
200 }
201
202 /**
203 * Fired when the plugin is activated.
204 *
205 * @since 1.0.0
206 * @param boolean $network_wide True if WPMU superadmin uses
207 * "Network Activate" action, false if
208 * WPMU is disabled or plugin is
209 * activated on an individual blog.
210 */
211 public function activate($network_wide) {
212 $this->create_capabilities();
213
214 return;
215 // was never used nor missed, but could come in handy one day
216
217 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
218
219 if ( $network_wide ) {
220
221 // Get all blog ids
222 $blog_ids = $this->model->get_blog_ids();
223
224 foreach ( $blog_ids as $blog_id ) {
225
226 switch_to_blog( $blog_id );
227 $this->single_activate();
228 }
229
230 restore_current_blog();
231 } else {
232 $this->single_activate();
233 }
234 } else {
235 $this->single_activate();
236 }
237 }
238
239 /**
240 * Fired when the plugin is deactivated.
241 *
242 * @since 1.0.0
243 * @param boolean $network_wide
244 *
245 * True if WPMU superadmin uses
246 * "Network Deactivate" action, false if
247 * WPMU is disabled or plugin is
248 * deactivated on an individual blog.
249 */
250 public function deactivate($network_wide) {
251 $this->remove_capabilities();
252
253 return;
254
255 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
256
257 if ( $network_wide ) {
258
259 // Get all blog ids
260 $blog_ids = $this->model->get_blog_ids();
261
262 foreach ( $blog_ids as $blog_id ) {
263
264 switch_to_blog( $blog_id );
265 $this->single_deactivate();
266 }
267
268 restore_current_blog();
269 } else {
270 $this->single_deactivate();
271 }
272 } else {
273 $this->single_deactivate();
274 }
275 }
276
277 /**
278 * flush rewrites on plugin activation so permalinks for them work from the beginning on
279 *
280 * @since 1.0.0
281 * @link http://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation
282 */
283 /*public function post_types_rewrite_flush(){
284 // load custom post type
285 Advanced_Ads::get_instance()->create_post_types();
286 // flush rewrite rules
287 flush_rewrite_rules();
288 }*/
289
290 /**
291 * remove WP tag edit page for the ad group taxonomy
292 * needed, because we can’t remove it with `show_ui` without also removing the meta box
293 *
294 * @since 1.0.0
295 */
296 public function remove_taxonomy_menu_item() {
297 remove_submenu_page( 'edit.php?post_type=advanced_ads', 'edit-tags.php?taxonomy=advanced_ads_groups&amp;post_type=advanced_ads' );
298 }
299
300 /**
301 * shortcode to include ad in frontend
302 *
303 * @since 1.0.0
304 * @param arr $atts
305 */
306 public function shortcode_display_ad($atts){
307 $id = isset($atts['id']) ? (int) $atts['id'] : 0;
308
309 // use the public available function here
310 return get_ad( $id );
311 }
312
313 /**
314 * shortcode to include ad from an ad group in frontend
315 *
316 * @since 1.0.0
317 * @param arr $atts
318 */
319 public function shortcode_display_ad_group($atts){
320 $id = isset($atts['id']) ? (int) $atts['id'] : 0;
321
322 // use the public available function here
323 return get_ad_group( $id );
324 }
325
326 /**
327 * shortcode to display content of an ad placement in frontend
328 *
329 * @since 1.1.0
330 * @param arr $atts
331 */
332 public function shortcode_display_ad_placement($atts){
333 $id = isset($atts['id']) ? (string) $atts['id'] : '';
334
335 // use the public available function here
336 return get_ad_placement( $id );
337 }
338
339 /**
340 * return plugin options
341 * these are the options updated by the user
342 *
343 * @since 1.0.1
344 * @return array $options
345 * @todo parse default options
346 */
347 public function options() {
348 if ( ! isset( $this->options ) ) {
349 $this->options = get_option( ADVADS_SLUG, array() );
350 }
351
352 return $this->options;
353 }
354
355 /**
356 * update plugin options (not for settings page, but if automatic options are needed)
357 *
358 * @since 1.5.1
359 * @param array $options new options
360 */
361 public function update_options( array $options ) {
362 // do not allow to clear options
363 if ( $options === array() ) {
364 return;
365 }
366
367 $this->options = $options;
368 update_option( ADVADS_SLUG, $options );
369 }
370
371 /**
372 * return internal plugin options
373 * these are options set by the plugin
374 *
375 * @since 1.0.1
376 * @return array $options
377 * @todo parse default options
378 */
379 public function internal_options() {
380 if ( ! isset( $this->internal_options ) ) {
381 $defaults = array(
382 'version' => ADVADS_VERSION,
383 'installed' => time(), // when was this installed
384 );
385 $this->internal_options = get_option( ADVADS_SLUG . '-internal', array() );
386
387 // save defaults
388 if($this->internal_options === array()){
389 $this->internal_options = $defaults;
390 $this->update_internal_options($this->internal_options);
391 }
392
393 // for versions installed prior to 1.5.3 set installed date for now
394 if( ! isset( $this->internal_options['installed'] )){
395 $this->internal_options['installed'] = time();
396 $this->update_internal_options($this->internal_options);
397 }
398 }
399
400 return $this->internal_options;
401 }
402
403 /**
404 * update internal plugin options
405 *
406 * @since 1.5.1
407 * @param array $options new internal options
408 */
409 public function update_internal_options( array $options ) {
410 // do not allow to clear options
411 if ( $options === array() ) {
412 return;
413 }
414
415 $this->internal_options = $options;
416 update_option( ADVADS_SLUG . '-internal', $options );
417 }
418
419 /**
420 * get prefix used for frontend elements
421 *
422 * @since 1.6.8.2
423 */
424 public function get_frontend_prefix(){
425 if ( ! $this->frontend_prefix ) {
426 $options = $this->options();
427
428 if ( ! isset( $options['front-prefix'] ) ) {
429 if ( isset( $options['id-prefix'] ) ) {
430 // deprecated: keeps widgets working that previously received an id based on the front-prefix
431 $this->frontend_prefix = esc_attr( $options['id-prefix'] );
432 } else {
433 $host = parse_url( get_home_url(), PHP_URL_HOST );
434 $this->frontend_prefix = preg_match( '/[A-Za-z][A-Za-z0-9_]{4}/', $host, $result ) ? $result[0] . '-' : Advanced_Ads_Plugin::DEFAULT_FRONTEND_PREFIX;
435 }
436 } else {
437 $this->frontend_prefix = $options['front-prefix'];
438 }
439 }
440 return $this->frontend_prefix;
441 }
442
443 /**
444 * get priority used for injection inside content
445 *
446 * @since 1.6.10.2
447 */
448 public function get_content_injection_priority(){
449 $options = $this->options();
450
451 return isset( $options['content-injection-priority'] ) ? intval( $options['content-injection-priority'] ) : 100;
452 }
453
454 /**
455 * returns the capability needed to perform an action
456 *
457 * @since 1.6.14
458 * @param str $capability a capability to check, can be internal to Advanced Ads
459 * @return str $capability a valid WordPress capability
460 */
461 public static function user_cap( $capability = 'manage_options' ){
462
463 global $advanced_ads_capabilities;
464
465 // admins can do everything
466 // is also a fallback if no option or more specific capability is given
467 if( current_user_can( 'manage_options' ) ){
468 return 'manage_options';
469 }
470
471 return apply_filters( 'advanced-ads-capability', $capability );
472
473 // check, if capability is mapped to an existing WP capability
474 /*if( isset( $advanced_ads_capabilities[ $capability ] ) ){
475 return apply_filters( 'advanced-ads-capability', $advanced_ads_capabilities[ $capability ], $capability );
476 } else {
477 // if not, use 'manage_posts' capability
478 return apply_filters( 'advanced-ads-capability', 'manage_options', $capability );
479 }*/
480
481 }
482
483 /**
484 * Create roles and capabilities
485 *
486 */
487 public function create_capabilities() {
488 if ( $role = get_role( 'administrator' ) ) {
489 $role->add_cap( 'advanced_ads_manage_options' );
490 $role->add_cap( 'advanced_ads_see_interface' );
491 $role->add_cap( 'advanced_ads_edit_ads' );
492 $role->add_cap( 'advanced_ads_manage_placements' );
493 $role->add_cap( 'advanced_ads_place_ads' );
494 }
495 }
496
497 /**
498 * Remove roles and capabilities
499 *
500 */
501 public function remove_capabilities() {
502 if ( $role = get_role( 'administrator' ) ) {
503 $role->remove_cap( 'advanced_ads_manage_options' );
504 $role->remove_cap( 'advanced_ads_see_interface' );
505 $role->remove_cap( 'advanced_ads_edit_ads' );
506 $role->remove_cap( 'advanced_ads_manage_placements' );
507 $role->remove_cap( 'advanced_ads_place_ads' );
508 }
509 }
510
511 /**
512 * Fired when the plugin is uninstalled.
513 */
514 public static function uninstall() {
515 $advads_options = Advanced_Ads::get_instance()->options();
516
517 if ( ! empty( $advads_options['uninstall-delete-data'] ) ) {
518 global $wpdb;
519 $main_blog_id = $wpdb->blogid;
520
521 Advanced_Ads::get_instance()->create_post_types();
522
523 if ( ! is_multisite() ) {
524 Advanced_Ads_Plugin::get_instance()->uninstall_single();
525 } else {
526 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
527
528 foreach ( $blog_ids as $blog_id ) {
529 switch_to_blog( $blog_id );
530 Advanced_Ads_Plugin::get_instance()->uninstall_single();
531 }
532 switch_to_blog( $main_blog_id );
533 }
534
535 // Delete assets (main blog).
536 Advanced_Ads_Ad_Blocker_Admin::get_instance()->clear_assets();
537 delete_option( ADVADS_AB_SLUG );
538 }
539
540 }
541
542 /**
543 * Fired for each blog when the plugin is uninstalled.
544 *
545 */
546 protected function uninstall_single() {
547 global $wpdb;
548
549 // Ads.
550 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", Advanced_Ads::POST_TYPE_SLUG ) );
551
552 if ( $post_ids ) {
553 $wpdb->delete(
554 $wpdb->posts,
555 array( 'post_type' => Advanced_Ads::POST_TYPE_SLUG ),
556 array( '%s' )
557 );
558
559 $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN( " . implode( ',', $post_ids ) . " )" );
560 }
561
562 // Groups.
563 $term_ids = $wpdb->get_col( $wpdb->prepare( "SELECT t.term_id FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s", Advanced_Ads::AD_GROUP_TAXONOMY ) );
564
565 foreach ( $term_ids as $term_id ) {
566 wp_delete_term( $term_id, Advanced_Ads::AD_GROUP_TAXONOMY );
567 }
568
569 delete_option( 'advads-ad-groups' );
570 delete_option( Advanced_Ads::AD_GROUP_TAXONOMY . '_children' );
571 delete_option( 'advads-ad-weights' );
572
573 // Placements.
574 delete_option( 'advads-ads-placements' );
575
576 // User metadata.
577 delete_metadata( 'user', null, 'advanced-ads-hide-wizard', '', true );
578 delete_metadata( 'user', null, 'advanced-ads-subscribed', '', true );
579
580 // Post metadata.
581 delete_metadata( 'post', null, '_advads_ad_settings', '', true );
582
583 // Transients.
584 delete_transient( ADVADS_SLUG . '_add-on-updates-checked' );
585
586 delete_option( GADSENSE_OPT_NAME );
587 delete_option( ADVADS_SLUG );
588 delete_option( ADVADS_SLUG . '-internal' );
589 delete_option( ADVADS_SLUG . '-notices' );
590
591 // Widget.
592 $base_widget_id = Advanced_Ads_Widget::get_base_id();
593 delete_option( 'widget_' . $base_widget_id );
594
595 do_action( 'advanced-ads-uninstall' );
596
597 wp_cache_flush();
598 }
599
600 }
601