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 day ago
class-placement-footer.php
1 year ago
class-placement-header.php
1 year ago
class-placement-repository.php
1 day ago
class-placement-sidebar-widget.php
1 year ago
class-placement-standard.php
1 year ago
class-placement-types.php
1 day ago
class-placements.php
1 day ago
index.php
1 year ago
class-placement-types.php
117 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 | * Built-in placement type classes. |
| 53 | * |
| 54 | * @return string[] |
| 55 | */ |
| 56 | protected function default_type_classes(): array { |
| 57 | return [ |
| 58 | After_Content::class, |
| 59 | Before_Content::class, |
| 60 | Content::class, |
| 61 | Footer::class, |
| 62 | Header::class, |
| 63 | Sidebar_Widget::class, |
| 64 | Standard::class, |
| 65 | ]; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Register custom types. |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | public function register_types(): void { |
| 74 | parent::register_types(); |
| 75 | |
| 76 | $this->sort_types(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get type dropdown options |
| 81 | * |
| 82 | * @return array |
| 83 | */ |
| 84 | public function get_dropdown_options(): array { |
| 85 | $options = []; |
| 86 | |
| 87 | foreach ( $this->get_types() as $type ) { |
| 88 | $options[ $type->get_id() ] = $type->get_title(); |
| 89 | } |
| 90 | |
| 91 | asort( $options ); |
| 92 | |
| 93 | return $options; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sort screens by order. |
| 98 | * |
| 99 | * @return void |
| 100 | */ |
| 101 | private function sort_types(): void { |
| 102 | uasort( |
| 103 | $this->types, |
| 104 | static function ( $a, $b ) { |
| 105 | $order_a = $a->get_order(); |
| 106 | $order_b = $b->get_order(); |
| 107 | |
| 108 | if ( $order_a === $order_b ) { |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | return ( $order_a < $order_b ) ? -1 : 1; |
| 113 | } |
| 114 | ); |
| 115 | } |
| 116 | } |
| 117 |