| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | if ( ! defined( 'ABSPATH' ) ) { |
| 11: | exit; |
| 12: | } |
| 13: | |
| 14: | |
| 15: | class EPL_Elementor_Property_Taxonomy extends \Elementor\Widget_Base { |
| 16: | use EPL_Elementor_Dynamic_Widget; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | public function get_name() { |
| 24: | return 'epl-property-taxonomy'; |
| 25: | } |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | public function get_title() { |
| 33: | return esc_html__( 'Taxonomy', 'easy-property-listings' ); |
| 34: | } |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public function get_icon() { |
| 42: | return 'eicon-meta-data'; |
| 43: | } |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | public function get_categories() { |
| 51: | return array( 'epl-elements' ); |
| 52: | } |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | public function get_keywords() { |
| 60: | return array( 'property', 'taxonomy', 'features', 'location', 'suburb', 'terms', 'epl' ); |
| 61: | } |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | private function get_taxonomies() { |
| 69: | $options = array(); |
| 70: | $taxonomies = get_object_taxonomies( epl_get_core_post_types(), 'objects' ); |
| 71: | foreach ( $taxonomies as $taxonomy ) { |
| 72: | if ( $taxonomy->public ) { |
| 73: | $options[ $taxonomy->name ] = $taxonomy->labels->singular_name . ' (' . $taxonomy->name . ')'; |
| 74: | } |
| 75: | } |
| 76: | return $options; |
| 77: | } |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | protected function register_controls() { |
| 85: | $this->start_controls_section( 'section_content', array( 'label' => esc_html__( 'Taxonomy', 'easy-property-listings' ) ) ); |
| 86: | $this->add_control( 'taxonomy', array( 'label' => esc_html__( 'Taxonomy', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => $this->get_taxonomies(), 'default' => 'tax_feature' ) ); |
| 87: | $this->add_control( 'layout', array( 'label' => esc_html__( 'Layout', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'inline', 'options' => array( 'inline' => esc_html__( 'Inline', 'easy-property-listings' ), 'list' => esc_html__( 'List', 'easy-property-listings' ) ) ) ); |
| 88: | $this->add_control( 'separator', array( 'label' => esc_html__( 'Separator', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => ', ', 'condition' => array( 'layout' => 'inline' ) ) ); |
| 89: | $this->add_control( 'link_terms', array( 'label' => esc_html__( 'Link Terms', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes' ) ); |
| 90: | $this->add_control( 'show_label', array( 'label' => esc_html__( 'Show Taxonomy Label', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => '' ) ); |
| 91: | $this->add_control( 'custom_label', array( 'label' => esc_html__( 'Custom Label', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::TEXT, 'condition' => array( 'show_label' => 'yes' ) ) ); |
| 92: | $this->add_control( 'empty_message', array( 'label' => esc_html__( 'Empty Value', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::TEXT ) ); |
| 93: | $this->end_controls_section(); |
| 94: | |
| 95: | $this->start_controls_section( 'section_style', array( 'label' => esc_html__( 'Terms', 'easy-property-listings' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE ) ); |
| 96: | $this->add_control( 'color', array( 'label' => esc_html__( 'Text Color', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .epl-property-taxonomy' => 'color: {{VALUE}};', '{{WRAPPER}} .epl-property-taxonomy a' => 'color: {{VALUE}};' ) ) ); |
| 97: | $this->add_control( 'link_hover_color', array( 'label' => esc_html__( 'Link Hover Color', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .epl-property-taxonomy a:hover' => 'color: {{VALUE}};' ) ) ); |
| 98: | $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array( 'name' => 'typography', 'selector' => '{{WRAPPER}} .epl-property-taxonomy' ) ); |
| 99: | $this->add_responsive_control( 'term_gap', array( 'label' => esc_html__( 'List Gap', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'range' => array( 'px' => array( 'min' => 0, 'max' => 100 ) ), 'selectors' => array( '{{WRAPPER}} .epl-property-taxonomy-list' => 'gap: {{SIZE}}{{UNIT}};' ), 'condition' => array( 'layout' => 'list' ) ) ); |
| 100: | $this->add_responsive_control( 'alignment', array( 'label' => esc_html__( 'Alignment', 'easy-property-listings' ), 'type' => \Elementor\Controls_Manager::CHOOSE, 'options' => array( 'left' => array( 'title' => esc_html__( 'Left', 'easy-property-listings' ), 'icon' => 'eicon-text-align-left' ), 'center' => array( 'title' => esc_html__( 'Center', 'easy-property-listings' ), 'icon' => 'eicon-text-align-center' ), 'right' => array( 'title' => esc_html__( 'Right', 'easy-property-listings' ), 'icon' => 'eicon-text-align-right' ) ), 'selectors' => array( '{{WRAPPER}} .epl-property-taxonomy' => 'text-align: {{VALUE}};' ) ) ); |
| 101: | $this->end_controls_section(); |
| 102: | } |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | protected function render() { |
| 110: | $property = EPL_Elementor::setup_listing_context(); |
| 111: | if ( ! $property ) { |
| 112: | if ( EPL_Elementor::is_editor() ) { |
| 113: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Property Taxonomy - No listings found.', 'easy-property-listings' ) . '</div>'; |
| 114: | } |
| 115: | EPL_Elementor::restore_listing_context(); |
| 116: | return; |
| 117: | } |
| 118: | |
| 119: | $settings = $this->get_settings_for_display(); |
| 120: | $taxonomy = sanitize_key( $settings['taxonomy'] ); |
| 121: | $object = get_taxonomy( $taxonomy ); |
| 122: | $terms = $object ? wp_get_post_terms( $property->post->ID, $taxonomy ) : array(); |
| 123: | |
| 124: | if ( is_wp_error( $terms ) || empty( $terms ) ) { |
| 125: | if ( ! empty( $settings['empty_message'] ) ) { |
| 126: | echo '<div class="epl-property-taxonomy epl-property-taxonomy-empty">' . esc_html( $settings['empty_message'] ) . '</div>'; |
| 127: | } |
| 128: | EPL_Elementor::restore_listing_context(); |
| 129: | return; |
| 130: | } |
| 131: | |
| 132: | $items = array(); |
| 133: | foreach ( $terms as $term ) { |
| 134: | $name = esc_html( $term->name ); |
| 135: | if ( 'yes' === $settings['link_terms'] ) { |
| 136: | $link = get_term_link( $term ); |
| 137: | $name = is_wp_error( $link ) ? $name : '<a href="' . esc_url( $link ) . '">' . $name . '</a>'; |
| 138: | } |
| 139: | $items[] = '<span class="epl-property-taxonomy-term epl-property-taxonomy-term-' . esc_attr( $term->slug ) . '">' . $name . '</span>'; |
| 140: | } |
| 141: | |
| 142: | $label = ''; |
| 143: | if ( 'yes' === $settings['show_label'] ) { |
| 144: | $label = $settings['custom_label'] ? $settings['custom_label'] : $object->labels->name; |
| 145: | $label = '<span class="epl-property-taxonomy-label">' . esc_html( $label ) . '</span>'; |
| 146: | } |
| 147: | |
| 148: | if ( 'list' === $settings['layout'] ) { |
| 149: | $content = '<ul class="epl-property-taxonomy-list"><li>' . implode( '</li><li>', $items ) . '</li></ul>'; |
| 150: | } else { |
| 151: | $content = '<span class="epl-property-taxonomy-inline">' . implode( esc_html( $settings['separator'] ), $items ) . '</span>'; |
| 152: | } |
| 153: | |
| 154: | echo '<div class="epl-property-taxonomy epl-property-taxonomy-' . esc_attr( $taxonomy ) . '">' . wp_kses_post( $label . $content ) . '</div>'; |
| 155: | EPL_Elementor::restore_listing_context(); |
| 156: | } |
| 157: | } |
| 158: | |