Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Slack social sharing #953

Merged
merged 2 commits into from
Jul 27, 2023
Merged
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
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