PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.7.0.2
Advanced Ads – Ad Manager & AdSense v1.7.0.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 / classes / plugin.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 10 years ago ad-ajax.php 10 years ago ad-model.php 11 years ago ad-select.php 10 years ago ad.php 10 years ago ad_ajax_callbacks.php 10 years ago ad_group.php 10 years ago ad_placements.php 10 years ago ad_type_abstract.php 11 years ago ad_type_content.php 10 years ago ad_type_image.php 10 years ago ad_type_plain.php 10 years ago checks.php 10 years ago display-conditions.php 10 years ago plugin.php 10 years ago upgrades.php 10 years ago visitor-conditions.php 10 years ago widget.php 10 years ago
plugin.php
465 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 *
16 * @var Advanced_Ads_Plugin
17 */
18 protected static $instance;
19
20 /**
21 *
22 * @var Advanced_Ads_Model
23 */
24 protected $model;
25
26 /**
27 * plugin options
28 *
29 * @since 1.0.1
30 * @var array (if loaded)
31 */
32 protected $options;
33
34 /**
35 * interal plugin options – set by the plugin
36 *
37 * @since 1.4.5
38 * @var array (if loaded)
39 */
40 protected $internal_options;
41
42 /**
43 * default prefix of selectors (id, class) in the frontend
44 * can be changed by options
45 *
46 * @var Advanced_Ads_Plugin
47 */
48 const DEFAULT_FRONTEND_PREFIX = 'advads-';
49
50
51 private function __construct() {
52 register_activation_hook( dirname( __FILE__ ), array( $this, 'activate' ) );
53 register_deactivation_hook( dirname( __FILE__ ), array( $this, 'deactivate' ) );
54
55 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
56 }
57
58 /**
59 *
60 * @return Advanced_Ads_Plugin
61 */
62 public static function get_instance() {
63 // If the single instance hasn't been set, set it now.
64 if ( null === self::$instance ) {
65 self::$instance = new self;
66 }
67
68 return self::$instance;
69 }
70
71 /**
72 *
73 * @param Advanced_Ads_Model $model
74 */
75 public function set_model(Advanced_Ads_Model $model) {
76 $this->model = $model;
77 }
78
79 public function wp_plugins_loaded() {
80 // Load plugin text domain
81 $this->load_plugin_textdomain();
82
83 $internal_options = $this->internal_options();
84
85 /**
86 * run upgrades, if this is a new version
87 */
88 if ( !defined( 'DOING_AJAX' ) && isset( $internal_options['version'] ) && version_compare( $internal_options['version'], ADVADS_VERSION, '<' ) ) {
89 new Advanced_Ads_Upgrades();
90 }
91
92 // activate plugin when new blog is added on multisites // -TODO this is admin-only
93 add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
94
95 // Load public-facing style sheet and JavaScript.
96 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
97 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
98
99 // add short codes
100 add_shortcode( 'the_ad', array( $this, 'shortcode_display_ad' ) );
101 add_shortcode( 'the_ad_group', array( $this, 'shortcode_display_ad_group' ) );
102 add_shortcode( 'the_ad_placement', array( $this, 'shortcode_display_ad_placement' ) );
103
104 // remove default ad group menu item // -TODO only for admin
105 add_action( 'admin_menu', array( $this, 'remove_taxonomy_menu_item' ) );
106 // load widgets
107 add_action( 'widgets_init', array( $this, 'widget_init' ) );
108
109 // load display conditions
110 new Advanced_Ads_Display_Conditions();
111 }
112
113 /**
114 * Register and enqueue public-facing style sheet.
115 *
116 * @since 1.0.0
117 */
118 public function enqueue_styles() {
119 // wp_enqueue_style( $this->get_plugin_slug() . '-plugin-styles', plugins_url('assets/css/public.css', __FILE__), array(), ADVADS_VERSION);
120 }
121
122 /**
123 * Return the plugin slug.
124 *
125 * @since 1.0.0
126 * @return Plugin slug variable.
127 */
128 public function get_plugin_slug() {
129 return ADVADS_SLUG;
130 }
131
132 /**
133 * Register and enqueues public-facing JavaScript files.
134 *
135 * @since 1.0.0
136 */
137 public function enqueue_scripts() {
138 // wp_enqueue_script( $this->get_plugin_slug() . '-plugin-script', plugins_url('assets/js/public.js', __FILE__), array('jquery'), ADVADS_VERSION);
139 $options = $this->options();
140 $activated_js = apply_filters( 'advanced-ads-activate-advanced-js', isset( $options['advanced-js'] ) );
141 if ( $activated_js ){
142 wp_enqueue_script( $this->get_plugin_slug() . '-advanced-js', ADVADS_BASE_URL . 'public/assets/js/advanced.js', array( 'jquery' ), ADVADS_VERSION );
143 }
144 }
145
146 public function widget_init() {
147 register_widget( 'Advanced_Ads_Widget' );
148 }
149
150 /**
151 * Fired when a new site is activated with a WPMU environment.
152 *
153 * @since 1.0.0
154 * @param int $blog_id ID of the new blog.
155 */
156 public function activate_new_site($blog_id) {
157
158 if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
159 return;
160 }
161
162 switch_to_blog( $blog_id );
163 $this->single_activate();
164 restore_current_blog();
165 }
166
167 /**
168 * Fired for each blog when the plugin is activated.
169 *
170 * @since 1.0.0
171 */
172 protected function single_activate() {
173 $this->post_types_rewrite_flush();
174 // -TODO inform modules
175 }
176
177 /**
178 * Fired for each blog when the plugin is deactivated.
179 *
180 * @since 1.0.0
181 */
182 protected function single_deactivate() {
183 // -TODO inform modules
184 }
185
186 /**
187 * Load the plugin text domain for translation.
188 *
189 * @since 1.0.0
190 */
191 public function load_plugin_textdomain() {
192 // $locale = apply_filters('advanced-ads-plugin-locale', get_locale(), $domain);
193 load_plugin_textdomain( ADVADS_SLUG, false, ADVADS_BASE_DIR . '/languages' );
194 }
195
196 /**
197 * Fired when the plugin is activated.
198 *
199 * @since 1.0.0
200 * @param boolean $network_wide True if WPMU superadmin uses
201 * "Network Activate" action, false if
202 * WPMU is disabled or plugin is
203 * activated on an individual blog.
204 */
205 public function activate($network_wide) {
206
207 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
208
209 if ( $network_wide ) {
210
211 // Get all blog ids
212 $blog_ids = $this->model->get_blog_ids();
213
214 foreach ( $blog_ids as $blog_id ) {
215
216 switch_to_blog( $blog_id );
217 $this->single_activate();
218 }
219
220 restore_current_blog();
221 } else {
222 $this->single_activate();
223 }
224 } else {
225 $this->single_activate();
226 }
227 }
228
229 /**
230 * Fired when the plugin is deactivated.
231 *
232 * @since 1.0.0
233 * @param boolean $network_wide
234 *
235 * True if WPMU superadmin uses
236 * "Network Deactivate" action, false if
237 * WPMU is disabled or plugin is
238 * deactivated on an individual blog.
239 */
240 public function deactivate($network_wide) {
241
242 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
243
244 if ( $network_wide ) {
245
246 // Get all blog ids
247 $blog_ids = $this->model->get_blog_ids();
248
249 foreach ( $blog_ids as $blog_id ) {
250
251 switch_to_blog( $blog_id );
252 $this->single_deactivate();
253 }
254
255 restore_current_blog();
256 } else {
257 $this->single_deactivate();
258 }
259 } else {
260 $this->single_deactivate();
261 }
262 }
263
264 /**
265 * flush rewrites on plugin activation so permalinks for them work from the beginning on
266 *
267 * @since 1.0.0
268 * @link http://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation
269 */
270 public function post_types_rewrite_flush(){
271 // load custom post type
272 Advanced_Ads::get_instance()->create_post_types();
273 // flush rewrite rules
274 flush_rewrite_rules();
275 }
276
277 /**
278 * remove WP tag edit page for the ad group taxonomy
279 * needed, because we can’t remove it with `show_ui` without also removing the meta box
280 *
281 * @since 1.0.0
282 */
283 public function remove_taxonomy_menu_item() {
284 remove_submenu_page( 'edit.php?post_type=advanced_ads', 'edit-tags.php?taxonomy=advanced_ads_groups&amp;post_type=advanced_ads' );
285 }
286
287 /**
288 * shortcode to include ad in frontend
289 *
290 * @since 1.0.0
291 * @param arr $atts
292 */
293 public function shortcode_display_ad($atts){
294 $id = isset($atts['id']) ? (int) $atts['id'] : 0;
295
296 // use the public available function here
297 return get_ad( $id );
298 }
299
300 /**
301 * shortcode to include ad from an ad group in frontend
302 *
303 * @since 1.0.0
304 * @param arr $atts
305 */
306 public function shortcode_display_ad_group($atts){
307 $id = isset($atts['id']) ? (int) $atts['id'] : 0;
308
309 // use the public available function here
310 return get_ad_group( $id );
311 }
312
313 /**
314 * shortcode to display content of an ad placement in frontend
315 *
316 * @since 1.1.0
317 * @param arr $atts
318 */
319 public function shortcode_display_ad_placement($atts){
320 $id = isset($atts['id']) ? (string) $atts['id'] : '';
321
322 // use the public available function here
323 return get_ad_placement( $id );
324 }
325
326 /**
327 * return plugin options
328 * these are the options updated by the user
329 *
330 * @since 1.0.1
331 * @return array $options
332 * @todo parse default options
333 */
334 public function options() {
335 if ( ! isset( $this->options ) ) {
336 $this->options = get_option( ADVADS_SLUG, array() );
337 }
338
339 return $this->options;
340 }
341
342 /**
343 * update plugin options (not for settings page, but if automatic options are needed)
344 *
345 * @since 1.5.1
346 * @param array $options new options
347 */
348 public function update_options( array $options ) {
349 // do not allow to clear options
350 if ( $options === array() ) {
351 return;
352 }
353
354 $this->options = $options;
355 update_option( ADVADS_SLUG, $options );
356 }
357
358 /**
359 * return internal plugin options
360 * these are options set by the plugin
361 *
362 * @since 1.0.1
363 * @return array $options
364 * @todo parse default options
365 */
366 public function internal_options() {
367 if ( ! isset( $this->internal_options ) ) {
368 $defaults = array(
369 'version' => ADVADS_VERSION,
370 'installed' => time(), // when was this installed
371 );
372 $this->internal_options = get_option( ADVADS_SLUG . '-internal', array() );
373
374 // save defaults
375 if($this->internal_options === array()){
376 $this->internal_options = $defaults;
377 $this->update_internal_options($this->internal_options);
378 }
379
380 // for versions installed prior to 1.5.3 set installed date for now
381 if( ! isset( $this->internal_options['installed'] )){
382 $this->internal_options['installed'] = time();
383 $this->update_internal_options($this->internal_options);
384 }
385 }
386
387 return $this->internal_options;
388 }
389
390 /**
391 * update internal plugin options
392 *
393 * @since 1.5.1
394 * @param array $options new internal options
395 */
396 public function update_internal_options( array $options ) {
397 // do not allow to clear options
398 if ( $options === array() ) {
399 return;
400 }
401
402 $this->internal_options = $options;
403 update_option( ADVADS_SLUG . '-internal', $options );
404 }
405
406 /**
407 * get prefix used for frontend elements
408 *
409 * @since 1.6.8.2
410 */
411 public function get_frontend_prefix(){
412 $options = $this->options();
413
414 // get previously option if new one doesn’t exist yet
415 if( !isset( $options['front-prefix'] ) ){
416 $prefix = ( isset($options['id-prefix'])) ? esc_attr( $options['id-prefix'] ) : Advanced_Ads_Plugin::DEFAULT_FRONTEND_PREFIX;
417 } else {
418 $prefix = $options['front-prefix'];
419 }
420
421 return $prefix;
422 }
423
424 /**
425 * get priority used for injection inside content
426 *
427 * @since 1.6.10.2
428 */
429 public function get_content_injection_priority(){
430 $options = $this->options();
431
432 return isset( $options['content-injection-priority'] ) ? intval( $options['content-injection-priority'] ) : 100;
433 }
434
435 /**
436 * returns the capability needed to perform an action
437 *
438 * @since 1.6.14
439 * @param str $capability a capability to check, can be internal to Advanced Ads
440 * @return str $capability a valid WordPress capability
441 */
442 public static function user_cap( $capability = 'manage_options' ){
443
444 global $advanced_ads_capabilities;
445
446 // admins can do everything
447 // is also a fallback if no option or more specific capability is given
448 if( current_user_can( 'manage_options' ) ){
449 return 'manage_options';
450 }
451
452 return apply_filters( 'advanced-ads-capability', $capability );
453
454 // check, if capability is mapped to an existing WP capability
455 /*if( isset( $advanced_ads_capabilities[ $capability ] ) ){
456 return apply_filters( 'advanced-ads-capability', $advanced_ads_capabilities[ $capability ], $capability );
457 } else {
458 // if not, use 'manage_posts' capability
459 return apply_filters( 'advanced-ads-capability', 'manage_options', $capability );
460 }*/
461
462 }
463
464 }
465