DragDropBuilder
1 month ago
EmailSettings
1 year ago
Membership
1 month ago
AbstractSettingsPage.php
2 years ago
AddNewForm.php
1 year ago
AdminFooter.php
4 years ago
ExtensionsSettingsPage.php
1 year ago
FormList.php
4 months ago
Forms.php
1 year ago
FuseWP.php
3 years ago
GeneralSettings.php
9 months ago
IDUserColumn.php
5 years ago
LicenseUpgrader.php
3 years ago
MailOptin.php
3 years ago
MemberDirectories.php
1 year ago
MembersDirectoryList.php
4 years ago
ToolsSettingsPage.php
4 years ago
index.php
3 years ago
LicenseUpgrader.php
440 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\ExtensionManager; |
| 6 | use ProfilePress\Core\Classes\Installer\PluginSilentUpgrader; |
| 7 | use ProfilePress\Core\Classes\Installer\PluginSilentUpgraderSkin; |
| 8 | use ProfilePress\Custom_Settings_Page_Api; |
| 9 | |
| 10 | class LicenseUpgrader |
| 11 | { |
| 12 | public function __construct() |
| 13 | { |
| 14 | if ( ! ExtensionManager::is_premium()) { |
| 15 | |
| 16 | add_filter('ppress_settings_page_submenus_tabs', [$this, 'add_menu']); |
| 17 | add_action('ppress_admin_settings_submenu_page_general_license', [$this, 'admin_page']); |
| 18 | |
| 19 | add_action('ppress_register_menu_page_general_license', function () { |
| 20 | |
| 21 | add_filter('ppress_general_settings_admin_page_title', function () { |
| 22 | return esc_html__('License', 'wp-user-avatar'); |
| 23 | }); |
| 24 | }); |
| 25 | |
| 26 | add_action('admin_enqueue_scripts', [$this, 'settings_enqueues']); |
| 27 | |
| 28 | add_action('wp_ajax_ppress_connect_url', array($this, 'generate_url')); |
| 29 | } |
| 30 | |
| 31 | add_action('wp_ajax_nopriv_ppress_connect_process', array($this, 'process')); |
| 32 | } |
| 33 | |
| 34 | public function add_menu($tabs) |
| 35 | { |
| 36 | $tabs[-1] = ['parent' => 'general', 'id' => 'license', 'label' => esc_html__('License', 'wp-user-avatar')]; |
| 37 | |
| 38 | return $tabs; |
| 39 | } |
| 40 | |
| 41 | public function admin_page() |
| 42 | { |
| 43 | $settings = [ |
| 44 | [ |
| 45 | 'section_title' => '', |
| 46 | 'disable_submit_button' => true, |
| 47 | 'license_key' => [ |
| 48 | 'type' => 'arbitrary', |
| 49 | 'data' => $this->admin_settings_page_callback() |
| 50 | ] |
| 51 | ] |
| 52 | ]; |
| 53 | |
| 54 | $instance = Custom_Settings_Page_Api::instance($settings, 'ppress_license', esc_html__('License', 'wp-user-avatar')); |
| 55 | $instance->remove_white_design(); |
| 56 | $instance->remove_h2_header(); |
| 57 | $instance->build(true); |
| 58 | } |
| 59 | |
| 60 | public function admin_settings_page_callback() |
| 61 | { |
| 62 | $nonce = wp_create_nonce('ppress-connect-url'); |
| 63 | |
| 64 | ob_start(); |
| 65 | |
| 66 | ?> |
| 67 | <style> |
| 68 | .ppress-admin-wrap .wrap h2 { |
| 69 | display: none; |
| 70 | } |
| 71 | |
| 72 | .ppress-admin .remove_white_styling #post-body-content .form-table th { |
| 73 | width: 200px !important; |
| 74 | } |
| 75 | |
| 76 | .ppress-admin .remove_white_styling #post-body-content input[type=text] { |
| 77 | width: 25em !important; |
| 78 | } |
| 79 | </style> |
| 80 | |
| 81 | <div class="ppress-lite-license-wrap"> |
| 82 | <p style="font-size: 110%;"> |
| 83 | <?php |
| 84 | esc_html_e( |
| 85 | 'You\'re using ProfilePress Lite - no license needed. Enjoy! 😊', |
| 86 | 'wp-user-avatar' |
| 87 | ); |
| 88 | ?> |
| 89 | </p> |
| 90 | |
| 91 | <p class="description" style="margin-bottom: 8px;"> |
| 92 | <?php |
| 93 | echo wp_kses_post( |
| 94 | sprintf( |
| 95 | /* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */ |
| 96 | __( |
| 97 | 'Already purchased? Simply %1$sretrieve your license key%2$s and enter it below to connect with ProfilePress Pro.', |
| 98 | 'wp-user-avatar' |
| 99 | ), |
| 100 | sprintf( |
| 101 | '<a href="%s" target="_blank" rel="noopener noreferrer">', |
| 102 | 'https://profilepress.com/account/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page' |
| 103 | ), |
| 104 | '</a>' |
| 105 | ) |
| 106 | ); |
| 107 | ?> |
| 108 | </p> |
| 109 | |
| 110 | <div class="ppress-license-field"> |
| 111 | <input |
| 112 | type="text" |
| 113 | id="ppress-connect-license-key" |
| 114 | name="ppress-license-key" |
| 115 | value="" |
| 116 | class="regular-text" |
| 117 | style="line-height: 1; font-size: 1.15rem; padding: 10px;" |
| 118 | /> |
| 119 | |
| 120 | <button |
| 121 | class="button button-secondary ppress-license-button" |
| 122 | id="ppress-connect-license-submit" |
| 123 | data-connecting="<?php esc_attr_e('Connecting...', 'wp-user-avatar'); ?>" |
| 124 | data-connect="<?php esc_attr_e('Unlock Pro Features Now', 'wp-user-avatar'); ?>" |
| 125 | > |
| 126 | <?php esc_html_e('Unlock Pro Features Now', 'wp-user-avatar'); ?> |
| 127 | </button> |
| 128 | |
| 129 | <input type="hidden" name="ppress-action" value="ppress-connect"/> |
| 130 | <input type="hidden" id="ppress-connect-license-nonce" name="ppress-connect-license-nonce" value="<?php echo esc_attr($nonce); ?>"/> |
| 131 | </div> |
| 132 | |
| 133 | <div id="ppress-connect-license-feedback" class="ppress-license-message"></div> |
| 134 | |
| 135 | <div class="ppress-settings-upgrade"> |
| 136 | <div class="ppress-settings-upgrade__inner"> |
| 137 | <span class="dashicons dashicons-unlock" style="font-size: 40px; width: 40px; height: 50px;"></span> |
| 138 | <h3> |
| 139 | <?php esc_html_e('Unlock Powerful Pro Features', 'wp-user-avatar'); ?> |
| 140 | </h3> |
| 141 | |
| 142 | <ul> |
| 143 | <li> |
| 144 | <div class="dashicons dashicons-yes"></div> |
| 145 | <?php esc_html_e('No extra 2% Stripe fee', 'wp-user-avatar'); ?> |
| 146 | </li> |
| 147 | <li> |
| 148 | <div class="dashicons dashicons-yes"></div> |
| 149 | <a href="https://profilepress.com/addons/paypal/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 150 | <?php esc_html_e('Collect PayPal payments', 'wp-user-avatar'); ?> |
| 151 | </a> |
| 152 | </li> |
| 153 | <li> |
| 154 | <div class="dashicons dashicons-yes"></div> |
| 155 | <a href="https://profilepress.com/addons/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 156 | <?php esc_html_e('Mollie & Razorpay gateways', 'wp-user-avatar'); ?> |
| 157 | </a> |
| 158 | </li> |
| 159 | <li> |
| 160 | <div class="dashicons dashicons-yes"></div> |
| 161 | <?php esc_html_e('Premium form & profile themes', 'wp-user-avatar'); ?> |
| 162 | </li> |
| 163 | <li> |
| 164 | <div class="dashicons dashicons-yes"></div> |
| 165 | <?php esc_html_e('Premium directory themes', 'wp-user-avatar'); ?> |
| 166 | </li> |
| 167 | <li> |
| 168 | <div class="dashicons dashicons-yes"></div> |
| 169 | <a href="https://profilepress.com/article/drag-drop-advanced-shortcode-builders/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 170 | <?php esc_html_e('Advanced shortcode builder', 'wp-user-avatar'); ?> |
| 171 | </a> |
| 172 | </li> |
| 173 | <li> |
| 174 | <div class="dashicons dashicons-yes"></div> |
| 175 | <a href="https://profilepress.com/addons/custom-fields/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 176 | <?php esc_html_e('Custom Fields', 'wp-user-avatar'); ?> |
| 177 | </a> |
| 178 | </li> |
| 179 | <li> |
| 180 | <div class="dashicons dashicons-yes"></div> |
| 181 | <a href="https://profilepress.com/addons/social-login/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 182 | <?php esc_html_e('Social Login', 'wp-user-avatar'); ?> |
| 183 | </a> |
| 184 | </li> |
| 185 | <li> |
| 186 | <div class="dashicons dashicons-yes"></div> |
| 187 | <a href="https://profilepress.com/addons/metered-paywall/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 188 | <?php esc_html_e('Metered Paywall', 'wp-user-avatar'); ?> |
| 189 | </a> |
| 190 | </li> |
| 191 | <li> |
| 192 | <div class="dashicons dashicons-yes"></div> |
| 193 | <a href="https://profilepress.com/addons/user-moderation/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 194 | <?php esc_html_e('User Moderation', 'wp-user-avatar'); ?> |
| 195 | </a> |
| 196 | </li> |
| 197 | <li> |
| 198 | <div class="dashicons dashicons-yes"></div> |
| 199 | <a href="https://profilepress.com/addons/passwordless-login/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 200 | <?php esc_html_e('Passwordless Login', 'wp-user-avatar'); ?> |
| 201 | </a> |
| 202 | </li> |
| 203 | <li> |
| 204 | <div class="dashicons dashicons-yes"></div> |
| 205 | <a href="https://profilepress.com/addons/?utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" target="_blank" rel="noopener noreferrer"> |
| 206 | <?php esc_html_e('And more addons', 'wp-user-avatar'); ?> |
| 207 | </a> |
| 208 | </li> |
| 209 | </ul> |
| 210 | |
| 211 | <a href="https://profilepress.com/pricing/?discount=10PPOFF&utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page" class="button button-primary button-large ppress-upgrade-btn ppress-upgrade-btn-large" target="_blank" rel="noopener noreferrer"> |
| 212 | <?php esc_html_e('Upgrade to ProfilePress Pro', 'wp-user-avatar'); ?> |
| 213 | </a> |
| 214 | </div> |
| 215 | |
| 216 | <div class="ppress-upgrade-btn-subtext"> |
| 217 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-hidden="true" focusable="false"> |
| 218 | <path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path> |
| 219 | </svg> |
| 220 | |
| 221 | <?php |
| 222 | echo wp_kses( |
| 223 | sprintf( |
| 224 | /* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */ |
| 225 | __( |
| 226 | '<strong>Bonus</strong>: Loyal ProfilePress Lite users get <u>10%% off</u> regular price, automatically applied at checkout. %1$sUpgrade to Pro →%2$s', |
| 227 | 'wp-user-avatar' |
| 228 | ), |
| 229 | sprintf( |
| 230 | '<a href="%s" rel="noopener noreferrer" target="_blank">', |
| 231 | 'https://profilepress.com/pricing/?discount=10PPOFF&utm_source=wp_dashboard&utm_medium=retrieve_license&utm_campaign=lite_license_page' |
| 232 | ), |
| 233 | '</a>' |
| 234 | ), |
| 235 | array( |
| 236 | 'a' => array( |
| 237 | 'href' => true, |
| 238 | 'rel' => true, |
| 239 | 'target' => true, |
| 240 | ), |
| 241 | 'strong' => array(), |
| 242 | 'u' => array(), |
| 243 | ) |
| 244 | ); |
| 245 | ?> |
| 246 | </div> |
| 247 | </div> |
| 248 | </div> |
| 249 | <?php |
| 250 | return ob_get_clean(); |
| 251 | } |
| 252 | |
| 253 | public function settings_enqueues() |
| 254 | { |
| 255 | wp_enqueue_script( |
| 256 | 'ppress-license-connect', |
| 257 | PPRESS_ASSETS_URL . "/js/admin/license.js", |
| 258 | ['jquery'], |
| 259 | PPRESS_VERSION_NUMBER, |
| 260 | true |
| 261 | ); |
| 262 | } |
| 263 | |
| 264 | public function generate_url() |
| 265 | { |
| 266 | check_ajax_referer('ppress-connect-url', 'nonce'); |
| 267 | |
| 268 | // Check for permissions. |
| 269 | if ( ! current_user_can('install_plugins')) { |
| 270 | wp_send_json_error(['message' => esc_html__('You are not allowed to install plugins.', 'wp-user-avatar')]); |
| 271 | } |
| 272 | |
| 273 | $key = ! empty($_POST['key']) ? sanitize_text_field(wp_unslash($_POST['key'])) : ''; |
| 274 | |
| 275 | if (empty($key)) { |
| 276 | wp_send_json_error(['message' => esc_html__('Please enter your license key to connect.', 'wp-user-avatar')]); |
| 277 | } |
| 278 | |
| 279 | if (ExtensionManager::is_premium()) { |
| 280 | wp_send_json_error(['message' => esc_html__('Only the Lite version can be upgraded.', 'wp-user-avatar')]); |
| 281 | } |
| 282 | |
| 283 | $active = activate_plugin('profilepress-pro/profilepress-pro.php', false, false, true); |
| 284 | |
| 285 | if ( ! is_wp_error($active)) { |
| 286 | |
| 287 | update_option('ppress_license_key', $key); |
| 288 | |
| 289 | wp_send_json_success([ |
| 290 | 'message' => \esc_html__('You already have ProfilePress Pro installed! Activating it now', 'wp-user-avatar'), |
| 291 | 'reload' => true, |
| 292 | ]); |
| 293 | } |
| 294 | |
| 295 | $oth = hash('sha512', wp_rand()); |
| 296 | |
| 297 | update_option('ppress_connect_token', $oth); |
| 298 | update_option('ppress_license_key', $key); |
| 299 | |
| 300 | $version = PPRESS_VERSION_NUMBER; |
| 301 | $endpoint = admin_url('admin-ajax.php'); |
| 302 | $redirect = PPRESS_SETTINGS_SETTING_GENERAL_PAGE; |
| 303 | $url = add_query_arg( |
| 304 | [ |
| 305 | 'key' => $key, |
| 306 | 'oth' => $oth, |
| 307 | 'endpoint' => $endpoint, |
| 308 | 'version' => $version, |
| 309 | 'siteurl' => \admin_url(), |
| 310 | 'homeurl' => \home_url(), |
| 311 | 'redirect' => rawurldecode(base64_encode($redirect)), // phpcs:ignore |
| 312 | 'v' => 1, |
| 313 | ], |
| 314 | 'https://upgrade.profilepress.com' |
| 315 | ); |
| 316 | |
| 317 | wp_send_json_success(['url' => $url]); |
| 318 | } |
| 319 | |
| 320 | public function process() |
| 321 | { |
| 322 | $error = wp_kses( |
| 323 | sprintf( |
| 324 | /* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */ |
| 325 | __( |
| 326 | 'Oops! We could not automatically install an upgrade. Please download the plugin from profilepress.com and install it manually.', |
| 327 | 'wp-user-avatar' |
| 328 | ) |
| 329 | ), |
| 330 | [ |
| 331 | 'a' => [ |
| 332 | 'target' => true, |
| 333 | 'href' => true, |
| 334 | ], |
| 335 | ] |
| 336 | ); |
| 337 | |
| 338 | $post_oth = ! empty($_REQUEST['oth']) ? sanitize_text_field($_REQUEST['oth']) : ''; |
| 339 | $post_url = ! empty($_REQUEST['file']) ? esc_url_raw($_REQUEST['file']) : ''; |
| 340 | |
| 341 | $license = get_option('ppress_license_key', ''); |
| 342 | |
| 343 | if (empty($post_oth) || empty($post_url)) { |
| 344 | wp_send_json_error(['message' => $error, 'code_err' => '1']); |
| 345 | } |
| 346 | |
| 347 | $oth = get_option('ppress_connect_token'); |
| 348 | |
| 349 | if (empty($oth)) { |
| 350 | wp_send_json_error(['message' => $error, 'code_err' => '2']); |
| 351 | } |
| 352 | |
| 353 | if ( ! hash_equals($oth, $post_oth)) { |
| 354 | wp_send_json_error(['message' => $error, 'code_err' => '3']); |
| 355 | } |
| 356 | |
| 357 | delete_option('ppress_connect_token'); |
| 358 | |
| 359 | // Set the current screen to avoid undefined notices. |
| 360 | set_current_screen('profilepress_page_ppress-config'); |
| 361 | |
| 362 | $url = PPRESS_SETTINGS_SETTING_GENERAL_PAGE; |
| 363 | |
| 364 | // Verify pro not activated. |
| 365 | if (ExtensionManager::is_premium()) { |
| 366 | wp_send_json_success(esc_html__('Plugin installed & activated.', 'wp-user-avatar')); |
| 367 | } |
| 368 | |
| 369 | // Verify pro not installed. |
| 370 | $active = activate_plugin('profilepress-pro/profilepress-pro.php', $url, false, true); |
| 371 | |
| 372 | if ( ! is_wp_error($active)) { |
| 373 | |
| 374 | wp_send_json_success([ |
| 375 | 'message' => esc_html__('Plugin installed & activated.', 'wp-user-avatar'), |
| 376 | 'code_err' => '3.5' |
| 377 | ]); |
| 378 | } |
| 379 | |
| 380 | $creds = request_filesystem_credentials($url, '', false, false, null); |
| 381 | |
| 382 | // Check for file system permissions. |
| 383 | if (false === $creds || ! \WP_Filesystem($creds)) { |
| 384 | wp_send_json_error(['message' => $error, 'code_err' => '4']); |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | * We do not need any extra credentials if we have gotten this far, so let's install the plugin. |
| 389 | */ |
| 390 | |
| 391 | // Do not allow WordPress to search/download translations, as this will break JS output. |
| 392 | remove_action('upgrader_process_complete', ['Language_Pack_Upgrader', 'async_upgrade'], 20); |
| 393 | |
| 394 | // Create the plugin upgrader with our custom skin. |
| 395 | $installer = new PluginSilentUpgrader(new PluginSilentUpgraderSkin()); |
| 396 | |
| 397 | // Error check. |
| 398 | if ( ! method_exists($installer, 'install')) { |
| 399 | wp_send_json_error(['message' => $error, 'code_err' => '5']); |
| 400 | } |
| 401 | |
| 402 | if (empty($license)) { |
| 403 | wp_send_json_error([ |
| 404 | 'message' => esc_html__('You are not licensed.', 'wp-user-avatar'), |
| 405 | 'code_err' => '6' |
| 406 | ]); |
| 407 | } |
| 408 | |
| 409 | $installer->install($post_url); |
| 410 | |
| 411 | // Flush the cache and return the newly installed plugin basename. |
| 412 | wp_cache_flush(); |
| 413 | |
| 414 | $plugin_basename = $installer->plugin_info(); |
| 415 | |
| 416 | if ($plugin_basename) { |
| 417 | |
| 418 | // Activate the plugin silently. |
| 419 | $activated = activate_plugin($plugin_basename, '', false, true); |
| 420 | |
| 421 | if ( ! is_wp_error($activated)) { |
| 422 | wp_send_json_success(esc_html__('Plugin installed & activated.', 'wp-user-avatar')); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | wp_send_json_error(['message' => $error, 'code_err' => '7']); |
| 427 | } |
| 428 | |
| 429 | public static function get_instance() |
| 430 | { |
| 431 | static $instance = null; |
| 432 | |
| 433 | if (is_null($instance)) { |
| 434 | $instance = new self(); |
| 435 | } |
| 436 | |
| 437 | return $instance; |
| 438 | } |
| 439 | } |
| 440 |