Skip to content

Commit a8b9d42

Browse files
committed
Add is_person_mode method - prevents code duplication
1 parent a7f0218 commit a8b9d42

1 file changed

Lines changed: 38 additions & 20 deletions

File tree

classes/suggested-tasks/providers/integrations/yoast/class-organization-logo.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public function __construct() {
4141
$this->yoast_seo = \YoastSEO();
4242
}
4343

44+
/**
45+
* Check if the site is in person mode.
46+
*
47+
* @return bool
48+
*/
49+
protected function is_person_mode() {
50+
return 'person' === $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ); // @phpstan-ignore-line property.nonObject
51+
}
52+
4453
/**
4554
* Get the task URL.
4655
*
@@ -56,9 +65,9 @@ protected function get_url() {
5665
* @return string
5766
*/
5867
protected function get_title() {
59-
return $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' // @phpstan-ignore-line property.nonObject
60-
? \esc_html__( 'Yoast SEO: set your organization logo', 'progress-planner' )
61-
: \esc_html__( 'Yoast SEO: set your person logo', 'progress-planner' );
68+
return $this->is_person_mode()
69+
? \esc_html__( 'Yoast SEO: set your person logo', 'progress-planner' )
70+
: \esc_html__( 'Yoast SEO: set your organization logo', 'progress-planner' );
6271
}
6372

6473
/**
@@ -67,9 +76,9 @@ protected function get_title() {
6776
* @return string
6877
*/
6978
public function get_external_link_url() {
70-
return $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' // @phpstan-ignore-line property.nonObject
71-
? \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-person-logo' )
72-
: \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-organization-logo' );
79+
return $this->is_person_mode()
80+
? \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-organization-logo' )
81+
: \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-person-logo' );
7382
}
7483

7584
/**
@@ -118,15 +127,15 @@ public function should_add_task() {
118127
return false;
119128
}
120129

121-
// If the site is for a person, and the person logo is already set, we don't need to add the task.
122-
if ( $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) === 'company' // @phpstan-ignore-line property.nonObject
130+
// If the site is for a company, and the company logo is already set, we don't need to add the task.
131+
if ( ! $this->is_person_mode()
123132
&& $this->yoast_seo->helpers->options->get( 'company_logo' ) // @phpstan-ignore-line property.nonObject
124133
) {
125134
return false;
126135
}
127136

128-
// If the site is for a person, and the organization logo is already set, we don't need to add the task.
129-
if ( $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) === 'person' // @phpstan-ignore-line property.nonObject
137+
// If the site is for a person, and the person logo is already set, we don't need to add the task.
138+
if ( $this->is_person_mode()
130139
&& $this->yoast_seo->helpers->options->get( 'person_logo' ) // @phpstan-ignore-line property.nonObject
131140
) {
132141
return false;
@@ -142,16 +151,19 @@ public function should_add_task() {
142151
*/
143152
public function print_popover_instructions() {
144153
echo '<p>';
145-
$this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' // @phpstan-ignore-line property.nonObject
146-
? \printf(
147-
/* translators: %s: "Read more" link. */
148-
\esc_html__( 'To make Yoast SEO output the correct Schema, you need to set your organization logo in the Yoast SEO settings. %s.', 'progress-planner' ),
149-
'<a href="' . \esc_url( \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-person-logo' ) ) . '" target="_blank" data-prpl_accessibility_text="' . \esc_attr__( 'Read more about the Yoast SEO Organization Logo', 'progress-planner' ) . '">' . \esc_html__( 'Read more', 'progress-planner' ) . '</a>'
150-
) : \printf(
154+
if ( $this->is_person_mode() ) {
155+
\printf(
151156
/* translators: %s: "Read more" link. */
152157
\esc_html__( 'To make Yoast SEO output the correct Schema, you need to set your person logo in the Yoast SEO settings. %s.', 'progress-planner' ),
153158
'<a href="' . \esc_url( \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-organization-logo' ) ) . '" target="_blank" data-prpl_accessibility_text="' . \esc_attr__( 'Read more about the Yoast SEO Person Logo', 'progress-planner' ) . '">' . \esc_html__( 'Read more', 'progress-planner' ) . '</a>'
154159
);
160+
} else {
161+
\printf(
162+
/* translators: %s: "Read more" link. */
163+
\esc_html__( 'To make Yoast SEO output the correct Schema, you need to set your organization logo in the Yoast SEO settings. %s.', 'progress-planner' ),
164+
'<a href="' . \esc_url( \progress_planner()->get_ui__branding()->get_url( 'https://prpl.fyi/yoast-person-logo' ) ) . '" target="_blank" data-prpl_accessibility_text="' . \esc_attr__( 'Read more about the Yoast SEO Organization Logo', 'progress-planner' ) . '">' . \esc_html__( 'Read more', 'progress-planner' ) . '</a>'
165+
);
166+
}
155167
echo '</p>';
156168
}
157169

@@ -164,7 +176,9 @@ public function print_popover_form_contents() {
164176
// Enqueue media scripts.
165177
\wp_enqueue_media();
166178

167-
$organization_logo_id = $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' ? $this->yoast_seo->helpers->options->get( 'company_logo' ) : $this->yoast_seo->helpers->options->get( 'person_logo' ); // @phpstan-ignore-line property.nonObject
179+
$organization_logo_id = $this->is_person_mode()
180+
? $this->yoast_seo->helpers->options->get( 'person_logo' ) // @phpstan-ignore-line property.nonObject
181+
: $this->yoast_seo->helpers->options->get( 'company_logo' ); // @phpstan-ignore-line property.nonObject
168182
?>
169183
<div id="organization-logo-preview" style="margin-bottom: 15px; min-height: 150px; display: flex; align-items: center; justify-content: center; border: 2px dashed #ddd; border-radius: 4px; padding: 10px;">
170184
<?php if ( $organization_logo_id ) : ?>
@@ -192,9 +206,13 @@ protected function get_enqueue_data() {
192206
return [
193207
'name' => 'prplYoastOrganizationLogo',
194208
'data' => [
195-
'mediaTitle' => $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' ? \esc_html__( 'Choose Organization Logo', 'progress-planner' ) : \esc_html__( 'Choose Person Logo', 'progress-planner' ), // @phpstan-ignore-line property.nonObject
196-
'mediaButtonText' => $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' ? \esc_html__( 'Use as Organization Logo', 'progress-planner' ) : \esc_html__( 'Use as Person Logo', 'progress-planner' ), // @phpstan-ignore-line property.nonObject
197-
'companyOrPerson' => $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person' ? 'company' : 'person', // @phpstan-ignore-line property.nonObject
209+
'mediaTitle' => $this->is_person_mode()
210+
? \esc_html__( 'Choose Person Logo', 'progress-planner' )
211+
: \esc_html__( 'Choose Organization Logo', 'progress-planner' ),
212+
'mediaButtonText' => $this->is_person_mode()
213+
? \esc_html__( 'Use as Person Logo', 'progress-planner' )
214+
: \esc_html__( 'Use as Organization Logo', 'progress-planner' ),
215+
'companyOrPerson' => $this->is_person_mode() ? 'person' : 'company',
198216
],
199217
];
200218
}

0 commit comments

Comments
 (0)