diff options
Diffstat (limited to 'plugins/jetpack/class.jetpack-twitter-cards.php')
-rw-r--r-- | plugins/jetpack/class.jetpack-twitter-cards.php | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/plugins/jetpack/class.jetpack-twitter-cards.php b/plugins/jetpack/class.jetpack-twitter-cards.php index 5b629eb0..1cb5bcf3 100644 --- a/plugins/jetpack/class.jetpack-twitter-cards.php +++ b/plugins/jetpack/class.jetpack-twitter-cards.php @@ -26,6 +26,15 @@ class Jetpack_Twitter_Cards { * These tags apply to any page (home, archives, etc) */ + // If we have information on the author/creator, then include that as well + if ( ! empty( $post ) && ! empty( $post->post_author ) ) { + /** This action is documented in modules/sharedaddy/sharing-sources.php */ + $handle = apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID ); + if ( ! empty( $handle ) && ! self::is_default_site_tag( $handle ) ) { + $og_tags['twitter:creator'] = self::sanitize_twitter_user( $handle ); + } + } + $site_tag = self::site_tag(); /** This action is documented in modules/sharedaddy/sharing-sources.php */ $site_tag = apply_filters( 'jetpack_sharing_twitter_via', $site_tag, ( is_singular() ? $post->ID : null ) ); @@ -107,15 +116,6 @@ class Jetpack_Twitter_Cards { $og_tags['twitter:card'] = $card_type; - // If we have information on the author/creator, then include that as well - if ( ! empty( $post ) && ! empty( $post->post_author ) ) { - /** This action is documented in modules/sharedaddy/sharing-sources.php */ - $handle = apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID ); - if ( ! empty( $handle ) && 'wordpressdotcom' != $handle && 'jetpack' != $handle ) { - $og_tags['twitter:creator'] = self::sanitize_twitter_user( $handle ); - } - } - // Make sure we have a description for Twitter, their validator isn't happy without some content (single space not valid). if ( ! isset( $og_tags['og:description'] ) || '' == trim( $og_tags['og:description'] ) || __('Visit the post for more.', 'jetpack') == $og_tags['og:description'] ) { // empty( trim( $og_tags['og:description'] ) ) isn't valid php $has_creator = ( ! empty($og_tags['twitter:creator']) && '@wordpressdotcom' != $og_tags['twitter:creator'] ) ? true : false; @@ -143,9 +143,13 @@ class Jetpack_Twitter_Cards { return '@' . preg_replace( '/^@/', '', $str ); } + static function is_default_site_tag( $site_tag ) { + return in_array( $site_tag, array( '@wordpressdotcom', '@jetpack', 'wordpressdotcom', 'jetpack' ) ); + } + static function prioritize_creator_over_default_site( $site_tag, $og_tags = array() ) { - if ( ! empty( $og_tags['twitter:creator'] ) && in_array( $site_tag, array( '@wordpressdotcom', '@jetpack' ) ) ) { - $site_tag = $og_tags['twitter:creator']; + if ( ! empty( $og_tags['twitter:creator'] ) && self::is_default_site_tag( $site_tag ) ) { + return $og_tags['twitter:creator']; } return $site_tag; } |