1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\services\editor; |
4
|
|
|
|
5
|
|
|
use EE_Register_CPTs; |
6
|
|
|
use WP_Post_Type; |
7
|
|
|
|
8
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class EditorBlockAdminManager |
14
|
|
|
* Description |
15
|
|
|
* |
16
|
|
|
* @package EventEspresso\core\services\editor |
17
|
|
|
* @author Brent Christensen |
18
|
|
|
* @since $VID:$ |
19
|
|
|
*/ |
20
|
|
|
class EditorBlockAdminManager extends EditorBlockManager |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Returns the name of a hookpoint to be used to call initialize() |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function init_hook() |
29
|
|
|
{ |
30
|
|
|
return 'AHEE__EE_System__load_CPTs_and_session__complete'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Perform any early setup required for block editors to functions |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
* @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
39
|
|
|
* @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
40
|
|
|
* @throws \InvalidArgumentException |
41
|
|
|
*/ |
42
|
|
|
public function initialize() |
43
|
|
|
{ |
44
|
|
|
$custom_post_types = EE_Register_CPTs::get_CPTs(); |
45
|
|
|
$espresso_post_types = array_keys($custom_post_types); |
46
|
|
|
$espresso_post_types[] = 'espresso_registrations'; |
47
|
|
|
if ( |
48
|
|
|
($this->action === 'edit' || $this->action === 'create_new' || $this->action === 'edit_attendee') |
49
|
|
|
&& in_array($this->page, $espresso_post_types, true) |
50
|
|
|
) { |
51
|
|
|
$this->loadCustomPostTypeBlockEditor(array_keys($custom_post_types)); |
52
|
|
|
} |
53
|
|
|
add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/ |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function loadCustomPostTypeBlockEditor(array $custom_post_types) |
58
|
|
|
{ |
59
|
|
|
$this->modifyWpPostTypes($custom_post_types); |
60
|
|
|
add_action('admin_enqueue_scripts', array($this, 'registerAdminScripts'), 20); |
61
|
|
|
add_filter('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', 'gutenberg_init', 10, 2); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Manipulate globals related to EE Post Type so gutenberg loads. |
66
|
|
|
*/ |
67
|
|
|
private function modifyWpPostTypes(array $custom_post_types) |
68
|
|
|
{ |
69
|
|
|
global $wp_post_types, $_wp_post_type_features; |
70
|
|
|
foreach ($custom_post_types as $post_type) { |
71
|
|
|
$_wp_post_type_features[ $post_type ]['editor'] = true; |
72
|
|
|
if(isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type){ |
|
|
|
|
73
|
|
|
$post_type_object = $wp_post_types[ $post_type ]; |
74
|
|
|
$post_type_object->show_in_rest = true; |
75
|
|
|
$post_type_object->template = array(); |
76
|
|
|
foreach ($this->blocks as $block) { |
77
|
|
|
if($block->appliesToPostType($post_type)){ |
78
|
|
|
$post_type_object->template[] = $block->getEditorContainer(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function coerceEeCptEditorUrlForGutenberg($url, $path, $blog_id) |
87
|
|
|
{ |
88
|
|
|
if ( |
89
|
|
|
$this->page === 'espresso_events' |
90
|
|
|
&& ($this->action === 'edit' || $this->action === 'create_new') |
91
|
|
|
&& strpos($path, 'post.php') !== false |
92
|
|
|
) { |
93
|
|
|
return add_query_arg( |
94
|
|
|
array( |
95
|
|
|
'page' => $this->page, |
96
|
|
|
'action' => $this->action |
97
|
|
|
), |
98
|
|
|
get_site_url($blog_id) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
return $url; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|
106
|
|
View Code Duplication |
public function registerAdminScripts() |
107
|
|
|
{ |
108
|
|
|
wp_register_script( |
109
|
|
|
'ee-event-editor-blocks', |
110
|
|
|
$this->domain->distributionAssetsUrl() . 'ee-event-editor-blocks.dist.js', |
111
|
|
|
array('wp-blocks'), |
112
|
|
|
filemtime($this->domain->distributionAssetsPath() . 'ee-event-editor-blocks.dist.js') |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|