ProductTemplates
4 weeks ago
BlockRegistry.php
4 weeks ago
BlockTemplateUtils.php
4 weeks ago
Init.php
4 weeks ago
ProductFormsController.php
4 weeks ago
ProductTemplate.php
4 weeks ago
RedirectionController.php
4 weeks ago
Tracks.php
4 weeks ago
Tracks.php
57 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Product Block Editor |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor; |
| 7 | |
| 8 | /** |
| 9 | * Add tracks for the product block editor. |
| 10 | * |
| 11 | * @deprecated 10.9.0 Product editor extension APIs will be removed in WooCommerce 11.0. |
| 12 | */ |
| 13 | class Tracks { |
| 14 | |
| 15 | /** |
| 16 | * Initialize the tracks. |
| 17 | */ |
| 18 | public function init() { |
| 19 | add_filter( 'woocommerce_product_source', array( $this, 'add_product_source' ) ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Check if a URL is a product editor page. |
| 24 | * |
| 25 | * @param string $url Url to check. |
| 26 | * @return boolean |
| 27 | */ |
| 28 | protected function is_product_editor_page( $url ) { |
| 29 | $query_string = wp_parse_url( wp_get_referer(), PHP_URL_QUERY ); |
| 30 | parse_str( $query_string, $query ); |
| 31 | |
| 32 | if ( ! isset( $query['page'] ) || 'wc-admin' !== $query['page'] || ! isset( $query['path'] ) ) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | $path_pieces = explode( '/', $query['path'] ); |
| 37 | $route = $path_pieces[1]; |
| 38 | |
| 39 | return 'add-product' === $route || 'product' === $route; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Update the product source if we're on the product editor page. |
| 44 | * |
| 45 | * @param string $source Source of product. |
| 46 | * @return string |
| 47 | */ |
| 48 | public function add_product_source( $source ) { |
| 49 | if ( $this->is_product_editor_page( wp_get_referer() ) ) { |
| 50 | return 'product-block-editor-v1'; |
| 51 | } |
| 52 | |
| 53 | return $source; |
| 54 | } |
| 55 | |
| 56 | } |
| 57 |