PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 1.0.5
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v1.0.5
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 / BlockServiceProvider.php

BlockServiceProvider.php in SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments 1.0.5, at app/src/BlockLibrary/BlockServiceProvider.php

135 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Block Service Provider
5 */
6
7 namespace SureCart\BlockLibrary;
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 $container['blocks.patterns'] = function () use ( $app ) {
34 return new BlockPatternsService( $app );
35 };
36
37 $app->alias( 'blocks', 'blocks' );
38
39 $app->alias(
40 'block',
41 function () use ( $app ) {
42 return call_user_func_array( [ $app->blocks(), 'render' ], func_get_args() );
43 }
44 );
45 }
46
47 /**
48 * {@inheritDoc}
49 *
50 * @param \Pimple\Container $container Service Container.
51 *
52 * @return void
53 *
54 * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter
55 */
56 public function bootstrap( $container ) {
57 $container['blocks.patterns']->bootstrap();
58 // allow design tokens in css.
59 add_filter(
60 'safe_style_css',
61 function( $styles ) {
62 return array_merge(
63 [
64 '--spacing',
65 '--font-weight',
66 '--line-height',
67 '--font-size',
68 '--text-align',
69 '--color',
70 '--sc-input-label-color',
71 ],
72 $styles
73 );
74 }
75 );
76 // allow our web components in wp_kses contexts.
77 add_filter( 'wp_kses_allowed_html', [ $this, 'ksesComponents' ] );
78 // register our blocks.
79 add_action( 'init', [ $this, 'registerBlocks' ] );
80 // register our category.
81 add_action( 'block_categories_all', [ $this, 'registerBlockCategories' ] );
82 }
83
84 /**
85 * Register our custom block category.
86 *
87 * @param array $categories Array of categories.
88 * @return array
89 */
90 public function registerBlockCategories( $categories ) {
91 return [
92 ...[
93 [
94 'slug' => 'surecart',
95 'title' => esc_html__( 'SureCart', 'surecart' ),
96 ],
97 ],
98 ...$categories,
99 ];
100 }
101
102 /**
103 * Add iFrame to allowed wp_kses_post tags
104 *
105 * @param array $tags Allowed tags, attributes, and/or entities.
106 *
107 * @return array
108 */
109 public function ksesComponents( $tags ) {
110 $components = json_decode( file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'app/src/Support/kses.json' ), true );
111
112 // add slot to defaults.
113 $tags['span']['slot'] = true;
114 $tags['div']['slot'] = true;
115
116 return array_merge( $components, $tags );
117 }
118
119 /**
120 * Register blocks from config
121 *
122 * @param \Pimple\Container $container Service Container.
123 *
124 * @return void
125 */
126 public function registerBlocks() {
127 $service = \SureCart::resolve( SURECART_CONFIG_KEY );
128 if ( ! empty( $service['blocks'] ) ) {
129 foreach ( $service['blocks'] as $block ) {
130 ( new $block() )->register();
131 }
132 }
133 }
134 }
135