PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.4.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.4.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Integrations / Bricks / BricksTemplateService.php
BricksTemplateService.php
60 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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