Onboarding.php
5 months ago
OnboardingHelper.php
1 year ago
OnboardingIndustries.php
2 years ago
OnboardingJetpack.php
3 years ago
OnboardingMailchimp.php
3 years ago
OnboardingProducts.php
3 years ago
OnboardingProfile.php
1 year ago
OnboardingSetupWizard.php
1 year ago
OnboardingSync.php
2 years ago
OnboardingProfile.php
73 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Onboarding Setup Wizard |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin\Onboarding; |
| 7 | |
| 8 | use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists; |
| 9 | use Automattic\WooCommerce\Admin\PageController; |
| 10 | use Automattic\WooCommerce\Admin\WCAdminHelper; |
| 11 | |
| 12 | /** |
| 13 | * Contains backend logic for the onboarding profile and checklist feature. |
| 14 | */ |
| 15 | class OnboardingProfile { |
| 16 | /** |
| 17 | * Profile data option name. |
| 18 | */ |
| 19 | const DATA_OPTION = 'woocommerce_onboarding_profile'; |
| 20 | |
| 21 | /** |
| 22 | * Option for storing the onboarding profile progress. |
| 23 | */ |
| 24 | const PROGRESS_OPTION = 'woocommerce_onboarding_profile_progress'; |
| 25 | |
| 26 | /** |
| 27 | * Add onboarding actions. |
| 28 | */ |
| 29 | public static function init() { |
| 30 | add_action( 'update_option_' . self::DATA_OPTION, array( __CLASS__, 'trigger_complete' ), 10, 2 ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Trigger the woocommerce_onboarding_profile_completed action |
| 35 | * |
| 36 | * @param array $old_value Previous value. |
| 37 | * @param array $value Current value. |
| 38 | */ |
| 39 | public static function trigger_complete( $old_value, $value ) { |
| 40 | if ( isset( $old_value['completed'] ) && $old_value['completed'] ) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | if ( ! isset( $value['completed'] ) || ! $value['completed'] ) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Action hook fired when the onboarding profile (or onboarding wizard, |
| 50 | * or profiler) is completed. |
| 51 | * |
| 52 | * @since 1.5.0 |
| 53 | */ |
| 54 | do_action( 'woocommerce_onboarding_profile_completed' ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Check if the profiler still needs to be completed. |
| 59 | * |
| 60 | * @return bool |
| 61 | */ |
| 62 | public static function needs_completion() { |
| 63 | $onboarding_data = get_option( self::DATA_OPTION, array() ); |
| 64 | |
| 65 | $is_completed = isset( $onboarding_data['completed'] ) && true === $onboarding_data['completed']; |
| 66 | $is_skipped = isset( $onboarding_data['skipped'] ) && true === $onboarding_data['skipped']; |
| 67 | |
| 68 | // @todo When merging to WooCommerce Core, we should set the `completed` flag to true during the upgrade progress. |
| 69 | // https://github.com/woocommerce/woocommerce-admin/pull/2300#discussion_r287237498. |
| 70 | return ! $is_completed && ! $is_skipped; |
| 71 | } |
| 72 | } |
| 73 |