1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Gutenberg; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Commands\EnqueuePublicAssets; |
6
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
8
|
|
|
use GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks\SiteReviewBlock; |
9
|
|
|
use GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks\SiteReviewsBlock; |
10
|
|
|
use GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks\SiteReviewsFormBlock; |
11
|
|
|
use GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks\SiteReviewsSummaryBlock; |
12
|
|
|
use GeminiLabs\SiteReviews\Modules\Assets\AssetJs; |
13
|
|
|
use GeminiLabs\SiteReviews\Modules\Style; |
14
|
|
|
|
15
|
|
|
class Controller extends AbstractController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* The CSS registered here will not load in the site editor unless it contains the .wp-block selector. |
19
|
|
|
* |
20
|
|
|
* @see https://github.com/WordPress/gutenberg/issues/41821 |
21
|
|
|
* |
22
|
|
|
* @action enqueue_block_editor_assets |
23
|
|
|
*/ |
24
|
|
|
public function enqueueBlockEditorAssets(): void |
25
|
|
|
{ |
26
|
|
|
wp_enqueue_style( |
27
|
|
|
glsr()->id.'/blocks', |
28
|
|
|
glsr(Style::class)->stylesheetUrl('blocks'), |
29
|
|
|
['wp-edit-blocks'], |
30
|
|
|
glsr()->version |
31
|
|
|
); |
32
|
|
|
wp_add_inline_style(glsr()->id.'/blocks', (new EnqueuePublicAssets())->inlineStyles()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param bool|string[] $blockTypes |
37
|
|
|
* |
38
|
|
|
* @return bool|string[] |
39
|
|
|
* |
40
|
|
|
* @filter allowed_block_types_all |
41
|
|
|
*/ |
42
|
|
|
public function filterAllowedBlockTypes($blockTypes, \WP_Block_Editor_Context $context) |
43
|
|
|
{ |
44
|
|
|
$postType = Arr::get($context, 'post.post_type'); |
45
|
|
|
return glsr()->post_type !== $postType |
46
|
|
|
? $blockTypes |
47
|
|
|
: []; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array[] $categories |
52
|
|
|
* |
53
|
|
|
* @filter block_categories_all |
54
|
|
|
*/ |
55
|
|
|
public function filterBlockCategories(array $categories): array |
56
|
|
|
{ |
57
|
|
|
$categories[] = [ |
58
|
|
|
'slug' => glsr()->id, |
59
|
|
|
'title' => glsr()->name, |
60
|
|
|
]; |
61
|
|
|
return $categories; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @filter use_block_editor_for_post_type |
66
|
|
|
*/ |
67
|
|
|
public function filterUseBlockEditor(bool $useBlockEditor, string $postType): bool |
68
|
|
|
{ |
69
|
|
|
return glsr()->post_type !== $postType ? $useBlockEditor : false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @action init |
74
|
|
|
*/ |
75
|
|
|
public function registerBlocks(): void |
76
|
|
|
{ |
77
|
|
|
glsr(SiteReviewBlock::class)->register(); |
78
|
|
|
glsr(SiteReviewsBlock::class)->register(); |
79
|
|
|
glsr(SiteReviewsFormBlock::class)->register(); |
80
|
|
|
glsr(SiteReviewsSummaryBlock::class)->register(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string[] $widgets |
85
|
|
|
* |
86
|
|
|
* @filter widget_types_to_hide_from_legacy_widget_block |
87
|
|
|
*/ |
88
|
|
|
public function removeLegacyWidgets(array $widgets): array |
89
|
|
|
{ |
90
|
|
|
array_push($widgets, 'glsr_site-review', 'glsr_site-reviews', 'glsr_site-reviews-form', 'glsr_site-reviews-summary'); |
91
|
|
|
return $widgets; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|