[wp-meta] [Making WordPress.org] #4228: Gutenberg theme: Remove reliance upon the plugin

Making WordPress.org noreply at wordpress.org
Thu Mar 21 14:26:12 UTC 2019

#4228: Gutenberg theme: Remove reliance upon the plugin
 Reporter:  dd32     |       Owner:  (none)
     Type:  task     |      Status:  new
 Priority:  high     |   Milestone:
Component:  General  |  Resolution:
 Keywords:           |

Comment (by TJNowell):

 I got frontenberg working with the internal block editor but it required
 some changes

 First, I use this to figure out if gutenberg is present and active:

 if ( ! function_exists('gutenberg_editor_scripts_and_styles') ) {

 If so, it:

  - conditionally enqueues a selection of scripts such as the hearbeat
  - polyfills `get_current_screen` and makes it return `''`
  - enqueues `gutenberg_editor_scripts_and_styles`

 If not, it:

  - calls the WP 5 enqueue assets action
  - adds `frontenberg_load_wp5_editor` to `template_redirect`, where it
 then does the same job that `wp-admin/edit-form-blocks.php` does

 Before the editor was merged, it was enough to enqueue the GB editor, make
 sure the relevant HTML was added, and that
 `gutenberg_editor_scripts_and_styles` was added on the enqueue scripts

 `gutenberg_editor_scripts_and_styles` called functions that took care of
 instantiating the editor, but when it was merged all that nice hookable
 function code got smushed into `wp-admin/edit-form-blocks.php`, and a lot
 of flexibility and power was lost. I tried including that file directly
 but ran into lots of issues. Frontenberg ran fine without including any WP
 Admin files before this, and to get that file working would require a lot
 of hacks, and compromises, some of which I could not work around.

 So, I created `frontenberg_load_wp5_editor`. I started by copying the
 contents of that file into a function and running it on the
 `template_direct` hook. I made enough changes to get it working, then made
 additional changes based on Frontenbergs specific use case. E.g. removing
 the metabox setup code ( metaboxes don't work anyway ), and the post
 locking ( why figure out if the post is locked when post locking makes the
 frontend unusable? Force it to unlocked ).

 I also added a number of supporting functions that replace WP 5 functions
 used in that file, so that I can return static values, or do non-WP Admin
 things. This meant I didn't have to load in more WP Admin files

 Finally, I adjusted the JS with a basic check:

                 var fbeditor = window._wpLoadBlockEditor;
                 if ( window._wpLoadGutenbergEditor ) {
                         fbeditor = window._wpLoadGutenbergEditor;

 `fbeditor` then gets used to adjust a promise to intercept and cancel any
 `PUT` `POST` `DELETE` or `PATCH` requests so that they never get sent.

 Full implementation here:

Ticket URL: <https://meta.trac.wordpress.org/ticket/4228#comment:6>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org

More information about the wp-meta mailing list