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

Use guest authors in Slack preview when needed #947

Merged
merged 1 commit into from
May 3, 2021
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
15 changes: 15 additions & 0 deletions includes/class-patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Patches {
*/
public static function init() {
add_filter( 'redirect_canonical', [ __CLASS__, 'patch_redirect_canonical' ], 10, 2 );
add_filter( 'wpseo_enhanced_slack_data', [ __CLASS__, 'use_cap_for_slack_preview' ] );
}

/**
Expand Down Expand Up @@ -68,5 +69,19 @@ public static function patch_redirect_canonical( $redirect_url, $requested_url )
// Otherwise, do redirect.
return $redirect_url;
}

/**
* Use the Co-Author in Slack preview metadata instead of the regular post author if needed.
*
* @param array $slack_data Array of data which will be output in twitter:data tags.
* @return array Modified $slack_data
*/
public static function use_cap_for_slack_preview( $slack_data ) {
if ( function_exists( 'coauthors' ) && is_single() && isset( $slack_data[ __( 'Written by', 'wordpress-seo' ) ] ) ) {
$slack_data[ __( 'Written by', 'wordpress-seo' ) ] = coauthors( null, null, null, null, false );
}

return $slack_data;
}
}
Patches::init();