*/ protected function element(): array { return Elements::get( static::ELEMENT ) ?? array( 'title' => static::ELEMENT, 'fields' => array(), ); } public function get_name(): string { return 'schedulereed-' . str_replace( '_', '-', static::ELEMENT ); } public function get_title(): string { return $this->element()['title']; } public function get_icon(): string { return $this->element()['icon'] ?? 'eicon-calendar'; } /** * Panel category. * * @return string[] */ public function get_categories(): array { return array( Elementor::CATEGORY ); } /** * Search words. * * @return string[] */ public function get_keywords(): array { return array( 'schedulereed', 'booking', 'appointment', 'calendar' ); } /** * Scripts the element needs, so they load in the editor preview too. * * @return string[] */ public function get_script_depends(): array { return $this->element()['scripts'] ?? array(); } /** * Styles the element needs. * * @return string[] */ public function get_style_depends(): array { return $this->element()['styles'] ?? $this->element()['scripts'] ?? array(); } protected function register_controls(): void { $fields = $this->element()['fields']; if ( array() === $fields ) { return; } $this->start_controls_section( 'schedulereed_settings', array( 'label' => __( 'Settings', 'schedulereed' ), 'tab' => Controls_Manager::TAB_CONTENT, ) ); foreach ( $fields as $key => $field ) { $this->add_control( $key, self::control( $field ) ); } $this->end_controls_section(); } /** * Elementor control arguments for a field. * * @param array $field Field. * @return array */ public static function control( array $field ): array { $control = array( 'label' => $field['label'] ); switch ( $field['type'] ) { case 'yesno': return $control + array( 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Yes', 'schedulereed' ), 'label_off' => __( 'No', 'schedulereed' ), 'return_value' => 'yes', 'default' => 'yes' === $field['default'] ? 'yes' : '', ); case 'number': return $control + array( 'type' => Controls_Manager::NUMBER, 'min' => $field['min'] ?? 0, 'max' => $field['max'] ?? null, 'step' => 1, 'default' => $field['default'], ); case 'select': return $control + array( 'type' => Controls_Manager::SELECT, 'options' => $field['options'], 'default' => (string) $field['default'], ); default: return $control + array( 'type' => Controls_Manager::TEXT, 'default' => (string) $field['default'], ); } } protected function render(): void { // The shortcode escapes its own output. echo Elements::render( static::ELEMENT, (array) $this->get_settings_for_display() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } }