| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Property Additional Field Widget. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
class Elementor_Property_Additional_Field_Widget extends \Elementor\Widget_Base { |
| 8 |
|
| 9 |
public function get_name() { |
| 10 |
return 'property-additional-field'; |
| 11 |
} |
| 12 |
|
| 13 |
public function get_title() { |
| 14 |
return __( 'Additional Field', 'propertyhive' ); |
| 15 |
} |
| 16 |
|
| 17 |
public function get_icon() { |
| 18 |
return 'eicon-meta-data'; |
| 19 |
} |
| 20 |
|
| 21 |
public function get_categories() { |
| 22 |
return [ 'property-hive' ]; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_keywords() { |
| 26 |
return [ 'property hive', 'propertyhive', 'property', 'additional', 'custom' ]; |
| 27 |
} |
| 28 |
|
| 29 |
protected function _register_controls() { |
| 30 |
|
| 31 |
$this->start_controls_section( |
| 32 |
'content_section', |
| 33 |
[ |
| 34 |
'label' => __( 'Additional Field', 'propertyhive' ), |
| 35 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
$current_settings = get_option( 'propertyhive_template_assistant', array() ); |
| 40 |
|
| 41 |
$custom_fields = ( (isset($current_settings['custom_fields'])) ? $current_settings['custom_fields'] : array() ); |
| 42 |
|
| 43 |
$options = array(); |
| 44 |
foreach ( $custom_fields as $custom_field ) |
| 45 |
{ |
| 46 |
if ( substr($custom_field['meta_box'], 0, 9) == 'property_' ) |
| 47 |
{ |
| 48 |
$options[$custom_field['field_name']] = __( $custom_field['field_label'], 'propertyhive' ); |
| 49 |
} |
| 50 |
} |
| 51 |
foreach ( $custom_fields as $custom_field ) |
| 52 |
{ |
| 53 |
if ( substr($custom_field['meta_box'], 0, 7) == 'office_' ) |
| 54 |
{ |
| 55 |
$options['office-' . $custom_field['field_name']] = __( $custom_field['field_label'], 'propertyhive' ) . ' (' . __( 'Office custom field', 'propertyhive' ) . ')'; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
$this->add_control( |
| 60 |
'field', |
| 61 |
[ |
| 62 |
'label' => __( 'Field', 'propertyhive' ), |
| 63 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 64 |
'options' => $options, |
| 65 |
] |
| 66 |
); |
| 67 |
|
| 68 |
$this->add_control( |
| 69 |
'icon', |
| 70 |
[ |
| 71 |
'label' => __( 'Icon', 'propertyhive' ), |
| 72 |
'type' => \Elementor\Controls_Manager::ICONS, |
| 73 |
] |
| 74 |
); |
| 75 |
|
| 76 |
$this->add_control( |
| 77 |
'before', |
| 78 |
[ |
| 79 |
'label' => __( 'Before', 'propertyhive' ), |
| 80 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 81 |
] |
| 82 |
); |
| 83 |
|
| 84 |
$this->add_control( |
| 85 |
'after', |
| 86 |
[ |
| 87 |
'label' => __( 'After', 'propertyhive' ), |
| 88 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 89 |
] |
| 90 |
); |
| 91 |
|
| 92 |
$this->end_controls_section(); |
| 93 |
|
| 94 |
$this->start_controls_section( |
| 95 |
'style_section', |
| 96 |
[ |
| 97 |
'label' => __( 'Additional Field', 'propertyhive' ), |
| 98 |
'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 99 |
] |
| 100 |
); |
| 101 |
|
| 102 |
$this->add_group_control( |
| 103 |
\Elementor\Group_Control_Typography::get_type(), |
| 104 |
[ |
| 105 |
'name' => 'typography', |
| 106 |
'label' => __( 'Typography', 'propertyhive' ), |
| 107 |
'global' => [ |
| 108 |
'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY, |
| 109 |
], |
| 110 |
'selector' => '{{WRAPPER}}', |
| 111 |
] |
| 112 |
); |
| 113 |
|
| 114 |
$this->add_control( |
| 115 |
'color', |
| 116 |
[ |
| 117 |
'label' => __( 'Colour', 'propertyhive' ), |
| 118 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 119 |
'global' => [ |
| 120 |
'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY, |
| 121 |
], |
| 122 |
'selectors' => [ |
| 123 |
'{{WRAPPER}}' => 'color: {{VALUE}}', |
| 124 |
], |
| 125 |
] |
| 126 |
); |
| 127 |
|
| 128 |
$this->end_controls_section(); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
protected function render() { |
| 133 |
|
| 134 |
global $property; |
| 135 |
|
| 136 |
$settings = $this->get_settings_for_display(); |
| 137 |
|
| 138 |
if ( !isset($property->id) ) |
| 139 |
{ |
| 140 |
return; |
| 141 |
} |
| 142 |
|
| 143 |
if ( !isset($settings['field']) || empty($settings['field']) ) |
| 144 |
{ |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
$field_name = ''; |
| 149 |
$field_value = ''; |
| 150 |
if ( substr($settings['field'], 0, 7) == 'office-' ) |
| 151 |
{ |
| 152 |
$field_name = str_replace('office-', '', $settings['field']); |
| 153 |
$office_id = (int)$property->_office_id; |
| 154 |
if ( !empty($office_id) ) |
| 155 |
{ |
| 156 |
$field_value = get_post_meta( $office_id, $field_name, true ); |
| 157 |
} |
| 158 |
$field_meta_box = 'office'; |
| 159 |
} |
| 160 |
else |
| 161 |
{ |
| 162 |
// Property field |
| 163 |
$field_name = $settings['field']; |
| 164 |
if ( $property->{$settings['field']} != '' && !empty($property->{$settings['field']}) ) |
| 165 |
{ |
| 166 |
$field_value = $property->{$settings['field']}; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
if ( !empty($field_value) ) |
| 171 |
{ |
| 172 |
$current_settings = get_option( 'propertyhive_template_assistant', array() ); |
| 173 |
|
| 174 |
$custom_fields = ( (isset($current_settings['custom_fields'])) ? $current_settings['custom_fields'] : array() ); |
| 175 |
|
| 176 |
foreach ( $custom_fields as $custom_field ) |
| 177 |
{ |
| 178 |
if ( $custom_field['field_name'] == $field_name ) |
| 179 |
{ |
| 180 |
if ( isset($custom_field['field_type']) ) |
| 181 |
{ |
| 182 |
switch ( $custom_field['field_type'] ) |
| 183 |
{ |
| 184 |
case "image": |
| 185 |
{ |
| 186 |
$image = wp_get_attachment_image_src( $field_value, 'full' ); |
| 187 |
if ($image !== FALSE) |
| 188 |
{ |
| 189 |
$field_value = '<img src="' . $image[0] . '" alt="">'; |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
break; |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
if ( !empty($field_value) ) |
| 200 |
{ |
| 201 |
echo '<div class="elementor-widget-additional-field elementor-widget-additional-field-' . $settings['field'] . '">'; |
| 202 |
if ( isset($settings['icon']) && !empty($settings['icon']) ) |
| 203 |
{ |
| 204 |
\Elementor\Icons_Manager::render_icon( $settings['icon'], [ 'aria-hidden' => 'true' ] ); |
| 205 |
echo ' '; |
| 206 |
} |
| 207 |
if ( isset($settings['before']) && !empty($settings['before']) ) |
| 208 |
{ |
| 209 |
echo $settings['before'] . ' '; |
| 210 |
} |
| 211 |
echo $field_value; |
| 212 |
if ( isset($settings['after']) && !empty($settings['after']) ) |
| 213 |
{ |
| 214 |
echo ' ' . $settings['after']; |
| 215 |
} |
| 216 |
echo '</div>'; |
| 217 |
} |
| 218 |
|
| 219 |
} |
| 220 |
|
| 221 |
} |