Concerns
4 months ago
Elements
2 months ago
scripts
1 year ago
BricksDynamicDataService.php
4 months ago
BricksElementsService.php
7 months ago
BricksServiceProvider.php
1 year ago
BricksTemplateService.php
8 months ago
BricksTemplateService.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\Bricks; |
| 4 | |
| 5 | /** |
| 6 | * Bricks template service. |
| 7 | */ |
| 8 | class BricksTemplateService { |
| 9 | /** |
| 10 | * Bootstrap the service. |
| 11 | * |
| 12 | * @return void |
| 13 | */ |
| 14 | public function bootstrap() { |
| 15 | add_filter( 'surecart/scripts/admin/product/data', [ $this, 'addBricksEditLink' ], 10, 2 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Add the bricks edit link to the data. |
| 20 | * |
| 21 | * @param array $data The data. |
| 22 | * |
| 23 | * @return array |
| 24 | */ |
| 25 | public function addBricksEditLink( $data ) { |
| 26 | if ( method_exists( \Bricks\Helpers::class, 'get_builder_edit_link' ) ) { |
| 27 | $product_id = $_GET['id'] ?? null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 28 | if ( empty( $product_id ) ) { |
| 29 | return $data; |
| 30 | } |
| 31 | |
| 32 | // Get the product by product id. |
| 33 | $product = sc_get_product( $product_id ); |
| 34 | if ( is_wp_error( $product ) ) { |
| 35 | return $data; |
| 36 | } |
| 37 | |
| 38 | // Get the post by product id. |
| 39 | $post = $product->post ?? null; |
| 40 | if ( empty( $post ) ) { |
| 41 | return $data; |
| 42 | } |
| 43 | |
| 44 | // Get the bricks edit link. |
| 45 | $data['bricks']['editLink'] = \Bricks\Helpers::get_builder_edit_link( $post->ID ); |
| 46 | } |
| 47 | |
| 48 | return $data; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Check if the current page is rendered with Bricks. |
| 53 | * |
| 54 | * @return bool |
| 55 | */ |
| 56 | public function isRenderedWithBricks(): bool { |
| 57 | return class_exists( '\Bricks\Helpers' ) && \Bricks\Helpers::render_with_bricks(); |
| 58 | } |
| 59 | } |
| 60 |