Skip to content

Commit

Permalink
Editor: Deprecate canUserUseUnfilteredHTML selector
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Dec 5, 2019
1 parent 2b874bd commit 1725e45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 46 deletions.
12 changes: 0 additions & 12 deletions docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ _Related_

- canInsertBlockType in core/block-editor store.

<a name="canUserUseUnfilteredHTML" href="#canUserUseUnfilteredHTML">#</a> **canUserUseUnfilteredHTML**

Returns whether or not the user has the unfiltered_html capability.

_Parameters_

- _state_ `Object`: Editor state.

_Returns_

- `boolean`: Whether the user can or can't post unfiltered HTML.

<a name="didPostSaveRequestFail" href="#didPostSaveRequestFail">#</a> **didPostSaveRequestFail**

Returns true if a previous post save was attempted but failed, or false
Expand Down
30 changes: 18 additions & 12 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {
find,
get,
has,
map,
pick,
mapValues,
Expand Down Expand Up @@ -1156,17 +1155,6 @@ export function getActivePostLock( state ) {
return state.postLock.activePostLock;
}

/**
* Returns whether or not the user has the unfiltered_html capability.
*
* @param {Object} state Editor state.
*
* @return {boolean} Whether the user can or can't post unfiltered HTML.
*/
export function canUserUseUnfilteredHTML( state ) {
return has( getCurrentPost( state ), [ '_links', 'wp:action-unfiltered-html' ] );
}

/**
* Returns whether the pre-publish panel should be shown
* or skipped when the user clicks the "publish" button.
Expand Down Expand Up @@ -1248,6 +1236,24 @@ export function getEditorSettings( state ) {
* Backward compatibility
*/

/**
* Returns whether or not the user has the unfiltered_html capability.
*
* @deprecated
* @private
*
* @param {Object} state Editor state.
*
* @return {boolean} Whether the user can or can't post unfiltered HTML.
*/
export const canUserUseUnfilteredHTML = createRegistrySelector( ( select ) => ( state ) => {
deprecated( '`wp.data.select( \'core/editor\' ).canUserUseUnfilteredHTML`', {
alternative: '`wp.data.select( \'core\' ).canUser( \'unfiltered-html\', \'posts\', wp.data.select( \'core/editor\' ).getCurrentPostId() )`',
} );

return select( 'core' ).canUser( 'unfiltered-html', 'posts', getCurrentPostId( state ) );
} );

function getBlockEditorSelector( name ) {
return createRegistrySelector( ( select ) => ( state, ...args ) => {
deprecated( '`wp.data.select( \'core/editor\' ).' + name + '`', {
Expand Down
22 changes: 0 additions & 22 deletions packages/editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ const {
getPermalinkParts,
isPostSavingLocked,
isPostAutosavingLocked,
canUserUseUnfilteredHTML,
} = selectors;

describe( 'selectors', () => {
Expand Down Expand Up @@ -2770,25 +2769,4 @@ describe( 'selectors', () => {
expect( getPermalinkParts( state ) ).toBeNull();
} );
} );

describe( 'canUserUseUnfilteredHTML', () => {
it( 'should return true if the _links object contains the property wp:action-unfiltered-html', () => {
const state = {
currentPost: {
_links: {
'wp:action-unfiltered-html': [],
},
},
};
expect( canUserUseUnfilteredHTML( state ) ).toBe( true );
} );
it( 'should return false if the _links object doesnt contain the property wp:action-unfiltered-html', () => {
const state = {
currentPost: {
_links: {},
},
};
expect( canUserUseUnfilteredHTML( state ) ).toBe( false );
} );
} );
} );

0 comments on commit 1725e45

Please sign in to comment.