@@ -14,68 +14,68 @@ |
||
| 14 | 14 | * @version 3.0.0 |
| 15 | 15 | */ |
| 16 | 16 | interface WC_Shipping_Zone_Data_Store_Interface { |
| 17 | - /** |
|
| 18 | - * Get a list of shipping methods for a specific zone. |
|
| 19 | - * |
|
| 20 | - * @param int $zone_id Zone ID. |
|
| 21 | - * @param bool $enabled_only True to request enabled methods only. |
|
| 22 | - * @return array Array of objects containing method_id, method_order, instance_id, is_enabled |
|
| 23 | - */ |
|
| 24 | - public function get_methods( $zone_id, $enabled_only ); |
|
| 17 | + /** |
|
| 18 | + * Get a list of shipping methods for a specific zone. |
|
| 19 | + * |
|
| 20 | + * @param int $zone_id Zone ID. |
|
| 21 | + * @param bool $enabled_only True to request enabled methods only. |
|
| 22 | + * @return array Array of objects containing method_id, method_order, instance_id, is_enabled |
|
| 23 | + */ |
|
| 24 | + public function get_methods( $zone_id, $enabled_only ); |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Get count of methods for a zone. |
|
| 28 | - * |
|
| 29 | - * @param int $zone_id Zone ID. |
|
| 30 | - * @return int Method Count |
|
| 31 | - */ |
|
| 32 | - public function get_method_count( $zone_id ); |
|
| 26 | + /** |
|
| 27 | + * Get count of methods for a zone. |
|
| 28 | + * |
|
| 29 | + * @param int $zone_id Zone ID. |
|
| 30 | + * @return int Method Count |
|
| 31 | + */ |
|
| 32 | + public function get_method_count( $zone_id ); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Add a shipping method to a zone. |
|
| 36 | - * |
|
| 37 | - * @param int $zone_id Zone ID. |
|
| 38 | - * @param string $type Method Type/ID. |
|
| 39 | - * @param int $order Method Order ID. |
|
| 40 | - * @return int Instance ID |
|
| 41 | - */ |
|
| 42 | - public function add_method( $zone_id, $type, $order ); |
|
| 34 | + /** |
|
| 35 | + * Add a shipping method to a zone. |
|
| 36 | + * |
|
| 37 | + * @param int $zone_id Zone ID. |
|
| 38 | + * @param string $type Method Type/ID. |
|
| 39 | + * @param int $order Method Order ID. |
|
| 40 | + * @return int Instance ID |
|
| 41 | + */ |
|
| 42 | + public function add_method( $zone_id, $type, $order ); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Delete a method instance. |
|
| 46 | - * |
|
| 47 | - * @param int $instance_id Instance ID. |
|
| 48 | - */ |
|
| 49 | - public function delete_method( $instance_id ); |
|
| 44 | + /** |
|
| 45 | + * Delete a method instance. |
|
| 46 | + * |
|
| 47 | + * @param int $instance_id Instance ID. |
|
| 48 | + */ |
|
| 49 | + public function delete_method( $instance_id ); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Get a shipping zone method instance. |
|
| 53 | - * |
|
| 54 | - * @param int $instance_id Instance ID. |
|
| 55 | - * @return object |
|
| 56 | - */ |
|
| 57 | - public function get_method( $instance_id ); |
|
| 51 | + /** |
|
| 52 | + * Get a shipping zone method instance. |
|
| 53 | + * |
|
| 54 | + * @param int $instance_id Instance ID. |
|
| 55 | + * @return object |
|
| 56 | + */ |
|
| 57 | + public function get_method( $instance_id ); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Find a matching zone ID for a given package. |
|
| 61 | - * |
|
| 62 | - * @param object $package Zone package object. |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public function get_zone_id_from_package( $package ); |
|
| 59 | + /** |
|
| 60 | + * Find a matching zone ID for a given package. |
|
| 61 | + * |
|
| 62 | + * @param object $package Zone package object. |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public function get_zone_id_from_package( $package ); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Return an ordered list of zones. |
|
| 69 | - * |
|
| 70 | - * @return array An array of objects containing a zone_id, zone_name, and zone_order. |
|
| 71 | - */ |
|
| 72 | - public function get_zones(); |
|
| 67 | + /** |
|
| 68 | + * Return an ordered list of zones. |
|
| 69 | + * |
|
| 70 | + * @return array An array of objects containing a zone_id, zone_name, and zone_order. |
|
| 71 | + */ |
|
| 72 | + public function get_zones(); |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Return a zone ID from an instance ID. |
|
| 76 | - * |
|
| 77 | - * @param int $id Instance ID. |
|
| 78 | - * @return int |
|
| 79 | - */ |
|
| 80 | - public function get_zone_id_by_instance_id( $id ); |
|
| 74 | + /** |
|
| 75 | + * Return a zone ID from an instance ID. |
|
| 76 | + * |
|
| 77 | + * @param int $id Instance ID. |
|
| 78 | + * @return int |
|
| 79 | + */ |
|
| 80 | + public function get_zone_id_by_instance_id( $id ); |
|
| 81 | 81 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param bool $enabled_only True to request enabled methods only. |
| 22 | 22 | * @return array Array of objects containing method_id, method_order, instance_id, is_enabled |
| 23 | 23 | */ |
| 24 | - public function get_methods( $zone_id, $enabled_only ); |
|
| 24 | + public function get_methods($zone_id, $enabled_only); |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Get count of methods for a zone. |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param int $zone_id Zone ID. |
| 30 | 30 | * @return int Method Count |
| 31 | 31 | */ |
| 32 | - public function get_method_count( $zone_id ); |
|
| 32 | + public function get_method_count($zone_id); |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Add a shipping method to a zone. |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | * @param int $order Method Order ID. |
| 40 | 40 | * @return int Instance ID |
| 41 | 41 | */ |
| 42 | - public function add_method( $zone_id, $type, $order ); |
|
| 42 | + public function add_method($zone_id, $type, $order); |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * Delete a method instance. |
| 46 | 46 | * |
| 47 | 47 | * @param int $instance_id Instance ID. |
| 48 | 48 | */ |
| 49 | - public function delete_method( $instance_id ); |
|
| 49 | + public function delete_method($instance_id); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Get a shipping zone method instance. |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param int $instance_id Instance ID. |
| 55 | 55 | * @return object |
| 56 | 56 | */ |
| 57 | - public function get_method( $instance_id ); |
|
| 57 | + public function get_method($instance_id); |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Find a matching zone ID for a given package. |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param object $package Zone package object. |
| 63 | 63 | * @return int |
| 64 | 64 | */ |
| 65 | - public function get_zone_id_from_package( $package ); |
|
| 65 | + public function get_zone_id_from_package($package); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Return an ordered list of zones. |
@@ -77,5 +77,5 @@ discard block |
||
| 77 | 77 | * @param int $id Instance ID. |
| 78 | 78 | * @return int |
| 79 | 79 | */ |
| 80 | - public function get_zone_id_by_instance_id( $id ); |
|
| 80 | + public function get_zone_id_by_instance_id($id); |
|
| 81 | 81 | } |
@@ -14,66 +14,66 @@ |
||
| 14 | 14 | * @version 3.0.0 |
| 15 | 15 | */ |
| 16 | 16 | interface WC_Product_Variable_Data_Store_Interface { |
| 17 | - /** |
|
| 18 | - * Does a child have a weight set? |
|
| 19 | - * |
|
| 20 | - * @param WC_Product $product Product object. |
|
| 21 | - * @return boolean |
|
| 22 | - */ |
|
| 23 | - public function child_has_weight( $product ); |
|
| 17 | + /** |
|
| 18 | + * Does a child have a weight set? |
|
| 19 | + * |
|
| 20 | + * @param WC_Product $product Product object. |
|
| 21 | + * @return boolean |
|
| 22 | + */ |
|
| 23 | + public function child_has_weight( $product ); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Does a child have dimensions set? |
|
| 27 | - * |
|
| 28 | - * @param WC_Product $product Product object. |
|
| 29 | - * @return boolean |
|
| 30 | - */ |
|
| 31 | - public function child_has_dimensions( $product ); |
|
| 25 | + /** |
|
| 26 | + * Does a child have dimensions set? |
|
| 27 | + * |
|
| 28 | + * @param WC_Product $product Product object. |
|
| 29 | + * @return boolean |
|
| 30 | + */ |
|
| 31 | + public function child_has_dimensions( $product ); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Is a child in stock? |
|
| 35 | - * |
|
| 36 | - * @param WC_Product $product Product object. |
|
| 37 | - * @return boolean |
|
| 38 | - */ |
|
| 39 | - public function child_is_in_stock( $product ); |
|
| 33 | + /** |
|
| 34 | + * Is a child in stock? |
|
| 35 | + * |
|
| 36 | + * @param WC_Product $product Product object. |
|
| 37 | + * @return boolean |
|
| 38 | + */ |
|
| 39 | + public function child_is_in_stock( $product ); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Syncs all variation names if the parent name is changed. |
|
| 43 | - * |
|
| 44 | - * @param WC_Product $product Product object. |
|
| 45 | - * @param string $previous_name Previous name. |
|
| 46 | - * @param string $new_name New name. |
|
| 47 | - */ |
|
| 48 | - public function sync_variation_names( &$product, $previous_name = '', $new_name = '' ); |
|
| 41 | + /** |
|
| 42 | + * Syncs all variation names if the parent name is changed. |
|
| 43 | + * |
|
| 44 | + * @param WC_Product $product Product object. |
|
| 45 | + * @param string $previous_name Previous name. |
|
| 46 | + * @param string $new_name New name. |
|
| 47 | + */ |
|
| 48 | + public function sync_variation_names( &$product, $previous_name = '', $new_name = '' ); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Stock managed at the parent level - update children being managed by this product. |
|
| 52 | - * This sync function syncs downwards (from parent to child) when the variable product is saved. |
|
| 53 | - * |
|
| 54 | - * @param WC_Product $product Product object. |
|
| 55 | - */ |
|
| 56 | - public function sync_managed_variation_stock_status( &$product ); |
|
| 50 | + /** |
|
| 51 | + * Stock managed at the parent level - update children being managed by this product. |
|
| 52 | + * This sync function syncs downwards (from parent to child) when the variable product is saved. |
|
| 53 | + * |
|
| 54 | + * @param WC_Product $product Product object. |
|
| 55 | + */ |
|
| 56 | + public function sync_managed_variation_stock_status( &$product ); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Sync variable product prices with children. |
|
| 60 | - * |
|
| 61 | - * @param WC_Product|int $product Product object or ID. |
|
| 62 | - */ |
|
| 63 | - public function sync_price( &$product ); |
|
| 58 | + /** |
|
| 59 | + * Sync variable product prices with children. |
|
| 60 | + * |
|
| 61 | + * @param WC_Product|int $product Product object or ID. |
|
| 62 | + */ |
|
| 63 | + public function sync_price( &$product ); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Delete variations of a product. |
|
| 67 | - * |
|
| 68 | - * @param int $product_id Product ID. |
|
| 69 | - * @param bool $force_delete False to trash. |
|
| 70 | - */ |
|
| 71 | - public function delete_variations( $product_id, $force_delete = false ); |
|
| 65 | + /** |
|
| 66 | + * Delete variations of a product. |
|
| 67 | + * |
|
| 68 | + * @param int $product_id Product ID. |
|
| 69 | + * @param bool $force_delete False to trash. |
|
| 70 | + */ |
|
| 71 | + public function delete_variations( $product_id, $force_delete = false ); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Untrash variations. |
|
| 75 | - * |
|
| 76 | - * @param int $product_id Product ID. |
|
| 77 | - */ |
|
| 78 | - public function untrash_variations( $product_id ); |
|
| 73 | + /** |
|
| 74 | + * Untrash variations. |
|
| 75 | + * |
|
| 76 | + * @param int $product_id Product ID. |
|
| 77 | + */ |
|
| 78 | + public function untrash_variations( $product_id ); |
|
| 79 | 79 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param WC_Product $product Product object. |
| 21 | 21 | * @return boolean |
| 22 | 22 | */ |
| 23 | - public function child_has_weight( $product ); |
|
| 23 | + public function child_has_weight($product); |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Does a child have dimensions set? |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param WC_Product $product Product object. |
| 29 | 29 | * @return boolean |
| 30 | 30 | */ |
| 31 | - public function child_has_dimensions( $product ); |
|
| 31 | + public function child_has_dimensions($product); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Is a child in stock? |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param WC_Product $product Product object. |
| 37 | 37 | * @return boolean |
| 38 | 38 | */ |
| 39 | - public function child_is_in_stock( $product ); |
|
| 39 | + public function child_is_in_stock($product); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Syncs all variation names if the parent name is changed. |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param string $previous_name Previous name. |
| 46 | 46 | * @param string $new_name New name. |
| 47 | 47 | */ |
| 48 | - public function sync_variation_names( &$product, $previous_name = '', $new_name = '' ); |
|
| 48 | + public function sync_variation_names(&$product, $previous_name = '', $new_name = ''); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Stock managed at the parent level - update children being managed by this product. |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @param WC_Product $product Product object. |
| 55 | 55 | */ |
| 56 | - public function sync_managed_variation_stock_status( &$product ); |
|
| 56 | + public function sync_managed_variation_stock_status(&$product); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Sync variable product prices with children. |
| 60 | 60 | * |
| 61 | 61 | * @param WC_Product|int $product Product object or ID. |
| 62 | 62 | */ |
| 63 | - public function sync_price( &$product ); |
|
| 63 | + public function sync_price(&$product); |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Delete variations of a product. |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | * @param int $product_id Product ID. |
| 69 | 69 | * @param bool $force_delete False to trash. |
| 70 | 70 | */ |
| 71 | - public function delete_variations( $product_id, $force_delete = false ); |
|
| 71 | + public function delete_variations($product_id, $force_delete = false); |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Untrash variations. |
| 75 | 75 | * |
| 76 | 76 | * @param int $product_id Product ID. |
| 77 | 77 | */ |
| 78 | - public function untrash_variations( $product_id ); |
|
| 78 | + public function untrash_variations($product_id); |
|
| 79 | 79 | } |
@@ -11,22 +11,22 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | interface WC_Webhook_Data_Store_Interface { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Get API version number. |
|
| 16 | - * |
|
| 17 | - * @since 3.2.0 |
|
| 18 | - * @param string $api_version REST API version. |
|
| 19 | - * @return int |
|
| 20 | - */ |
|
| 21 | - public function get_api_version_number( $api_version ); |
|
| 14 | + /** |
|
| 15 | + * Get API version number. |
|
| 16 | + * |
|
| 17 | + * @since 3.2.0 |
|
| 18 | + * @param string $api_version REST API version. |
|
| 19 | + * @return int |
|
| 20 | + */ |
|
| 21 | + public function get_api_version_number( $api_version ); |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get all webhooks IDs. |
|
| 25 | - * |
|
| 26 | - * @since 3.2.0 |
|
| 27 | - * @throws InvalidArgumentException If a $status value is passed in that is not in the known wc_get_webhook_statuses() keys. |
|
| 28 | - * @param string $status Optional - status to filter results by. Must be a key in return value of @see wc_get_webhook_statuses(). @since 3.6.0. |
|
| 29 | - * @return int[] |
|
| 30 | - */ |
|
| 31 | - public function get_webhooks_ids( $status = '' ); |
|
| 23 | + /** |
|
| 24 | + * Get all webhooks IDs. |
|
| 25 | + * |
|
| 26 | + * @since 3.2.0 |
|
| 27 | + * @throws InvalidArgumentException If a $status value is passed in that is not in the known wc_get_webhook_statuses() keys. |
|
| 28 | + * @param string $status Optional - status to filter results by. Must be a key in return value of @see wc_get_webhook_statuses(). @since 3.6.0. |
|
| 29 | + * @return int[] |
|
| 30 | + */ |
|
| 31 | + public function get_webhooks_ids( $status = '' ); |
|
| 32 | 32 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param string $api_version REST API version. |
| 19 | 19 | * @return int |
| 20 | 20 | */ |
| 21 | - public function get_api_version_number( $api_version ); |
|
| 21 | + public function get_api_version_number($api_version); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Get all webhooks IDs. |
@@ -28,5 +28,5 @@ discard block |
||
| 28 | 28 | * @param string $status Optional - status to filter results by. Must be a key in return value of @see wc_get_webhook_statuses(). @since 3.6.0. |
| 29 | 29 | * @return int[] |
| 30 | 30 | */ |
| 31 | - public function get_webhooks_ids( $status = '' ); |
|
| 31 | + public function get_webhooks_ids($status = ''); |
|
| 32 | 32 | } |
@@ -15,36 +15,36 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface WC_Abstract_Order_Data_Store_Interface { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Read order items of a specific type from the database for this order. |
|
| 20 | - * |
|
| 21 | - * @param WC_Order $order Order object. |
|
| 22 | - * @param string $type Order item type. |
|
| 23 | - * @return array |
|
| 24 | - */ |
|
| 25 | - public function read_items( $order, $type ); |
|
| 18 | + /** |
|
| 19 | + * Read order items of a specific type from the database for this order. |
|
| 20 | + * |
|
| 21 | + * @param WC_Order $order Order object. |
|
| 22 | + * @param string $type Order item type. |
|
| 23 | + * @return array |
|
| 24 | + */ |
|
| 25 | + public function read_items( $order, $type ); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Remove all line items (products, coupons, shipping, taxes) from the order. |
|
| 29 | - * |
|
| 30 | - * @param WC_Order $order Order object. |
|
| 31 | - * @param string $type Order item type. Default null. |
|
| 32 | - */ |
|
| 33 | - public function delete_items( $order, $type = null ); |
|
| 27 | + /** |
|
| 28 | + * Remove all line items (products, coupons, shipping, taxes) from the order. |
|
| 29 | + * |
|
| 30 | + * @param WC_Order $order Order object. |
|
| 31 | + * @param string $type Order item type. Default null. |
|
| 32 | + */ |
|
| 33 | + public function delete_items( $order, $type = null ); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get token ids for an order. |
|
| 37 | - * |
|
| 38 | - * @param WC_Order $order Order object. |
|
| 39 | - * @return array |
|
| 40 | - */ |
|
| 41 | - public function get_payment_token_ids( $order ); |
|
| 35 | + /** |
|
| 36 | + * Get token ids for an order. |
|
| 37 | + * |
|
| 38 | + * @param WC_Order $order Order object. |
|
| 39 | + * @return array |
|
| 40 | + */ |
|
| 41 | + public function get_payment_token_ids( $order ); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Update token ids for an order. |
|
| 45 | - * |
|
| 46 | - * @param WC_Order $order Order object. |
|
| 47 | - * @param array $token_ids Token IDs. |
|
| 48 | - */ |
|
| 49 | - public function update_payment_token_ids( $order, $token_ids ); |
|
| 43 | + /** |
|
| 44 | + * Update token ids for an order. |
|
| 45 | + * |
|
| 46 | + * @param WC_Order $order Order object. |
|
| 47 | + * @param array $token_ids Token IDs. |
|
| 48 | + */ |
|
| 49 | + public function update_payment_token_ids( $order, $token_ids ); |
|
| 50 | 50 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param string $type Order item type. |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public function read_items( $order, $type ); |
|
| 25 | + public function read_items($order, $type); |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Remove all line items (products, coupons, shipping, taxes) from the order. |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param WC_Order $order Order object. |
| 31 | 31 | * @param string $type Order item type. Default null. |
| 32 | 32 | */ |
| 33 | - public function delete_items( $order, $type = null ); |
|
| 33 | + public function delete_items($order, $type = null); |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Get token ids for an order. |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param WC_Order $order Order object. |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | - public function get_payment_token_ids( $order ); |
|
| 41 | + public function get_payment_token_ids($order); |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Update token ids for an order. |
@@ -46,5 +46,5 @@ discard block |
||
| 46 | 46 | * @param WC_Order $order Order object. |
| 47 | 47 | * @param array $token_ids Token IDs. |
| 48 | 48 | */ |
| 49 | - public function update_payment_token_ids( $order, $token_ids ); |
|
| 49 | + public function update_payment_token_ids($order, $token_ids); |
|
| 50 | 50 | } |
@@ -14,124 +14,124 @@ |
||
| 14 | 14 | * @version 3.0.0 |
| 15 | 15 | */ |
| 16 | 16 | interface WC_Order_Data_Store_Interface { |
| 17 | - /** |
|
| 18 | - * Get amount already refunded. |
|
| 19 | - * |
|
| 20 | - * @param WC_Order $order Order object. |
|
| 21 | - * @return float |
|
| 22 | - */ |
|
| 23 | - public function get_total_refunded( $order ); |
|
| 17 | + /** |
|
| 18 | + * Get amount already refunded. |
|
| 19 | + * |
|
| 20 | + * @param WC_Order $order Order object. |
|
| 21 | + * @return float |
|
| 22 | + */ |
|
| 23 | + public function get_total_refunded( $order ); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Get the total tax refunded. |
|
| 27 | - * |
|
| 28 | - * @param WC_Order $order Order object. |
|
| 29 | - * @return float |
|
| 30 | - */ |
|
| 31 | - public function get_total_tax_refunded( $order ); |
|
| 25 | + /** |
|
| 26 | + * Get the total tax refunded. |
|
| 27 | + * |
|
| 28 | + * @param WC_Order $order Order object. |
|
| 29 | + * @return float |
|
| 30 | + */ |
|
| 31 | + public function get_total_tax_refunded( $order ); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Get the total shipping refunded. |
|
| 35 | - * |
|
| 36 | - * @param WC_Order $order Order object. |
|
| 37 | - * @return float |
|
| 38 | - */ |
|
| 39 | - public function get_total_shipping_refunded( $order ); |
|
| 33 | + /** |
|
| 34 | + * Get the total shipping refunded. |
|
| 35 | + * |
|
| 36 | + * @param WC_Order $order Order object. |
|
| 37 | + * @return float |
|
| 38 | + */ |
|
| 39 | + public function get_total_shipping_refunded( $order ); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Finds an Order ID based on an order key. |
|
| 43 | - * |
|
| 44 | - * @param string $order_key An order key has generated by. |
|
| 45 | - * @return int The ID of an order, or 0 if the order could not be found. |
|
| 46 | - */ |
|
| 47 | - public function get_order_id_by_order_key( $order_key ); |
|
| 41 | + /** |
|
| 42 | + * Finds an Order ID based on an order key. |
|
| 43 | + * |
|
| 44 | + * @param string $order_key An order key has generated by. |
|
| 45 | + * @return int The ID of an order, or 0 if the order could not be found. |
|
| 46 | + */ |
|
| 47 | + public function get_order_id_by_order_key( $order_key ); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Return count of orders with a specific status. |
|
| 51 | - * |
|
| 52 | - * @param string $status Order status. |
|
| 53 | - * @return int |
|
| 54 | - */ |
|
| 55 | - public function get_order_count( $status ); |
|
| 49 | + /** |
|
| 50 | + * Return count of orders with a specific status. |
|
| 51 | + * |
|
| 52 | + * @param string $status Order status. |
|
| 53 | + * @return int |
|
| 54 | + */ |
|
| 55 | + public function get_order_count( $status ); |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Get all orders matching the passed in args. |
|
| 59 | - * |
|
| 60 | - * @see wc_get_orders() |
|
| 61 | - * @param array $args Arguments. |
|
| 62 | - * @return array of orders |
|
| 63 | - */ |
|
| 64 | - public function get_orders( $args = array() ); |
|
| 57 | + /** |
|
| 58 | + * Get all orders matching the passed in args. |
|
| 59 | + * |
|
| 60 | + * @see wc_get_orders() |
|
| 61 | + * @param array $args Arguments. |
|
| 62 | + * @return array of orders |
|
| 63 | + */ |
|
| 64 | + public function get_orders( $args = array() ); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Get unpaid orders after a certain date, |
|
| 68 | - * |
|
| 69 | - * @param int $date timestamp. |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - public function get_unpaid_orders( $date ); |
|
| 66 | + /** |
|
| 67 | + * Get unpaid orders after a certain date, |
|
| 68 | + * |
|
| 69 | + * @param int $date timestamp. |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + public function get_unpaid_orders( $date ); |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Search order data for a term and return ids. |
|
| 76 | - * |
|
| 77 | - * @param string $term Term name. |
|
| 78 | - * @return array of ids |
|
| 79 | - */ |
|
| 80 | - public function search_orders( $term ); |
|
| 74 | + /** |
|
| 75 | + * Search order data for a term and return ids. |
|
| 76 | + * |
|
| 77 | + * @param string $term Term name. |
|
| 78 | + * @return array of ids |
|
| 79 | + */ |
|
| 80 | + public function search_orders( $term ); |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Gets information about whether permissions were generated yet. |
|
| 84 | - * |
|
| 85 | - * @param WC_Order $order Order object. |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - public function get_download_permissions_granted( $order ); |
|
| 82 | + /** |
|
| 83 | + * Gets information about whether permissions were generated yet. |
|
| 84 | + * |
|
| 85 | + * @param WC_Order $order Order object. |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + public function get_download_permissions_granted( $order ); |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Stores information about whether permissions were generated yet. |
|
| 92 | - * |
|
| 93 | - * @param WC_Order $order Order object. |
|
| 94 | - * @param bool $set If should set. |
|
| 95 | - */ |
|
| 96 | - public function set_download_permissions_granted( $order, $set ); |
|
| 90 | + /** |
|
| 91 | + * Stores information about whether permissions were generated yet. |
|
| 92 | + * |
|
| 93 | + * @param WC_Order $order Order object. |
|
| 94 | + * @param bool $set If should set. |
|
| 95 | + */ |
|
| 96 | + public function set_download_permissions_granted( $order, $set ); |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Gets information about whether sales were recorded. |
|
| 100 | - * |
|
| 101 | - * @param WC_Order $order Order object. |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - public function get_recorded_sales( $order ); |
|
| 98 | + /** |
|
| 99 | + * Gets information about whether sales were recorded. |
|
| 100 | + * |
|
| 101 | + * @param WC_Order $order Order object. |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + public function get_recorded_sales( $order ); |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Stores information about whether sales were recorded. |
|
| 108 | - * |
|
| 109 | - * @param WC_Order $order Order object. |
|
| 110 | - * @param bool $set If should set. |
|
| 111 | - */ |
|
| 112 | - public function set_recorded_sales( $order, $set ); |
|
| 106 | + /** |
|
| 107 | + * Stores information about whether sales were recorded. |
|
| 108 | + * |
|
| 109 | + * @param WC_Order $order Order object. |
|
| 110 | + * @param bool $set If should set. |
|
| 111 | + */ |
|
| 112 | + public function set_recorded_sales( $order, $set ); |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Gets information about whether coupon counts were updated. |
|
| 116 | - * |
|
| 117 | - * @param WC_Order $order Order object. |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function get_recorded_coupon_usage_counts( $order ); |
|
| 114 | + /** |
|
| 115 | + * Gets information about whether coupon counts were updated. |
|
| 116 | + * |
|
| 117 | + * @param WC_Order $order Order object. |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function get_recorded_coupon_usage_counts( $order ); |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Stores information about whether coupon counts were updated. |
|
| 124 | - * |
|
| 125 | - * @param WC_Order $order Order object. |
|
| 126 | - * @param bool $set If should set. |
|
| 127 | - */ |
|
| 128 | - public function set_recorded_coupon_usage_counts( $order, $set ); |
|
| 122 | + /** |
|
| 123 | + * Stores information about whether coupon counts were updated. |
|
| 124 | + * |
|
| 125 | + * @param WC_Order $order Order object. |
|
| 126 | + * @param bool $set If should set. |
|
| 127 | + */ |
|
| 128 | + public function set_recorded_coupon_usage_counts( $order, $set ); |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Get the order type based on Order ID. |
|
| 132 | - * |
|
| 133 | - * @param int $order_id Order ID. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_order_type( $order_id ); |
|
| 130 | + /** |
|
| 131 | + * Get the order type based on Order ID. |
|
| 132 | + * |
|
| 133 | + * @param int $order_id Order ID. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_order_type( $order_id ); |
|
| 137 | 137 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param WC_Order $order Order object. |
| 21 | 21 | * @return float |
| 22 | 22 | */ |
| 23 | - public function get_total_refunded( $order ); |
|
| 23 | + public function get_total_refunded($order); |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Get the total tax refunded. |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param WC_Order $order Order object. |
| 29 | 29 | * @return float |
| 30 | 30 | */ |
| 31 | - public function get_total_tax_refunded( $order ); |
|
| 31 | + public function get_total_tax_refunded($order); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Get the total shipping refunded. |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param WC_Order $order Order object. |
| 37 | 37 | * @return float |
| 38 | 38 | */ |
| 39 | - public function get_total_shipping_refunded( $order ); |
|
| 39 | + public function get_total_shipping_refunded($order); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Finds an Order ID based on an order key. |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param string $order_key An order key has generated by. |
| 45 | 45 | * @return int The ID of an order, or 0 if the order could not be found. |
| 46 | 46 | */ |
| 47 | - public function get_order_id_by_order_key( $order_key ); |
|
| 47 | + public function get_order_id_by_order_key($order_key); |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Return count of orders with a specific status. |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param string $status Order status. |
| 53 | 53 | * @return int |
| 54 | 54 | */ |
| 55 | - public function get_order_count( $status ); |
|
| 55 | + public function get_order_count($status); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Get all orders matching the passed in args. |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param array $args Arguments. |
| 62 | 62 | * @return array of orders |
| 63 | 63 | */ |
| 64 | - public function get_orders( $args = array() ); |
|
| 64 | + public function get_orders($args = array()); |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Get unpaid orders after a certain date, |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param int $date timestamp. |
| 70 | 70 | * @return array |
| 71 | 71 | */ |
| 72 | - public function get_unpaid_orders( $date ); |
|
| 72 | + public function get_unpaid_orders($date); |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Search order data for a term and return ids. |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @param string $term Term name. |
| 78 | 78 | * @return array of ids |
| 79 | 79 | */ |
| 80 | - public function search_orders( $term ); |
|
| 80 | + public function search_orders($term); |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Gets information about whether permissions were generated yet. |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param WC_Order $order Order object. |
| 86 | 86 | * @return bool |
| 87 | 87 | */ |
| 88 | - public function get_download_permissions_granted( $order ); |
|
| 88 | + public function get_download_permissions_granted($order); |
|
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * Stores information about whether permissions were generated yet. |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param WC_Order $order Order object. |
| 94 | 94 | * @param bool $set If should set. |
| 95 | 95 | */ |
| 96 | - public function set_download_permissions_granted( $order, $set ); |
|
| 96 | + public function set_download_permissions_granted($order, $set); |
|
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * Gets information about whether sales were recorded. |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param WC_Order $order Order object. |
| 102 | 102 | * @return bool |
| 103 | 103 | */ |
| 104 | - public function get_recorded_sales( $order ); |
|
| 104 | + public function get_recorded_sales($order); |
|
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * Stores information about whether sales were recorded. |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param WC_Order $order Order object. |
| 110 | 110 | * @param bool $set If should set. |
| 111 | 111 | */ |
| 112 | - public function set_recorded_sales( $order, $set ); |
|
| 112 | + public function set_recorded_sales($order, $set); |
|
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * Gets information about whether coupon counts were updated. |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param WC_Order $order Order object. |
| 118 | 118 | * @return bool |
| 119 | 119 | */ |
| 120 | - public function get_recorded_coupon_usage_counts( $order ); |
|
| 120 | + public function get_recorded_coupon_usage_counts($order); |
|
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Stores information about whether coupon counts were updated. |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param WC_Order $order Order object. |
| 126 | 126 | * @param bool $set If should set. |
| 127 | 127 | */ |
| 128 | - public function set_recorded_coupon_usage_counts( $order, $set ); |
|
| 128 | + public function set_recorded_coupon_usage_counts($order, $set); |
|
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * Get the order type based on Order ID. |
@@ -133,5 +133,5 @@ discard block |
||
| 133 | 133 | * @param int $order_id Order ID. |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function get_order_type( $order_id ); |
|
| 136 | + public function get_order_type($order_id); |
|
| 137 | 137 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use Automattic\Jetpack\Constants; |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly. |
|
| 11 | + exit; // Exit if accessed directly. |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -20,427 +20,427 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class WC_Log_Handler_File extends WC_Log_Handler { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Stores open file handles. |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $handles = array(); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * File size limit for log files in bytes. |
|
| 32 | - * |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - protected $log_size_limit; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Cache logs that could not be written. |
|
| 39 | - * |
|
| 40 | - * If a log is written too early in the request, pluggable functions may be unavailable. These |
|
| 41 | - * logs will be cached and written on 'plugins_loaded' action. |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - protected $cached_logs = array(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Constructor for the logger. |
|
| 49 | - * |
|
| 50 | - * @param int $log_size_limit Optional. Size limit for log files. Default 5mb. |
|
| 51 | - */ |
|
| 52 | - public function __construct( $log_size_limit = null ) { |
|
| 53 | - if ( null === $log_size_limit ) { |
|
| 54 | - $log_size_limit = 5 * 1024 * 1024; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $this->log_size_limit = apply_filters( 'woocommerce_log_file_size_limit', $log_size_limit ); |
|
| 58 | - |
|
| 59 | - add_action( 'plugins_loaded', array( $this, 'write_cached_logs' ) ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Destructor. |
|
| 64 | - * |
|
| 65 | - * Cleans up open file handles. |
|
| 66 | - */ |
|
| 67 | - public function __destruct() { |
|
| 68 | - foreach ( $this->handles as $handle ) { |
|
| 69 | - if ( is_resource( $handle ) ) { |
|
| 70 | - fclose( $handle ); // @codingStandardsIgnoreLine. |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Handle a log entry. |
|
| 77 | - * |
|
| 78 | - * @param int $timestamp Log timestamp. |
|
| 79 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 80 | - * @param string $message Log message. |
|
| 81 | - * @param array $context { |
|
| 82 | - * Additional information for log handlers. |
|
| 83 | - * |
|
| 84 | - * @type string $source Optional. Determines log file to write to. Default 'log'. |
|
| 85 | - * @type bool $_legacy Optional. Default false. True to use outdated log format |
|
| 86 | - * originally used in deprecated WC_Logger::add calls. |
|
| 87 | - * } |
|
| 88 | - * |
|
| 89 | - * @return bool False if value was not handled and true if value was handled. |
|
| 90 | - */ |
|
| 91 | - public function handle( $timestamp, $level, $message, $context ) { |
|
| 92 | - |
|
| 93 | - if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 94 | - $handle = $context['source']; |
|
| 95 | - } else { |
|
| 96 | - $handle = 'log'; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $entry = self::format_entry( $timestamp, $level, $message, $context ); |
|
| 100 | - |
|
| 101 | - return $this->add( $entry, $handle ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Builds a log entry text from timestamp, level and message. |
|
| 106 | - * |
|
| 107 | - * @param int $timestamp Log timestamp. |
|
| 108 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 109 | - * @param string $message Log message. |
|
| 110 | - * @param array $context Additional information for log handlers. |
|
| 111 | - * |
|
| 112 | - * @return string Formatted log entry. |
|
| 113 | - */ |
|
| 114 | - protected static function format_entry( $timestamp, $level, $message, $context ) { |
|
| 115 | - |
|
| 116 | - if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) { |
|
| 117 | - if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 118 | - $handle = $context['source']; |
|
| 119 | - } else { |
|
| 120 | - $handle = 'log'; |
|
| 121 | - } |
|
| 122 | - $message = apply_filters( 'woocommerce_logger_add_message', $message, $handle ); |
|
| 123 | - $time = date_i18n( 'm-d-Y @ H:i:s' ); |
|
| 124 | - $entry = "{$time} - {$message}"; |
|
| 125 | - } else { |
|
| 126 | - $entry = parent::format_entry( $timestamp, $level, $message, $context ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return $entry; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Open log file for writing. |
|
| 134 | - * |
|
| 135 | - * @param string $handle Log handle. |
|
| 136 | - * @param string $mode Optional. File mode. Default 'a'. |
|
| 137 | - * @return bool Success. |
|
| 138 | - */ |
|
| 139 | - protected function open( $handle, $mode = 'a' ) { |
|
| 140 | - if ( $this->is_open( $handle ) ) { |
|
| 141 | - return true; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $file = self::get_log_file_path( $handle ); |
|
| 145 | - |
|
| 146 | - if ( $file ) { |
|
| 147 | - if ( ! file_exists( $file ) ) { |
|
| 148 | - $temphandle = @fopen( $file, 'w+' ); // @codingStandardsIgnoreLine. |
|
| 149 | - if ( is_resource( $temphandle ) ) { |
|
| 150 | - @fclose( $temphandle ); // @codingStandardsIgnoreLine. |
|
| 151 | - |
|
| 152 | - if ( Constants::is_defined( 'FS_CHMOD_FILE' ) ) { |
|
| 153 | - @chmod( $file, FS_CHMOD_FILE ); // @codingStandardsIgnoreLine. |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $resource = @fopen( $file, $mode ); // @codingStandardsIgnoreLine. |
|
| 159 | - |
|
| 160 | - if ( $resource ) { |
|
| 161 | - $this->handles[ $handle ] = $resource; |
|
| 162 | - return true; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Check if a handle is open. |
|
| 171 | - * |
|
| 172 | - * @param string $handle Log handle. |
|
| 173 | - * @return bool True if $handle is open. |
|
| 174 | - */ |
|
| 175 | - protected function is_open( $handle ) { |
|
| 176 | - return array_key_exists( $handle, $this->handles ) && is_resource( $this->handles[ $handle ] ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Close a handle. |
|
| 181 | - * |
|
| 182 | - * @param string $handle Log handle. |
|
| 183 | - * @return bool success |
|
| 184 | - */ |
|
| 185 | - protected function close( $handle ) { |
|
| 186 | - $result = false; |
|
| 187 | - |
|
| 188 | - if ( $this->is_open( $handle ) ) { |
|
| 189 | - $result = fclose( $this->handles[ $handle ] ); // @codingStandardsIgnoreLine. |
|
| 190 | - unset( $this->handles[ $handle ] ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return $result; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Add a log entry to chosen file. |
|
| 198 | - * |
|
| 199 | - * @param string $entry Log entry text. |
|
| 200 | - * @param string $handle Log entry handle. |
|
| 201 | - * |
|
| 202 | - * @return bool True if write was successful. |
|
| 203 | - */ |
|
| 204 | - protected function add( $entry, $handle ) { |
|
| 205 | - $result = false; |
|
| 206 | - |
|
| 207 | - if ( $this->should_rotate( $handle ) ) { |
|
| 208 | - $this->log_rotate( $handle ); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ( $this->open( $handle ) && is_resource( $this->handles[ $handle ] ) ) { |
|
| 212 | - $result = fwrite( $this->handles[ $handle ], $entry . PHP_EOL ); // @codingStandardsIgnoreLine. |
|
| 213 | - } else { |
|
| 214 | - $this->cache_log( $entry, $handle ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return false !== $result; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Clear entries from chosen file. |
|
| 222 | - * |
|
| 223 | - * @param string $handle Log handle. |
|
| 224 | - * |
|
| 225 | - * @return bool |
|
| 226 | - */ |
|
| 227 | - public function clear( $handle ) { |
|
| 228 | - $result = false; |
|
| 229 | - |
|
| 230 | - // Close the file if it's already open. |
|
| 231 | - $this->close( $handle ); |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * $this->open( $handle, 'w' ) == Open the file for writing only. Place the file pointer at |
|
| 235 | - * the beginning of the file, and truncate the file to zero length. |
|
| 236 | - */ |
|
| 237 | - if ( $this->open( $handle, 'w' ) && is_resource( $this->handles[ $handle ] ) ) { |
|
| 238 | - $result = true; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - do_action( 'woocommerce_log_clear', $handle ); |
|
| 242 | - |
|
| 243 | - return $result; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Remove/delete the chosen file. |
|
| 248 | - * |
|
| 249 | - * @param string $handle Log handle. |
|
| 250 | - * |
|
| 251 | - * @return bool |
|
| 252 | - */ |
|
| 253 | - public function remove( $handle ) { |
|
| 254 | - $removed = false; |
|
| 255 | - $logs = $this->get_log_files(); |
|
| 256 | - $handle = sanitize_title( $handle ); |
|
| 257 | - |
|
| 258 | - if ( isset( $logs[ $handle ] ) && $logs[ $handle ] ) { |
|
| 259 | - $file = realpath( trailingslashit( WC_LOG_DIR ) . $logs[ $handle ] ); |
|
| 260 | - if ( 0 === stripos( $file, realpath( trailingslashit( WC_LOG_DIR ) ) ) && is_file( $file ) && is_writable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 261 | - $this->close( $file ); // Close first to be certain no processes keep it alive after it is unlinked. |
|
| 262 | - $removed = unlink( $file ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_unlink |
|
| 263 | - } |
|
| 264 | - do_action( 'woocommerce_log_remove', $handle, $removed ); |
|
| 265 | - } |
|
| 266 | - return $removed; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Check if log file should be rotated. |
|
| 271 | - * |
|
| 272 | - * Compares the size of the log file to determine whether it is over the size limit. |
|
| 273 | - * |
|
| 274 | - * @param string $handle Log handle. |
|
| 275 | - * @return bool True if if should be rotated. |
|
| 276 | - */ |
|
| 277 | - protected function should_rotate( $handle ) { |
|
| 278 | - $file = self::get_log_file_path( $handle ); |
|
| 279 | - if ( $file ) { |
|
| 280 | - if ( $this->is_open( $handle ) ) { |
|
| 281 | - $file_stat = fstat( $this->handles[ $handle ] ); |
|
| 282 | - return $file_stat['size'] > $this->log_size_limit; |
|
| 283 | - } elseif ( file_exists( $file ) ) { |
|
| 284 | - return filesize( $file ) > $this->log_size_limit; |
|
| 285 | - } else { |
|
| 286 | - return false; |
|
| 287 | - } |
|
| 288 | - } else { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Rotate log files. |
|
| 295 | - * |
|
| 296 | - * Logs are rotated by prepending '.x' to the '.log' suffix. |
|
| 297 | - * The current log plus 10 historical logs are maintained. |
|
| 298 | - * For example: |
|
| 299 | - * base.9.log -> [ REMOVED ] |
|
| 300 | - * base.8.log -> base.9.log |
|
| 301 | - * ... |
|
| 302 | - * base.0.log -> base.1.log |
|
| 303 | - * base.log -> base.0.log |
|
| 304 | - * |
|
| 305 | - * @param string $handle Log handle. |
|
| 306 | - */ |
|
| 307 | - protected function log_rotate( $handle ) { |
|
| 308 | - for ( $i = 8; $i >= 0; $i-- ) { |
|
| 309 | - $this->increment_log_infix( $handle, $i ); |
|
| 310 | - } |
|
| 311 | - $this->increment_log_infix( $handle ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Increment a log file suffix. |
|
| 316 | - * |
|
| 317 | - * @param string $handle Log handle. |
|
| 318 | - * @param null|int $number Optional. Default null. Log suffix number to be incremented. |
|
| 319 | - * @return bool True if increment was successful, otherwise false. |
|
| 320 | - */ |
|
| 321 | - protected function increment_log_infix( $handle, $number = null ) { |
|
| 322 | - if ( null === $number ) { |
|
| 323 | - $suffix = ''; |
|
| 324 | - $next_suffix = '.0'; |
|
| 325 | - } else { |
|
| 326 | - $suffix = '.' . $number; |
|
| 327 | - $next_suffix = '.' . ( $number + 1 ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - $rename_from = self::get_log_file_path( "{$handle}{$suffix}" ); |
|
| 331 | - $rename_to = self::get_log_file_path( "{$handle}{$next_suffix}" ); |
|
| 332 | - |
|
| 333 | - if ( $this->is_open( $rename_from ) ) { |
|
| 334 | - $this->close( $rename_from ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if ( is_writable( $rename_from ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 338 | - return rename( $rename_from, $rename_to ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename |
|
| 339 | - } else { |
|
| 340 | - return false; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Get a log file path. |
|
| 347 | - * |
|
| 348 | - * @param string $handle Log name. |
|
| 349 | - * @return bool|string The log file path or false if path cannot be determined. |
|
| 350 | - */ |
|
| 351 | - public static function get_log_file_path( $handle ) { |
|
| 352 | - if ( function_exists( 'wp_hash' ) ) { |
|
| 353 | - return trailingslashit( WC_LOG_DIR ) . self::get_log_file_name( $handle ); |
|
| 354 | - } else { |
|
| 355 | - wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'woocommerce' ), '3.0' ); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Get a log file name. |
|
| 362 | - * |
|
| 363 | - * File names consist of the handle, followed by the date, followed by a hash, .log. |
|
| 364 | - * |
|
| 365 | - * @since 3.3 |
|
| 366 | - * @param string $handle Log name. |
|
| 367 | - * @return bool|string The log file name or false if cannot be determined. |
|
| 368 | - */ |
|
| 369 | - public static function get_log_file_name( $handle ) { |
|
| 370 | - if ( function_exists( 'wp_hash' ) ) { |
|
| 371 | - $date_suffix = date( 'Y-m-d', time() ); |
|
| 372 | - $hash_suffix = wp_hash( $handle ); |
|
| 373 | - return sanitize_file_name( implode( '-', array( $handle, $date_suffix, $hash_suffix ) ) . '.log' ); |
|
| 374 | - } else { |
|
| 375 | - wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'woocommerce' ), '3.3' ); |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Cache log to write later. |
|
| 382 | - * |
|
| 383 | - * @param string $entry Log entry text. |
|
| 384 | - * @param string $handle Log entry handle. |
|
| 385 | - */ |
|
| 386 | - protected function cache_log( $entry, $handle ) { |
|
| 387 | - $this->cached_logs[] = array( |
|
| 388 | - 'entry' => $entry, |
|
| 389 | - 'handle' => $handle, |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Write cached logs. |
|
| 395 | - */ |
|
| 396 | - public function write_cached_logs() { |
|
| 397 | - foreach ( $this->cached_logs as $log ) { |
|
| 398 | - $this->add( $log['entry'], $log['handle'] ); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Delete all logs older than a defined timestamp. |
|
| 404 | - * |
|
| 405 | - * @since 3.4.0 |
|
| 406 | - * @param integer $timestamp Timestamp to delete logs before. |
|
| 407 | - */ |
|
| 408 | - public static function delete_logs_before_timestamp( $timestamp = 0 ) { |
|
| 409 | - if ( ! $timestamp ) { |
|
| 410 | - return; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - $log_files = self::get_log_files(); |
|
| 414 | - |
|
| 415 | - foreach ( $log_files as $log_file ) { |
|
| 416 | - $last_modified = filemtime( trailingslashit( WC_LOG_DIR ) . $log_file ); |
|
| 417 | - |
|
| 418 | - if ( $last_modified < $timestamp ) { |
|
| 419 | - @unlink( trailingslashit( WC_LOG_DIR ) . $log_file ); // @codingStandardsIgnoreLine. |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Get all log files in the log directory. |
|
| 426 | - * |
|
| 427 | - * @since 3.4.0 |
|
| 428 | - * @return array |
|
| 429 | - */ |
|
| 430 | - public static function get_log_files() { |
|
| 431 | - $files = @scandir( WC_LOG_DIR ); // @codingStandardsIgnoreLine. |
|
| 432 | - $result = array(); |
|
| 433 | - |
|
| 434 | - if ( ! empty( $files ) ) { |
|
| 435 | - foreach ( $files as $key => $value ) { |
|
| 436 | - if ( ! in_array( $value, array( '.', '..' ), true ) ) { |
|
| 437 | - if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) { |
|
| 438 | - $result[ sanitize_title( $value ) ] = $value; |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return $result; |
|
| 445 | - } |
|
| 23 | + /** |
|
| 24 | + * Stores open file handles. |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $handles = array(); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * File size limit for log files in bytes. |
|
| 32 | + * |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + protected $log_size_limit; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Cache logs that could not be written. |
|
| 39 | + * |
|
| 40 | + * If a log is written too early in the request, pluggable functions may be unavailable. These |
|
| 41 | + * logs will be cached and written on 'plugins_loaded' action. |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + protected $cached_logs = array(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Constructor for the logger. |
|
| 49 | + * |
|
| 50 | + * @param int $log_size_limit Optional. Size limit for log files. Default 5mb. |
|
| 51 | + */ |
|
| 52 | + public function __construct( $log_size_limit = null ) { |
|
| 53 | + if ( null === $log_size_limit ) { |
|
| 54 | + $log_size_limit = 5 * 1024 * 1024; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $this->log_size_limit = apply_filters( 'woocommerce_log_file_size_limit', $log_size_limit ); |
|
| 58 | + |
|
| 59 | + add_action( 'plugins_loaded', array( $this, 'write_cached_logs' ) ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Destructor. |
|
| 64 | + * |
|
| 65 | + * Cleans up open file handles. |
|
| 66 | + */ |
|
| 67 | + public function __destruct() { |
|
| 68 | + foreach ( $this->handles as $handle ) { |
|
| 69 | + if ( is_resource( $handle ) ) { |
|
| 70 | + fclose( $handle ); // @codingStandardsIgnoreLine. |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Handle a log entry. |
|
| 77 | + * |
|
| 78 | + * @param int $timestamp Log timestamp. |
|
| 79 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 80 | + * @param string $message Log message. |
|
| 81 | + * @param array $context { |
|
| 82 | + * Additional information for log handlers. |
|
| 83 | + * |
|
| 84 | + * @type string $source Optional. Determines log file to write to. Default 'log'. |
|
| 85 | + * @type bool $_legacy Optional. Default false. True to use outdated log format |
|
| 86 | + * originally used in deprecated WC_Logger::add calls. |
|
| 87 | + * } |
|
| 88 | + * |
|
| 89 | + * @return bool False if value was not handled and true if value was handled. |
|
| 90 | + */ |
|
| 91 | + public function handle( $timestamp, $level, $message, $context ) { |
|
| 92 | + |
|
| 93 | + if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 94 | + $handle = $context['source']; |
|
| 95 | + } else { |
|
| 96 | + $handle = 'log'; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $entry = self::format_entry( $timestamp, $level, $message, $context ); |
|
| 100 | + |
|
| 101 | + return $this->add( $entry, $handle ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Builds a log entry text from timestamp, level and message. |
|
| 106 | + * |
|
| 107 | + * @param int $timestamp Log timestamp. |
|
| 108 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 109 | + * @param string $message Log message. |
|
| 110 | + * @param array $context Additional information for log handlers. |
|
| 111 | + * |
|
| 112 | + * @return string Formatted log entry. |
|
| 113 | + */ |
|
| 114 | + protected static function format_entry( $timestamp, $level, $message, $context ) { |
|
| 115 | + |
|
| 116 | + if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) { |
|
| 117 | + if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 118 | + $handle = $context['source']; |
|
| 119 | + } else { |
|
| 120 | + $handle = 'log'; |
|
| 121 | + } |
|
| 122 | + $message = apply_filters( 'woocommerce_logger_add_message', $message, $handle ); |
|
| 123 | + $time = date_i18n( 'm-d-Y @ H:i:s' ); |
|
| 124 | + $entry = "{$time} - {$message}"; |
|
| 125 | + } else { |
|
| 126 | + $entry = parent::format_entry( $timestamp, $level, $message, $context ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return $entry; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Open log file for writing. |
|
| 134 | + * |
|
| 135 | + * @param string $handle Log handle. |
|
| 136 | + * @param string $mode Optional. File mode. Default 'a'. |
|
| 137 | + * @return bool Success. |
|
| 138 | + */ |
|
| 139 | + protected function open( $handle, $mode = 'a' ) { |
|
| 140 | + if ( $this->is_open( $handle ) ) { |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $file = self::get_log_file_path( $handle ); |
|
| 145 | + |
|
| 146 | + if ( $file ) { |
|
| 147 | + if ( ! file_exists( $file ) ) { |
|
| 148 | + $temphandle = @fopen( $file, 'w+' ); // @codingStandardsIgnoreLine. |
|
| 149 | + if ( is_resource( $temphandle ) ) { |
|
| 150 | + @fclose( $temphandle ); // @codingStandardsIgnoreLine. |
|
| 151 | + |
|
| 152 | + if ( Constants::is_defined( 'FS_CHMOD_FILE' ) ) { |
|
| 153 | + @chmod( $file, FS_CHMOD_FILE ); // @codingStandardsIgnoreLine. |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $resource = @fopen( $file, $mode ); // @codingStandardsIgnoreLine. |
|
| 159 | + |
|
| 160 | + if ( $resource ) { |
|
| 161 | + $this->handles[ $handle ] = $resource; |
|
| 162 | + return true; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Check if a handle is open. |
|
| 171 | + * |
|
| 172 | + * @param string $handle Log handle. |
|
| 173 | + * @return bool True if $handle is open. |
|
| 174 | + */ |
|
| 175 | + protected function is_open( $handle ) { |
|
| 176 | + return array_key_exists( $handle, $this->handles ) && is_resource( $this->handles[ $handle ] ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Close a handle. |
|
| 181 | + * |
|
| 182 | + * @param string $handle Log handle. |
|
| 183 | + * @return bool success |
|
| 184 | + */ |
|
| 185 | + protected function close( $handle ) { |
|
| 186 | + $result = false; |
|
| 187 | + |
|
| 188 | + if ( $this->is_open( $handle ) ) { |
|
| 189 | + $result = fclose( $this->handles[ $handle ] ); // @codingStandardsIgnoreLine. |
|
| 190 | + unset( $this->handles[ $handle ] ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return $result; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Add a log entry to chosen file. |
|
| 198 | + * |
|
| 199 | + * @param string $entry Log entry text. |
|
| 200 | + * @param string $handle Log entry handle. |
|
| 201 | + * |
|
| 202 | + * @return bool True if write was successful. |
|
| 203 | + */ |
|
| 204 | + protected function add( $entry, $handle ) { |
|
| 205 | + $result = false; |
|
| 206 | + |
|
| 207 | + if ( $this->should_rotate( $handle ) ) { |
|
| 208 | + $this->log_rotate( $handle ); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ( $this->open( $handle ) && is_resource( $this->handles[ $handle ] ) ) { |
|
| 212 | + $result = fwrite( $this->handles[ $handle ], $entry . PHP_EOL ); // @codingStandardsIgnoreLine. |
|
| 213 | + } else { |
|
| 214 | + $this->cache_log( $entry, $handle ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return false !== $result; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Clear entries from chosen file. |
|
| 222 | + * |
|
| 223 | + * @param string $handle Log handle. |
|
| 224 | + * |
|
| 225 | + * @return bool |
|
| 226 | + */ |
|
| 227 | + public function clear( $handle ) { |
|
| 228 | + $result = false; |
|
| 229 | + |
|
| 230 | + // Close the file if it's already open. |
|
| 231 | + $this->close( $handle ); |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * $this->open( $handle, 'w' ) == Open the file for writing only. Place the file pointer at |
|
| 235 | + * the beginning of the file, and truncate the file to zero length. |
|
| 236 | + */ |
|
| 237 | + if ( $this->open( $handle, 'w' ) && is_resource( $this->handles[ $handle ] ) ) { |
|
| 238 | + $result = true; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + do_action( 'woocommerce_log_clear', $handle ); |
|
| 242 | + |
|
| 243 | + return $result; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Remove/delete the chosen file. |
|
| 248 | + * |
|
| 249 | + * @param string $handle Log handle. |
|
| 250 | + * |
|
| 251 | + * @return bool |
|
| 252 | + */ |
|
| 253 | + public function remove( $handle ) { |
|
| 254 | + $removed = false; |
|
| 255 | + $logs = $this->get_log_files(); |
|
| 256 | + $handle = sanitize_title( $handle ); |
|
| 257 | + |
|
| 258 | + if ( isset( $logs[ $handle ] ) && $logs[ $handle ] ) { |
|
| 259 | + $file = realpath( trailingslashit( WC_LOG_DIR ) . $logs[ $handle ] ); |
|
| 260 | + if ( 0 === stripos( $file, realpath( trailingslashit( WC_LOG_DIR ) ) ) && is_file( $file ) && is_writable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 261 | + $this->close( $file ); // Close first to be certain no processes keep it alive after it is unlinked. |
|
| 262 | + $removed = unlink( $file ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_unlink |
|
| 263 | + } |
|
| 264 | + do_action( 'woocommerce_log_remove', $handle, $removed ); |
|
| 265 | + } |
|
| 266 | + return $removed; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Check if log file should be rotated. |
|
| 271 | + * |
|
| 272 | + * Compares the size of the log file to determine whether it is over the size limit. |
|
| 273 | + * |
|
| 274 | + * @param string $handle Log handle. |
|
| 275 | + * @return bool True if if should be rotated. |
|
| 276 | + */ |
|
| 277 | + protected function should_rotate( $handle ) { |
|
| 278 | + $file = self::get_log_file_path( $handle ); |
|
| 279 | + if ( $file ) { |
|
| 280 | + if ( $this->is_open( $handle ) ) { |
|
| 281 | + $file_stat = fstat( $this->handles[ $handle ] ); |
|
| 282 | + return $file_stat['size'] > $this->log_size_limit; |
|
| 283 | + } elseif ( file_exists( $file ) ) { |
|
| 284 | + return filesize( $file ) > $this->log_size_limit; |
|
| 285 | + } else { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 288 | + } else { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Rotate log files. |
|
| 295 | + * |
|
| 296 | + * Logs are rotated by prepending '.x' to the '.log' suffix. |
|
| 297 | + * The current log plus 10 historical logs are maintained. |
|
| 298 | + * For example: |
|
| 299 | + * base.9.log -> [ REMOVED ] |
|
| 300 | + * base.8.log -> base.9.log |
|
| 301 | + * ... |
|
| 302 | + * base.0.log -> base.1.log |
|
| 303 | + * base.log -> base.0.log |
|
| 304 | + * |
|
| 305 | + * @param string $handle Log handle. |
|
| 306 | + */ |
|
| 307 | + protected function log_rotate( $handle ) { |
|
| 308 | + for ( $i = 8; $i >= 0; $i-- ) { |
|
| 309 | + $this->increment_log_infix( $handle, $i ); |
|
| 310 | + } |
|
| 311 | + $this->increment_log_infix( $handle ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Increment a log file suffix. |
|
| 316 | + * |
|
| 317 | + * @param string $handle Log handle. |
|
| 318 | + * @param null|int $number Optional. Default null. Log suffix number to be incremented. |
|
| 319 | + * @return bool True if increment was successful, otherwise false. |
|
| 320 | + */ |
|
| 321 | + protected function increment_log_infix( $handle, $number = null ) { |
|
| 322 | + if ( null === $number ) { |
|
| 323 | + $suffix = ''; |
|
| 324 | + $next_suffix = '.0'; |
|
| 325 | + } else { |
|
| 326 | + $suffix = '.' . $number; |
|
| 327 | + $next_suffix = '.' . ( $number + 1 ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + $rename_from = self::get_log_file_path( "{$handle}{$suffix}" ); |
|
| 331 | + $rename_to = self::get_log_file_path( "{$handle}{$next_suffix}" ); |
|
| 332 | + |
|
| 333 | + if ( $this->is_open( $rename_from ) ) { |
|
| 334 | + $this->close( $rename_from ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if ( is_writable( $rename_from ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 338 | + return rename( $rename_from, $rename_to ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename |
|
| 339 | + } else { |
|
| 340 | + return false; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Get a log file path. |
|
| 347 | + * |
|
| 348 | + * @param string $handle Log name. |
|
| 349 | + * @return bool|string The log file path or false if path cannot be determined. |
|
| 350 | + */ |
|
| 351 | + public static function get_log_file_path( $handle ) { |
|
| 352 | + if ( function_exists( 'wp_hash' ) ) { |
|
| 353 | + return trailingslashit( WC_LOG_DIR ) . self::get_log_file_name( $handle ); |
|
| 354 | + } else { |
|
| 355 | + wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'woocommerce' ), '3.0' ); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Get a log file name. |
|
| 362 | + * |
|
| 363 | + * File names consist of the handle, followed by the date, followed by a hash, .log. |
|
| 364 | + * |
|
| 365 | + * @since 3.3 |
|
| 366 | + * @param string $handle Log name. |
|
| 367 | + * @return bool|string The log file name or false if cannot be determined. |
|
| 368 | + */ |
|
| 369 | + public static function get_log_file_name( $handle ) { |
|
| 370 | + if ( function_exists( 'wp_hash' ) ) { |
|
| 371 | + $date_suffix = date( 'Y-m-d', time() ); |
|
| 372 | + $hash_suffix = wp_hash( $handle ); |
|
| 373 | + return sanitize_file_name( implode( '-', array( $handle, $date_suffix, $hash_suffix ) ) . '.log' ); |
|
| 374 | + } else { |
|
| 375 | + wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'woocommerce' ), '3.3' ); |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Cache log to write later. |
|
| 382 | + * |
|
| 383 | + * @param string $entry Log entry text. |
|
| 384 | + * @param string $handle Log entry handle. |
|
| 385 | + */ |
|
| 386 | + protected function cache_log( $entry, $handle ) { |
|
| 387 | + $this->cached_logs[] = array( |
|
| 388 | + 'entry' => $entry, |
|
| 389 | + 'handle' => $handle, |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Write cached logs. |
|
| 395 | + */ |
|
| 396 | + public function write_cached_logs() { |
|
| 397 | + foreach ( $this->cached_logs as $log ) { |
|
| 398 | + $this->add( $log['entry'], $log['handle'] ); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Delete all logs older than a defined timestamp. |
|
| 404 | + * |
|
| 405 | + * @since 3.4.0 |
|
| 406 | + * @param integer $timestamp Timestamp to delete logs before. |
|
| 407 | + */ |
|
| 408 | + public static function delete_logs_before_timestamp( $timestamp = 0 ) { |
|
| 409 | + if ( ! $timestamp ) { |
|
| 410 | + return; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + $log_files = self::get_log_files(); |
|
| 414 | + |
|
| 415 | + foreach ( $log_files as $log_file ) { |
|
| 416 | + $last_modified = filemtime( trailingslashit( WC_LOG_DIR ) . $log_file ); |
|
| 417 | + |
|
| 418 | + if ( $last_modified < $timestamp ) { |
|
| 419 | + @unlink( trailingslashit( WC_LOG_DIR ) . $log_file ); // @codingStandardsIgnoreLine. |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Get all log files in the log directory. |
|
| 426 | + * |
|
| 427 | + * @since 3.4.0 |
|
| 428 | + * @return array |
|
| 429 | + */ |
|
| 430 | + public static function get_log_files() { |
|
| 431 | + $files = @scandir( WC_LOG_DIR ); // @codingStandardsIgnoreLine. |
|
| 432 | + $result = array(); |
|
| 433 | + |
|
| 434 | + if ( ! empty( $files ) ) { |
|
| 435 | + foreach ( $files as $key => $value ) { |
|
| 436 | + if ( ! in_array( $value, array( '.', '..' ), true ) ) { |
|
| 437 | + if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) { |
|
| 438 | + $result[ sanitize_title( $value ) ] = $value; |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return $result; |
|
| 445 | + } |
|
| 446 | 446 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | use Automattic\Jetpack\Constants; |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if (!defined('ABSPATH')) { |
|
| 11 | 11 | exit; // Exit if accessed directly. |
| 12 | 12 | } |
| 13 | 13 | |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @param int $log_size_limit Optional. Size limit for log files. Default 5mb. |
| 51 | 51 | */ |
| 52 | - public function __construct( $log_size_limit = null ) { |
|
| 53 | - if ( null === $log_size_limit ) { |
|
| 52 | + public function __construct($log_size_limit = null) { |
|
| 53 | + if (null === $log_size_limit) { |
|
| 54 | 54 | $log_size_limit = 5 * 1024 * 1024; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $this->log_size_limit = apply_filters( 'woocommerce_log_file_size_limit', $log_size_limit ); |
|
| 57 | + $this->log_size_limit = apply_filters('woocommerce_log_file_size_limit', $log_size_limit); |
|
| 58 | 58 | |
| 59 | - add_action( 'plugins_loaded', array( $this, 'write_cached_logs' ) ); |
|
| 59 | + add_action('plugins_loaded', array($this, 'write_cached_logs')); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | * Cleans up open file handles. |
| 66 | 66 | */ |
| 67 | 67 | public function __destruct() { |
| 68 | - foreach ( $this->handles as $handle ) { |
|
| 69 | - if ( is_resource( $handle ) ) { |
|
| 70 | - fclose( $handle ); // @codingStandardsIgnoreLine. |
|
| 68 | + foreach ($this->handles as $handle) { |
|
| 69 | + if (is_resource($handle)) { |
|
| 70 | + fclose($handle); // @codingStandardsIgnoreLine. |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -88,17 +88,17 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return bool False if value was not handled and true if value was handled. |
| 90 | 90 | */ |
| 91 | - public function handle( $timestamp, $level, $message, $context ) { |
|
| 91 | + public function handle($timestamp, $level, $message, $context) { |
|
| 92 | 92 | |
| 93 | - if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 93 | + if (isset($context['source']) && $context['source']) { |
|
| 94 | 94 | $handle = $context['source']; |
| 95 | 95 | } else { |
| 96 | 96 | $handle = 'log'; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $entry = self::format_entry( $timestamp, $level, $message, $context ); |
|
| 99 | + $entry = self::format_entry($timestamp, $level, $message, $context); |
|
| 100 | 100 | |
| 101 | - return $this->add( $entry, $handle ); |
|
| 101 | + return $this->add($entry, $handle); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -111,19 +111,19 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return string Formatted log entry. |
| 113 | 113 | */ |
| 114 | - protected static function format_entry( $timestamp, $level, $message, $context ) { |
|
| 114 | + protected static function format_entry($timestamp, $level, $message, $context) { |
|
| 115 | 115 | |
| 116 | - if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) { |
|
| 117 | - if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 116 | + if (isset($context['_legacy']) && true === $context['_legacy']) { |
|
| 117 | + if (isset($context['source']) && $context['source']) { |
|
| 118 | 118 | $handle = $context['source']; |
| 119 | 119 | } else { |
| 120 | 120 | $handle = 'log'; |
| 121 | 121 | } |
| 122 | - $message = apply_filters( 'woocommerce_logger_add_message', $message, $handle ); |
|
| 123 | - $time = date_i18n( 'm-d-Y @ H:i:s' ); |
|
| 122 | + $message = apply_filters('woocommerce_logger_add_message', $message, $handle); |
|
| 123 | + $time = date_i18n('m-d-Y @ H:i:s'); |
|
| 124 | 124 | $entry = "{$time} - {$message}"; |
| 125 | 125 | } else { |
| 126 | - $entry = parent::format_entry( $timestamp, $level, $message, $context ); |
|
| 126 | + $entry = parent::format_entry($timestamp, $level, $message, $context); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return $entry; |
@@ -136,29 +136,29 @@ discard block |
||
| 136 | 136 | * @param string $mode Optional. File mode. Default 'a'. |
| 137 | 137 | * @return bool Success. |
| 138 | 138 | */ |
| 139 | - protected function open( $handle, $mode = 'a' ) { |
|
| 140 | - if ( $this->is_open( $handle ) ) { |
|
| 139 | + protected function open($handle, $mode = 'a') { |
|
| 140 | + if ($this->is_open($handle)) { |
|
| 141 | 141 | return true; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $file = self::get_log_file_path( $handle ); |
|
| 144 | + $file = self::get_log_file_path($handle); |
|
| 145 | 145 | |
| 146 | - if ( $file ) { |
|
| 147 | - if ( ! file_exists( $file ) ) { |
|
| 148 | - $temphandle = @fopen( $file, 'w+' ); // @codingStandardsIgnoreLine. |
|
| 149 | - if ( is_resource( $temphandle ) ) { |
|
| 150 | - @fclose( $temphandle ); // @codingStandardsIgnoreLine. |
|
| 146 | + if ($file) { |
|
| 147 | + if (!file_exists($file)) { |
|
| 148 | + $temphandle = @fopen($file, 'w+'); // @codingStandardsIgnoreLine. |
|
| 149 | + if (is_resource($temphandle)) { |
|
| 150 | + @fclose($temphandle); // @codingStandardsIgnoreLine. |
|
| 151 | 151 | |
| 152 | - if ( Constants::is_defined( 'FS_CHMOD_FILE' ) ) { |
|
| 153 | - @chmod( $file, FS_CHMOD_FILE ); // @codingStandardsIgnoreLine. |
|
| 152 | + if (Constants::is_defined('FS_CHMOD_FILE')) { |
|
| 153 | + @chmod($file, FS_CHMOD_FILE); // @codingStandardsIgnoreLine. |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $resource = @fopen( $file, $mode ); // @codingStandardsIgnoreLine. |
|
| 158 | + $resource = @fopen($file, $mode); // @codingStandardsIgnoreLine. |
|
| 159 | 159 | |
| 160 | - if ( $resource ) { |
|
| 161 | - $this->handles[ $handle ] = $resource; |
|
| 160 | + if ($resource) { |
|
| 161 | + $this->handles[$handle] = $resource; |
|
| 162 | 162 | return true; |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * @param string $handle Log handle. |
| 173 | 173 | * @return bool True if $handle is open. |
| 174 | 174 | */ |
| 175 | - protected function is_open( $handle ) { |
|
| 176 | - return array_key_exists( $handle, $this->handles ) && is_resource( $this->handles[ $handle ] ); |
|
| 175 | + protected function is_open($handle) { |
|
| 176 | + return array_key_exists($handle, $this->handles) && is_resource($this->handles[$handle]); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -182,12 +182,12 @@ discard block |
||
| 182 | 182 | * @param string $handle Log handle. |
| 183 | 183 | * @return bool success |
| 184 | 184 | */ |
| 185 | - protected function close( $handle ) { |
|
| 185 | + protected function close($handle) { |
|
| 186 | 186 | $result = false; |
| 187 | 187 | |
| 188 | - if ( $this->is_open( $handle ) ) { |
|
| 189 | - $result = fclose( $this->handles[ $handle ] ); // @codingStandardsIgnoreLine. |
|
| 190 | - unset( $this->handles[ $handle ] ); |
|
| 188 | + if ($this->is_open($handle)) { |
|
| 189 | + $result = fclose($this->handles[$handle]); // @codingStandardsIgnoreLine. |
|
| 190 | + unset($this->handles[$handle]); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | return $result; |
@@ -201,17 +201,17 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @return bool True if write was successful. |
| 203 | 203 | */ |
| 204 | - protected function add( $entry, $handle ) { |
|
| 204 | + protected function add($entry, $handle) { |
|
| 205 | 205 | $result = false; |
| 206 | 206 | |
| 207 | - if ( $this->should_rotate( $handle ) ) { |
|
| 208 | - $this->log_rotate( $handle ); |
|
| 207 | + if ($this->should_rotate($handle)) { |
|
| 208 | + $this->log_rotate($handle); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( $this->open( $handle ) && is_resource( $this->handles[ $handle ] ) ) { |
|
| 212 | - $result = fwrite( $this->handles[ $handle ], $entry . PHP_EOL ); // @codingStandardsIgnoreLine. |
|
| 211 | + if ($this->open($handle) && is_resource($this->handles[$handle])) { |
|
| 212 | + $result = fwrite($this->handles[$handle], $entry . PHP_EOL); // @codingStandardsIgnoreLine. |
|
| 213 | 213 | } else { |
| 214 | - $this->cache_log( $entry, $handle ); |
|
| 214 | + $this->cache_log($entry, $handle); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | return false !== $result; |
@@ -224,21 +224,21 @@ discard block |
||
| 224 | 224 | * |
| 225 | 225 | * @return bool |
| 226 | 226 | */ |
| 227 | - public function clear( $handle ) { |
|
| 227 | + public function clear($handle) { |
|
| 228 | 228 | $result = false; |
| 229 | 229 | |
| 230 | 230 | // Close the file if it's already open. |
| 231 | - $this->close( $handle ); |
|
| 231 | + $this->close($handle); |
|
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * $this->open( $handle, 'w' ) == Open the file for writing only. Place the file pointer at |
| 235 | 235 | * the beginning of the file, and truncate the file to zero length. |
| 236 | 236 | */ |
| 237 | - if ( $this->open( $handle, 'w' ) && is_resource( $this->handles[ $handle ] ) ) { |
|
| 237 | + if ($this->open($handle, 'w') && is_resource($this->handles[$handle])) { |
|
| 238 | 238 | $result = true; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - do_action( 'woocommerce_log_clear', $handle ); |
|
| 241 | + do_action('woocommerce_log_clear', $handle); |
|
| 242 | 242 | |
| 243 | 243 | return $result; |
| 244 | 244 | } |
@@ -250,18 +250,18 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return bool |
| 252 | 252 | */ |
| 253 | - public function remove( $handle ) { |
|
| 253 | + public function remove($handle) { |
|
| 254 | 254 | $removed = false; |
| 255 | 255 | $logs = $this->get_log_files(); |
| 256 | - $handle = sanitize_title( $handle ); |
|
| 256 | + $handle = sanitize_title($handle); |
|
| 257 | 257 | |
| 258 | - if ( isset( $logs[ $handle ] ) && $logs[ $handle ] ) { |
|
| 259 | - $file = realpath( trailingslashit( WC_LOG_DIR ) . $logs[ $handle ] ); |
|
| 260 | - if ( 0 === stripos( $file, realpath( trailingslashit( WC_LOG_DIR ) ) ) && is_file( $file ) && is_writable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 261 | - $this->close( $file ); // Close first to be certain no processes keep it alive after it is unlinked. |
|
| 262 | - $removed = unlink( $file ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_unlink |
|
| 258 | + if (isset($logs[$handle]) && $logs[$handle]) { |
|
| 259 | + $file = realpath(trailingslashit(WC_LOG_DIR) . $logs[$handle]); |
|
| 260 | + if (0 === stripos($file, realpath(trailingslashit(WC_LOG_DIR))) && is_file($file) && is_writable($file)) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 261 | + $this->close($file); // Close first to be certain no processes keep it alive after it is unlinked. |
|
| 262 | + $removed = unlink($file); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_unlink |
|
| 263 | 263 | } |
| 264 | - do_action( 'woocommerce_log_remove', $handle, $removed ); |
|
| 264 | + do_action('woocommerce_log_remove', $handle, $removed); |
|
| 265 | 265 | } |
| 266 | 266 | return $removed; |
| 267 | 267 | } |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | * @param string $handle Log handle. |
| 275 | 275 | * @return bool True if if should be rotated. |
| 276 | 276 | */ |
| 277 | - protected function should_rotate( $handle ) { |
|
| 278 | - $file = self::get_log_file_path( $handle ); |
|
| 279 | - if ( $file ) { |
|
| 280 | - if ( $this->is_open( $handle ) ) { |
|
| 281 | - $file_stat = fstat( $this->handles[ $handle ] ); |
|
| 277 | + protected function should_rotate($handle) { |
|
| 278 | + $file = self::get_log_file_path($handle); |
|
| 279 | + if ($file) { |
|
| 280 | + if ($this->is_open($handle)) { |
|
| 281 | + $file_stat = fstat($this->handles[$handle]); |
|
| 282 | 282 | return $file_stat['size'] > $this->log_size_limit; |
| 283 | - } elseif ( file_exists( $file ) ) { |
|
| 284 | - return filesize( $file ) > $this->log_size_limit; |
|
| 283 | + } elseif (file_exists($file)) { |
|
| 284 | + return filesize($file) > $this->log_size_limit; |
|
| 285 | 285 | } else { |
| 286 | 286 | return false; |
| 287 | 287 | } |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | * |
| 305 | 305 | * @param string $handle Log handle. |
| 306 | 306 | */ |
| 307 | - protected function log_rotate( $handle ) { |
|
| 308 | - for ( $i = 8; $i >= 0; $i-- ) { |
|
| 309 | - $this->increment_log_infix( $handle, $i ); |
|
| 307 | + protected function log_rotate($handle) { |
|
| 308 | + for ($i = 8; $i >= 0; $i--) { |
|
| 309 | + $this->increment_log_infix($handle, $i); |
|
| 310 | 310 | } |
| 311 | - $this->increment_log_infix( $handle ); |
|
| 311 | + $this->increment_log_infix($handle); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -318,24 +318,24 @@ discard block |
||
| 318 | 318 | * @param null|int $number Optional. Default null. Log suffix number to be incremented. |
| 319 | 319 | * @return bool True if increment was successful, otherwise false. |
| 320 | 320 | */ |
| 321 | - protected function increment_log_infix( $handle, $number = null ) { |
|
| 322 | - if ( null === $number ) { |
|
| 321 | + protected function increment_log_infix($handle, $number = null) { |
|
| 322 | + if (null === $number) { |
|
| 323 | 323 | $suffix = ''; |
| 324 | 324 | $next_suffix = '.0'; |
| 325 | 325 | } else { |
| 326 | 326 | $suffix = '.' . $number; |
| 327 | - $next_suffix = '.' . ( $number + 1 ); |
|
| 327 | + $next_suffix = '.' . ($number + 1); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - $rename_from = self::get_log_file_path( "{$handle}{$suffix}" ); |
|
| 331 | - $rename_to = self::get_log_file_path( "{$handle}{$next_suffix}" ); |
|
| 330 | + $rename_from = self::get_log_file_path("{$handle}{$suffix}"); |
|
| 331 | + $rename_to = self::get_log_file_path("{$handle}{$next_suffix}"); |
|
| 332 | 332 | |
| 333 | - if ( $this->is_open( $rename_from ) ) { |
|
| 334 | - $this->close( $rename_from ); |
|
| 333 | + if ($this->is_open($rename_from)) { |
|
| 334 | + $this->close($rename_from); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if ( is_writable( $rename_from ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 338 | - return rename( $rename_from, $rename_to ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename |
|
| 337 | + if (is_writable($rename_from)) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable |
|
| 338 | + return rename($rename_from, $rename_to); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename |
|
| 339 | 339 | } else { |
| 340 | 340 | return false; |
| 341 | 341 | } |
@@ -348,11 +348,11 @@ discard block |
||
| 348 | 348 | * @param string $handle Log name. |
| 349 | 349 | * @return bool|string The log file path or false if path cannot be determined. |
| 350 | 350 | */ |
| 351 | - public static function get_log_file_path( $handle ) { |
|
| 352 | - if ( function_exists( 'wp_hash' ) ) { |
|
| 353 | - return trailingslashit( WC_LOG_DIR ) . self::get_log_file_name( $handle ); |
|
| 351 | + public static function get_log_file_path($handle) { |
|
| 352 | + if (function_exists('wp_hash')) { |
|
| 353 | + return trailingslashit(WC_LOG_DIR) . self::get_log_file_name($handle); |
|
| 354 | 354 | } else { |
| 355 | - wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'woocommerce' ), '3.0' ); |
|
| 355 | + wc_doing_it_wrong(__METHOD__, __('This method should not be called before plugins_loaded.', 'woocommerce'), '3.0'); |
|
| 356 | 356 | return false; |
| 357 | 357 | } |
| 358 | 358 | } |
@@ -366,13 +366,13 @@ discard block |
||
| 366 | 366 | * @param string $handle Log name. |
| 367 | 367 | * @return bool|string The log file name or false if cannot be determined. |
| 368 | 368 | */ |
| 369 | - public static function get_log_file_name( $handle ) { |
|
| 370 | - if ( function_exists( 'wp_hash' ) ) { |
|
| 371 | - $date_suffix = date( 'Y-m-d', time() ); |
|
| 372 | - $hash_suffix = wp_hash( $handle ); |
|
| 373 | - return sanitize_file_name( implode( '-', array( $handle, $date_suffix, $hash_suffix ) ) . '.log' ); |
|
| 369 | + public static function get_log_file_name($handle) { |
|
| 370 | + if (function_exists('wp_hash')) { |
|
| 371 | + $date_suffix = date('Y-m-d', time()); |
|
| 372 | + $hash_suffix = wp_hash($handle); |
|
| 373 | + return sanitize_file_name(implode('-', array($handle, $date_suffix, $hash_suffix)) . '.log'); |
|
| 374 | 374 | } else { |
| 375 | - wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'woocommerce' ), '3.3' ); |
|
| 375 | + wc_doing_it_wrong(__METHOD__, __('This method should not be called before plugins_loaded.', 'woocommerce'), '3.3'); |
|
| 376 | 376 | return false; |
| 377 | 377 | } |
| 378 | 378 | } |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | * @param string $entry Log entry text. |
| 384 | 384 | * @param string $handle Log entry handle. |
| 385 | 385 | */ |
| 386 | - protected function cache_log( $entry, $handle ) { |
|
| 386 | + protected function cache_log($entry, $handle) { |
|
| 387 | 387 | $this->cached_logs[] = array( |
| 388 | 388 | 'entry' => $entry, |
| 389 | 389 | 'handle' => $handle, |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | * Write cached logs. |
| 395 | 395 | */ |
| 396 | 396 | public function write_cached_logs() { |
| 397 | - foreach ( $this->cached_logs as $log ) { |
|
| 398 | - $this->add( $log['entry'], $log['handle'] ); |
|
| 397 | + foreach ($this->cached_logs as $log) { |
|
| 398 | + $this->add($log['entry'], $log['handle']); |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
@@ -405,18 +405,18 @@ discard block |
||
| 405 | 405 | * @since 3.4.0 |
| 406 | 406 | * @param integer $timestamp Timestamp to delete logs before. |
| 407 | 407 | */ |
| 408 | - public static function delete_logs_before_timestamp( $timestamp = 0 ) { |
|
| 409 | - if ( ! $timestamp ) { |
|
| 408 | + public static function delete_logs_before_timestamp($timestamp = 0) { |
|
| 409 | + if (!$timestamp) { |
|
| 410 | 410 | return; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | $log_files = self::get_log_files(); |
| 414 | 414 | |
| 415 | - foreach ( $log_files as $log_file ) { |
|
| 416 | - $last_modified = filemtime( trailingslashit( WC_LOG_DIR ) . $log_file ); |
|
| 415 | + foreach ($log_files as $log_file) { |
|
| 416 | + $last_modified = filemtime(trailingslashit(WC_LOG_DIR) . $log_file); |
|
| 417 | 417 | |
| 418 | - if ( $last_modified < $timestamp ) { |
|
| 419 | - @unlink( trailingslashit( WC_LOG_DIR ) . $log_file ); // @codingStandardsIgnoreLine. |
|
| 418 | + if ($last_modified < $timestamp) { |
|
| 419 | + @unlink(trailingslashit(WC_LOG_DIR) . $log_file); // @codingStandardsIgnoreLine. |
|
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | } |
@@ -428,14 +428,14 @@ discard block |
||
| 428 | 428 | * @return array |
| 429 | 429 | */ |
| 430 | 430 | public static function get_log_files() { |
| 431 | - $files = @scandir( WC_LOG_DIR ); // @codingStandardsIgnoreLine. |
|
| 431 | + $files = @scandir(WC_LOG_DIR); // @codingStandardsIgnoreLine. |
|
| 432 | 432 | $result = array(); |
| 433 | 433 | |
| 434 | - if ( ! empty( $files ) ) { |
|
| 435 | - foreach ( $files as $key => $value ) { |
|
| 436 | - if ( ! in_array( $value, array( '.', '..' ), true ) ) { |
|
| 437 | - if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) { |
|
| 438 | - $result[ sanitize_title( $value ) ] = $value; |
|
| 434 | + if (!empty($files)) { |
|
| 435 | + foreach ($files as $key => $value) { |
|
| 436 | + if (!in_array($value, array('.', '..'), true)) { |
|
| 437 | + if (!is_dir($value) && strstr($value, '.log')) { |
|
| 438 | + $result[sanitize_title($value)] = $value; |
|
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use Automattic\Jetpack\Constants; |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly. |
|
| 11 | + exit; // Exit if accessed directly. |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -20,174 +20,174 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class WC_Log_Handler_DB extends WC_Log_Handler { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Handle a log entry. |
|
| 25 | - * |
|
| 26 | - * @param int $timestamp Log timestamp. |
|
| 27 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 28 | - * @param string $message Log message. |
|
| 29 | - * @param array $context { |
|
| 30 | - * Additional information for log handlers. |
|
| 31 | - * |
|
| 32 | - * @type string $source Optional. Source will be available in log table. |
|
| 33 | - * If no source is provided, attempt to provide sensible default. |
|
| 34 | - * } |
|
| 35 | - * |
|
| 36 | - * @see WC_Log_Handler_DB::get_log_source() for default source. |
|
| 37 | - * |
|
| 38 | - * @return bool False if value was not handled and true if value was handled. |
|
| 39 | - */ |
|
| 40 | - public function handle( $timestamp, $level, $message, $context ) { |
|
| 41 | - |
|
| 42 | - if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 43 | - $source = $context['source']; |
|
| 44 | - } else { |
|
| 45 | - $source = $this->get_log_source(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return $this->add( $timestamp, $level, $message, $source, $context ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Add a log entry to chosen file. |
|
| 53 | - * |
|
| 54 | - * @param int $timestamp Log timestamp. |
|
| 55 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 56 | - * @param string $message Log message. |
|
| 57 | - * @param string $source Log source. Useful for filtering and sorting. |
|
| 58 | - * @param array $context Context will be serialized and stored in database. |
|
| 59 | - * |
|
| 60 | - * @return bool True if write was successful. |
|
| 61 | - */ |
|
| 62 | - protected static function add( $timestamp, $level, $message, $source, $context ) { |
|
| 63 | - global $wpdb; |
|
| 64 | - |
|
| 65 | - $insert = array( |
|
| 66 | - 'timestamp' => date( 'Y-m-d H:i:s', $timestamp ), |
|
| 67 | - 'level' => WC_Log_Levels::get_level_severity( $level ), |
|
| 68 | - 'message' => $message, |
|
| 69 | - 'source' => $source, |
|
| 70 | - ); |
|
| 71 | - |
|
| 72 | - $format = array( |
|
| 73 | - '%s', |
|
| 74 | - '%d', |
|
| 75 | - '%s', |
|
| 76 | - '%s', |
|
| 77 | - '%s', // possible serialized context. |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - if ( ! empty( $context ) ) { |
|
| 81 | - try { |
|
| 82 | - $insert['context'] = serialize( $context ); // @codingStandardsIgnoreLine. |
|
| 83 | - } catch ( Exception $e ) { |
|
| 84 | - $insert['context'] = serialize( 'There was an error while serializing the context: ' . $e->getMessage() ); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return false !== $wpdb->insert( "{$wpdb->prefix}woocommerce_log", $insert, $format ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Clear all logs from the DB. |
|
| 93 | - * |
|
| 94 | - * @return bool True if flush was successful. |
|
| 95 | - */ |
|
| 96 | - public static function flush() { |
|
| 97 | - global $wpdb; |
|
| 98 | - |
|
| 99 | - return $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_log" ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Clear entries for a chosen handle/source. |
|
| 104 | - * |
|
| 105 | - * @param string $source Log source. |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public function clear( $source ) { |
|
| 109 | - global $wpdb; |
|
| 110 | - |
|
| 111 | - return $wpdb->query( |
|
| 112 | - $wpdb->prepare( |
|
| 113 | - "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE source = %s", |
|
| 114 | - $source |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Delete selected logs from DB. |
|
| 121 | - * |
|
| 122 | - * @param int|string|array $log_ids Log ID or array of Log IDs to be deleted. |
|
| 123 | - * |
|
| 124 | - * @return bool |
|
| 125 | - */ |
|
| 126 | - public static function delete( $log_ids ) { |
|
| 127 | - global $wpdb; |
|
| 128 | - |
|
| 129 | - if ( ! is_array( $log_ids ) ) { |
|
| 130 | - $log_ids = array( $log_ids ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $format = array_fill( 0, count( $log_ids ), '%d' ); |
|
| 134 | - $query_in = '(' . implode( ',', $format ) . ')'; |
|
| 135 | - return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE log_id IN {$query_in}", $log_ids ) ); // @codingStandardsIgnoreLine. |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Delete all logs older than a defined timestamp. |
|
| 140 | - * |
|
| 141 | - * @since 3.4.0 |
|
| 142 | - * @param integer $timestamp Timestamp to delete logs before. |
|
| 143 | - */ |
|
| 144 | - public static function delete_logs_before_timestamp( $timestamp = 0 ) { |
|
| 145 | - if ( ! $timestamp ) { |
|
| 146 | - return; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - global $wpdb; |
|
| 150 | - |
|
| 151 | - $wpdb->query( |
|
| 152 | - $wpdb->prepare( |
|
| 153 | - "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE timestamp < %s", |
|
| 154 | - date( 'Y-m-d H:i:s', $timestamp ) |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Get appropriate source based on file name. |
|
| 161 | - * |
|
| 162 | - * Try to provide an appropriate source in case none is provided. |
|
| 163 | - * |
|
| 164 | - * @return string Text to use as log source. "" (empty string) if none is found. |
|
| 165 | - */ |
|
| 166 | - protected static function get_log_source() { |
|
| 167 | - static $ignore_files = array( 'class-wc-log-handler-db', 'class-wc-logger' ); |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * PHP < 5.3.6 correct behavior |
|
| 171 | - * |
|
| 172 | - * @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters |
|
| 173 | - */ |
|
| 174 | - if ( Constants::is_defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) { |
|
| 175 | - $debug_backtrace_arg = DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:ignore PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound |
|
| 176 | - } else { |
|
| 177 | - $debug_backtrace_arg = false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $trace = debug_backtrace( $debug_backtrace_arg ); // @codingStandardsIgnoreLine. |
|
| 181 | - foreach ( $trace as $t ) { |
|
| 182 | - if ( isset( $t['file'] ) ) { |
|
| 183 | - $filename = pathinfo( $t['file'], PATHINFO_FILENAME ); |
|
| 184 | - if ( ! in_array( $filename, $ignore_files, true ) ) { |
|
| 185 | - return $filename; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return ''; |
|
| 191 | - } |
|
| 23 | + /** |
|
| 24 | + * Handle a log entry. |
|
| 25 | + * |
|
| 26 | + * @param int $timestamp Log timestamp. |
|
| 27 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 28 | + * @param string $message Log message. |
|
| 29 | + * @param array $context { |
|
| 30 | + * Additional information for log handlers. |
|
| 31 | + * |
|
| 32 | + * @type string $source Optional. Source will be available in log table. |
|
| 33 | + * If no source is provided, attempt to provide sensible default. |
|
| 34 | + * } |
|
| 35 | + * |
|
| 36 | + * @see WC_Log_Handler_DB::get_log_source() for default source. |
|
| 37 | + * |
|
| 38 | + * @return bool False if value was not handled and true if value was handled. |
|
| 39 | + */ |
|
| 40 | + public function handle( $timestamp, $level, $message, $context ) { |
|
| 41 | + |
|
| 42 | + if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 43 | + $source = $context['source']; |
|
| 44 | + } else { |
|
| 45 | + $source = $this->get_log_source(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return $this->add( $timestamp, $level, $message, $source, $context ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Add a log entry to chosen file. |
|
| 53 | + * |
|
| 54 | + * @param int $timestamp Log timestamp. |
|
| 55 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 56 | + * @param string $message Log message. |
|
| 57 | + * @param string $source Log source. Useful for filtering and sorting. |
|
| 58 | + * @param array $context Context will be serialized and stored in database. |
|
| 59 | + * |
|
| 60 | + * @return bool True if write was successful. |
|
| 61 | + */ |
|
| 62 | + protected static function add( $timestamp, $level, $message, $source, $context ) { |
|
| 63 | + global $wpdb; |
|
| 64 | + |
|
| 65 | + $insert = array( |
|
| 66 | + 'timestamp' => date( 'Y-m-d H:i:s', $timestamp ), |
|
| 67 | + 'level' => WC_Log_Levels::get_level_severity( $level ), |
|
| 68 | + 'message' => $message, |
|
| 69 | + 'source' => $source, |
|
| 70 | + ); |
|
| 71 | + |
|
| 72 | + $format = array( |
|
| 73 | + '%s', |
|
| 74 | + '%d', |
|
| 75 | + '%s', |
|
| 76 | + '%s', |
|
| 77 | + '%s', // possible serialized context. |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + if ( ! empty( $context ) ) { |
|
| 81 | + try { |
|
| 82 | + $insert['context'] = serialize( $context ); // @codingStandardsIgnoreLine. |
|
| 83 | + } catch ( Exception $e ) { |
|
| 84 | + $insert['context'] = serialize( 'There was an error while serializing the context: ' . $e->getMessage() ); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return false !== $wpdb->insert( "{$wpdb->prefix}woocommerce_log", $insert, $format ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Clear all logs from the DB. |
|
| 93 | + * |
|
| 94 | + * @return bool True if flush was successful. |
|
| 95 | + */ |
|
| 96 | + public static function flush() { |
|
| 97 | + global $wpdb; |
|
| 98 | + |
|
| 99 | + return $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_log" ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Clear entries for a chosen handle/source. |
|
| 104 | + * |
|
| 105 | + * @param string $source Log source. |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public function clear( $source ) { |
|
| 109 | + global $wpdb; |
|
| 110 | + |
|
| 111 | + return $wpdb->query( |
|
| 112 | + $wpdb->prepare( |
|
| 113 | + "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE source = %s", |
|
| 114 | + $source |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Delete selected logs from DB. |
|
| 121 | + * |
|
| 122 | + * @param int|string|array $log_ids Log ID or array of Log IDs to be deleted. |
|
| 123 | + * |
|
| 124 | + * @return bool |
|
| 125 | + */ |
|
| 126 | + public static function delete( $log_ids ) { |
|
| 127 | + global $wpdb; |
|
| 128 | + |
|
| 129 | + if ( ! is_array( $log_ids ) ) { |
|
| 130 | + $log_ids = array( $log_ids ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $format = array_fill( 0, count( $log_ids ), '%d' ); |
|
| 134 | + $query_in = '(' . implode( ',', $format ) . ')'; |
|
| 135 | + return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE log_id IN {$query_in}", $log_ids ) ); // @codingStandardsIgnoreLine. |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Delete all logs older than a defined timestamp. |
|
| 140 | + * |
|
| 141 | + * @since 3.4.0 |
|
| 142 | + * @param integer $timestamp Timestamp to delete logs before. |
|
| 143 | + */ |
|
| 144 | + public static function delete_logs_before_timestamp( $timestamp = 0 ) { |
|
| 145 | + if ( ! $timestamp ) { |
|
| 146 | + return; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + global $wpdb; |
|
| 150 | + |
|
| 151 | + $wpdb->query( |
|
| 152 | + $wpdb->prepare( |
|
| 153 | + "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE timestamp < %s", |
|
| 154 | + date( 'Y-m-d H:i:s', $timestamp ) |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Get appropriate source based on file name. |
|
| 161 | + * |
|
| 162 | + * Try to provide an appropriate source in case none is provided. |
|
| 163 | + * |
|
| 164 | + * @return string Text to use as log source. "" (empty string) if none is found. |
|
| 165 | + */ |
|
| 166 | + protected static function get_log_source() { |
|
| 167 | + static $ignore_files = array( 'class-wc-log-handler-db', 'class-wc-logger' ); |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * PHP < 5.3.6 correct behavior |
|
| 171 | + * |
|
| 172 | + * @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters |
|
| 173 | + */ |
|
| 174 | + if ( Constants::is_defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) { |
|
| 175 | + $debug_backtrace_arg = DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:ignore PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound |
|
| 176 | + } else { |
|
| 177 | + $debug_backtrace_arg = false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $trace = debug_backtrace( $debug_backtrace_arg ); // @codingStandardsIgnoreLine. |
|
| 181 | + foreach ( $trace as $t ) { |
|
| 182 | + if ( isset( $t['file'] ) ) { |
|
| 183 | + $filename = pathinfo( $t['file'], PATHINFO_FILENAME ); |
|
| 184 | + if ( ! in_array( $filename, $ignore_files, true ) ) { |
|
| 185 | + return $filename; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return ''; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | use Automattic\Jetpack\Constants; |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if (!defined('ABSPATH')) { |
|
| 11 | 11 | exit; // Exit if accessed directly. |
| 12 | 12 | } |
| 13 | 13 | |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return bool False if value was not handled and true if value was handled. |
| 39 | 39 | */ |
| 40 | - public function handle( $timestamp, $level, $message, $context ) { |
|
| 40 | + public function handle($timestamp, $level, $message, $context) { |
|
| 41 | 41 | |
| 42 | - if ( isset( $context['source'] ) && $context['source'] ) { |
|
| 42 | + if (isset($context['source']) && $context['source']) { |
|
| 43 | 43 | $source = $context['source']; |
| 44 | 44 | } else { |
| 45 | 45 | $source = $this->get_log_source(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - return $this->add( $timestamp, $level, $message, $source, $context ); |
|
| 48 | + return $this->add($timestamp, $level, $message, $source, $context); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @return bool True if write was successful. |
| 61 | 61 | */ |
| 62 | - protected static function add( $timestamp, $level, $message, $source, $context ) { |
|
| 62 | + protected static function add($timestamp, $level, $message, $source, $context) { |
|
| 63 | 63 | global $wpdb; |
| 64 | 64 | |
| 65 | 65 | $insert = array( |
| 66 | - 'timestamp' => date( 'Y-m-d H:i:s', $timestamp ), |
|
| 67 | - 'level' => WC_Log_Levels::get_level_severity( $level ), |
|
| 66 | + 'timestamp' => date('Y-m-d H:i:s', $timestamp), |
|
| 67 | + 'level' => WC_Log_Levels::get_level_severity($level), |
|
| 68 | 68 | 'message' => $message, |
| 69 | 69 | 'source' => $source, |
| 70 | 70 | ); |
@@ -77,15 +77,15 @@ discard block |
||
| 77 | 77 | '%s', // possible serialized context. |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - if ( ! empty( $context ) ) { |
|
| 80 | + if (!empty($context)) { |
|
| 81 | 81 | try { |
| 82 | - $insert['context'] = serialize( $context ); // @codingStandardsIgnoreLine. |
|
| 83 | - } catch ( Exception $e ) { |
|
| 84 | - $insert['context'] = serialize( 'There was an error while serializing the context: ' . $e->getMessage() ); |
|
| 82 | + $insert['context'] = serialize($context); // @codingStandardsIgnoreLine. |
|
| 83 | + } catch (Exception $e) { |
|
| 84 | + $insert['context'] = serialize('There was an error while serializing the context: ' . $e->getMessage()); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return false !== $wpdb->insert( "{$wpdb->prefix}woocommerce_log", $insert, $format ); |
|
| 88 | + return false !== $wpdb->insert("{$wpdb->prefix}woocommerce_log", $insert, $format); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | public static function flush() { |
| 97 | 97 | global $wpdb; |
| 98 | 98 | |
| 99 | - return $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_log" ); |
|
| 99 | + return $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_log"); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param string $source Log source. |
| 106 | 106 | * @return bool |
| 107 | 107 | */ |
| 108 | - public function clear( $source ) { |
|
| 108 | + public function clear($source) { |
|
| 109 | 109 | global $wpdb; |
| 110 | 110 | |
| 111 | 111 | return $wpdb->query( |
@@ -123,16 +123,16 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return bool |
| 125 | 125 | */ |
| 126 | - public static function delete( $log_ids ) { |
|
| 126 | + public static function delete($log_ids) { |
|
| 127 | 127 | global $wpdb; |
| 128 | 128 | |
| 129 | - if ( ! is_array( $log_ids ) ) { |
|
| 130 | - $log_ids = array( $log_ids ); |
|
| 129 | + if (!is_array($log_ids)) { |
|
| 130 | + $log_ids = array($log_ids); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $format = array_fill( 0, count( $log_ids ), '%d' ); |
|
| 134 | - $query_in = '(' . implode( ',', $format ) . ')'; |
|
| 135 | - return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE log_id IN {$query_in}", $log_ids ) ); // @codingStandardsIgnoreLine. |
|
| 133 | + $format = array_fill(0, count($log_ids), '%d'); |
|
| 134 | + $query_in = '(' . implode(',', $format) . ')'; |
|
| 135 | + return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_log WHERE log_id IN {$query_in}", $log_ids)); // @codingStandardsIgnoreLine. |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | * @since 3.4.0 |
| 142 | 142 | * @param integer $timestamp Timestamp to delete logs before. |
| 143 | 143 | */ |
| 144 | - public static function delete_logs_before_timestamp( $timestamp = 0 ) { |
|
| 145 | - if ( ! $timestamp ) { |
|
| 144 | + public static function delete_logs_before_timestamp($timestamp = 0) { |
|
| 145 | + if (!$timestamp) { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | $wpdb->query( |
| 152 | 152 | $wpdb->prepare( |
| 153 | 153 | "DELETE FROM {$wpdb->prefix}woocommerce_log WHERE timestamp < %s", |
| 154 | - date( 'Y-m-d H:i:s', $timestamp ) |
|
| 154 | + date('Y-m-d H:i:s', $timestamp) |
|
| 155 | 155 | ) |
| 156 | 156 | ); |
| 157 | 157 | } |
@@ -164,24 +164,24 @@ discard block |
||
| 164 | 164 | * @return string Text to use as log source. "" (empty string) if none is found. |
| 165 | 165 | */ |
| 166 | 166 | protected static function get_log_source() { |
| 167 | - static $ignore_files = array( 'class-wc-log-handler-db', 'class-wc-logger' ); |
|
| 167 | + static $ignore_files = array('class-wc-log-handler-db', 'class-wc-logger'); |
|
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | 170 | * PHP < 5.3.6 correct behavior |
| 171 | 171 | * |
| 172 | 172 | * @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters |
| 173 | 173 | */ |
| 174 | - if ( Constants::is_defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) { |
|
| 174 | + if (Constants::is_defined('DEBUG_BACKTRACE_IGNORE_ARGS')) { |
|
| 175 | 175 | $debug_backtrace_arg = DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:ignore PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound |
| 176 | 176 | } else { |
| 177 | 177 | $debug_backtrace_arg = false; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - $trace = debug_backtrace( $debug_backtrace_arg ); // @codingStandardsIgnoreLine. |
|
| 181 | - foreach ( $trace as $t ) { |
|
| 182 | - if ( isset( $t['file'] ) ) { |
|
| 183 | - $filename = pathinfo( $t['file'], PATHINFO_FILENAME ); |
|
| 184 | - if ( ! in_array( $filename, $ignore_files, true ) ) { |
|
| 180 | + $trace = debug_backtrace($debug_backtrace_arg); // @codingStandardsIgnoreLine. |
|
| 181 | + foreach ($trace as $t) { |
|
| 182 | + if (isset($t['file'])) { |
|
| 183 | + $filename = pathinfo($t['file'], PATHINFO_FILENAME); |
|
| 184 | + if (!in_array($filename, $ignore_files, true)) { |
|
| 185 | 185 | return $filename; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | - exit; // Exit if accessed directly. |
|
| 9 | + exit; // Exit if accessed directly. |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -32,195 +32,195 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class WC_Log_Handler_Email extends WC_Log_Handler { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Minimum log level this handler will process. |
|
| 37 | - * |
|
| 38 | - * @var int Integer representation of minimum log level to handle. |
|
| 39 | - */ |
|
| 40 | - protected $threshold; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Stores email recipients. |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $recipients = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Stores log messages. |
|
| 51 | - * |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $logs = array(); |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Stores integer representation of maximum logged level. |
|
| 58 | - * |
|
| 59 | - * @var int |
|
| 60 | - */ |
|
| 61 | - protected $max_severity = null; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Constructor for log handler. |
|
| 65 | - * |
|
| 66 | - * @param string|array $recipients Optional. Email(s) to receive log messages. Defaults to site admin email. |
|
| 67 | - * @param string $threshold Optional. Minimum level that should receive log messages. |
|
| 68 | - * Default 'alert'. One of: emergency|alert|critical|error|warning|notice|info|debug. |
|
| 69 | - */ |
|
| 70 | - public function __construct( $recipients = null, $threshold = 'alert' ) { |
|
| 71 | - if ( null === $recipients ) { |
|
| 72 | - $recipients = get_option( 'admin_email' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ( is_array( $recipients ) ) { |
|
| 76 | - foreach ( $recipients as $recipient ) { |
|
| 77 | - $this->add_email( $recipient ); |
|
| 78 | - } |
|
| 79 | - } else { |
|
| 80 | - $this->add_email( $recipients ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $this->set_threshold( $threshold ); |
|
| 84 | - add_action( 'shutdown', array( $this, 'send_log_email' ) ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Set handler severity threshold. |
|
| 89 | - * |
|
| 90 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 91 | - */ |
|
| 92 | - public function set_threshold( $level ) { |
|
| 93 | - $this->threshold = WC_Log_Levels::get_level_severity( $level ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Determine whether handler should handle log. |
|
| 98 | - * |
|
| 99 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 100 | - * @return bool True if the log should be handled. |
|
| 101 | - */ |
|
| 102 | - protected function should_handle( $level ) { |
|
| 103 | - return $this->threshold <= WC_Log_Levels::get_level_severity( $level ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Handle a log entry. |
|
| 108 | - * |
|
| 109 | - * @param int $timestamp Log timestamp. |
|
| 110 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 111 | - * @param string $message Log message. |
|
| 112 | - * @param array $context Optional. Additional information for log handlers. |
|
| 113 | - * |
|
| 114 | - * @return bool False if value was not handled and true if value was handled. |
|
| 115 | - */ |
|
| 116 | - public function handle( $timestamp, $level, $message, $context ) { |
|
| 117 | - |
|
| 118 | - if ( $this->should_handle( $level ) ) { |
|
| 119 | - $this->add_log( $timestamp, $level, $message, $context ); |
|
| 120 | - return true; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return false; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Send log email. |
|
| 128 | - * |
|
| 129 | - * @return bool True if email is successfully sent otherwise false. |
|
| 130 | - */ |
|
| 131 | - public function send_log_email() { |
|
| 132 | - $result = false; |
|
| 133 | - |
|
| 134 | - if ( ! empty( $this->logs ) ) { |
|
| 135 | - $subject = $this->get_subject(); |
|
| 136 | - $body = $this->get_body(); |
|
| 137 | - $result = wp_mail( $this->recipients, $subject, $body ); |
|
| 138 | - $this->clear_logs(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $result; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Build subject for log email. |
|
| 146 | - * |
|
| 147 | - * @return string subject |
|
| 148 | - */ |
|
| 149 | - protected function get_subject() { |
|
| 150 | - $site_name = get_bloginfo( 'name' ); |
|
| 151 | - $max_level = strtoupper( WC_Log_Levels::get_severity_level( $this->max_severity ) ); |
|
| 152 | - $log_count = count( $this->logs ); |
|
| 153 | - |
|
| 154 | - return sprintf( |
|
| 155 | - /* translators: 1: Site name 2: Maximum level 3: Log count */ |
|
| 156 | - _n( |
|
| 157 | - '[%1$s] %2$s: %3$s WooCommerce log message', |
|
| 158 | - '[%1$s] %2$s: %3$s WooCommerce log messages', |
|
| 159 | - $log_count, |
|
| 160 | - 'woocommerce' |
|
| 161 | - ), |
|
| 162 | - $site_name, |
|
| 163 | - $max_level, |
|
| 164 | - $log_count |
|
| 165 | - ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Build body for log email. |
|
| 170 | - * |
|
| 171 | - * @return string body |
|
| 172 | - */ |
|
| 173 | - protected function get_body() { |
|
| 174 | - $site_name = get_bloginfo( 'name' ); |
|
| 175 | - $entries = implode( PHP_EOL, $this->logs ); |
|
| 176 | - $log_count = count( $this->logs ); |
|
| 177 | - return _n( |
|
| 178 | - 'You have received the following WooCommerce log message:', |
|
| 179 | - 'You have received the following WooCommerce log messages:', |
|
| 180 | - $log_count, |
|
| 181 | - 'woocommerce' |
|
| 182 | - ) . PHP_EOL |
|
| 183 | - . PHP_EOL |
|
| 184 | - . $entries |
|
| 185 | - . PHP_EOL |
|
| 186 | - . PHP_EOL |
|
| 187 | - /* translators: %s: Site name */ |
|
| 188 | - . sprintf( __( 'Visit %s admin area:', 'woocommerce' ), $site_name ) |
|
| 189 | - . PHP_EOL |
|
| 190 | - . admin_url(); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Adds an email to the list of recipients. |
|
| 195 | - * |
|
| 196 | - * @param string $email Email address to add. |
|
| 197 | - */ |
|
| 198 | - public function add_email( $email ) { |
|
| 199 | - array_push( $this->recipients, $email ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Add log message. |
|
| 204 | - * |
|
| 205 | - * @param int $timestamp Log timestamp. |
|
| 206 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 207 | - * @param string $message Log message. |
|
| 208 | - * @param array $context Additional information for log handlers. |
|
| 209 | - */ |
|
| 210 | - protected function add_log( $timestamp, $level, $message, $context ) { |
|
| 211 | - $this->logs[] = $this->format_entry( $timestamp, $level, $message, $context ); |
|
| 212 | - |
|
| 213 | - $log_severity = WC_Log_Levels::get_level_severity( $level ); |
|
| 214 | - if ( $this->max_severity < $log_severity ) { |
|
| 215 | - $this->max_severity = $log_severity; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Clear log messages. |
|
| 221 | - */ |
|
| 222 | - protected function clear_logs() { |
|
| 223 | - $this->logs = array(); |
|
| 224 | - } |
|
| 35 | + /** |
|
| 36 | + * Minimum log level this handler will process. |
|
| 37 | + * |
|
| 38 | + * @var int Integer representation of minimum log level to handle. |
|
| 39 | + */ |
|
| 40 | + protected $threshold; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Stores email recipients. |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $recipients = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Stores log messages. |
|
| 51 | + * |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $logs = array(); |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Stores integer representation of maximum logged level. |
|
| 58 | + * |
|
| 59 | + * @var int |
|
| 60 | + */ |
|
| 61 | + protected $max_severity = null; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Constructor for log handler. |
|
| 65 | + * |
|
| 66 | + * @param string|array $recipients Optional. Email(s) to receive log messages. Defaults to site admin email. |
|
| 67 | + * @param string $threshold Optional. Minimum level that should receive log messages. |
|
| 68 | + * Default 'alert'. One of: emergency|alert|critical|error|warning|notice|info|debug. |
|
| 69 | + */ |
|
| 70 | + public function __construct( $recipients = null, $threshold = 'alert' ) { |
|
| 71 | + if ( null === $recipients ) { |
|
| 72 | + $recipients = get_option( 'admin_email' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ( is_array( $recipients ) ) { |
|
| 76 | + foreach ( $recipients as $recipient ) { |
|
| 77 | + $this->add_email( $recipient ); |
|
| 78 | + } |
|
| 79 | + } else { |
|
| 80 | + $this->add_email( $recipients ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $this->set_threshold( $threshold ); |
|
| 84 | + add_action( 'shutdown', array( $this, 'send_log_email' ) ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Set handler severity threshold. |
|
| 89 | + * |
|
| 90 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 91 | + */ |
|
| 92 | + public function set_threshold( $level ) { |
|
| 93 | + $this->threshold = WC_Log_Levels::get_level_severity( $level ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Determine whether handler should handle log. |
|
| 98 | + * |
|
| 99 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 100 | + * @return bool True if the log should be handled. |
|
| 101 | + */ |
|
| 102 | + protected function should_handle( $level ) { |
|
| 103 | + return $this->threshold <= WC_Log_Levels::get_level_severity( $level ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Handle a log entry. |
|
| 108 | + * |
|
| 109 | + * @param int $timestamp Log timestamp. |
|
| 110 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 111 | + * @param string $message Log message. |
|
| 112 | + * @param array $context Optional. Additional information for log handlers. |
|
| 113 | + * |
|
| 114 | + * @return bool False if value was not handled and true if value was handled. |
|
| 115 | + */ |
|
| 116 | + public function handle( $timestamp, $level, $message, $context ) { |
|
| 117 | + |
|
| 118 | + if ( $this->should_handle( $level ) ) { |
|
| 119 | + $this->add_log( $timestamp, $level, $message, $context ); |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return false; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Send log email. |
|
| 128 | + * |
|
| 129 | + * @return bool True if email is successfully sent otherwise false. |
|
| 130 | + */ |
|
| 131 | + public function send_log_email() { |
|
| 132 | + $result = false; |
|
| 133 | + |
|
| 134 | + if ( ! empty( $this->logs ) ) { |
|
| 135 | + $subject = $this->get_subject(); |
|
| 136 | + $body = $this->get_body(); |
|
| 137 | + $result = wp_mail( $this->recipients, $subject, $body ); |
|
| 138 | + $this->clear_logs(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $result; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Build subject for log email. |
|
| 146 | + * |
|
| 147 | + * @return string subject |
|
| 148 | + */ |
|
| 149 | + protected function get_subject() { |
|
| 150 | + $site_name = get_bloginfo( 'name' ); |
|
| 151 | + $max_level = strtoupper( WC_Log_Levels::get_severity_level( $this->max_severity ) ); |
|
| 152 | + $log_count = count( $this->logs ); |
|
| 153 | + |
|
| 154 | + return sprintf( |
|
| 155 | + /* translators: 1: Site name 2: Maximum level 3: Log count */ |
|
| 156 | + _n( |
|
| 157 | + '[%1$s] %2$s: %3$s WooCommerce log message', |
|
| 158 | + '[%1$s] %2$s: %3$s WooCommerce log messages', |
|
| 159 | + $log_count, |
|
| 160 | + 'woocommerce' |
|
| 161 | + ), |
|
| 162 | + $site_name, |
|
| 163 | + $max_level, |
|
| 164 | + $log_count |
|
| 165 | + ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Build body for log email. |
|
| 170 | + * |
|
| 171 | + * @return string body |
|
| 172 | + */ |
|
| 173 | + protected function get_body() { |
|
| 174 | + $site_name = get_bloginfo( 'name' ); |
|
| 175 | + $entries = implode( PHP_EOL, $this->logs ); |
|
| 176 | + $log_count = count( $this->logs ); |
|
| 177 | + return _n( |
|
| 178 | + 'You have received the following WooCommerce log message:', |
|
| 179 | + 'You have received the following WooCommerce log messages:', |
|
| 180 | + $log_count, |
|
| 181 | + 'woocommerce' |
|
| 182 | + ) . PHP_EOL |
|
| 183 | + . PHP_EOL |
|
| 184 | + . $entries |
|
| 185 | + . PHP_EOL |
|
| 186 | + . PHP_EOL |
|
| 187 | + /* translators: %s: Site name */ |
|
| 188 | + . sprintf( __( 'Visit %s admin area:', 'woocommerce' ), $site_name ) |
|
| 189 | + . PHP_EOL |
|
| 190 | + . admin_url(); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Adds an email to the list of recipients. |
|
| 195 | + * |
|
| 196 | + * @param string $email Email address to add. |
|
| 197 | + */ |
|
| 198 | + public function add_email( $email ) { |
|
| 199 | + array_push( $this->recipients, $email ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Add log message. |
|
| 204 | + * |
|
| 205 | + * @param int $timestamp Log timestamp. |
|
| 206 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
|
| 207 | + * @param string $message Log message. |
|
| 208 | + * @param array $context Additional information for log handlers. |
|
| 209 | + */ |
|
| 210 | + protected function add_log( $timestamp, $level, $message, $context ) { |
|
| 211 | + $this->logs[] = $this->format_entry( $timestamp, $level, $message, $context ); |
|
| 212 | + |
|
| 213 | + $log_severity = WC_Log_Levels::get_level_severity( $level ); |
|
| 214 | + if ( $this->max_severity < $log_severity ) { |
|
| 215 | + $this->max_severity = $log_severity; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Clear log messages. |
|
| 221 | + */ |
|
| 222 | + protected function clear_logs() { |
|
| 223 | + $this->logs = array(); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * @package WooCommerce\Log Handlers |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | +if (!defined('ABSPATH')) { |
|
| 9 | 9 | exit; // Exit if accessed directly. |
| 10 | 10 | } |
| 11 | 11 | |
@@ -67,21 +67,21 @@ discard block |
||
| 67 | 67 | * @param string $threshold Optional. Minimum level that should receive log messages. |
| 68 | 68 | * Default 'alert'. One of: emergency|alert|critical|error|warning|notice|info|debug. |
| 69 | 69 | */ |
| 70 | - public function __construct( $recipients = null, $threshold = 'alert' ) { |
|
| 71 | - if ( null === $recipients ) { |
|
| 72 | - $recipients = get_option( 'admin_email' ); |
|
| 70 | + public function __construct($recipients = null, $threshold = 'alert') { |
|
| 71 | + if (null === $recipients) { |
|
| 72 | + $recipients = get_option('admin_email'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( is_array( $recipients ) ) { |
|
| 76 | - foreach ( $recipients as $recipient ) { |
|
| 77 | - $this->add_email( $recipient ); |
|
| 75 | + if (is_array($recipients)) { |
|
| 76 | + foreach ($recipients as $recipient) { |
|
| 77 | + $this->add_email($recipient); |
|
| 78 | 78 | } |
| 79 | 79 | } else { |
| 80 | - $this->add_email( $recipients ); |
|
| 80 | + $this->add_email($recipients); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $this->set_threshold( $threshold ); |
|
| 84 | - add_action( 'shutdown', array( $this, 'send_log_email' ) ); |
|
| 83 | + $this->set_threshold($threshold); |
|
| 84 | + add_action('shutdown', array($this, 'send_log_email')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
| 91 | 91 | */ |
| 92 | - public function set_threshold( $level ) { |
|
| 93 | - $this->threshold = WC_Log_Levels::get_level_severity( $level ); |
|
| 92 | + public function set_threshold($level) { |
|
| 93 | + $this->threshold = WC_Log_Levels::get_level_severity($level); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | * @param string $level emergency|alert|critical|error|warning|notice|info|debug. |
| 100 | 100 | * @return bool True if the log should be handled. |
| 101 | 101 | */ |
| 102 | - protected function should_handle( $level ) { |
|
| 103 | - return $this->threshold <= WC_Log_Levels::get_level_severity( $level ); |
|
| 102 | + protected function should_handle($level) { |
|
| 103 | + return $this->threshold <= WC_Log_Levels::get_level_severity($level); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return bool False if value was not handled and true if value was handled. |
| 115 | 115 | */ |
| 116 | - public function handle( $timestamp, $level, $message, $context ) { |
|
| 116 | + public function handle($timestamp, $level, $message, $context) { |
|
| 117 | 117 | |
| 118 | - if ( $this->should_handle( $level ) ) { |
|
| 119 | - $this->add_log( $timestamp, $level, $message, $context ); |
|
| 118 | + if ($this->should_handle($level)) { |
|
| 119 | + $this->add_log($timestamp, $level, $message, $context); |
|
| 120 | 120 | return true; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | public function send_log_email() { |
| 132 | 132 | $result = false; |
| 133 | 133 | |
| 134 | - if ( ! empty( $this->logs ) ) { |
|
| 134 | + if (!empty($this->logs)) { |
|
| 135 | 135 | $subject = $this->get_subject(); |
| 136 | 136 | $body = $this->get_body(); |
| 137 | - $result = wp_mail( $this->recipients, $subject, $body ); |
|
| 137 | + $result = wp_mail($this->recipients, $subject, $body); |
|
| 138 | 138 | $this->clear_logs(); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | * @return string subject |
| 148 | 148 | */ |
| 149 | 149 | protected function get_subject() { |
| 150 | - $site_name = get_bloginfo( 'name' ); |
|
| 151 | - $max_level = strtoupper( WC_Log_Levels::get_severity_level( $this->max_severity ) ); |
|
| 152 | - $log_count = count( $this->logs ); |
|
| 150 | + $site_name = get_bloginfo('name'); |
|
| 151 | + $max_level = strtoupper(WC_Log_Levels::get_severity_level($this->max_severity)); |
|
| 152 | + $log_count = count($this->logs); |
|
| 153 | 153 | |
| 154 | 154 | return sprintf( |
| 155 | 155 | /* translators: 1: Site name 2: Maximum level 3: Log count */ |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | * @return string body |
| 172 | 172 | */ |
| 173 | 173 | protected function get_body() { |
| 174 | - $site_name = get_bloginfo( 'name' ); |
|
| 175 | - $entries = implode( PHP_EOL, $this->logs ); |
|
| 176 | - $log_count = count( $this->logs ); |
|
| 174 | + $site_name = get_bloginfo('name'); |
|
| 175 | + $entries = implode(PHP_EOL, $this->logs); |
|
| 176 | + $log_count = count($this->logs); |
|
| 177 | 177 | return _n( |
| 178 | 178 | 'You have received the following WooCommerce log message:', |
| 179 | 179 | 'You have received the following WooCommerce log messages:', |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | . PHP_EOL |
| 186 | 186 | . PHP_EOL |
| 187 | 187 | /* translators: %s: Site name */ |
| 188 | - . sprintf( __( 'Visit %s admin area:', 'woocommerce' ), $site_name ) |
|
| 188 | + . sprintf(__('Visit %s admin area:', 'woocommerce'), $site_name) |
|
| 189 | 189 | . PHP_EOL |
| 190 | 190 | . admin_url(); |
| 191 | 191 | } |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @param string $email Email address to add. |
| 197 | 197 | */ |
| 198 | - public function add_email( $email ) { |
|
| 199 | - array_push( $this->recipients, $email ); |
|
| 198 | + public function add_email($email) { |
|
| 199 | + array_push($this->recipients, $email); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @param string $message Log message. |
| 208 | 208 | * @param array $context Additional information for log handlers. |
| 209 | 209 | */ |
| 210 | - protected function add_log( $timestamp, $level, $message, $context ) { |
|
| 211 | - $this->logs[] = $this->format_entry( $timestamp, $level, $message, $context ); |
|
| 210 | + protected function add_log($timestamp, $level, $message, $context) { |
|
| 211 | + $this->logs[] = $this->format_entry($timestamp, $level, $message, $context); |
|
| 212 | 212 | |
| 213 | - $log_severity = WC_Log_Levels::get_level_severity( $level ); |
|
| 214 | - if ( $this->max_severity < $log_severity ) { |
|
| 213 | + $log_severity = WC_Log_Levels::get_level_severity($level); |
|
| 214 | + if ($this->max_severity < $log_severity) { |
|
| 215 | 215 | $this->max_severity = $log_severity; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -21,1071 +21,1071 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class WC_Install { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * DB updates and callbacks that need to be run per version. |
|
| 26 | - * |
|
| 27 | - * Please note that these functions are invoked when WooCommerce is updated from a previous version, |
|
| 28 | - * but NOT when WooCommerce is newly installed. |
|
| 29 | - * |
|
| 30 | - * Database schema changes must be incorporated to the SQL returned by get_schema, which is applied |
|
| 31 | - * via dbDelta at both install and update time. If any other kind of database change is required |
|
| 32 | - * at install time (e.g. populating tables), use the 'woocommerce_installed' hook. |
|
| 33 | - * |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - private static $db_updates = array( |
|
| 37 | - '2.0.0' => array( |
|
| 38 | - 'wc_update_200_file_paths', |
|
| 39 | - 'wc_update_200_permalinks', |
|
| 40 | - 'wc_update_200_subcat_display', |
|
| 41 | - 'wc_update_200_taxrates', |
|
| 42 | - 'wc_update_200_line_items', |
|
| 43 | - 'wc_update_200_images', |
|
| 44 | - 'wc_update_200_db_version', |
|
| 45 | - ), |
|
| 46 | - '2.0.9' => array( |
|
| 47 | - 'wc_update_209_brazillian_state', |
|
| 48 | - 'wc_update_209_db_version', |
|
| 49 | - ), |
|
| 50 | - '2.1.0' => array( |
|
| 51 | - 'wc_update_210_remove_pages', |
|
| 52 | - 'wc_update_210_file_paths', |
|
| 53 | - 'wc_update_210_db_version', |
|
| 54 | - ), |
|
| 55 | - '2.2.0' => array( |
|
| 56 | - 'wc_update_220_shipping', |
|
| 57 | - 'wc_update_220_order_status', |
|
| 58 | - 'wc_update_220_variations', |
|
| 59 | - 'wc_update_220_attributes', |
|
| 60 | - 'wc_update_220_db_version', |
|
| 61 | - ), |
|
| 62 | - '2.3.0' => array( |
|
| 63 | - 'wc_update_230_options', |
|
| 64 | - 'wc_update_230_db_version', |
|
| 65 | - ), |
|
| 66 | - '2.4.0' => array( |
|
| 67 | - 'wc_update_240_options', |
|
| 68 | - 'wc_update_240_shipping_methods', |
|
| 69 | - 'wc_update_240_api_keys', |
|
| 70 | - 'wc_update_240_refunds', |
|
| 71 | - 'wc_update_240_db_version', |
|
| 72 | - ), |
|
| 73 | - '2.4.1' => array( |
|
| 74 | - 'wc_update_241_variations', |
|
| 75 | - 'wc_update_241_db_version', |
|
| 76 | - ), |
|
| 77 | - '2.5.0' => array( |
|
| 78 | - 'wc_update_250_currency', |
|
| 79 | - 'wc_update_250_db_version', |
|
| 80 | - ), |
|
| 81 | - '2.6.0' => array( |
|
| 82 | - 'wc_update_260_options', |
|
| 83 | - 'wc_update_260_termmeta', |
|
| 84 | - 'wc_update_260_zones', |
|
| 85 | - 'wc_update_260_zone_methods', |
|
| 86 | - 'wc_update_260_refunds', |
|
| 87 | - 'wc_update_260_db_version', |
|
| 88 | - ), |
|
| 89 | - '3.0.0' => array( |
|
| 90 | - 'wc_update_300_grouped_products', |
|
| 91 | - 'wc_update_300_settings', |
|
| 92 | - 'wc_update_300_product_visibility', |
|
| 93 | - 'wc_update_300_db_version', |
|
| 94 | - ), |
|
| 95 | - '3.1.0' => array( |
|
| 96 | - 'wc_update_310_downloadable_products', |
|
| 97 | - 'wc_update_310_old_comments', |
|
| 98 | - 'wc_update_310_db_version', |
|
| 99 | - ), |
|
| 100 | - '3.1.2' => array( |
|
| 101 | - 'wc_update_312_shop_manager_capabilities', |
|
| 102 | - 'wc_update_312_db_version', |
|
| 103 | - ), |
|
| 104 | - '3.2.0' => array( |
|
| 105 | - 'wc_update_320_mexican_states', |
|
| 106 | - 'wc_update_320_db_version', |
|
| 107 | - ), |
|
| 108 | - '3.3.0' => array( |
|
| 109 | - 'wc_update_330_image_options', |
|
| 110 | - 'wc_update_330_webhooks', |
|
| 111 | - 'wc_update_330_product_stock_status', |
|
| 112 | - 'wc_update_330_set_default_product_cat', |
|
| 113 | - 'wc_update_330_clear_transients', |
|
| 114 | - 'wc_update_330_set_paypal_sandbox_credentials', |
|
| 115 | - 'wc_update_330_db_version', |
|
| 116 | - ), |
|
| 117 | - '3.4.0' => array( |
|
| 118 | - 'wc_update_340_states', |
|
| 119 | - 'wc_update_340_state', |
|
| 120 | - 'wc_update_340_last_active', |
|
| 121 | - 'wc_update_340_db_version', |
|
| 122 | - ), |
|
| 123 | - '3.4.3' => array( |
|
| 124 | - 'wc_update_343_cleanup_foreign_keys', |
|
| 125 | - 'wc_update_343_db_version', |
|
| 126 | - ), |
|
| 127 | - '3.4.4' => array( |
|
| 128 | - 'wc_update_344_recreate_roles', |
|
| 129 | - 'wc_update_344_db_version', |
|
| 130 | - ), |
|
| 131 | - '3.5.0' => array( |
|
| 132 | - 'wc_update_350_reviews_comment_type', |
|
| 133 | - 'wc_update_350_db_version', |
|
| 134 | - ), |
|
| 135 | - '3.5.2' => array( |
|
| 136 | - 'wc_update_352_drop_download_log_fk', |
|
| 137 | - ), |
|
| 138 | - '3.5.4' => array( |
|
| 139 | - 'wc_update_354_modify_shop_manager_caps', |
|
| 140 | - 'wc_update_354_db_version', |
|
| 141 | - ), |
|
| 142 | - '3.6.0' => array( |
|
| 143 | - 'wc_update_360_product_lookup_tables', |
|
| 144 | - 'wc_update_360_term_meta', |
|
| 145 | - 'wc_update_360_downloadable_product_permissions_index', |
|
| 146 | - 'wc_update_360_db_version', |
|
| 147 | - ), |
|
| 148 | - '3.7.0' => array( |
|
| 149 | - 'wc_update_370_tax_rate_classes', |
|
| 150 | - 'wc_update_370_mro_std_currency', |
|
| 151 | - 'wc_update_370_db_version', |
|
| 152 | - ), |
|
| 153 | - '3.9.0' => array( |
|
| 154 | - 'wc_update_390_move_maxmind_database', |
|
| 155 | - 'wc_update_390_change_geolocation_database_update_cron', |
|
| 156 | - 'wc_update_390_db_version', |
|
| 157 | - ), |
|
| 158 | - '4.0.0' => array( |
|
| 159 | - 'wc_update_product_lookup_tables', |
|
| 160 | - 'wc_update_400_increase_size_of_column', |
|
| 161 | - 'wc_update_400_reset_action_scheduler_migration_status', |
|
| 162 | - 'wc_admin_update_0201_order_status_index', |
|
| 163 | - 'wc_admin_update_0230_rename_gross_total', |
|
| 164 | - 'wc_admin_update_0251_remove_unsnooze_action', |
|
| 165 | - 'wc_update_400_db_version', |
|
| 166 | - ), |
|
| 167 | - '4.4.0' => array( |
|
| 168 | - 'wc_update_440_insert_attribute_terms_for_variable_products', |
|
| 169 | - 'wc_admin_update_110_remove_facebook_note', |
|
| 170 | - 'wc_admin_update_130_remove_dismiss_action_from_tracking_opt_in_note', |
|
| 171 | - 'wc_update_440_db_version', |
|
| 172 | - ), |
|
| 173 | - '4.5.0' => array( |
|
| 174 | - 'wc_update_450_sanitize_coupons_code', |
|
| 175 | - 'wc_update_450_db_version', |
|
| 176 | - ), |
|
| 177 | - '5.0.0' => array( |
|
| 178 | - 'wc_update_500_fix_product_review_count', |
|
| 179 | - 'wc_admin_update_160_remove_facebook_note', |
|
| 180 | - 'wc_admin_update_170_homescreen_layout', |
|
| 181 | - 'wc_update_500_db_version', |
|
| 182 | - ), |
|
| 183 | - '5.6.0' => array( |
|
| 184 | - 'wc_update_560_create_refund_returns_page', |
|
| 185 | - 'wc_update_560_db_version', |
|
| 186 | - ), |
|
| 187 | - '6.0.0' => array( |
|
| 188 | - 'wc_update_600_migrate_rate_limit_options', |
|
| 189 | - 'wc_admin_update_270_delete_report_downloads', |
|
| 190 | - 'wc_admin_update_271_update_task_list_options', |
|
| 191 | - 'wc_admin_update_280_order_status', |
|
| 192 | - 'wc_admin_update_290_update_apperance_task_option', |
|
| 193 | - 'wc_admin_update_290_delete_default_homepage_layout_option', |
|
| 194 | - 'wc_update_600_db_version', |
|
| 195 | - ), |
|
| 196 | - '6.3.0' => array( |
|
| 197 | - 'wc_update_630_create_product_attributes_lookup_table', |
|
| 198 | - 'wc_admin_update_300_update_is_read_from_last_read', |
|
| 199 | - 'wc_update_630_db_version', |
|
| 200 | - ), |
|
| 201 | - '6.4.0' => array( |
|
| 202 | - 'wc_update_640_add_primary_key_to_product_attributes_lookup_table', |
|
| 203 | - 'wc_admin_update_340_remove_is_primary_from_note_action', |
|
| 204 | - 'wc_update_640_db_version', |
|
| 205 | - ), |
|
| 206 | - '6.5.0' => array( |
|
| 207 | - 'wc_update_650_approved_download_directories', |
|
| 208 | - ), |
|
| 209 | - '6.5.1' => array( |
|
| 210 | - 'wc_update_651_approved_download_directories', |
|
| 211 | - ), |
|
| 212 | - '6.7.0' => array( |
|
| 213 | - 'wc_update_670_purge_comments_count_cache', |
|
| 214 | - 'wc_update_670_delete_deprecated_remote_inbox_notifications_option', |
|
| 215 | - ), |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Hook in tabs. |
|
| 220 | - */ |
|
| 221 | - public static function init() { |
|
| 222 | - add_action( 'init', array( __CLASS__, 'check_version' ), 5 ); |
|
| 223 | - add_action( 'init', array( __CLASS__, 'manual_database_update' ), 20 ); |
|
| 224 | - add_action( 'admin_init', array( __CLASS__, 'wc_admin_db_update_notice' ) ); |
|
| 225 | - add_action( 'admin_init', array( __CLASS__, 'add_admin_note_after_page_created' ) ); |
|
| 226 | - add_action( 'woocommerce_run_update_callback', array( __CLASS__, 'run_update_callback' ) ); |
|
| 227 | - add_action( 'woocommerce_update_db_to_current_version', array( __CLASS__, 'update_db_version' ) ); |
|
| 228 | - add_action( 'admin_init', array( __CLASS__, 'install_actions' ) ); |
|
| 229 | - add_action( 'woocommerce_page_created', array( __CLASS__, 'page_created' ), 10, 2 ); |
|
| 230 | - add_filter( 'plugin_action_links_' . WC_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) ); |
|
| 231 | - add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 ); |
|
| 232 | - add_filter( 'wpmu_drop_tables', array( __CLASS__, 'wpmu_drop_tables' ) ); |
|
| 233 | - add_filter( 'cron_schedules', array( __CLASS__, 'cron_schedules' ) ); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Check WooCommerce version and run the updater is required. |
|
| 238 | - * |
|
| 239 | - * This check is done on all requests and runs if the versions do not match. |
|
| 240 | - */ |
|
| 241 | - public static function check_version() { |
|
| 242 | - $wc_version = get_option( 'woocommerce_version' ); |
|
| 243 | - $wc_code_version = WC()->version; |
|
| 244 | - $requires_update = version_compare( $wc_version, $wc_code_version, '<' ); |
|
| 245 | - if ( ! Constants::is_defined( 'IFRAME_REQUEST' ) && $requires_update ) { |
|
| 246 | - self::install(); |
|
| 247 | - /** |
|
| 248 | - * Run after WooCommerce has been updated. |
|
| 249 | - * |
|
| 250 | - * @since 2.2.0 |
|
| 251 | - */ |
|
| 252 | - do_action( 'woocommerce_updated' ); |
|
| 253 | - do_action_deprecated( 'woocommerce_admin_updated', array(), $wc_code_version, 'woocommerce_updated' ); |
|
| 254 | - // If there is no woocommerce_version option, consider it as a new install. |
|
| 255 | - if ( ! $wc_version ) { |
|
| 256 | - /** |
|
| 257 | - * Run when WooCommerce has been installed for the first time. |
|
| 258 | - * |
|
| 259 | - * @since 6.5.0 |
|
| 260 | - */ |
|
| 261 | - do_action( 'woocommerce_newly_installed' ); |
|
| 262 | - do_action_deprecated( 'woocommerce_admin_newly_installed', array(), $wc_code_version, 'woocommerce_newly_installed' ); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Performan manual database update when triggered by WooCommerce System Tools. |
|
| 269 | - * |
|
| 270 | - * @since 3.6.5 |
|
| 271 | - */ |
|
| 272 | - public static function manual_database_update() { |
|
| 273 | - $blog_id = get_current_blog_id(); |
|
| 274 | - |
|
| 275 | - add_action( 'wp_' . $blog_id . '_wc_updater_cron', array( __CLASS__, 'run_manual_database_update' ) ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Add WC Admin based db update notice. |
|
| 280 | - * |
|
| 281 | - * @since 4.0.0 |
|
| 282 | - */ |
|
| 283 | - public static function wc_admin_db_update_notice() { |
|
| 284 | - if ( |
|
| 285 | - WC()->is_wc_admin_active() && |
|
| 286 | - false !== get_option( 'woocommerce_admin_install_timestamp' ) |
|
| 287 | - ) { |
|
| 288 | - new WC_Notes_Run_Db_Update(); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Run manual database update. |
|
| 294 | - */ |
|
| 295 | - public static function run_manual_database_update() { |
|
| 296 | - self::update(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Run an update callback when triggered by ActionScheduler. |
|
| 301 | - * |
|
| 302 | - * @param string $update_callback Callback name. |
|
| 303 | - * |
|
| 304 | - * @since 3.6.0 |
|
| 305 | - */ |
|
| 306 | - public static function run_update_callback( $update_callback ) { |
|
| 307 | - include_once dirname( __FILE__ ) . '/wc-update-functions.php'; |
|
| 308 | - |
|
| 309 | - if ( is_callable( $update_callback ) ) { |
|
| 310 | - self::run_update_callback_start( $update_callback ); |
|
| 311 | - $result = (bool) call_user_func( $update_callback ); |
|
| 312 | - self::run_update_callback_end( $update_callback, $result ); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Triggered when a callback will run. |
|
| 318 | - * |
|
| 319 | - * @since 3.6.0 |
|
| 320 | - * @param string $callback Callback name. |
|
| 321 | - */ |
|
| 322 | - protected static function run_update_callback_start( $callback ) { |
|
| 323 | - wc_maybe_define_constant( 'WC_UPDATING', true ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Triggered when a callback has ran. |
|
| 328 | - * |
|
| 329 | - * @since 3.6.0 |
|
| 330 | - * @param string $callback Callback name. |
|
| 331 | - * @param bool $result Return value from callback. Non-false need to run again. |
|
| 332 | - */ |
|
| 333 | - protected static function run_update_callback_end( $callback, $result ) { |
|
| 334 | - if ( $result ) { |
|
| 335 | - WC()->queue()->add( |
|
| 336 | - 'woocommerce_run_update_callback', |
|
| 337 | - array( |
|
| 338 | - 'update_callback' => $callback, |
|
| 339 | - ), |
|
| 340 | - 'woocommerce-db-updates' |
|
| 341 | - ); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Install actions when a update button is clicked within the admin area. |
|
| 347 | - * |
|
| 348 | - * This function is hooked into admin_init to affect admin only. |
|
| 349 | - */ |
|
| 350 | - public static function install_actions() { |
|
| 351 | - if ( ! empty( $_GET['do_update_woocommerce'] ) ) { // WPCS: input var ok. |
|
| 352 | - check_admin_referer( 'wc_db_update', 'wc_db_update_nonce' ); |
|
| 353 | - self::update(); |
|
| 354 | - WC_Admin_Notices::add_notice( 'update', true ); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Install WC. |
|
| 360 | - */ |
|
| 361 | - public static function install() { |
|
| 362 | - if ( ! is_blog_installed() ) { |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Check if we are not already running this routine. |
|
| 367 | - if ( self::is_installing() ) { |
|
| 368 | - return; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // If we made it till here nothing is running yet, lets set the transient now. |
|
| 372 | - set_transient( 'wc_installing', 'yes', MINUTE_IN_SECONDS * 10 ); |
|
| 373 | - wc_maybe_define_constant( 'WC_INSTALLING', true ); |
|
| 374 | - |
|
| 375 | - WC()->wpdb_table_fix(); |
|
| 376 | - self::remove_admin_notices(); |
|
| 377 | - self::create_tables(); |
|
| 378 | - self::verify_base_tables(); |
|
| 379 | - self::create_options(); |
|
| 380 | - self::migrate_options(); |
|
| 381 | - self::create_roles(); |
|
| 382 | - self::setup_environment(); |
|
| 383 | - self::create_terms(); |
|
| 384 | - self::create_cron_jobs(); |
|
| 385 | - self::delete_obsolete_notes(); |
|
| 386 | - self::create_files(); |
|
| 387 | - self::maybe_create_pages(); |
|
| 388 | - self::maybe_set_activation_transients(); |
|
| 389 | - self::set_paypal_standard_load_eligibility(); |
|
| 390 | - self::update_wc_version(); |
|
| 391 | - self::maybe_update_db_version(); |
|
| 392 | - |
|
| 393 | - delete_transient( 'wc_installing' ); |
|
| 394 | - |
|
| 395 | - // Use add_option() here to avoid overwriting this value with each |
|
| 396 | - // plugin version update. We base plugin age off of this value. |
|
| 397 | - add_option( 'woocommerce_admin_install_timestamp', time() ); |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Flush the rewrite rules after install or update. |
|
| 401 | - * |
|
| 402 | - * @since 2.7.0 |
|
| 403 | - */ |
|
| 404 | - do_action( 'woocommerce_flush_rewrite_rules' ); |
|
| 405 | - /** |
|
| 406 | - * Run after WooCommerce has been installed or updated. |
|
| 407 | - * |
|
| 408 | - * @since 3.2.0 |
|
| 409 | - */ |
|
| 410 | - do_action( 'woocommerce_installed' ); |
|
| 411 | - /** |
|
| 412 | - * Run after WooCommerce Admin has been installed or updated. |
|
| 413 | - * |
|
| 414 | - * @since 6.5.0 |
|
| 415 | - */ |
|
| 416 | - do_action( 'woocommerce_admin_installed' ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Returns true if we're installing. |
|
| 421 | - * |
|
| 422 | - * @return bool |
|
| 423 | - */ |
|
| 424 | - private static function is_installing() { |
|
| 425 | - return 'yes' === get_transient( 'wc_installing' ); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Check if all the base tables are present. |
|
| 430 | - * |
|
| 431 | - * @param bool $modify_notice Whether to modify notice based on if all tables are present. |
|
| 432 | - * @param bool $execute Whether to execute get_schema queries as well. |
|
| 433 | - * |
|
| 434 | - * @return array List of queries. |
|
| 435 | - */ |
|
| 436 | - public static function verify_base_tables( $modify_notice = true, $execute = false ) { |
|
| 437 | - if ( $execute ) { |
|
| 438 | - self::create_tables(); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $missing_tables = wc_get_container() |
|
| 442 | - ->get( DatabaseUtil::class ) |
|
| 443 | - ->get_missing_tables( self::get_schema() ); |
|
| 444 | - |
|
| 445 | - if ( 0 < count( $missing_tables ) ) { |
|
| 446 | - if ( $modify_notice ) { |
|
| 447 | - WC_Admin_Notices::add_notice( 'base_tables_missing' ); |
|
| 448 | - } |
|
| 449 | - update_option( 'woocommerce_schema_missing_tables', $missing_tables ); |
|
| 450 | - } else { |
|
| 451 | - if ( $modify_notice ) { |
|
| 452 | - WC_Admin_Notices::remove_notice( 'base_tables_missing' ); |
|
| 453 | - } |
|
| 454 | - update_option( 'woocommerce_schema_version', WC()->db_version ); |
|
| 455 | - delete_option( 'woocommerce_schema_missing_tables' ); |
|
| 456 | - } |
|
| 457 | - return $missing_tables; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Reset any notices added to admin. |
|
| 462 | - * |
|
| 463 | - * @since 3.2.0 |
|
| 464 | - */ |
|
| 465 | - private static function remove_admin_notices() { |
|
| 466 | - include_once dirname( __FILE__ ) . '/admin/class-wc-admin-notices.php'; |
|
| 467 | - WC_Admin_Notices::remove_all_notices(); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Setup WC environment - post types, taxonomies, endpoints. |
|
| 472 | - * |
|
| 473 | - * @since 3.2.0 |
|
| 474 | - */ |
|
| 475 | - private static function setup_environment() { |
|
| 476 | - WC_Post_types::register_post_types(); |
|
| 477 | - WC_Post_types::register_taxonomies(); |
|
| 478 | - WC()->query->init_query_vars(); |
|
| 479 | - WC()->query->add_endpoints(); |
|
| 480 | - WC_API::add_endpoint(); |
|
| 481 | - WC_Auth::add_endpoint(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Is this a brand new WC install? |
|
| 486 | - * |
|
| 487 | - * A brand new install has no version yet. Also treat empty installs as 'new'. |
|
| 488 | - * |
|
| 489 | - * @since 3.2.0 |
|
| 490 | - * @return boolean |
|
| 491 | - */ |
|
| 492 | - public static function is_new_install() { |
|
| 493 | - $product_count = array_sum( (array) wp_count_posts( 'product' ) ); |
|
| 494 | - |
|
| 495 | - return is_null( get_option( 'woocommerce_version', null ) ) || ( 0 === $product_count && -1 === wc_get_page_id( 'shop' ) ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Is a DB update needed? |
|
| 500 | - * |
|
| 501 | - * @since 3.2.0 |
|
| 502 | - * @return boolean |
|
| 503 | - */ |
|
| 504 | - public static function needs_db_update() { |
|
| 505 | - $current_db_version = get_option( 'woocommerce_db_version', null ); |
|
| 506 | - $updates = self::get_db_update_callbacks(); |
|
| 507 | - $update_versions = array_keys( $updates ); |
|
| 508 | - usort( $update_versions, 'version_compare' ); |
|
| 509 | - |
|
| 510 | - return ! is_null( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' ); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * See if we need to set redirect transients for activation or not. |
|
| 515 | - * |
|
| 516 | - * @since 4.6.0 |
|
| 517 | - */ |
|
| 518 | - private static function maybe_set_activation_transients() { |
|
| 519 | - if ( self::is_new_install() ) { |
|
| 520 | - set_transient( '_wc_activation_redirect', 1, 30 ); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * See if we need to show or run database updates during install. |
|
| 526 | - * |
|
| 527 | - * @since 3.2.0 |
|
| 528 | - */ |
|
| 529 | - private static function maybe_update_db_version() { |
|
| 530 | - if ( self::needs_db_update() ) { |
|
| 531 | - /** |
|
| 532 | - * Allow WooCommerce to auto-update without prompting the user. |
|
| 533 | - * |
|
| 534 | - * @since 3.2.0 |
|
| 535 | - */ |
|
| 536 | - if ( apply_filters( 'woocommerce_enable_auto_update_db', false ) ) { |
|
| 537 | - self::update(); |
|
| 538 | - } else { |
|
| 539 | - WC_Admin_Notices::add_notice( 'update', true ); |
|
| 540 | - } |
|
| 541 | - } else { |
|
| 542 | - self::update_db_version(); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Update WC version to current. |
|
| 548 | - */ |
|
| 549 | - private static function update_wc_version() { |
|
| 550 | - update_option( 'woocommerce_version', WC()->version ); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Get list of DB update callbacks. |
|
| 555 | - * |
|
| 556 | - * @since 3.0.0 |
|
| 557 | - * @return array |
|
| 558 | - */ |
|
| 559 | - public static function get_db_update_callbacks() { |
|
| 560 | - return self::$db_updates; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Push all needed DB updates to the queue for processing. |
|
| 565 | - */ |
|
| 566 | - private static function update() { |
|
| 567 | - $current_db_version = get_option( 'woocommerce_db_version' ); |
|
| 568 | - $loop = 0; |
|
| 569 | - |
|
| 570 | - foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) { |
|
| 571 | - if ( version_compare( $current_db_version, $version, '<' ) ) { |
|
| 572 | - foreach ( $update_callbacks as $update_callback ) { |
|
| 573 | - WC()->queue()->schedule_single( |
|
| 574 | - time() + $loop, |
|
| 575 | - 'woocommerce_run_update_callback', |
|
| 576 | - array( |
|
| 577 | - 'update_callback' => $update_callback, |
|
| 578 | - ), |
|
| 579 | - 'woocommerce-db-updates' |
|
| 580 | - ); |
|
| 581 | - $loop++; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // After the callbacks finish, update the db version to the current WC version. |
|
| 587 | - $current_wc_version = WC()->version; |
|
| 588 | - if ( version_compare( $current_db_version, $current_wc_version, '<' ) && |
|
| 589 | - ! WC()->queue()->get_next( 'woocommerce_update_db_to_current_version' ) ) { |
|
| 590 | - WC()->queue()->schedule_single( |
|
| 591 | - time() + $loop, |
|
| 592 | - 'woocommerce_update_db_to_current_version', |
|
| 593 | - array( |
|
| 594 | - 'version' => $current_wc_version, |
|
| 595 | - ), |
|
| 596 | - 'woocommerce-db-updates' |
|
| 597 | - ); |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * Update DB version to current. |
|
| 603 | - * |
|
| 604 | - * @param string|null $version New WooCommerce DB version or null. |
|
| 605 | - */ |
|
| 606 | - public static function update_db_version( $version = null ) { |
|
| 607 | - update_option( 'woocommerce_db_version', is_null( $version ) ? WC()->version : $version ); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Add more cron schedules. |
|
| 612 | - * |
|
| 613 | - * @param array $schedules List of WP scheduled cron jobs. |
|
| 614 | - * |
|
| 615 | - * @return array |
|
| 616 | - */ |
|
| 617 | - public static function cron_schedules( $schedules ) { |
|
| 618 | - $schedules['monthly'] = array( |
|
| 619 | - 'interval' => 2635200, |
|
| 620 | - 'display' => __( 'Monthly', 'woocommerce' ), |
|
| 621 | - ); |
|
| 622 | - $schedules['fifteendays'] = array( |
|
| 623 | - 'interval' => 1296000, |
|
| 624 | - 'display' => __( 'Every 15 Days', 'woocommerce' ), |
|
| 625 | - ); |
|
| 626 | - return $schedules; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Create cron jobs (clear them first). |
|
| 631 | - */ |
|
| 632 | - private static function create_cron_jobs() { |
|
| 633 | - wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' ); |
|
| 634 | - wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' ); |
|
| 635 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' ); |
|
| 636 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_personal_data' ); |
|
| 637 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_logs' ); |
|
| 638 | - wp_clear_scheduled_hook( 'woocommerce_geoip_updater' ); |
|
| 639 | - wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); |
|
| 640 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_rate_limits' ); |
|
| 641 | - |
|
| 642 | - $ve = get_option( 'gmt_offset' ) > 0 ? '-' : '+'; |
|
| 643 | - |
|
| 644 | - wp_schedule_event( strtotime( '00:00 tomorrow ' . $ve . absint( get_option( 'gmt_offset' ) ) . ' HOURS' ), 'daily', 'woocommerce_scheduled_sales' ); |
|
| 645 | - |
|
| 646 | - $held_duration = get_option( 'woocommerce_hold_stock_minutes', '60' ); |
|
| 647 | - |
|
| 648 | - if ( '' !== $held_duration ) { |
|
| 649 | - /** |
|
| 650 | - * Determines the interval at which to cancel unpaid orders in minutes. |
|
| 651 | - * |
|
| 652 | - * @since 5.1.0 |
|
| 653 | - */ |
|
| 654 | - $cancel_unpaid_interval = apply_filters( 'woocommerce_cancel_unpaid_orders_interval_minutes', absint( $held_duration ) ); |
|
| 655 | - wp_schedule_single_event( time() + ( absint( $cancel_unpaid_interval ) * 60 ), 'woocommerce_cancel_unpaid_orders' ); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // Delay the first run of `woocommerce_cleanup_personal_data` by 10 seconds |
|
| 659 | - // so it doesn't occur in the same request. WooCommerce Admin also schedules |
|
| 660 | - // a daily cron that gets lost due to a race condition. WC_Privacy's background |
|
| 661 | - // processing instance updates the cron schedule from within a cron job. |
|
| 662 | - wp_schedule_event( time() + 10, 'daily', 'woocommerce_cleanup_personal_data' ); |
|
| 663 | - wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_logs' ); |
|
| 664 | - wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'woocommerce_cleanup_sessions' ); |
|
| 665 | - wp_schedule_event( time() + MINUTE_IN_SECONDS, 'fifteendays', 'woocommerce_geoip_updater' ); |
|
| 666 | - /** |
|
| 667 | - * How frequent to schedule the tracker send event. |
|
| 668 | - * |
|
| 669 | - * @since 2.3.0 |
|
| 670 | - */ |
|
| 671 | - wp_schedule_event( time() + 10, apply_filters( 'woocommerce_tracker_event_recurrence', 'daily' ), 'woocommerce_tracker_send_event' ); |
|
| 672 | - wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_rate_limits' ); |
|
| 673 | - |
|
| 674 | - if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) { |
|
| 675 | - wp_schedule_event( time(), 'daily', 'wc_admin_daily' ); |
|
| 676 | - } |
|
| 677 | - // Note: this is potentially redundant when the core package exists. |
|
| 678 | - wp_schedule_single_event( time() + 10, 'generate_category_lookup_table' ); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Create pages on installation. |
|
| 683 | - */ |
|
| 684 | - public static function maybe_create_pages() { |
|
| 685 | - if ( empty( get_option( 'woocommerce_db_version' ) ) ) { |
|
| 686 | - self::create_pages(); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Create pages that the plugin relies on, storing page IDs in variables. |
|
| 692 | - */ |
|
| 693 | - public static function create_pages() { |
|
| 694 | - include_once dirname( __FILE__ ) . '/admin/wc-admin-functions.php'; |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Determines the cart shortcode tag used for the cart page. |
|
| 698 | - * |
|
| 699 | - * @since 2.1.0 |
|
| 700 | - */ |
|
| 701 | - $cart_shortcode = apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ); |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Determines the checkout shortcode tag used on the checkout page. |
|
| 705 | - * |
|
| 706 | - * @since 2.1.0 |
|
| 707 | - */ |
|
| 708 | - $checkout_shortcode = apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ); |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * Determines the my account shortcode tag used on the my account page. |
|
| 712 | - * |
|
| 713 | - * @since 2.1.0 |
|
| 714 | - */ |
|
| 715 | - $my_account_shortcode = apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ); |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * Determines which pages are created during install. |
|
| 719 | - * |
|
| 720 | - * @since 2.1.0 |
|
| 721 | - */ |
|
| 722 | - $pages = apply_filters( |
|
| 723 | - 'woocommerce_create_pages', |
|
| 724 | - array( |
|
| 725 | - 'shop' => array( |
|
| 726 | - 'name' => _x( 'shop', 'Page slug', 'woocommerce' ), |
|
| 727 | - 'title' => _x( 'Shop', 'Page title', 'woocommerce' ), |
|
| 728 | - 'content' => '', |
|
| 729 | - ), |
|
| 730 | - 'cart' => array( |
|
| 731 | - 'name' => _x( 'cart', 'Page slug', 'woocommerce' ), |
|
| 732 | - 'title' => _x( 'Cart', 'Page title', 'woocommerce' ), |
|
| 733 | - 'content' => '<!-- wp:shortcode -->[' . $cart_shortcode . ']<!-- /wp:shortcode -->', |
|
| 734 | - ), |
|
| 735 | - 'checkout' => array( |
|
| 736 | - 'name' => _x( 'checkout', 'Page slug', 'woocommerce' ), |
|
| 737 | - 'title' => _x( 'Checkout', 'Page title', 'woocommerce' ), |
|
| 738 | - 'content' => '<!-- wp:shortcode -->[' . $checkout_shortcode . ']<!-- /wp:shortcode -->', |
|
| 739 | - ), |
|
| 740 | - 'myaccount' => array( |
|
| 741 | - 'name' => _x( 'my-account', 'Page slug', 'woocommerce' ), |
|
| 742 | - 'title' => _x( 'My account', 'Page title', 'woocommerce' ), |
|
| 743 | - 'content' => '<!-- wp:shortcode -->[' . $my_account_shortcode . ']<!-- /wp:shortcode -->', |
|
| 744 | - ), |
|
| 745 | - 'refund_returns' => array( |
|
| 746 | - 'name' => _x( 'refund_returns', 'Page slug', 'woocommerce' ), |
|
| 747 | - 'title' => _x( 'Refund and Returns Policy', 'Page title', 'woocommerce' ), |
|
| 748 | - 'content' => self::get_refunds_return_policy_page_content(), |
|
| 749 | - 'post_status' => 'draft', |
|
| 750 | - ), |
|
| 751 | - ) |
|
| 752 | - ); |
|
| 753 | - |
|
| 754 | - foreach ( $pages as $key => $page ) { |
|
| 755 | - wc_create_page( |
|
| 756 | - esc_sql( $page['name'] ), |
|
| 757 | - 'woocommerce_' . $key . '_page_id', |
|
| 758 | - $page['title'], |
|
| 759 | - $page['content'], |
|
| 760 | - ! empty( $page['parent'] ) ? wc_get_page_id( $page['parent'] ) : '', |
|
| 761 | - ! empty( $page['post_status'] ) ? $page['post_status'] : 'publish' |
|
| 762 | - ); |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * Default options. |
|
| 768 | - * |
|
| 769 | - * Sets up the default options used on the settings page. |
|
| 770 | - */ |
|
| 771 | - private static function create_options() { |
|
| 772 | - // Include settings so that we can run through defaults. |
|
| 773 | - include_once dirname( __FILE__ ) . '/admin/class-wc-admin-settings.php'; |
|
| 774 | - |
|
| 775 | - $settings = WC_Admin_Settings::get_settings_pages(); |
|
| 776 | - |
|
| 777 | - foreach ( $settings as $section ) { |
|
| 778 | - if ( ! is_a( $section, 'WC_Settings_Page' ) || ! method_exists( $section, 'get_settings' ) ) { |
|
| 779 | - continue; |
|
| 780 | - } |
|
| 781 | - $subsections = array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) ); |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * We are using 'WC_Settings_Page::get_settings' on purpose even thought it's deprecated. |
|
| 785 | - * See the method documentation for an explanation. |
|
| 786 | - */ |
|
| 787 | - |
|
| 788 | - foreach ( $subsections as $subsection ) { |
|
| 789 | - foreach ( $section->get_settings( $subsection ) as $value ) { |
|
| 790 | - if ( isset( $value['default'] ) && isset( $value['id'] ) ) { |
|
| 791 | - $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true; |
|
| 792 | - add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) ); |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // Define other defaults if not in setting screens. |
|
| 799 | - add_option( 'woocommerce_single_image_width', '600', '', 'yes' ); |
|
| 800 | - add_option( 'woocommerce_thumbnail_image_width', '300', '', 'yes' ); |
|
| 801 | - add_option( 'woocommerce_checkout_highlight_required_fields', 'yes', '', 'yes' ); |
|
| 802 | - add_option( 'woocommerce_demo_store', 'no', '', 'no' ); |
|
| 803 | - |
|
| 804 | - if ( self::is_new_install() ) { |
|
| 805 | - // Define initial tax classes. |
|
| 806 | - WC_Tax::create_tax_class( __( 'Reduced rate', 'woocommerce' ) ); |
|
| 807 | - WC_Tax::create_tax_class( __( 'Zero rate', 'woocommerce' ) ); |
|
| 808 | - |
|
| 809 | - // For new installs, setup and enable Approved Product Download Directories. |
|
| 810 | - wc_get_container()->get( Download_Directories_Sync::class )->init_feature( false, true ); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Delete obsolete notes. |
|
| 816 | - */ |
|
| 817 | - public static function delete_obsolete_notes() { |
|
| 818 | - global $wpdb; |
|
| 819 | - $obsolete_notes_names = array( |
|
| 820 | - 'wc-admin-welcome-note', |
|
| 821 | - 'wc-admin-store-notice-setting-moved', |
|
| 822 | - 'wc-admin-store-notice-giving-feedback', |
|
| 823 | - 'wc-admin-learn-more-about-product-settings', |
|
| 824 | - 'wc-admin-onboarding-profiler-reminder', |
|
| 825 | - 'wc-admin-historical-data', |
|
| 826 | - 'wc-admin-review-shipping-settings', |
|
| 827 | - 'wc-admin-home-screen-feedback', |
|
| 828 | - 'wc-admin-effortless-payments-by-mollie', |
|
| 829 | - 'wc-admin-google-ads-and-marketing', |
|
| 830 | - 'wc-admin-marketing-intro', |
|
| 831 | - 'wc-admin-draw-attention', |
|
| 832 | - 'wc-admin-need-some-inspiration', |
|
| 833 | - 'wc-admin-choose-niche', |
|
| 834 | - 'wc-admin-start-dropshipping-business', |
|
| 835 | - 'wc-admin-filter-by-product-variations-in-reports', |
|
| 836 | - 'wc-admin-learn-more-about-variable-products', |
|
| 837 | - 'wc-admin-getting-started-ecommerce-webinar', |
|
| 838 | - 'wc-admin-navigation-feedback', |
|
| 839 | - 'wc-admin-navigation-feedback-follow-up', |
|
| 840 | - 'wc-admin-set-up-additional-payment-types', |
|
| 841 | - 'wc-admin-deactivate-plugin', |
|
| 842 | - ); |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * An array of deprecated notes to delete on update. |
|
| 846 | - * |
|
| 847 | - * @since 6.5.0 |
|
| 848 | - */ |
|
| 849 | - $additional_obsolete_notes_names = apply_filters( |
|
| 850 | - 'woocommerce_admin_obsolete_notes_names', |
|
| 851 | - array() |
|
| 852 | - ); |
|
| 853 | - |
|
| 854 | - if ( is_array( $additional_obsolete_notes_names ) ) { |
|
| 855 | - $obsolete_notes_names = array_merge( |
|
| 856 | - $obsolete_notes_names, |
|
| 857 | - $additional_obsolete_notes_names |
|
| 858 | - ); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - foreach ( $obsolete_notes_names as $obsolete_notes_name ) { |
|
| 862 | - $wpdb->delete( $wpdb->prefix . 'wc_admin_notes', array( 'name' => $obsolete_notes_name ) ); |
|
| 863 | - $wpdb->delete( $wpdb->prefix . 'wc_admin_note_actions', array( 'name' => $obsolete_notes_name ) ); |
|
| 864 | - } |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * Migrate option values to their new keys/names. |
|
| 869 | - */ |
|
| 870 | - public static function migrate_options() { |
|
| 871 | - |
|
| 872 | - $migrated_options = array( |
|
| 873 | - 'woocommerce_onboarding_profile' => 'wc_onboarding_profile', |
|
| 874 | - 'woocommerce_admin_install_timestamp' => 'wc_admin_install_timestamp', |
|
| 875 | - 'woocommerce_onboarding_opt_in' => 'wc_onboarding_opt_in', |
|
| 876 | - 'woocommerce_admin_import_stats' => 'wc_admin_import_stats', |
|
| 877 | - 'woocommerce_admin_version' => 'wc_admin_version', |
|
| 878 | - 'woocommerce_admin_last_orders_milestone' => 'wc_admin_last_orders_milestone', |
|
| 879 | - 'woocommerce_admin-wc-helper-last-refresh' => 'wc-admin-wc-helper-last-refresh', |
|
| 880 | - 'woocommerce_admin_report_export_status' => 'wc_admin_report_export_status', |
|
| 881 | - 'woocommerce_task_list_complete' => 'woocommerce_task_list_complete', |
|
| 882 | - 'woocommerce_task_list_hidden' => 'woocommerce_task_list_hidden', |
|
| 883 | - 'woocommerce_extended_task_list_complete' => 'woocommerce_extended_task_list_complete', |
|
| 884 | - 'woocommerce_extended_task_list_hidden' => 'woocommerce_extended_task_list_hidden', |
|
| 885 | - ); |
|
| 886 | - |
|
| 887 | - wc_maybe_define_constant( 'WC_ADMIN_MIGRATING_OPTIONS', true ); |
|
| 888 | - |
|
| 889 | - foreach ( $migrated_options as $new_option => $old_option ) { |
|
| 890 | - $old_option_value = get_option( $old_option, false ); |
|
| 891 | - |
|
| 892 | - // Continue if no option value was previously set. |
|
| 893 | - if ( false === $old_option_value ) { |
|
| 894 | - continue; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - if ( '1' === $old_option_value ) { |
|
| 898 | - $old_option_value = 'yes'; |
|
| 899 | - } elseif ( '0' === $old_option_value ) { |
|
| 900 | - $old_option_value = 'no'; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - update_option( $new_option, $old_option_value ); |
|
| 904 | - if ( $new_option !== $old_option ) { |
|
| 905 | - delete_option( $old_option ); |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - /** |
|
| 910 | - * Add the default terms for WC taxonomies - product types and order statuses. Modify this at your own risk. |
|
| 911 | - */ |
|
| 912 | - public static function create_terms() { |
|
| 913 | - $taxonomies = array( |
|
| 914 | - 'product_type' => array( |
|
| 915 | - 'simple', |
|
| 916 | - 'grouped', |
|
| 917 | - 'variable', |
|
| 918 | - 'external', |
|
| 919 | - ), |
|
| 920 | - 'product_visibility' => array( |
|
| 921 | - 'exclude-from-search', |
|
| 922 | - 'exclude-from-catalog', |
|
| 923 | - 'featured', |
|
| 924 | - 'outofstock', |
|
| 925 | - 'rated-1', |
|
| 926 | - 'rated-2', |
|
| 927 | - 'rated-3', |
|
| 928 | - 'rated-4', |
|
| 929 | - 'rated-5', |
|
| 930 | - ), |
|
| 931 | - ); |
|
| 932 | - |
|
| 933 | - foreach ( $taxonomies as $taxonomy => $terms ) { |
|
| 934 | - foreach ( $terms as $term ) { |
|
| 935 | - if ( ! get_term_by( 'name', $term, $taxonomy ) ) { // @codingStandardsIgnoreLine. |
|
| 936 | - wp_insert_term( $term, $taxonomy ); |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - $woocommerce_default_category = (int) get_option( 'default_product_cat', 0 ); |
|
| 942 | - |
|
| 943 | - if ( ! $woocommerce_default_category || ! term_exists( $woocommerce_default_category, 'product_cat' ) ) { |
|
| 944 | - $default_product_cat_id = 0; |
|
| 945 | - $default_product_cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug', 'woocommerce' ) ); |
|
| 946 | - $default_product_cat = get_term_by( 'slug', $default_product_cat_slug, 'product_cat' ); // @codingStandardsIgnoreLine. |
|
| 947 | - |
|
| 948 | - if ( $default_product_cat ) { |
|
| 949 | - $default_product_cat_id = absint( $default_product_cat->term_taxonomy_id ); |
|
| 950 | - } else { |
|
| 951 | - $result = wp_insert_term( _x( 'Uncategorized', 'Default category slug', 'woocommerce' ), 'product_cat', array( 'slug' => $default_product_cat_slug ) ); |
|
| 952 | - |
|
| 953 | - if ( ! is_wp_error( $result ) && ! empty( $result['term_taxonomy_id'] ) ) { |
|
| 954 | - $default_product_cat_id = absint( $result['term_taxonomy_id'] ); |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - if ( $default_product_cat_id ) { |
|
| 959 | - update_option( 'default_product_cat', $default_product_cat_id ); |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - /** |
|
| 965 | - * Set up the database tables which the plugin needs to function. |
|
| 966 | - * WARNING: If you are modifying this method, make sure that its safe to call regardless of the state of database. |
|
| 967 | - * |
|
| 968 | - * This is called from `install` method and is executed in-sync when WC is installed or updated. This can also be called optionally from `verify_base_tables`. |
|
| 969 | - * |
|
| 970 | - * TODO: Add all crucial tables that we have created from workers in the past. |
|
| 971 | - * |
|
| 972 | - * Tables: |
|
| 973 | - * woocommerce_attribute_taxonomies - Table for storing attribute taxonomies - these are user defined |
|
| 974 | - * woocommerce_downloadable_product_permissions - Table for storing user and guest download permissions. |
|
| 975 | - * KEY(order_id, product_id, download_id) used for organizing downloads on the My Account page |
|
| 976 | - * woocommerce_order_items - Order line items are stored in a table to make them easily queryable for reports |
|
| 977 | - * woocommerce_order_itemmeta - Order line item meta is stored in a table for storing extra data. |
|
| 978 | - * woocommerce_tax_rates - Tax Rates are stored inside 2 tables making tax queries simple and efficient. |
|
| 979 | - * woocommerce_tax_rate_locations - Each rate can be applied to more than one postcode/city hence the second table. |
|
| 980 | - */ |
|
| 981 | - public static function create_tables() { |
|
| 982 | - global $wpdb; |
|
| 983 | - |
|
| 984 | - $wpdb->hide_errors(); |
|
| 985 | - |
|
| 986 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Before updating with DBDELTA, remove any primary keys which could be |
|
| 990 | - * modified due to schema updates. |
|
| 991 | - */ |
|
| 992 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_downloadable_product_permissions';" ) ) { |
|
| 993 | - if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}woocommerce_downloadable_product_permissions` LIKE 'permission_id';" ) ) { |
|
| 994 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions DROP PRIMARY KEY, ADD `permission_id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT;" ); |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * Change wp_woocommerce_sessions schema to use a bigint auto increment field instead of char(32) field as |
|
| 1000 | - * the primary key as it is not a good practice to use a char(32) field as the primary key of a table and as |
|
| 1001 | - * there were reports of issues with this table (see https://github.com/woocommerce/woocommerce/issues/20912). |
|
| 1002 | - * |
|
| 1003 | - * This query needs to run before dbDelta() as this WP function is not able to handle primary key changes |
|
| 1004 | - * (see https://github.com/woocommerce/woocommerce/issues/21534 and https://core.trac.wordpress.org/ticket/40357). |
|
| 1005 | - */ |
|
| 1006 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_sessions'" ) ) { |
|
| 1007 | - if ( ! $wpdb->get_var( "SHOW KEYS FROM {$wpdb->prefix}woocommerce_sessions WHERE Key_name = 'PRIMARY' AND Column_name = 'session_id'" ) ) { |
|
| 1008 | - $wpdb->query( |
|
| 1009 | - "ALTER TABLE `{$wpdb->prefix}woocommerce_sessions` DROP PRIMARY KEY, DROP KEY `session_id`, ADD PRIMARY KEY(`session_id`), ADD UNIQUE KEY(`session_key`)" |
|
| 1010 | - ); |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - dbDelta( self::get_schema() ); |
|
| 1015 | - |
|
| 1016 | - $index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->comments} WHERE column_name = 'comment_type' and key_name = 'woo_idx_comment_type'" ); |
|
| 1017 | - |
|
| 1018 | - if ( is_null( $index_exists ) ) { |
|
| 1019 | - // Add an index to the field comment_type to improve the response time of the query |
|
| 1020 | - // used by WC_Comments::wp_count_comments() to get the number of comments by type. |
|
| 1021 | - $wpdb->query( "ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)" ); |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - // Get tables data types and check it matches before adding constraint. |
|
| 1025 | - $download_log_columns = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}wc_download_log WHERE Field = 'permission_id'", ARRAY_A ); |
|
| 1026 | - $download_log_column_type = ''; |
|
| 1027 | - if ( isset( $download_log_columns[0]['Type'] ) ) { |
|
| 1028 | - $download_log_column_type = $download_log_columns[0]['Type']; |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - $download_permissions_columns = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE Field = 'permission_id'", ARRAY_A ); |
|
| 1032 | - $download_permissions_column_type = ''; |
|
| 1033 | - if ( isset( $download_permissions_columns[0]['Type'] ) ) { |
|
| 1034 | - $download_permissions_column_type = $download_permissions_columns[0]['Type']; |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - // Add constraint to download logs if the columns matches. |
|
| 1038 | - if ( ! empty( $download_permissions_column_type ) && ! empty( $download_log_column_type ) && $download_permissions_column_type === $download_log_column_type ) { |
|
| 1039 | - $fk_result = $wpdb->get_row( "SHOW CREATE TABLE {$wpdb->prefix}wc_download_log" ); |
|
| 1040 | - if ( false === strpos( $fk_result->{'Create Table'}, "fk_{$wpdb->prefix}wc_download_log_permission_id" ) ) { |
|
| 1041 | - $wpdb->query( |
|
| 1042 | - "ALTER TABLE `{$wpdb->prefix}wc_download_log` |
|
| 24 | + /** |
|
| 25 | + * DB updates and callbacks that need to be run per version. |
|
| 26 | + * |
|
| 27 | + * Please note that these functions are invoked when WooCommerce is updated from a previous version, |
|
| 28 | + * but NOT when WooCommerce is newly installed. |
|
| 29 | + * |
|
| 30 | + * Database schema changes must be incorporated to the SQL returned by get_schema, which is applied |
|
| 31 | + * via dbDelta at both install and update time. If any other kind of database change is required |
|
| 32 | + * at install time (e.g. populating tables), use the 'woocommerce_installed' hook. |
|
| 33 | + * |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + private static $db_updates = array( |
|
| 37 | + '2.0.0' => array( |
|
| 38 | + 'wc_update_200_file_paths', |
|
| 39 | + 'wc_update_200_permalinks', |
|
| 40 | + 'wc_update_200_subcat_display', |
|
| 41 | + 'wc_update_200_taxrates', |
|
| 42 | + 'wc_update_200_line_items', |
|
| 43 | + 'wc_update_200_images', |
|
| 44 | + 'wc_update_200_db_version', |
|
| 45 | + ), |
|
| 46 | + '2.0.9' => array( |
|
| 47 | + 'wc_update_209_brazillian_state', |
|
| 48 | + 'wc_update_209_db_version', |
|
| 49 | + ), |
|
| 50 | + '2.1.0' => array( |
|
| 51 | + 'wc_update_210_remove_pages', |
|
| 52 | + 'wc_update_210_file_paths', |
|
| 53 | + 'wc_update_210_db_version', |
|
| 54 | + ), |
|
| 55 | + '2.2.0' => array( |
|
| 56 | + 'wc_update_220_shipping', |
|
| 57 | + 'wc_update_220_order_status', |
|
| 58 | + 'wc_update_220_variations', |
|
| 59 | + 'wc_update_220_attributes', |
|
| 60 | + 'wc_update_220_db_version', |
|
| 61 | + ), |
|
| 62 | + '2.3.0' => array( |
|
| 63 | + 'wc_update_230_options', |
|
| 64 | + 'wc_update_230_db_version', |
|
| 65 | + ), |
|
| 66 | + '2.4.0' => array( |
|
| 67 | + 'wc_update_240_options', |
|
| 68 | + 'wc_update_240_shipping_methods', |
|
| 69 | + 'wc_update_240_api_keys', |
|
| 70 | + 'wc_update_240_refunds', |
|
| 71 | + 'wc_update_240_db_version', |
|
| 72 | + ), |
|
| 73 | + '2.4.1' => array( |
|
| 74 | + 'wc_update_241_variations', |
|
| 75 | + 'wc_update_241_db_version', |
|
| 76 | + ), |
|
| 77 | + '2.5.0' => array( |
|
| 78 | + 'wc_update_250_currency', |
|
| 79 | + 'wc_update_250_db_version', |
|
| 80 | + ), |
|
| 81 | + '2.6.0' => array( |
|
| 82 | + 'wc_update_260_options', |
|
| 83 | + 'wc_update_260_termmeta', |
|
| 84 | + 'wc_update_260_zones', |
|
| 85 | + 'wc_update_260_zone_methods', |
|
| 86 | + 'wc_update_260_refunds', |
|
| 87 | + 'wc_update_260_db_version', |
|
| 88 | + ), |
|
| 89 | + '3.0.0' => array( |
|
| 90 | + 'wc_update_300_grouped_products', |
|
| 91 | + 'wc_update_300_settings', |
|
| 92 | + 'wc_update_300_product_visibility', |
|
| 93 | + 'wc_update_300_db_version', |
|
| 94 | + ), |
|
| 95 | + '3.1.0' => array( |
|
| 96 | + 'wc_update_310_downloadable_products', |
|
| 97 | + 'wc_update_310_old_comments', |
|
| 98 | + 'wc_update_310_db_version', |
|
| 99 | + ), |
|
| 100 | + '3.1.2' => array( |
|
| 101 | + 'wc_update_312_shop_manager_capabilities', |
|
| 102 | + 'wc_update_312_db_version', |
|
| 103 | + ), |
|
| 104 | + '3.2.0' => array( |
|
| 105 | + 'wc_update_320_mexican_states', |
|
| 106 | + 'wc_update_320_db_version', |
|
| 107 | + ), |
|
| 108 | + '3.3.0' => array( |
|
| 109 | + 'wc_update_330_image_options', |
|
| 110 | + 'wc_update_330_webhooks', |
|
| 111 | + 'wc_update_330_product_stock_status', |
|
| 112 | + 'wc_update_330_set_default_product_cat', |
|
| 113 | + 'wc_update_330_clear_transients', |
|
| 114 | + 'wc_update_330_set_paypal_sandbox_credentials', |
|
| 115 | + 'wc_update_330_db_version', |
|
| 116 | + ), |
|
| 117 | + '3.4.0' => array( |
|
| 118 | + 'wc_update_340_states', |
|
| 119 | + 'wc_update_340_state', |
|
| 120 | + 'wc_update_340_last_active', |
|
| 121 | + 'wc_update_340_db_version', |
|
| 122 | + ), |
|
| 123 | + '3.4.3' => array( |
|
| 124 | + 'wc_update_343_cleanup_foreign_keys', |
|
| 125 | + 'wc_update_343_db_version', |
|
| 126 | + ), |
|
| 127 | + '3.4.4' => array( |
|
| 128 | + 'wc_update_344_recreate_roles', |
|
| 129 | + 'wc_update_344_db_version', |
|
| 130 | + ), |
|
| 131 | + '3.5.0' => array( |
|
| 132 | + 'wc_update_350_reviews_comment_type', |
|
| 133 | + 'wc_update_350_db_version', |
|
| 134 | + ), |
|
| 135 | + '3.5.2' => array( |
|
| 136 | + 'wc_update_352_drop_download_log_fk', |
|
| 137 | + ), |
|
| 138 | + '3.5.4' => array( |
|
| 139 | + 'wc_update_354_modify_shop_manager_caps', |
|
| 140 | + 'wc_update_354_db_version', |
|
| 141 | + ), |
|
| 142 | + '3.6.0' => array( |
|
| 143 | + 'wc_update_360_product_lookup_tables', |
|
| 144 | + 'wc_update_360_term_meta', |
|
| 145 | + 'wc_update_360_downloadable_product_permissions_index', |
|
| 146 | + 'wc_update_360_db_version', |
|
| 147 | + ), |
|
| 148 | + '3.7.0' => array( |
|
| 149 | + 'wc_update_370_tax_rate_classes', |
|
| 150 | + 'wc_update_370_mro_std_currency', |
|
| 151 | + 'wc_update_370_db_version', |
|
| 152 | + ), |
|
| 153 | + '3.9.0' => array( |
|
| 154 | + 'wc_update_390_move_maxmind_database', |
|
| 155 | + 'wc_update_390_change_geolocation_database_update_cron', |
|
| 156 | + 'wc_update_390_db_version', |
|
| 157 | + ), |
|
| 158 | + '4.0.0' => array( |
|
| 159 | + 'wc_update_product_lookup_tables', |
|
| 160 | + 'wc_update_400_increase_size_of_column', |
|
| 161 | + 'wc_update_400_reset_action_scheduler_migration_status', |
|
| 162 | + 'wc_admin_update_0201_order_status_index', |
|
| 163 | + 'wc_admin_update_0230_rename_gross_total', |
|
| 164 | + 'wc_admin_update_0251_remove_unsnooze_action', |
|
| 165 | + 'wc_update_400_db_version', |
|
| 166 | + ), |
|
| 167 | + '4.4.0' => array( |
|
| 168 | + 'wc_update_440_insert_attribute_terms_for_variable_products', |
|
| 169 | + 'wc_admin_update_110_remove_facebook_note', |
|
| 170 | + 'wc_admin_update_130_remove_dismiss_action_from_tracking_opt_in_note', |
|
| 171 | + 'wc_update_440_db_version', |
|
| 172 | + ), |
|
| 173 | + '4.5.0' => array( |
|
| 174 | + 'wc_update_450_sanitize_coupons_code', |
|
| 175 | + 'wc_update_450_db_version', |
|
| 176 | + ), |
|
| 177 | + '5.0.0' => array( |
|
| 178 | + 'wc_update_500_fix_product_review_count', |
|
| 179 | + 'wc_admin_update_160_remove_facebook_note', |
|
| 180 | + 'wc_admin_update_170_homescreen_layout', |
|
| 181 | + 'wc_update_500_db_version', |
|
| 182 | + ), |
|
| 183 | + '5.6.0' => array( |
|
| 184 | + 'wc_update_560_create_refund_returns_page', |
|
| 185 | + 'wc_update_560_db_version', |
|
| 186 | + ), |
|
| 187 | + '6.0.0' => array( |
|
| 188 | + 'wc_update_600_migrate_rate_limit_options', |
|
| 189 | + 'wc_admin_update_270_delete_report_downloads', |
|
| 190 | + 'wc_admin_update_271_update_task_list_options', |
|
| 191 | + 'wc_admin_update_280_order_status', |
|
| 192 | + 'wc_admin_update_290_update_apperance_task_option', |
|
| 193 | + 'wc_admin_update_290_delete_default_homepage_layout_option', |
|
| 194 | + 'wc_update_600_db_version', |
|
| 195 | + ), |
|
| 196 | + '6.3.0' => array( |
|
| 197 | + 'wc_update_630_create_product_attributes_lookup_table', |
|
| 198 | + 'wc_admin_update_300_update_is_read_from_last_read', |
|
| 199 | + 'wc_update_630_db_version', |
|
| 200 | + ), |
|
| 201 | + '6.4.0' => array( |
|
| 202 | + 'wc_update_640_add_primary_key_to_product_attributes_lookup_table', |
|
| 203 | + 'wc_admin_update_340_remove_is_primary_from_note_action', |
|
| 204 | + 'wc_update_640_db_version', |
|
| 205 | + ), |
|
| 206 | + '6.5.0' => array( |
|
| 207 | + 'wc_update_650_approved_download_directories', |
|
| 208 | + ), |
|
| 209 | + '6.5.1' => array( |
|
| 210 | + 'wc_update_651_approved_download_directories', |
|
| 211 | + ), |
|
| 212 | + '6.7.0' => array( |
|
| 213 | + 'wc_update_670_purge_comments_count_cache', |
|
| 214 | + 'wc_update_670_delete_deprecated_remote_inbox_notifications_option', |
|
| 215 | + ), |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Hook in tabs. |
|
| 220 | + */ |
|
| 221 | + public static function init() { |
|
| 222 | + add_action( 'init', array( __CLASS__, 'check_version' ), 5 ); |
|
| 223 | + add_action( 'init', array( __CLASS__, 'manual_database_update' ), 20 ); |
|
| 224 | + add_action( 'admin_init', array( __CLASS__, 'wc_admin_db_update_notice' ) ); |
|
| 225 | + add_action( 'admin_init', array( __CLASS__, 'add_admin_note_after_page_created' ) ); |
|
| 226 | + add_action( 'woocommerce_run_update_callback', array( __CLASS__, 'run_update_callback' ) ); |
|
| 227 | + add_action( 'woocommerce_update_db_to_current_version', array( __CLASS__, 'update_db_version' ) ); |
|
| 228 | + add_action( 'admin_init', array( __CLASS__, 'install_actions' ) ); |
|
| 229 | + add_action( 'woocommerce_page_created', array( __CLASS__, 'page_created' ), 10, 2 ); |
|
| 230 | + add_filter( 'plugin_action_links_' . WC_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) ); |
|
| 231 | + add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 ); |
|
| 232 | + add_filter( 'wpmu_drop_tables', array( __CLASS__, 'wpmu_drop_tables' ) ); |
|
| 233 | + add_filter( 'cron_schedules', array( __CLASS__, 'cron_schedules' ) ); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Check WooCommerce version and run the updater is required. |
|
| 238 | + * |
|
| 239 | + * This check is done on all requests and runs if the versions do not match. |
|
| 240 | + */ |
|
| 241 | + public static function check_version() { |
|
| 242 | + $wc_version = get_option( 'woocommerce_version' ); |
|
| 243 | + $wc_code_version = WC()->version; |
|
| 244 | + $requires_update = version_compare( $wc_version, $wc_code_version, '<' ); |
|
| 245 | + if ( ! Constants::is_defined( 'IFRAME_REQUEST' ) && $requires_update ) { |
|
| 246 | + self::install(); |
|
| 247 | + /** |
|
| 248 | + * Run after WooCommerce has been updated. |
|
| 249 | + * |
|
| 250 | + * @since 2.2.0 |
|
| 251 | + */ |
|
| 252 | + do_action( 'woocommerce_updated' ); |
|
| 253 | + do_action_deprecated( 'woocommerce_admin_updated', array(), $wc_code_version, 'woocommerce_updated' ); |
|
| 254 | + // If there is no woocommerce_version option, consider it as a new install. |
|
| 255 | + if ( ! $wc_version ) { |
|
| 256 | + /** |
|
| 257 | + * Run when WooCommerce has been installed for the first time. |
|
| 258 | + * |
|
| 259 | + * @since 6.5.0 |
|
| 260 | + */ |
|
| 261 | + do_action( 'woocommerce_newly_installed' ); |
|
| 262 | + do_action_deprecated( 'woocommerce_admin_newly_installed', array(), $wc_code_version, 'woocommerce_newly_installed' ); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Performan manual database update when triggered by WooCommerce System Tools. |
|
| 269 | + * |
|
| 270 | + * @since 3.6.5 |
|
| 271 | + */ |
|
| 272 | + public static function manual_database_update() { |
|
| 273 | + $blog_id = get_current_blog_id(); |
|
| 274 | + |
|
| 275 | + add_action( 'wp_' . $blog_id . '_wc_updater_cron', array( __CLASS__, 'run_manual_database_update' ) ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Add WC Admin based db update notice. |
|
| 280 | + * |
|
| 281 | + * @since 4.0.0 |
|
| 282 | + */ |
|
| 283 | + public static function wc_admin_db_update_notice() { |
|
| 284 | + if ( |
|
| 285 | + WC()->is_wc_admin_active() && |
|
| 286 | + false !== get_option( 'woocommerce_admin_install_timestamp' ) |
|
| 287 | + ) { |
|
| 288 | + new WC_Notes_Run_Db_Update(); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Run manual database update. |
|
| 294 | + */ |
|
| 295 | + public static function run_manual_database_update() { |
|
| 296 | + self::update(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Run an update callback when triggered by ActionScheduler. |
|
| 301 | + * |
|
| 302 | + * @param string $update_callback Callback name. |
|
| 303 | + * |
|
| 304 | + * @since 3.6.0 |
|
| 305 | + */ |
|
| 306 | + public static function run_update_callback( $update_callback ) { |
|
| 307 | + include_once dirname( __FILE__ ) . '/wc-update-functions.php'; |
|
| 308 | + |
|
| 309 | + if ( is_callable( $update_callback ) ) { |
|
| 310 | + self::run_update_callback_start( $update_callback ); |
|
| 311 | + $result = (bool) call_user_func( $update_callback ); |
|
| 312 | + self::run_update_callback_end( $update_callback, $result ); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Triggered when a callback will run. |
|
| 318 | + * |
|
| 319 | + * @since 3.6.0 |
|
| 320 | + * @param string $callback Callback name. |
|
| 321 | + */ |
|
| 322 | + protected static function run_update_callback_start( $callback ) { |
|
| 323 | + wc_maybe_define_constant( 'WC_UPDATING', true ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Triggered when a callback has ran. |
|
| 328 | + * |
|
| 329 | + * @since 3.6.0 |
|
| 330 | + * @param string $callback Callback name. |
|
| 331 | + * @param bool $result Return value from callback. Non-false need to run again. |
|
| 332 | + */ |
|
| 333 | + protected static function run_update_callback_end( $callback, $result ) { |
|
| 334 | + if ( $result ) { |
|
| 335 | + WC()->queue()->add( |
|
| 336 | + 'woocommerce_run_update_callback', |
|
| 337 | + array( |
|
| 338 | + 'update_callback' => $callback, |
|
| 339 | + ), |
|
| 340 | + 'woocommerce-db-updates' |
|
| 341 | + ); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Install actions when a update button is clicked within the admin area. |
|
| 347 | + * |
|
| 348 | + * This function is hooked into admin_init to affect admin only. |
|
| 349 | + */ |
|
| 350 | + public static function install_actions() { |
|
| 351 | + if ( ! empty( $_GET['do_update_woocommerce'] ) ) { // WPCS: input var ok. |
|
| 352 | + check_admin_referer( 'wc_db_update', 'wc_db_update_nonce' ); |
|
| 353 | + self::update(); |
|
| 354 | + WC_Admin_Notices::add_notice( 'update', true ); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Install WC. |
|
| 360 | + */ |
|
| 361 | + public static function install() { |
|
| 362 | + if ( ! is_blog_installed() ) { |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Check if we are not already running this routine. |
|
| 367 | + if ( self::is_installing() ) { |
|
| 368 | + return; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // If we made it till here nothing is running yet, lets set the transient now. |
|
| 372 | + set_transient( 'wc_installing', 'yes', MINUTE_IN_SECONDS * 10 ); |
|
| 373 | + wc_maybe_define_constant( 'WC_INSTALLING', true ); |
|
| 374 | + |
|
| 375 | + WC()->wpdb_table_fix(); |
|
| 376 | + self::remove_admin_notices(); |
|
| 377 | + self::create_tables(); |
|
| 378 | + self::verify_base_tables(); |
|
| 379 | + self::create_options(); |
|
| 380 | + self::migrate_options(); |
|
| 381 | + self::create_roles(); |
|
| 382 | + self::setup_environment(); |
|
| 383 | + self::create_terms(); |
|
| 384 | + self::create_cron_jobs(); |
|
| 385 | + self::delete_obsolete_notes(); |
|
| 386 | + self::create_files(); |
|
| 387 | + self::maybe_create_pages(); |
|
| 388 | + self::maybe_set_activation_transients(); |
|
| 389 | + self::set_paypal_standard_load_eligibility(); |
|
| 390 | + self::update_wc_version(); |
|
| 391 | + self::maybe_update_db_version(); |
|
| 392 | + |
|
| 393 | + delete_transient( 'wc_installing' ); |
|
| 394 | + |
|
| 395 | + // Use add_option() here to avoid overwriting this value with each |
|
| 396 | + // plugin version update. We base plugin age off of this value. |
|
| 397 | + add_option( 'woocommerce_admin_install_timestamp', time() ); |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Flush the rewrite rules after install or update. |
|
| 401 | + * |
|
| 402 | + * @since 2.7.0 |
|
| 403 | + */ |
|
| 404 | + do_action( 'woocommerce_flush_rewrite_rules' ); |
|
| 405 | + /** |
|
| 406 | + * Run after WooCommerce has been installed or updated. |
|
| 407 | + * |
|
| 408 | + * @since 3.2.0 |
|
| 409 | + */ |
|
| 410 | + do_action( 'woocommerce_installed' ); |
|
| 411 | + /** |
|
| 412 | + * Run after WooCommerce Admin has been installed or updated. |
|
| 413 | + * |
|
| 414 | + * @since 6.5.0 |
|
| 415 | + */ |
|
| 416 | + do_action( 'woocommerce_admin_installed' ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Returns true if we're installing. |
|
| 421 | + * |
|
| 422 | + * @return bool |
|
| 423 | + */ |
|
| 424 | + private static function is_installing() { |
|
| 425 | + return 'yes' === get_transient( 'wc_installing' ); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Check if all the base tables are present. |
|
| 430 | + * |
|
| 431 | + * @param bool $modify_notice Whether to modify notice based on if all tables are present. |
|
| 432 | + * @param bool $execute Whether to execute get_schema queries as well. |
|
| 433 | + * |
|
| 434 | + * @return array List of queries. |
|
| 435 | + */ |
|
| 436 | + public static function verify_base_tables( $modify_notice = true, $execute = false ) { |
|
| 437 | + if ( $execute ) { |
|
| 438 | + self::create_tables(); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $missing_tables = wc_get_container() |
|
| 442 | + ->get( DatabaseUtil::class ) |
|
| 443 | + ->get_missing_tables( self::get_schema() ); |
|
| 444 | + |
|
| 445 | + if ( 0 < count( $missing_tables ) ) { |
|
| 446 | + if ( $modify_notice ) { |
|
| 447 | + WC_Admin_Notices::add_notice( 'base_tables_missing' ); |
|
| 448 | + } |
|
| 449 | + update_option( 'woocommerce_schema_missing_tables', $missing_tables ); |
|
| 450 | + } else { |
|
| 451 | + if ( $modify_notice ) { |
|
| 452 | + WC_Admin_Notices::remove_notice( 'base_tables_missing' ); |
|
| 453 | + } |
|
| 454 | + update_option( 'woocommerce_schema_version', WC()->db_version ); |
|
| 455 | + delete_option( 'woocommerce_schema_missing_tables' ); |
|
| 456 | + } |
|
| 457 | + return $missing_tables; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Reset any notices added to admin. |
|
| 462 | + * |
|
| 463 | + * @since 3.2.0 |
|
| 464 | + */ |
|
| 465 | + private static function remove_admin_notices() { |
|
| 466 | + include_once dirname( __FILE__ ) . '/admin/class-wc-admin-notices.php'; |
|
| 467 | + WC_Admin_Notices::remove_all_notices(); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Setup WC environment - post types, taxonomies, endpoints. |
|
| 472 | + * |
|
| 473 | + * @since 3.2.0 |
|
| 474 | + */ |
|
| 475 | + private static function setup_environment() { |
|
| 476 | + WC_Post_types::register_post_types(); |
|
| 477 | + WC_Post_types::register_taxonomies(); |
|
| 478 | + WC()->query->init_query_vars(); |
|
| 479 | + WC()->query->add_endpoints(); |
|
| 480 | + WC_API::add_endpoint(); |
|
| 481 | + WC_Auth::add_endpoint(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Is this a brand new WC install? |
|
| 486 | + * |
|
| 487 | + * A brand new install has no version yet. Also treat empty installs as 'new'. |
|
| 488 | + * |
|
| 489 | + * @since 3.2.0 |
|
| 490 | + * @return boolean |
|
| 491 | + */ |
|
| 492 | + public static function is_new_install() { |
|
| 493 | + $product_count = array_sum( (array) wp_count_posts( 'product' ) ); |
|
| 494 | + |
|
| 495 | + return is_null( get_option( 'woocommerce_version', null ) ) || ( 0 === $product_count && -1 === wc_get_page_id( 'shop' ) ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Is a DB update needed? |
|
| 500 | + * |
|
| 501 | + * @since 3.2.0 |
|
| 502 | + * @return boolean |
|
| 503 | + */ |
|
| 504 | + public static function needs_db_update() { |
|
| 505 | + $current_db_version = get_option( 'woocommerce_db_version', null ); |
|
| 506 | + $updates = self::get_db_update_callbacks(); |
|
| 507 | + $update_versions = array_keys( $updates ); |
|
| 508 | + usort( $update_versions, 'version_compare' ); |
|
| 509 | + |
|
| 510 | + return ! is_null( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' ); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * See if we need to set redirect transients for activation or not. |
|
| 515 | + * |
|
| 516 | + * @since 4.6.0 |
|
| 517 | + */ |
|
| 518 | + private static function maybe_set_activation_transients() { |
|
| 519 | + if ( self::is_new_install() ) { |
|
| 520 | + set_transient( '_wc_activation_redirect', 1, 30 ); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * See if we need to show or run database updates during install. |
|
| 526 | + * |
|
| 527 | + * @since 3.2.0 |
|
| 528 | + */ |
|
| 529 | + private static function maybe_update_db_version() { |
|
| 530 | + if ( self::needs_db_update() ) { |
|
| 531 | + /** |
|
| 532 | + * Allow WooCommerce to auto-update without prompting the user. |
|
| 533 | + * |
|
| 534 | + * @since 3.2.0 |
|
| 535 | + */ |
|
| 536 | + if ( apply_filters( 'woocommerce_enable_auto_update_db', false ) ) { |
|
| 537 | + self::update(); |
|
| 538 | + } else { |
|
| 539 | + WC_Admin_Notices::add_notice( 'update', true ); |
|
| 540 | + } |
|
| 541 | + } else { |
|
| 542 | + self::update_db_version(); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Update WC version to current. |
|
| 548 | + */ |
|
| 549 | + private static function update_wc_version() { |
|
| 550 | + update_option( 'woocommerce_version', WC()->version ); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Get list of DB update callbacks. |
|
| 555 | + * |
|
| 556 | + * @since 3.0.0 |
|
| 557 | + * @return array |
|
| 558 | + */ |
|
| 559 | + public static function get_db_update_callbacks() { |
|
| 560 | + return self::$db_updates; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Push all needed DB updates to the queue for processing. |
|
| 565 | + */ |
|
| 566 | + private static function update() { |
|
| 567 | + $current_db_version = get_option( 'woocommerce_db_version' ); |
|
| 568 | + $loop = 0; |
|
| 569 | + |
|
| 570 | + foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) { |
|
| 571 | + if ( version_compare( $current_db_version, $version, '<' ) ) { |
|
| 572 | + foreach ( $update_callbacks as $update_callback ) { |
|
| 573 | + WC()->queue()->schedule_single( |
|
| 574 | + time() + $loop, |
|
| 575 | + 'woocommerce_run_update_callback', |
|
| 576 | + array( |
|
| 577 | + 'update_callback' => $update_callback, |
|
| 578 | + ), |
|
| 579 | + 'woocommerce-db-updates' |
|
| 580 | + ); |
|
| 581 | + $loop++; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + // After the callbacks finish, update the db version to the current WC version. |
|
| 587 | + $current_wc_version = WC()->version; |
|
| 588 | + if ( version_compare( $current_db_version, $current_wc_version, '<' ) && |
|
| 589 | + ! WC()->queue()->get_next( 'woocommerce_update_db_to_current_version' ) ) { |
|
| 590 | + WC()->queue()->schedule_single( |
|
| 591 | + time() + $loop, |
|
| 592 | + 'woocommerce_update_db_to_current_version', |
|
| 593 | + array( |
|
| 594 | + 'version' => $current_wc_version, |
|
| 595 | + ), |
|
| 596 | + 'woocommerce-db-updates' |
|
| 597 | + ); |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * Update DB version to current. |
|
| 603 | + * |
|
| 604 | + * @param string|null $version New WooCommerce DB version or null. |
|
| 605 | + */ |
|
| 606 | + public static function update_db_version( $version = null ) { |
|
| 607 | + update_option( 'woocommerce_db_version', is_null( $version ) ? WC()->version : $version ); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Add more cron schedules. |
|
| 612 | + * |
|
| 613 | + * @param array $schedules List of WP scheduled cron jobs. |
|
| 614 | + * |
|
| 615 | + * @return array |
|
| 616 | + */ |
|
| 617 | + public static function cron_schedules( $schedules ) { |
|
| 618 | + $schedules['monthly'] = array( |
|
| 619 | + 'interval' => 2635200, |
|
| 620 | + 'display' => __( 'Monthly', 'woocommerce' ), |
|
| 621 | + ); |
|
| 622 | + $schedules['fifteendays'] = array( |
|
| 623 | + 'interval' => 1296000, |
|
| 624 | + 'display' => __( 'Every 15 Days', 'woocommerce' ), |
|
| 625 | + ); |
|
| 626 | + return $schedules; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Create cron jobs (clear them first). |
|
| 631 | + */ |
|
| 632 | + private static function create_cron_jobs() { |
|
| 633 | + wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' ); |
|
| 634 | + wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' ); |
|
| 635 | + wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' ); |
|
| 636 | + wp_clear_scheduled_hook( 'woocommerce_cleanup_personal_data' ); |
|
| 637 | + wp_clear_scheduled_hook( 'woocommerce_cleanup_logs' ); |
|
| 638 | + wp_clear_scheduled_hook( 'woocommerce_geoip_updater' ); |
|
| 639 | + wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); |
|
| 640 | + wp_clear_scheduled_hook( 'woocommerce_cleanup_rate_limits' ); |
|
| 641 | + |
|
| 642 | + $ve = get_option( 'gmt_offset' ) > 0 ? '-' : '+'; |
|
| 643 | + |
|
| 644 | + wp_schedule_event( strtotime( '00:00 tomorrow ' . $ve . absint( get_option( 'gmt_offset' ) ) . ' HOURS' ), 'daily', 'woocommerce_scheduled_sales' ); |
|
| 645 | + |
|
| 646 | + $held_duration = get_option( 'woocommerce_hold_stock_minutes', '60' ); |
|
| 647 | + |
|
| 648 | + if ( '' !== $held_duration ) { |
|
| 649 | + /** |
|
| 650 | + * Determines the interval at which to cancel unpaid orders in minutes. |
|
| 651 | + * |
|
| 652 | + * @since 5.1.0 |
|
| 653 | + */ |
|
| 654 | + $cancel_unpaid_interval = apply_filters( 'woocommerce_cancel_unpaid_orders_interval_minutes', absint( $held_duration ) ); |
|
| 655 | + wp_schedule_single_event( time() + ( absint( $cancel_unpaid_interval ) * 60 ), 'woocommerce_cancel_unpaid_orders' ); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + // Delay the first run of `woocommerce_cleanup_personal_data` by 10 seconds |
|
| 659 | + // so it doesn't occur in the same request. WooCommerce Admin also schedules |
|
| 660 | + // a daily cron that gets lost due to a race condition. WC_Privacy's background |
|
| 661 | + // processing instance updates the cron schedule from within a cron job. |
|
| 662 | + wp_schedule_event( time() + 10, 'daily', 'woocommerce_cleanup_personal_data' ); |
|
| 663 | + wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_logs' ); |
|
| 664 | + wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'woocommerce_cleanup_sessions' ); |
|
| 665 | + wp_schedule_event( time() + MINUTE_IN_SECONDS, 'fifteendays', 'woocommerce_geoip_updater' ); |
|
| 666 | + /** |
|
| 667 | + * How frequent to schedule the tracker send event. |
|
| 668 | + * |
|
| 669 | + * @since 2.3.0 |
|
| 670 | + */ |
|
| 671 | + wp_schedule_event( time() + 10, apply_filters( 'woocommerce_tracker_event_recurrence', 'daily' ), 'woocommerce_tracker_send_event' ); |
|
| 672 | + wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_rate_limits' ); |
|
| 673 | + |
|
| 674 | + if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) { |
|
| 675 | + wp_schedule_event( time(), 'daily', 'wc_admin_daily' ); |
|
| 676 | + } |
|
| 677 | + // Note: this is potentially redundant when the core package exists. |
|
| 678 | + wp_schedule_single_event( time() + 10, 'generate_category_lookup_table' ); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Create pages on installation. |
|
| 683 | + */ |
|
| 684 | + public static function maybe_create_pages() { |
|
| 685 | + if ( empty( get_option( 'woocommerce_db_version' ) ) ) { |
|
| 686 | + self::create_pages(); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Create pages that the plugin relies on, storing page IDs in variables. |
|
| 692 | + */ |
|
| 693 | + public static function create_pages() { |
|
| 694 | + include_once dirname( __FILE__ ) . '/admin/wc-admin-functions.php'; |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Determines the cart shortcode tag used for the cart page. |
|
| 698 | + * |
|
| 699 | + * @since 2.1.0 |
|
| 700 | + */ |
|
| 701 | + $cart_shortcode = apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ); |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Determines the checkout shortcode tag used on the checkout page. |
|
| 705 | + * |
|
| 706 | + * @since 2.1.0 |
|
| 707 | + */ |
|
| 708 | + $checkout_shortcode = apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ); |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * Determines the my account shortcode tag used on the my account page. |
|
| 712 | + * |
|
| 713 | + * @since 2.1.0 |
|
| 714 | + */ |
|
| 715 | + $my_account_shortcode = apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ); |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * Determines which pages are created during install. |
|
| 719 | + * |
|
| 720 | + * @since 2.1.0 |
|
| 721 | + */ |
|
| 722 | + $pages = apply_filters( |
|
| 723 | + 'woocommerce_create_pages', |
|
| 724 | + array( |
|
| 725 | + 'shop' => array( |
|
| 726 | + 'name' => _x( 'shop', 'Page slug', 'woocommerce' ), |
|
| 727 | + 'title' => _x( 'Shop', 'Page title', 'woocommerce' ), |
|
| 728 | + 'content' => '', |
|
| 729 | + ), |
|
| 730 | + 'cart' => array( |
|
| 731 | + 'name' => _x( 'cart', 'Page slug', 'woocommerce' ), |
|
| 732 | + 'title' => _x( 'Cart', 'Page title', 'woocommerce' ), |
|
| 733 | + 'content' => '<!-- wp:shortcode -->[' . $cart_shortcode . ']<!-- /wp:shortcode -->', |
|
| 734 | + ), |
|
| 735 | + 'checkout' => array( |
|
| 736 | + 'name' => _x( 'checkout', 'Page slug', 'woocommerce' ), |
|
| 737 | + 'title' => _x( 'Checkout', 'Page title', 'woocommerce' ), |
|
| 738 | + 'content' => '<!-- wp:shortcode -->[' . $checkout_shortcode . ']<!-- /wp:shortcode -->', |
|
| 739 | + ), |
|
| 740 | + 'myaccount' => array( |
|
| 741 | + 'name' => _x( 'my-account', 'Page slug', 'woocommerce' ), |
|
| 742 | + 'title' => _x( 'My account', 'Page title', 'woocommerce' ), |
|
| 743 | + 'content' => '<!-- wp:shortcode -->[' . $my_account_shortcode . ']<!-- /wp:shortcode -->', |
|
| 744 | + ), |
|
| 745 | + 'refund_returns' => array( |
|
| 746 | + 'name' => _x( 'refund_returns', 'Page slug', 'woocommerce' ), |
|
| 747 | + 'title' => _x( 'Refund and Returns Policy', 'Page title', 'woocommerce' ), |
|
| 748 | + 'content' => self::get_refunds_return_policy_page_content(), |
|
| 749 | + 'post_status' => 'draft', |
|
| 750 | + ), |
|
| 751 | + ) |
|
| 752 | + ); |
|
| 753 | + |
|
| 754 | + foreach ( $pages as $key => $page ) { |
|
| 755 | + wc_create_page( |
|
| 756 | + esc_sql( $page['name'] ), |
|
| 757 | + 'woocommerce_' . $key . '_page_id', |
|
| 758 | + $page['title'], |
|
| 759 | + $page['content'], |
|
| 760 | + ! empty( $page['parent'] ) ? wc_get_page_id( $page['parent'] ) : '', |
|
| 761 | + ! empty( $page['post_status'] ) ? $page['post_status'] : 'publish' |
|
| 762 | + ); |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * Default options. |
|
| 768 | + * |
|
| 769 | + * Sets up the default options used on the settings page. |
|
| 770 | + */ |
|
| 771 | + private static function create_options() { |
|
| 772 | + // Include settings so that we can run through defaults. |
|
| 773 | + include_once dirname( __FILE__ ) . '/admin/class-wc-admin-settings.php'; |
|
| 774 | + |
|
| 775 | + $settings = WC_Admin_Settings::get_settings_pages(); |
|
| 776 | + |
|
| 777 | + foreach ( $settings as $section ) { |
|
| 778 | + if ( ! is_a( $section, 'WC_Settings_Page' ) || ! method_exists( $section, 'get_settings' ) ) { |
|
| 779 | + continue; |
|
| 780 | + } |
|
| 781 | + $subsections = array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) ); |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * We are using 'WC_Settings_Page::get_settings' on purpose even thought it's deprecated. |
|
| 785 | + * See the method documentation for an explanation. |
|
| 786 | + */ |
|
| 787 | + |
|
| 788 | + foreach ( $subsections as $subsection ) { |
|
| 789 | + foreach ( $section->get_settings( $subsection ) as $value ) { |
|
| 790 | + if ( isset( $value['default'] ) && isset( $value['id'] ) ) { |
|
| 791 | + $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true; |
|
| 792 | + add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) ); |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // Define other defaults if not in setting screens. |
|
| 799 | + add_option( 'woocommerce_single_image_width', '600', '', 'yes' ); |
|
| 800 | + add_option( 'woocommerce_thumbnail_image_width', '300', '', 'yes' ); |
|
| 801 | + add_option( 'woocommerce_checkout_highlight_required_fields', 'yes', '', 'yes' ); |
|
| 802 | + add_option( 'woocommerce_demo_store', 'no', '', 'no' ); |
|
| 803 | + |
|
| 804 | + if ( self::is_new_install() ) { |
|
| 805 | + // Define initial tax classes. |
|
| 806 | + WC_Tax::create_tax_class( __( 'Reduced rate', 'woocommerce' ) ); |
|
| 807 | + WC_Tax::create_tax_class( __( 'Zero rate', 'woocommerce' ) ); |
|
| 808 | + |
|
| 809 | + // For new installs, setup and enable Approved Product Download Directories. |
|
| 810 | + wc_get_container()->get( Download_Directories_Sync::class )->init_feature( false, true ); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Delete obsolete notes. |
|
| 816 | + */ |
|
| 817 | + public static function delete_obsolete_notes() { |
|
| 818 | + global $wpdb; |
|
| 819 | + $obsolete_notes_names = array( |
|
| 820 | + 'wc-admin-welcome-note', |
|
| 821 | + 'wc-admin-store-notice-setting-moved', |
|
| 822 | + 'wc-admin-store-notice-giving-feedback', |
|
| 823 | + 'wc-admin-learn-more-about-product-settings', |
|
| 824 | + 'wc-admin-onboarding-profiler-reminder', |
|
| 825 | + 'wc-admin-historical-data', |
|
| 826 | + 'wc-admin-review-shipping-settings', |
|
| 827 | + 'wc-admin-home-screen-feedback', |
|
| 828 | + 'wc-admin-effortless-payments-by-mollie', |
|
| 829 | + 'wc-admin-google-ads-and-marketing', |
|
| 830 | + 'wc-admin-marketing-intro', |
|
| 831 | + 'wc-admin-draw-attention', |
|
| 832 | + 'wc-admin-need-some-inspiration', |
|
| 833 | + 'wc-admin-choose-niche', |
|
| 834 | + 'wc-admin-start-dropshipping-business', |
|
| 835 | + 'wc-admin-filter-by-product-variations-in-reports', |
|
| 836 | + 'wc-admin-learn-more-about-variable-products', |
|
| 837 | + 'wc-admin-getting-started-ecommerce-webinar', |
|
| 838 | + 'wc-admin-navigation-feedback', |
|
| 839 | + 'wc-admin-navigation-feedback-follow-up', |
|
| 840 | + 'wc-admin-set-up-additional-payment-types', |
|
| 841 | + 'wc-admin-deactivate-plugin', |
|
| 842 | + ); |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * An array of deprecated notes to delete on update. |
|
| 846 | + * |
|
| 847 | + * @since 6.5.0 |
|
| 848 | + */ |
|
| 849 | + $additional_obsolete_notes_names = apply_filters( |
|
| 850 | + 'woocommerce_admin_obsolete_notes_names', |
|
| 851 | + array() |
|
| 852 | + ); |
|
| 853 | + |
|
| 854 | + if ( is_array( $additional_obsolete_notes_names ) ) { |
|
| 855 | + $obsolete_notes_names = array_merge( |
|
| 856 | + $obsolete_notes_names, |
|
| 857 | + $additional_obsolete_notes_names |
|
| 858 | + ); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + foreach ( $obsolete_notes_names as $obsolete_notes_name ) { |
|
| 862 | + $wpdb->delete( $wpdb->prefix . 'wc_admin_notes', array( 'name' => $obsolete_notes_name ) ); |
|
| 863 | + $wpdb->delete( $wpdb->prefix . 'wc_admin_note_actions', array( 'name' => $obsolete_notes_name ) ); |
|
| 864 | + } |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * Migrate option values to their new keys/names. |
|
| 869 | + */ |
|
| 870 | + public static function migrate_options() { |
|
| 871 | + |
|
| 872 | + $migrated_options = array( |
|
| 873 | + 'woocommerce_onboarding_profile' => 'wc_onboarding_profile', |
|
| 874 | + 'woocommerce_admin_install_timestamp' => 'wc_admin_install_timestamp', |
|
| 875 | + 'woocommerce_onboarding_opt_in' => 'wc_onboarding_opt_in', |
|
| 876 | + 'woocommerce_admin_import_stats' => 'wc_admin_import_stats', |
|
| 877 | + 'woocommerce_admin_version' => 'wc_admin_version', |
|
| 878 | + 'woocommerce_admin_last_orders_milestone' => 'wc_admin_last_orders_milestone', |
|
| 879 | + 'woocommerce_admin-wc-helper-last-refresh' => 'wc-admin-wc-helper-last-refresh', |
|
| 880 | + 'woocommerce_admin_report_export_status' => 'wc_admin_report_export_status', |
|
| 881 | + 'woocommerce_task_list_complete' => 'woocommerce_task_list_complete', |
|
| 882 | + 'woocommerce_task_list_hidden' => 'woocommerce_task_list_hidden', |
|
| 883 | + 'woocommerce_extended_task_list_complete' => 'woocommerce_extended_task_list_complete', |
|
| 884 | + 'woocommerce_extended_task_list_hidden' => 'woocommerce_extended_task_list_hidden', |
|
| 885 | + ); |
|
| 886 | + |
|
| 887 | + wc_maybe_define_constant( 'WC_ADMIN_MIGRATING_OPTIONS', true ); |
|
| 888 | + |
|
| 889 | + foreach ( $migrated_options as $new_option => $old_option ) { |
|
| 890 | + $old_option_value = get_option( $old_option, false ); |
|
| 891 | + |
|
| 892 | + // Continue if no option value was previously set. |
|
| 893 | + if ( false === $old_option_value ) { |
|
| 894 | + continue; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + if ( '1' === $old_option_value ) { |
|
| 898 | + $old_option_value = 'yes'; |
|
| 899 | + } elseif ( '0' === $old_option_value ) { |
|
| 900 | + $old_option_value = 'no'; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + update_option( $new_option, $old_option_value ); |
|
| 904 | + if ( $new_option !== $old_option ) { |
|
| 905 | + delete_option( $old_option ); |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + /** |
|
| 910 | + * Add the default terms for WC taxonomies - product types and order statuses. Modify this at your own risk. |
|
| 911 | + */ |
|
| 912 | + public static function create_terms() { |
|
| 913 | + $taxonomies = array( |
|
| 914 | + 'product_type' => array( |
|
| 915 | + 'simple', |
|
| 916 | + 'grouped', |
|
| 917 | + 'variable', |
|
| 918 | + 'external', |
|
| 919 | + ), |
|
| 920 | + 'product_visibility' => array( |
|
| 921 | + 'exclude-from-search', |
|
| 922 | + 'exclude-from-catalog', |
|
| 923 | + 'featured', |
|
| 924 | + 'outofstock', |
|
| 925 | + 'rated-1', |
|
| 926 | + 'rated-2', |
|
| 927 | + 'rated-3', |
|
| 928 | + 'rated-4', |
|
| 929 | + 'rated-5', |
|
| 930 | + ), |
|
| 931 | + ); |
|
| 932 | + |
|
| 933 | + foreach ( $taxonomies as $taxonomy => $terms ) { |
|
| 934 | + foreach ( $terms as $term ) { |
|
| 935 | + if ( ! get_term_by( 'name', $term, $taxonomy ) ) { // @codingStandardsIgnoreLine. |
|
| 936 | + wp_insert_term( $term, $taxonomy ); |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + $woocommerce_default_category = (int) get_option( 'default_product_cat', 0 ); |
|
| 942 | + |
|
| 943 | + if ( ! $woocommerce_default_category || ! term_exists( $woocommerce_default_category, 'product_cat' ) ) { |
|
| 944 | + $default_product_cat_id = 0; |
|
| 945 | + $default_product_cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug', 'woocommerce' ) ); |
|
| 946 | + $default_product_cat = get_term_by( 'slug', $default_product_cat_slug, 'product_cat' ); // @codingStandardsIgnoreLine. |
|
| 947 | + |
|
| 948 | + if ( $default_product_cat ) { |
|
| 949 | + $default_product_cat_id = absint( $default_product_cat->term_taxonomy_id ); |
|
| 950 | + } else { |
|
| 951 | + $result = wp_insert_term( _x( 'Uncategorized', 'Default category slug', 'woocommerce' ), 'product_cat', array( 'slug' => $default_product_cat_slug ) ); |
|
| 952 | + |
|
| 953 | + if ( ! is_wp_error( $result ) && ! empty( $result['term_taxonomy_id'] ) ) { |
|
| 954 | + $default_product_cat_id = absint( $result['term_taxonomy_id'] ); |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + if ( $default_product_cat_id ) { |
|
| 959 | + update_option( 'default_product_cat', $default_product_cat_id ); |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * Set up the database tables which the plugin needs to function. |
|
| 966 | + * WARNING: If you are modifying this method, make sure that its safe to call regardless of the state of database. |
|
| 967 | + * |
|
| 968 | + * This is called from `install` method and is executed in-sync when WC is installed or updated. This can also be called optionally from `verify_base_tables`. |
|
| 969 | + * |
|
| 970 | + * TODO: Add all crucial tables that we have created from workers in the past. |
|
| 971 | + * |
|
| 972 | + * Tables: |
|
| 973 | + * woocommerce_attribute_taxonomies - Table for storing attribute taxonomies - these are user defined |
|
| 974 | + * woocommerce_downloadable_product_permissions - Table for storing user and guest download permissions. |
|
| 975 | + * KEY(order_id, product_id, download_id) used for organizing downloads on the My Account page |
|
| 976 | + * woocommerce_order_items - Order line items are stored in a table to make them easily queryable for reports |
|
| 977 | + * woocommerce_order_itemmeta - Order line item meta is stored in a table for storing extra data. |
|
| 978 | + * woocommerce_tax_rates - Tax Rates are stored inside 2 tables making tax queries simple and efficient. |
|
| 979 | + * woocommerce_tax_rate_locations - Each rate can be applied to more than one postcode/city hence the second table. |
|
| 980 | + */ |
|
| 981 | + public static function create_tables() { |
|
| 982 | + global $wpdb; |
|
| 983 | + |
|
| 984 | + $wpdb->hide_errors(); |
|
| 985 | + |
|
| 986 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Before updating with DBDELTA, remove any primary keys which could be |
|
| 990 | + * modified due to schema updates. |
|
| 991 | + */ |
|
| 992 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_downloadable_product_permissions';" ) ) { |
|
| 993 | + if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}woocommerce_downloadable_product_permissions` LIKE 'permission_id';" ) ) { |
|
| 994 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions DROP PRIMARY KEY, ADD `permission_id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT;" ); |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * Change wp_woocommerce_sessions schema to use a bigint auto increment field instead of char(32) field as |
|
| 1000 | + * the primary key as it is not a good practice to use a char(32) field as the primary key of a table and as |
|
| 1001 | + * there were reports of issues with this table (see https://github.com/woocommerce/woocommerce/issues/20912). |
|
| 1002 | + * |
|
| 1003 | + * This query needs to run before dbDelta() as this WP function is not able to handle primary key changes |
|
| 1004 | + * (see https://github.com/woocommerce/woocommerce/issues/21534 and https://core.trac.wordpress.org/ticket/40357). |
|
| 1005 | + */ |
|
| 1006 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_sessions'" ) ) { |
|
| 1007 | + if ( ! $wpdb->get_var( "SHOW KEYS FROM {$wpdb->prefix}woocommerce_sessions WHERE Key_name = 'PRIMARY' AND Column_name = 'session_id'" ) ) { |
|
| 1008 | + $wpdb->query( |
|
| 1009 | + "ALTER TABLE `{$wpdb->prefix}woocommerce_sessions` DROP PRIMARY KEY, DROP KEY `session_id`, ADD PRIMARY KEY(`session_id`), ADD UNIQUE KEY(`session_key`)" |
|
| 1010 | + ); |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + dbDelta( self::get_schema() ); |
|
| 1015 | + |
|
| 1016 | + $index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->comments} WHERE column_name = 'comment_type' and key_name = 'woo_idx_comment_type'" ); |
|
| 1017 | + |
|
| 1018 | + if ( is_null( $index_exists ) ) { |
|
| 1019 | + // Add an index to the field comment_type to improve the response time of the query |
|
| 1020 | + // used by WC_Comments::wp_count_comments() to get the number of comments by type. |
|
| 1021 | + $wpdb->query( "ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)" ); |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + // Get tables data types and check it matches before adding constraint. |
|
| 1025 | + $download_log_columns = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}wc_download_log WHERE Field = 'permission_id'", ARRAY_A ); |
|
| 1026 | + $download_log_column_type = ''; |
|
| 1027 | + if ( isset( $download_log_columns[0]['Type'] ) ) { |
|
| 1028 | + $download_log_column_type = $download_log_columns[0]['Type']; |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + $download_permissions_columns = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE Field = 'permission_id'", ARRAY_A ); |
|
| 1032 | + $download_permissions_column_type = ''; |
|
| 1033 | + if ( isset( $download_permissions_columns[0]['Type'] ) ) { |
|
| 1034 | + $download_permissions_column_type = $download_permissions_columns[0]['Type']; |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + // Add constraint to download logs if the columns matches. |
|
| 1038 | + if ( ! empty( $download_permissions_column_type ) && ! empty( $download_log_column_type ) && $download_permissions_column_type === $download_log_column_type ) { |
|
| 1039 | + $fk_result = $wpdb->get_row( "SHOW CREATE TABLE {$wpdb->prefix}wc_download_log" ); |
|
| 1040 | + if ( false === strpos( $fk_result->{'Create Table'}, "fk_{$wpdb->prefix}wc_download_log_permission_id" ) ) { |
|
| 1041 | + $wpdb->query( |
|
| 1042 | + "ALTER TABLE `{$wpdb->prefix}wc_download_log` |
|
| 1043 | 1043 | ADD CONSTRAINT `fk_{$wpdb->prefix}wc_download_log_permission_id` |
| 1044 | 1044 | FOREIGN KEY (`permission_id`) |
| 1045 | 1045 | REFERENCES `{$wpdb->prefix}woocommerce_downloadable_product_permissions` (`permission_id`) ON DELETE CASCADE;" |
| 1046 | - ); |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - // Clear table caches. |
|
| 1051 | - delete_transient( 'wc_attribute_taxonomies' ); |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * Get Table schema. |
|
| 1056 | - * |
|
| 1057 | - * See https://github.com/woocommerce/woocommerce/wiki/Database-Description/ |
|
| 1058 | - * |
|
| 1059 | - * A note on indexes; Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that. |
|
| 1060 | - * As of WordPress 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which |
|
| 1061 | - * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters. |
|
| 1062 | - * |
|
| 1063 | - * Changing indexes may cause duplicate index notices in logs due to https://core.trac.wordpress.org/ticket/34870 but dropping |
|
| 1064 | - * indexes first causes too much load on some servers/larger DB. |
|
| 1065 | - * |
|
| 1066 | - * When adding or removing a table, make sure to update the list of tables in WC_Install::get_tables(). |
|
| 1067 | - * |
|
| 1068 | - * @return string |
|
| 1069 | - */ |
|
| 1070 | - private static function get_schema() { |
|
| 1071 | - global $wpdb; |
|
| 1072 | - |
|
| 1073 | - $collate = ''; |
|
| 1074 | - |
|
| 1075 | - if ( $wpdb->has_cap( 'collation' ) ) { |
|
| 1076 | - $collate = $wpdb->get_charset_collate(); |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - /* |
|
| 1046 | + ); |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + // Clear table caches. |
|
| 1051 | + delete_transient( 'wc_attribute_taxonomies' ); |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * Get Table schema. |
|
| 1056 | + * |
|
| 1057 | + * See https://github.com/woocommerce/woocommerce/wiki/Database-Description/ |
|
| 1058 | + * |
|
| 1059 | + * A note on indexes; Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that. |
|
| 1060 | + * As of WordPress 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which |
|
| 1061 | + * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters. |
|
| 1062 | + * |
|
| 1063 | + * Changing indexes may cause duplicate index notices in logs due to https://core.trac.wordpress.org/ticket/34870 but dropping |
|
| 1064 | + * indexes first causes too much load on some servers/larger DB. |
|
| 1065 | + * |
|
| 1066 | + * When adding or removing a table, make sure to update the list of tables in WC_Install::get_tables(). |
|
| 1067 | + * |
|
| 1068 | + * @return string |
|
| 1069 | + */ |
|
| 1070 | + private static function get_schema() { |
|
| 1071 | + global $wpdb; |
|
| 1072 | + |
|
| 1073 | + $collate = ''; |
|
| 1074 | + |
|
| 1075 | + if ( $wpdb->has_cap( 'collation' ) ) { |
|
| 1076 | + $collate = $wpdb->get_charset_collate(); |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + /* |
|
| 1080 | 1080 | * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that. |
| 1081 | 1081 | * As of WP 4.2, however, they moved to utf8mb4, which uses 4 bytes per character. This means that an index which |
| 1082 | 1082 | * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters. |
| 1083 | 1083 | */ |
| 1084 | - $max_index_length = 191; |
|
| 1084 | + $max_index_length = 191; |
|
| 1085 | 1085 | |
| 1086 | - $product_attributes_lookup_table_creation_sql = wc_get_container()->get( DataRegenerator::class )->get_table_creation_sql(); |
|
| 1086 | + $product_attributes_lookup_table_creation_sql = wc_get_container()->get( DataRegenerator::class )->get_table_creation_sql(); |
|
| 1087 | 1087 | |
| 1088 | - $tables = " |
|
| 1088 | + $tables = " |
|
| 1089 | 1089 | CREATE TABLE {$wpdb->prefix}woocommerce_sessions ( |
| 1090 | 1090 | session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 1091 | 1091 | session_key char(32) NOT NULL, |
@@ -1428,686 +1428,686 @@ discard block |
||
| 1428 | 1428 | ) $collate; |
| 1429 | 1429 | "; |
| 1430 | 1430 | |
| 1431 | - return $tables; |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * Return a list of WooCommerce tables. Used to make sure all WC tables are dropped when uninstalling the plugin |
|
| 1436 | - * in a single site or multi site environment. |
|
| 1437 | - * |
|
| 1438 | - * @return array WC tables. |
|
| 1439 | - */ |
|
| 1440 | - public static function get_tables() { |
|
| 1441 | - global $wpdb; |
|
| 1442 | - |
|
| 1443 | - $tables = array( |
|
| 1444 | - "{$wpdb->prefix}wc_download_log", |
|
| 1445 | - "{$wpdb->prefix}wc_product_download_directories", |
|
| 1446 | - "{$wpdb->prefix}wc_product_meta_lookup", |
|
| 1447 | - "{$wpdb->prefix}wc_tax_rate_classes", |
|
| 1448 | - "{$wpdb->prefix}wc_webhooks", |
|
| 1449 | - "{$wpdb->prefix}woocommerce_api_keys", |
|
| 1450 | - "{$wpdb->prefix}woocommerce_attribute_taxonomies", |
|
| 1451 | - "{$wpdb->prefix}woocommerce_downloadable_product_permissions", |
|
| 1452 | - "{$wpdb->prefix}woocommerce_log", |
|
| 1453 | - "{$wpdb->prefix}woocommerce_order_itemmeta", |
|
| 1454 | - "{$wpdb->prefix}woocommerce_order_items", |
|
| 1455 | - "{$wpdb->prefix}woocommerce_payment_tokenmeta", |
|
| 1456 | - "{$wpdb->prefix}woocommerce_payment_tokens", |
|
| 1457 | - "{$wpdb->prefix}woocommerce_sessions", |
|
| 1458 | - "{$wpdb->prefix}woocommerce_shipping_zone_locations", |
|
| 1459 | - "{$wpdb->prefix}woocommerce_shipping_zone_methods", |
|
| 1460 | - "{$wpdb->prefix}woocommerce_shipping_zones", |
|
| 1461 | - "{$wpdb->prefix}woocommerce_tax_rate_locations", |
|
| 1462 | - "{$wpdb->prefix}woocommerce_tax_rates", |
|
| 1463 | - "{$wpdb->prefix}wc_reserved_stock", |
|
| 1464 | - "{$wpdb->prefix}wc_rate_limits", |
|
| 1465 | - wc_get_container()->get( DataRegenerator::class )->get_lookup_table_name(), |
|
| 1466 | - |
|
| 1467 | - // WCA Tables. |
|
| 1468 | - "{$wpdb->prefix}wc_order_stats", |
|
| 1469 | - "{$wpdb->prefix}wc_order_product_lookup", |
|
| 1470 | - "{$wpdb->prefix}wc_order_tax_lookup", |
|
| 1471 | - "{$wpdb->prefix}wc_order_coupon_lookup", |
|
| 1472 | - "{$wpdb->prefix}wc_admin_notes", |
|
| 1473 | - "{$wpdb->prefix}wc_admin_note_actions", |
|
| 1474 | - "{$wpdb->prefix}wc_customer_lookup", |
|
| 1475 | - "{$wpdb->prefix}wc_category_lookup", |
|
| 1476 | - ); |
|
| 1477 | - |
|
| 1478 | - /** |
|
| 1479 | - * Filter the list of known WooCommerce tables. |
|
| 1480 | - * |
|
| 1481 | - * If WooCommerce plugins need to add new tables, they can inject them here. |
|
| 1482 | - * |
|
| 1483 | - * @param array $tables An array of WooCommerce-specific database table names. |
|
| 1484 | - * @since 3.4.0 |
|
| 1485 | - */ |
|
| 1486 | - $tables = apply_filters( 'woocommerce_install_get_tables', $tables ); |
|
| 1487 | - |
|
| 1488 | - return $tables; |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - /** |
|
| 1492 | - * Drop WooCommerce tables. |
|
| 1493 | - * |
|
| 1494 | - * @return void |
|
| 1495 | - */ |
|
| 1496 | - public static function drop_tables() { |
|
| 1497 | - global $wpdb; |
|
| 1498 | - |
|
| 1499 | - $tables = self::get_tables(); |
|
| 1500 | - |
|
| 1501 | - foreach ( $tables as $table ) { |
|
| 1502 | - $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 1503 | - } |
|
| 1504 | - } |
|
| 1505 | - |
|
| 1506 | - /** |
|
| 1507 | - * Uninstall tables when MU blog is deleted. |
|
| 1508 | - * |
|
| 1509 | - * @param array $tables List of tables that will be deleted by WP. |
|
| 1510 | - * |
|
| 1511 | - * @return string[] |
|
| 1512 | - */ |
|
| 1513 | - public static function wpmu_drop_tables( $tables ) { |
|
| 1514 | - return array_merge( $tables, self::get_tables() ); |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Create roles and capabilities. |
|
| 1519 | - */ |
|
| 1520 | - public static function create_roles() { |
|
| 1521 | - global $wp_roles; |
|
| 1522 | - |
|
| 1523 | - if ( ! class_exists( 'WP_Roles' ) ) { |
|
| 1524 | - return; |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - if ( ! isset( $wp_roles ) ) { |
|
| 1528 | - $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - // Dummy gettext calls to get strings in the catalog. |
|
| 1532 | - /* translators: user role */ |
|
| 1533 | - _x( 'Customer', 'User role', 'woocommerce' ); |
|
| 1534 | - /* translators: user role */ |
|
| 1535 | - _x( 'Shop manager', 'User role', 'woocommerce' ); |
|
| 1536 | - |
|
| 1537 | - // Customer role. |
|
| 1538 | - add_role( |
|
| 1539 | - 'customer', |
|
| 1540 | - 'Customer', |
|
| 1541 | - array( |
|
| 1542 | - 'read' => true, |
|
| 1543 | - ) |
|
| 1544 | - ); |
|
| 1545 | - |
|
| 1546 | - // Shop manager role. |
|
| 1547 | - add_role( |
|
| 1548 | - 'shop_manager', |
|
| 1549 | - 'Shop manager', |
|
| 1550 | - array( |
|
| 1551 | - 'level_9' => true, |
|
| 1552 | - 'level_8' => true, |
|
| 1553 | - 'level_7' => true, |
|
| 1554 | - 'level_6' => true, |
|
| 1555 | - 'level_5' => true, |
|
| 1556 | - 'level_4' => true, |
|
| 1557 | - 'level_3' => true, |
|
| 1558 | - 'level_2' => true, |
|
| 1559 | - 'level_1' => true, |
|
| 1560 | - 'level_0' => true, |
|
| 1561 | - 'read' => true, |
|
| 1562 | - 'read_private_pages' => true, |
|
| 1563 | - 'read_private_posts' => true, |
|
| 1564 | - 'edit_posts' => true, |
|
| 1565 | - 'edit_pages' => true, |
|
| 1566 | - 'edit_published_posts' => true, |
|
| 1567 | - 'edit_published_pages' => true, |
|
| 1568 | - 'edit_private_pages' => true, |
|
| 1569 | - 'edit_private_posts' => true, |
|
| 1570 | - 'edit_others_posts' => true, |
|
| 1571 | - 'edit_others_pages' => true, |
|
| 1572 | - 'publish_posts' => true, |
|
| 1573 | - 'publish_pages' => true, |
|
| 1574 | - 'delete_posts' => true, |
|
| 1575 | - 'delete_pages' => true, |
|
| 1576 | - 'delete_private_pages' => true, |
|
| 1577 | - 'delete_private_posts' => true, |
|
| 1578 | - 'delete_published_pages' => true, |
|
| 1579 | - 'delete_published_posts' => true, |
|
| 1580 | - 'delete_others_posts' => true, |
|
| 1581 | - 'delete_others_pages' => true, |
|
| 1582 | - 'manage_categories' => true, |
|
| 1583 | - 'manage_links' => true, |
|
| 1584 | - 'moderate_comments' => true, |
|
| 1585 | - 'upload_files' => true, |
|
| 1586 | - 'export' => true, |
|
| 1587 | - 'import' => true, |
|
| 1588 | - 'list_users' => true, |
|
| 1589 | - 'edit_theme_options' => true, |
|
| 1590 | - ) |
|
| 1591 | - ); |
|
| 1592 | - |
|
| 1593 | - $capabilities = self::get_core_capabilities(); |
|
| 1594 | - |
|
| 1595 | - foreach ( $capabilities as $cap_group ) { |
|
| 1596 | - foreach ( $cap_group as $cap ) { |
|
| 1597 | - $wp_roles->add_cap( 'shop_manager', $cap ); |
|
| 1598 | - $wp_roles->add_cap( 'administrator', $cap ); |
|
| 1599 | - } |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * Get capabilities for WooCommerce - these are assigned to admin/shop manager during installation or reset. |
|
| 1605 | - * |
|
| 1606 | - * @return array |
|
| 1607 | - */ |
|
| 1608 | - public static function get_core_capabilities() { |
|
| 1609 | - $capabilities = array(); |
|
| 1610 | - |
|
| 1611 | - $capabilities['core'] = array( |
|
| 1612 | - 'manage_woocommerce', |
|
| 1613 | - 'view_woocommerce_reports', |
|
| 1614 | - ); |
|
| 1615 | - |
|
| 1616 | - $capability_types = array( 'product', 'shop_order', 'shop_coupon' ); |
|
| 1617 | - |
|
| 1618 | - foreach ( $capability_types as $capability_type ) { |
|
| 1619 | - |
|
| 1620 | - $capabilities[ $capability_type ] = array( |
|
| 1621 | - // Post type. |
|
| 1622 | - "edit_{$capability_type}", |
|
| 1623 | - "read_{$capability_type}", |
|
| 1624 | - "delete_{$capability_type}", |
|
| 1625 | - "edit_{$capability_type}s", |
|
| 1626 | - "edit_others_{$capability_type}s", |
|
| 1627 | - "publish_{$capability_type}s", |
|
| 1628 | - "read_private_{$capability_type}s", |
|
| 1629 | - "delete_{$capability_type}s", |
|
| 1630 | - "delete_private_{$capability_type}s", |
|
| 1631 | - "delete_published_{$capability_type}s", |
|
| 1632 | - "delete_others_{$capability_type}s", |
|
| 1633 | - "edit_private_{$capability_type}s", |
|
| 1634 | - "edit_published_{$capability_type}s", |
|
| 1635 | - |
|
| 1636 | - // Terms. |
|
| 1637 | - "manage_{$capability_type}_terms", |
|
| 1638 | - "edit_{$capability_type}_terms", |
|
| 1639 | - "delete_{$capability_type}_terms", |
|
| 1640 | - "assign_{$capability_type}_terms", |
|
| 1641 | - ); |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - return $capabilities; |
|
| 1645 | - } |
|
| 1646 | - |
|
| 1647 | - /** |
|
| 1648 | - * Remove WooCommerce roles. |
|
| 1649 | - */ |
|
| 1650 | - public static function remove_roles() { |
|
| 1651 | - global $wp_roles; |
|
| 1652 | - |
|
| 1653 | - if ( ! class_exists( 'WP_Roles' ) ) { |
|
| 1654 | - return; |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - if ( ! isset( $wp_roles ) ) { |
|
| 1658 | - $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
|
| 1659 | - } |
|
| 1660 | - |
|
| 1661 | - $capabilities = self::get_core_capabilities(); |
|
| 1662 | - |
|
| 1663 | - foreach ( $capabilities as $cap_group ) { |
|
| 1664 | - foreach ( $cap_group as $cap ) { |
|
| 1665 | - $wp_roles->remove_cap( 'shop_manager', $cap ); |
|
| 1666 | - $wp_roles->remove_cap( 'administrator', $cap ); |
|
| 1667 | - } |
|
| 1668 | - } |
|
| 1669 | - |
|
| 1670 | - remove_role( 'customer' ); |
|
| 1671 | - remove_role( 'shop_manager' ); |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * Create files/directories. |
|
| 1676 | - */ |
|
| 1677 | - private static function create_files() { |
|
| 1678 | - /** |
|
| 1679 | - * Bypass if filesystem is read-only and/or non-standard upload system is used. |
|
| 1680 | - * |
|
| 1681 | - * @since 3.2.0 |
|
| 1682 | - */ |
|
| 1683 | - if ( apply_filters( 'woocommerce_install_skip_create_files', false ) ) { |
|
| 1684 | - return; |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - // Install files and folders for uploading files and prevent hotlinking. |
|
| 1688 | - $upload_dir = wp_get_upload_dir(); |
|
| 1689 | - $download_method = get_option( 'woocommerce_file_download_method', 'force' ); |
|
| 1690 | - |
|
| 1691 | - $files = array( |
|
| 1692 | - array( |
|
| 1693 | - 'base' => $upload_dir['basedir'] . '/woocommerce_uploads', |
|
| 1694 | - 'file' => 'index.html', |
|
| 1695 | - 'content' => '', |
|
| 1696 | - ), |
|
| 1697 | - array( |
|
| 1698 | - 'base' => WC_LOG_DIR, |
|
| 1699 | - 'file' => '.htaccess', |
|
| 1700 | - 'content' => 'deny from all', |
|
| 1701 | - ), |
|
| 1702 | - array( |
|
| 1703 | - 'base' => WC_LOG_DIR, |
|
| 1704 | - 'file' => 'index.html', |
|
| 1705 | - 'content' => '', |
|
| 1706 | - ), |
|
| 1707 | - array( |
|
| 1708 | - 'base' => $upload_dir['basedir'] . '/woocommerce_uploads', |
|
| 1709 | - 'file' => '.htaccess', |
|
| 1710 | - 'content' => 'redirect' === $download_method ? 'Options -Indexes' : 'deny from all', |
|
| 1711 | - ), |
|
| 1712 | - ); |
|
| 1713 | - |
|
| 1714 | - foreach ( $files as $file ) { |
|
| 1715 | - if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) { |
|
| 1716 | - $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'wb' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen |
|
| 1717 | - if ( $file_handle ) { |
|
| 1718 | - fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite |
|
| 1719 | - fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose |
|
| 1720 | - } |
|
| 1721 | - } |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - // Create attachment for placeholders. |
|
| 1725 | - self::create_placeholder_image(); |
|
| 1726 | - } |
|
| 1727 | - |
|
| 1728 | - /** |
|
| 1729 | - * Create a placeholder image in the media library. |
|
| 1730 | - * |
|
| 1731 | - * @since 3.5.0 |
|
| 1732 | - */ |
|
| 1733 | - private static function create_placeholder_image() { |
|
| 1734 | - $placeholder_image = get_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1735 | - |
|
| 1736 | - // Validate current setting if set. If set, return. |
|
| 1737 | - if ( ! empty( $placeholder_image ) ) { |
|
| 1738 | - if ( ! is_numeric( $placeholder_image ) ) { |
|
| 1739 | - return; |
|
| 1740 | - } elseif ( $placeholder_image && wp_attachment_is_image( $placeholder_image ) ) { |
|
| 1741 | - return; |
|
| 1742 | - } |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - $upload_dir = wp_upload_dir(); |
|
| 1746 | - $source = WC()->plugin_path() . '/assets/images/placeholder-attachment.png'; |
|
| 1747 | - $filename = $upload_dir['basedir'] . '/woocommerce-placeholder.png'; |
|
| 1748 | - |
|
| 1749 | - if ( ! file_exists( $filename ) ) { |
|
| 1750 | - copy( $source, $filename ); // @codingStandardsIgnoreLine. |
|
| 1751 | - } |
|
| 1752 | - |
|
| 1753 | - if ( ! file_exists( $filename ) ) { |
|
| 1754 | - update_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1755 | - return; |
|
| 1756 | - } |
|
| 1757 | - |
|
| 1758 | - $filetype = wp_check_filetype( basename( $filename ), null ); |
|
| 1759 | - $attachment = array( |
|
| 1760 | - 'guid' => $upload_dir['url'] . '/' . basename( $filename ), |
|
| 1761 | - 'post_mime_type' => $filetype['type'], |
|
| 1762 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 1763 | - 'post_content' => '', |
|
| 1764 | - 'post_status' => 'inherit', |
|
| 1765 | - ); |
|
| 1766 | - |
|
| 1767 | - $attach_id = wp_insert_attachment( $attachment, $filename ); |
|
| 1768 | - if ( is_wp_error( $attach_id ) ) { |
|
| 1769 | - update_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1770 | - return; |
|
| 1771 | - } |
|
| 1772 | - |
|
| 1773 | - update_option( 'woocommerce_placeholder_image', $attach_id ); |
|
| 1774 | - |
|
| 1775 | - // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. |
|
| 1776 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1777 | - |
|
| 1778 | - // Generate the metadata for the attachment, and update the database record. |
|
| 1779 | - $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); |
|
| 1780 | - wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 1781 | - } |
|
| 1782 | - |
|
| 1783 | - /** |
|
| 1784 | - * Show action links on the plugin screen. |
|
| 1785 | - * |
|
| 1786 | - * @param mixed $links Plugin Action links. |
|
| 1787 | - * |
|
| 1788 | - * @return array |
|
| 1789 | - */ |
|
| 1790 | - public static function plugin_action_links( $links ) { |
|
| 1791 | - $action_links = array( |
|
| 1792 | - 'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings' ) . '" aria-label="' . esc_attr__( 'View WooCommerce settings', 'woocommerce' ) . '">' . esc_html__( 'Settings', 'woocommerce' ) . '</a>', |
|
| 1793 | - ); |
|
| 1794 | - |
|
| 1795 | - return array_merge( $action_links, $links ); |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - /** |
|
| 1799 | - * Show row meta on the plugin screen. |
|
| 1800 | - * |
|
| 1801 | - * @param mixed $links Plugin Row Meta. |
|
| 1802 | - * @param mixed $file Plugin Base file. |
|
| 1803 | - * |
|
| 1804 | - * @return array |
|
| 1805 | - */ |
|
| 1806 | - public static function plugin_row_meta( $links, $file ) { |
|
| 1807 | - if ( WC_PLUGIN_BASENAME !== $file ) { |
|
| 1808 | - return $links; |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - /** |
|
| 1812 | - * The WooCommerce documentation URL. |
|
| 1813 | - * |
|
| 1814 | - * @since 2.7.0 |
|
| 1815 | - */ |
|
| 1816 | - $docs_url = apply_filters( 'woocommerce_docs_url', 'https://docs.woocommerce.com/documentation/plugins/woocommerce/' ); |
|
| 1817 | - |
|
| 1818 | - /** |
|
| 1819 | - * The WooCommerce API documentation URL. |
|
| 1820 | - * |
|
| 1821 | - * @since 2.2.0 |
|
| 1822 | - */ |
|
| 1823 | - $api_docs_url = apply_filters( 'woocommerce_apidocs_url', 'https://docs.woocommerce.com/wc-apidocs/' ); |
|
| 1824 | - |
|
| 1825 | - /** |
|
| 1826 | - * The community WooCommerce support URL. |
|
| 1827 | - * |
|
| 1828 | - * @since 2.2.0 |
|
| 1829 | - */ |
|
| 1830 | - $community_support_url = apply_filters( 'woocommerce_community_support_url', 'https://wordpress.org/support/plugin/woocommerce/' ); |
|
| 1831 | - |
|
| 1832 | - /** |
|
| 1833 | - * The premium support URL. |
|
| 1834 | - * |
|
| 1835 | - * @since |
|
| 1836 | - */ |
|
| 1837 | - $support_url = apply_filters( 'woocommerce_support_url', 'https://woocommerce.com/my-account/create-a-ticket/' ); |
|
| 1838 | - |
|
| 1839 | - $row_meta = array( |
|
| 1840 | - 'docs' => '<a href="' . esc_url( $docs_url ) . '" aria-label="' . esc_attr__( 'View WooCommerce documentation', 'woocommerce' ) . '">' . esc_html__( 'Docs', 'woocommerce' ) . '</a>', |
|
| 1841 | - 'apidocs' => '<a href="' . esc_url( $api_docs_url ) . '" aria-label="' . esc_attr__( 'View WooCommerce API docs', 'woocommerce' ) . '">' . esc_html__( 'API docs', 'woocommerce' ) . '</a>', |
|
| 1842 | - 'support' => '<a href="' . esc_url( $community_support_url ) . '" aria-label="' . esc_attr__( 'Visit community forums', 'woocommerce' ) . '">' . esc_html__( 'Community support', 'woocommerce' ) . '</a>', |
|
| 1843 | - ); |
|
| 1844 | - |
|
| 1845 | - if ( WCConnectionHelper::is_connected() ) { |
|
| 1846 | - $row_meta['premium_support'] = '<a href="' . esc_url( $support_url ) . '" aria-label="' . esc_attr__( 'Visit premium customer support', 'woocommerce' ) . '">' . esc_html__( 'Premium support', 'woocommerce' ) . '</a>'; |
|
| 1847 | - } |
|
| 1848 | - |
|
| 1849 | - return array_merge( $links, $row_meta ); |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - /** |
|
| 1853 | - * Get slug from path and associate it with the path. |
|
| 1854 | - * |
|
| 1855 | - * @param array $plugins Associative array of plugin files to paths. |
|
| 1856 | - * @param string $key Plugin relative path. Example: woocommerce/woocommerce.php. |
|
| 1857 | - */ |
|
| 1858 | - private static function associate_plugin_file( $plugins, $key ) { |
|
| 1859 | - $path = explode( '/', $key ); |
|
| 1860 | - $filename = end( $path ); |
|
| 1861 | - $plugins[ $filename ] = $key; |
|
| 1862 | - return $plugins; |
|
| 1863 | - } |
|
| 1864 | - |
|
| 1865 | - /** |
|
| 1866 | - * Install a plugin from .org in the background via a cron job (used by |
|
| 1867 | - * installer - opt in). |
|
| 1868 | - * |
|
| 1869 | - * @param string $plugin_to_install_id Plugin ID. |
|
| 1870 | - * @param array $plugin_to_install Plugin information. |
|
| 1871 | - * |
|
| 1872 | - * @throws Exception If unable to proceed with plugin installation. |
|
| 1873 | - * @since 2.6.0 |
|
| 1874 | - */ |
|
| 1875 | - public static function background_installer( $plugin_to_install_id, $plugin_to_install ) { |
|
| 1876 | - // Explicitly clear the event. |
|
| 1877 | - $args = func_get_args(); |
|
| 1878 | - |
|
| 1879 | - if ( ! empty( $plugin_to_install['repo-slug'] ) ) { |
|
| 1880 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
| 1881 | - require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
|
| 1882 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 1883 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 1884 | - |
|
| 1885 | - WP_Filesystem(); |
|
| 1886 | - |
|
| 1887 | - $skin = new Automatic_Upgrader_Skin(); |
|
| 1888 | - $upgrader = new WP_Upgrader( $skin ); |
|
| 1889 | - $installed_plugins = array_reduce( array_keys( get_plugins() ), array( __CLASS__, 'associate_plugin_file' ) ); |
|
| 1890 | - if ( empty( $installed_plugins ) ) { |
|
| 1891 | - $installed_plugins = array(); |
|
| 1892 | - } |
|
| 1893 | - $plugin_slug = $plugin_to_install['repo-slug']; |
|
| 1894 | - $plugin_file = isset( $plugin_to_install['file'] ) ? $plugin_to_install['file'] : $plugin_slug . '.php'; |
|
| 1895 | - $installed = false; |
|
| 1896 | - $activate = false; |
|
| 1897 | - |
|
| 1898 | - // See if the plugin is installed already. |
|
| 1899 | - if ( isset( $installed_plugins[ $plugin_file ] ) ) { |
|
| 1900 | - $installed = true; |
|
| 1901 | - $activate = ! is_plugin_active( $installed_plugins[ $plugin_file ] ); |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - // Install this thing! |
|
| 1905 | - if ( ! $installed ) { |
|
| 1906 | - // Suppress feedback. |
|
| 1907 | - ob_start(); |
|
| 1908 | - |
|
| 1909 | - try { |
|
| 1910 | - $plugin_information = plugins_api( |
|
| 1911 | - 'plugin_information', |
|
| 1912 | - array( |
|
| 1913 | - 'slug' => $plugin_slug, |
|
| 1914 | - 'fields' => array( |
|
| 1915 | - 'short_description' => false, |
|
| 1916 | - 'sections' => false, |
|
| 1917 | - 'requires' => false, |
|
| 1918 | - 'rating' => false, |
|
| 1919 | - 'ratings' => false, |
|
| 1920 | - 'downloaded' => false, |
|
| 1921 | - 'last_updated' => false, |
|
| 1922 | - 'added' => false, |
|
| 1923 | - 'tags' => false, |
|
| 1924 | - 'homepage' => false, |
|
| 1925 | - 'donate_link' => false, |
|
| 1926 | - 'author_profile' => false, |
|
| 1927 | - 'author' => false, |
|
| 1928 | - ), |
|
| 1929 | - ) |
|
| 1930 | - ); |
|
| 1931 | - |
|
| 1932 | - if ( is_wp_error( $plugin_information ) ) { |
|
| 1933 | - throw new Exception( $plugin_information->get_error_message() ); |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - $package = $plugin_information->download_link; |
|
| 1937 | - $download = $upgrader->download_package( $package ); |
|
| 1938 | - |
|
| 1939 | - if ( is_wp_error( $download ) ) { |
|
| 1940 | - throw new Exception( $download->get_error_message() ); |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
| 1944 | - |
|
| 1945 | - if ( is_wp_error( $working_dir ) ) { |
|
| 1946 | - throw new Exception( $working_dir->get_error_message() ); |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - $result = $upgrader->install_package( |
|
| 1950 | - array( |
|
| 1951 | - 'source' => $working_dir, |
|
| 1952 | - 'destination' => WP_PLUGIN_DIR, |
|
| 1953 | - 'clear_destination' => false, |
|
| 1954 | - 'abort_if_destination_exists' => false, |
|
| 1955 | - 'clear_working' => true, |
|
| 1956 | - 'hook_extra' => array( |
|
| 1957 | - 'type' => 'plugin', |
|
| 1958 | - 'action' => 'install', |
|
| 1959 | - ), |
|
| 1960 | - ) |
|
| 1961 | - ); |
|
| 1962 | - |
|
| 1963 | - if ( is_wp_error( $result ) ) { |
|
| 1964 | - throw new Exception( $result->get_error_message() ); |
|
| 1965 | - } |
|
| 1966 | - |
|
| 1967 | - $activate = true; |
|
| 1968 | - |
|
| 1969 | - } catch ( Exception $e ) { |
|
| 1970 | - WC_Admin_Notices::add_custom_notice( |
|
| 1971 | - $plugin_to_install_id . '_install_error', |
|
| 1972 | - sprintf( |
|
| 1973 | - // translators: 1: plugin name, 2: error message, 3: URL to install plugin manually. |
|
| 1974 | - __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ), |
|
| 1975 | - $plugin_to_install['name'], |
|
| 1976 | - $e->getMessage(), |
|
| 1977 | - esc_url( admin_url( 'index.php?wc-install-plugin-redirect=' . $plugin_slug ) ) |
|
| 1978 | - ) |
|
| 1979 | - ); |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - // Discard feedback. |
|
| 1983 | - ob_end_clean(); |
|
| 1984 | - } |
|
| 1985 | - |
|
| 1986 | - wp_clean_plugins_cache(); |
|
| 1987 | - |
|
| 1988 | - // Activate this thing. |
|
| 1989 | - if ( $activate ) { |
|
| 1990 | - try { |
|
| 1991 | - add_action( 'add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array( __CLASS__, 'remove_mailchimps_redirect' ), 10, 2 ); |
|
| 1992 | - $result = activate_plugin( $installed ? $installed_plugins[ $plugin_file ] : $plugin_slug . '/' . $plugin_file ); |
|
| 1993 | - |
|
| 1994 | - if ( is_wp_error( $result ) ) { |
|
| 1995 | - throw new Exception( $result->get_error_message() ); |
|
| 1996 | - } |
|
| 1997 | - } catch ( Exception $e ) { |
|
| 1998 | - WC_Admin_Notices::add_custom_notice( |
|
| 1999 | - $plugin_to_install_id . '_install_error', |
|
| 2000 | - sprintf( |
|
| 2001 | - // translators: 1: plugin name, 2: URL to WP plugin page. |
|
| 2002 | - __( '%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce' ), |
|
| 2003 | - $plugin_to_install['name'], |
|
| 2004 | - admin_url( 'plugins.php' ) |
|
| 2005 | - ) |
|
| 2006 | - ); |
|
| 2007 | - } |
|
| 2008 | - } |
|
| 2009 | - } |
|
| 2010 | - } |
|
| 2011 | - |
|
| 2012 | - /** |
|
| 2013 | - * Removes redirect added during MailChimp plugin's activation. |
|
| 2014 | - * |
|
| 2015 | - * @param string $option Option name. |
|
| 2016 | - * @param string $value Option value. |
|
| 2017 | - */ |
|
| 2018 | - public static function remove_mailchimps_redirect( $option, $value ) { |
|
| 2019 | - // Remove this action to prevent infinite looping. |
|
| 2020 | - remove_action( 'add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array( __CLASS__, 'remove_mailchimps_redirect' ) ); |
|
| 2021 | - |
|
| 2022 | - // Update redirect back to false. |
|
| 2023 | - update_option( 'mailchimp_woocommerce_plugin_do_activation_redirect', false ); |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - /** |
|
| 2027 | - * Install a theme from .org in the background via a cron job (used by installer - opt in). |
|
| 2028 | - * |
|
| 2029 | - * @param string $theme_slug Theme slug. |
|
| 2030 | - * |
|
| 2031 | - * @throws Exception If unable to proceed with theme installation. |
|
| 2032 | - * @since 3.1.0 |
|
| 2033 | - */ |
|
| 2034 | - public static function theme_background_installer( $theme_slug ) { |
|
| 2035 | - // Explicitly clear the event. |
|
| 2036 | - $args = func_get_args(); |
|
| 2037 | - |
|
| 2038 | - if ( ! empty( $theme_slug ) ) { |
|
| 2039 | - // Suppress feedback. |
|
| 2040 | - ob_start(); |
|
| 2041 | - |
|
| 2042 | - try { |
|
| 2043 | - $theme = wp_get_theme( $theme_slug ); |
|
| 2044 | - |
|
| 2045 | - if ( ! $theme->exists() ) { |
|
| 2046 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
| 2047 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 2048 | - include_once ABSPATH . 'wp-admin/includes/theme.php'; |
|
| 2049 | - |
|
| 2050 | - WP_Filesystem(); |
|
| 2051 | - |
|
| 2052 | - $skin = new Automatic_Upgrader_Skin(); |
|
| 2053 | - $upgrader = new Theme_Upgrader( $skin ); |
|
| 2054 | - $api = themes_api( |
|
| 2055 | - 'theme_information', |
|
| 2056 | - array( |
|
| 2057 | - 'slug' => $theme_slug, |
|
| 2058 | - 'fields' => array( 'sections' => false ), |
|
| 2059 | - ) |
|
| 2060 | - ); |
|
| 2061 | - $result = $upgrader->install( $api->download_link ); |
|
| 2062 | - |
|
| 2063 | - if ( is_wp_error( $result ) ) { |
|
| 2064 | - throw new Exception( $result->get_error_message() ); |
|
| 2065 | - } elseif ( is_wp_error( $skin->result ) ) { |
|
| 2066 | - throw new Exception( $skin->result->get_error_message() ); |
|
| 2067 | - } elseif ( is_null( $result ) ) { |
|
| 2068 | - throw new Exception( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
|
| 2069 | - } |
|
| 2070 | - } |
|
| 2071 | - |
|
| 2072 | - switch_theme( $theme_slug ); |
|
| 2073 | - } catch ( Exception $e ) { |
|
| 2074 | - WC_Admin_Notices::add_custom_notice( |
|
| 2075 | - $theme_slug . '_install_error', |
|
| 2076 | - sprintf( |
|
| 2077 | - // translators: 1: theme slug, 2: error message, 3: URL to install theme manually. |
|
| 2078 | - __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ), |
|
| 2079 | - $theme_slug, |
|
| 2080 | - $e->getMessage(), |
|
| 2081 | - esc_url( admin_url( 'update.php?action=install-theme&theme=' . $theme_slug . '&_wpnonce=' . wp_create_nonce( 'install-theme_' . $theme_slug ) ) ) |
|
| 2082 | - ) |
|
| 2083 | - ); |
|
| 2084 | - } |
|
| 2085 | - |
|
| 2086 | - // Discard feedback. |
|
| 2087 | - ob_end_clean(); |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * Sets whether PayPal Standard will be loaded on install. |
|
| 2093 | - * |
|
| 2094 | - * @since 5.5.0 |
|
| 2095 | - */ |
|
| 2096 | - private static function set_paypal_standard_load_eligibility() { |
|
| 2097 | - // Initiating the payment gateways sets the flag. |
|
| 2098 | - if ( class_exists( 'WC_Gateway_Paypal' ) ) { |
|
| 2099 | - ( new WC_Gateway_Paypal() )->should_load(); |
|
| 2100 | - } |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - /** |
|
| 2104 | - * Gets the content of the sample refunds and return policy page. |
|
| 2105 | - * |
|
| 2106 | - * @since 5.6.0 |
|
| 2107 | - * @return string The content for the page |
|
| 2108 | - */ |
|
| 2109 | - private static function get_refunds_return_policy_page_content() { |
|
| 2110 | - return <<<EOT |
|
| 1431 | + return $tables; |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * Return a list of WooCommerce tables. Used to make sure all WC tables are dropped when uninstalling the plugin |
|
| 1436 | + * in a single site or multi site environment. |
|
| 1437 | + * |
|
| 1438 | + * @return array WC tables. |
|
| 1439 | + */ |
|
| 1440 | + public static function get_tables() { |
|
| 1441 | + global $wpdb; |
|
| 1442 | + |
|
| 1443 | + $tables = array( |
|
| 1444 | + "{$wpdb->prefix}wc_download_log", |
|
| 1445 | + "{$wpdb->prefix}wc_product_download_directories", |
|
| 1446 | + "{$wpdb->prefix}wc_product_meta_lookup", |
|
| 1447 | + "{$wpdb->prefix}wc_tax_rate_classes", |
|
| 1448 | + "{$wpdb->prefix}wc_webhooks", |
|
| 1449 | + "{$wpdb->prefix}woocommerce_api_keys", |
|
| 1450 | + "{$wpdb->prefix}woocommerce_attribute_taxonomies", |
|
| 1451 | + "{$wpdb->prefix}woocommerce_downloadable_product_permissions", |
|
| 1452 | + "{$wpdb->prefix}woocommerce_log", |
|
| 1453 | + "{$wpdb->prefix}woocommerce_order_itemmeta", |
|
| 1454 | + "{$wpdb->prefix}woocommerce_order_items", |
|
| 1455 | + "{$wpdb->prefix}woocommerce_payment_tokenmeta", |
|
| 1456 | + "{$wpdb->prefix}woocommerce_payment_tokens", |
|
| 1457 | + "{$wpdb->prefix}woocommerce_sessions", |
|
| 1458 | + "{$wpdb->prefix}woocommerce_shipping_zone_locations", |
|
| 1459 | + "{$wpdb->prefix}woocommerce_shipping_zone_methods", |
|
| 1460 | + "{$wpdb->prefix}woocommerce_shipping_zones", |
|
| 1461 | + "{$wpdb->prefix}woocommerce_tax_rate_locations", |
|
| 1462 | + "{$wpdb->prefix}woocommerce_tax_rates", |
|
| 1463 | + "{$wpdb->prefix}wc_reserved_stock", |
|
| 1464 | + "{$wpdb->prefix}wc_rate_limits", |
|
| 1465 | + wc_get_container()->get( DataRegenerator::class )->get_lookup_table_name(), |
|
| 1466 | + |
|
| 1467 | + // WCA Tables. |
|
| 1468 | + "{$wpdb->prefix}wc_order_stats", |
|
| 1469 | + "{$wpdb->prefix}wc_order_product_lookup", |
|
| 1470 | + "{$wpdb->prefix}wc_order_tax_lookup", |
|
| 1471 | + "{$wpdb->prefix}wc_order_coupon_lookup", |
|
| 1472 | + "{$wpdb->prefix}wc_admin_notes", |
|
| 1473 | + "{$wpdb->prefix}wc_admin_note_actions", |
|
| 1474 | + "{$wpdb->prefix}wc_customer_lookup", |
|
| 1475 | + "{$wpdb->prefix}wc_category_lookup", |
|
| 1476 | + ); |
|
| 1477 | + |
|
| 1478 | + /** |
|
| 1479 | + * Filter the list of known WooCommerce tables. |
|
| 1480 | + * |
|
| 1481 | + * If WooCommerce plugins need to add new tables, they can inject them here. |
|
| 1482 | + * |
|
| 1483 | + * @param array $tables An array of WooCommerce-specific database table names. |
|
| 1484 | + * @since 3.4.0 |
|
| 1485 | + */ |
|
| 1486 | + $tables = apply_filters( 'woocommerce_install_get_tables', $tables ); |
|
| 1487 | + |
|
| 1488 | + return $tables; |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + /** |
|
| 1492 | + * Drop WooCommerce tables. |
|
| 1493 | + * |
|
| 1494 | + * @return void |
|
| 1495 | + */ |
|
| 1496 | + public static function drop_tables() { |
|
| 1497 | + global $wpdb; |
|
| 1498 | + |
|
| 1499 | + $tables = self::get_tables(); |
|
| 1500 | + |
|
| 1501 | + foreach ( $tables as $table ) { |
|
| 1502 | + $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 1503 | + } |
|
| 1504 | + } |
|
| 1505 | + |
|
| 1506 | + /** |
|
| 1507 | + * Uninstall tables when MU blog is deleted. |
|
| 1508 | + * |
|
| 1509 | + * @param array $tables List of tables that will be deleted by WP. |
|
| 1510 | + * |
|
| 1511 | + * @return string[] |
|
| 1512 | + */ |
|
| 1513 | + public static function wpmu_drop_tables( $tables ) { |
|
| 1514 | + return array_merge( $tables, self::get_tables() ); |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Create roles and capabilities. |
|
| 1519 | + */ |
|
| 1520 | + public static function create_roles() { |
|
| 1521 | + global $wp_roles; |
|
| 1522 | + |
|
| 1523 | + if ( ! class_exists( 'WP_Roles' ) ) { |
|
| 1524 | + return; |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + if ( ! isset( $wp_roles ) ) { |
|
| 1528 | + $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + // Dummy gettext calls to get strings in the catalog. |
|
| 1532 | + /* translators: user role */ |
|
| 1533 | + _x( 'Customer', 'User role', 'woocommerce' ); |
|
| 1534 | + /* translators: user role */ |
|
| 1535 | + _x( 'Shop manager', 'User role', 'woocommerce' ); |
|
| 1536 | + |
|
| 1537 | + // Customer role. |
|
| 1538 | + add_role( |
|
| 1539 | + 'customer', |
|
| 1540 | + 'Customer', |
|
| 1541 | + array( |
|
| 1542 | + 'read' => true, |
|
| 1543 | + ) |
|
| 1544 | + ); |
|
| 1545 | + |
|
| 1546 | + // Shop manager role. |
|
| 1547 | + add_role( |
|
| 1548 | + 'shop_manager', |
|
| 1549 | + 'Shop manager', |
|
| 1550 | + array( |
|
| 1551 | + 'level_9' => true, |
|
| 1552 | + 'level_8' => true, |
|
| 1553 | + 'level_7' => true, |
|
| 1554 | + 'level_6' => true, |
|
| 1555 | + 'level_5' => true, |
|
| 1556 | + 'level_4' => true, |
|
| 1557 | + 'level_3' => true, |
|
| 1558 | + 'level_2' => true, |
|
| 1559 | + 'level_1' => true, |
|
| 1560 | + 'level_0' => true, |
|
| 1561 | + 'read' => true, |
|
| 1562 | + 'read_private_pages' => true, |
|
| 1563 | + 'read_private_posts' => true, |
|
| 1564 | + 'edit_posts' => true, |
|
| 1565 | + 'edit_pages' => true, |
|
| 1566 | + 'edit_published_posts' => true, |
|
| 1567 | + 'edit_published_pages' => true, |
|
| 1568 | + 'edit_private_pages' => true, |
|
| 1569 | + 'edit_private_posts' => true, |
|
| 1570 | + 'edit_others_posts' => true, |
|
| 1571 | + 'edit_others_pages' => true, |
|
| 1572 | + 'publish_posts' => true, |
|
| 1573 | + 'publish_pages' => true, |
|
| 1574 | + 'delete_posts' => true, |
|
| 1575 | + 'delete_pages' => true, |
|
| 1576 | + 'delete_private_pages' => true, |
|
| 1577 | + 'delete_private_posts' => true, |
|
| 1578 | + 'delete_published_pages' => true, |
|
| 1579 | + 'delete_published_posts' => true, |
|
| 1580 | + 'delete_others_posts' => true, |
|
| 1581 | + 'delete_others_pages' => true, |
|
| 1582 | + 'manage_categories' => true, |
|
| 1583 | + 'manage_links' => true, |
|
| 1584 | + 'moderate_comments' => true, |
|
| 1585 | + 'upload_files' => true, |
|
| 1586 | + 'export' => true, |
|
| 1587 | + 'import' => true, |
|
| 1588 | + 'list_users' => true, |
|
| 1589 | + 'edit_theme_options' => true, |
|
| 1590 | + ) |
|
| 1591 | + ); |
|
| 1592 | + |
|
| 1593 | + $capabilities = self::get_core_capabilities(); |
|
| 1594 | + |
|
| 1595 | + foreach ( $capabilities as $cap_group ) { |
|
| 1596 | + foreach ( $cap_group as $cap ) { |
|
| 1597 | + $wp_roles->add_cap( 'shop_manager', $cap ); |
|
| 1598 | + $wp_roles->add_cap( 'administrator', $cap ); |
|
| 1599 | + } |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * Get capabilities for WooCommerce - these are assigned to admin/shop manager during installation or reset. |
|
| 1605 | + * |
|
| 1606 | + * @return array |
|
| 1607 | + */ |
|
| 1608 | + public static function get_core_capabilities() { |
|
| 1609 | + $capabilities = array(); |
|
| 1610 | + |
|
| 1611 | + $capabilities['core'] = array( |
|
| 1612 | + 'manage_woocommerce', |
|
| 1613 | + 'view_woocommerce_reports', |
|
| 1614 | + ); |
|
| 1615 | + |
|
| 1616 | + $capability_types = array( 'product', 'shop_order', 'shop_coupon' ); |
|
| 1617 | + |
|
| 1618 | + foreach ( $capability_types as $capability_type ) { |
|
| 1619 | + |
|
| 1620 | + $capabilities[ $capability_type ] = array( |
|
| 1621 | + // Post type. |
|
| 1622 | + "edit_{$capability_type}", |
|
| 1623 | + "read_{$capability_type}", |
|
| 1624 | + "delete_{$capability_type}", |
|
| 1625 | + "edit_{$capability_type}s", |
|
| 1626 | + "edit_others_{$capability_type}s", |
|
| 1627 | + "publish_{$capability_type}s", |
|
| 1628 | + "read_private_{$capability_type}s", |
|
| 1629 | + "delete_{$capability_type}s", |
|
| 1630 | + "delete_private_{$capability_type}s", |
|
| 1631 | + "delete_published_{$capability_type}s", |
|
| 1632 | + "delete_others_{$capability_type}s", |
|
| 1633 | + "edit_private_{$capability_type}s", |
|
| 1634 | + "edit_published_{$capability_type}s", |
|
| 1635 | + |
|
| 1636 | + // Terms. |
|
| 1637 | + "manage_{$capability_type}_terms", |
|
| 1638 | + "edit_{$capability_type}_terms", |
|
| 1639 | + "delete_{$capability_type}_terms", |
|
| 1640 | + "assign_{$capability_type}_terms", |
|
| 1641 | + ); |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + return $capabilities; |
|
| 1645 | + } |
|
| 1646 | + |
|
| 1647 | + /** |
|
| 1648 | + * Remove WooCommerce roles. |
|
| 1649 | + */ |
|
| 1650 | + public static function remove_roles() { |
|
| 1651 | + global $wp_roles; |
|
| 1652 | + |
|
| 1653 | + if ( ! class_exists( 'WP_Roles' ) ) { |
|
| 1654 | + return; |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + if ( ! isset( $wp_roles ) ) { |
|
| 1658 | + $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
|
| 1659 | + } |
|
| 1660 | + |
|
| 1661 | + $capabilities = self::get_core_capabilities(); |
|
| 1662 | + |
|
| 1663 | + foreach ( $capabilities as $cap_group ) { |
|
| 1664 | + foreach ( $cap_group as $cap ) { |
|
| 1665 | + $wp_roles->remove_cap( 'shop_manager', $cap ); |
|
| 1666 | + $wp_roles->remove_cap( 'administrator', $cap ); |
|
| 1667 | + } |
|
| 1668 | + } |
|
| 1669 | + |
|
| 1670 | + remove_role( 'customer' ); |
|
| 1671 | + remove_role( 'shop_manager' ); |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + /** |
|
| 1675 | + * Create files/directories. |
|
| 1676 | + */ |
|
| 1677 | + private static function create_files() { |
|
| 1678 | + /** |
|
| 1679 | + * Bypass if filesystem is read-only and/or non-standard upload system is used. |
|
| 1680 | + * |
|
| 1681 | + * @since 3.2.0 |
|
| 1682 | + */ |
|
| 1683 | + if ( apply_filters( 'woocommerce_install_skip_create_files', false ) ) { |
|
| 1684 | + return; |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + // Install files and folders for uploading files and prevent hotlinking. |
|
| 1688 | + $upload_dir = wp_get_upload_dir(); |
|
| 1689 | + $download_method = get_option( 'woocommerce_file_download_method', 'force' ); |
|
| 1690 | + |
|
| 1691 | + $files = array( |
|
| 1692 | + array( |
|
| 1693 | + 'base' => $upload_dir['basedir'] . '/woocommerce_uploads', |
|
| 1694 | + 'file' => 'index.html', |
|
| 1695 | + 'content' => '', |
|
| 1696 | + ), |
|
| 1697 | + array( |
|
| 1698 | + 'base' => WC_LOG_DIR, |
|
| 1699 | + 'file' => '.htaccess', |
|
| 1700 | + 'content' => 'deny from all', |
|
| 1701 | + ), |
|
| 1702 | + array( |
|
| 1703 | + 'base' => WC_LOG_DIR, |
|
| 1704 | + 'file' => 'index.html', |
|
| 1705 | + 'content' => '', |
|
| 1706 | + ), |
|
| 1707 | + array( |
|
| 1708 | + 'base' => $upload_dir['basedir'] . '/woocommerce_uploads', |
|
| 1709 | + 'file' => '.htaccess', |
|
| 1710 | + 'content' => 'redirect' === $download_method ? 'Options -Indexes' : 'deny from all', |
|
| 1711 | + ), |
|
| 1712 | + ); |
|
| 1713 | + |
|
| 1714 | + foreach ( $files as $file ) { |
|
| 1715 | + if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) { |
|
| 1716 | + $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'wb' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen |
|
| 1717 | + if ( $file_handle ) { |
|
| 1718 | + fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite |
|
| 1719 | + fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose |
|
| 1720 | + } |
|
| 1721 | + } |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + // Create attachment for placeholders. |
|
| 1725 | + self::create_placeholder_image(); |
|
| 1726 | + } |
|
| 1727 | + |
|
| 1728 | + /** |
|
| 1729 | + * Create a placeholder image in the media library. |
|
| 1730 | + * |
|
| 1731 | + * @since 3.5.0 |
|
| 1732 | + */ |
|
| 1733 | + private static function create_placeholder_image() { |
|
| 1734 | + $placeholder_image = get_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1735 | + |
|
| 1736 | + // Validate current setting if set. If set, return. |
|
| 1737 | + if ( ! empty( $placeholder_image ) ) { |
|
| 1738 | + if ( ! is_numeric( $placeholder_image ) ) { |
|
| 1739 | + return; |
|
| 1740 | + } elseif ( $placeholder_image && wp_attachment_is_image( $placeholder_image ) ) { |
|
| 1741 | + return; |
|
| 1742 | + } |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + $upload_dir = wp_upload_dir(); |
|
| 1746 | + $source = WC()->plugin_path() . '/assets/images/placeholder-attachment.png'; |
|
| 1747 | + $filename = $upload_dir['basedir'] . '/woocommerce-placeholder.png'; |
|
| 1748 | + |
|
| 1749 | + if ( ! file_exists( $filename ) ) { |
|
| 1750 | + copy( $source, $filename ); // @codingStandardsIgnoreLine. |
|
| 1751 | + } |
|
| 1752 | + |
|
| 1753 | + if ( ! file_exists( $filename ) ) { |
|
| 1754 | + update_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1755 | + return; |
|
| 1756 | + } |
|
| 1757 | + |
|
| 1758 | + $filetype = wp_check_filetype( basename( $filename ), null ); |
|
| 1759 | + $attachment = array( |
|
| 1760 | + 'guid' => $upload_dir['url'] . '/' . basename( $filename ), |
|
| 1761 | + 'post_mime_type' => $filetype['type'], |
|
| 1762 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 1763 | + 'post_content' => '', |
|
| 1764 | + 'post_status' => 'inherit', |
|
| 1765 | + ); |
|
| 1766 | + |
|
| 1767 | + $attach_id = wp_insert_attachment( $attachment, $filename ); |
|
| 1768 | + if ( is_wp_error( $attach_id ) ) { |
|
| 1769 | + update_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1770 | + return; |
|
| 1771 | + } |
|
| 1772 | + |
|
| 1773 | + update_option( 'woocommerce_placeholder_image', $attach_id ); |
|
| 1774 | + |
|
| 1775 | + // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. |
|
| 1776 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1777 | + |
|
| 1778 | + // Generate the metadata for the attachment, and update the database record. |
|
| 1779 | + $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); |
|
| 1780 | + wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 1781 | + } |
|
| 1782 | + |
|
| 1783 | + /** |
|
| 1784 | + * Show action links on the plugin screen. |
|
| 1785 | + * |
|
| 1786 | + * @param mixed $links Plugin Action links. |
|
| 1787 | + * |
|
| 1788 | + * @return array |
|
| 1789 | + */ |
|
| 1790 | + public static function plugin_action_links( $links ) { |
|
| 1791 | + $action_links = array( |
|
| 1792 | + 'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings' ) . '" aria-label="' . esc_attr__( 'View WooCommerce settings', 'woocommerce' ) . '">' . esc_html__( 'Settings', 'woocommerce' ) . '</a>', |
|
| 1793 | + ); |
|
| 1794 | + |
|
| 1795 | + return array_merge( $action_links, $links ); |
|
| 1796 | + } |
|
| 1797 | + |
|
| 1798 | + /** |
|
| 1799 | + * Show row meta on the plugin screen. |
|
| 1800 | + * |
|
| 1801 | + * @param mixed $links Plugin Row Meta. |
|
| 1802 | + * @param mixed $file Plugin Base file. |
|
| 1803 | + * |
|
| 1804 | + * @return array |
|
| 1805 | + */ |
|
| 1806 | + public static function plugin_row_meta( $links, $file ) { |
|
| 1807 | + if ( WC_PLUGIN_BASENAME !== $file ) { |
|
| 1808 | + return $links; |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + /** |
|
| 1812 | + * The WooCommerce documentation URL. |
|
| 1813 | + * |
|
| 1814 | + * @since 2.7.0 |
|
| 1815 | + */ |
|
| 1816 | + $docs_url = apply_filters( 'woocommerce_docs_url', 'https://docs.woocommerce.com/documentation/plugins/woocommerce/' ); |
|
| 1817 | + |
|
| 1818 | + /** |
|
| 1819 | + * The WooCommerce API documentation URL. |
|
| 1820 | + * |
|
| 1821 | + * @since 2.2.0 |
|
| 1822 | + */ |
|
| 1823 | + $api_docs_url = apply_filters( 'woocommerce_apidocs_url', 'https://docs.woocommerce.com/wc-apidocs/' ); |
|
| 1824 | + |
|
| 1825 | + /** |
|
| 1826 | + * The community WooCommerce support URL. |
|
| 1827 | + * |
|
| 1828 | + * @since 2.2.0 |
|
| 1829 | + */ |
|
| 1830 | + $community_support_url = apply_filters( 'woocommerce_community_support_url', 'https://wordpress.org/support/plugin/woocommerce/' ); |
|
| 1831 | + |
|
| 1832 | + /** |
|
| 1833 | + * The premium support URL. |
|
| 1834 | + * |
|
| 1835 | + * @since |
|
| 1836 | + */ |
|
| 1837 | + $support_url = apply_filters( 'woocommerce_support_url', 'https://woocommerce.com/my-account/create-a-ticket/' ); |
|
| 1838 | + |
|
| 1839 | + $row_meta = array( |
|
| 1840 | + 'docs' => '<a href="' . esc_url( $docs_url ) . '" aria-label="' . esc_attr__( 'View WooCommerce documentation', 'woocommerce' ) . '">' . esc_html__( 'Docs', 'woocommerce' ) . '</a>', |
|
| 1841 | + 'apidocs' => '<a href="' . esc_url( $api_docs_url ) . '" aria-label="' . esc_attr__( 'View WooCommerce API docs', 'woocommerce' ) . '">' . esc_html__( 'API docs', 'woocommerce' ) . '</a>', |
|
| 1842 | + 'support' => '<a href="' . esc_url( $community_support_url ) . '" aria-label="' . esc_attr__( 'Visit community forums', 'woocommerce' ) . '">' . esc_html__( 'Community support', 'woocommerce' ) . '</a>', |
|
| 1843 | + ); |
|
| 1844 | + |
|
| 1845 | + if ( WCConnectionHelper::is_connected() ) { |
|
| 1846 | + $row_meta['premium_support'] = '<a href="' . esc_url( $support_url ) . '" aria-label="' . esc_attr__( 'Visit premium customer support', 'woocommerce' ) . '">' . esc_html__( 'Premium support', 'woocommerce' ) . '</a>'; |
|
| 1847 | + } |
|
| 1848 | + |
|
| 1849 | + return array_merge( $links, $row_meta ); |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + /** |
|
| 1853 | + * Get slug from path and associate it with the path. |
|
| 1854 | + * |
|
| 1855 | + * @param array $plugins Associative array of plugin files to paths. |
|
| 1856 | + * @param string $key Plugin relative path. Example: woocommerce/woocommerce.php. |
|
| 1857 | + */ |
|
| 1858 | + private static function associate_plugin_file( $plugins, $key ) { |
|
| 1859 | + $path = explode( '/', $key ); |
|
| 1860 | + $filename = end( $path ); |
|
| 1861 | + $plugins[ $filename ] = $key; |
|
| 1862 | + return $plugins; |
|
| 1863 | + } |
|
| 1864 | + |
|
| 1865 | + /** |
|
| 1866 | + * Install a plugin from .org in the background via a cron job (used by |
|
| 1867 | + * installer - opt in). |
|
| 1868 | + * |
|
| 1869 | + * @param string $plugin_to_install_id Plugin ID. |
|
| 1870 | + * @param array $plugin_to_install Plugin information. |
|
| 1871 | + * |
|
| 1872 | + * @throws Exception If unable to proceed with plugin installation. |
|
| 1873 | + * @since 2.6.0 |
|
| 1874 | + */ |
|
| 1875 | + public static function background_installer( $plugin_to_install_id, $plugin_to_install ) { |
|
| 1876 | + // Explicitly clear the event. |
|
| 1877 | + $args = func_get_args(); |
|
| 1878 | + |
|
| 1879 | + if ( ! empty( $plugin_to_install['repo-slug'] ) ) { |
|
| 1880 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
| 1881 | + require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
|
| 1882 | + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 1883 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 1884 | + |
|
| 1885 | + WP_Filesystem(); |
|
| 1886 | + |
|
| 1887 | + $skin = new Automatic_Upgrader_Skin(); |
|
| 1888 | + $upgrader = new WP_Upgrader( $skin ); |
|
| 1889 | + $installed_plugins = array_reduce( array_keys( get_plugins() ), array( __CLASS__, 'associate_plugin_file' ) ); |
|
| 1890 | + if ( empty( $installed_plugins ) ) { |
|
| 1891 | + $installed_plugins = array(); |
|
| 1892 | + } |
|
| 1893 | + $plugin_slug = $plugin_to_install['repo-slug']; |
|
| 1894 | + $plugin_file = isset( $plugin_to_install['file'] ) ? $plugin_to_install['file'] : $plugin_slug . '.php'; |
|
| 1895 | + $installed = false; |
|
| 1896 | + $activate = false; |
|
| 1897 | + |
|
| 1898 | + // See if the plugin is installed already. |
|
| 1899 | + if ( isset( $installed_plugins[ $plugin_file ] ) ) { |
|
| 1900 | + $installed = true; |
|
| 1901 | + $activate = ! is_plugin_active( $installed_plugins[ $plugin_file ] ); |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + // Install this thing! |
|
| 1905 | + if ( ! $installed ) { |
|
| 1906 | + // Suppress feedback. |
|
| 1907 | + ob_start(); |
|
| 1908 | + |
|
| 1909 | + try { |
|
| 1910 | + $plugin_information = plugins_api( |
|
| 1911 | + 'plugin_information', |
|
| 1912 | + array( |
|
| 1913 | + 'slug' => $plugin_slug, |
|
| 1914 | + 'fields' => array( |
|
| 1915 | + 'short_description' => false, |
|
| 1916 | + 'sections' => false, |
|
| 1917 | + 'requires' => false, |
|
| 1918 | + 'rating' => false, |
|
| 1919 | + 'ratings' => false, |
|
| 1920 | + 'downloaded' => false, |
|
| 1921 | + 'last_updated' => false, |
|
| 1922 | + 'added' => false, |
|
| 1923 | + 'tags' => false, |
|
| 1924 | + 'homepage' => false, |
|
| 1925 | + 'donate_link' => false, |
|
| 1926 | + 'author_profile' => false, |
|
| 1927 | + 'author' => false, |
|
| 1928 | + ), |
|
| 1929 | + ) |
|
| 1930 | + ); |
|
| 1931 | + |
|
| 1932 | + if ( is_wp_error( $plugin_information ) ) { |
|
| 1933 | + throw new Exception( $plugin_information->get_error_message() ); |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + $package = $plugin_information->download_link; |
|
| 1937 | + $download = $upgrader->download_package( $package ); |
|
| 1938 | + |
|
| 1939 | + if ( is_wp_error( $download ) ) { |
|
| 1940 | + throw new Exception( $download->get_error_message() ); |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + $working_dir = $upgrader->unpack_package( $download, true ); |
|
| 1944 | + |
|
| 1945 | + if ( is_wp_error( $working_dir ) ) { |
|
| 1946 | + throw new Exception( $working_dir->get_error_message() ); |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + $result = $upgrader->install_package( |
|
| 1950 | + array( |
|
| 1951 | + 'source' => $working_dir, |
|
| 1952 | + 'destination' => WP_PLUGIN_DIR, |
|
| 1953 | + 'clear_destination' => false, |
|
| 1954 | + 'abort_if_destination_exists' => false, |
|
| 1955 | + 'clear_working' => true, |
|
| 1956 | + 'hook_extra' => array( |
|
| 1957 | + 'type' => 'plugin', |
|
| 1958 | + 'action' => 'install', |
|
| 1959 | + ), |
|
| 1960 | + ) |
|
| 1961 | + ); |
|
| 1962 | + |
|
| 1963 | + if ( is_wp_error( $result ) ) { |
|
| 1964 | + throw new Exception( $result->get_error_message() ); |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + $activate = true; |
|
| 1968 | + |
|
| 1969 | + } catch ( Exception $e ) { |
|
| 1970 | + WC_Admin_Notices::add_custom_notice( |
|
| 1971 | + $plugin_to_install_id . '_install_error', |
|
| 1972 | + sprintf( |
|
| 1973 | + // translators: 1: plugin name, 2: error message, 3: URL to install plugin manually. |
|
| 1974 | + __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ), |
|
| 1975 | + $plugin_to_install['name'], |
|
| 1976 | + $e->getMessage(), |
|
| 1977 | + esc_url( admin_url( 'index.php?wc-install-plugin-redirect=' . $plugin_slug ) ) |
|
| 1978 | + ) |
|
| 1979 | + ); |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + // Discard feedback. |
|
| 1983 | + ob_end_clean(); |
|
| 1984 | + } |
|
| 1985 | + |
|
| 1986 | + wp_clean_plugins_cache(); |
|
| 1987 | + |
|
| 1988 | + // Activate this thing. |
|
| 1989 | + if ( $activate ) { |
|
| 1990 | + try { |
|
| 1991 | + add_action( 'add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array( __CLASS__, 'remove_mailchimps_redirect' ), 10, 2 ); |
|
| 1992 | + $result = activate_plugin( $installed ? $installed_plugins[ $plugin_file ] : $plugin_slug . '/' . $plugin_file ); |
|
| 1993 | + |
|
| 1994 | + if ( is_wp_error( $result ) ) { |
|
| 1995 | + throw new Exception( $result->get_error_message() ); |
|
| 1996 | + } |
|
| 1997 | + } catch ( Exception $e ) { |
|
| 1998 | + WC_Admin_Notices::add_custom_notice( |
|
| 1999 | + $plugin_to_install_id . '_install_error', |
|
| 2000 | + sprintf( |
|
| 2001 | + // translators: 1: plugin name, 2: URL to WP plugin page. |
|
| 2002 | + __( '%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce' ), |
|
| 2003 | + $plugin_to_install['name'], |
|
| 2004 | + admin_url( 'plugins.php' ) |
|
| 2005 | + ) |
|
| 2006 | + ); |
|
| 2007 | + } |
|
| 2008 | + } |
|
| 2009 | + } |
|
| 2010 | + } |
|
| 2011 | + |
|
| 2012 | + /** |
|
| 2013 | + * Removes redirect added during MailChimp plugin's activation. |
|
| 2014 | + * |
|
| 2015 | + * @param string $option Option name. |
|
| 2016 | + * @param string $value Option value. |
|
| 2017 | + */ |
|
| 2018 | + public static function remove_mailchimps_redirect( $option, $value ) { |
|
| 2019 | + // Remove this action to prevent infinite looping. |
|
| 2020 | + remove_action( 'add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array( __CLASS__, 'remove_mailchimps_redirect' ) ); |
|
| 2021 | + |
|
| 2022 | + // Update redirect back to false. |
|
| 2023 | + update_option( 'mailchimp_woocommerce_plugin_do_activation_redirect', false ); |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + /** |
|
| 2027 | + * Install a theme from .org in the background via a cron job (used by installer - opt in). |
|
| 2028 | + * |
|
| 2029 | + * @param string $theme_slug Theme slug. |
|
| 2030 | + * |
|
| 2031 | + * @throws Exception If unable to proceed with theme installation. |
|
| 2032 | + * @since 3.1.0 |
|
| 2033 | + */ |
|
| 2034 | + public static function theme_background_installer( $theme_slug ) { |
|
| 2035 | + // Explicitly clear the event. |
|
| 2036 | + $args = func_get_args(); |
|
| 2037 | + |
|
| 2038 | + if ( ! empty( $theme_slug ) ) { |
|
| 2039 | + // Suppress feedback. |
|
| 2040 | + ob_start(); |
|
| 2041 | + |
|
| 2042 | + try { |
|
| 2043 | + $theme = wp_get_theme( $theme_slug ); |
|
| 2044 | + |
|
| 2045 | + if ( ! $theme->exists() ) { |
|
| 2046 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
| 2047 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 2048 | + include_once ABSPATH . 'wp-admin/includes/theme.php'; |
|
| 2049 | + |
|
| 2050 | + WP_Filesystem(); |
|
| 2051 | + |
|
| 2052 | + $skin = new Automatic_Upgrader_Skin(); |
|
| 2053 | + $upgrader = new Theme_Upgrader( $skin ); |
|
| 2054 | + $api = themes_api( |
|
| 2055 | + 'theme_information', |
|
| 2056 | + array( |
|
| 2057 | + 'slug' => $theme_slug, |
|
| 2058 | + 'fields' => array( 'sections' => false ), |
|
| 2059 | + ) |
|
| 2060 | + ); |
|
| 2061 | + $result = $upgrader->install( $api->download_link ); |
|
| 2062 | + |
|
| 2063 | + if ( is_wp_error( $result ) ) { |
|
| 2064 | + throw new Exception( $result->get_error_message() ); |
|
| 2065 | + } elseif ( is_wp_error( $skin->result ) ) { |
|
| 2066 | + throw new Exception( $skin->result->get_error_message() ); |
|
| 2067 | + } elseif ( is_null( $result ) ) { |
|
| 2068 | + throw new Exception( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
|
| 2069 | + } |
|
| 2070 | + } |
|
| 2071 | + |
|
| 2072 | + switch_theme( $theme_slug ); |
|
| 2073 | + } catch ( Exception $e ) { |
|
| 2074 | + WC_Admin_Notices::add_custom_notice( |
|
| 2075 | + $theme_slug . '_install_error', |
|
| 2076 | + sprintf( |
|
| 2077 | + // translators: 1: theme slug, 2: error message, 3: URL to install theme manually. |
|
| 2078 | + __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ), |
|
| 2079 | + $theme_slug, |
|
| 2080 | + $e->getMessage(), |
|
| 2081 | + esc_url( admin_url( 'update.php?action=install-theme&theme=' . $theme_slug . '&_wpnonce=' . wp_create_nonce( 'install-theme_' . $theme_slug ) ) ) |
|
| 2082 | + ) |
|
| 2083 | + ); |
|
| 2084 | + } |
|
| 2085 | + |
|
| 2086 | + // Discard feedback. |
|
| 2087 | + ob_end_clean(); |
|
| 2088 | + } |
|
| 2089 | + } |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * Sets whether PayPal Standard will be loaded on install. |
|
| 2093 | + * |
|
| 2094 | + * @since 5.5.0 |
|
| 2095 | + */ |
|
| 2096 | + private static function set_paypal_standard_load_eligibility() { |
|
| 2097 | + // Initiating the payment gateways sets the flag. |
|
| 2098 | + if ( class_exists( 'WC_Gateway_Paypal' ) ) { |
|
| 2099 | + ( new WC_Gateway_Paypal() )->should_load(); |
|
| 2100 | + } |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + /** |
|
| 2104 | + * Gets the content of the sample refunds and return policy page. |
|
| 2105 | + * |
|
| 2106 | + * @since 5.6.0 |
|
| 2107 | + * @return string The content for the page |
|
| 2108 | + */ |
|
| 2109 | + private static function get_refunds_return_policy_page_content() { |
|
| 2110 | + return <<<EOT |
|
| 2111 | 2111 | <!-- wp:paragraph --> |
| 2112 | 2112 | <p><b>This is a sample page.</b></p> |
| 2113 | 2113 | <!-- /wp:paragraph --> |
@@ -2249,46 +2249,46 @@ discard block |
||
| 2249 | 2249 | <p>Contact us at {email} for questions related to refunds and returns.</p> |
| 2250 | 2250 | <!-- /wp:paragraph --> |
| 2251 | 2251 | EOT; |
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * Adds an admin inbox note after a page has been created to notify |
|
| 2256 | - * user. For example to take action to edit the page such as the |
|
| 2257 | - * Refund and returns page. |
|
| 2258 | - * |
|
| 2259 | - * @since 5.6.0 |
|
| 2260 | - * @return void |
|
| 2261 | - */ |
|
| 2262 | - public static function add_admin_note_after_page_created() { |
|
| 2263 | - if ( ! WC()->is_wc_admin_active() ) { |
|
| 2264 | - return; |
|
| 2265 | - } |
|
| 2266 | - |
|
| 2267 | - $page_id = get_option( 'woocommerce_refund_returns_page_created', null ); |
|
| 2268 | - |
|
| 2269 | - if ( null === $page_id ) { |
|
| 2270 | - return; |
|
| 2271 | - } |
|
| 2272 | - |
|
| 2273 | - WC_Notes_Refund_Returns::possibly_add_note( $page_id ); |
|
| 2274 | - } |
|
| 2275 | - |
|
| 2276 | - /** |
|
| 2277 | - * When pages are created, we might want to take some action. |
|
| 2278 | - * In this case we want to set an option when refund and returns |
|
| 2279 | - * page is created. |
|
| 2280 | - * |
|
| 2281 | - * @since 5.6.0 |
|
| 2282 | - * @param int $page_id ID of the page. |
|
| 2283 | - * @param array $page_data The data of the page created. |
|
| 2284 | - * @return void |
|
| 2285 | - */ |
|
| 2286 | - public static function page_created( $page_id, $page_data ) { |
|
| 2287 | - if ( 'refund_returns' === $page_data['post_name'] ) { |
|
| 2288 | - delete_option( 'woocommerce_refund_returns_page_created' ); |
|
| 2289 | - add_option( 'woocommerce_refund_returns_page_created', $page_id, '', false ); |
|
| 2290 | - } |
|
| 2291 | - } |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * Adds an admin inbox note after a page has been created to notify |
|
| 2256 | + * user. For example to take action to edit the page such as the |
|
| 2257 | + * Refund and returns page. |
|
| 2258 | + * |
|
| 2259 | + * @since 5.6.0 |
|
| 2260 | + * @return void |
|
| 2261 | + */ |
|
| 2262 | + public static function add_admin_note_after_page_created() { |
|
| 2263 | + if ( ! WC()->is_wc_admin_active() ) { |
|
| 2264 | + return; |
|
| 2265 | + } |
|
| 2266 | + |
|
| 2267 | + $page_id = get_option( 'woocommerce_refund_returns_page_created', null ); |
|
| 2268 | + |
|
| 2269 | + if ( null === $page_id ) { |
|
| 2270 | + return; |
|
| 2271 | + } |
|
| 2272 | + |
|
| 2273 | + WC_Notes_Refund_Returns::possibly_add_note( $page_id ); |
|
| 2274 | + } |
|
| 2275 | + |
|
| 2276 | + /** |
|
| 2277 | + * When pages are created, we might want to take some action. |
|
| 2278 | + * In this case we want to set an option when refund and returns |
|
| 2279 | + * page is created. |
|
| 2280 | + * |
|
| 2281 | + * @since 5.6.0 |
|
| 2282 | + * @param int $page_id ID of the page. |
|
| 2283 | + * @param array $page_data The data of the page created. |
|
| 2284 | + * @return void |
|
| 2285 | + */ |
|
| 2286 | + public static function page_created( $page_id, $page_data ) { |
|
| 2287 | + if ( 'refund_returns' === $page_data['post_name'] ) { |
|
| 2288 | + delete_option( 'woocommerce_refund_returns_page_created' ); |
|
| 2289 | + add_option( 'woocommerce_refund_returns_page_created', $page_id, '', false ); |
|
| 2290 | + } |
|
| 2291 | + } |
|
| 2292 | 2292 | } |
| 2293 | 2293 | |
| 2294 | 2294 | WC_Install::init(); |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | use Automattic\WooCommerce\Internal\Utilities\DatabaseUtil; |
| 15 | 15 | use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper as WCConnectionHelper; |
| 16 | 16 | |
| 17 | -defined( 'ABSPATH' ) || exit; |
|
| 17 | +defined('ABSPATH') || exit; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * WC_Install Class. |
@@ -219,18 +219,18 @@ discard block |
||
| 219 | 219 | * Hook in tabs. |
| 220 | 220 | */ |
| 221 | 221 | public static function init() { |
| 222 | - add_action( 'init', array( __CLASS__, 'check_version' ), 5 ); |
|
| 223 | - add_action( 'init', array( __CLASS__, 'manual_database_update' ), 20 ); |
|
| 224 | - add_action( 'admin_init', array( __CLASS__, 'wc_admin_db_update_notice' ) ); |
|
| 225 | - add_action( 'admin_init', array( __CLASS__, 'add_admin_note_after_page_created' ) ); |
|
| 226 | - add_action( 'woocommerce_run_update_callback', array( __CLASS__, 'run_update_callback' ) ); |
|
| 227 | - add_action( 'woocommerce_update_db_to_current_version', array( __CLASS__, 'update_db_version' ) ); |
|
| 228 | - add_action( 'admin_init', array( __CLASS__, 'install_actions' ) ); |
|
| 229 | - add_action( 'woocommerce_page_created', array( __CLASS__, 'page_created' ), 10, 2 ); |
|
| 230 | - add_filter( 'plugin_action_links_' . WC_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) ); |
|
| 231 | - add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 ); |
|
| 232 | - add_filter( 'wpmu_drop_tables', array( __CLASS__, 'wpmu_drop_tables' ) ); |
|
| 233 | - add_filter( 'cron_schedules', array( __CLASS__, 'cron_schedules' ) ); |
|
| 222 | + add_action('init', array(__CLASS__, 'check_version'), 5); |
|
| 223 | + add_action('init', array(__CLASS__, 'manual_database_update'), 20); |
|
| 224 | + add_action('admin_init', array(__CLASS__, 'wc_admin_db_update_notice')); |
|
| 225 | + add_action('admin_init', array(__CLASS__, 'add_admin_note_after_page_created')); |
|
| 226 | + add_action('woocommerce_run_update_callback', array(__CLASS__, 'run_update_callback')); |
|
| 227 | + add_action('woocommerce_update_db_to_current_version', array(__CLASS__, 'update_db_version')); |
|
| 228 | + add_action('admin_init', array(__CLASS__, 'install_actions')); |
|
| 229 | + add_action('woocommerce_page_created', array(__CLASS__, 'page_created'), 10, 2); |
|
| 230 | + add_filter('plugin_action_links_' . WC_PLUGIN_BASENAME, array(__CLASS__, 'plugin_action_links')); |
|
| 231 | + add_filter('plugin_row_meta', array(__CLASS__, 'plugin_row_meta'), 10, 2); |
|
| 232 | + add_filter('wpmu_drop_tables', array(__CLASS__, 'wpmu_drop_tables')); |
|
| 233 | + add_filter('cron_schedules', array(__CLASS__, 'cron_schedules')); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,27 +239,27 @@ discard block |
||
| 239 | 239 | * This check is done on all requests and runs if the versions do not match. |
| 240 | 240 | */ |
| 241 | 241 | public static function check_version() { |
| 242 | - $wc_version = get_option( 'woocommerce_version' ); |
|
| 242 | + $wc_version = get_option('woocommerce_version'); |
|
| 243 | 243 | $wc_code_version = WC()->version; |
| 244 | - $requires_update = version_compare( $wc_version, $wc_code_version, '<' ); |
|
| 245 | - if ( ! Constants::is_defined( 'IFRAME_REQUEST' ) && $requires_update ) { |
|
| 244 | + $requires_update = version_compare($wc_version, $wc_code_version, '<'); |
|
| 245 | + if (!Constants::is_defined('IFRAME_REQUEST') && $requires_update) { |
|
| 246 | 246 | self::install(); |
| 247 | 247 | /** |
| 248 | 248 | * Run after WooCommerce has been updated. |
| 249 | 249 | * |
| 250 | 250 | * @since 2.2.0 |
| 251 | 251 | */ |
| 252 | - do_action( 'woocommerce_updated' ); |
|
| 253 | - do_action_deprecated( 'woocommerce_admin_updated', array(), $wc_code_version, 'woocommerce_updated' ); |
|
| 252 | + do_action('woocommerce_updated'); |
|
| 253 | + do_action_deprecated('woocommerce_admin_updated', array(), $wc_code_version, 'woocommerce_updated'); |
|
| 254 | 254 | // If there is no woocommerce_version option, consider it as a new install. |
| 255 | - if ( ! $wc_version ) { |
|
| 255 | + if (!$wc_version) { |
|
| 256 | 256 | /** |
| 257 | 257 | * Run when WooCommerce has been installed for the first time. |
| 258 | 258 | * |
| 259 | 259 | * @since 6.5.0 |
| 260 | 260 | */ |
| 261 | - do_action( 'woocommerce_newly_installed' ); |
|
| 262 | - do_action_deprecated( 'woocommerce_admin_newly_installed', array(), $wc_code_version, 'woocommerce_newly_installed' ); |
|
| 261 | + do_action('woocommerce_newly_installed'); |
|
| 262 | + do_action_deprecated('woocommerce_admin_newly_installed', array(), $wc_code_version, 'woocommerce_newly_installed'); |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | public static function manual_database_update() { |
| 273 | 273 | $blog_id = get_current_blog_id(); |
| 274 | 274 | |
| 275 | - add_action( 'wp_' . $blog_id . '_wc_updater_cron', array( __CLASS__, 'run_manual_database_update' ) ); |
|
| 275 | + add_action('wp_' . $blog_id . '_wc_updater_cron', array(__CLASS__, 'run_manual_database_update')); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | public static function wc_admin_db_update_notice() { |
| 284 | 284 | if ( |
| 285 | 285 | WC()->is_wc_admin_active() && |
| 286 | - false !== get_option( 'woocommerce_admin_install_timestamp' ) |
|
| 286 | + false !== get_option('woocommerce_admin_install_timestamp') |
|
| 287 | 287 | ) { |
| 288 | 288 | new WC_Notes_Run_Db_Update(); |
| 289 | 289 | } |
@@ -303,13 +303,13 @@ discard block |
||
| 303 | 303 | * |
| 304 | 304 | * @since 3.6.0 |
| 305 | 305 | */ |
| 306 | - public static function run_update_callback( $update_callback ) { |
|
| 307 | - include_once dirname( __FILE__ ) . '/wc-update-functions.php'; |
|
| 306 | + public static function run_update_callback($update_callback) { |
|
| 307 | + include_once dirname(__FILE__) . '/wc-update-functions.php'; |
|
| 308 | 308 | |
| 309 | - if ( is_callable( $update_callback ) ) { |
|
| 310 | - self::run_update_callback_start( $update_callback ); |
|
| 311 | - $result = (bool) call_user_func( $update_callback ); |
|
| 312 | - self::run_update_callback_end( $update_callback, $result ); |
|
| 309 | + if (is_callable($update_callback)) { |
|
| 310 | + self::run_update_callback_start($update_callback); |
|
| 311 | + $result = (bool) call_user_func($update_callback); |
|
| 312 | + self::run_update_callback_end($update_callback, $result); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | * @since 3.6.0 |
| 320 | 320 | * @param string $callback Callback name. |
| 321 | 321 | */ |
| 322 | - protected static function run_update_callback_start( $callback ) { |
|
| 323 | - wc_maybe_define_constant( 'WC_UPDATING', true ); |
|
| 322 | + protected static function run_update_callback_start($callback) { |
|
| 323 | + wc_maybe_define_constant('WC_UPDATING', true); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -330,8 +330,8 @@ discard block |
||
| 330 | 330 | * @param string $callback Callback name. |
| 331 | 331 | * @param bool $result Return value from callback. Non-false need to run again. |
| 332 | 332 | */ |
| 333 | - protected static function run_update_callback_end( $callback, $result ) { |
|
| 334 | - if ( $result ) { |
|
| 333 | + protected static function run_update_callback_end($callback, $result) { |
|
| 334 | + if ($result) { |
|
| 335 | 335 | WC()->queue()->add( |
| 336 | 336 | 'woocommerce_run_update_callback', |
| 337 | 337 | array( |
@@ -348,10 +348,10 @@ discard block |
||
| 348 | 348 | * This function is hooked into admin_init to affect admin only. |
| 349 | 349 | */ |
| 350 | 350 | public static function install_actions() { |
| 351 | - if ( ! empty( $_GET['do_update_woocommerce'] ) ) { // WPCS: input var ok. |
|
| 352 | - check_admin_referer( 'wc_db_update', 'wc_db_update_nonce' ); |
|
| 351 | + if (!empty($_GET['do_update_woocommerce'])) { // WPCS: input var ok. |
|
| 352 | + check_admin_referer('wc_db_update', 'wc_db_update_nonce'); |
|
| 353 | 353 | self::update(); |
| 354 | - WC_Admin_Notices::add_notice( 'update', true ); |
|
| 354 | + WC_Admin_Notices::add_notice('update', true); |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
@@ -359,18 +359,18 @@ discard block |
||
| 359 | 359 | * Install WC. |
| 360 | 360 | */ |
| 361 | 361 | public static function install() { |
| 362 | - if ( ! is_blog_installed() ) { |
|
| 362 | + if (!is_blog_installed()) { |
|
| 363 | 363 | return; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // Check if we are not already running this routine. |
| 367 | - if ( self::is_installing() ) { |
|
| 367 | + if (self::is_installing()) { |
|
| 368 | 368 | return; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // If we made it till here nothing is running yet, lets set the transient now. |
| 372 | - set_transient( 'wc_installing', 'yes', MINUTE_IN_SECONDS * 10 ); |
|
| 373 | - wc_maybe_define_constant( 'WC_INSTALLING', true ); |
|
| 372 | + set_transient('wc_installing', 'yes', MINUTE_IN_SECONDS * 10); |
|
| 373 | + wc_maybe_define_constant('WC_INSTALLING', true); |
|
| 374 | 374 | |
| 375 | 375 | WC()->wpdb_table_fix(); |
| 376 | 376 | self::remove_admin_notices(); |
@@ -390,30 +390,30 @@ discard block |
||
| 390 | 390 | self::update_wc_version(); |
| 391 | 391 | self::maybe_update_db_version(); |
| 392 | 392 | |
| 393 | - delete_transient( 'wc_installing' ); |
|
| 393 | + delete_transient('wc_installing'); |
|
| 394 | 394 | |
| 395 | 395 | // Use add_option() here to avoid overwriting this value with each |
| 396 | 396 | // plugin version update. We base plugin age off of this value. |
| 397 | - add_option( 'woocommerce_admin_install_timestamp', time() ); |
|
| 397 | + add_option('woocommerce_admin_install_timestamp', time()); |
|
| 398 | 398 | |
| 399 | 399 | /** |
| 400 | 400 | * Flush the rewrite rules after install or update. |
| 401 | 401 | * |
| 402 | 402 | * @since 2.7.0 |
| 403 | 403 | */ |
| 404 | - do_action( 'woocommerce_flush_rewrite_rules' ); |
|
| 404 | + do_action('woocommerce_flush_rewrite_rules'); |
|
| 405 | 405 | /** |
| 406 | 406 | * Run after WooCommerce has been installed or updated. |
| 407 | 407 | * |
| 408 | 408 | * @since 3.2.0 |
| 409 | 409 | */ |
| 410 | - do_action( 'woocommerce_installed' ); |
|
| 410 | + do_action('woocommerce_installed'); |
|
| 411 | 411 | /** |
| 412 | 412 | * Run after WooCommerce Admin has been installed or updated. |
| 413 | 413 | * |
| 414 | 414 | * @since 6.5.0 |
| 415 | 415 | */ |
| 416 | - do_action( 'woocommerce_admin_installed' ); |
|
| 416 | + do_action('woocommerce_admin_installed'); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @return bool |
| 423 | 423 | */ |
| 424 | 424 | private static function is_installing() { |
| 425 | - return 'yes' === get_transient( 'wc_installing' ); |
|
| 425 | + return 'yes' === get_transient('wc_installing'); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -433,26 +433,26 @@ discard block |
||
| 433 | 433 | * |
| 434 | 434 | * @return array List of queries. |
| 435 | 435 | */ |
| 436 | - public static function verify_base_tables( $modify_notice = true, $execute = false ) { |
|
| 437 | - if ( $execute ) { |
|
| 436 | + public static function verify_base_tables($modify_notice = true, $execute = false) { |
|
| 437 | + if ($execute) { |
|
| 438 | 438 | self::create_tables(); |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | $missing_tables = wc_get_container() |
| 442 | - ->get( DatabaseUtil::class ) |
|
| 443 | - ->get_missing_tables( self::get_schema() ); |
|
| 442 | + ->get(DatabaseUtil::class) |
|
| 443 | + ->get_missing_tables(self::get_schema()); |
|
| 444 | 444 | |
| 445 | - if ( 0 < count( $missing_tables ) ) { |
|
| 446 | - if ( $modify_notice ) { |
|
| 447 | - WC_Admin_Notices::add_notice( 'base_tables_missing' ); |
|
| 445 | + if (0 < count($missing_tables)) { |
|
| 446 | + if ($modify_notice) { |
|
| 447 | + WC_Admin_Notices::add_notice('base_tables_missing'); |
|
| 448 | 448 | } |
| 449 | - update_option( 'woocommerce_schema_missing_tables', $missing_tables ); |
|
| 449 | + update_option('woocommerce_schema_missing_tables', $missing_tables); |
|
| 450 | 450 | } else { |
| 451 | - if ( $modify_notice ) { |
|
| 452 | - WC_Admin_Notices::remove_notice( 'base_tables_missing' ); |
|
| 451 | + if ($modify_notice) { |
|
| 452 | + WC_Admin_Notices::remove_notice('base_tables_missing'); |
|
| 453 | 453 | } |
| 454 | - update_option( 'woocommerce_schema_version', WC()->db_version ); |
|
| 455 | - delete_option( 'woocommerce_schema_missing_tables' ); |
|
| 454 | + update_option('woocommerce_schema_version', WC()->db_version); |
|
| 455 | + delete_option('woocommerce_schema_missing_tables'); |
|
| 456 | 456 | } |
| 457 | 457 | return $missing_tables; |
| 458 | 458 | } |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | * @since 3.2.0 |
| 464 | 464 | */ |
| 465 | 465 | private static function remove_admin_notices() { |
| 466 | - include_once dirname( __FILE__ ) . '/admin/class-wc-admin-notices.php'; |
|
| 466 | + include_once dirname(__FILE__) . '/admin/class-wc-admin-notices.php'; |
|
| 467 | 467 | WC_Admin_Notices::remove_all_notices(); |
| 468 | 468 | } |
| 469 | 469 | |
@@ -490,9 +490,9 @@ discard block |
||
| 490 | 490 | * @return boolean |
| 491 | 491 | */ |
| 492 | 492 | public static function is_new_install() { |
| 493 | - $product_count = array_sum( (array) wp_count_posts( 'product' ) ); |
|
| 493 | + $product_count = array_sum((array) wp_count_posts('product')); |
|
| 494 | 494 | |
| 495 | - return is_null( get_option( 'woocommerce_version', null ) ) || ( 0 === $product_count && -1 === wc_get_page_id( 'shop' ) ); |
|
| 495 | + return is_null(get_option('woocommerce_version', null)) || (0 === $product_count && -1 === wc_get_page_id('shop')); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
@@ -502,12 +502,12 @@ discard block |
||
| 502 | 502 | * @return boolean |
| 503 | 503 | */ |
| 504 | 504 | public static function needs_db_update() { |
| 505 | - $current_db_version = get_option( 'woocommerce_db_version', null ); |
|
| 505 | + $current_db_version = get_option('woocommerce_db_version', null); |
|
| 506 | 506 | $updates = self::get_db_update_callbacks(); |
| 507 | - $update_versions = array_keys( $updates ); |
|
| 508 | - usort( $update_versions, 'version_compare' ); |
|
| 507 | + $update_versions = array_keys($updates); |
|
| 508 | + usort($update_versions, 'version_compare'); |
|
| 509 | 509 | |
| 510 | - return ! is_null( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' ); |
|
| 510 | + return !is_null($current_db_version) && version_compare($current_db_version, end($update_versions), '<'); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -516,8 +516,8 @@ discard block |
||
| 516 | 516 | * @since 4.6.0 |
| 517 | 517 | */ |
| 518 | 518 | private static function maybe_set_activation_transients() { |
| 519 | - if ( self::is_new_install() ) { |
|
| 520 | - set_transient( '_wc_activation_redirect', 1, 30 ); |
|
| 519 | + if (self::is_new_install()) { |
|
| 520 | + set_transient('_wc_activation_redirect', 1, 30); |
|
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
@@ -527,16 +527,16 @@ discard block |
||
| 527 | 527 | * @since 3.2.0 |
| 528 | 528 | */ |
| 529 | 529 | private static function maybe_update_db_version() { |
| 530 | - if ( self::needs_db_update() ) { |
|
| 530 | + if (self::needs_db_update()) { |
|
| 531 | 531 | /** |
| 532 | 532 | * Allow WooCommerce to auto-update without prompting the user. |
| 533 | 533 | * |
| 534 | 534 | * @since 3.2.0 |
| 535 | 535 | */ |
| 536 | - if ( apply_filters( 'woocommerce_enable_auto_update_db', false ) ) { |
|
| 536 | + if (apply_filters('woocommerce_enable_auto_update_db', false)) { |
|
| 537 | 537 | self::update(); |
| 538 | 538 | } else { |
| 539 | - WC_Admin_Notices::add_notice( 'update', true ); |
|
| 539 | + WC_Admin_Notices::add_notice('update', true); |
|
| 540 | 540 | } |
| 541 | 541 | } else { |
| 542 | 542 | self::update_db_version(); |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | * Update WC version to current. |
| 548 | 548 | */ |
| 549 | 549 | private static function update_wc_version() { |
| 550 | - update_option( 'woocommerce_version', WC()->version ); |
|
| 550 | + update_option('woocommerce_version', WC()->version); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -564,12 +564,12 @@ discard block |
||
| 564 | 564 | * Push all needed DB updates to the queue for processing. |
| 565 | 565 | */ |
| 566 | 566 | private static function update() { |
| 567 | - $current_db_version = get_option( 'woocommerce_db_version' ); |
|
| 567 | + $current_db_version = get_option('woocommerce_db_version'); |
|
| 568 | 568 | $loop = 0; |
| 569 | 569 | |
| 570 | - foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) { |
|
| 571 | - if ( version_compare( $current_db_version, $version, '<' ) ) { |
|
| 572 | - foreach ( $update_callbacks as $update_callback ) { |
|
| 570 | + foreach (self::get_db_update_callbacks() as $version => $update_callbacks) { |
|
| 571 | + if (version_compare($current_db_version, $version, '<')) { |
|
| 572 | + foreach ($update_callbacks as $update_callback) { |
|
| 573 | 573 | WC()->queue()->schedule_single( |
| 574 | 574 | time() + $loop, |
| 575 | 575 | 'woocommerce_run_update_callback', |
@@ -585,8 +585,8 @@ discard block |
||
| 585 | 585 | |
| 586 | 586 | // After the callbacks finish, update the db version to the current WC version. |
| 587 | 587 | $current_wc_version = WC()->version; |
| 588 | - if ( version_compare( $current_db_version, $current_wc_version, '<' ) && |
|
| 589 | - ! WC()->queue()->get_next( 'woocommerce_update_db_to_current_version' ) ) { |
|
| 588 | + if (version_compare($current_db_version, $current_wc_version, '<') && |
|
| 589 | + !WC()->queue()->get_next('woocommerce_update_db_to_current_version')) { |
|
| 590 | 590 | WC()->queue()->schedule_single( |
| 591 | 591 | time() + $loop, |
| 592 | 592 | 'woocommerce_update_db_to_current_version', |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | * |
| 604 | 604 | * @param string|null $version New WooCommerce DB version or null. |
| 605 | 605 | */ |
| 606 | - public static function update_db_version( $version = null ) { |
|
| 607 | - update_option( 'woocommerce_db_version', is_null( $version ) ? WC()->version : $version ); |
|
| 606 | + public static function update_db_version($version = null) { |
|
| 607 | + update_option('woocommerce_db_version', is_null($version) ? WC()->version : $version); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -614,14 +614,14 @@ discard block |
||
| 614 | 614 | * |
| 615 | 615 | * @return array |
| 616 | 616 | */ |
| 617 | - public static function cron_schedules( $schedules ) { |
|
| 618 | - $schedules['monthly'] = array( |
|
| 617 | + public static function cron_schedules($schedules) { |
|
| 618 | + $schedules['monthly'] = array( |
|
| 619 | 619 | 'interval' => 2635200, |
| 620 | - 'display' => __( 'Monthly', 'woocommerce' ), |
|
| 620 | + 'display' => __('Monthly', 'woocommerce'), |
|
| 621 | 621 | ); |
| 622 | 622 | $schedules['fifteendays'] = array( |
| 623 | 623 | 'interval' => 1296000, |
| 624 | - 'display' => __( 'Every 15 Days', 'woocommerce' ), |
|
| 624 | + 'display' => __('Every 15 Days', 'woocommerce'), |
|
| 625 | 625 | ); |
| 626 | 626 | return $schedules; |
| 627 | 627 | } |
@@ -630,59 +630,59 @@ discard block |
||
| 630 | 630 | * Create cron jobs (clear them first). |
| 631 | 631 | */ |
| 632 | 632 | private static function create_cron_jobs() { |
| 633 | - wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' ); |
|
| 634 | - wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' ); |
|
| 635 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' ); |
|
| 636 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_personal_data' ); |
|
| 637 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_logs' ); |
|
| 638 | - wp_clear_scheduled_hook( 'woocommerce_geoip_updater' ); |
|
| 639 | - wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); |
|
| 640 | - wp_clear_scheduled_hook( 'woocommerce_cleanup_rate_limits' ); |
|
| 633 | + wp_clear_scheduled_hook('woocommerce_scheduled_sales'); |
|
| 634 | + wp_clear_scheduled_hook('woocommerce_cancel_unpaid_orders'); |
|
| 635 | + wp_clear_scheduled_hook('woocommerce_cleanup_sessions'); |
|
| 636 | + wp_clear_scheduled_hook('woocommerce_cleanup_personal_data'); |
|
| 637 | + wp_clear_scheduled_hook('woocommerce_cleanup_logs'); |
|
| 638 | + wp_clear_scheduled_hook('woocommerce_geoip_updater'); |
|
| 639 | + wp_clear_scheduled_hook('woocommerce_tracker_send_event'); |
|
| 640 | + wp_clear_scheduled_hook('woocommerce_cleanup_rate_limits'); |
|
| 641 | 641 | |
| 642 | - $ve = get_option( 'gmt_offset' ) > 0 ? '-' : '+'; |
|
| 642 | + $ve = get_option('gmt_offset') > 0 ? '-' : '+'; |
|
| 643 | 643 | |
| 644 | - wp_schedule_event( strtotime( '00:00 tomorrow ' . $ve . absint( get_option( 'gmt_offset' ) ) . ' HOURS' ), 'daily', 'woocommerce_scheduled_sales' ); |
|
| 644 | + wp_schedule_event(strtotime('00:00 tomorrow ' . $ve . absint(get_option('gmt_offset')) . ' HOURS'), 'daily', 'woocommerce_scheduled_sales'); |
|
| 645 | 645 | |
| 646 | - $held_duration = get_option( 'woocommerce_hold_stock_minutes', '60' ); |
|
| 646 | + $held_duration = get_option('woocommerce_hold_stock_minutes', '60'); |
|
| 647 | 647 | |
| 648 | - if ( '' !== $held_duration ) { |
|
| 648 | + if ('' !== $held_duration) { |
|
| 649 | 649 | /** |
| 650 | 650 | * Determines the interval at which to cancel unpaid orders in minutes. |
| 651 | 651 | * |
| 652 | 652 | * @since 5.1.0 |
| 653 | 653 | */ |
| 654 | - $cancel_unpaid_interval = apply_filters( 'woocommerce_cancel_unpaid_orders_interval_minutes', absint( $held_duration ) ); |
|
| 655 | - wp_schedule_single_event( time() + ( absint( $cancel_unpaid_interval ) * 60 ), 'woocommerce_cancel_unpaid_orders' ); |
|
| 654 | + $cancel_unpaid_interval = apply_filters('woocommerce_cancel_unpaid_orders_interval_minutes', absint($held_duration)); |
|
| 655 | + wp_schedule_single_event(time() + (absint($cancel_unpaid_interval) * 60), 'woocommerce_cancel_unpaid_orders'); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | // Delay the first run of `woocommerce_cleanup_personal_data` by 10 seconds |
| 659 | 659 | // so it doesn't occur in the same request. WooCommerce Admin also schedules |
| 660 | 660 | // a daily cron that gets lost due to a race condition. WC_Privacy's background |
| 661 | 661 | // processing instance updates the cron schedule from within a cron job. |
| 662 | - wp_schedule_event( time() + 10, 'daily', 'woocommerce_cleanup_personal_data' ); |
|
| 663 | - wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_logs' ); |
|
| 664 | - wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'woocommerce_cleanup_sessions' ); |
|
| 665 | - wp_schedule_event( time() + MINUTE_IN_SECONDS, 'fifteendays', 'woocommerce_geoip_updater' ); |
|
| 662 | + wp_schedule_event(time() + 10, 'daily', 'woocommerce_cleanup_personal_data'); |
|
| 663 | + wp_schedule_event(time() + (3 * HOUR_IN_SECONDS), 'daily', 'woocommerce_cleanup_logs'); |
|
| 664 | + wp_schedule_event(time() + (6 * HOUR_IN_SECONDS), 'twicedaily', 'woocommerce_cleanup_sessions'); |
|
| 665 | + wp_schedule_event(time() + MINUTE_IN_SECONDS, 'fifteendays', 'woocommerce_geoip_updater'); |
|
| 666 | 666 | /** |
| 667 | 667 | * How frequent to schedule the tracker send event. |
| 668 | 668 | * |
| 669 | 669 | * @since 2.3.0 |
| 670 | 670 | */ |
| 671 | - wp_schedule_event( time() + 10, apply_filters( 'woocommerce_tracker_event_recurrence', 'daily' ), 'woocommerce_tracker_send_event' ); |
|
| 672 | - wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_rate_limits' ); |
|
| 671 | + wp_schedule_event(time() + 10, apply_filters('woocommerce_tracker_event_recurrence', 'daily'), 'woocommerce_tracker_send_event'); |
|
| 672 | + wp_schedule_event(time() + (3 * HOUR_IN_SECONDS), 'daily', 'woocommerce_cleanup_rate_limits'); |
|
| 673 | 673 | |
| 674 | - if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) { |
|
| 675 | - wp_schedule_event( time(), 'daily', 'wc_admin_daily' ); |
|
| 674 | + if (!wp_next_scheduled('wc_admin_daily')) { |
|
| 675 | + wp_schedule_event(time(), 'daily', 'wc_admin_daily'); |
|
| 676 | 676 | } |
| 677 | 677 | // Note: this is potentially redundant when the core package exists. |
| 678 | - wp_schedule_single_event( time() + 10, 'generate_category_lookup_table' ); |
|
| 678 | + wp_schedule_single_event(time() + 10, 'generate_category_lookup_table'); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
| 682 | 682 | * Create pages on installation. |
| 683 | 683 | */ |
| 684 | 684 | public static function maybe_create_pages() { |
| 685 | - if ( empty( get_option( 'woocommerce_db_version' ) ) ) { |
|
| 685 | + if (empty(get_option('woocommerce_db_version'))) { |
|
| 686 | 686 | self::create_pages(); |
| 687 | 687 | } |
| 688 | 688 | } |
@@ -691,28 +691,28 @@ discard block |
||
| 691 | 691 | * Create pages that the plugin relies on, storing page IDs in variables. |
| 692 | 692 | */ |
| 693 | 693 | public static function create_pages() { |
| 694 | - include_once dirname( __FILE__ ) . '/admin/wc-admin-functions.php'; |
|
| 694 | + include_once dirname(__FILE__) . '/admin/wc-admin-functions.php'; |
|
| 695 | 695 | |
| 696 | 696 | /** |
| 697 | 697 | * Determines the cart shortcode tag used for the cart page. |
| 698 | 698 | * |
| 699 | 699 | * @since 2.1.0 |
| 700 | 700 | */ |
| 701 | - $cart_shortcode = apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ); |
|
| 701 | + $cart_shortcode = apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart'); |
|
| 702 | 702 | |
| 703 | 703 | /** |
| 704 | 704 | * Determines the checkout shortcode tag used on the checkout page. |
| 705 | 705 | * |
| 706 | 706 | * @since 2.1.0 |
| 707 | 707 | */ |
| 708 | - $checkout_shortcode = apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ); |
|
| 708 | + $checkout_shortcode = apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout'); |
|
| 709 | 709 | |
| 710 | 710 | /** |
| 711 | 711 | * Determines the my account shortcode tag used on the my account page. |
| 712 | 712 | * |
| 713 | 713 | * @since 2.1.0 |
| 714 | 714 | */ |
| 715 | - $my_account_shortcode = apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ); |
|
| 715 | + $my_account_shortcode = apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account'); |
|
| 716 | 716 | |
| 717 | 717 | /** |
| 718 | 718 | * Determines which pages are created during install. |
@@ -723,42 +723,42 @@ discard block |
||
| 723 | 723 | 'woocommerce_create_pages', |
| 724 | 724 | array( |
| 725 | 725 | 'shop' => array( |
| 726 | - 'name' => _x( 'shop', 'Page slug', 'woocommerce' ), |
|
| 727 | - 'title' => _x( 'Shop', 'Page title', 'woocommerce' ), |
|
| 726 | + 'name' => _x('shop', 'Page slug', 'woocommerce'), |
|
| 727 | + 'title' => _x('Shop', 'Page title', 'woocommerce'), |
|
| 728 | 728 | 'content' => '', |
| 729 | 729 | ), |
| 730 | 730 | 'cart' => array( |
| 731 | - 'name' => _x( 'cart', 'Page slug', 'woocommerce' ), |
|
| 732 | - 'title' => _x( 'Cart', 'Page title', 'woocommerce' ), |
|
| 731 | + 'name' => _x('cart', 'Page slug', 'woocommerce'), |
|
| 732 | + 'title' => _x('Cart', 'Page title', 'woocommerce'), |
|
| 733 | 733 | 'content' => '<!-- wp:shortcode -->[' . $cart_shortcode . ']<!-- /wp:shortcode -->', |
| 734 | 734 | ), |
| 735 | 735 | 'checkout' => array( |
| 736 | - 'name' => _x( 'checkout', 'Page slug', 'woocommerce' ), |
|
| 737 | - 'title' => _x( 'Checkout', 'Page title', 'woocommerce' ), |
|
| 736 | + 'name' => _x('checkout', 'Page slug', 'woocommerce'), |
|
| 737 | + 'title' => _x('Checkout', 'Page title', 'woocommerce'), |
|
| 738 | 738 | 'content' => '<!-- wp:shortcode -->[' . $checkout_shortcode . ']<!-- /wp:shortcode -->', |
| 739 | 739 | ), |
| 740 | 740 | 'myaccount' => array( |
| 741 | - 'name' => _x( 'my-account', 'Page slug', 'woocommerce' ), |
|
| 742 | - 'title' => _x( 'My account', 'Page title', 'woocommerce' ), |
|
| 741 | + 'name' => _x('my-account', 'Page slug', 'woocommerce'), |
|
| 742 | + 'title' => _x('My account', 'Page title', 'woocommerce'), |
|
| 743 | 743 | 'content' => '<!-- wp:shortcode -->[' . $my_account_shortcode . ']<!-- /wp:shortcode -->', |
| 744 | 744 | ), |
| 745 | 745 | 'refund_returns' => array( |
| 746 | - 'name' => _x( 'refund_returns', 'Page slug', 'woocommerce' ), |
|
| 747 | - 'title' => _x( 'Refund and Returns Policy', 'Page title', 'woocommerce' ), |
|
| 746 | + 'name' => _x('refund_returns', 'Page slug', 'woocommerce'), |
|
| 747 | + 'title' => _x('Refund and Returns Policy', 'Page title', 'woocommerce'), |
|
| 748 | 748 | 'content' => self::get_refunds_return_policy_page_content(), |
| 749 | 749 | 'post_status' => 'draft', |
| 750 | 750 | ), |
| 751 | 751 | ) |
| 752 | 752 | ); |
| 753 | 753 | |
| 754 | - foreach ( $pages as $key => $page ) { |
|
| 754 | + foreach ($pages as $key => $page) { |
|
| 755 | 755 | wc_create_page( |
| 756 | - esc_sql( $page['name'] ), |
|
| 756 | + esc_sql($page['name']), |
|
| 757 | 757 | 'woocommerce_' . $key . '_page_id', |
| 758 | 758 | $page['title'], |
| 759 | 759 | $page['content'], |
| 760 | - ! empty( $page['parent'] ) ? wc_get_page_id( $page['parent'] ) : '', |
|
| 761 | - ! empty( $page['post_status'] ) ? $page['post_status'] : 'publish' |
|
| 760 | + !empty($page['parent']) ? wc_get_page_id($page['parent']) : '', |
|
| 761 | + !empty($page['post_status']) ? $page['post_status'] : 'publish' |
|
| 762 | 762 | ); |
| 763 | 763 | } |
| 764 | 764 | } |
@@ -770,44 +770,44 @@ discard block |
||
| 770 | 770 | */ |
| 771 | 771 | private static function create_options() { |
| 772 | 772 | // Include settings so that we can run through defaults. |
| 773 | - include_once dirname( __FILE__ ) . '/admin/class-wc-admin-settings.php'; |
|
| 773 | + include_once dirname(__FILE__) . '/admin/class-wc-admin-settings.php'; |
|
| 774 | 774 | |
| 775 | 775 | $settings = WC_Admin_Settings::get_settings_pages(); |
| 776 | 776 | |
| 777 | - foreach ( $settings as $section ) { |
|
| 778 | - if ( ! is_a( $section, 'WC_Settings_Page' ) || ! method_exists( $section, 'get_settings' ) ) { |
|
| 777 | + foreach ($settings as $section) { |
|
| 778 | + if (!is_a($section, 'WC_Settings_Page') || !method_exists($section, 'get_settings')) { |
|
| 779 | 779 | continue; |
| 780 | 780 | } |
| 781 | - $subsections = array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) ); |
|
| 781 | + $subsections = array_unique(array_merge(array(''), array_keys($section->get_sections()))); |
|
| 782 | 782 | |
| 783 | 783 | /** |
| 784 | 784 | * We are using 'WC_Settings_Page::get_settings' on purpose even thought it's deprecated. |
| 785 | 785 | * See the method documentation for an explanation. |
| 786 | 786 | */ |
| 787 | 787 | |
| 788 | - foreach ( $subsections as $subsection ) { |
|
| 789 | - foreach ( $section->get_settings( $subsection ) as $value ) { |
|
| 790 | - if ( isset( $value['default'] ) && isset( $value['id'] ) ) { |
|
| 791 | - $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true; |
|
| 792 | - add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) ); |
|
| 788 | + foreach ($subsections as $subsection) { |
|
| 789 | + foreach ($section->get_settings($subsection) as $value) { |
|
| 790 | + if (isset($value['default']) && isset($value['id'])) { |
|
| 791 | + $autoload = isset($value['autoload']) ? (bool) $value['autoload'] : true; |
|
| 792 | + add_option($value['id'], $value['default'], '', ($autoload ? 'yes' : 'no')); |
|
| 793 | 793 | } |
| 794 | 794 | } |
| 795 | 795 | } |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | // Define other defaults if not in setting screens. |
| 799 | - add_option( 'woocommerce_single_image_width', '600', '', 'yes' ); |
|
| 800 | - add_option( 'woocommerce_thumbnail_image_width', '300', '', 'yes' ); |
|
| 801 | - add_option( 'woocommerce_checkout_highlight_required_fields', 'yes', '', 'yes' ); |
|
| 802 | - add_option( 'woocommerce_demo_store', 'no', '', 'no' ); |
|
| 799 | + add_option('woocommerce_single_image_width', '600', '', 'yes'); |
|
| 800 | + add_option('woocommerce_thumbnail_image_width', '300', '', 'yes'); |
|
| 801 | + add_option('woocommerce_checkout_highlight_required_fields', 'yes', '', 'yes'); |
|
| 802 | + add_option('woocommerce_demo_store', 'no', '', 'no'); |
|
| 803 | 803 | |
| 804 | - if ( self::is_new_install() ) { |
|
| 804 | + if (self::is_new_install()) { |
|
| 805 | 805 | // Define initial tax classes. |
| 806 | - WC_Tax::create_tax_class( __( 'Reduced rate', 'woocommerce' ) ); |
|
| 807 | - WC_Tax::create_tax_class( __( 'Zero rate', 'woocommerce' ) ); |
|
| 806 | + WC_Tax::create_tax_class(__('Reduced rate', 'woocommerce')); |
|
| 807 | + WC_Tax::create_tax_class(__('Zero rate', 'woocommerce')); |
|
| 808 | 808 | |
| 809 | 809 | // For new installs, setup and enable Approved Product Download Directories. |
| 810 | - wc_get_container()->get( Download_Directories_Sync::class )->init_feature( false, true ); |
|
| 810 | + wc_get_container()->get(Download_Directories_Sync::class)->init_feature(false, true); |
|
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | |
@@ -851,16 +851,16 @@ discard block |
||
| 851 | 851 | array() |
| 852 | 852 | ); |
| 853 | 853 | |
| 854 | - if ( is_array( $additional_obsolete_notes_names ) ) { |
|
| 854 | + if (is_array($additional_obsolete_notes_names)) { |
|
| 855 | 855 | $obsolete_notes_names = array_merge( |
| 856 | 856 | $obsolete_notes_names, |
| 857 | 857 | $additional_obsolete_notes_names |
| 858 | 858 | ); |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - foreach ( $obsolete_notes_names as $obsolete_notes_name ) { |
|
| 862 | - $wpdb->delete( $wpdb->prefix . 'wc_admin_notes', array( 'name' => $obsolete_notes_name ) ); |
|
| 863 | - $wpdb->delete( $wpdb->prefix . 'wc_admin_note_actions', array( 'name' => $obsolete_notes_name ) ); |
|
| 861 | + foreach ($obsolete_notes_names as $obsolete_notes_name) { |
|
| 862 | + $wpdb->delete($wpdb->prefix . 'wc_admin_notes', array('name' => $obsolete_notes_name)); |
|
| 863 | + $wpdb->delete($wpdb->prefix . 'wc_admin_note_actions', array('name' => $obsolete_notes_name)); |
|
| 864 | 864 | } |
| 865 | 865 | } |
| 866 | 866 | |
@@ -884,25 +884,25 @@ discard block |
||
| 884 | 884 | 'woocommerce_extended_task_list_hidden' => 'woocommerce_extended_task_list_hidden', |
| 885 | 885 | ); |
| 886 | 886 | |
| 887 | - wc_maybe_define_constant( 'WC_ADMIN_MIGRATING_OPTIONS', true ); |
|
| 887 | + wc_maybe_define_constant('WC_ADMIN_MIGRATING_OPTIONS', true); |
|
| 888 | 888 | |
| 889 | - foreach ( $migrated_options as $new_option => $old_option ) { |
|
| 890 | - $old_option_value = get_option( $old_option, false ); |
|
| 889 | + foreach ($migrated_options as $new_option => $old_option) { |
|
| 890 | + $old_option_value = get_option($old_option, false); |
|
| 891 | 891 | |
| 892 | 892 | // Continue if no option value was previously set. |
| 893 | - if ( false === $old_option_value ) { |
|
| 893 | + if (false === $old_option_value) { |
|
| 894 | 894 | continue; |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | - if ( '1' === $old_option_value ) { |
|
| 897 | + if ('1' === $old_option_value) { |
|
| 898 | 898 | $old_option_value = 'yes'; |
| 899 | - } elseif ( '0' === $old_option_value ) { |
|
| 899 | + } elseif ('0' === $old_option_value) { |
|
| 900 | 900 | $old_option_value = 'no'; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | - update_option( $new_option, $old_option_value ); |
|
| 904 | - if ( $new_option !== $old_option ) { |
|
| 905 | - delete_option( $old_option ); |
|
| 903 | + update_option($new_option, $old_option_value); |
|
| 904 | + if ($new_option !== $old_option) { |
|
| 905 | + delete_option($old_option); |
|
| 906 | 906 | } |
| 907 | 907 | } |
| 908 | 908 | } |
@@ -930,33 +930,33 @@ discard block |
||
| 930 | 930 | ), |
| 931 | 931 | ); |
| 932 | 932 | |
| 933 | - foreach ( $taxonomies as $taxonomy => $terms ) { |
|
| 934 | - foreach ( $terms as $term ) { |
|
| 935 | - if ( ! get_term_by( 'name', $term, $taxonomy ) ) { // @codingStandardsIgnoreLine. |
|
| 936 | - wp_insert_term( $term, $taxonomy ); |
|
| 933 | + foreach ($taxonomies as $taxonomy => $terms) { |
|
| 934 | + foreach ($terms as $term) { |
|
| 935 | + if (!get_term_by('name', $term, $taxonomy)) { // @codingStandardsIgnoreLine. |
|
| 936 | + wp_insert_term($term, $taxonomy); |
|
| 937 | 937 | } |
| 938 | 938 | } |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - $woocommerce_default_category = (int) get_option( 'default_product_cat', 0 ); |
|
| 941 | + $woocommerce_default_category = (int) get_option('default_product_cat', 0); |
|
| 942 | 942 | |
| 943 | - if ( ! $woocommerce_default_category || ! term_exists( $woocommerce_default_category, 'product_cat' ) ) { |
|
| 943 | + if (!$woocommerce_default_category || !term_exists($woocommerce_default_category, 'product_cat')) { |
|
| 944 | 944 | $default_product_cat_id = 0; |
| 945 | - $default_product_cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug', 'woocommerce' ) ); |
|
| 946 | - $default_product_cat = get_term_by( 'slug', $default_product_cat_slug, 'product_cat' ); // @codingStandardsIgnoreLine. |
|
| 945 | + $default_product_cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug', 'woocommerce')); |
|
| 946 | + $default_product_cat = get_term_by('slug', $default_product_cat_slug, 'product_cat'); // @codingStandardsIgnoreLine. |
|
| 947 | 947 | |
| 948 | - if ( $default_product_cat ) { |
|
| 949 | - $default_product_cat_id = absint( $default_product_cat->term_taxonomy_id ); |
|
| 948 | + if ($default_product_cat) { |
|
| 949 | + $default_product_cat_id = absint($default_product_cat->term_taxonomy_id); |
|
| 950 | 950 | } else { |
| 951 | - $result = wp_insert_term( _x( 'Uncategorized', 'Default category slug', 'woocommerce' ), 'product_cat', array( 'slug' => $default_product_cat_slug ) ); |
|
| 951 | + $result = wp_insert_term(_x('Uncategorized', 'Default category slug', 'woocommerce'), 'product_cat', array('slug' => $default_product_cat_slug)); |
|
| 952 | 952 | |
| 953 | - if ( ! is_wp_error( $result ) && ! empty( $result['term_taxonomy_id'] ) ) { |
|
| 954 | - $default_product_cat_id = absint( $result['term_taxonomy_id'] ); |
|
| 953 | + if (!is_wp_error($result) && !empty($result['term_taxonomy_id'])) { |
|
| 954 | + $default_product_cat_id = absint($result['term_taxonomy_id']); |
|
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | - if ( $default_product_cat_id ) { |
|
| 959 | - update_option( 'default_product_cat', $default_product_cat_id ); |
|
| 958 | + if ($default_product_cat_id) { |
|
| 959 | + update_option('default_product_cat', $default_product_cat_id); |
|
| 960 | 960 | } |
| 961 | 961 | } |
| 962 | 962 | } |
@@ -989,9 +989,9 @@ discard block |
||
| 989 | 989 | * Before updating with DBDELTA, remove any primary keys which could be |
| 990 | 990 | * modified due to schema updates. |
| 991 | 991 | */ |
| 992 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_downloadable_product_permissions';" ) ) { |
|
| 993 | - if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}woocommerce_downloadable_product_permissions` LIKE 'permission_id';" ) ) { |
|
| 994 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions DROP PRIMARY KEY, ADD `permission_id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT;" ); |
|
| 992 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_downloadable_product_permissions';")) { |
|
| 993 | + if (!$wpdb->get_var("SHOW COLUMNS FROM `{$wpdb->prefix}woocommerce_downloadable_product_permissions` LIKE 'permission_id';")) { |
|
| 994 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions DROP PRIMARY KEY, ADD `permission_id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT;"); |
|
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | |
@@ -1003,41 +1003,41 @@ discard block |
||
| 1003 | 1003 | * This query needs to run before dbDelta() as this WP function is not able to handle primary key changes |
| 1004 | 1004 | * (see https://github.com/woocommerce/woocommerce/issues/21534 and https://core.trac.wordpress.org/ticket/40357). |
| 1005 | 1005 | */ |
| 1006 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_sessions'" ) ) { |
|
| 1007 | - if ( ! $wpdb->get_var( "SHOW KEYS FROM {$wpdb->prefix}woocommerce_sessions WHERE Key_name = 'PRIMARY' AND Column_name = 'session_id'" ) ) { |
|
| 1006 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_sessions'")) { |
|
| 1007 | + if (!$wpdb->get_var("SHOW KEYS FROM {$wpdb->prefix}woocommerce_sessions WHERE Key_name = 'PRIMARY' AND Column_name = 'session_id'")) { |
|
| 1008 | 1008 | $wpdb->query( |
| 1009 | 1009 | "ALTER TABLE `{$wpdb->prefix}woocommerce_sessions` DROP PRIMARY KEY, DROP KEY `session_id`, ADD PRIMARY KEY(`session_id`), ADD UNIQUE KEY(`session_key`)" |
| 1010 | 1010 | ); |
| 1011 | 1011 | } |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | - dbDelta( self::get_schema() ); |
|
| 1014 | + dbDelta(self::get_schema()); |
|
| 1015 | 1015 | |
| 1016 | - $index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->comments} WHERE column_name = 'comment_type' and key_name = 'woo_idx_comment_type'" ); |
|
| 1016 | + $index_exists = $wpdb->get_row("SHOW INDEX FROM {$wpdb->comments} WHERE column_name = 'comment_type' and key_name = 'woo_idx_comment_type'"); |
|
| 1017 | 1017 | |
| 1018 | - if ( is_null( $index_exists ) ) { |
|
| 1018 | + if (is_null($index_exists)) { |
|
| 1019 | 1019 | // Add an index to the field comment_type to improve the response time of the query |
| 1020 | 1020 | // used by WC_Comments::wp_count_comments() to get the number of comments by type. |
| 1021 | - $wpdb->query( "ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)" ); |
|
| 1021 | + $wpdb->query("ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)"); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | // Get tables data types and check it matches before adding constraint. |
| 1025 | - $download_log_columns = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}wc_download_log WHERE Field = 'permission_id'", ARRAY_A ); |
|
| 1025 | + $download_log_columns = $wpdb->get_results("SHOW COLUMNS FROM {$wpdb->prefix}wc_download_log WHERE Field = 'permission_id'", ARRAY_A); |
|
| 1026 | 1026 | $download_log_column_type = ''; |
| 1027 | - if ( isset( $download_log_columns[0]['Type'] ) ) { |
|
| 1027 | + if (isset($download_log_columns[0]['Type'])) { |
|
| 1028 | 1028 | $download_log_column_type = $download_log_columns[0]['Type']; |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | - $download_permissions_columns = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE Field = 'permission_id'", ARRAY_A ); |
|
| 1031 | + $download_permissions_columns = $wpdb->get_results("SHOW COLUMNS FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE Field = 'permission_id'", ARRAY_A); |
|
| 1032 | 1032 | $download_permissions_column_type = ''; |
| 1033 | - if ( isset( $download_permissions_columns[0]['Type'] ) ) { |
|
| 1033 | + if (isset($download_permissions_columns[0]['Type'])) { |
|
| 1034 | 1034 | $download_permissions_column_type = $download_permissions_columns[0]['Type']; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | // Add constraint to download logs if the columns matches. |
| 1038 | - if ( ! empty( $download_permissions_column_type ) && ! empty( $download_log_column_type ) && $download_permissions_column_type === $download_log_column_type ) { |
|
| 1039 | - $fk_result = $wpdb->get_row( "SHOW CREATE TABLE {$wpdb->prefix}wc_download_log" ); |
|
| 1040 | - if ( false === strpos( $fk_result->{'Create Table'}, "fk_{$wpdb->prefix}wc_download_log_permission_id" ) ) { |
|
| 1038 | + if (!empty($download_permissions_column_type) && !empty($download_log_column_type) && $download_permissions_column_type === $download_log_column_type) { |
|
| 1039 | + $fk_result = $wpdb->get_row("SHOW CREATE TABLE {$wpdb->prefix}wc_download_log"); |
|
| 1040 | + if (false === strpos($fk_result->{'Create Table'}, "fk_{$wpdb->prefix}wc_download_log_permission_id")) { |
|
| 1041 | 1041 | $wpdb->query( |
| 1042 | 1042 | "ALTER TABLE `{$wpdb->prefix}wc_download_log` |
| 1043 | 1043 | ADD CONSTRAINT `fk_{$wpdb->prefix}wc_download_log_permission_id` |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | // Clear table caches. |
| 1051 | - delete_transient( 'wc_attribute_taxonomies' ); |
|
| 1051 | + delete_transient('wc_attribute_taxonomies'); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | /** |
@@ -1072,7 +1072,7 @@ discard block |
||
| 1072 | 1072 | |
| 1073 | 1073 | $collate = ''; |
| 1074 | 1074 | |
| 1075 | - if ( $wpdb->has_cap( 'collation' ) ) { |
|
| 1075 | + if ($wpdb->has_cap('collation')) { |
|
| 1076 | 1076 | $collate = $wpdb->get_charset_collate(); |
| 1077 | 1077 | } |
| 1078 | 1078 | |
@@ -1083,7 +1083,7 @@ discard block |
||
| 1083 | 1083 | */ |
| 1084 | 1084 | $max_index_length = 191; |
| 1085 | 1085 | |
| 1086 | - $product_attributes_lookup_table_creation_sql = wc_get_container()->get( DataRegenerator::class )->get_table_creation_sql(); |
|
| 1086 | + $product_attributes_lookup_table_creation_sql = wc_get_container()->get(DataRegenerator::class)->get_table_creation_sql(); |
|
| 1087 | 1087 | |
| 1088 | 1088 | $tables = " |
| 1089 | 1089 | CREATE TABLE {$wpdb->prefix}woocommerce_sessions ( |
@@ -1462,7 +1462,7 @@ discard block |
||
| 1462 | 1462 | "{$wpdb->prefix}woocommerce_tax_rates", |
| 1463 | 1463 | "{$wpdb->prefix}wc_reserved_stock", |
| 1464 | 1464 | "{$wpdb->prefix}wc_rate_limits", |
| 1465 | - wc_get_container()->get( DataRegenerator::class )->get_lookup_table_name(), |
|
| 1465 | + wc_get_container()->get(DataRegenerator::class)->get_lookup_table_name(), |
|
| 1466 | 1466 | |
| 1467 | 1467 | // WCA Tables. |
| 1468 | 1468 | "{$wpdb->prefix}wc_order_stats", |
@@ -1483,7 +1483,7 @@ discard block |
||
| 1483 | 1483 | * @param array $tables An array of WooCommerce-specific database table names. |
| 1484 | 1484 | * @since 3.4.0 |
| 1485 | 1485 | */ |
| 1486 | - $tables = apply_filters( 'woocommerce_install_get_tables', $tables ); |
|
| 1486 | + $tables = apply_filters('woocommerce_install_get_tables', $tables); |
|
| 1487 | 1487 | |
| 1488 | 1488 | return $tables; |
| 1489 | 1489 | } |
@@ -1498,8 +1498,8 @@ discard block |
||
| 1498 | 1498 | |
| 1499 | 1499 | $tables = self::get_tables(); |
| 1500 | 1500 | |
| 1501 | - foreach ( $tables as $table ) { |
|
| 1502 | - $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 1501 | + foreach ($tables as $table) { |
|
| 1502 | + $wpdb->query("DROP TABLE IF EXISTS {$table}"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 1503 | 1503 | } |
| 1504 | 1504 | } |
| 1505 | 1505 | |
@@ -1510,8 +1510,8 @@ discard block |
||
| 1510 | 1510 | * |
| 1511 | 1511 | * @return string[] |
| 1512 | 1512 | */ |
| 1513 | - public static function wpmu_drop_tables( $tables ) { |
|
| 1514 | - return array_merge( $tables, self::get_tables() ); |
|
| 1513 | + public static function wpmu_drop_tables($tables) { |
|
| 1514 | + return array_merge($tables, self::get_tables()); |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | /** |
@@ -1520,19 +1520,19 @@ discard block |
||
| 1520 | 1520 | public static function create_roles() { |
| 1521 | 1521 | global $wp_roles; |
| 1522 | 1522 | |
| 1523 | - if ( ! class_exists( 'WP_Roles' ) ) { |
|
| 1523 | + if (!class_exists('WP_Roles')) { |
|
| 1524 | 1524 | return; |
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | - if ( ! isset( $wp_roles ) ) { |
|
| 1527 | + if (!isset($wp_roles)) { |
|
| 1528 | 1528 | $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | // Dummy gettext calls to get strings in the catalog. |
| 1532 | 1532 | /* translators: user role */ |
| 1533 | - _x( 'Customer', 'User role', 'woocommerce' ); |
|
| 1533 | + _x('Customer', 'User role', 'woocommerce'); |
|
| 1534 | 1534 | /* translators: user role */ |
| 1535 | - _x( 'Shop manager', 'User role', 'woocommerce' ); |
|
| 1535 | + _x('Shop manager', 'User role', 'woocommerce'); |
|
| 1536 | 1536 | |
| 1537 | 1537 | // Customer role. |
| 1538 | 1538 | add_role( |
@@ -1592,10 +1592,10 @@ discard block |
||
| 1592 | 1592 | |
| 1593 | 1593 | $capabilities = self::get_core_capabilities(); |
| 1594 | 1594 | |
| 1595 | - foreach ( $capabilities as $cap_group ) { |
|
| 1596 | - foreach ( $cap_group as $cap ) { |
|
| 1597 | - $wp_roles->add_cap( 'shop_manager', $cap ); |
|
| 1598 | - $wp_roles->add_cap( 'administrator', $cap ); |
|
| 1595 | + foreach ($capabilities as $cap_group) { |
|
| 1596 | + foreach ($cap_group as $cap) { |
|
| 1597 | + $wp_roles->add_cap('shop_manager', $cap); |
|
| 1598 | + $wp_roles->add_cap('administrator', $cap); |
|
| 1599 | 1599 | } |
| 1600 | 1600 | } |
| 1601 | 1601 | } |
@@ -1613,11 +1613,11 @@ discard block |
||
| 1613 | 1613 | 'view_woocommerce_reports', |
| 1614 | 1614 | ); |
| 1615 | 1615 | |
| 1616 | - $capability_types = array( 'product', 'shop_order', 'shop_coupon' ); |
|
| 1616 | + $capability_types = array('product', 'shop_order', 'shop_coupon'); |
|
| 1617 | 1617 | |
| 1618 | - foreach ( $capability_types as $capability_type ) { |
|
| 1618 | + foreach ($capability_types as $capability_type) { |
|
| 1619 | 1619 | |
| 1620 | - $capabilities[ $capability_type ] = array( |
|
| 1620 | + $capabilities[$capability_type] = array( |
|
| 1621 | 1621 | // Post type. |
| 1622 | 1622 | "edit_{$capability_type}", |
| 1623 | 1623 | "read_{$capability_type}", |
@@ -1650,25 +1650,25 @@ discard block |
||
| 1650 | 1650 | public static function remove_roles() { |
| 1651 | 1651 | global $wp_roles; |
| 1652 | 1652 | |
| 1653 | - if ( ! class_exists( 'WP_Roles' ) ) { |
|
| 1653 | + if (!class_exists('WP_Roles')) { |
|
| 1654 | 1654 | return; |
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | - if ( ! isset( $wp_roles ) ) { |
|
| 1657 | + if (!isset($wp_roles)) { |
|
| 1658 | 1658 | $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | $capabilities = self::get_core_capabilities(); |
| 1662 | 1662 | |
| 1663 | - foreach ( $capabilities as $cap_group ) { |
|
| 1664 | - foreach ( $cap_group as $cap ) { |
|
| 1665 | - $wp_roles->remove_cap( 'shop_manager', $cap ); |
|
| 1666 | - $wp_roles->remove_cap( 'administrator', $cap ); |
|
| 1663 | + foreach ($capabilities as $cap_group) { |
|
| 1664 | + foreach ($cap_group as $cap) { |
|
| 1665 | + $wp_roles->remove_cap('shop_manager', $cap); |
|
| 1666 | + $wp_roles->remove_cap('administrator', $cap); |
|
| 1667 | 1667 | } |
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | - remove_role( 'customer' ); |
|
| 1671 | - remove_role( 'shop_manager' ); |
|
| 1670 | + remove_role('customer'); |
|
| 1671 | + remove_role('shop_manager'); |
|
| 1672 | 1672 | } |
| 1673 | 1673 | |
| 1674 | 1674 | /** |
@@ -1680,13 +1680,13 @@ discard block |
||
| 1680 | 1680 | * |
| 1681 | 1681 | * @since 3.2.0 |
| 1682 | 1682 | */ |
| 1683 | - if ( apply_filters( 'woocommerce_install_skip_create_files', false ) ) { |
|
| 1683 | + if (apply_filters('woocommerce_install_skip_create_files', false)) { |
|
| 1684 | 1684 | return; |
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | 1687 | // Install files and folders for uploading files and prevent hotlinking. |
| 1688 | 1688 | $upload_dir = wp_get_upload_dir(); |
| 1689 | - $download_method = get_option( 'woocommerce_file_download_method', 'force' ); |
|
| 1689 | + $download_method = get_option('woocommerce_file_download_method', 'force'); |
|
| 1690 | 1690 | |
| 1691 | 1691 | $files = array( |
| 1692 | 1692 | array( |
@@ -1711,12 +1711,12 @@ discard block |
||
| 1711 | 1711 | ), |
| 1712 | 1712 | ); |
| 1713 | 1713 | |
| 1714 | - foreach ( $files as $file ) { |
|
| 1715 | - if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) { |
|
| 1716 | - $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'wb' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen |
|
| 1717 | - if ( $file_handle ) { |
|
| 1718 | - fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite |
|
| 1719 | - fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose |
|
| 1714 | + foreach ($files as $file) { |
|
| 1715 | + if (wp_mkdir_p($file['base']) && !file_exists(trailingslashit($file['base']) . $file['file'])) { |
|
| 1716 | + $file_handle = @fopen(trailingslashit($file['base']) . $file['file'], 'wb'); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen |
|
| 1717 | + if ($file_handle) { |
|
| 1718 | + fwrite($file_handle, $file['content']); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite |
|
| 1719 | + fclose($file_handle); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose |
|
| 1720 | 1720 | } |
| 1721 | 1721 | } |
| 1722 | 1722 | } |
@@ -1731,13 +1731,13 @@ discard block |
||
| 1731 | 1731 | * @since 3.5.0 |
| 1732 | 1732 | */ |
| 1733 | 1733 | private static function create_placeholder_image() { |
| 1734 | - $placeholder_image = get_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1734 | + $placeholder_image = get_option('woocommerce_placeholder_image', 0); |
|
| 1735 | 1735 | |
| 1736 | 1736 | // Validate current setting if set. If set, return. |
| 1737 | - if ( ! empty( $placeholder_image ) ) { |
|
| 1738 | - if ( ! is_numeric( $placeholder_image ) ) { |
|
| 1737 | + if (!empty($placeholder_image)) { |
|
| 1738 | + if (!is_numeric($placeholder_image)) { |
|
| 1739 | 1739 | return; |
| 1740 | - } elseif ( $placeholder_image && wp_attachment_is_image( $placeholder_image ) ) { |
|
| 1740 | + } elseif ($placeholder_image && wp_attachment_is_image($placeholder_image)) { |
|
| 1741 | 1741 | return; |
| 1742 | 1742 | } |
| 1743 | 1743 | } |
@@ -1746,38 +1746,38 @@ discard block |
||
| 1746 | 1746 | $source = WC()->plugin_path() . '/assets/images/placeholder-attachment.png'; |
| 1747 | 1747 | $filename = $upload_dir['basedir'] . '/woocommerce-placeholder.png'; |
| 1748 | 1748 | |
| 1749 | - if ( ! file_exists( $filename ) ) { |
|
| 1750 | - copy( $source, $filename ); // @codingStandardsIgnoreLine. |
|
| 1749 | + if (!file_exists($filename)) { |
|
| 1750 | + copy($source, $filename); // @codingStandardsIgnoreLine. |
|
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | - if ( ! file_exists( $filename ) ) { |
|
| 1754 | - update_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1753 | + if (!file_exists($filename)) { |
|
| 1754 | + update_option('woocommerce_placeholder_image', 0); |
|
| 1755 | 1755 | return; |
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | - $filetype = wp_check_filetype( basename( $filename ), null ); |
|
| 1758 | + $filetype = wp_check_filetype(basename($filename), null); |
|
| 1759 | 1759 | $attachment = array( |
| 1760 | - 'guid' => $upload_dir['url'] . '/' . basename( $filename ), |
|
| 1760 | + 'guid' => $upload_dir['url'] . '/' . basename($filename), |
|
| 1761 | 1761 | 'post_mime_type' => $filetype['type'], |
| 1762 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 1762 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
| 1763 | 1763 | 'post_content' => '', |
| 1764 | 1764 | 'post_status' => 'inherit', |
| 1765 | 1765 | ); |
| 1766 | 1766 | |
| 1767 | - $attach_id = wp_insert_attachment( $attachment, $filename ); |
|
| 1768 | - if ( is_wp_error( $attach_id ) ) { |
|
| 1769 | - update_option( 'woocommerce_placeholder_image', 0 ); |
|
| 1767 | + $attach_id = wp_insert_attachment($attachment, $filename); |
|
| 1768 | + if (is_wp_error($attach_id)) { |
|
| 1769 | + update_option('woocommerce_placeholder_image', 0); |
|
| 1770 | 1770 | return; |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | - update_option( 'woocommerce_placeholder_image', $attach_id ); |
|
| 1773 | + update_option('woocommerce_placeholder_image', $attach_id); |
|
| 1774 | 1774 | |
| 1775 | 1775 | // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. |
| 1776 | 1776 | require_once ABSPATH . 'wp-admin/includes/image.php'; |
| 1777 | 1777 | |
| 1778 | 1778 | // Generate the metadata for the attachment, and update the database record. |
| 1779 | - $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); |
|
| 1780 | - wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 1779 | + $attach_data = wp_generate_attachment_metadata($attach_id, $filename); |
|
| 1780 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | /** |
@@ -1787,12 +1787,12 @@ discard block |
||
| 1787 | 1787 | * |
| 1788 | 1788 | * @return array |
| 1789 | 1789 | */ |
| 1790 | - public static function plugin_action_links( $links ) { |
|
| 1790 | + public static function plugin_action_links($links) { |
|
| 1791 | 1791 | $action_links = array( |
| 1792 | - 'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings' ) . '" aria-label="' . esc_attr__( 'View WooCommerce settings', 'woocommerce' ) . '">' . esc_html__( 'Settings', 'woocommerce' ) . '</a>', |
|
| 1792 | + 'settings' => '<a href="' . admin_url('admin.php?page=wc-settings') . '" aria-label="' . esc_attr__('View WooCommerce settings', 'woocommerce') . '">' . esc_html__('Settings', 'woocommerce') . '</a>', |
|
| 1793 | 1793 | ); |
| 1794 | 1794 | |
| 1795 | - return array_merge( $action_links, $links ); |
|
| 1795 | + return array_merge($action_links, $links); |
|
| 1796 | 1796 | } |
| 1797 | 1797 | |
| 1798 | 1798 | /** |
@@ -1803,8 +1803,8 @@ discard block |
||
| 1803 | 1803 | * |
| 1804 | 1804 | * @return array |
| 1805 | 1805 | */ |
| 1806 | - public static function plugin_row_meta( $links, $file ) { |
|
| 1807 | - if ( WC_PLUGIN_BASENAME !== $file ) { |
|
| 1806 | + public static function plugin_row_meta($links, $file) { |
|
| 1807 | + if (WC_PLUGIN_BASENAME !== $file) { |
|
| 1808 | 1808 | return $links; |
| 1809 | 1809 | } |
| 1810 | 1810 | |
@@ -1813,40 +1813,40 @@ discard block |
||
| 1813 | 1813 | * |
| 1814 | 1814 | * @since 2.7.0 |
| 1815 | 1815 | */ |
| 1816 | - $docs_url = apply_filters( 'woocommerce_docs_url', 'https://docs.woocommerce.com/documentation/plugins/woocommerce/' ); |
|
| 1816 | + $docs_url = apply_filters('woocommerce_docs_url', 'https://docs.woocommerce.com/documentation/plugins/woocommerce/'); |
|
| 1817 | 1817 | |
| 1818 | 1818 | /** |
| 1819 | 1819 | * The WooCommerce API documentation URL. |
| 1820 | 1820 | * |
| 1821 | 1821 | * @since 2.2.0 |
| 1822 | 1822 | */ |
| 1823 | - $api_docs_url = apply_filters( 'woocommerce_apidocs_url', 'https://docs.woocommerce.com/wc-apidocs/' ); |
|
| 1823 | + $api_docs_url = apply_filters('woocommerce_apidocs_url', 'https://docs.woocommerce.com/wc-apidocs/'); |
|
| 1824 | 1824 | |
| 1825 | 1825 | /** |
| 1826 | 1826 | * The community WooCommerce support URL. |
| 1827 | 1827 | * |
| 1828 | 1828 | * @since 2.2.0 |
| 1829 | 1829 | */ |
| 1830 | - $community_support_url = apply_filters( 'woocommerce_community_support_url', 'https://wordpress.org/support/plugin/woocommerce/' ); |
|
| 1830 | + $community_support_url = apply_filters('woocommerce_community_support_url', 'https://wordpress.org/support/plugin/woocommerce/'); |
|
| 1831 | 1831 | |
| 1832 | 1832 | /** |
| 1833 | 1833 | * The premium support URL. |
| 1834 | 1834 | * |
| 1835 | 1835 | * @since |
| 1836 | 1836 | */ |
| 1837 | - $support_url = apply_filters( 'woocommerce_support_url', 'https://woocommerce.com/my-account/create-a-ticket/' ); |
|
| 1837 | + $support_url = apply_filters('woocommerce_support_url', 'https://woocommerce.com/my-account/create-a-ticket/'); |
|
| 1838 | 1838 | |
| 1839 | 1839 | $row_meta = array( |
| 1840 | - 'docs' => '<a href="' . esc_url( $docs_url ) . '" aria-label="' . esc_attr__( 'View WooCommerce documentation', 'woocommerce' ) . '">' . esc_html__( 'Docs', 'woocommerce' ) . '</a>', |
|
| 1841 | - 'apidocs' => '<a href="' . esc_url( $api_docs_url ) . '" aria-label="' . esc_attr__( 'View WooCommerce API docs', 'woocommerce' ) . '">' . esc_html__( 'API docs', 'woocommerce' ) . '</a>', |
|
| 1842 | - 'support' => '<a href="' . esc_url( $community_support_url ) . '" aria-label="' . esc_attr__( 'Visit community forums', 'woocommerce' ) . '">' . esc_html__( 'Community support', 'woocommerce' ) . '</a>', |
|
| 1840 | + 'docs' => '<a href="' . esc_url($docs_url) . '" aria-label="' . esc_attr__('View WooCommerce documentation', 'woocommerce') . '">' . esc_html__('Docs', 'woocommerce') . '</a>', |
|
| 1841 | + 'apidocs' => '<a href="' . esc_url($api_docs_url) . '" aria-label="' . esc_attr__('View WooCommerce API docs', 'woocommerce') . '">' . esc_html__('API docs', 'woocommerce') . '</a>', |
|
| 1842 | + 'support' => '<a href="' . esc_url($community_support_url) . '" aria-label="' . esc_attr__('Visit community forums', 'woocommerce') . '">' . esc_html__('Community support', 'woocommerce') . '</a>', |
|
| 1843 | 1843 | ); |
| 1844 | 1844 | |
| 1845 | - if ( WCConnectionHelper::is_connected() ) { |
|
| 1846 | - $row_meta['premium_support'] = '<a href="' . esc_url( $support_url ) . '" aria-label="' . esc_attr__( 'Visit premium customer support', 'woocommerce' ) . '">' . esc_html__( 'Premium support', 'woocommerce' ) . '</a>'; |
|
| 1845 | + if (WCConnectionHelper::is_connected()) { |
|
| 1846 | + $row_meta['premium_support'] = '<a href="' . esc_url($support_url) . '" aria-label="' . esc_attr__('Visit premium customer support', 'woocommerce') . '">' . esc_html__('Premium support', 'woocommerce') . '</a>'; |
|
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | - return array_merge( $links, $row_meta ); |
|
| 1849 | + return array_merge($links, $row_meta); |
|
| 1850 | 1850 | } |
| 1851 | 1851 | |
| 1852 | 1852 | /** |
@@ -1855,10 +1855,10 @@ discard block |
||
| 1855 | 1855 | * @param array $plugins Associative array of plugin files to paths. |
| 1856 | 1856 | * @param string $key Plugin relative path. Example: woocommerce/woocommerce.php. |
| 1857 | 1857 | */ |
| 1858 | - private static function associate_plugin_file( $plugins, $key ) { |
|
| 1859 | - $path = explode( '/', $key ); |
|
| 1860 | - $filename = end( $path ); |
|
| 1861 | - $plugins[ $filename ] = $key; |
|
| 1858 | + private static function associate_plugin_file($plugins, $key) { |
|
| 1859 | + $path = explode('/', $key); |
|
| 1860 | + $filename = end($path); |
|
| 1861 | + $plugins[$filename] = $key; |
|
| 1862 | 1862 | return $plugins; |
| 1863 | 1863 | } |
| 1864 | 1864 | |
@@ -1872,11 +1872,11 @@ discard block |
||
| 1872 | 1872 | * @throws Exception If unable to proceed with plugin installation. |
| 1873 | 1873 | * @since 2.6.0 |
| 1874 | 1874 | */ |
| 1875 | - public static function background_installer( $plugin_to_install_id, $plugin_to_install ) { |
|
| 1875 | + public static function background_installer($plugin_to_install_id, $plugin_to_install) { |
|
| 1876 | 1876 | // Explicitly clear the event. |
| 1877 | 1877 | $args = func_get_args(); |
| 1878 | 1878 | |
| 1879 | - if ( ! empty( $plugin_to_install['repo-slug'] ) ) { |
|
| 1879 | + if (!empty($plugin_to_install['repo-slug'])) { |
|
| 1880 | 1880 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 1881 | 1881 | require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 1882 | 1882 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
@@ -1885,24 +1885,24 @@ discard block |
||
| 1885 | 1885 | WP_Filesystem(); |
| 1886 | 1886 | |
| 1887 | 1887 | $skin = new Automatic_Upgrader_Skin(); |
| 1888 | - $upgrader = new WP_Upgrader( $skin ); |
|
| 1889 | - $installed_plugins = array_reduce( array_keys( get_plugins() ), array( __CLASS__, 'associate_plugin_file' ) ); |
|
| 1890 | - if ( empty( $installed_plugins ) ) { |
|
| 1888 | + $upgrader = new WP_Upgrader($skin); |
|
| 1889 | + $installed_plugins = array_reduce(array_keys(get_plugins()), array(__CLASS__, 'associate_plugin_file')); |
|
| 1890 | + if (empty($installed_plugins)) { |
|
| 1891 | 1891 | $installed_plugins = array(); |
| 1892 | 1892 | } |
| 1893 | 1893 | $plugin_slug = $plugin_to_install['repo-slug']; |
| 1894 | - $plugin_file = isset( $plugin_to_install['file'] ) ? $plugin_to_install['file'] : $plugin_slug . '.php'; |
|
| 1894 | + $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php'; |
|
| 1895 | 1895 | $installed = false; |
| 1896 | 1896 | $activate = false; |
| 1897 | 1897 | |
| 1898 | 1898 | // See if the plugin is installed already. |
| 1899 | - if ( isset( $installed_plugins[ $plugin_file ] ) ) { |
|
| 1899 | + if (isset($installed_plugins[$plugin_file])) { |
|
| 1900 | 1900 | $installed = true; |
| 1901 | - $activate = ! is_plugin_active( $installed_plugins[ $plugin_file ] ); |
|
| 1901 | + $activate = !is_plugin_active($installed_plugins[$plugin_file]); |
|
| 1902 | 1902 | } |
| 1903 | 1903 | |
| 1904 | 1904 | // Install this thing! |
| 1905 | - if ( ! $installed ) { |
|
| 1905 | + if (!$installed) { |
|
| 1906 | 1906 | // Suppress feedback. |
| 1907 | 1907 | ob_start(); |
| 1908 | 1908 | |
@@ -1929,21 +1929,21 @@ discard block |
||
| 1929 | 1929 | ) |
| 1930 | 1930 | ); |
| 1931 | 1931 | |
| 1932 | - if ( is_wp_error( $plugin_information ) ) { |
|
| 1933 | - throw new Exception( $plugin_information->get_error_message() ); |
|
| 1932 | + if (is_wp_error($plugin_information)) { |
|
| 1933 | + throw new Exception($plugin_information->get_error_message()); |
|
| 1934 | 1934 | } |
| 1935 | 1935 | |
| 1936 | 1936 | $package = $plugin_information->download_link; |
| 1937 | - $download = $upgrader->download_package( $package ); |
|
| 1937 | + $download = $upgrader->download_package($package); |
|
| 1938 | 1938 | |
| 1939 | - if ( is_wp_error( $download ) ) { |
|
| 1940 | - throw new Exception( $download->get_error_message() ); |
|
| 1939 | + if (is_wp_error($download)) { |
|
| 1940 | + throw new Exception($download->get_error_message()); |
|
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
| 1943 | + $working_dir = $upgrader->unpack_package($download, true); |
|
| 1944 | 1944 | |
| 1945 | - if ( is_wp_error( $working_dir ) ) { |
|
| 1946 | - throw new Exception( $working_dir->get_error_message() ); |
|
| 1945 | + if (is_wp_error($working_dir)) { |
|
| 1946 | + throw new Exception($working_dir->get_error_message()); |
|
| 1947 | 1947 | } |
| 1948 | 1948 | |
| 1949 | 1949 | $result = $upgrader->install_package( |
@@ -1960,21 +1960,21 @@ discard block |
||
| 1960 | 1960 | ) |
| 1961 | 1961 | ); |
| 1962 | 1962 | |
| 1963 | - if ( is_wp_error( $result ) ) { |
|
| 1964 | - throw new Exception( $result->get_error_message() ); |
|
| 1963 | + if (is_wp_error($result)) { |
|
| 1964 | + throw new Exception($result->get_error_message()); |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | $activate = true; |
| 1968 | 1968 | |
| 1969 | - } catch ( Exception $e ) { |
|
| 1969 | + } catch (Exception $e) { |
|
| 1970 | 1970 | WC_Admin_Notices::add_custom_notice( |
| 1971 | 1971 | $plugin_to_install_id . '_install_error', |
| 1972 | 1972 | sprintf( |
| 1973 | 1973 | // translators: 1: plugin name, 2: error message, 3: URL to install plugin manually. |
| 1974 | - __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ), |
|
| 1974 | + __('%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce'), |
|
| 1975 | 1975 | $plugin_to_install['name'], |
| 1976 | 1976 | $e->getMessage(), |
| 1977 | - esc_url( admin_url( 'index.php?wc-install-plugin-redirect=' . $plugin_slug ) ) |
|
| 1977 | + esc_url(admin_url('index.php?wc-install-plugin-redirect=' . $plugin_slug)) |
|
| 1978 | 1978 | ) |
| 1979 | 1979 | ); |
| 1980 | 1980 | } |
@@ -1986,22 +1986,22 @@ discard block |
||
| 1986 | 1986 | wp_clean_plugins_cache(); |
| 1987 | 1987 | |
| 1988 | 1988 | // Activate this thing. |
| 1989 | - if ( $activate ) { |
|
| 1989 | + if ($activate) { |
|
| 1990 | 1990 | try { |
| 1991 | - add_action( 'add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array( __CLASS__, 'remove_mailchimps_redirect' ), 10, 2 ); |
|
| 1992 | - $result = activate_plugin( $installed ? $installed_plugins[ $plugin_file ] : $plugin_slug . '/' . $plugin_file ); |
|
| 1991 | + add_action('add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array(__CLASS__, 'remove_mailchimps_redirect'), 10, 2); |
|
| 1992 | + $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file); |
|
| 1993 | 1993 | |
| 1994 | - if ( is_wp_error( $result ) ) { |
|
| 1995 | - throw new Exception( $result->get_error_message() ); |
|
| 1994 | + if (is_wp_error($result)) { |
|
| 1995 | + throw new Exception($result->get_error_message()); |
|
| 1996 | 1996 | } |
| 1997 | - } catch ( Exception $e ) { |
|
| 1997 | + } catch (Exception $e) { |
|
| 1998 | 1998 | WC_Admin_Notices::add_custom_notice( |
| 1999 | 1999 | $plugin_to_install_id . '_install_error', |
| 2000 | 2000 | sprintf( |
| 2001 | 2001 | // translators: 1: plugin name, 2: URL to WP plugin page. |
| 2002 | - __( '%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce' ), |
|
| 2002 | + __('%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce'), |
|
| 2003 | 2003 | $plugin_to_install['name'], |
| 2004 | - admin_url( 'plugins.php' ) |
|
| 2004 | + admin_url('plugins.php') |
|
| 2005 | 2005 | ) |
| 2006 | 2006 | ); |
| 2007 | 2007 | } |
@@ -2015,12 +2015,12 @@ discard block |
||
| 2015 | 2015 | * @param string $option Option name. |
| 2016 | 2016 | * @param string $value Option value. |
| 2017 | 2017 | */ |
| 2018 | - public static function remove_mailchimps_redirect( $option, $value ) { |
|
| 2018 | + public static function remove_mailchimps_redirect($option, $value) { |
|
| 2019 | 2019 | // Remove this action to prevent infinite looping. |
| 2020 | - remove_action( 'add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array( __CLASS__, 'remove_mailchimps_redirect' ) ); |
|
| 2020 | + remove_action('add_option_mailchimp_woocommerce_plugin_do_activation_redirect', array(__CLASS__, 'remove_mailchimps_redirect')); |
|
| 2021 | 2021 | |
| 2022 | 2022 | // Update redirect back to false. |
| 2023 | - update_option( 'mailchimp_woocommerce_plugin_do_activation_redirect', false ); |
|
| 2023 | + update_option('mailchimp_woocommerce_plugin_do_activation_redirect', false); |
|
| 2024 | 2024 | } |
| 2025 | 2025 | |
| 2026 | 2026 | /** |
@@ -2031,18 +2031,18 @@ discard block |
||
| 2031 | 2031 | * @throws Exception If unable to proceed with theme installation. |
| 2032 | 2032 | * @since 3.1.0 |
| 2033 | 2033 | */ |
| 2034 | - public static function theme_background_installer( $theme_slug ) { |
|
| 2034 | + public static function theme_background_installer($theme_slug) { |
|
| 2035 | 2035 | // Explicitly clear the event. |
| 2036 | 2036 | $args = func_get_args(); |
| 2037 | 2037 | |
| 2038 | - if ( ! empty( $theme_slug ) ) { |
|
| 2038 | + if (!empty($theme_slug)) { |
|
| 2039 | 2039 | // Suppress feedback. |
| 2040 | 2040 | ob_start(); |
| 2041 | 2041 | |
| 2042 | 2042 | try { |
| 2043 | - $theme = wp_get_theme( $theme_slug ); |
|
| 2043 | + $theme = wp_get_theme($theme_slug); |
|
| 2044 | 2044 | |
| 2045 | - if ( ! $theme->exists() ) { |
|
| 2045 | + if (!$theme->exists()) { |
|
| 2046 | 2046 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2047 | 2047 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 2048 | 2048 | include_once ABSPATH . 'wp-admin/includes/theme.php'; |
@@ -2050,35 +2050,35 @@ discard block |
||
| 2050 | 2050 | WP_Filesystem(); |
| 2051 | 2051 | |
| 2052 | 2052 | $skin = new Automatic_Upgrader_Skin(); |
| 2053 | - $upgrader = new Theme_Upgrader( $skin ); |
|
| 2053 | + $upgrader = new Theme_Upgrader($skin); |
|
| 2054 | 2054 | $api = themes_api( |
| 2055 | 2055 | 'theme_information', |
| 2056 | 2056 | array( |
| 2057 | 2057 | 'slug' => $theme_slug, |
| 2058 | - 'fields' => array( 'sections' => false ), |
|
| 2058 | + 'fields' => array('sections' => false), |
|
| 2059 | 2059 | ) |
| 2060 | 2060 | ); |
| 2061 | - $result = $upgrader->install( $api->download_link ); |
|
| 2062 | - |
|
| 2063 | - if ( is_wp_error( $result ) ) { |
|
| 2064 | - throw new Exception( $result->get_error_message() ); |
|
| 2065 | - } elseif ( is_wp_error( $skin->result ) ) { |
|
| 2066 | - throw new Exception( $skin->result->get_error_message() ); |
|
| 2067 | - } elseif ( is_null( $result ) ) { |
|
| 2068 | - throw new Exception( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
|
| 2061 | + $result = $upgrader->install($api->download_link); |
|
| 2062 | + |
|
| 2063 | + if (is_wp_error($result)) { |
|
| 2064 | + throw new Exception($result->get_error_message()); |
|
| 2065 | + } elseif (is_wp_error($skin->result)) { |
|
| 2066 | + throw new Exception($skin->result->get_error_message()); |
|
| 2067 | + } elseif (is_null($result)) { |
|
| 2068 | + throw new Exception('Unable to connect to the filesystem. Please confirm your credentials.'); |
|
| 2069 | 2069 | } |
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | - switch_theme( $theme_slug ); |
|
| 2073 | - } catch ( Exception $e ) { |
|
| 2072 | + switch_theme($theme_slug); |
|
| 2073 | + } catch (Exception $e) { |
|
| 2074 | 2074 | WC_Admin_Notices::add_custom_notice( |
| 2075 | 2075 | $theme_slug . '_install_error', |
| 2076 | 2076 | sprintf( |
| 2077 | 2077 | // translators: 1: theme slug, 2: error message, 3: URL to install theme manually. |
| 2078 | - __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ), |
|
| 2078 | + __('%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce'), |
|
| 2079 | 2079 | $theme_slug, |
| 2080 | 2080 | $e->getMessage(), |
| 2081 | - esc_url( admin_url( 'update.php?action=install-theme&theme=' . $theme_slug . '&_wpnonce=' . wp_create_nonce( 'install-theme_' . $theme_slug ) ) ) |
|
| 2081 | + esc_url(admin_url('update.php?action=install-theme&theme=' . $theme_slug . '&_wpnonce=' . wp_create_nonce('install-theme_' . $theme_slug))) |
|
| 2082 | 2082 | ) |
| 2083 | 2083 | ); |
| 2084 | 2084 | } |
@@ -2095,8 +2095,8 @@ discard block |
||
| 2095 | 2095 | */ |
| 2096 | 2096 | private static function set_paypal_standard_load_eligibility() { |
| 2097 | 2097 | // Initiating the payment gateways sets the flag. |
| 2098 | - if ( class_exists( 'WC_Gateway_Paypal' ) ) { |
|
| 2099 | - ( new WC_Gateway_Paypal() )->should_load(); |
|
| 2098 | + if (class_exists('WC_Gateway_Paypal')) { |
|
| 2099 | + (new WC_Gateway_Paypal())->should_load(); |
|
| 2100 | 2100 | } |
| 2101 | 2101 | } |
| 2102 | 2102 | |
@@ -2260,17 +2260,17 @@ discard block |
||
| 2260 | 2260 | * @return void |
| 2261 | 2261 | */ |
| 2262 | 2262 | public static function add_admin_note_after_page_created() { |
| 2263 | - if ( ! WC()->is_wc_admin_active() ) { |
|
| 2263 | + if (!WC()->is_wc_admin_active()) { |
|
| 2264 | 2264 | return; |
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | - $page_id = get_option( 'woocommerce_refund_returns_page_created', null ); |
|
| 2267 | + $page_id = get_option('woocommerce_refund_returns_page_created', null); |
|
| 2268 | 2268 | |
| 2269 | - if ( null === $page_id ) { |
|
| 2269 | + if (null === $page_id) { |
|
| 2270 | 2270 | return; |
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | - WC_Notes_Refund_Returns::possibly_add_note( $page_id ); |
|
| 2273 | + WC_Notes_Refund_Returns::possibly_add_note($page_id); |
|
| 2274 | 2274 | } |
| 2275 | 2275 | |
| 2276 | 2276 | /** |
@@ -2283,10 +2283,10 @@ discard block |
||
| 2283 | 2283 | * @param array $page_data The data of the page created. |
| 2284 | 2284 | * @return void |
| 2285 | 2285 | */ |
| 2286 | - public static function page_created( $page_id, $page_data ) { |
|
| 2287 | - if ( 'refund_returns' === $page_data['post_name'] ) { |
|
| 2288 | - delete_option( 'woocommerce_refund_returns_page_created' ); |
|
| 2289 | - add_option( 'woocommerce_refund_returns_page_created', $page_id, '', false ); |
|
| 2286 | + public static function page_created($page_id, $page_data) { |
|
| 2287 | + if ('refund_returns' === $page_data['post_name']) { |
|
| 2288 | + delete_option('woocommerce_refund_returns_page_created'); |
|
| 2289 | + add_option('woocommerce_refund_returns_page_created', $page_id, '', false); |
|
| 2290 | 2290 | } |
| 2291 | 2291 | } |
| 2292 | 2292 | } |