Skip to content

Commit

Permalink
Merge pull request #21631 from Yoast/21630-refactor-sitewide_social_i…
Browse files Browse the repository at this point in the history
…mage-preference

21630 refactor sitewide social image preference
  • Loading branch information
thijsoo committed Sep 16, 2024
2 parents 9e615c6 + db295e4 commit a9d9992
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 42 deletions.
1 change: 0 additions & 1 deletion admin/formatter/class-metabox-formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private function get_defaults() {

$defaults = [
'author_name' => get_the_author_meta( 'display_name' ),
'sitewide_social_image' => WPSEO_Options::get( 'og_default_image' ),
'keyword_usage' => [],
'title_template' => '',
'metadesc_template' => '',
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/elementor/initializers/editor-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const populateStore = store => {
store.dispatch(
actions.setSettings( {
socialPreviews: {
sitewideImage: window.wpseoScriptData.metabox.sitewide_social_image,
sitewideImage: window.wpseoScriptData.sitewideSocialImage,
siteName: window.wpseoScriptData.metabox.site_name,
contentImage: window.wpseoScriptData.metabox.first_content_image,
twitterCardType: window.wpseoScriptData.metabox.twitterCardType,
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/initializers/editor-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const populateStore = store => {
store.dispatch(
actions.setSettings( {
socialPreviews: {
sitewideImage: window.wpseoScriptData.metabox.sitewide_social_image,
sitewideImage: window.wpseoScriptData.sitewideSocialImage,
siteName: window.wpseoScriptData.metabox.site_name,
contentImage: window.wpseoScriptData.metabox.first_content_image,
twitterCardType: window.wpseoScriptData.metabox.twitterCardType,
Expand Down
15 changes: 14 additions & 1 deletion src/editors/framework/site/base-site-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yoast\WP\SEO\Editors\Framework\Site;

use Exception;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
Expand Down Expand Up @@ -41,6 +42,13 @@ abstract class Base_Site_Information {
*/
protected $product_helper;

/**
* The options helper.
*
* @var Options_Helper $options_helper
*/
protected $options_helper;

/**
* The constructor.
*
Expand All @@ -49,17 +57,20 @@ abstract class Base_Site_Information {
* repository.
* @param Meta_Surface $meta The meta surface.
* @param Product_Helper $product_helper The product helper.
* @param Options_Helper $options_helper The options helper.
*/
public function __construct(
Short_Link_Helper $short_link_helper,
Wistia_Embed_Permission_Repository $wistia_embed_permission_repository,
Meta_Surface $meta,
Product_Helper $product_helper
Product_Helper $product_helper,
Options_Helper $options_helper
) {
$this->short_link_helper = $short_link_helper;
$this->wistia_embed_permission_repository = $wistia_embed_permission_repository;
$this->meta = $meta;
$this->product_helper = $product_helper;
$this->options_helper = $options_helper;
}

/**
Expand All @@ -80,6 +91,7 @@ public function get_site_information(): array {
'isRtl' => \is_rtl(),
'isPremium' => $this->product_helper->is_premium(),
'siteIconUrl' => \get_site_icon_url(),
'sitewideSocialImage' => $this->options_helper->get( 'og_default_image' ),
// phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962.
'isPrivateBlog' => ( (string) \get_option( 'blog_public' ) ) === '0',
];
Expand All @@ -97,6 +109,7 @@ public function get_legacy_site_information(): array {
'linkParams' => $this->short_link_helper->get_query_params(),
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ),
'sitewideSocialImage' => $this->options_helper->get( 'og_default_image' ),
// phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962.
'isPrivateBlog' => ( (string) \get_option( 'blog_public' ) ) === '0',
'metabox' => [
Expand Down
7 changes: 5 additions & 2 deletions src/editors/framework/site/post-site-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yoast\WP\SEO\Editors\Framework\Site;

use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
Expand Down Expand Up @@ -45,6 +46,7 @@ class Post_Site_Information extends Base_Site_Information {
* @param Meta_Surface $meta The meta surface.
* @param Product_Helper $product_helper The product helper.
* @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action.
* @param Options_Helper $options_helper The options helper.
*
* @return void
*/
Expand All @@ -54,9 +56,10 @@ public function __construct(
Wistia_Embed_Permission_Repository $wistia_embed_permission_repository,
Meta_Surface $meta,
Product_Helper $product_helper,
Alert_Dismissal_Action $alert_dismissal_action
Alert_Dismissal_Action $alert_dismissal_action,
Options_Helper $options_helper
) {
parent::__construct( $short_link_helper, $wistia_embed_permission_repository, $meta, $product_helper );
parent::__construct( $short_link_helper, $wistia_embed_permission_repository, $meta, $product_helper, $options_helper );
$this->promotion_manager = $promotion_manager;
$this->alert_dismissal_action = $alert_dismissal_action;
}
Expand Down
33 changes: 0 additions & 33 deletions src/editors/framework/site/term-site-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@

use WP_Taxonomy;
use WP_Term;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
use Yoast\WP\SEO\Surfaces\Meta_Surface;

/**
* The Term_Site_Information class.
*/
class Term_Site_Information extends Base_Site_Information {

/**
* The options helper.
*
* @var Options_Helper
*/
private $options_helper;

/**
* The taxonomy.
*
Expand All @@ -36,27 +24,6 @@ class Term_Site_Information extends Base_Site_Information {
*/
private $term;

/**
* The constructor.
*
* @param Options_Helper $options_helper The options helper.
* @param Short_Link_Helper $short_link_helper The short link helper.
* @param Wistia_Embed_Permission_Repository $wistia_embed_permission_repository The wistia embed permission
* repository.
* @param Meta_Surface $meta The meta surface.
* @param Product_Helper $product_helper The product helper.
*/
public function __construct(
Options_Helper $options_helper,
Short_Link_Helper $short_link_helper,
Wistia_Embed_Permission_Repository $wistia_embed_permission_repository,
Meta_Surface $meta,
Product_Helper $product_helper
) {
parent::__construct( $short_link_helper, $wistia_embed_permission_repository, $meta, $product_helper );
$this->options_helper = $options_helper;
}

/**
* Sets the term for the information object and retrieves its taxonomy.
*
Expand Down
16 changes: 15 additions & 1 deletion tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mockery;
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
Expand Down Expand Up @@ -68,6 +69,13 @@ final class Post_Site_Information_Test extends TestCase {
*/
private $product_helper;

/**
* The options helper.
*
* @var Mockery\MockInterface|Options_Helper $options_helper
*/
private $options_helper;

/**
* The Post_Site_Information container.
*
Expand All @@ -88,8 +96,9 @@ protected function set_up() {
$this->meta_surface = Mockery::mock( Meta_Surface::class );
$this->product_helper = Mockery::mock( Product_Helper::class );
$this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class );
$this->options_helper = Mockery::mock( Options_Helper::class );

$this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action );
$this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action, $this->options_helper );
$this->instance->set_permalink( 'perma' );
$this->set_mocks();
}
Expand Down Expand Up @@ -136,7 +145,9 @@ public function test_legacy_site_information() {
],
'pluginUrl' => '/location',
'wistiaEmbedPermission' => true,
'sitewideSocialImage' => null,
'isPrivateBlog' => false,

];

Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' );
Expand All @@ -146,6 +157,7 @@ public function test_legacy_site_information() {
$this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] );
$this->promotion_manager->expects( 'is' )->andReturnFalse();
$this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' );
$this->options_helper->expects( 'get' )->with( 'og_default_image' )->andReturn( null );

$this->assertSame( $expected, $this->instance->get_legacy_site_information() );
}
Expand Down Expand Up @@ -191,6 +203,7 @@ public function test_site_information() {
'isRtl' => false,
'isPremium' => true,
'siteIconUrl' => 'https://example.org',
'sitewideSocialImage' => null,
'isPrivateBlog' => false,
];

Expand All @@ -205,6 +218,7 @@ public function test_site_information() {
$this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] );
$this->promotion_manager->expects( 'is' )->andReturnFalse();
$this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' );
$this->options_helper->expects( 'get' )->with( 'og_default_image' )->andReturn( null );

$this->assertSame( $expected, $this->instance->get_site_information() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function set_up() {
$this->meta_surface = Mockery::mock( Meta_Surface::class );
$this->product_helper = Mockery::mock( Product_Helper::class );

$this->instance = new Term_Site_Information( $this->options_helper, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper );
$this->instance = new Term_Site_Information( $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->options_helper );
$taxonomy = Mockery::mock( WP_Taxonomy::class )->makePartial();
$taxonomy->rewrite = false;
$mock_term = Mockery::mock( WP_Term::class )->makePartial();
Expand All @@ -93,6 +93,7 @@ protected function set_up() {

$this->instance->set_term( $mock_term );
$this->options_helper->expects( 'get' )->with( 'stripcategorybase', false )->andReturnFalse();
$this->options_helper->expects( 'get' )->with( 'og_default_image' )->andReturn( null );

$this->set_mocks();
}
Expand Down Expand Up @@ -127,6 +128,7 @@ public function test_site_information() {
'isRtl' => false,
'isPremium' => true,
'siteIconUrl' => 'https://example.org',
'sitewideSocialImage' => null,
'isPrivateBlog' => true,
];

Expand Down Expand Up @@ -173,6 +175,7 @@ public function test_legacy_site_information() {
],
'pluginUrl' => '/location',
'wistiaEmbedPermission' => true,
'sitewideSocialImage' => null,
'isPrivateBlog' => false,
];

Expand Down
13 changes: 12 additions & 1 deletion tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Mockery;
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
Expand Down Expand Up @@ -64,6 +65,13 @@ final class Post_Site_Information_Test extends TestCase {
*/
private $product_helper;

/**
* The options helper.
*
* @var Mockery\MockInterface|Options_Helper $options_helper
*/
private $options_helper;

/**
* The Post_Site_Information container.
*
Expand All @@ -84,9 +92,10 @@ public function set_up() {
$this->wistia_embed_repo->expects( 'get_value_for_user' )->with( 0 )->andReturnTrue();
$this->meta_surface = \YoastSEO()->meta;
$this->product_helper = \YoastSEO()->helpers->product;
$this->options_helper = \YoastSEO()->helpers->options;
$this->alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class );

$this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action );
$this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action, $this->options_helper );
$this->instance->set_permalink( 'perma' );
}

Expand Down Expand Up @@ -124,6 +133,7 @@ public function test_legacy_site_information() {
'linkParams' => $this->short_link_helper->get_query_params(),
'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo',
'wistiaEmbedPermission' => true,
'sitewideSocialImage' => '',
'isPrivateBlog' => false,
];

Expand Down Expand Up @@ -163,6 +173,7 @@ public function test_site_information() {
'isRtl' => false,
'isPremium' => false,
'siteIconUrl' => '',
'sitewideSocialImage' => '',
'isPrivateBlog' => true,
];

Expand Down

0 comments on commit a9d9992

Please sign in to comment.