PluginProbe
Advanced Ads – Ad Manager & AdSense / 2.0.21
Advanced Ads – Ad Manager & AdSense v2.0.21
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 All 348 releases
advanced-ads / includes / placements / class-placement-types.php
class-placement-types.php
115 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Placements types manager..
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.47.0
8 */
9
10 namespace AdvancedAds\Placements;
11
12 use AdvancedAds\Abstracts\Types;
13 use AdvancedAds\Placements\Types\Footer;
14 use AdvancedAds\Placements\Types\Header;
15 use AdvancedAds\Placements\Types\Content;
16 use AdvancedAds\Placements\Types\Unknown;
17 use AdvancedAds\Interfaces\Placement_Type;
18 use AdvancedAds\Placements\Types\Standard;
19 use AdvancedAds\Placements\Types\After_Content;
20 use AdvancedAds\Placements\Types\Before_Content;
21 use AdvancedAds\Placements\Types\Sidebar_Widget;
22
23 defined( 'ABSPATH' ) || exit;
24
25 /**
26 * Placements Types.
27 */
28 class Placement_Types extends Types {
29
30 /**
31 * Hook to filter types.
32 *
33 * @var string
34 */
35 protected $hook = 'advanced-ads-placement-types';
36
37 /**
38 * Class for unknown type.
39 *
40 * @var string
41 */
42 protected $type_unknown = Unknown::class;
43
44 /**
45 * Type interface to check.
46 *
47 * @var string
48 */
49 protected $type_interface = Placement_Type::class;
50
51 /**
52 * Register custom types.
53 *
54 * @return void
55 */
56 public function register_types(): void {
57 parent::register_types();
58
59 $this->sort_types();
60 }
61
62 /**
63 * Register default types.
64 *
65 * @return void
66 */
67 protected function register_default_types(): void {
68 $this->register_type( After_Content::class );
69 $this->register_type( Before_Content::class );
70 $this->register_type( Content::class );
71 $this->register_type( Footer::class );
72 $this->register_type( Header::class );
73 $this->register_type( Sidebar_Widget::class );
74 $this->register_type( Standard::class );
75 }
76
77 /**
78 * Get type dropdown options
79 *
80 * @return array
81 */
82 public function get_dropdown_options(): array {
83 $options = [];
84
85 foreach ( $this->get_types() as $type ) {
86 $options[ $type->get_id() ] = $type->get_title();
87 }
88
89 asort( $options );
90
91 return $options;
92 }
93
94 /**
95 * Sort screens by order.
96 *
97 * @return void
98 */
99 private function sort_types(): void {
100 uasort(
101 $this->types,
102 static function ( $a, $b ) {
103 $order_a = $a->get_order();
104 $order_b = $b->get_order();
105
106 if ( $order_a === $order_b ) {
107 return 0;
108 }
109
110 return ( $order_a < $order_b ) ? -1 : 1;
111 }
112 );
113 }
114 }
115