PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.47.3
Advanced Ads – Ad Manager & AdSense v1.47.3
2.0.26 2.0.25 2.0.24 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 / ad_group.php
advanced-ads / classes Last commit date
Advanced_Ads_Modal.php 2 years ago EDD_SL_Plugin_Updater.php 4 years ago ad-ajax.php 2 years ago ad-debug.php 2 years ago ad-expiration.php 3 years ago ad-health-notices.php 2 years ago ad-model.php 2 years ago ad-select.php 3 years ago ad.php 2 years ago ad_ajax_callbacks.php 2 years ago ad_group.php 2 years ago ad_placements.php 2 years ago ad_type_abstract.php 2 years ago ad_type_content.php 2 years ago ad_type_dummy.php 3 years ago ad_type_group.php 2 years ago ad_type_image.php 2 years ago ad_type_plain.php 2 years ago checks.php 2 years ago class-translation-promo.php 3 years ago compatibility.php 2 years ago display-conditions.php 2 years ago filesystem.php 3 years ago frontend_checks.php 2 years ago in-content-injector.php 2 years ago inline-css.php 2 years ago plugin.php 2 years ago upgrades.php 2 years ago utils.php 3 years ago visitor-conditions.php 2 years ago widget.php 2 years ago
ad_group.php
683 lines
1 <?php
2
3 use AdvancedAds\Entities;
4 use AdvancedAds\Utilities\WordPress;
5
6 /**
7 * An ad group object
8 *
9 * @package Advanced_Ads_Group
10 * @author Thomas Maier <support@wpadvancedads.com>
11 * @license GPL-2.0+
12 * @link https://wpadvancedads.com
13 * @copyright 2014 Thomas Maier, Advanced Ads GmbH
14 */
15 class Advanced_Ads_Group {
16
17 /**
18 * Default ad group weight
19 * previously called MAX_AD_GROUP_WEIGHT
20 */
21 const MAX_AD_GROUP_DEFAULT_WEIGHT = 10;
22
23 /**
24 * Term id of this ad group
25 */
26 public $id = 0;
27
28 /**
29 * Group type
30 *
31 * @since 1.4.8
32 */
33 public $type = 'default';
34
35 /**
36 * Name of the taxonomy
37 */
38 public $taxonomy = '';
39
40 /**
41 * Post type of the ads
42 */
43 protected $post_type = '';
44
45 /**
46 * The current loaded ad
47 */
48 protected $current_ad = '';
49
50 /**
51 * The name of the term
52 */
53 public $name = '';
54
55 /**
56 * The slug of the term
57 */
58 public $slug = '';
59
60 /**
61 * The description of the term
62 */
63 public $description = '';
64
65 /**
66 * Number of ads to display in the group block
67 */
68 public $ad_count = 1;
69
70 /**$slug
71 * contains other options
72 *
73 * @since 1.5.5
74 */
75 public $options = [];
76
77 /**
78 * Optional arguments passed to ads.
79 *
80 * @var array
81 */
82 public $ad_args = [];
83
84 /**
85 * Containing ad weights
86 */
87 private $ad_weights;
88
89 /**
90 * Array with post type objects (ads)
91 */
92 private $ads = false;
93
94 /**
95 * Multidimensional array contains information about the wrapper
96 * each possible html attribute is an array with possible multiple elements.
97 *
98 * @since untagged
99 */
100 public $wrapper = [];
101
102 /**
103 * Displayed above the ad.
104 */
105 public $label = '';
106
107 /**
108 * Whether this group is in a head placement.
109 *
110 * @var bool
111 */
112 private $is_head_placement;
113
114 /**
115 * True, if this is an Advanced Ads Ad Group
116 *
117 * @var bool
118 */
119 public $is_group = false;
120
121 /**
122 * The decorated WP_Term object.
123 *
124 * @var \WP_Term
125 */
126 private $group;
127
128 /**
129 * Init ad group object
130 *
131 * @param int|WP_Term $group Either id of the ad group or term object.
132 * @param iterable $ad_args Optional arguments passed to ads.
133 *
134 * @since 1.0.0
135 */
136 public function __construct( $group, iterable $ad_args = [] ) {
137 $this->taxonomy = Entities::TAXONOMY_AD_GROUP;
138
139 $this->group = get_term( $group, $this->taxonomy );
140 if ( $this->group === null || is_wp_error( $this->group ) ) {
141 return;
142 }
143
144 $this->is_group = true;
145 $this->id = $this->group->term_id;
146 $this->name = $this->group->name;
147 $this->slug = $this->group->slug;
148 $this->description = $this->group->description;
149 $this->post_type = Entities::POST_TYPE_AD;
150 $this->ad_args = $ad_args;
151 $this->is_head_placement = isset( $this->ad_args['placement_type'] ) && $this->ad_args['placement_type'] === 'header';
152 $this->ad_args['is_top_level'] = ! isset( $this->ad_args['is_top_level'] );
153
154 $this->load_additional_attributes();
155
156 if ( ! $this->is_head_placement ) {
157 $this->create_wrapper();
158 }
159 }
160
161 /**
162 * If a property on the original WP_Term is requested, return it, otherwise null.
163 *
164 * @param string $name The requested property name.
165 *
166 * @return mixed|null
167 * @noinspection MagicMethodsValidityInspection -- We don't want to allow setting of properties.
168 */
169 public function __get( string $name ) {
170 return $this->group->$name ?? null;
171 }
172
173 /**
174 * Whether a property is set.
175 *
176 * @param string $name The requested property name.
177 *
178 * @return bool
179 * @noinspection MagicMethodsValidityInspection -- We don't want to allow setting of properties.
180 */
181 public function __isset( string $name ): bool {
182 return isset( $this->group->$name );
183 }
184
185 /**
186 * Load additional attributes for groups that are not part of the WP terms
187 *
188 * @since 1.4.8
189 */
190 protected function load_additional_attributes() {
191 // -TODO should abstract (i.e. only call once per request)
192 $all_groups = get_option( 'advads-ad-groups', [] );
193
194 if ( ! isset( $all_groups[ $this->id ] ) || ! is_array( $all_groups[ $this->id ] ) ) { return; }
195
196 if ( isset( $this->ad_args['change-group'] ) ) {
197 // some options was provided by the user
198 $group_data = Advanced_Ads_Utils::merge_deep_array( [ $all_groups[ $this->id ], $this->ad_args['change-group'] ] ) ;
199 } else {
200 $group_data = $all_groups[ $this->id ];
201 }
202
203 if ( isset( $group_data['type'] ) ) {
204 $this->type = $group_data['type'];
205 }
206
207 // get ad count; default is 1
208 if ( isset( $group_data['ad_count'] ) ) {
209 $this->ad_count = $group_data['ad_count'] === 'all' ? 'all' : (int) $group_data['ad_count'];
210 }
211
212 if ( isset( $group_data['options'] ) ) {
213 $this->options = isset( $group_data['options'] ) ? $group_data['options'] : [];
214 }
215 }
216
217 /**
218 * Control the output of the group by type and amount of ads
219 *
220 * @param array $ordered_ad_ids Ordered ids of the ads that belong to the group.
221 *
222 * @return string $output output of ad(s) by ad
223 * @since 1.4.8
224 */
225 public function output( $ordered_ad_ids ) {
226 if ( empty( $ordered_ad_ids ) ) {
227 return '';
228 }
229
230 // load the ad output
231 $output = [];
232 $ads_displayed = 0;
233 $ad_count = apply_filters( 'advanced-ads-group-ad-count', $this->ad_count, $this );
234
235 $ad_select = Advanced_Ads_Select::get_instance();
236
237 // the Advanced_Ads_Ad obj can access this info
238 $this->ad_args['group_info'] = [
239 'id' => $this->id,
240 'name' => $this->name,
241 'type' => $this->type,
242 'refresh_enabled' => ! empty( $this->options['refresh']['enabled'] ),
243 ];
244 $this->ad_args['ad_label'] = 'disabled';
245
246 if( is_array( $ordered_ad_ids ) ){
247 foreach ( $ordered_ad_ids as $_ad_id ) {
248 $this->ad_args['group_info']['ads_displayed'] = $ads_displayed;
249
250 // load the ad output
251 $ad = $ad_select->get_ad_by_method( $_ad_id, Advanced_Ads_Select::AD, $this->ad_args );
252
253 if ( ! empty( $ad ) ) {
254 $output[] = $ad;
255 $ads_displayed++;
256 // break the loop when maximum ads are reached
257 if( $ads_displayed === $ad_count ) {
258 break;
259 }
260 }
261 }
262 }
263
264 $global_output = ! isset( $this->ad_args['global_output'] ) || $this->ad_args['global_output'];
265 if ( $global_output ) {
266 // add the group to the global output array
267 $advads = Advanced_Ads::get_instance();
268 $advads->current_ads[] = ['type' => 'group', 'id' => $this->id, 'title' => $this->name];
269 }
270
271 if ( $output === [] || ! is_array( $output ) ) {
272 return '';
273 }
274
275 // filter grouped ads output
276 $output_array = apply_filters( 'advanced-ads-group-output-array', $output, $this );
277
278 // make sure the right format comes through the filter
279 if ( $output_array === [] || ! is_array( $output_array ) ) {
280 return '';
281 }
282
283 $output_string = implode( '', $output_array );
284
285 // Adds inline css to the wrapper.
286 if ( ! empty( $this->ad_args['inline-css'] ) && $this->ad_args['is_top_level'] ) {
287 $inline_css = new Advanced_Ads_Inline_Css();
288 $this->wrapper = $inline_css->add_css( $this->wrapper, $this->ad_args['inline-css'], $global_output );
289 }
290
291 if ( ! $this->is_head_placement && $this->wrapper !== [] ) {
292 $output_string = '<div' . Advanced_Ads_Utils::build_html_attributes( $this->wrapper ) . '>'
293 . $this->label
294 . apply_filters( 'advanced-ads-output-wrapper-before-content-group', '', $this )
295 . $output_string
296 . apply_filters( 'advanced-ads-output-wrapper-after-content-group', '', $this )
297 . '</div>';
298 }
299
300 if ( ! empty( $this->ad_args['is_top_level'] ) && ! empty( $this->ad_args['placement_clearfix'] ) ) {
301 $output_string .= '<br style="clear: both; display: block; float: none;"/>';
302 }
303
304 // filter final group output
305 return apply_filters( 'advanced-ads-group-output', $output_string, $this );
306 }
307
308 /**
309 * Get ordered ids of the ads that belong to the group
310 *
311 * @return array
312 */
313 public function get_ordered_ad_ids() {
314 // load ads
315 $ads = $this->load_all_ads();
316 if ( ! is_array( $ads ) ) {
317 return [];
318 }
319
320 // get ad weights serving as an order here
321 $weights = $this->get_ad_weights( array_keys( $ads ) );
322 $ad_ids = wp_list_pluck( $ads, 'ID' );
323
324 // remove ads with 0 ad weight and unavailable ads (e.g. drafts).
325 foreach ( $weights as $ad_id => $ad_weight ) {
326 if ( $ad_weight === 0 || ! in_array( $ad_id, $ad_ids, true ) ) {
327 unset( $weights[ $ad_id ] );
328 }
329 }
330
331 // order ads based on group type
332 if ( $this->type === 'ordered' ) {
333 $ordered_ad_ids = $this->shuffle_ordered_ads( $weights );
334 } else { // default
335 $ordered_ad_ids = $this->shuffle_ads( $ads, $weights );
336 }
337
338 return apply_filters( 'advanced-ads-group-output-ad-ids', $ordered_ad_ids, $this->type, $ads, $weights, $this );
339 }
340
341 /**
342 * Return all ads from this group
343 *
344 * @since 1.0.0
345 */
346 public function get_all_ads() {
347 return $this->load_all_ads();
348 }
349
350 /**
351 * Load all public ads for this group
352 *
353 * @since 1.0.0
354 * @update 1.1.0 load only public ads
355 * @update allow to cache groups for few minutes
356 *
357 * @return bool|WP_Post[] $ads array with ad (post) objects
358 */
359 private function load_all_ads() {
360
361 if ( ! $this->id ) {
362 return [];
363 }
364
365 if ( false !== $this->ads ) {
366 return $this->ads;
367 }
368
369 // Much more complex than needed: one of the three queries is not needed and the last query gets slow quiet fast.
370 $args = [
371 'post_type' => $this->post_type,
372 'post_status' => 'publish',
373 'posts_per_page' => -1,
374 'taxonomy' => $this->taxonomy,
375 'term' => $this->slug,
376 'orderby' => 'id', // Might want to avoid sorting as not needed for most calls and fast in PHP; slight I/O blocking concern.
377 ];
378
379 $ads = new WP_Query( $args );
380
381 if ( $ads->have_posts() ) {
382 $this->ads = $this->add_post_ids( $ads->posts );
383 } else {
384 $this->ads = [];
385 }
386
387 return $this->ads;
388 }
389
390 /**
391 * Use post ids as keys for ad array
392 *
393 * @since 1.0.0
394 * @param array $ads array with post objects.
395 * @return array $ads array with post objects with post id as their key.
396 */
397 private function add_post_ids( array $ads ) {
398 return array_reduce(
399 $ads,
400 function( $ads, $ad ) {
401 $ads[ $ad->ID ] = $ad;
402
403 return $ads;
404 },
405 []
406 );
407 }
408
409 /**
410 * Shuffle ads based on ad weight.
411 *
412 * @param array $ads ad objects.
413 * @param array $weights ad weights, indexed by ad id.
414 *
415 * @return array
416 * @since 1.0.0
417 */
418 public function shuffle_ads( $ads, $weights ) {
419 // get a random ad for every ad there is
420 $shuffled_ads = [];
421 // while non-zero weights are set select random next
422 // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- prevents code duplication.
423 while ( null !== ( $random_ad_id = $this->get_random_ad_by_weight( $weights ) ) ) {
424 // remove chosen ad from weights array
425 unset( $weights[ $random_ad_id ] );
426 // put random ad into shuffled array
427 if ( ! empty( $ads[ $random_ad_id ] ) ) {
428 $shuffled_ads[] = $random_ad_id;
429 }
430 }
431
432 return $shuffled_ads;
433 }
434
435 /**
436 * Shuffle ads that have the same width.
437 *
438 * @since untagged
439 * @param array $weights Array of $ad_id => weight pairs.
440 * @return array $ordered_ad_ids Ordered ad ids.
441 */
442 public function shuffle_ordered_ads( array $weights ) {
443 // order to highest weight first
444 arsort( $weights );
445 $ordered_ad_ids = array_keys( $weights );
446
447 $weights = array_values( $weights );
448 $count = count( $weights );
449 $pos = 0;
450 for ( $i = 1; $i <= $count; $i++ ) {
451 if ( $i == $count || $weights[ $i ] !== $weights[ $i - 1] ) {
452 $slice_len = $i - $pos;
453 if ( $slice_len !== 1 ) {
454 $shuffled = array_slice( $ordered_ad_ids, $pos, $slice_len );
455 shuffle ( $shuffled );
456 // Replace the unshuffled chunk with the shuffled one.
457 array_splice( $ordered_ad_ids, $pos, $slice_len, $shuffled );
458 }
459 $pos = $i;
460 }
461 }
462 return $ordered_ad_ids;
463 }
464
465 /**
466 * Get random ad by ad weight.
467 *
468 * @since 1.0.0
469 * @param array $ad_weights Indexed by ad_id [int $ad_id => int $weight].
470 * @source applied with fix for order http://stackoverflow.com/a/11872928/904614
471 *
472 * @return null|int
473 */
474 private function get_random_ad_by_weight(array $ad_weights) {
475
476 // use maximum ad weight for ads without this
477 // ads might have a weight of zero (0); to avoid mt_rand fail assume that at least 1 is set.
478 $max = array_sum( $ad_weights );
479 if ( $max < 1 ) {
480 return null;
481 }
482
483 $rand = mt_rand( 1, $max );
484 foreach ( $ad_weights as $ad_id => $weight ) {
485 $rand -= $weight;
486 if ( $rand <= 0 ) {
487 return $ad_id;
488 }
489 }
490
491 return null;
492 }
493
494 /**
495 * Get weights of ads in this group
496 *
497 * @param array $ad_ids Ids of ads assigned to this group.
498 *
499 * @return array
500 */
501 public function get_ad_weights( $ad_ids = [] ) {
502 if ( is_array( $this->ad_weights ) ) {
503 return $this->ad_weights;
504 }
505
506 $weights = get_option( 'advads-ad-weights', [] );
507 $this->ad_weights = [];
508 if ( array_key_exists( $this->id, $weights ) ) {
509 $this->ad_weights = $weights[ $this->id ];
510 }
511 asort( $this->ad_weights );
512
513 // add ads whose weight has not yet been saved with the default value.
514 foreach ( $ad_ids as $ad_id ) {
515 if ( ! array_key_exists( $ad_id, $this->ad_weights ) ) {
516 $this->ad_weights[ $ad_id ] = self::MAX_AD_GROUP_DEFAULT_WEIGHT;
517 }
518 }
519
520 return $this->ad_weights;
521 }
522
523 /**
524 * Save ad group information that are not included in terms or ad weight
525 *
526 * @since 1.4.8
527 * @param arr $args group arguments
528 */
529 public function save($args = []) {
530
531 $defaults = [ 'type' => 'default', 'ad_count' => 1, 'options' => [] ];
532 $args = wp_parse_args($args, $defaults);
533
534 // get global ad group option
535 $groups = get_option( 'advads-ad-groups', [] );
536
537 $groups[$this->id] = $args;
538
539 update_option( 'advads-ad-groups', $groups );
540 }
541
542 /**
543 * Delete all the ad weights for a group by id
544 *
545 * @since 1.0.0
546 */
547 public static function delete_ad_weights($group_id){
548 $all_weights = get_option( 'advads-ad-weights', [] );
549 if ($all_weights && isset($all_weights[$group_id])){
550 unset($all_weights[$group_id]);
551 update_option( 'advads-ad-weights', $all_weights );
552 }
553 }
554
555 /**
556 * Create a wrapper to place around the group.
557 */
558 private function create_wrapper() {
559 $this->wrapper = [];
560
561 if ( $this->ad_args['is_top_level'] ) {
562 // Add label.
563 $placement_state = isset( $this->ad_args['ad_label'] ) ? $this->ad_args['ad_label'] : 'default';
564 $this->label = Advanced_Ads::get_instance()->get_label( $placement_state );
565
566 // Add placement class.
567 if ( ! empty( $this->ad_args['output']['class'] ) && is_array( $this->ad_args['output']['class'] ) ) {
568 $this->wrapper['class'] = $this->ad_args['output']['class'];
569 }
570
571 // ad Health Tool add class wrapper
572 if ( WordPress::user_can('advanced_ads_edit_ads') ) {
573 $frontend_prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
574 $this->wrapper['class'][] = $frontend_prefix . 'highlighted-wrappers';
575 }
576
577 if ( isset( $this->ad_args['output']['wrapper_attrs'] ) && is_array( $this->ad_args['output']['wrapper_attrs'] ) ) {
578 foreach ( $this->ad_args['output']['wrapper_attrs'] as $key => $value ) {
579 $this->wrapper[$key] = $value;
580 }
581 }
582
583 if ( ! empty( $this->ad_args['placement_position'] ) ) {
584 switch ( $this->ad_args['placement_position'] ) {
585 case 'left' :
586 $this->wrapper['style']['float'] = 'left';
587 break;
588 case 'right' :
589 $this->wrapper['style']['float'] = 'right';
590 break;
591 case 'center' :
592 // We don't know whether the 'add_wrapper_sizes' option exists and width is set.
593 $this->wrapper['style']['text-align'] = 'center';
594 break;
595 }
596 }
597 }
598
599 $this->wrapper = (array) apply_filters( 'advanced-ads-output-wrapper-options-group', $this->wrapper, $this );
600
601 if ( ( $this->wrapper !== [] || $this->label ) && ! isset( $this->wrapper['id'] ) ) {
602 $prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
603 $this->wrapper['id'] = $prefix . mt_rand();
604 }
605 }
606
607 /**
608 * Calculate the number of available weights for a group depending on
609 * number of ads and default value.
610 *
611 * @param int $num_ads Number of ads in the group.
612 * @since 1.8.22
613 *
614 * @return max weight used in group settings
615 */
616 public static function get_max_ad_weight( $num_ads = 1 ){
617
618 // use default if lower than default.
619 $num_ads = absint( $num_ads );
620
621 // use number of ads or max ad weight value, whatever is higher
622 $max_weight = $num_ads < self::MAX_AD_GROUP_DEFAULT_WEIGHT ? self::MAX_AD_GROUP_DEFAULT_WEIGHT : $num_ads;
623
624 // allow users to manipulate max ad weight
625 return apply_filters( 'advanced-ads-max-ad-weight', $max_weight, $num_ads );
626 }
627
628 /**
629 * Get group hints.
630 *
631 * @param Advanced_Ads_Group $group The group object.
632 *
633 * @return string[] Group hints (escaped strings).
634 */
635 public static function get_hints( Advanced_Ads_Group $group ) {
636 $hints = [];
637
638 if (
639 ! Advanced_Ads_Checks::cache()
640 || count( $group->get_all_ads() ) < 2
641 ) {
642 return $hints;
643 }
644
645 if ( ! class_exists( 'Advanced_Ads_Pro' ) ) {
646 $installed_plugins = get_plugins();
647
648 if ( isset( $installed_plugins['advanced-ads-pro/advanced-ads-pro.php'] ) ) {
649 $link = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=advanced-ads-pro/advanced-ads-pro.php', 'activate-plugin_advanced-ads-pro/advanced-ads-pro.php' );
650 $link_title = __( 'Activate now', 'advanced-ads' );
651 } else {
652 $link = 'https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=groups-CB';
653 $link_title = __( 'Get this add-on', 'advanced-ads' );
654 }
655
656 $hints[] = sprintf(
657 wp_kses(
658 // translators: %1$s is an URL, %2$s is a URL text
659 __( 'It seems that a caching plugin is activated. Your ads might not rotate properly. The cache busting in Advanced Ads Pro will solve that. <a href="%1$s" target="_blank">%2$s.</a>', 'advanced-ads' ),
660 [
661 'a' => [
662 'href' => [],
663 'target' => [],
664 ],
665 ]
666 ),
667 $link,
668 $link_title
669 );
670 }
671
672 /**
673 * Allows to add new hints.
674 *
675 * @param string[] $hints Existing hints (escaped strings).
676 * @param Advanced_Ads_Group $group The group object.
677 */
678 return apply_filters( 'advanced-ads-group-hints', $hints, $group );
679 }
680
681
682 }
683