AdditionalPayments.php
1 year ago
Appearance.php
2 years ago
CustomizeStore.php
5 months ago
ExperimentalShippingRecommendation.php
5 months ago
ExtendStore.php
1 year ago
GetMobileApp.php
3 years ago
LaunchYourStore.php
2 years ago
Marketing.php
7 months ago
Payments.php
10 months ago
Products.php
1 month ago
ReviewShippingOptions.php
3 years ago
Shipping.php
3 months ago
StoreCreation.php
4 years ago
StoreDetails.php
3 years ago
Tax.php
1 year ago
TourInAppMarketplace.php
2 years ago
WooCommercePayments.php
5 months ago
GetMobileApp.php
107 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks; |
| 4 | |
| 5 | use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task; |
| 6 | use Automattic\Jetpack\Connection\Manager; // https://github.com/Automattic/jetpack/blob/trunk/projects/packages/connection/src/class-manager.php . |
| 7 | |
| 8 | /** |
| 9 | * Get Mobile App Task |
| 10 | */ |
| 11 | class GetMobileApp extends Task { |
| 12 | /** |
| 13 | * ID. |
| 14 | * |
| 15 | * @return string |
| 16 | */ |
| 17 | public function get_id() { |
| 18 | return 'get-mobile-app'; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Title. |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function get_title() { |
| 27 | return __( 'Get the free WooCommerce mobile app', 'woocommerce' ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Content. |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | public function get_content() { |
| 36 | return ''; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Time. |
| 41 | * |
| 42 | * @return string |
| 43 | */ |
| 44 | public function get_time() { |
| 45 | return ''; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Task completion. |
| 50 | * |
| 51 | * @return bool |
| 52 | */ |
| 53 | public function is_complete() { |
| 54 | return get_option( 'woocommerce_admin_dismissed_mobile_app_modal' ) === 'yes'; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Task visibility. |
| 59 | * Can view under these conditions: |
| 60 | * - Jetpack is installed and connected && current site user has a wordpress.com account connected to jetpack |
| 61 | * - Jetpack is not connected && current user is capable of installing plugins |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | public function can_view() { |
| 66 | $jetpack_can_be_installed = current_user_can( 'manage_woocommerce' ) && current_user_can( 'install_plugins' ) && ! self::is_jetpack_connected(); |
| 67 | $jetpack_is_installed_and_current_user_connected = self::is_current_user_connected(); |
| 68 | |
| 69 | return $jetpack_can_be_installed || $jetpack_is_installed_and_current_user_connected; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Determines if site has any users connected to WordPress.com via JetPack |
| 74 | * |
| 75 | * @return bool |
| 76 | */ |
| 77 | private static function is_jetpack_connected() { |
| 78 | if ( class_exists( '\Automattic\Jetpack\Connection\Manager' ) && method_exists( '\Automattic\Jetpack\Connection\Manager', 'is_active' ) ) { |
| 79 | $connection = new Manager(); |
| 80 | return $connection->is_active(); |
| 81 | } |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Determines if the current user is connected to Jetpack. |
| 87 | * |
| 88 | * @return bool |
| 89 | */ |
| 90 | private static function is_current_user_connected() { |
| 91 | if ( class_exists( '\Automattic\Jetpack\Connection\Manager' ) && method_exists( '\Automattic\Jetpack\Connection\Manager', 'is_user_connected' ) ) { |
| 92 | $connection = new Manager(); |
| 93 | return $connection->is_connection_owner(); |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Action URL. |
| 100 | * |
| 101 | * @return string |
| 102 | */ |
| 103 | public function get_action_url() { |
| 104 | return admin_url( 'admin.php?page=wc-admin&mobileAppModal=true' ); |
| 105 | } |
| 106 | } |
| 107 |