| @@ -24,16 +24,8 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | class API { |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Shipping+ confirmation page and the authorization data guarding its form. | |
| 29 | - */ | |
| 30 | - public const SHIPPING_PLUS_SLUG = 'makecommerce_shipping_plus'; | |
| 31 | - public const SHIPPING_PLUS_CAPABILITY = 'manage_options'; | |
| 32 | - public const SHIPPING_PLUS_NONCE_ACTION = 'mc_shipping_plus_confirm'; | |
| 33 | - public const SHIPPING_PLUS_NONCE_FIELD = 'mc_shipping_plus_nonce'; | |
| 34 | - | |
| 35 | - /** | |
| 36 | 28 | * The ID of this plugin. |
| 37 | 29 | * |
| 38 | 30 | * @since 3.0.0 |
| 39 | 31 | * @access private |
| @@ -490,13 +482,8 @@ | ||
| 490 | 482 | 'makecommerce-bootstrap', |
| 491 | 483 | plugin_dir_url(__DIR__) . 'makecommerce/assets/bootstrap.5.3.3.min.css' |
| 492 | 484 | ); |
| 493 | 485 | |
| 494 | - wp_enqueue_style( | |
| 495 | - 'shipping-confirm', | |
| 496 | - 'https://static.maksekeskus.ee/modules/woocommerce/css/shipping-confirm.css' | |
| 497 | - ); | |
| 498 | - | |
| 499 | 486 | wp_enqueue_script( |
| 500 | 487 | 'makecommerce-bootstrap', |
| 501 | 488 | plugin_dir_url(__DIR__) . 'makecommerce/assets/bootstrap.bundle.min.js', |
| 502 | 489 | [], |
| @@ -509,16 +496,16 @@ | ||
| 509 | 496 | add_submenu_page( |
| 510 | 497 | 'shipping_plus', |
| 511 | 498 | 'Shipping+ Confirmation', |
| 512 | 499 | 'Shipping+ Confirmation', |
| 513 | - self::SHIPPING_PLUS_CAPABILITY, | |
| 514 | - self::SHIPPING_PLUS_SLUG, | |
| 500 | + 'manage_options', | |
| 501 | + 'makecommerce_shipping_plus', | |
| 515 | 502 | [$this, 'render_shipping_plus_page'] |
| 516 | 503 | ); |
| 517 | 504 | } |
| 518 | 505 | |
| 519 | 506 | public function remove_shipping_confirm_menu(): void { |
| 520 | - remove_submenu_page( 'shipping_plus', self::SHIPPING_PLUS_SLUG ); | |
| 507 | + remove_submenu_page( 'shipping_plus', 'makecommerce_shipping_plus' ); | |
| 521 | 508 | } |
| 522 | 509 | |
| 523 | 510 | public function render_shipping_plus_page() |
| 524 | 511 | { |
| @@ -542,28 +529,14 @@ | ||
| 542 | 529 | } |
| 543 | 530 | |
| 544 | 531 | public function save_shipping_plus_confirmation(): void |
| 545 | 532 | { |
| 546 | - $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; | |
| 547 | - | |
| 548 | 533 | if ( |
| 549 | 534 | isset($_POST['accept_shipping']) && |
| 550 | - $current_page === self::SHIPPING_PLUS_SLUG | |
| 535 | + $_GET['page'] === 'makecommerce_shipping_plus' | |
| 551 | 536 | ) { |
| 552 | - // Only users who are allowed to see this page may confirm the migration | |
| 553 | - if (!current_user_can(self::SHIPPING_PLUS_CAPABILITY)) { | |
| 554 | - wp_die( | |
| 555 | - esc_html__('You do not have permission to change MakeCommerce settings.', 'wc_makecommerce_domain'), | |
| 556 | - esc_html__('Forbidden', 'wc_makecommerce_domain'), | |
| 557 | - ['response' => 403] | |
| 558 | - ); | |
| 559 | - } | |
| 560 | - | |
| 561 | - check_admin_referer(self::SHIPPING_PLUS_NONCE_ACTION, self::SHIPPING_PLUS_NONCE_FIELD); | |
| 562 | - | |
| 563 | 537 | update_option('mc_shipping_plus_confirmed', 'yes'); |
| 564 | 538 | update_option('mc_shipping_plus', 'yes'); |
| 565 | - update_option('makecommerce_install_status', 'upgrade'); | |
| 566 | 539 | $this->mc_shipping_plus_creds_migration(); |
| 567 | 540 | wp_redirect(admin_url('admin.php?page=makecommerce_dashboard')); |
| 568 | 541 | exit; |
| 569 | 542 | } |
| @@ -582,16 +555,17 @@ | ||
| 582 | 555 | 'mc_public_key' => 'mk_public_key', |
| 583 | 556 | 'mc_test_shop_id' => 'mk_test_shop_id', |
| 584 | 557 | 'mc_test_secret_key' => 'mk_test_private_key', |
| 585 | 558 | 'mc_test_public_key' => 'mk_test_public_key', |
| 586 | - 'mc_api_mode' => 'mk_api_type', | |
| 559 | + 'mc_api_mode' => 'mk_api_mode', | |
| 587 | 560 | ]; |
| 588 | 561 | |
| 589 | 562 | foreach ($migration_map as $new_key => $old_key) { |
| 563 | + $new_value = get_option($new_key, null); | |
| 590 | 564 | $old_value = get_option($old_key, null); |
| 591 | 565 | |
| 592 | - if ($old_value !== null) { | |
| 566 | + if (($new_value === '' || $new_value === null) && $old_value !== null && $old_value !== '') { | |
| 593 | 567 | update_option($new_key, $old_value); |
| 594 | 568 | } |
| 595 | 569 | } |
| 596 | 570 | } |
| 597 | 571 | } |