Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ _Returns_

### getAuthors

> **Deprecated** since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.

Returns all available authors.

_Parameters_
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ _This package assumes that your code will run in an **ES2015+** environment. If
Below is an example of a component which simply renders a list of authors:

```jsx
const { withSelect } = wp.data;
const { useSelect } = wp.data;

function MyAuthorsListBase() {
const authors = useSelect( ( select ) => {
return select( 'core' ).getUsers( { who: 'authors' } );
}, [] );

if ( ! authors ) {
return null;
}

function MyAuthorsListBase( { authors } ) {
return (
<ul>
{ authors.map( ( author ) => (
Expand All @@ -30,10 +38,6 @@ function MyAuthorsListBase( { authors } ) {
</ul>
);
}

const MyAuthorsList = withSelect( ( select ) => ( {
authors: select( 'core' ).getAuthors(),
} ) )( MyAuthorsListBase );
```

## Actions
Expand Down Expand Up @@ -290,6 +294,8 @@ _Returns_

### getAuthors

> **Deprecated** since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.

Returns all available authors.

_Parameters_
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@wordpress/blocks": "file:../blocks",
"@wordpress/data": "file:../data",
"@wordpress/data-controls": "file:../data-controls",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/element": "file:../element",
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
Expand Down
11 changes: 0 additions & 11 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ export function* getAuthors( query ) {
yield receiveUserQuery( path, users );
}

/**
* Temporary approach to resolving editor access to author queries.
*
* @param {number} id The author id.
*/
export function* __unstableGetAuthor( id ) {
const path = `/wp/v2/users?who=authors&include=${ id }`;
const users = yield apiFetch( { path } );
yield receiveUserQuery( 'author', users );
}

/**
* Requests the current user from the REST API.
*/
Expand Down
20 changes: 8 additions & 12 deletions packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { set, map, find, get, filter, compact } from 'lodash';
*/
import { createRegistrySelector } from '@wordpress/data';
import { addQueryArgs } from '@wordpress/url';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -47,31 +48,26 @@ export const isRequestingEmbedPreview = createRegistrySelector(
/**
* Returns all available authors.
*
* @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
*
* @param {Object} state Data state.
* @param {Object|undefined} query Optional object of query parameters to
* include with request.
* @return {Array} Authors list.
*/
export function getAuthors( state, query ) {
deprecated( "select( 'core' ).getAuthors()", {
since: '5.9',
alternative: "select( 'core' ).getUsers({ who: 'authors' })",
} );

const path = addQueryArgs(
'/wp/v2/users/?who=authors&per_page=100',
query
);
return getUserQueryResults( state, path );
}

/**
* Returns all available authors.
*
* @param {Object} state Data state.
* @param {number} id The author id.
*
* @return {Array} Authors list.
*/
export function __unstableGetAuthor( state, id ) {
return get( state, [ 'users', 'byId', id ], null );
}

/**
* Returns the current user.
*
Expand Down