| 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 |
if( $wppb_add_on['type'] == 'paid' ) |
| 103 |
echo '<h3 class="wppb-add-on-price">' . __( 'Available in Hobbyist and Pro Versions', 'profile-builder' ) . '</h3>'; |
| 104 |
else |
| 105 |
echo '<h3 class="wppb-add-on-price">' . __( 'Available in All Versions', 'profile-builder' ) . '</h3>'; |
| 106 |
|
| 107 |
echo '<p class="wppb-add-on-description">' . $wppb_add_on['description'] . '</p>'; |
| 108 |
|
| 109 |
echo '</div>'; |
| 110 |
|
| 111 |
$wppb_version_validation = version_compare(PROFILE_BUILDER_VERSION, $wppb_add_on['product_version']); |
| 112 |
|
| 113 |
($wppb_version_validation != -1) ? $wppb_version_validation_class = 'wppb-add-on-compatible' : $wppb_version_validation_class = 'wppb-add-on-not-compatible'; |
| 114 |
|
| 115 |
echo '<div class="plugin-card-bottom ' . $wppb_version_validation_class . '">'; |
| 116 |
|
| 117 |
// PB minimum version number is all good |
| 118 |
if ($wppb_version_validation != -1) { |
| 119 |
|
| 120 |
// PB version type does match |
| 121 |
if (in_array(strtolower($version), $wppb_add_on['product_version_type'])) { |
| 122 |
|
| 123 |
$ajax_nonce = wp_create_nonce("wppb-activate-addon"); |
| 124 |
|
| 125 |
if ($wppb_add_on_exists) { |
| 126 |
|
| 127 |
// Display activate/deactivate buttons |
| 128 |
if (!$wppb_add_on_is_active) { |
| 129 |
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>'; |
| 130 |
|
| 131 |
// If add-on is network activated don't allow deactivation |
| 132 |
} elseif (!$wppb_add_on_is_network_active) { |
| 133 |
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>'; |
| 134 |
} |
| 135 |
|
| 136 |
// Display message to the user |
| 137 |
if (!$wppb_add_on_is_active) { |
| 138 |
echo '<span class="dashicons dashicons-no-alt"></span><span class="wppb-add-on-message">' . __('Add-On is <strong>inactive</strong>', 'profile-builder') . '</span>'; |
| 139 |
} else { |
| 140 |
echo '<span class="dashicons dashicons-yes"></span><span class="wppb-add-on-message">' . __('Add-On is <strong>active</strong>', 'profile-builder') . '</span>'; |
| 141 |
} |
| 142 |
|
| 143 |
} else { |
| 144 |
|
| 145 |
// 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 |
| 146 |
// handles the in-page download |
| 147 |
($wppb_add_on['paid']) ? $wppb_paid_link_class = 'button-primary' : $wppb_paid_link_class = 'button-secondary'; |
| 148 |
($wppb_add_on['paid']) ? $wppb_paid_link_text = __('Learn More', 'profile-builder') : $wppb_paid_link_text = __('Download Now', 'profile-builder'); |
| 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['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="https://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.png', __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 |
// handles the in-page download |
| 247 |
$wppb_paid_link_class = 'button-secondary'; |
| 248 |
$wppb_paid_link_text = __('Download Now', 'profile-builder'); |
| 249 |
|
| 250 |
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>'; |
| 251 |
echo '<span class="dashicons dashicons-yes"></span><span class="wppb-add-on-message">' . __('Compatible with your version of Profile Builder.', 'profile-builder') . '</span>'; |
| 252 |
|
| 253 |
} |
| 254 |
?> |
| 255 |
<div class="spinner"></div> |
| 256 |
<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> |
| 257 |
</div> |
| 258 |
</div> |
| 259 |
</div> |
| 260 |
|
| 261 |
</div> |
| 262 |
<?php |
| 263 |
} |
| 264 |
|
| 265 |
/* |
| 266 |
* Function that returns the array of add-ons from cozmoslabs.com if it finds the file |
| 267 |
* If something goes wrong it returns false |
| 268 |
* |
| 269 |
* @since v.2.1.0 |
| 270 |
*/ |
| 271 |
function wppb_add_ons_get_remote_content() { |
| 272 |
|
| 273 |
$response = wp_remote_get('https://www.cozmoslabs.com/wp-content/plugins/cozmoslabs-products-add-ons/profile-builder-add-ons.json'); |
| 274 |
|
| 275 |
if( is_wp_error($response) ) { |
| 276 |
return false; |
| 277 |
} else { |
| 278 |
$json_file_contents = $response['body']; |
| 279 |
$wppb_add_ons = json_decode( $json_file_contents, true ); |
| 280 |
} |
| 281 |
|
| 282 |
if( !is_object( $wppb_add_ons ) && !is_array( $wppb_add_ons ) ) { |
| 283 |
return false; |
| 284 |
} |
| 285 |
|
| 286 |
return $wppb_add_ons; |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
/* |
| 292 |
* Function that is triggered through Ajax to activate an add-on |
| 293 |
* |
| 294 |
* @since v.2.1.0 |
| 295 |
*/ |
| 296 |
function wppb_add_on_activate() { |
| 297 |
check_ajax_referer( 'wppb-activate-addon', 'nonce' ); |
| 298 |
if( current_user_can( 'manage_options' ) ){ |
| 299 |
// Setup variables from POST |
| 300 |
$wppb_add_on_to_activate = $_POST['wppb_add_on_to_activate']; |
| 301 |
$response = $_POST['wppb_add_on_index']; |
| 302 |
|
| 303 |
if( !empty( $wppb_add_on_to_activate ) && !is_plugin_active( $wppb_add_on_to_activate )) { |
| 304 |
activate_plugin( $wppb_add_on_to_activate ); |
| 305 |
} |
| 306 |
|
| 307 |
if( !empty( $response ) ) |
| 308 |
echo $response; |
| 309 |
} |
| 310 |
wp_die(); |
| 311 |
} |
| 312 |
add_action( 'wp_ajax_wppb_add_on_activate', 'wppb_add_on_activate' ); |
| 313 |
|
| 314 |
|
| 315 |
/* |
| 316 |
* Function that is triggered through Ajax to deactivate an add-on |
| 317 |
* |
| 318 |
* @since v.2.1.0 |
| 319 |
*/ |
| 320 |
function wppb_add_on_deactivate() { |
| 321 |
check_ajax_referer( 'wppb-activate-addon', 'nonce' ); |
| 322 |
if( current_user_can( 'manage_options' ) ){ |
| 323 |
// Setup variables from POST |
| 324 |
$wppb_add_on_to_deactivate = $_POST['wppb_add_on_to_deactivate']; |
| 325 |
$response = $_POST['wppb_add_on_index']; |
| 326 |
|
| 327 |
if( !empty( $wppb_add_on_to_deactivate )) |
| 328 |
deactivate_plugins( $wppb_add_on_to_deactivate ); |
| 329 |
|
| 330 |
if( !empty( $response ) ) |
| 331 |
echo $response; |
| 332 |
} |
| 333 |
wp_die(); |
| 334 |
|
| 335 |
} |
| 336 |
add_action( 'wp_ajax_wppb_add_on_deactivate', 'wppb_add_on_deactivate' ); |
| 337 |
|
| 338 |
|
| 339 |
/* |
| 340 |
* Function that downloads and unzips the .zip file returned from Cozmoslabs |
| 341 |
* |
| 342 |
* @since v.2.1.0 |
| 343 |
*/ |
| 344 |
function wppb_add_on_download_zip_file() { |
| 345 |
|
| 346 |
check_ajax_referer( 'wppb-activate-addon', 'nonce' ); |
| 347 |
|
| 348 |
// Set the response to success and change it later if needed |
| 349 |
$response = $_POST['wppb_add_on_index']; |
| 350 |
$add_on_index = $response; |
| 351 |
|
| 352 |
// Setup variables from POST |
| 353 |
$wppb_add_on_download_url = $_POST['wppb_add_on_download_url']; |
| 354 |
$wppb_add_on_zip_name = $_POST['wppb_add_on_zip_name']; |
| 355 |
|
| 356 |
if( strpos( $wppb_add_on_download_url, 'https://www.cozmoslabs.com/' ) === false && strpos( $wppb_add_on_download_url, 'https://downloads.wordpress.org/' ) === false ) |
| 357 |
wp_die(); |
| 358 |
|
| 359 |
// Get .zip file |
| 360 |
$remote_response = wp_remote_get( $wppb_add_on_download_url, array( 'timeout' => 500000) ); |
| 361 |
if( is_wp_error( $remote_response ) ) { |
| 362 |
$response = 'error-' . $add_on_index; |
| 363 |
} else { |
| 364 |
$file_contents = $remote_response['body']; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
// Put the file in the plugins directory |
| 369 |
if( isset( $file_contents ) ) { |
| 370 |
if( file_put_contents( WP_PLUGIN_DIR . '/' . $wppb_add_on_zip_name, $file_contents ) === false ) { |
| 371 |
$response = 'error-' . $add_on_index; |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
// Unzip the file |
| 377 |
if( $response != 'error' ) { |
| 378 |
WP_Filesystem(); |
| 379 |
if( unzip_file( WP_PLUGIN_DIR . '/' . $wppb_add_on_zip_name , WP_PLUGIN_DIR ) ) { |
| 380 |
// Remove the zip file after we are all done |
| 381 |
unlink( WP_PLUGIN_DIR . '/' . $wppb_add_on_zip_name ); |
| 382 |
} else { |
| 383 |
$response = 'error-' . $add_on_index; |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
echo $response; |
| 388 |
wp_die(); |
| 389 |
} |
| 390 |
add_action( 'wp_ajax_wppb_add_on_download_zip_file', 'wppb_add_on_download_zip_file' ); |
| 391 |
|
| 392 |
|
| 393 |
/* |
| 394 |
* Function that retrieves the data of the newly added plugin |
| 395 |
* |
| 396 |
* @since v.2.1.0 |
| 397 |
*/ |
| 398 |
function wppb_add_on_get_new_plugin_data() { |
| 399 |
$wppb_add_on_name = $_POST['wppb_add_on_name']; |
| 400 |
|
| 401 |
$wppb_get_all_plugins = get_plugins(); |
| 402 |
foreach( $wppb_get_all_plugins as $wppb_plugin_key => $wppb_plugin ) { |
| 403 |
|
| 404 |
if( strpos( $wppb_plugin['Name'], $wppb_add_on_name ) !== false && strpos( $wppb_plugin['AuthorName'], 'Cozmoslabs' ) !== false ) { |
| 405 |
|
| 406 |
// Deactivate the add-on if it's active |
| 407 |
if( is_plugin_active( $wppb_plugin_key )) { |
| 408 |
deactivate_plugins( $wppb_plugin_key ); |
| 409 |
} |
| 410 |
|
| 411 |
// Return the plugin path |
| 412 |
echo $wppb_plugin_key; |
| 413 |
wp_die(); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
wp_die(); |
| 418 |
} |
| 419 |
add_action( 'wp_ajax_wppb_add_on_get_new_plugin_data', 'wppb_add_on_get_new_plugin_data' ); |