PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.3.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.3.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 / BlockLibrary / BlockCurrencyConversionSupportService.php
BlockCurrencyConversionSupportService.php
41 lines 1015 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\BlockLibrary;
4
5 /**
6 * Provide anchor support for blocks.
7 */
8 class BlockCurrencyConversionSupportService {
9 /**
10 * Register block support.
11 *
12 * @return void
13 */
14 public function bootstrap() {
15 add_filter( 'pre_render_block', [ $this, 'applySupport' ], 10, 2 );
16 }
17
18 /**
19 * Apply the currency conversion support.
20 *
21 * @param string $pre_render Pre-render content.
22 * @param array $parsed_block Parsed block.
23 *
24 * @return string
25 */
26 public function applySupport( $pre_render, $parsed_block ) {
27 // Get the block type object.
28 $block_type = \WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] );
29
30 // Should the block convert currency? (either true or false).
31 $support = $block_type->supports['currencyConversion'] ?? null;
32
33 if ( ! empty( $block_type ) && null !== $support ) {
34 \SureCart::currency()->convert( wp_validate_boolean( $support ) );
35 }
36
37 // Returning '' means "go ahead and render normally".
38 return $pre_render;
39 }
40 }
41