From d3b7cf6c91b6c426fd9f1a8b5f72c0efe4659723 Mon Sep 17 00:00:00 2001 From: "Hercilio M. Ortiz" Date: Tue, 25 Jul 2023 21:35:31 -0300 Subject: [PATCH 1/2] Feat: Add Slack social sharing - Regarding the issue #952, compatibility of the Co-Authors Plus with Yoast Slack sharing --- php/integrations/yoast.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/php/integrations/yoast.php b/php/integrations/yoast.php index d47489ec..baddea23 100644 --- a/php/integrations/yoast.php +++ b/php/integrations/yoast.php @@ -83,6 +83,7 @@ public static function register_hooks() { add_filter( 'wpseo_schema_author', [ __CLASS__, 'filter_author_graph' ], 11, 4 ); add_filter( 'wpseo_schema_profilepage', [ __CLASS__, 'filter_schema_profilepage' ], 11, 4 ); add_filter( 'wpseo_meta_author', [ __CLASS__, 'filter_author_meta' ], 11, 2 ); + add_filter( 'wpseo_enhanced_slack_data', [__CLASS__, 'filter_slack_data'], 10, 2 ); add_filter( 'wpseo_robots_array', [ __CLASS__, 'allow_indexing_guest_author_archive' ], 10, 2 ); add_filter( 'wpseo_opengraph_url', [ __CLASS__, 'fix_guest_author_archive_url_presenter' ], 10, 2 ); } @@ -239,6 +240,38 @@ public static function filter_author_meta( $author_name, $presentation ) { return $author_name; } + $output = self::get_authors_display_names_output( $author_objects ); + return $output; + } + + /** + * Filter the enhanced data for sharing on Slack. + * + * @param array $data The enhanced Slack sharing data. + * @param Indexable_Presentation $presentation The presentation of an indexable. + * @return array + */ + public static function filter_slack_data( $data, $presentation ) { + $author_objects = get_coauthors( $presentation->context->post->id ); + + // Fallback in case of error. + if ( empty( $author_objects ) ) { + return $data; + } + + $output = self::get_authors_display_names_output( $author_objects ); + $data[ \__( 'Written by', 'wordpress-seo' ) ] = $output; + return $data; + } + + /** + * Returns the list of authors display names separated by commas. + * + * @param WP_User[] $author_objects The list of authors. + * + * @return string + */ + private static function get_authors_display_names_output( $author_objects ) { $output = ''; foreach ( $author_objects as $i => $author ) { $output .= $author->display_name; From 3d6254466f2afe9368278299c0c3d84bd76bb361 Mon Sep 17 00:00:00 2001 From: "Hercilio M. Ortiz" Date: Wed, 26 Jul 2023 21:05:50 -0300 Subject: [PATCH 2/2] Update: Reviewing php/integration/yoast.php - Nitpicks pointed in #953 --- php/integrations/yoast.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/php/integrations/yoast.php b/php/integrations/yoast.php index baddea23..208b4387 100644 --- a/php/integrations/yoast.php +++ b/php/integrations/yoast.php @@ -240,16 +240,15 @@ public static function filter_author_meta( $author_name, $presentation ) { return $author_name; } - $output = self::get_authors_display_names_output( $author_objects ); - return $output; + return self::get_authors_display_names_output( $author_objects ); } /** * Filter the enhanced data for sharing on Slack. * - * @param array $data The enhanced Slack sharing data. + * @param array $data The enhanced Slack sharing data. * @param Indexable_Presentation $presentation The presentation of an indexable. - * @return array + * @return array The potentially amended enhanced Slack sharing data. */ public static function filter_slack_data( $data, $presentation ) { $author_objects = get_coauthors( $presentation->context->post->id ); @@ -268,8 +267,7 @@ public static function filter_slack_data( $data, $presentation ) { * Returns the list of authors display names separated by commas. * * @param WP_User[] $author_objects The list of authors. - * - * @return string + * @return string Author display names separated by commas. */ private static function get_authors_display_names_output( $author_objects ) { $output = '';