| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wdk\Elementor\Widgets; |
| 4 |
|
| 5 |
use Wdk\Elementor\Widgets\WdkElementorBase; |
| 6 |
use Elementor\Widget_Base; |
| 7 |
use Elementor\Controls_Manager; |
| 8 |
use Elementor\Utils; |
| 9 |
use Elementor\Typography; |
| 10 |
use Elementor\Editor; |
| 11 |
use Elementor\Plugin; |
| 12 |
use Elementor\Repeater; |
| 13 |
use Elementor\Core\Schemes; |
| 14 |
use Elementor\Icons_Manager; |
| 15 |
use Elementor\Group_Control_Typography; |
| 16 |
use Elementor\Group_Control_Border; |
| 17 |
use Elementor\Group_Control_Box_Shadow; |
| 18 |
|
| 19 |
if (!defined('ABSPATH')) |
| 20 |
exit; // Exit if accessed directly |
| 21 |
|
| 22 |
/** |
| 23 |
* @since 1.1.0 |
| 24 |
*/ |
| 25 |
class WdkButtonAddlisting extends WdkElementorBase { |
| 26 |
|
| 27 |
public $field_id = NULL; |
| 28 |
public $fields_list = array(); |
| 29 |
|
| 30 |
public function __construct($data = array(), $args = null) { |
| 31 |
|
| 32 |
\Elementor\Controls_Manager::add_tab( |
| 33 |
'tab_conf', |
| 34 |
esc_html__('Settings', 'wpdirectorykit') |
| 35 |
); |
| 36 |
|
| 37 |
\Elementor\Controls_Manager::add_tab( |
| 38 |
'tab_layout', |
| 39 |
esc_html__('Layout', 'wpdirectorykit') |
| 40 |
); |
| 41 |
|
| 42 |
\Elementor\Controls_Manager::add_tab( |
| 43 |
'tab_content', |
| 44 |
esc_html__('Main', 'wpdirectorykit') |
| 45 |
); |
| 46 |
|
| 47 |
|
| 48 |
if ($this->is_edit_mode_load()) { |
| 49 |
$this->enqueue_styles_scripts(); |
| 50 |
} |
| 51 |
|
| 52 |
parent::__construct($data, $args); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* Retrieve the widget name. |
| 59 |
* |
| 60 |
* @since 1.1.0 |
| 61 |
* |
| 62 |
* @access public |
| 63 |
* |
| 64 |
* @return string Widget name. |
| 65 |
*/ |
| 66 |
public function get_name() { |
| 67 |
return 'wdk-button-addlisting'; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Retrieve the widget title. |
| 72 |
* |
| 73 |
* @since 1.1.0 |
| 74 |
* |
| 75 |
* @access public |
| 76 |
* |
| 77 |
* @return string Widget title. |
| 78 |
*/ |
| 79 |
public function get_title() { |
| 80 |
return esc_html__('Wdk Button Add Listing', 'wpdirectorykit'); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Retrieve the widget icon. |
| 85 |
* |
| 86 |
* @since 1.1.0 |
| 87 |
* |
| 88 |
* @access public |
| 89 |
* |
| 90 |
* @return string Widget icon. |
| 91 |
*/ |
| 92 |
public function get_icon() { |
| 93 |
return 'eicon-dual-button'; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Register the widget controls. |
| 98 |
* |
| 99 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 100 |
* |
| 101 |
* @since 1.1.0 |
| 102 |
* |
| 103 |
* @access protected |
| 104 |
*/ |
| 105 |
protected function register_controls() { |
| 106 |
$this->generate_controls_conf(); |
| 107 |
$this->generate_controls_layout(); |
| 108 |
$this->generate_controls_styles(); |
| 109 |
$this->generate_controls_content(); |
| 110 |
|
| 111 |
$this->insert_pro_message('1'); |
| 112 |
parent::register_controls(); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Render the widget output on the frontend. |
| 117 |
* |
| 118 |
* Written in PHP and used to generate the final HTML. |
| 119 |
* |
| 120 |
* @since 1.1.0 |
| 121 |
* |
| 122 |
* @access protected |
| 123 |
*/ |
| 124 |
protected function render() { |
| 125 |
parent::render(); |
| 126 |
|
| 127 |
$this->data['id_element'] = $this->get_id(); |
| 128 |
$this->data['settings'] = $this->get_settings(); |
| 129 |
|
| 130 |
$this->data['settings']['link_url'] = get_admin_url() . "admin.php?page=wdk_listing"; |
| 131 |
if(is_user_logged_in()) { |
| 132 |
|
| 133 |
if(function_exists('wdk_dash_url') && wdk_dash_url('dash_page=listings&function=edit')){ |
| 134 |
if(current_user_can('edit_own_listings') || wmvc_user_in_role('administrator')){ |
| 135 |
$this->data['settings']['link_url'] = wdk_dash_url('dash_page=listings&function=edit'); |
| 136 |
} else { |
| 137 |
$this->data['settings']['link_text'] = esc_html__('My Profile', 'wpdirectorykit'); |
| 138 |
$this->data['settings']['link_url'] = wdk_dash_url('dash_page=profile'); |
| 139 |
} |
| 140 |
} else { |
| 141 |
$this->data['settings']['link_url'] = get_admin_url() . "admin.php?page=wdk_listing"; |
| 142 |
} |
| 143 |
|
| 144 |
} else { |
| 145 |
$redirect = get_admin_url() . "admin.php?page=wdk_listing"; |
| 146 |
if(function_exists('wdk_dash_url') && wdk_get_option('wdk_membership_login_page')){ |
| 147 |
$redirect = wdk_dash_url('dash_page=listings&function=edit'); |
| 148 |
} |
| 149 |
|
| 150 |
$this->data['settings']['link_url'] = wp_login_url($redirect); |
| 151 |
if(wdk_get_option('wdk_membership_login_page')){ |
| 152 |
$this->data['settings']['link_url'] = wdk_url_suffix(get_permalink(wdk_get_option('wdk_membership_login_page')), 'redirect_to='.urlencode($redirect)); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
if(!empty($this->data['settings']['custom_link']['url'])) { |
| 158 |
$this->add_link_attributes( 'custom_link', $this->data['settings']['custom_link'] ); |
| 159 |
} |
| 160 |
|
| 161 |
$this->data['is_edit_mode']= false; |
| 162 |
if(Plugin::$instance->editor->is_edit_mode()){ |
| 163 |
$this->data['is_edit_mode']= true; |
| 164 |
} else { |
| 165 |
} |
| 166 |
|
| 167 |
echo $this->view('wdk-button-addlisting', $this->data); |
| 168 |
} |
| 169 |
|
| 170 |
private function generate_controls_conf() { |
| 171 |
$this->start_controls_section( |
| 172 |
'tab_conf_main_section', |
| 173 |
[ |
| 174 |
'label' => esc_html__('Main', 'wpdirectorykit'), |
| 175 |
'tab' => '1', |
| 176 |
] |
| 177 |
); |
| 178 |
|
| 179 |
$this->add_control( |
| 180 |
'link_text', |
| 181 |
[ |
| 182 |
'label' => __('Text Button', 'wpdirectorykit'), |
| 183 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 184 |
'default' => __('Add Listing', 'wpdirectorykit'), |
| 185 |
'separator' => 'before', |
| 186 |
] |
| 187 |
); |
| 188 |
|
| 189 |
$this->add_control( |
| 190 |
'link_id', |
| 191 |
[ |
| 192 |
'label' => __('Secial attr id for link', 'wpdirectorykit'), |
| 193 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 194 |
'default' => '', |
| 195 |
] |
| 196 |
); |
| 197 |
|
| 198 |
$this->add_control( |
| 199 |
'link_icon', |
| 200 |
[ |
| 201 |
'label' => esc_html__('Icon', 'wpdirectorykit'), |
| 202 |
'type' => Controls_Manager::ICONS, |
| 203 |
'label_block' => true, |
| 204 |
'default' => [ |
| 205 |
'value' => 'fa fa-plus', |
| 206 |
'library' => 'solid', |
| 207 |
], |
| 208 |
] |
| 209 |
); |
| 210 |
|
| 211 |
$this->add_control( |
| 212 |
'link_icon_position', |
| 213 |
[ |
| 214 |
'label' => esc_html__('icon Position', 'wpdirectorykit'), |
| 215 |
'type' => Controls_Manager::SELECT, |
| 216 |
'options' => [ |
| 217 |
'left' => esc_html__('Left', 'wpdirectorykit'), |
| 218 |
'right' => esc_html__('Right', 'wpdirectorykit'), |
| 219 |
], |
| 220 |
'default' => 'left', |
| 221 |
] |
| 222 |
); |
| 223 |
|
| 224 |
$this->add_control( |
| 225 |
'custom_link', |
| 226 |
[ |
| 227 |
'label' => esc_html__( 'Link', 'wpdirectorykit' ), |
| 228 |
'desciption' => esc_html__( 'use this url instead default', 'wpdirectorykit' ), |
| 229 |
'type' => \Elementor\Controls_Manager::URL, |
| 230 |
'placeholder' => esc_html__( 'https://your-link.com', 'wpdirectorykit' ), |
| 231 |
'options' => [ 'url', 'is_external', 'nofollow' ], |
| 232 |
'default' => [ |
| 233 |
'url' => '', |
| 234 |
'is_external' => true, |
| 235 |
'nofollow' => true, |
| 236 |
// 'custom_attributes' => '', |
| 237 |
], |
| 238 |
'label_block' => true, |
| 239 |
] |
| 240 |
); |
| 241 |
|
| 242 |
$this->end_controls_section(); |
| 243 |
} |
| 244 |
|
| 245 |
private function generate_controls_layout() { |
| 246 |
|
| 247 |
} |
| 248 |
|
| 249 |
private function generate_controls_styles() { |
| 250 |
$items = [ |
| 251 |
[ |
| 252 |
'key'=>'btn', |
| 253 |
'label'=> esc_html__('Button', 'wpdirectorykit'), |
| 254 |
'options'=>'full', |
| 255 |
] |
| 256 |
]; |
| 257 |
|
| 258 |
foreach ($items as $item) { |
| 259 |
$this->start_controls_section( |
| 260 |
$item['key'].'_section', |
| 261 |
[ |
| 262 |
'label' => $item['label'], |
| 263 |
'tab' => 'tab_layout' |
| 264 |
] |
| 265 |
); |
| 266 |
|
| 267 |
$selectors = array( |
| 268 |
'normal' => '{{WRAPPER}} .wdk-element .wdk-element-button', |
| 269 |
'hover'=>'{{WRAPPER}} .wdk-element .wdk-element-button%1$s' |
| 270 |
); |
| 271 |
$this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']); |
| 272 |
|
| 273 |
$this->end_controls_section(); |
| 274 |
/* END special for some elements */ |
| 275 |
} |
| 276 |
|
| 277 |
$items = [ |
| 278 |
[ |
| 279 |
'key'=>'icon', |
| 280 |
'label'=> esc_html__('Icon', 'wpdirectorykit'), |
| 281 |
'options'=>['margin','font-size','color','background','border','border_radius','padding'], |
| 282 |
] |
| 283 |
]; |
| 284 |
|
| 285 |
foreach ($items as $item) { |
| 286 |
$this->start_controls_section( |
| 287 |
$item['key'].'_section', |
| 288 |
[ |
| 289 |
'label' => $item['label'], |
| 290 |
'tab' => 'tab_layout' |
| 291 |
] |
| 292 |
); |
| 293 |
|
| 294 |
$selectors = array( |
| 295 |
'normal' => '{{WRAPPER}} .wdk-element .wdk-element-button i,{{WRAPPER}} .wdk-element .wdk-element-button svg', |
| 296 |
'hover'=>'{{WRAPPER}} .wdk-element .wdk-element-button%1$s i,{{WRAPPER}} .wdk-element .wdk-element-button%1$s svg' |
| 297 |
); |
| 298 |
$this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']); |
| 299 |
|
| 300 |
$this->end_controls_section(); |
| 301 |
/* END special for some elements */ |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
private function generate_controls_content() { |
| 307 |
|
| 308 |
} |
| 309 |
|
| 310 |
public function enqueue_styles_scripts() { |
| 311 |
wp_enqueue_style('wdk-element-button'); |
| 312 |
} |
| 313 |
} |
| 314 |
|