Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Improve docs for PostFeaturedImage
- Loading branch information
Showing
2 changed files
with
42 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,59 @@ | ||
PostFeaturedImage | ||
=========== | ||
|
||
PostFeaturedImage is a React component used to render the Post Featured Image selection tool. | ||
`PostFeaturedImage` is a React component used to render the Post Featured Image selection tool. | ||
|
||
## Setup | ||
|
||
It includes a `wp.hooks` filter `editor.PostFeaturedImage` that enables developers to replace or extend it. | ||
|
||
## Examples | ||
_Examples:_ | ||
|
||
Replace the contents of the panel: | ||
|
||
```js | ||
function replacePostFeaturedImage() { | ||
return function() { | ||
return wp.element.createElement( | ||
'div', | ||
{}, | ||
'The replacement contents or components.' | ||
); | ||
} | ||
} | ||
|
||
wp.hooks.addFilter( | ||
'editor.PostFeaturedImage', | ||
'myplugin/myhook', | ||
function() { | ||
return function() { | ||
return wp.element.createElement( | ||
'div', | ||
{}, | ||
'The replacement contents or components.' | ||
); | ||
} | ||
} | ||
'my-plugin/replace-post-featured-image', | ||
replacePostFeaturedImage | ||
); | ||
``` | ||
|
||
Prepend/Append to the panel contents: | ||
Prepend and append to the panel contents: | ||
|
||
```js | ||
var el = wp.element.createElement; | ||
|
||
function wrapPostFeaturedImage( OriginalComponent ) { | ||
return function( props ) { | ||
return ( | ||
el( | ||
wp.element.Fragment, | ||
{}, | ||
'Prepend above', | ||
el( | ||
OriginalComponent, | ||
props | ||
), | ||
'Append below' | ||
) | ||
); | ||
} | ||
} | ||
|
||
wp.hooks.addFilter( | ||
'editor.PostFeaturedImage', | ||
'myplugin/myhook', | ||
function( original ) { | ||
return function() { | ||
return ( | ||
wp.element.createElement( | ||
'div', | ||
{ key: 'outer' + Math.random() }, | ||
[ | ||
'Prepend above', | ||
_.extend( original( {} ), { key: 'my-key' } ), | ||
'Append below' | ||
] | ||
) | ||
); | ||
} | ||
} | ||
'my-plugin/wrap-post-featured-image', | ||
wrapPostFeaturedImage | ||
); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.