Skip to content

Commit

Permalink
Merge pull request #953 from Hercilio1/feat/slack-sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones authored Jul 27, 2023
2 parents cd24320 + 3d62544 commit 1a1e011
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions php/integrations/yoast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -239,6 +240,36 @@ public static function filter_author_meta( $author_name, $presentation ) {
return $author_name;
}

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 Indexable_Presentation $presentation The presentation of an indexable.
* @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 );

// 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 Author display names separated by commas.
*/
private static function get_authors_display_names_output( $author_objects ) {
$output = '';
foreach ( $author_objects as $i => $author ) {
$output .= $author->display_name;
Expand Down

0 comments on commit 1a1e011

Please sign in to comment.