PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.0
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.0
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / libs / framework / classes / install-notice.php
elementskit-lite / libs / framework / classes Last commit date
ajax.php 3 weeks ago install-notice.php 3 weeks ago install-tracker.php 3 weeks ago onboard-status.php 3 weeks ago plugin-data-sender.php 1 year ago plugin-installer.php 3 weeks ago plugin-skin.php 1 year ago plugin-status.php 4 years ago utils.php 1 year ago
install-notice.php
220 lines
1 <?php
2
3 namespace ElementsKit_Lite\Libs\Framework\Classes;
4
5 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * Displays and processes the consolidated WPMet plugin install notice.
9 *
10 * @since 3.9.5
11 */
12 class Install_Notice {
13
14 /**
15 * ElementsKit plugin basename.
16 *
17 * @since 3.9.5
18 * @var string
19 */
20 const PLUGIN_FILE = 'elementskit-lite/elementskit-lite.php';
21
22 /**
23 * Register notice, asset, and AJAX hooks.
24 *
25 * @since 3.9.5
26 *
27 * @return void
28 */
29 public function init(): void {
30 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
31 add_action( 'admin_notices', array( $this, 'render' ) );
32 add_action( 'wp_ajax_elementskit_dismiss_auto_install_notice', array( $this, 'handle_dismiss' ) );
33 add_action( 'wp_ajax_elementskit_confirm_auto_install_notice', array( $this, 'handle_confirm' ) );
34 }
35
36 /**
37 * Determine whether the install notice should be displayed.
38 *
39 * @since 3.9.5
40 *
41 * @return bool True when the notice should be displayed.
42 */
43 private function should_render(): bool {
44 if ( ! current_user_can( 'manage_options' ) ) {
45 return false;
46 }
47
48 if ( Install_Tracker::is_notice_dismissed( self::PLUGIN_FILE ) ) {
49 return false;
50 }
51
52 if ( Utils::instance()->get_settings( 'ekit_user_consent_for_banner', 'yes' ) !== 'yes' ) {
53 return false;
54 }
55
56 // Show when ElementsKit was auto-installed or completed its own onboarding without giving email.
57 $registry = Install_Tracker::get_registry();
58 $auto_installed = isset( $registry['elementskit-lite/elementskit-lite.php'] );
59 $own_onboarded = (bool) get_option( 'elements_kit_onboard_status' );
60 if ( ! $auto_installed && ! $own_onboarded ) {
61 return false;
62 }
63
64 // If not auto-installed, suppress when email was already collected during own onboarding.
65 if ( ! $auto_installed && Install_Tracker::has_collected_email() ) {
66 return false;
67 }
68
69 // Only show on the ElementsKit dashboard and Get Help pages.
70 $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
71 return in_array( $current_page, array( 'elementskit', 'elementskit-lite_get_help' ), true );
72 }
73
74 /**
75 * Enqueue the install notice styles and scripts.
76 *
77 * @since 3.9.5
78 *
79 * @return void
80 */
81 public function enqueue_assets(): void {
82 if ( ! $this->should_render() ) {
83 return;
84 }
85
86 $asset_url = \ElementsKit_Lite::lib_url() . 'framework/assets/';
87 $version = \ElementsKit_Lite::version();
88
89 wp_enqueue_style( 'elementskit-install-notice', $asset_url . 'css/install-notice.css', array(), $version );
90 wp_enqueue_script( 'elementskit-install-notice', $asset_url . 'js/install-notice.js', array( 'jquery' ), $version, true );
91 wp_localize_script(
92 'elementskit-install-notice',
93 'elementskitInstallNotice',
94 array(
95 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
96 'nonce' => wp_create_nonce( 'elementskit_auto_install_notice_nonce' ),
97 'applying' => __( 'Applying…', 'elementskit-lite' ),
98 )
99 );
100 }
101
102 /**
103 * Render the consolidated plugin install notice.
104 *
105 * @since 3.9.5
106 *
107 * @return void
108 */
109 public function render(): void {
110 if ( ! $this->should_render() ) {
111 return;
112 }
113
114 ?>
115 <div class="notice notice-info wpmet-elementskit-auto-install-notice">
116 <div class="wpmet-elementskit-notice-content">
117 <h3>
118 <?php esc_html_e( 'Get more from your new plugins 🚀', 'elementskit-lite' ); ?>
119 </h3>
120 <p>
121 <?php esc_html_e( 'Allow us to use non-sensitive data from your site to improve our products and get personalized performance tips.', 'elementskit-lite' ); ?>
122 </p>
123 </div>
124 <div class="wpmet-elementskit-notice-actions">
125 <button class="button wpmet-elementskit-notice-btn-skip" id="wpmet-elementskit-notice-skip">
126 <?php esc_html_e( 'Skip for Now', 'elementskit-lite' ); ?>
127 </button>
128 <button class="button button-primary wpmet-elementskit-notice-btn-confirm" id="wpmet-elementskit-notice-confirm">
129 <?php esc_html_e( 'Confirm & Apply', 'elementskit-lite' ); ?>
130 </button>
131 </div>
132 </div>
133 <?php
134 }
135
136 /**
137 * Handle the notice dismissal AJAX request.
138 *
139 * @since 3.9.5
140 *
141 * @return void
142 */
143 public function handle_dismiss(): void {
144 check_ajax_referer( 'elementskit_auto_install_notice_nonce', 'nonce' );
145 if ( ! current_user_can( 'manage_options' ) ) {
146 wp_send_json_error();
147 }
148 Install_Tracker::dismiss_notice( self::PLUGIN_FILE );
149 wp_send_json_success();
150 }
151
152 /**
153 * Handle the notice confirmation AJAX request.
154 *
155 * Sends subscription data for ElementsKit and registered plugins before
156 * resolving the current install notice.
157 *
158 * @since 3.9.5
159 *
160 * @return void
161 */
162 public function handle_confirm(): void {
163 check_ajax_referer( 'elementskit_auto_install_notice_nonce', 'nonce' );
164 if ( ! current_user_can( 'manage_options' ) ) {
165 wp_send_json_error();
166 }
167
168 $registry = Install_Tracker::get_registry();
169 $email = Install_Tracker::get_collected_email();
170 $email = $email ? $email : $this->get_user_email();
171 $email = $email ? $email : sanitize_email( get_option( 'admin_email' ) );
172
173 Plugin_Data_Sender::instance()->sendEmailSubscribeData(
174 'plugin-subscribe',
175 array(
176 'email' => $email,
177 'slug' => 'elementskit',
178 )
179 );
180
181 // Also send for auto-installed plugins that do not have their own notice banner.
182 $plugin_map = Install_Tracker::get_onboard_status_map();
183 foreach ( array_keys( $registry ) as $plugin_file ) {
184 if (
185 self::PLUGIN_FILE !== $plugin_file
186 && ! empty( $plugin_map[ $plugin_file ]['crm_slug'] )
187 ) {
188 Plugin_Data_Sender::instance()->sendEmailSubscribeData(
189 'plugin-subscribe',
190 array(
191 'email' => $email,
192 'slug' => sanitize_key( $plugin_map[ $plugin_file ]['crm_slug'] ),
193 )
194 );
195 }
196 }
197
198 Install_Tracker::store_collected_email( $email );
199 Install_Tracker::dismiss_notice( self::PLUGIN_FILE );
200 wp_send_json_success();
201 }
202
203 /**
204 * Return the admin email address stored in plugin options, if available.
205 *
206 * @since 3.9.5
207 *
208 * @return string A sanitized email address, or an empty string when not set.
209 */
210 private function get_user_email(): string {
211 $options = get_option( 'elementskit_options', array() );
212
213 if ( empty( $options['settings']['newsletter_email'] ) ) {
214 return '';
215 }
216
217 return sanitize_email( $options['settings']['newsletter_email'] );
218 }
219 }
220