From abbd3584a85a9a44525ecd5ef0dfe34c7e109d4d Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 10 Apr 2025 11:32:06 -0300 Subject: [PATCH 1/5] Add id to store formatted author data --- src/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 4a3f9ec8..5f4956a1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -72,8 +72,9 @@ export const addItemByValue = ( * * @return {Object} The object containing data relevant to the Coauthors component. */ -export const formatAuthorData = ( { displayName, userNicename, email } ) => { +export const formatAuthorData = ( { id, displayName, userNicename, email } ) => { return { + id, label: `${ displayName } | ${ email }`, display: displayName, value: userNicename, From eaf5107370cb890dfc267b1c89e40804ab0afdfc Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 10 Apr 2025 14:38:40 -0300 Subject: [PATCH 2/5] chore: update docblock --- src/utils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 5f4956a1..3b115286 100644 --- a/src/utils.js +++ b/src/utils.js @@ -66,9 +66,10 @@ export const addItemByValue = ( * Format the author option object. * * @param {Object} root0 An author object from the API endpoint. - * @param {Object} root0.displayName Name to display in the UI. - * @param {Object} root0.userNicename The unique username. - * @param {Object} root0.email + * @param {string} root0.id The author ID. + * @param {string} root0.displayName Name to display in the UI. + * @param {string} root0.userNicename The unique username. + * @param {string} root0.email The author's email address. * * @return {Object} The object containing data relevant to the Coauthors component. */ From 752e244fac34e7ecd31fb799c20aed9553e6c4e0 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 10 Apr 2025 15:02:54 -0300 Subject: [PATCH 3/5] feat: include entity type --- php/class-coauthors-endpoint.php | 1 + src/utils.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/php/class-coauthors-endpoint.php b/php/class-coauthors-endpoint.php index cfeb2c15..4631af0a 100644 --- a/php/class-coauthors-endpoint.php +++ b/php/class-coauthors-endpoint.php @@ -216,6 +216,7 @@ public function _format_author_data( $author ): array { 'email' => sanitize_email( $author->user_email ), 'displayName' => esc_html( str_replace( '∣', '|', $author->display_name ) ), 'avatar' => esc_url( get_avatar_url( $author->ID ) ), + 'userType' => $author->type, ); } diff --git a/src/utils.js b/src/utils.js index 3b115286..c3c8fe16 100644 --- a/src/utils.js +++ b/src/utils.js @@ -70,14 +70,16 @@ export const addItemByValue = ( * @param {string} root0.displayName Name to display in the UI. * @param {string} root0.userNicename The unique username. * @param {string} root0.email The author's email address. + * @param {string} root0.userType The entity type, either 'wp-user' or 'guest-user'. * * @return {Object} The object containing data relevant to the Coauthors component. */ -export const formatAuthorData = ( { id, displayName, userNicename, email } ) => { +export const formatAuthorData = ( { id, displayName, userNicename, email, userType } ) => { return { id, label: `${ displayName } | ${ email }`, display: displayName, value: userNicename, + userType, }; }; From 36cfb450a47e69eaa4ed7f037f846b38c223ad54 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 10 Apr 2025 15:04:31 -0300 Subject: [PATCH 4/5] fix: docblock --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index c3c8fe16..cb5e8146 100644 --- a/src/utils.js +++ b/src/utils.js @@ -70,7 +70,7 @@ export const addItemByValue = ( * @param {string} root0.displayName Name to display in the UI. * @param {string} root0.userNicename The unique username. * @param {string} root0.email The author's email address. - * @param {string} root0.userType The entity type, either 'wp-user' or 'guest-user'. + * @param {string} root0.userType The entity type, either 'wpuser' or 'guest-user'. * * @return {Object} The object containing data relevant to the Coauthors component. */ From 33ceb2d3e64caa114733abc29237751734c2cc25 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 10 Apr 2025 16:34:09 -0300 Subject: [PATCH 5/5] fix: follow return standard --- php/class-coauthors-endpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-endpoint.php b/php/class-coauthors-endpoint.php index 4631af0a..d7424265 100644 --- a/php/class-coauthors-endpoint.php +++ b/php/class-coauthors-endpoint.php @@ -216,7 +216,7 @@ public function _format_author_data( $author ): array { 'email' => sanitize_email( $author->user_email ), 'displayName' => esc_html( str_replace( '∣', '|', $author->display_name ) ), 'avatar' => esc_url( get_avatar_url( $author->ID ) ), - 'userType' => $author->type, + 'userType' => esc_html( $author->type ), ); }