| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
require_once "class-pb-widget-base.php"; |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor widget for our wppb-list-users shortcode |
| 10 |
*/ |
| 11 |
class PB_Elementor_User_Listing_Widget extends PB_Elementor_Widget { |
| 12 |
|
| 13 |
public function __construct($data = [], $args = null) { |
| 14 |
parent::__construct($data, $args); |
| 15 |
|
| 16 |
if( defined( 'WPPB_PAID_PLUGIN_URL' ) ){ |
| 17 |
wp_register_script('wppb-userlisting-js', WPPB_PAID_PLUGIN_URL . 'add-ons/user-listing/userlisting.js', array('jquery', 'jquery-touch-punch'), PROFILE_BUILDER_VERSION, true); |
| 18 |
wp_localize_script( 'wppb-userlisting-js', 'wppb_userlisting_obj', array( 'pageSlug' => wppb_get_users_pagination_slug() ) ); |
| 19 |
wp_register_style('wppb-ul-slider-css', WPPB_PAID_PLUGIN_URL . 'add-ons/user-listing/jquery-ui-slider.min.css', array(), PROFILE_BUILDER_VERSION ); |
| 20 |
//wp_register_script('jquery-ui-slider'); |
| 21 |
} |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
public function get_script_depends() { |
| 26 |
if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists(WPPB_PAID_PLUGIN_DIR . '/add-ons/user-listing/userlisting.php') ) { |
| 27 |
return [ |
| 28 |
'wppb-userlisting-js', |
| 29 |
'jquery-ui-slider', |
| 30 |
]; |
| 31 |
} |
| 32 |
return []; |
| 33 |
} |
| 34 |
|
| 35 |
public function get_style_depends() { |
| 36 |
$styles = []; |
| 37 |
if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists(WPPB_PAID_PLUGIN_DIR . '/add-ons/user-listing/userlisting.php') ) { |
| 38 |
$styles = [ |
| 39 |
'wppb-ul-slider-css', |
| 40 |
]; |
| 41 |
} |
| 42 |
return $styles; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get widget name. |
| 47 |
* |
| 48 |
*/ |
| 49 |
public function get_name() { |
| 50 |
return 'wppb-list-users'; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Get widget title. |
| 55 |
* |
| 56 |
*/ |
| 57 |
public function get_title() { |
| 58 |
return __( 'User Listing', 'profile-builder' ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Get widget icon. |
| 63 |
* to-do |
| 64 |
*/ |
| 65 |
public function get_icon() { |
| 66 |
return 'eicon-post-list'; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Register widget controls. |
| 71 |
* |
| 72 |
*/ |
| 73 |
protected function register_controls() { |
| 74 |
|
| 75 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 76 |
$meta_names = array( |
| 77 |
'' => '' |
| 78 |
); |
| 79 |
foreach( $wppb_manage_fields as $value ){ |
| 80 |
if( $value['meta-name'] ) { |
| 81 |
$meta_names[$value['meta-name']] = $value['meta-name']; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
$this->start_controls_section( |
| 86 |
'pb_user_listing_settings', |
| 87 |
array( |
| 88 |
'label' => __( 'Listing Settings', 'profile-builder' ), |
| 89 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 90 |
) |
| 91 |
); |
| 92 |
|
| 93 |
$ul_names = array(); |
| 94 |
$userlisting_posts = get_posts( array( 'posts_per_page' => -1, 'post_status' =>'publish', 'post_type' => 'wppb-ul-cpt', 'orderby' => 'post_date', 'order' => 'ASC' ) ); |
| 95 |
if( !empty( $userlisting_posts ) ){ |
| 96 |
foreach ( $userlisting_posts as $post ){ |
| 97 |
$ul_names[ $post->post_name ] = $post->post_title; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
reset($ul_names); |
| 102 |
$default_key = is_null( key($ul_names) ) ? '' : key($ul_names); |
| 103 |
|
| 104 |
$this->add_control( |
| 105 |
'pb_name', |
| 106 |
array( |
| 107 |
'label' => __( 'User Listing', 'profile-builder' ), |
| 108 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 109 |
'options' => $ul_names, |
| 110 |
'default' => $default_key, |
| 111 |
) |
| 112 |
); |
| 113 |
|
| 114 |
$this->add_control( |
| 115 |
'pb_single', |
| 116 |
array( |
| 117 |
'label' => __('Single', 'profile-builder'), |
| 118 |
'type' => \Elementor\Controls_Manager::SWITCHER, |
| 119 |
'label_on' => __('Yes', 'profile-builder'), |
| 120 |
'label_off' => __('No', 'profile-builder'), |
| 121 |
'return_value' => 'yes', |
| 122 |
'default' => '', |
| 123 |
) |
| 124 |
); |
| 125 |
|
| 126 |
$this->add_control( |
| 127 |
'pb_meta_key', |
| 128 |
array( |
| 129 |
'label' => __( 'Meta Key', 'profile-builder' ), |
| 130 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 131 |
'options' => $meta_names, |
| 132 |
'default' => '', |
| 133 |
'condition' => [ |
| 134 |
'pb_single' => '', |
| 135 |
], |
| 136 |
) |
| 137 |
); |
| 138 |
|
| 139 |
$this->add_control( |
| 140 |
'pb_meta_value', |
| 141 |
array( |
| 142 |
'label' => __( 'Meta Value', 'profile-builder' ), |
| 143 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 144 |
'placeholder' => __( 'Enter Meta Value', 'profile-builder' ), |
| 145 |
'default' => '', |
| 146 |
'condition' => [ |
| 147 |
'pb_single' => '', |
| 148 |
'pb_meta_key!' => '', |
| 149 |
], |
| 150 |
) |
| 151 |
); |
| 152 |
|
| 153 |
$this->add_control( |
| 154 |
'pb_include', |
| 155 |
array( |
| 156 |
'label' => __( 'Include', 'profile-builder' ), |
| 157 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 158 |
'placeholder' => __( 'Enter User IDs', 'profile-builder' ), |
| 159 |
'default' => '', |
| 160 |
'condition' => [ |
| 161 |
'pb_single' => '', |
| 162 |
], |
| 163 |
) |
| 164 |
); |
| 165 |
|
| 166 |
$this->add_control( |
| 167 |
'pb_exclude', |
| 168 |
array( |
| 169 |
'label' => __( 'Exclude', 'profile-builder' ), |
| 170 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 171 |
'placeholder' => __( 'Enter User IDs', 'profile-builder' ), |
| 172 |
'default' => '', |
| 173 |
'condition' => [ |
| 174 |
'pb_single' => '', |
| 175 |
], |
| 176 |
) |
| 177 |
); |
| 178 |
|
| 179 |
$this->add_control( |
| 180 |
'pb_id', |
| 181 |
array( |
| 182 |
'label' => __( 'ID', 'profile-builder' ), |
| 183 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 184 |
'placeholder' => __( 'Enter User ID', 'profile-builder' ), |
| 185 |
'default' => '', |
| 186 |
'condition' => [ |
| 187 |
'pb_single' => 'yes', |
| 188 |
], |
| 189 |
) |
| 190 |
); |
| 191 |
|
| 192 |
$this->end_controls_section(); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Render widget output in the front-end. |
| 197 |
* |
| 198 |
*/ |
| 199 |
protected function render() { |
| 200 |
$output = $this->render_widget( 'ul' ); |
| 201 |
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 202 |
} |
| 203 |
} |
| 204 |
|