| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | if ( ! defined( 'ABSPATH' ) ) { |
| 12: | exit; |
| 13: | } |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | class EPL_Elementor_Agent_Name extends \Elementor\Widget_Base { |
| 23: | use EPL_Elementor_Dynamic_Widget; |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function get_name() { |
| 30: | return 'epl-agent-name'; |
| 31: | } |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | public function get_title() { |
| 38: | return esc_html__( 'Name', 'easy-property-listings' ); |
| 39: | } |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | public function get_icon() { |
| 46: | return 'eicon-heading'; |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public function get_categories() { |
| 54: | return array( 'epl-staff', 'epl-author' ); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | public function get_keywords() { |
| 62: | return array( 'agent', 'name', 'title', 'epl' ); |
| 63: | } |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | protected function register_controls() { |
| 70: | |
| 71: | $this->start_controls_section( |
| 72: | 'section_content', |
| 73: | array( |
| 74: | 'label' => esc_html__( 'Content', 'easy-property-listings' ), |
| 75: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 76: | ) |
| 77: | ); |
| 78: | |
| 79: | $this->add_control( |
| 80: | 'html_tag', |
| 81: | array( |
| 82: | 'label' => esc_html__( 'HTML Tag', 'easy-property-listings' ), |
| 83: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 84: | 'options' => array( |
| 85: | 'h1' => 'H1', |
| 86: | 'h2' => 'H2', |
| 87: | 'h3' => 'H3', |
| 88: | 'h4' => 'H4', |
| 89: | 'h5' => 'H5', |
| 90: | 'h6' => 'H6', |
| 91: | 'div' => 'div', |
| 92: | 'span' => 'span', |
| 93: | 'p' => 'p', |
| 94: | ), |
| 95: | 'default' => 'h4', |
| 96: | ) |
| 97: | ); |
| 98: | |
| 99: | $this->add_control( |
| 100: | 'link_to_author', |
| 101: | array( |
| 102: | 'label' => esc_html__( 'Link to Author Page', 'easy-property-listings' ), |
| 103: | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 104: | 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ), |
| 105: | 'label_off' => esc_html__( 'No', 'easy-property-listings' ), |
| 106: | 'return_value' => 'yes', |
| 107: | 'default' => 'yes', |
| 108: | ) |
| 109: | ); |
| 110: | |
| 111: | $this->end_controls_section(); |
| 112: | |
| 113: | |
| 114: | $this->start_controls_section( |
| 115: | 'section_style', |
| 116: | array( |
| 117: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 118: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 119: | ) |
| 120: | ); |
| 121: | |
| 122: | $this->add_control( |
| 123: | 'text_color', |
| 124: | array( |
| 125: | 'label' => esc_html__( 'Color', 'easy-property-listings' ), |
| 126: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 127: | 'selectors' => array( |
| 128: | '{{WRAPPER}} .epl-agent-name' => 'color: {{VALUE}};', |
| 129: | '{{WRAPPER}} .epl-agent-name a' => 'color: {{VALUE}};', |
| 130: | ), |
| 131: | ) |
| 132: | ); |
| 133: | |
| 134: | $this->add_group_control( |
| 135: | \Elementor\Group_Control_Typography::get_type(), |
| 136: | array( |
| 137: | 'name' => 'typography', |
| 138: | 'selector' => '{{WRAPPER}} .epl-agent-name', |
| 139: | ) |
| 140: | ); |
| 141: | |
| 142: | $this->add_responsive_control( |
| 143: | 'text_align', |
| 144: | array( |
| 145: | 'label' => esc_html__( 'Alignment', 'easy-property-listings' ), |
| 146: | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 147: | 'options' => array( |
| 148: | 'left' => array( |
| 149: | 'title' => esc_html__( 'Left', 'easy-property-listings' ), |
| 150: | 'icon' => 'eicon-text-align-left', |
| 151: | ), |
| 152: | 'center' => array( |
| 153: | 'title' => esc_html__( 'Center', 'easy-property-listings' ), |
| 154: | 'icon' => 'eicon-text-align-center', |
| 155: | ), |
| 156: | 'right' => array( |
| 157: | 'title' => esc_html__( 'Right', 'easy-property-listings' ), |
| 158: | 'icon' => 'eicon-text-align-right', |
| 159: | ), |
| 160: | ), |
| 161: | 'selectors' => array( |
| 162: | '{{WRAPPER}} .epl-agent-name' => 'text-align: {{VALUE}};', |
| 163: | ), |
| 164: | ) |
| 165: | ); |
| 166: | |
| 167: | $this->end_controls_section(); |
| 168: | } |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | |
| 174: | protected function render() { |
| 175: | $author = $this->get_current_agent(); |
| 176: | |
| 177: | if ( ! $author ) { |
| 178: | if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 179: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Name - No agent context.', 'easy-property-listings' ) . '</div>'; |
| 180: | } |
| 181: | return; |
| 182: | } |
| 183: | |
| 184: | $settings = $this->get_settings_for_display(); |
| 185: | $tag = \Elementor\Utils::validate_html_tag( $settings['html_tag'] ); |
| 186: | $link = 'yes' === $settings['link_to_author']; |
| 187: | $display_name = $author->get_author_name(); |
| 188: | $permalink = apply_filters( 'epl_author_profile_link', get_author_posts_url( $author->author_id ), $author ); |
| 189: | |
| 190: | echo '<' . esc_attr( $tag ) . ' class="epl-agent-name">'; |
| 191: | |
| 192: | if ( $link ) { |
| 193: | echo '<a href="' . esc_url( $permalink ) . '">' . esc_html( $display_name ) . '</a>'; |
| 194: | } else { |
| 195: | echo esc_html( $display_name ); |
| 196: | } |
| 197: | |
| 198: | echo '</' . esc_attr( $tag ) . '>'; |
| 199: | } |
| 200: | |
| 201: | |
| 202: | |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | private function get_current_agent() { |
| 208: | global $epl_current_agent; |
| 209: | |
| 210: | if ( ! empty( $epl_current_agent ) ) { |
| 211: | return $epl_current_agent; |
| 212: | } |
| 213: | |
| 214: | $property = EPL_Elementor::setup_listing_context(); |
| 215: | |
| 216: | if ( $property ) { |
| 217: | $author = EPL_Elementor::get_listing_agent( $property ); |
| 218: | EPL_Elementor::restore_listing_context(); |
| 219: | return $author; |
| 220: | } |
| 221: | |
| 222: | EPL_Elementor::restore_listing_context(); |
| 223: | return null; |
| 224: | } |
| 225: | } |
| 226: | |