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