AffiliateWP
3 years ago
Beaver
1 year ago
Bricks
1 year ago
BuddyBoss
3 years ago
Contracts
3 years ago
Elementor
1 year ago
LearnDash
3 years ago
LearnDashGroup
3 years ago
LifterLMS
3 years ago
MemberPress
3 years ago
ThriveAutomator
2 years ago
TutorLMS
1 year ago
User
3 years ago
AbstractIntegration.php
3 years ago
DiviServiceProvider.php
1 year ago
IntegrationService.php
2 years ago
DiviServiceProvider.php
69 lines
| 1 | <?php |
| 2 | namespace SureCart\Integrations; |
| 3 | |
| 4 | use SureCart\Migration\ProductPageWrapperService; |
| 5 | use SureCartCore\ServiceProviders\ServiceProviderInterface; |
| 6 | |
| 7 | /** |
| 8 | * Divi Service Provider |
| 9 | */ |
| 10 | class DiviServiceProvider implements ServiceProviderInterface { |
| 11 | /** |
| 12 | * {@inheritDoc} |
| 13 | * |
| 14 | * @param \Pimple\Container $container Service Container. |
| 15 | */ |
| 16 | public function register( $container ) { |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * {@inheritDoc} |
| 21 | * |
| 22 | * @param \Pimple\Container $container Service Container. |
| 23 | */ |
| 24 | public function bootstrap( $container ) { |
| 25 | add_filter( 'surecart/shortcode/render', [ $this, 'handleDiviShortcode' ], 10, 4 ); |
| 26 | add_filter( 'et_builder_render_layout', [ $this,'handleProductPageWrapper' ], 12 ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * If divi is active, only load the assets on the current request. |
| 31 | * |
| 32 | * @param string $content Content of Shortcode. |
| 33 | * @param string $atts Attributes of Shortcode. |
| 34 | * @param string $atts Shortcode Tag. |
| 35 | * @param string $form Form Object if present. |
| 36 | * |
| 37 | * @return string $content Content of Shortcode || The Shortcode itself. |
| 38 | */ |
| 39 | public function handleDiviShortcode( $content, $atts, $name, $form = false ) { |
| 40 | |
| 41 | if ( 'sc_form' !== $name || empty( $atts['id'] ) || empty( $_GET['et_pb_preview'] ) ) { |
| 42 | return $content; |
| 43 | } |
| 44 | |
| 45 | return '[sc_form id="' . $atts['id'] . '"]'; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Handle product page wrapper |
| 50 | * |
| 51 | * @param string $content The content. |
| 52 | * |
| 53 | * @return string |
| 54 | */ |
| 55 | public function handleProductPageWrapper( $content ) { |
| 56 | $original_post = get_post(); |
| 57 | global $post; |
| 58 | $post = get_queried_object(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 59 | setup_postdata( $post ); |
| 60 | |
| 61 | $output = ( new ProductPageWrapperService( $content ) )->wrap(); |
| 62 | |
| 63 | $post = $original_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 64 | setup_postdata( $original_post ); |
| 65 | |
| 66 | return $output; |
| 67 | } |
| 68 | } |
| 69 |