PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / admin / includes / wpr-templates-modal-popups.php
royal-elementor-addons / admin / includes Last commit date
wpr-conditions-manager.php 5 days ago wpr-editor-hooks.php 5 days ago wpr-render-templates.php 5 days ago wpr-templates-actions.php 5 days ago wpr-templates-category-filter.php 5 days ago wpr-templates-library.php 5 days ago wpr-templates-loop.php 5 days ago wpr-templates-modal-popups.php 5 days ago wpr-templates-shortcode.php 5 days ago
wpr-templates-modal-popups.php
249 lines
1 <?php
2 namespace WprAddons\Admin\Includes;
3
4 use WprAddons\Plugin;
5 use WprAddons\Classes\Utilities;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * WPR_Templates_Modal_Popups setup
13 *
14 * @since 1.0
15 */
16 class WPR_Templates_Modal_Popups {
17
18 /**
19 ** Instance of Elemenntor Frontend class.
20 *
21 ** @var \Elementor\Frontend()
22 */
23 private static $elementor_instance;
24
25 /**
26 ** Constructor
27 */
28 public function __construct() {
29 // Elementor Frontend
30 self::$elementor_instance = \Elementor\Plugin::instance();
31
32 add_action( 'template_include', [ $this, 'set_post_type_template' ], 9999 );
33
34 add_action( 'wp_footer', [ $this, 'render_popups' ] );
35 }
36
37 /**
38 * Set blank template for editor
39 */
40 public function set_post_type_template( $template ) {
41
42 if ( is_singular( 'wpr_templates' ) ) {
43 if ( 'wpr-popups' === Utilities::get_elementor_template_type(get_the_ID()) && self::$elementor_instance->preview->is_preview_mode() ) {
44 $template = WPR_ADDONS_PATH . 'modules/popup/editor.php';
45 }
46
47 return $template;
48 }
49
50 return $template;
51 }
52
53 /**
54 ** Popups
55 */
56 public function render_popups() {
57 $conditions = json_decode( get_option('wpr_popup_conditions'), true );
58
59 if ( ! empty( $conditions ) ) {
60 $conditions = $this->reverse_template_conditions( $conditions );
61
62 // Global
63 if ( isset( $conditions['global'] ) ) {
64 WPR_Templates_Modal_Popups::display_popups_by_location( $conditions, 'global' );
65 }
66
67 // Custom
68 if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
69 // Archive
70 \WprAddonsPro\Classes\Pro_Modules::archive_pages_popup_conditions( $conditions );
71
72 // Single
73 \WprAddonsPro\Classes\Pro_Modules::single_pages_popup_conditions( $conditions );
74 }
75
76
77 // Enqueue ScrolBar JS //TODO - check if displayed multiple times
78 wp_enqueue_script( 'wpr-popup-scroll-js', WPR_ADDONS_URL .'assets/js/lib/perfect-scrollbar/perfect-scrollbar.min.js', [ 'jquery' ], '0.4.9' );
79 }
80 }
81
82 /**
83 ** Reverse Template Conditions
84 */
85 public function reverse_template_conditions( $conditions ) {
86 $reverse = [];
87
88 foreach ( $conditions as $key => $condition ) {
89 foreach( $condition as $location ) {
90 if ( ! isset( $reverse[$location] ) ) {
91 $reverse[$location] = [ $key ];
92 } else {
93 array_push( $reverse[$location], $key );
94 }
95 }
96 }
97
98 return $reverse;
99 }
100
101 /**
102 ** Display Popups by Location
103 */
104 public static function display_popups_by_location( $conditions, $page ) {
105 foreach ( $conditions[$page] as $key => $popup ) {
106 WPR_Templates_Modal_Popups::render_popup_content( $popup );
107 }
108 }
109
110 /**
111 ** Display Elementor Content
112 */
113 public static function render_popup_content( $slug ) {
114 $template_name = '';
115
116 $template_id = Utilities::get_template_id( $slug );
117
118 if ( defined('ICL_LANGUAGE_CODE') ) {
119 $default_language_code = apply_filters('wpml_default_language', null);
120 $current_language_code = apply_filters( 'wpml_current_language', NULL );
121
122
123 IF ( ICL_LANGUAGE_CODE !== $default_language_code ) {
124 $template_id = apply_filters('wpml_object_id', $template_id, 'wpr_templates', true, $current_language_code);
125 }
126 }
127
128 $get_settings = WPR_Templates_Modal_Popups::get_template_settings( $slug );
129 $get_elementor_content = self::$elementor_instance->frontend->get_builder_content( $template_id, false );
130
131 if ( '' === $get_elementor_content ) {
132 return;
133 }
134
135 // Encode Settings
136 $get_encoded_settings = ! empty( $get_settings ) ? wp_json_encode( $get_settings ) : '[]';
137
138 // Template Settings Attribute
139 $template_settings_attr = "data-settings='". esc_attr($get_encoded_settings) ."'";
140
141 // Return if NOT available for current user
142 if ( ! WPR_Templates_Modal_Popups::check_available_user_roles( $get_settings['popup_show_for_roles'] ) ) {
143 return;
144 }
145
146 if ( ! self::$elementor_instance->preview->is_preview_mode() ) {
147 echo '<div id="wpr-popup-id-'. esc_attr($template_id) .'" class="wpr-template-popup" '. $template_settings_attr .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
148 echo '<div class="wpr-template-popup-inner">';
149
150 // Popup Overlay & Close Button
151 echo '<div class="wpr-popup-overlay"></div>';
152
153 // Template Container
154 echo '<div class="wpr-popup-container">';
155
156 // Close Button
157 if ( \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' ) ) { // GOGA: why not included
158 echo '<div class="wpr-popup-close-btn"><i class="fa fa-times"></i></div>';
159 } else {
160 echo '<div class="wpr-popup-close-btn"><i class="eicon-close"></i></div>';
161 }
162
163 // Elementor Template Content
164 echo '<div class="wpr-popup-container-inner">';
165 echo ''. $get_elementor_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
166 echo '</div>';
167
168 echo '</div>';
169
170 echo '</div>';
171 echo '</div>';
172 }
173 }
174
175 /**
176 ** Get Template Settings
177 */
178 public static function get_template_settings( $slug ) {
179 $settings = [];
180 $defaults = [];
181
182 $template_id = Utilities::get_template_id( $slug );
183 $meta_settings = get_post_meta( $template_id, '_elementor_page_settings', true );
184
185 $popup_defaults = [
186 'popup_trigger' => 'load',
187 'popup_load_delay' => 1,
188 'popup_scroll_progress' => 10,
189 'popup_inactivity_time' => 15,
190 'popup_element_scroll' => '',
191 'popup_custom_trigger' => '',
192 'popup_specific_date' => date( 'Y-m-d H:i', strtotime( '+1 month' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ),
193 'popup_stop_after_date' => false,
194 'popup_stop_after_date_select' => date( 'Y-m-d H:i', strtotime( '+1 day' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ),
195 'popup_show_again_delay' => 1,
196 'popup_disable_esc_key' => false,
197 'popup_automatic_close_switch' => false,
198 'popup_automatic_close_delay' => 10,
199 'popup_animation' => 'fade',
200 'popup_animation_duration' => 1,
201 'popup_show_for_roles' => '',
202 'popup_show_via_referral' => false,
203 'popup_referral_keyword' => '',
204 'popup_display_as' => 'modal',
205 'popup_show_on_device' => true,
206 'popup_show_on_device_mobile' => true,
207 'popup_show_on_device_tablet' => true,
208 'popup_disable_page_scroll' => true,
209 'popup_overlay_disable_close' => false,
210 'popup_close_button_display_delay' => 0,
211 ];
212
213 // Determine Template
214 if ( strpos( $slug, 'popup') ) {
215 $defaults = $popup_defaults;
216 }
217
218 foreach( $defaults as $option => $value ) {
219 if ( isset($meta_settings[$option]) ) {
220 $settings[$option] = $meta_settings[$option];
221 }
222 }
223
224 return array_merge( $defaults, $settings );
225 }
226
227 /**
228 ** Check Available User Rols
229 */
230 public static function check_available_user_roles( $selected_roles ) {
231 if ( empty( $selected_roles ) ) {
232 return true;
233 }
234
235 $current_user = wp_get_current_user();
236
237 if ( ! empty( $current_user->roles ) ) {
238 $role = $current_user->roles[0];
239 } else {
240 $role = 'guest';
241 }
242
243 if ( in_array( $role, $selected_roles ) ) {
244 return true;
245 }
246
247 return false;
248 }
249 }