Gutenberg: Hooks and filters support and documentation

Created on 20 Jun 2017  路  8Comments  路  Source: WordPress/gutenberg

Stripping this out from #1164. see the point touched by @hedgefield, as I'm not aware of any public discussion happened around this:

The first question I think people will have is which of the current hooks/filters used in the post edit screen and metaboxes will be dropped and which ones still supported?

The current WordPress edit post screen provides a good amount of hooks and filters. I'm not even sure there's a list of all the known hooks/filters that run in that page or if there's an easy way to programmatically get a list.

However, Gutenberg is going to replace relevant parts of, if not almost all, the edit post screen. I think it would be reasonable (I'd say even necessary) to publish a list of:

  • all the hooks/filters that will be dropped
  • all the hooks/filters that will stay
  • all the new hooks/filters, if any

Ideally, this should happen as soon as possible, and at least a few months before Gutenberg gets merged to give plugin/theme authors the time required to adapt their code.

Backwards Compatibility [Feature] Extensibility

Most helpful comment

I've made an overview of actions and filters that are removed with Gutenberg so far using https://wordpress.org/plugins/debug-bar-actions-and-filters-addon/

post-new.php

Actions removed (15)

  • pre_get_users
  • pre_user_query
  • post_edit_form_tag
  • edit_form_top
  • edit_form_before_permalink
  • edit_form_after_title
  • media_buttons
  • edit_form_after_editor
  • submitpost_box
  • post_submitbox_minor_actions
  • post_submitbox_misc_actions
  • post_submitbox_start
  • post_comment_status_meta_box-options
  • dbx_post_sidebar
  • post_lock_lost_dialog

Filters removed (1)

  • manage_post_columns

Actions added (8)

  • rest_api_init
  • the_post
  • parse_tax_query
  • parse_query
  • pre_get_posts
  • posts_selection
  • wp_enqueue_editor
  • enqueue_block_editor_assets

Filters added (7)

  • default_option_WPLANG
  • default_option_posts_per_page
  • default_option_use_smilies
  • post_password_required
  • rest_post_dispatch
  • rest_pre_dispatch
  • screen_options_show_screen

post.php?action=edit

Actions removed (20)

  • update_post_meta
  • update_postmeta
  • updated_post_meta
  • updated_postmeta
  • pre_get_users
  • pre_user_query
  • post_edit_form_tag
  • edit_form_top
  • edit_form_before_permalink
  • edit_form_after_title
  • media_buttons
  • edit_form_after_editor
  • submitpost_box
  • post_submitbox_minor_actions
  • post_submitbox_misc_actions
  • post_submitbox_start
  • post_comment_status_meta_box-options
  • parse_comment_query
  • pre_get_comments
  • post_lock_lost_dialog

Filters removed (1)

  • manage_post_columns

Actions added (4)

  • rest_api_init
  • the_post
  • wp_enqueue_editor
  • enqueue_block_editor_assets

Filters added (7)

  • default_option_WPLANG
  • default_option_posts_per_page
  • default_option_use_smilies
  • post_password_required
  • rest_post_dispatch
  • rest_pre_dispatch
  • screen_options_show_screen

All 8 comments

I've made an overview of actions and filters that are removed with Gutenberg so far using https://wordpress.org/plugins/debug-bar-actions-and-filters-addon/

post-new.php

Actions removed (15)

  • pre_get_users
  • pre_user_query
  • post_edit_form_tag
  • edit_form_top
  • edit_form_before_permalink
  • edit_form_after_title
  • media_buttons
  • edit_form_after_editor
  • submitpost_box
  • post_submitbox_minor_actions
  • post_submitbox_misc_actions
  • post_submitbox_start
  • post_comment_status_meta_box-options
  • dbx_post_sidebar
  • post_lock_lost_dialog

Filters removed (1)

  • manage_post_columns

Actions added (8)

  • rest_api_init
  • the_post
  • parse_tax_query
  • parse_query
  • pre_get_posts
  • posts_selection
  • wp_enqueue_editor
  • enqueue_block_editor_assets

Filters added (7)

  • default_option_WPLANG
  • default_option_posts_per_page
  • default_option_use_smilies
  • post_password_required
  • rest_post_dispatch
  • rest_pre_dispatch
  • screen_options_show_screen

post.php?action=edit

Actions removed (20)

  • update_post_meta
  • update_postmeta
  • updated_post_meta
  • updated_postmeta
  • pre_get_users
  • pre_user_query
  • post_edit_form_tag
  • edit_form_top
  • edit_form_before_permalink
  • edit_form_after_title
  • media_buttons
  • edit_form_after_editor
  • submitpost_box
  • post_submitbox_minor_actions
  • post_submitbox_misc_actions
  • post_submitbox_start
  • post_comment_status_meta_box-options
  • parse_comment_query
  • pre_get_comments
  • post_lock_lost_dialog

Filters removed (1)

  • manage_post_columns

Actions added (4)

  • rest_api_init
  • the_post
  • wp_enqueue_editor
  • enqueue_block_editor_assets

Filters added (7)

  • default_option_WPLANG
  • default_option_posts_per_page
  • default_option_use_smilies
  • post_password_required
  • rest_post_dispatch
  • rest_pre_dispatch
  • screen_options_show_screen

We need to address these better as part of MVP. The minimal thing we should do is deprecate these in an orderly fashion instead of plainly removing.

In Yoast SEO we have the following function:

        /**
     * Shows deprecation warnings to the user if a plugin has registered a filter we have deprecated.
     */
    public function show_hook_deprecation_warnings() {
        global $wp_filter;
        if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
            return false;
        }
        // WordPress hooks that have been deprecated since a Yoast SEO version.
        $deprecated_filters = array(
            'wpseo_metadesc_length'            => array(
                'version'     => '3.0',
                'alternative' => 'javascript',
            ),
            'wpseo_metadesc_length_reason'     => array(
                'version'     => '3.0',
                'alternative' => 'javascript',
            ),
            'wpseo_body_length_score'          => array(
                'version'     => '3.0',
                'alternative' => 'javascript',
            ),
            'wpseo_linkdex_results'            => array(
                'version'     => '3.0',
                'alternative' => 'javascript',
            ),
            'wpseo_snippet'                    => array(
                'version'     => '3.0',
                'alternative' => 'javascript',
            ),
            'wp_seo_get_bc_title'              => array(
                'version'     => '5.8',
                'alternative' => 'wpseo_breadcrumb_single_link_info',
            ),
            'wpseo_stopwords'                  => array(
                'version'     => '6.4',
                'alternative' => null,
            ),
            'wpseo_redirect_orphan_attachment' => array(
                'version'     => '6.4',
                'alternative' => null,
            ),
        );
        // Determine which filters have been registered.
        $deprecated_notices = array_intersect(
            array_keys( $deprecated_filters ),
            array_keys( $wp_filter )
        );
        // Show notice for each deprecated filter or action that has been registered.
        foreach ( $deprecated_notices as $deprecated_filter ) {
            $deprecation_info = $deprecated_filters[ $deprecated_filter ];
            _deprecated_hook(
                $deprecated_filter,
                'WPSEO ' . $deprecation_info['version'],
                $deprecation_info['alternative']
            );
        }
    }

We should consider including something like this in Gutenberg as well, at least for the new editor page.

Related PR: https://github.com/WordPress/gutenberg/issues/4674. There is some discussion how to add hooks support for all actions related to data changes.

Re:

I'm not even sure there's a list of all the known hooks/filters that run in that page or if there's an easy way to programmatically get a list.

I use a trace plugin that reports all the hooks and filters to an output file at shutdown. It is an enormous list of hooks. I won't show you all of the 11,000 hook and filters run on wp-admin/post-new.php
Here's a tiny section showing what happens in the the_content processing used when the REST API is getting the rendered part of the post and excerpt.

[hook replace_editor;admin_enqueue_scripts;the_content filter 1 1 0]
[hook replace_editor;admin_enqueue_scripts;the_content;gettext_with_context filter 4 1 0]
[hook replace_editor;admin_enqueue_scripts;the_content;pre_option_use_smilies filter 3 1 0]
[hook replace_editor;admin_enqueue_scripts;the_content;alloptions filter 1 1 0]
[hook replace_editor;admin_enqueue_scripts;the_content;option_use_smilies filter 2 1 0]
[hook replace_editor;admin_enqueue_scripts;get_the_excerpt filter 2 1 0]
[hook replace_editor;admin_enqueue_scripts;the_excerpt filter 1 1 0]
[hook replace_editor;admin_enqueue_scripts;the_excerpt;pre_option_use_smilies filter 3 1 0]
[hook replace_editor;admin_enqueue_scripts;the_excerpt;alloptions filter 1 1 0]
[hook replace_editor;admin_enqueue_scripts;the_excerpt;option_use_smilies filter 2 1 0]

Regarding the actions and filters added and removed, developers need to be made aware that the sequence in which actions are invoked may change. e.g.

In my development environment, having sorted the hooks by name there were 101 difference sections between Classic and Gutenberg. Here's a selection, sorted by hook name.
image

Also they should undertand that the editor now uses REST requests to populate different sections of the edit screens. So, after wp-admin/post-new.php the browser may also be firing off other requests such as:

  • GET wp-json/wp/v2/users?context=edit&per_page=100
  • GET wp-json/wp/v2/tags?per_page=100&orderby=count&order=desc ...
  • GET wp-json/wp/v2/categories?per_page=100&orderby=count&order=desc ...

I think the issue is not just about actions and filters that are removed, but also about the ones that won't work or have any effect any longer. For example. screen_settings won't have any effect simply because in Gutenberg there's no UI for the Screen Options. See https://github.com/WordPress/gutenberg/issues/1351

Just a heads up that I'm working on a more specific migration guide and welcome everyone's input.

Closing this issue as it's now an ongoing project (https://github.com/danielbachhuber/gutenberg-migration-guide) and also tracked with #4151. Feel free to open issues / PRs in that repo as you find specific integration points you want to document.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maddisondesigns picture maddisondesigns  路  3Comments

franz-josef-kaiser picture franz-josef-kaiser  路  3Comments

jasmussen picture jasmussen  路  3Comments

mhenrylucero picture mhenrylucero  路  3Comments

maddisondesigns picture maddisondesigns  路  3Comments