| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Back To Search Widget. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
class Elementor_Back_To_Search_Widget extends \Elementor\Widget_Base { |
| 8 |
|
| 9 |
public function get_name() { |
| 10 |
return 'back-to-search'; |
| 11 |
} |
| 12 |
|
| 13 |
public function get_title() { |
| 14 |
return __( 'Back To Search', 'propertyhive' ); |
| 15 |
} |
| 16 |
|
| 17 |
public function get_icon() { |
| 18 |
return 'eicon-arrow-left'; |
| 19 |
} |
| 20 |
|
| 21 |
public function get_categories() { |
| 22 |
return [ 'property-hive' ]; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_keywords() { |
| 26 |
return [ 'property hive', 'propertyhive', 'back' ]; |
| 27 |
} |
| 28 |
|
| 29 |
protected function register_controls() { |
| 30 |
|
| 31 |
$this->start_controls_section( |
| 32 |
'style_section', |
| 33 |
[ |
| 34 |
'label' => __( 'Back To Search', 'propertyhive' ), |
| 35 |
'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
$this->add_control( |
| 40 |
'note', |
| 41 |
[ |
| 42 |
'label' => __( 'Note', 'propertyhive' ), |
| 43 |
'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 44 |
'raw' => __( 'This requires step 1 and 2 from <a href="https://docs.wp-property-hive.com/developer-guide/miscellaneous-and-snippets/add-back-to-search-results-link-to-property-details-page/" target="_blank">this documentation</a> to be added to your theme for this to work correctly. If not done then the Back To Search link will just always link back to the results page but won\'t retain any search criteria set.', 'propertyhive' ), |
| 45 |
] |
| 46 |
); |
| 47 |
|
| 48 |
$this->add_control( |
| 49 |
'icon', |
| 50 |
[ |
| 51 |
'label' => __( 'Icon', 'propertyhive' ), |
| 52 |
'type' => \Elementor\Controls_Manager::ICONS, |
| 53 |
'default' => [ |
| 54 |
'value' => 'fas fa-arrow-left', |
| 55 |
'library' => 'solid', |
| 56 |
], |
| 57 |
] |
| 58 |
); |
| 59 |
|
| 60 |
$this->add_control( |
| 61 |
'label', |
| 62 |
[ |
| 63 |
'label' => __( 'Label', 'propertyhive' ), |
| 64 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 65 |
'default' => __( 'Back To Search', 'propertyhive' ), |
| 66 |
] |
| 67 |
); |
| 68 |
|
| 69 |
$this->add_group_control( |
| 70 |
\Elementor\Group_Control_Typography::get_type(), |
| 71 |
[ |
| 72 |
'name' => 'back_to_search_typography', |
| 73 |
'label' => __( 'Typography', 'propertyhive' ), |
| 74 |
'global' => [ |
| 75 |
'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY, |
| 76 |
], |
| 77 |
'selector' => '{{WRAPPER}} .back-to-search a', |
| 78 |
] |
| 79 |
); |
| 80 |
|
| 81 |
$this->add_control( |
| 82 |
'color', |
| 83 |
[ |
| 84 |
'label' => __( 'Colour', 'propertyhive' ), |
| 85 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 86 |
'global' => [ |
| 87 |
'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY, |
| 88 |
], |
| 89 |
'selectors' => [ |
| 90 |
'{{WRAPPER}} .back-to-search a' => 'color: {{VALUE}}', |
| 91 |
], |
| 92 |
] |
| 93 |
); |
| 94 |
|
| 95 |
$this->add_control( |
| 96 |
'icon_color', |
| 97 |
[ |
| 98 |
'label' => __( 'Icon Colour', 'propertyhive' ), |
| 99 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 100 |
'global' => [ |
| 101 |
'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY, |
| 102 |
], |
| 103 |
'selectors' => [ |
| 104 |
'{{WRAPPER}} .back-to-search i' => 'color: {{VALUE}}', |
| 105 |
], |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
'text_align', |
| 111 |
[ |
| 112 |
'label' => __( 'Alignment', 'propertyhive' ), |
| 113 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 114 |
'options' => [ |
| 115 |
'left' => [ |
| 116 |
'title' => __( 'Left', 'propertyhive' ), |
| 117 |
'icon' => 'eicon-text-align-left', |
| 118 |
], |
| 119 |
'center' => [ |
| 120 |
'title' => __( 'Center', 'propertyhive' ), |
| 121 |
'icon' => 'eicon-text-align-center', |
| 122 |
], |
| 123 |
'right' => [ |
| 124 |
'title' => __( 'Right', 'propertyhive' ), |
| 125 |
'icon' => 'eicon-text-align-right', |
| 126 |
], |
| 127 |
], |
| 128 |
'default' => 'left', |
| 129 |
'toggle' => true, |
| 130 |
'selectors' => [ |
| 131 |
'{{WRAPPER}} .back-to-search' => 'text-align: {{VALUE}}', |
| 132 |
], |
| 133 |
] |
| 134 |
); |
| 135 |
|
| 136 |
$this->end_controls_section(); |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
protected function render() { |
| 141 |
|
| 142 |
global $property; |
| 143 |
|
| 144 |
$settings = $this->get_settings_for_display(); |
| 145 |
|
| 146 |
if ( !isset($property->id) ) { |
| 147 |
return; |
| 148 |
} |
| 149 |
|
| 150 |
echo '<div class="back-to-search">'; |
| 151 |
if ( isset($_SESSION['last_search']) && is_string( $_SESSION['last_search'] ) && $_SESSION['last_search'] != '' ) |
| 152 |
{ |
| 153 |
echo '<a href="' . esc_url( esc_url_raw( $_SESSION['last_search'] ) ) . '">'; |
| 154 |
} |
| 155 |
else |
| 156 |
{ |
| 157 |
echo '<a href="' . esc_url(get_permalink(ph_get_page_id( 'search_results' ))) . '">'; |
| 158 |
} |
| 159 |
if ( isset($settings['icon']) && !empty($settings['icon']) ) |
| 160 |
{ |
| 161 |
\Elementor\Icons_Manager::render_icon( $settings['icon'], [ 'aria-hidden' => 'true' ] ); |
| 162 |
echo ' '; |
| 163 |
} |
| 164 |
echo esc_html($settings['label']); |
| 165 |
echo '</a>'; |
| 166 |
echo '</div>'; |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
} |