From 2575d239c586a45c86935dd0b07e11e2b1ca00ca Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 4 Jan 2019 10:40:24 +0100 Subject: [PATCH] Add filter for preview interstitial markup (#12463) --- .../developers/filters/editor-filters.md | 14 ++++++++++++++ .../src/components/post-preview-button/index.js | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/designers-developers/developers/filters/editor-filters.md b/docs/designers-developers/developers/filters/editor-filters.md index 1289b8241936ba..a205d583103b02 100644 --- a/docs/designers-developers/developers/filters/editor-filters.md +++ b/docs/designers-developers/developers/filters/editor-filters.md @@ -16,3 +16,17 @@ var withImageSize = function( size, mediaId, postId ) { wp.hooks.addFilter( 'editor.PostFeaturedImage.imageSize', 'my-plugin/with-image-size', withImageSize ); ``` +### `editor.PostPreview.interstitialMarkup` + +Filters the interstitial message shown when generating previews. + +_Example:_ + +```js +var customPreviewMessage = function() { + return 'Post preview is being generated!'; +}; + +wp.hooks.addFilter( 'editor.PostPreview.interstitialMarkup', 'my-plugin/custom-preview-message', customPreviewMessage ); +``` + diff --git a/packages/editor/src/components/post-preview-button/index.js b/packages/editor/src/components/post-preview-button/index.js index b735ebcd5324ed..265daa1a7db3fe 100644 --- a/packages/editor/src/components/post-preview-button/index.js +++ b/packages/editor/src/components/post-preview-button/index.js @@ -12,6 +12,7 @@ import { __, _x } from '@wordpress/i18n'; import { withSelect, withDispatch } from '@wordpress/data'; import { DotTip } from '@wordpress/nux'; import { ifCondition, compose } from '@wordpress/compose'; +import { applyFilters } from '@wordpress/hooks'; function writeInterstitialMessage( targetDocument ) { let markup = renderToString( @@ -79,6 +80,13 @@ function writeInterstitialMessage( targetDocument ) { `; + /** + * Filters the interstitial message shown when generating previews. + * + * @param {String} markup The preview interstitial markup. + */ + markup = applyFilters( 'editor.PostPreview.interstitialMarkup', markup ); + targetDocument.write( markup ); targetDocument.title = __( 'Generating preview…' ); targetDocument.close();