Skip to content
Open
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,088 changes: 2,087 additions & 1 deletion build/index.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions php/api/endpoints/class-coauthors-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ public function get_item_schema(): array {
'context' => array( 'view' ),
'readonly' => true,
),
'term_id' => array(
'description' => __( 'Term ID for the Authors Taxonomy', 'co-authors-plus' ),
'type' => 'integer',
'context' => array( 'view' ),
'readonly' => true,
),
),
);

Expand Down
3 changes: 3 additions & 0 deletions php/class-coauthors-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public function can_edit_coauthors(): bool {
*/
public function _format_author_data( $author ): array {

$term = $this -> coauthors -> get_author_term( $author );

return array(
'id' => esc_html( $author->ID ),
'userNicename' => esc_html( rawurldecode( $author->user_nicename ) ),
Expand All @@ -217,6 +219,7 @@ public function _format_author_data( $author ): array {
'displayName' => esc_html( str_replace( '∣', '|', $author->display_name ) ),
'avatar' => esc_url( get_avatar_url( $author->ID ) ),
'userType' => esc_html( $author->type ),
'termID' => absint( $term -> term_id ),
);
}

Expand Down
1 change: 1 addition & 0 deletions src/components/author-selection/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ AuthorsSelection.propTypes = {
email: PropTypes.string,
displayName: PropTypes.string,
avatar: PropTypes.string,
termID: PropTypes.number,
} ),
] ).isRequired,
updateAuthors: PropTypes.func.isRequired,
Expand Down
13 changes: 13 additions & 0 deletions src/components/co-authors/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,21 @@ const CoAuthors = () => {
const updateAuthors = ( newAuthors ) => {
setAuthorsStore( newAuthors );
setSelectedAuthors( newAuthors );
setPostTerms( newAuthors );
};

const setPostTerms = ( newAuthors ) => {

var authorTerms = [];

newAuthors.forEach(( author ) => {

authorTerms.push( author.termID );
});

wp.data.dispatch('core/editor').editPost({ coauthors: authorTerms } );
}

/**
* Change handler for adding new item by value.
* Updates authors state.
Expand Down
18 changes: 0 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,3 @@ registerPlugin( 'plugin-coauthors-document-setting', {
icon: 'users',
} );

// Save authors when the post is saved.
// https://github.com/WordPress/gutenberg/issues/17632
const { isSavingPost, getCurrentPost } = select("core/editor");
const { getAuthors, saveAuthors } = select("cap/authors");

let checked = true; // Start in a checked state.

subscribe(() => {
if (isSavingPost()) {
checked = false;
} else if (!checked) {
const { id } = getCurrentPost();
const authors = getAuthors(id);
saveAuthors(id, authors);
checked = true;
}
});

4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ export const addItemByValue = (
* @param {string} root0.userNicename The unique username.
* @param {string} root0.email The author's email address.
* @param {string} root0.userType The entity type, either 'wpuser' or 'guest-user'.
* @param {string} root0.termID The ID for the user's term in the "author" taxonomy
*
* @return {Object} The object containing data relevant to the Coauthors component.
*/
export const formatAuthorData = ( { id, displayName, userNicename, email, userType } ) => {
export const formatAuthorData = ( { id, displayName, userNicename, email, userType, termID } ) => {
return {
id,
label: `${ displayName } | ${ email }`,
display: displayName,
value: userNicename,
userType,
termID,
};
};