Skip to content

Commit

Permalink
Revert "Social: Convert OG image from post body (#35038)" (#37368)
Browse files Browse the repository at this point in the history
* Add back the old filter function.

* Fix the project versions
  • Loading branch information
pablinos authored May 15, 2024
1 parent b3f41ac commit 3d6b12f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions projects/packages/publicize/changelog/revert-35038
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Added back the previous OpenGraph filter function
2 changes: 1 addition & 1 deletion projects/packages/publicize/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize",
"version": "0.44.0",
"version": "0.44.1-alpha",
"description": "Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/publicize/#readme",
"bugs": {
Expand Down
33 changes: 32 additions & 1 deletion projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function __construct() {

// Default checkbox state for each Connection.
add_filter( 'publicize_checkbox_default', array( $this, 'publicize_checkbox_default' ), 10, 2 );
add_filter( 'jetpack_open_graph_tags', array( $this, 'jetpack_social_open_graph_filter' ), 12, 1 ); // $priority = 12, to run after Jetpack adds the tags in the Jetpack_Twitter_Cards class.
add_filter( 'jetpack_open_graph_tags', array( $this, 'add_jetpack_social_og_image' ), 12, 1 ); // $priority = 12, to run after Jetpack adds the tags in the Jetpack_Twitter_Cards class.

// Alter the "Post Publish" admin notice to mention the Connections we Publicized to.
add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 20, 1 );
Expand Down Expand Up @@ -1803,6 +1803,37 @@ public function add_jetpack_social_og_image( $tags, $opengraph_image ) {
);
}

/**
* Add the Jetpack Social images (attached media, SIG image) to the OpenGraph tags.
*
* @param array $tags Current tags.
*/
public function add_jetpack_social_og_images( $tags ) {
$opengraph_image = $this->get_social_opengraph_image( get_the_ID() );

if ( empty( $opengraph_image ) ) {
return $tags;
}

// If this code is running in Jetpack, we need to add Twitter cards.
// Some active plugins disable Jetpack's Twitter Cards, so we need
// to check if the class was instantiated before adding the cards.
$needs_twitter_cards = class_exists( 'Jetpack_Twitter_Cards' );

return array_merge(
$tags,
array(
'og:image' => $opengraph_image['url'],
'og:image:width' => $opengraph_image['width'],
'og:image:height' => $opengraph_image['height'],
),
$needs_twitter_cards ? array(
'twitter:image' => $opengraph_image['url'],
'twitter:card' => 'summary_large_image',
) : array()
);
}

/**
* Util
*/
Expand Down

0 comments on commit 3d6b12f

Please sign in to comment.