Skip to content

Commit

Permalink
Take the unfiltered_html capability from state (#7729)
Browse files Browse the repository at this point in the history
* Update block-edit

* Update UnknownConverter
  • Loading branch information
nosolosw authored Jul 10, 2018
1 parent 570aa39 commit a3a07b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
14 changes: 4 additions & 10 deletions editor/components/block-edit/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* External dependencies
*/
import { noop, get } from 'lodash';
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { Component, compose } from '@wordpress/element';
import { withAPIData } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -27,13 +26,10 @@ export class BlockEdit extends Component {
}

getChildContext() {
const { user } = this.props;
const { canUserUseUnfilteredHTML } = this.props;

return {
canUserUseUnfilteredHTML: get( user.data, [
'capabilities',
'unfiltered_html',
], false ),
canUserUseUnfilteredHTML,
};
}

Expand Down Expand Up @@ -72,8 +68,6 @@ BlockEdit.childContextTypes = {
export default compose( [
withSelect( ( select ) => ( {
postType: select( 'core/editor' ).getEditedPostAttribute( 'type' ),
} ) ),
withAPIData( ( { postType } ) => ( {
user: `/wp/v2/users/me?post_type=${ postType }&context=edit`,
canUserUseUnfilteredHTML: select( 'core/editor' ).canUserUseUnfilteredHTML(),
} ) ),
] )( BlockEdit );
17 changes: 5 additions & 12 deletions editor/components/block-settings-menu/unknown-converter.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { IconButton, withAPIData } from '@wordpress/components';
import { IconButton } from '@wordpress/components';
import { getUnknownTypeHandlerName, rawHandler, serialize } from '@wordpress/blocks';
import { compose } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';

export function UnknownConverter( { block, onReplace, small, user, role } ) {
export function UnknownConverter( { block, onReplace, small, canUserUseUnfilteredHTML, role } ) {
if ( ! block || getUnknownTypeHandlerName() !== block.name ) {
return null;
}
Expand All @@ -23,7 +18,7 @@ export function UnknownConverter( { block, onReplace, small, user, role } ) {
onReplace( block.uid, rawHandler( {
HTML: serialize( block ),
mode: 'BLOCKS',
canUserUseUnfilteredHTML: get( user, [ 'data', 'capabilities', 'unfiltered_html' ], false ),
canUserUseUnfilteredHTML,
} ) );
};

Expand All @@ -42,16 +37,14 @@ export function UnknownConverter( { block, onReplace, small, user, role } ) {

export default compose(
withSelect( ( select, { uid } ) => {
const { getBlock, getCurrentPostType } = select( 'core/editor' );
const { canUserUseUnfilteredHTML, getBlock, getCurrentPostType } = select( 'core/editor' );
return {
block: getBlock( uid ),
postType: getCurrentPostType(),
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(),
};
} ),
withDispatch( ( dispatch ) => ( {
onReplace: dispatch( 'core/editor' ).replaceBlocks,
} ) ),
withAPIData( ( { postType } ) => ( {
user: `/wp/v2/users/me?post_type=${ postType }&context=edit`,
} ) ),
)( UnknownConverter );

0 comments on commit a3a07b1

Please sign in to comment.