types
3 months ago
class-placement-after-content.php
1 year ago
class-placement-before-content.php
1 year ago
class-placement-content.php
1 year ago
class-placement-factory.php
1 week ago
class-placement-footer.php
1 year ago
class-placement-header.php
1 year ago
class-placement-repository.php
1 week ago
class-placement-sidebar-widget.php
1 year ago
class-placement-standard.php
1 year ago
class-placement-types.php
3 months ago
class-placements.php
1 year ago
index.php
1 year ago
class-placement-types.php
115 lines
| 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 |