WidgetsSettingsExtender.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FapiMember\Elementor\WidgetSettingsExtender; |
| 4 | |
| 5 | use Elementor\Controls_Manager; |
| 6 | |
| 7 | final class WidgetsSettingsExtender |
| 8 | { |
| 9 | private static $sections = null; |
| 10 | |
| 11 | public static function register() { |
| 12 | add_action( |
| 13 | 'elementor/element/after_section_end', |
| 14 | function ( $section, $section_id ) { |
| 15 | if ( 'section_custom_attributes_pro' !== $section_id ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | self::doExtend( $section ); |
| 20 | }, |
| 21 | 10, |
| 22 | 2 |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return void |
| 28 | */ |
| 29 | public static function doExtend( $section ) { |
| 30 | $section->start_controls_section( |
| 31 | 'fapi-member', |
| 32 | array( |
| 33 | 'label' => __( 'FAPI Member', 'fapi-member' ), |
| 34 | 'tab' => Controls_Manager::TAB_ADVANCED, |
| 35 | ) |
| 36 | ); |
| 37 | |
| 38 | $section->add_control( |
| 39 | 'hasSectionOrLevel', |
| 40 | array( |
| 41 | 'label' => __( 'Zobrazit blok pokud návštěvník', 'fapi-member' ), |
| 42 | 'type' => Controls_Manager::SELECT, |
| 43 | 'options' => array( |
| 44 | '1' => array( |
| 45 | 'title' => esc_html__( 'je člen sekce/úrovně', 'fapi-member' ), |
| 46 | ), |
| 47 | '0' => array( |
| 48 | 'title' => esc_html__( 'není členem sekce/úrovně', 'fapi-member' ), |
| 49 | ), |
| 50 | '' => array( |
| 51 | 'title' => esc_html__( 'zobrazit všem návštěvníkům (vybrané sekce a úrovně se ignorují)', 'fapi-member' ), |
| 52 | ), |
| 53 | ), |
| 54 | 'description' => esc_html__( 'Obsah se zobrazí v případě že člen je/není přiřazený v členské sekci nebo úrovni nebo všem návštěvníkům.', 'fapi-member' ), |
| 55 | 'show_label' => true, |
| 56 | 'default' => '', |
| 57 | ) |
| 58 | ); |
| 59 | |
| 60 | $levels = self::getLevels(); |
| 61 | |
| 62 | $section->add_control( |
| 63 | 'fapiSectionAndLevels', |
| 64 | array( |
| 65 | 'label' => esc_html__( 'Členské sekce a úrovně', 'fapi-member' ), |
| 66 | 'type' => Controls_Manager::SELECT2, |
| 67 | 'multiple' => true, |
| 68 | 'options' => $levels, |
| 69 | ) |
| 70 | ); |
| 71 | |
| 72 | $section->end_controls_section(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return array<mixed> |
| 77 | */ |
| 78 | private static function getLevels() { |
| 79 | global $levelRepository; |
| 80 | |
| 81 | if (self::$sections !== null) { |
| 82 | return self::$sections; |
| 83 | } |
| 84 | |
| 85 | self::$sections = []; |
| 86 | $sections = $levelRepository->getAllSections(); |
| 87 | |
| 88 | foreach ($sections as $section) { |
| 89 | self::$sections[$section->getId()] = $section->getName(); |
| 90 | |
| 91 | foreach ($section->getLevels() as $level) { |
| 92 | self::$sections[$level->getId()] = $section->getName() . ' - ' . $level->getName(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return self::$sections; |
| 97 | } |
| 98 | |
| 99 | } |
| 100 |