@@ -22,197 +22,197 @@ |
||
| 22 | 22 | abstract class BlockAssetRegister implements AssetRegisterInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var DomainInterface $domain |
|
| 27 | - */ |
|
| 28 | - private $domain; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var Registry $registry |
|
| 32 | - */ |
|
| 33 | - private $registry; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string $script_handle |
|
| 37 | - */ |
|
| 38 | - private $script_handle; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array $script_dependencies |
|
| 42 | - */ |
|
| 43 | - private $script_dependencies; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string $style_handle |
|
| 47 | - */ |
|
| 48 | - private $style_handle; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var array $style_dependencies |
|
| 52 | - */ |
|
| 53 | - private $style_dependencies; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * BlockAssetRegister constructor. |
|
| 58 | - * |
|
| 59 | - * @param string $script_handle |
|
| 60 | - * @param array $script_dependencies |
|
| 61 | - * @param string $style_handle |
|
| 62 | - * @param array $style_dependencies |
|
| 63 | - * @param DomainInterface $domain |
|
| 64 | - * @param Registry $registry |
|
| 65 | - */ |
|
| 66 | - public function __construct( |
|
| 67 | - $script_handle, |
|
| 68 | - array $script_dependencies, |
|
| 69 | - $style_handle, |
|
| 70 | - array $style_dependencies, |
|
| 71 | - DomainInterface $domain, |
|
| 72 | - Registry $registry |
|
| 73 | - ) { |
|
| 74 | - $this->script_handle = $script_handle; |
|
| 75 | - $this->script_dependencies = $script_dependencies; |
|
| 76 | - $this->style_handle = $style_handle; |
|
| 77 | - $this->style_dependencies = $style_dependencies; |
|
| 78 | - $this->domain = $domain; |
|
| 79 | - $this->registry = $registry; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function scriptHandle() |
|
| 87 | - { |
|
| 88 | - return $this->script_handle; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $script_handle |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - */ |
|
| 96 | - public function setScriptHandle($script_handle) |
|
| 97 | - { |
|
| 98 | - if (! is_string($script_handle)) { |
|
| 99 | - throw new InvalidDataTypeException('$script_handle', $script_handle, 'string'); |
|
| 100 | - } |
|
| 101 | - $this->script_handle = $script_handle; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function styleHandle() |
|
| 109 | - { |
|
| 110 | - return $this->style_handle; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param string $style_handle |
|
| 116 | - * @throws InvalidDataTypeException |
|
| 117 | - */ |
|
| 118 | - public function setStyleHandle($style_handle) |
|
| 119 | - { |
|
| 120 | - if (! is_string($style_handle)) { |
|
| 121 | - throw new InvalidDataTypeException('$style_handle', $style_handle, 'string'); |
|
| 122 | - } |
|
| 123 | - $this->style_handle = $style_handle; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function scriptDependencies() |
|
| 131 | - { |
|
| 132 | - return $this->script_dependencies; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param array $script_dependencies |
|
| 138 | - */ |
|
| 139 | - public function setScriptDependencies($script_dependencies) |
|
| 140 | - { |
|
| 141 | - $this->script_dependencies = $script_dependencies + array( |
|
| 142 | - 'eejs-core', |
|
| 143 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 144 | - 'wp-i18n', // Provides localization functions |
|
| 145 | - 'wp-element', // Provides React.Component |
|
| 146 | - 'wp-components' // Provides many prebuilt components and controls |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return array |
|
| 153 | - */ |
|
| 154 | - public function styleDependencies() |
|
| 155 | - { |
|
| 156 | - return $this->style_dependencies; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param array $style_dependencies |
|
| 162 | - */ |
|
| 163 | - public function setStyleDependencies($style_dependencies) |
|
| 164 | - { |
|
| 165 | - $this->style_dependencies = $style_dependencies; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return void |
|
| 171 | - * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
| 172 | - * @throws \InvalidArgumentException |
|
| 173 | - */ |
|
| 174 | - public function registerManifestFile() |
|
| 175 | - { |
|
| 176 | - if($this->domain->assetNamespace() !== Registry::ASSET_NAMESPACE_CORE) { |
|
| 177 | - $this->registry->registerManifestFile( |
|
| 178 | - $this->domain->assetNamespace(), |
|
| 179 | - $this->domain->distributionAssetsUrl(), |
|
| 180 | - $this->domain->distributionAssetsPath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return void |
|
| 188 | - */ |
|
| 189 | - public function registerScripts() |
|
| 190 | - { |
|
| 191 | - wp_register_script( |
|
| 192 | - $this->scriptHandle(), |
|
| 193 | - $this->registry->getJsUrl( |
|
| 194 | - $this->domain->assetNamespace(), |
|
| 195 | - $this->scriptHandle() |
|
| 196 | - ), |
|
| 197 | - $this->scriptDependencies(), |
|
| 198 | - null, |
|
| 199 | - true |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @return void |
|
| 206 | - */ |
|
| 207 | - public function registerStyles() |
|
| 208 | - { |
|
| 209 | - wp_register_style( |
|
| 210 | - $this->styleHandle(), |
|
| 211 | - $this->registry->getCssUrl( |
|
| 212 | - $this->domain->assetNamespace(), |
|
| 213 | - $this->styleHandle() |
|
| 214 | - ), |
|
| 215 | - $this->styleDependencies() |
|
| 216 | - ); |
|
| 217 | - } |
|
| 25 | + /** |
|
| 26 | + * @var DomainInterface $domain |
|
| 27 | + */ |
|
| 28 | + private $domain; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var Registry $registry |
|
| 32 | + */ |
|
| 33 | + private $registry; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string $script_handle |
|
| 37 | + */ |
|
| 38 | + private $script_handle; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array $script_dependencies |
|
| 42 | + */ |
|
| 43 | + private $script_dependencies; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string $style_handle |
|
| 47 | + */ |
|
| 48 | + private $style_handle; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var array $style_dependencies |
|
| 52 | + */ |
|
| 53 | + private $style_dependencies; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * BlockAssetRegister constructor. |
|
| 58 | + * |
|
| 59 | + * @param string $script_handle |
|
| 60 | + * @param array $script_dependencies |
|
| 61 | + * @param string $style_handle |
|
| 62 | + * @param array $style_dependencies |
|
| 63 | + * @param DomainInterface $domain |
|
| 64 | + * @param Registry $registry |
|
| 65 | + */ |
|
| 66 | + public function __construct( |
|
| 67 | + $script_handle, |
|
| 68 | + array $script_dependencies, |
|
| 69 | + $style_handle, |
|
| 70 | + array $style_dependencies, |
|
| 71 | + DomainInterface $domain, |
|
| 72 | + Registry $registry |
|
| 73 | + ) { |
|
| 74 | + $this->script_handle = $script_handle; |
|
| 75 | + $this->script_dependencies = $script_dependencies; |
|
| 76 | + $this->style_handle = $style_handle; |
|
| 77 | + $this->style_dependencies = $style_dependencies; |
|
| 78 | + $this->domain = $domain; |
|
| 79 | + $this->registry = $registry; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function scriptHandle() |
|
| 87 | + { |
|
| 88 | + return $this->script_handle; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $script_handle |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + */ |
|
| 96 | + public function setScriptHandle($script_handle) |
|
| 97 | + { |
|
| 98 | + if (! is_string($script_handle)) { |
|
| 99 | + throw new InvalidDataTypeException('$script_handle', $script_handle, 'string'); |
|
| 100 | + } |
|
| 101 | + $this->script_handle = $script_handle; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function styleHandle() |
|
| 109 | + { |
|
| 110 | + return $this->style_handle; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param string $style_handle |
|
| 116 | + * @throws InvalidDataTypeException |
|
| 117 | + */ |
|
| 118 | + public function setStyleHandle($style_handle) |
|
| 119 | + { |
|
| 120 | + if (! is_string($style_handle)) { |
|
| 121 | + throw new InvalidDataTypeException('$style_handle', $style_handle, 'string'); |
|
| 122 | + } |
|
| 123 | + $this->style_handle = $style_handle; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function scriptDependencies() |
|
| 131 | + { |
|
| 132 | + return $this->script_dependencies; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param array $script_dependencies |
|
| 138 | + */ |
|
| 139 | + public function setScriptDependencies($script_dependencies) |
|
| 140 | + { |
|
| 141 | + $this->script_dependencies = $script_dependencies + array( |
|
| 142 | + 'eejs-core', |
|
| 143 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 144 | + 'wp-i18n', // Provides localization functions |
|
| 145 | + 'wp-element', // Provides React.Component |
|
| 146 | + 'wp-components' // Provides many prebuilt components and controls |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return array |
|
| 153 | + */ |
|
| 154 | + public function styleDependencies() |
|
| 155 | + { |
|
| 156 | + return $this->style_dependencies; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param array $style_dependencies |
|
| 162 | + */ |
|
| 163 | + public function setStyleDependencies($style_dependencies) |
|
| 164 | + { |
|
| 165 | + $this->style_dependencies = $style_dependencies; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return void |
|
| 171 | + * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
| 172 | + * @throws \InvalidArgumentException |
|
| 173 | + */ |
|
| 174 | + public function registerManifestFile() |
|
| 175 | + { |
|
| 176 | + if($this->domain->assetNamespace() !== Registry::ASSET_NAMESPACE_CORE) { |
|
| 177 | + $this->registry->registerManifestFile( |
|
| 178 | + $this->domain->assetNamespace(), |
|
| 179 | + $this->domain->distributionAssetsUrl(), |
|
| 180 | + $this->domain->distributionAssetsPath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return void |
|
| 188 | + */ |
|
| 189 | + public function registerScripts() |
|
| 190 | + { |
|
| 191 | + wp_register_script( |
|
| 192 | + $this->scriptHandle(), |
|
| 193 | + $this->registry->getJsUrl( |
|
| 194 | + $this->domain->assetNamespace(), |
|
| 195 | + $this->scriptHandle() |
|
| 196 | + ), |
|
| 197 | + $this->scriptDependencies(), |
|
| 198 | + null, |
|
| 199 | + true |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @return void |
|
| 206 | + */ |
|
| 207 | + public function registerStyles() |
|
| 208 | + { |
|
| 209 | + wp_register_style( |
|
| 210 | + $this->styleHandle(), |
|
| 211 | + $this->registry->getCssUrl( |
|
| 212 | + $this->domain->assetNamespace(), |
|
| 213 | + $this->styleHandle() |
|
| 214 | + ), |
|
| 215 | + $this->styleDependencies() |
|
| 216 | + ); |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | \ No newline at end of file |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function setScriptHandle($script_handle) |
| 97 | 97 | { |
| 98 | - if (! is_string($script_handle)) { |
|
| 98 | + if ( ! is_string($script_handle)) { |
|
| 99 | 99 | throw new InvalidDataTypeException('$script_handle', $script_handle, 'string'); |
| 100 | 100 | } |
| 101 | 101 | $this->script_handle = $script_handle; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function setStyleHandle($style_handle) |
| 119 | 119 | { |
| 120 | - if (! is_string($style_handle)) { |
|
| 120 | + if ( ! is_string($style_handle)) { |
|
| 121 | 121 | throw new InvalidDataTypeException('$style_handle', $style_handle, 'string'); |
| 122 | 122 | } |
| 123 | 123 | $this->style_handle = $style_handle; |
@@ -140,9 +140,9 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $this->script_dependencies = $script_dependencies + array( |
| 142 | 142 | 'eejs-core', |
| 143 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 144 | - 'wp-i18n', // Provides localization functions |
|
| 145 | - 'wp-element', // Provides React.Component |
|
| 143 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 144 | + 'wp-i18n', // Provides localization functions |
|
| 145 | + 'wp-element', // Provides React.Component |
|
| 146 | 146 | 'wp-components' // Provides many prebuilt components and controls |
| 147 | 147 | ); |
| 148 | 148 | } |
@@ -173,11 +173,11 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function registerManifestFile() |
| 175 | 175 | { |
| 176 | - if($this->domain->assetNamespace() !== Registry::ASSET_NAMESPACE_CORE) { |
|
| 176 | + if ($this->domain->assetNamespace() !== Registry::ASSET_NAMESPACE_CORE) { |
|
| 177 | 177 | $this->registry->registerManifestFile( |
| 178 | 178 | $this->domain->assetNamespace(), |
| 179 | 179 | $this->domain->distributionAssetsUrl(), |
| 180 | - $this->domain->distributionAssetsPath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
| 180 | + $this->domain->distributionAssetsPath().Registry::FILE_NAME_BUILD_MANIFEST |
|
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | } |
@@ -22,108 +22,108 @@ |
||
| 22 | 22 | class EspressoGutenbergEditor extends BlockManager |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var CustomPostTypeDefinitions $custom_post_types |
|
| 27 | - */ |
|
| 28 | - protected $custom_post_types; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * EspressoGutenbergEditor constructor. |
|
| 33 | - * |
|
| 34 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
| 35 | - * @param BlockCollection $blocks |
|
| 36 | - * @param RequestInterface $request |
|
| 37 | - */ |
|
| 38 | - public function __construct( |
|
| 39 | - CustomPostTypeDefinitions $custom_post_types, |
|
| 40 | - BlockCollection $blocks, |
|
| 41 | - RequestInterface $request |
|
| 42 | - ) { |
|
| 43 | - $this->custom_post_types = $custom_post_types; |
|
| 44 | - parent::__construct($blocks, $request); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Returns the name of a hookpoint to be used to call initialize() |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function init_hook() |
|
| 55 | - { |
|
| 56 | - return 'AHEE__EE_System__load_CPTs_and_session__complete'; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Perform any early setup required for block editors to functions |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public function initialize() |
|
| 66 | - { |
|
| 67 | - $custom_post_types = $this->custom_post_types->getCustomPostTypeSlugs(); |
|
| 68 | - $espresso_post_types = $custom_post_types; |
|
| 69 | - $espresso_post_types[] = 'espresso_registrations'; |
|
| 70 | - if ( |
|
| 71 | - ($this->action === 'edit' || $this->action === 'create_new' || $this->action === 'edit_attendee') |
|
| 72 | - && in_array($this->page, $espresso_post_types, true) |
|
| 73 | - ) { |
|
| 74 | - $this->loadCustomPostTypeBlockEditor($custom_post_types); |
|
| 75 | - } |
|
| 76 | - add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/ |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - public function loadCustomPostTypeBlockEditor(array $custom_post_types) |
|
| 81 | - { |
|
| 82 | - $this->modifyWpPostTypes($custom_post_types); |
|
| 83 | - // add_action('admin_enqueue_scripts', array($this, 'registerAdminScripts'), 20); |
|
| 84 | - add_filter('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', 'gutenberg_init', 10, 2); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Manipulate globals related to EE Post Type so gutenberg loads. |
|
| 90 | - * |
|
| 91 | - * @param array $custom_post_types |
|
| 92 | - */ |
|
| 93 | - private function modifyWpPostTypes(array $custom_post_types) |
|
| 94 | - { |
|
| 95 | - global $wp_post_types, $_wp_post_type_features; |
|
| 96 | - foreach ($custom_post_types as $post_type) { |
|
| 97 | - $_wp_post_type_features[ $post_type ]['editor'] = true; |
|
| 98 | - if (isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type) { |
|
| 99 | - $post_type_object = $wp_post_types[ $post_type ]; |
|
| 100 | - $post_type_object->show_in_rest = true; |
|
| 101 | - $post_type_object->template = array(); |
|
| 102 | - foreach ($this->blocks as $block) { |
|
| 103 | - if ($block->appliesToPostType($post_type)) { |
|
| 104 | - $post_type_object->template[] = $block->getEditorContainer(); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - public function coerceEeCptEditorUrlForGutenberg($url, $path, $blog_id) |
|
| 113 | - { |
|
| 114 | - if ( |
|
| 115 | - $this->page === 'espresso_events' |
|
| 116 | - && ($this->action === 'edit' || $this->action === 'create_new') |
|
| 117 | - && strpos($path, 'post.php') !== false |
|
| 118 | - ) { |
|
| 119 | - return add_query_arg( |
|
| 120 | - array( |
|
| 121 | - 'page' => $this->page, |
|
| 122 | - 'action' => $this->action |
|
| 123 | - ), |
|
| 124 | - get_site_url($blog_id) |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - return $url; |
|
| 128 | - } |
|
| 25 | + /** |
|
| 26 | + * @var CustomPostTypeDefinitions $custom_post_types |
|
| 27 | + */ |
|
| 28 | + protected $custom_post_types; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * EspressoGutenbergEditor constructor. |
|
| 33 | + * |
|
| 34 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
| 35 | + * @param BlockCollection $blocks |
|
| 36 | + * @param RequestInterface $request |
|
| 37 | + */ |
|
| 38 | + public function __construct( |
|
| 39 | + CustomPostTypeDefinitions $custom_post_types, |
|
| 40 | + BlockCollection $blocks, |
|
| 41 | + RequestInterface $request |
|
| 42 | + ) { |
|
| 43 | + $this->custom_post_types = $custom_post_types; |
|
| 44 | + parent::__construct($blocks, $request); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Returns the name of a hookpoint to be used to call initialize() |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function init_hook() |
|
| 55 | + { |
|
| 56 | + return 'AHEE__EE_System__load_CPTs_and_session__complete'; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Perform any early setup required for block editors to functions |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public function initialize() |
|
| 66 | + { |
|
| 67 | + $custom_post_types = $this->custom_post_types->getCustomPostTypeSlugs(); |
|
| 68 | + $espresso_post_types = $custom_post_types; |
|
| 69 | + $espresso_post_types[] = 'espresso_registrations'; |
|
| 70 | + if ( |
|
| 71 | + ($this->action === 'edit' || $this->action === 'create_new' || $this->action === 'edit_attendee') |
|
| 72 | + && in_array($this->page, $espresso_post_types, true) |
|
| 73 | + ) { |
|
| 74 | + $this->loadCustomPostTypeBlockEditor($custom_post_types); |
|
| 75 | + } |
|
| 76 | + add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/ |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + public function loadCustomPostTypeBlockEditor(array $custom_post_types) |
|
| 81 | + { |
|
| 82 | + $this->modifyWpPostTypes($custom_post_types); |
|
| 83 | + // add_action('admin_enqueue_scripts', array($this, 'registerAdminScripts'), 20); |
|
| 84 | + add_filter('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', 'gutenberg_init', 10, 2); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Manipulate globals related to EE Post Type so gutenberg loads. |
|
| 90 | + * |
|
| 91 | + * @param array $custom_post_types |
|
| 92 | + */ |
|
| 93 | + private function modifyWpPostTypes(array $custom_post_types) |
|
| 94 | + { |
|
| 95 | + global $wp_post_types, $_wp_post_type_features; |
|
| 96 | + foreach ($custom_post_types as $post_type) { |
|
| 97 | + $_wp_post_type_features[ $post_type ]['editor'] = true; |
|
| 98 | + if (isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type) { |
|
| 99 | + $post_type_object = $wp_post_types[ $post_type ]; |
|
| 100 | + $post_type_object->show_in_rest = true; |
|
| 101 | + $post_type_object->template = array(); |
|
| 102 | + foreach ($this->blocks as $block) { |
|
| 103 | + if ($block->appliesToPostType($post_type)) { |
|
| 104 | + $post_type_object->template[] = $block->getEditorContainer(); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + public function coerceEeCptEditorUrlForGutenberg($url, $path, $blog_id) |
|
| 113 | + { |
|
| 114 | + if ( |
|
| 115 | + $this->page === 'espresso_events' |
|
| 116 | + && ($this->action === 'edit' || $this->action === 'create_new') |
|
| 117 | + && strpos($path, 'post.php') !== false |
|
| 118 | + ) { |
|
| 119 | + return add_query_arg( |
|
| 120 | + array( |
|
| 121 | + 'page' => $this->page, |
|
| 122 | + 'action' => $this->action |
|
| 123 | + ), |
|
| 124 | + get_site_url($blog_id) |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + return $url; |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | ) { |
| 74 | 74 | $this->loadCustomPostTypeBlockEditor($custom_post_types); |
| 75 | 75 | } |
| 76 | - add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/ |
|
| 76 | + add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3); /**/ |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | global $wp_post_types, $_wp_post_type_features; |
| 96 | 96 | foreach ($custom_post_types as $post_type) { |
| 97 | - $_wp_post_type_features[ $post_type ]['editor'] = true; |
|
| 98 | - if (isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type) { |
|
| 99 | - $post_type_object = $wp_post_types[ $post_type ]; |
|
| 97 | + $_wp_post_type_features[$post_type]['editor'] = true; |
|
| 98 | + if (isset($wp_post_types[$post_type]) && $wp_post_types[$post_type] instanceof WP_Post_Type) { |
|
| 99 | + $post_type_object = $wp_post_types[$post_type]; |
|
| 100 | 100 | $post_type_object->show_in_rest = true; |
| 101 | 101 | $post_type_object->template = array(); |
| 102 | 102 | foreach ($this->blocks as $block) { |