PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.2.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.2.9
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / admin / add-ons.php

add-ons.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.2.9, at admin/add-ons.php

426 lines 21.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Function that creates the "Add-Ons" submenu page
4 *
5 * @since v.2.1.0
6 *
7 * @return void
8 */
9 function wppb_register_add_ons_submenu_page() {
10 add_submenu_page( 'profile-builder', __( 'Add-Ons', 'profile-builder' ), __( 'Add-Ons', 'profile-builder' ), 'manage_options', 'profile-builder-add-ons', 'wppb_add_ons_content' );
11 }
12 add_action( 'admin_menu', 'wppb_register_add_ons_submenu_page', 19 );
13
14
15 /**
16 * Function that adds content to the "Add-Ons" submenu page
17 *
18 * @since v.2.1.0
19 *
20 * @return string
21 */
22 function wppb_add_ons_content() {
23
24 $version = 'Free';
25 $version = ( ( PROFILE_BUILDER == 'Profile Builder Pro' ) ? 'Pro' : $version );
26 $version = ( ( PROFILE_BUILDER == 'Profile Builder Hobbyist' ) ? 'Hobbyist' : $version );
27
28 ?>
29
30 <div class="wrap wppb-add-on-wrap">
31
32 <h2><?php _e( 'Add-Ons', 'profile-builder' ); ?></h2>
33
34 <span id="wppb-add-on-activate-button-text" class="wppb-add-on-user-messages"><?php echo __( 'Activate', 'profile-builder' ); ?></span>
35
36 <span id="wppb-add-on-downloading-message-text" class="wppb-add-on-user-messages"><?php echo __( 'Downloading and installing...', 'profile-builder' ); ?></span>
37 <span id="wppb-add-on-download-finished-message-text" class="wppb-add-on-user-messages"><?php echo __( 'Installation complete', 'profile-builder' ); ?></span>
38
39 <span id="wppb-add-on-activated-button-text" class="wppb-add-on-user-messages"><?php echo __( 'Add-On is Active', 'profile-builder' ); ?></span>
40 <span id="wppb-add-on-activated-message-text" class="wppb-add-on-user-messages"><?php echo __( 'Add-On has been activated', 'profile-builder' ) ?></span>
41 <span id="wppb-add-on-activated-error-button-text" class="wppb-add-on-user-messages"><?php echo __( 'Retry Install', 'profile-builder' ) ?></span>
42
43 <span id="wppb-add-on-is-active-message-text" class="wppb-add-on-user-messages"><?php echo __( 'Add-On is <strong>active</strong>', 'profile-builder' ); ?></span>
44 <span id="wppb-add-on-is-not-active-message-text" class="wppb-add-on-user-messages"><?php echo __( 'Add-On is <strong>inactive</strong>', 'profile-builder' ); ?></span>
45
46 <span id="wppb-add-on-deactivate-button-text" class="wppb-add-on-user-messages"><?php echo __( 'Deactivate', 'profile-builder' ) ?></span>
47 <span id="wppb-add-on-deactivated-message-text" class="wppb-add-on-user-messages"><?php echo __( 'Add-On has been deactivated.', 'profile-builder' ) ?></span>
48
49 <div id="the-list">
50
51 <?php
52
53 $wppb_add_ons = wppb_add_ons_get_remote_content();
54 $wppb_get_all_plugins = get_plugins();
55 $wppb_get_active_plugins = get_option('active_plugins');
56
57 if( $wppb_add_ons === false ) {
58
59 echo __('Something went wrong, we could not connect to the server. Please try again later.', 'profile-builder');
60
61 } else {
62
63 foreach( $wppb_add_ons as $key => $wppb_add_on ) {
64
65 $wppb_add_on_exists = 0;
66 $wppb_add_on_is_active = 0;
67 $wppb_add_on_is_network_active = 0;
68
69 // Check to see if add-on is in the plugins folder
70 foreach ($wppb_get_all_plugins as $wppb_plugin_key => $wppb_plugin) {
71 if (strpos(strtolower($wppb_plugin['Name']), strtolower($wppb_add_on['name'])) !== false && strpos(strtolower($wppb_plugin['AuthorName']), strtolower('Cozmoslabs')) !== false) {
72 $wppb_add_on_exists = 1;
73
74 if (in_array($wppb_plugin_key, $wppb_get_active_plugins)) {
75 $wppb_add_on_is_active = 1;
76 }
77
78 // Consider the add-on active if it's network active
79 if (is_plugin_active_for_network($wppb_plugin_key)) {
80 $wppb_add_on_is_network_active = 1;
81 $wppb_add_on_is_active = 1;
82 }
83
84 $wppb_add_on['plugin_file'] = $wppb_plugin_key;
85 }
86 }
87
88 echo '<div class="plugin-card wppb-add-on">';
89 echo '<div class="plugin-card-top">';
90
91 echo '<a target="_blank" href="' . $wppb_add_on['url'] . '?utm_source=wpbackend&utm_medium=clientsite&utm_content=add-on-page&utm_campaign=PB' . $version . '">';
92 echo '<img src="' . $wppb_add_on['thumbnail_url'] . '" />';
93 echo '</a>';
94
95 echo '<h3 class="wppb-add-on-title">';
96 echo '<a target="_blank" href="' . $wppb_add_on['url'] . '?utm_source=wpbackend&utm_medium=clientsite&utm_content=add-on-page&utm_campaign=PB' . $version . '">';
97 echo $wppb_add_on['name'];
98 echo '</a>';
99 echo '</h3>';
100
101 echo '<h3 class="wppb-add-on-price">' . $wppb_add_on['price'] . '</h3>';
102 echo '<p class="wppb-add-on-description">' . $wppb_add_on['description'] . '</p>';
103
104 echo '</div>';
105
106 $wppb_version_validation = version_compare(PROFILE_BUILDER_VERSION, $wppb_add_on['product_version']);
107
108 ($wppb_version_validation != -1) ? $wppb_version_validation_class = 'wppb-add-on-compatible' : $wppb_version_validation_class = 'wppb-add-on-not-compatible';
109
110 echo '<div class="plugin-card-bottom ' . $wppb_version_validation_class . '">';
111
112 // PB minimum version number is all good
113 if ($wppb_version_validation != -1) {
114
115 // PB version type does match
116 if (in_array(strtolower($version), $wppb_add_on['product_version_type'])) {
117
118 $ajax_nonce = wp_create_nonce("wppb-activate-addon");
119
120 if ($wppb_add_on_exists) {
121
122 // Display activate/deactivate buttons
123 if (!$wppb_add_on_is_active) {
124 echo '<a class="wppb-add-on-activate right button button-secondary" href="' . $wppb_add_on['plugin_file'] . '" data-nonce="' . $ajax_nonce . '">' . __('Activate', 'profile-builder') . '</a>';
125
126 // If add-on is network activated don't allow deactivation
127 } elseif (!$wppb_add_on_is_network_active) {
128 echo '<a class="wppb-add-on-deactivate right button button-secondary" href="' . $wppb_add_on['plugin_file'] . '" data-nonce="' . $ajax_nonce . '">' . __('Deactivate', 'profile-builder') . '</a>';
129 }
130
131 // Display message to the user
132 if (!$wppb_add_on_is_active) {
133 echo '<span class="dashicons dashicons-no-alt"></span><span class="wppb-add-on-message">' . __('Add-On is <strong>inactive</strong>', 'profile-builder') . '</span>';
134 } else {
135 echo '<span class="dashicons dashicons-yes"></span><span class="wppb-add-on-message">' . __('Add-On is <strong>active</strong>', 'profile-builder') . '</span>';
136 }
137
138 } else {
139
140 // If we're on a multisite don't add the wpp-add-on-download class to the button so we don't fire the js that
141 // handles the in-page download
142 if (is_multisite()) {
143 ($wppb_add_on['paid']) ? $wppb_paid_link_class = 'button-primary' : $wppb_paid_link_class = 'button-secondary';
144 ($wppb_add_on['paid']) ? $wppb_paid_link_text = __('Buy Now', 'profile-builder') : $wppb_paid_link_text = __('Download Now', 'profile-builder');
145 } else {
146 ($wppb_add_on['paid']) ? $wppb_paid_link_class = 'button-primary' : $wppb_paid_link_class = 'button-secondary wppb-add-on-download';
147 ($wppb_add_on['paid']) ? $wppb_paid_link_text = __('Buy Now', 'profile-builder') : $wppb_paid_link_text = __('Install Now', 'profile-builder');
148 }
149
150 ($wppb_add_on['paid']) ? $wppb_paid_href_utm_text = '?utm_source=wpbackend&utm_medium=clientsite&utm_content=add-on-page-buy-button&utm_campaign=PB' . $version : $wppb_paid_href_utm_text = '&utm_source=wpbackend&utm_medium=clientsite&utm_content=add-on-page&utm_campaign=PB' . $version;
151
152 echo '<a target="_blank" class="right button ' . $wppb_paid_link_class . '" href="' . $wppb_add_on['download_url'] . $wppb_paid_href_utm_text . '" data-add-on-slug="profile-builder-' . $wppb_add_on['slug'] . '" data-add-on-name="' . $wppb_add_on['name'] . '" data-nonce="' . $ajax_nonce . '">' . $wppb_paid_link_text . '</a>';
153 echo '<span class="dashicons dashicons-yes"></span><span class="wppb-add-on-message">' . __('Compatible with your version of Profile Builder.', 'profile-builder') . '</span>';
154
155 }
156
157 echo '<div class="spinner"></div>';
158
159 // PB version type does not match
160 } else {
161
162 echo '<a target="_blank" class="button button-secondary right" href="http://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_content=add-on-page-upgrade-button&utm_campaign=PB' . $version . '">' . __('Upgrade Profile Builder', 'profile-builder') . '</a>';
163 echo '<span class="dashicons dashicons-no-alt"></span><span class="wppb-add-on-message">' . __('Not compatible with Profile Builder', 'profile-builder') . ' ' . $version . '</span>';
164
165 }
166
167 } else {
168
169 // If PB version is older than the minimum required version of the add-on
170 echo ' ' . '<a class="button button-secondary right" href="' . admin_url('plugins.php') . '">' . __('Update', 'profile-builder') . '</a>';
171 echo '<span class="wppb-add-on-message">' . __('Not compatible with your version of Profile Builder.', 'profile-builder') . '</span><br />';
172 echo '<span class="wppb-add-on-message">' . __('Minimum required Profile Builder version:', 'profile-builder') . '<strong> ' . $wppb_add_on['product_version'] . '</strong></span>';
173
174 }
175
176 // We had to put this error here because we need the url of the add-on
177 echo '<span class="wppb-add-on-user-messages wppb-error-manual-install">' . sprintf(__('Could not install add-on. Retry or <a href="%s" target="_blank">install manually</a>.', 'profile-builder'), esc_url($wppb_add_on['url'])) . '</span>';
178
179 echo '</div>';
180 echo '</div>';
181
182 } /* end $wppb_add_ons foreach */
183 }
184
185 ?>
186 </div>
187
188 <div class="clear"></div>
189 <div>
190 <h2><?php _e( 'Recommended Plugins', 'profile-builder' ) ?></h2>
191 <?php
192 $pms_add_on_exists = 0;
193 $pms_add_on_is_active = 0;
194 $pms_add_on_is_network_active = 0;
195 // Check to see if add-on is in the plugins folder
196 foreach ($wppb_get_all_plugins as $wppb_plugin_key => $wppb_plugin) {
197 if( strtolower($wppb_plugin['Name']) == strtolower( 'Paid Member Subscriptions' ) && strpos(strtolower($wppb_plugin['AuthorName']), strtolower('Cozmoslabs')) !== false) {
198 $pms_add_on_exists = 1;
199 if (in_array($wppb_plugin_key, $wppb_get_active_plugins)) {
200 $pms_add_on_is_active = 1;
201 }
202 // Consider the add-on active if it's network active
203 if (is_plugin_active_for_network($wppb_plugin_key)) {
204 $pms_add_on_is_network_active = 1;
205 $pms_add_on_is_active = 1;
206 }
207 $plugin_file = $wppb_plugin_key;
208 }
209 }
210 ?>
211 <div class="plugin-card wppb-recommended-plugin wppb-add-on">
212 <div class="plugin-card-top">
213 <a target="_blank" href="http://wordpress.org/plugins/paid-member-subscriptions/">
214 <img src="<?php echo plugins_url( '../assets/images/pms_recommended.jpg', __FILE__ ); ?>" width="100%">
215 </a>
216 <h3 class="wppb-add-on-title">
217 <a target="_blank" href="http://wordpress.org/plugins/paid-member-subscriptions/">Paid Member Subscriptions</a>
218 </h3>
219 <h3 class="wppb-add-on-price"><?php _e( 'Free', 'profile-builder' ) ?></h3>
220 <p class="wppb-add-on-description">
221 <?php _e( 'Accept user payments, create subscription plans and restrict content on your membership site.', 'profile-builder' ) ?>
222 <a href="<?php admin_url();?>plugin-install.php?tab=plugin-information&plugin=paid-member-subscriptions&TB_iframe=true&width=772&height=875" class="thickbox" aria-label="More information about Paid Member Subscriptions - membership & content restriction" data-title="Paid Member Subscriptions - membership & content restriction"><?php _e( 'More Details' ); ?></a>
223 </p>
224 </div>
225 <div class="plugin-card-bottom wppb-add-on-compatible">
226 <?php
227 if ($pms_add_on_exists) {
228
229 // Display activate/deactivate buttons
230 if (!$pms_add_on_is_active) {
231 echo '<a class="wppb-add-on-activate right button button-secondary" href="' . $plugin_file . '" data-nonce="' . $ajax_nonce . '">' . __('Activate', 'profile-builder') . '</a>';
232
233 // If add-on is network activated don't allow deactivation
234 } elseif (!$pms_add_on_is_network_active) {
235 echo '<a class="wppb-add-on-deactivate right button button-secondary" href="' . $plugin_file . '" data-nonce="' . $ajax_nonce . '">' . __('Deactivate', 'profile-builder') . '</a>';
236 }
237
238 // Display message to the user
239 if( !$pms_add_on_is_active ){
240 echo '<span class="dashicons dashicons-no-alt"></span><span class="wppb-add-on-message">' . __('Plugin is <strong>inactive</strong>', 'profile-builder') . '</span>';
241 } else {
242 echo '<span class="dashicons dashicons-yes"></span><span class="wppb-add-on-message">' . __('Plugin is <strong>active</strong>', 'profile-builder') . '</span>';
243 }
244
245 } else {
246
247 // If we're on a multisite don't add the wpp-add-on-download class to the button so we don't fire the js that
248 // handles the in-page download
249 if (is_multisite()) {
250 $wppb_paid_link_class = 'button-secondary';
251 $wppb_paid_link_text = __('Download Now', 'profile-builder' );
252 } else {
253 $wppb_paid_link_class = 'button-secondary wppb-add-on-download';
254 $wppb_paid_link_text = __('Install Now', 'profile-builder');
255 }
256
257 echo '<a target="_blank" class="right button ' . $wppb_paid_link_class . '" href="https://downloads.wordpress.org/plugin/paid-member-subscriptions.zip" data-add-on-slug="paid-member-subscriptions" data-add-on-name="Paid Member Subscriptions" data-nonce="' . $ajax_nonce . '">' . $wppb_paid_link_text . '</a>';
258 echo '<span class="dashicons dashicons-yes"></span><span class="wppb-add-on-message">' . __('Compatible with your version of Profile Builder.', 'profile-builder') . '</span>';
259
260 }
261 ?>
262 <div class="spinner"></div>
263 <span class="wppb-add-on-user-messages wppb-error-manual-install"><?php printf(__('Could not install plugin. Retry or <a href="%s" target="_blank">install manually</a>.', 'profile-builder'), esc_url( 'http://www.wordpress.org/plugins/paid-member-subscriptions' )) ?></a>.</span>
264 </div>
265 </div>
266 </div>
267
268 </div>
269 <?php
270 }
271
272 /*
273 * Function that returns the array of add-ons from cozmoslabs.com if it finds the file
274 * If something goes wrong it returns false
275 *
276 * @since v.2.1.0
277 */
278 function wppb_add_ons_get_remote_content() {
279
280 $response = wp_remote_get('http://www.cozmoslabs.com/wp-content/plugins/cozmoslabs-products-add-ons/profile-builder-add-ons.json');
281
282 if( is_wp_error($response) ) {
283 return false;
284 } else {
285 $json_file_contents = $response['body'];
286 $wppb_add_ons = json_decode( $json_file_contents, true );
287 }
288
289 if( !is_object( $wppb_add_ons ) && !is_array( $wppb_add_ons ) ) {
290 return false;
291 }
292
293 return $wppb_add_ons;
294
295 }
296
297
298 /*
299 * Function that is triggered through Ajax to activate an add-on
300 *
301 * @since v.2.1.0
302 */
303 function wppb_add_on_activate() {
304 check_ajax_referer( 'wppb-activate-addon', 'nonce' );
305 if( current_user_can( 'manage_options' ) ){
306 // Setup variables from POST
307 $wppb_add_on_to_activate = $_POST['wppb_add_on_to_activate'];
308 $response = $_POST['wppb_add_on_index'];
309
310 if( !empty( $wppb_add_on_to_activate ) && !is_plugin_active( $wppb_add_on_to_activate )) {
311 activate_plugin( $wppb_add_on_to_activate );
312 }
313
314 if( !empty( $response ) )
315 echo $response;
316 }
317 wp_die();
318 }
319 add_action( 'wp_ajax_wppb_add_on_activate', 'wppb_add_on_activate' );
320
321
322 /*
323 * Function that is triggered through Ajax to deactivate an add-on
324 *
325 * @since v.2.1.0
326 */
327 function wppb_add_on_deactivate() {
328 check_ajax_referer( 'wppb-activate-addon', 'nonce' );
329 if( current_user_can( 'manage_options' ) ){
330 // Setup variables from POST
331 $wppb_add_on_to_deactivate = $_POST['wppb_add_on_to_deactivate'];
332 $response = $_POST['wppb_add_on_index'];
333
334 if( !empty( $wppb_add_on_to_deactivate ))
335 deactivate_plugins( $wppb_add_on_to_deactivate );
336
337 if( !empty( $response ) )
338 echo $response;
339 }
340 wp_die();
341
342 }
343 add_action( 'wp_ajax_wppb_add_on_deactivate', 'wppb_add_on_deactivate' );
344
345
346 /*
347 * Function that downloads and unzips the .zip file returned from Cozmoslabs
348 *
349 * @since v.2.1.0
350 */
351 function wppb_add_on_download_zip_file() {
352
353 check_ajax_referer( 'wppb-activate-addon', 'nonce' );
354
355 // Set the response to success and change it later if needed
356 $response = $_POST['wppb_add_on_index'];
357 $add_on_index = $response;
358
359 // Setup variables from POST
360 $wppb_add_on_download_url = $_POST['wppb_add_on_download_url'];
361 $wppb_add_on_zip_name = $_POST['wppb_add_on_zip_name'];
362
363 if( strpos( $wppb_add_on_download_url, 'http://www.cozmoslabs.com/' ) === false && strpos( $wppb_add_on_download_url, 'https://downloads.wordpress.org/' ) === false )
364 wp_die();
365
366 // Get .zip file
367 $remote_response = wp_remote_get( $wppb_add_on_download_url, array( 'timeout' => 500000) );
368 if( is_wp_error( $remote_response ) ) {
369 $response = 'error-' . $add_on_index;
370 } else {
371 $file_contents = $remote_response['body'];
372 }
373
374
375 // Put the file in the plugins directory
376 if( isset( $file_contents ) ) {
377 if( file_put_contents( WP_PLUGIN_DIR . '/' . $wppb_add_on_zip_name, $file_contents ) === false ) {
378 $response = 'error-' . $add_on_index;
379 }
380 }
381
382
383 // Unzip the file
384 if( $response != 'error' ) {
385 WP_Filesystem();
386 if( unzip_file( WP_PLUGIN_DIR . '/' . $wppb_add_on_zip_name , WP_PLUGIN_DIR ) ) {
387 // Remove the zip file after we are all done
388 unlink( WP_PLUGIN_DIR . '/' . $wppb_add_on_zip_name );
389 } else {
390 $response = 'error-' . $add_on_index;
391 }
392 }
393
394 echo $response;
395 wp_die();
396 }
397 add_action( 'wp_ajax_wppb_add_on_download_zip_file', 'wppb_add_on_download_zip_file' );
398
399
400 /*
401 * Function that retrieves the data of the newly added plugin
402 *
403 * @since v.2.1.0
404 */
405 function wppb_add_on_get_new_plugin_data() {
406 $wppb_add_on_name = $_POST['wppb_add_on_name'];
407
408 $wppb_get_all_plugins = get_plugins();
409 foreach( $wppb_get_all_plugins as $wppb_plugin_key => $wppb_plugin ) {
410
411 if( strpos( $wppb_plugin['Name'], $wppb_add_on_name ) !== false && strpos( $wppb_plugin['AuthorName'], 'Cozmoslabs' ) !== false ) {
412
413 // Deactivate the add-on if it's active
414 if( is_plugin_active( $wppb_plugin_key )) {
415 deactivate_plugins( $wppb_plugin_key );
416 }
417
418 // Return the plugin path
419 echo $wppb_plugin_key;
420 wp_die();
421 }
422 }
423
424 wp_die();
425 }
426 add_action( 'wp_ajax_wppb_add_on_get_new_plugin_data', 'wppb_add_on_get_new_plugin_data' );