Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for preview interstitial markup #12463

Merged
merged 3 commits into from
Jan 4, 2019

Conversation

swissspidy
Copy link
Member

Description

This uses applyFilters to make the preview interstitial markup filterable.

Fixes #12238.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the filter with the following sample and it worked correctly:

wp.hooks.addFilter( 'editor.interstitialMessage', 'myplugin/preview', function() {
    return '<b>Post preview is being generated! 💃</b>';
} );

Would it be possible to add some docs to the filter?

@swissspidy
Copy link
Member Author

@jorgefilipecosta You mean in the handbook?

@chrisvanpatten
Copy link
Contributor

@swissspidy I don't know whether Jorge meant inline docs or in the handbook but this page would be a good spot for a note either way: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/filters/editor-filters.md

:)

@swissspidy
Copy link
Member Author

Ugh. We really need to automate that stuff.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter works great and the sample tests correctly. I think this is the right place to document the filter. The code looks great to me.
cc: @gziolo as he has a more high-level view on our extensibility efforts, and may have some comments on this new API.

@gziolo gziolo added the [Feature] Extensibility The ability to extend blocks or the editing experience label Dec 3, 2018
@gziolo gziolo added this to the 4.8 milestone Dec 3, 2018
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editor.interstitialMessage - my only concern would be the name of this filter. it doesn't contain any information about the context. What do you think about:
editor.PostPreview.interstitialMarkup

It is referenced much often as markup than message in the PR.

@gziolo gziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Dec 3, 2018
@swissspidy
Copy link
Member Author

editor.PostPreview.interstitialMarkup sounds great. Will change it accordingly.

@gziolo
Copy link
Member

gziolo commented Dec 3, 2018

I scheduled this PR for 4.8 (WordPress 5.0.2) as it is a new feature.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks for iterations. It looks good to go 👍

@youknowriad youknowriad modified the milestones: 4.8, 4.9 Dec 19, 2018
@youknowriad youknowriad merged commit 2575d23 into master Jan 4, 2019
@youknowriad youknowriad deleted the add/preview-interstitial-filter branch January 4, 2019 09:40
@leomuniz
Copy link
Contributor

leomuniz commented Jun 27, 2019

Hey guys.
You provided an example of how to use this filter, but I couldn't make it probably due to my lack of experience with Gutenberg. So I would appreciate if someone can offer a more complete solution than only the JS part.

I created a very simple plugin with 2 files only and without React to handle this:

my-plugin.php

<?php
/**
 * Plugin Name: My First Plugin
 * Plugin URI: http://www.mywebsite.com/my-first-plugin
 * Description: The very first plugin that I have ever created.
 * Version: 1.0
 * Author: Your Name
 * Author URI: http://www.mywebsite.com
 */

function enqueue_gutenberg_js() {
		wp_enqueue_script(
				'replace-animation-script',
				plugins_url( 'my-plugin.js', __FILE__ ),
				array( 'wp-element', 'wp-editor', 'wp-hooks' ),
				filemtime( plugin_dir_path( __FILE__ ) . '/my-plugin.js' )
		);
	}

 add_action( 'enqueue_block_editor_assets',  'enqueue_gutenberg_js' );

my-plugin.js

var customPreviewMessage = function() {
    return '<b>Post preview is being generated!</b>';
};

wp.hooks.addFilter( 'editor.PostPreview.interstitialMarkup', 'my-plugin/custom-preview-message', customPreviewMessage );

Of course it's not working and I'm still seeing the default Wordpress logo animation with the same text below it (otherwise I wouldn't be here). But my JS file is loaded successfully when loading Gutenberg Editor (I also added a console.log('test'); after wp.hooks.addFilter and it worked). There is no JS error in console and neither in PHP log files. Does anyone knows what I'm doing wrong? I can think about some possibilities like:

  • Is the enqueue_block_editor_message the proper hook?
  • Are wp-element, wp-editor and wp-hooks the needed dependencies?
  • Is React needed somehow? Even with my JS code being executed with no errors?

Thank you very much

@swissspidy
Copy link
Member Author

@leomuniz would you mind creating a new issue for this? Otherwise this gets easily lost

@leomuniz
Copy link
Contributor

Just opened. Tried to use as many as keywords possible to facilitate other people with similar problem: How to change or hide the Wordpress Animated Logo when loading a a post/page preview #16326

Thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add filter for customising the WordPress logo animation for preview
6 participants