AddToCartButton
1 year ago
Address
5 months ago
BumpLineItem
3 months ago
Button
5 months ago
BuyButton
1 year ago
Card
5 months ago
Cart
5 months ago
CartBumpLineItem
5 months ago
CartCoupon
5 months ago
CartHeader
5 months ago
CartItems
5 months ago
CartMenuButton
5 months ago
CartMessage
5 months ago
CartSubmit
5 months ago
CartSubtotal
5 months ago
Checkbox
3 months ago
CheckoutErrors
5 months ago
CheckoutForm
3 months ago
CollapsibleRow
1 week ago
CollectionPage
5 months ago
Column
5 months ago
Columns
1 week ago
ConditionalForm
5 months ago
Confirmation
5 months ago
Coupon
3 months ago
CustomerDashboardButton
5 months ago
Dashboard
3 months ago
Divider
5 months ago
Donation
5 months ago
DonationAmount
5 months ago
Email
3 months ago
ExpressPayment
3 months ago
FirstName
3 months ago
Form
3 days ago
Heading
5 months ago
Input
5 months ago
InvoiceDetails
5 months ago
InvoiceDueDate
5 months ago
InvoiceMemo
5 months ago
InvoiceNumber
5 months ago
InvoiceReceiptDownload
5 months ago
LastName
3 months ago
LineItemShipping
5 months ago
LineItems
3 days ago
LogoutButton
5 months ago
Name
3 months ago
NameYourPrice
3 months ago
OrderBumps
3 weeks ago
OrderConfirmationCustomer
5 months ago
OrderConfirmationLineItems
5 months ago
Password
5 months ago
Payment
3 months ago
Phone
1 week ago
PriceChoice
5 months ago
PriceSelector
5 months ago
Product
1 week ago
ProductCollection
1 week ago
ProductCollectionDescription
1 week ago
ProductCollectionImage
1 week ago
ProductCollectionTitle
1 week ago
ProductDonation
5 months ago
ProductDonationAmount
5 months ago
ProductDonationAmounts
5 months ago
ProductDonationCustomAmount
5 months ago
ProductDonationPrices
5 months ago
ProductDonationRecurringPrices
5 months ago
ProductItem
1 week ago
ProductItemImage
1 week ago
ProductItemList
1 week ago
ProductItemPrice
1 week ago
ProductItemTitle
1 week ago
Radio
5 months ago
RadioGroup
5 months ago
SessionDetail
5 months ago
ShippingChoices
5 months ago
StoreLogo
3 months ago
Submit
2 months ago
Subtotal
3 months ago
Switch
5 months ago
TaxIdInput
5 months ago
TaxLineItem
3 months ago
Textarea
3 months ago
Total
3 months ago
Totals
3 months ago
TrialLineItem
3 months ago
Upsell
1 week ago
VariantPriceSelector
5 months ago
BaseBlock.php
3 years ago
BlockService.php
4 years ago
BlockServiceProvider.php
6 months ago
CartBlock.php
2 years ago
BlockServiceProvider.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Block Service Provider |
| 5 | */ |
| 6 | |
| 7 | namespace SureCartBlocks\Blocks; |
| 8 | |
| 9 | use SureCartBlocks\Blocks\BlockService; |
| 10 | use SureCartCore\ServiceProviders\ServiceProviderInterface; |
| 11 | |
| 12 | /** |
| 13 | * Block Service Provider Class |
| 14 | * Registers block service used throughout the plugin |
| 15 | * |
| 16 | * @author SureCart <andre@surecart.com> |
| 17 | * @since 1.0.0 |
| 18 | * @license GPL |
| 19 | */ |
| 20 | class BlockServiceProvider implements ServiceProviderInterface { |
| 21 | /** |
| 22 | * {@inheritDoc} |
| 23 | * |
| 24 | * @param \Pimple\Container $container Service Container. |
| 25 | */ |
| 26 | public function register( $container ) { |
| 27 | $app = $container[ SURECART_APPLICATION_KEY ]; |
| 28 | |
| 29 | $container['blocks'] = function () use ( $app ) { |
| 30 | return new BlockService( $app ); |
| 31 | }; |
| 32 | |
| 33 | $app->alias( 'blocks', 'blocks' ); |
| 34 | |
| 35 | $app->alias( |
| 36 | 'block', |
| 37 | function () use ( $app ) { |
| 38 | return call_user_func_array( [ $app->blocks(), 'render' ], func_get_args() ); |
| 39 | } |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * {@inheritDoc} |
| 45 | * |
| 46 | * @param \Pimple\Container $container Service Container. |
| 47 | * |
| 48 | * @return void |
| 49 | * |
| 50 | * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter |
| 51 | */ |
| 52 | public function bootstrap( $container ) { |
| 53 | // allow our web components in wp_kses contexts. |
| 54 | add_filter( 'wp_kses_allowed_html', [ $this, 'ksesComponents' ] ); |
| 55 | add_filter( |
| 56 | 'safe_style_css', |
| 57 | function ( $styles ) { |
| 58 | return array_merge( |
| 59 | [ |
| 60 | '--spacing', |
| 61 | '--font-weight', |
| 62 | '--line-height', |
| 63 | '--font-size', |
| 64 | '--color', |
| 65 | '--sc-pill-option-active-background-color', |
| 66 | '--sc-pill-option-active-text-color', |
| 67 | '--sc-pill-option-active-border-color', |
| 68 | ], |
| 69 | $styles |
| 70 | ); |
| 71 | } |
| 72 | ); |
| 73 | |
| 74 | // register our blocks. |
| 75 | $this->registerBlocks( $container ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Add iFrame to allowed wp_kses_post tags |
| 80 | * |
| 81 | * @param array $tags Allowed tags, attributes, and/or entities. |
| 82 | * |
| 83 | * @return array |
| 84 | */ |
| 85 | public function ksesComponents( $tags ) { |
| 86 | $components = json_decode( file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'app / src / Support / kses . json' ), true ); |
| 87 | |
| 88 | // add slot to defaults. |
| 89 | $tags['span']['slot'] = true; |
| 90 | $tags['div']['slot'] = true; |
| 91 | |
| 92 | return array_merge( $components, $tags ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Register blocks from config |
| 97 | * |
| 98 | * @param \Pimple\Container $container Service Container. |
| 99 | * |
| 100 | * @return void |
| 101 | */ |
| 102 | public function registerBlocks( $container ) { |
| 103 | $service = \SureCart::resolve( SURECART_CONFIG_KEY ); |
| 104 | if ( ! empty( $service['blocks'] ) ) { |
| 105 | foreach ( $service['blocks'] as $block ) { |
| 106 | ( new $block() )->register( $container ); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 |