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
CustomizeStore.php
148 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks; |
| 4 | |
| 5 | use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task; |
| 6 | use WP_Post; |
| 7 | |
| 8 | /** |
| 9 | * Customize Your Store Task |
| 10 | * |
| 11 | * @internal |
| 12 | */ |
| 13 | class CustomizeStore extends Task { |
| 14 | /** |
| 15 | * Constructor |
| 16 | * |
| 17 | * @param TaskList $task_list Parent task list. |
| 18 | */ |
| 19 | public function __construct( $task_list ) { |
| 20 | parent::__construct( $task_list ); |
| 21 | |
| 22 | add_action( 'save_post_wp_global_styles', array( $this, 'mark_task_as_complete_block_theme' ), 10, 3 ); |
| 23 | add_action( 'save_post_wp_template', array( $this, 'mark_task_as_complete_block_theme' ), 10, 3 ); |
| 24 | add_action( 'save_post_wp_template_part', array( $this, 'mark_task_as_complete_block_theme' ), 10, 3 ); |
| 25 | add_action( 'customize_save_after', array( $this, 'mark_task_as_complete_classic_theme' ) ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Mark the CYS task as complete whenever the user updates their global styles. |
| 30 | * |
| 31 | * @param int $post_id Post ID. |
| 32 | * @param WP_Post $post Post object. |
| 33 | * @param bool $update Whether this is an existing post being updated. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function mark_task_as_complete_block_theme( $post_id, $post, $update ) { |
| 38 | if ( $post instanceof WP_Post ) { |
| 39 | $is_cys_complete = $this->has_custom_global_styles( $post ) || $this->has_custom_template( $post ); |
| 40 | |
| 41 | if ( $is_cys_complete ) { |
| 42 | update_option( 'woocommerce_admin_customize_store_completed', 'yes' ); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Mark the CYS task as complete whenever the user saves the customizer changes. |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | public function mark_task_as_complete_classic_theme() { |
| 53 | update_option( 'woocommerce_admin_customize_store_completed', 'yes' ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * ID. |
| 58 | * |
| 59 | * @return string |
| 60 | */ |
| 61 | public function get_id() { |
| 62 | return 'customize-store'; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Title. |
| 67 | * |
| 68 | * @return string |
| 69 | */ |
| 70 | public function get_title() { |
| 71 | return __( 'Customize your store ', 'woocommerce' ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Content. |
| 76 | * |
| 77 | * @return string |
| 78 | */ |
| 79 | public function get_content() { |
| 80 | return ''; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Time. |
| 85 | * |
| 86 | * @return string |
| 87 | */ |
| 88 | public function get_time() { |
| 89 | return ''; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Task completion. |
| 94 | * |
| 95 | * @return bool |
| 96 | */ |
| 97 | public function is_complete() { |
| 98 | return get_option( 'woocommerce_admin_customize_store_completed' ) === 'yes'; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Task visibility. |
| 103 | * |
| 104 | * @return bool |
| 105 | */ |
| 106 | public function can_view() { |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Action URL. |
| 112 | * |
| 113 | * @return string |
| 114 | */ |
| 115 | public function get_action_url() { |
| 116 | return admin_url( 'admin.php?page=wc-admin&path=%2Fcustomize-store' ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Checks if the post has custom global styles stored (if it is different from the default global styles). |
| 121 | * |
| 122 | * @param WP_Post $post The post object. |
| 123 | * @return bool |
| 124 | */ |
| 125 | private function has_custom_global_styles( WP_Post $post ) { |
| 126 | $required_keys = array( 'version', 'isGlobalStylesUserThemeJSON' ); |
| 127 | |
| 128 | $json_post_content = json_decode( $post->post_content, true ); |
| 129 | if ( is_null( $json_post_content ) ) { |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | $post_content_keys = array_keys( $json_post_content ); |
| 134 | |
| 135 | return ! empty( array_diff( $post_content_keys, $required_keys ) ) || ! empty( array_diff( $required_keys, $post_content_keys ) ); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Checks if the post is a template or a template part. |
| 140 | * |
| 141 | * @param WP_Post $post The post object. |
| 142 | * @return bool Whether the post is a template or a template part. |
| 143 | */ |
| 144 | private function has_custom_template( WP_Post $post ) { |
| 145 | return in_array( $post->post_type, array( 'wp_template', 'wp_template_part' ), true ); |
| 146 | } |
| 147 | } |
| 148 |