Skip to content

Commit 59d23b0

Browse files
committed
more tweaks
1 parent 8e59894 commit 59d23b0

8 files changed

Lines changed: 29 additions & 81 deletions

File tree

classes/suggested-tasks/class-task.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ public function is_completed(): bool {
130130
* @return bool
131131
*/
132132
public function celebrate(): bool {
133-
if ( ! $this->ID ) {
134-
return false;
135-
}
136-
137-
return \progress_planner()->get_suggested_tasks_db()->update_recommendation( $this->ID, [ 'post_status' => 'pending' ] );
133+
return $this->ID && \progress_planner()->get_suggested_tasks_db()->update_recommendation( $this->ID, [ 'post_status' => 'pending' ] );
138134
}
139135

140136
/**

classes/suggested-tasks/data-collector/class-inactive-plugins.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ protected function calculate_data() {
6666
}
6767
}
6868

69-
$unused_plugins = 0;
70-
if ( ! \is_multisite() && $plugins_total > $plugins_active ) {
71-
$unused_plugins = $plugins_total - $plugins_active;
72-
}
73-
74-
return $unused_plugins;
69+
return ! \is_multisite() && $plugins_total > $plugins_active
70+
? $plugins_total - $plugins_active
71+
: 0;
7572
}
7673
}

classes/suggested-tasks/providers/integrations/yoast/class-archive-author.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,8 @@ public function get_focus_tasks() {
9191
* @return bool
9292
*/
9393
public function should_add_task() {
94-
if ( ! $this->is_task_relevant() ) {
95-
return false;
96-
}
97-
98-
// If the author archive is already disabled, we don't need to add the task.
99-
if ( \YoastSEO()->helpers->options->get( 'disable-author' ) === true ) {
100-
return false;
101-
}
102-
103-
return true;
94+
return $this->is_task_relevant()
95+
&& \YoastSEO()->helpers->options->get( 'disable-author' ) !== true;
10496
}
10597

10698
/**

classes/suggested-tasks/providers/integrations/yoast/class-cornerstone-workout.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,11 @@ protected function get_url() {
144144
* @return bool
145145
*/
146146
public function should_add_task() {
147-
if ( ! \defined( 'WPSEO_PREMIUM_VERSION' ) ) {
148-
return false;
149-
}
150-
151-
return ! $this->is_task_dismissed(
152-
[
153-
'provider_id' => $this->get_provider_id(),
154-
]
155-
);
147+
return \defined( 'WPSEO_PREMIUM_VERSION' )
148+
&& ! $this->is_task_dismissed(
149+
[
150+
'provider_id' => $this->get_provider_id(),
151+
]
152+
);
156153
}
157154
}

classes/suggested-tasks/providers/integrations/yoast/class-fix-orphaned-content.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class Fix_Orphaned_Content extends Yoast_Provider {
4646
/**
4747
* The completed post IDs.
4848
*
49-
* @var array|null
49+
* @var array
5050
*/
51-
protected $completed_post_ids = null;
51+
protected $completed_post_ids = [];
5252

5353
/**
5454
* The data collector class name.
@@ -158,11 +158,7 @@ public function get_tasks_to_inject() {
158158
}
159159

160160
$data = $this->transform_collector_data( $this->get_data_collector()->collect() );
161-
$task_id = $this->get_task_id(
162-
[
163-
'target_post_id' => $data['target_post_id'],
164-
]
165-
);
161+
$task_id = $this->get_task_id( [ 'target_post_id' => $data['target_post_id'] ] );
166162

167163
// When we have data, check if task was completed.
168164
if ( true === \progress_planner()->get_suggested_tasks()->was_task_completed( $task_id ) ) {
@@ -207,9 +203,7 @@ public function get_post_from_task_id( $task_id ) {
207203
return null;
208204
}
209205

210-
$task = $tasks[0];
211-
212-
return $task->target_post_id ? \get_post( $task->target_post_id ) : null;
206+
return $tasks[0]->target_post_id ? \get_post( $tasks[0]->target_post_id ) : null;
213207
}
214208

215209
/**
@@ -218,18 +212,15 @@ public function get_post_from_task_id( $task_id ) {
218212
* @return array
219213
*/
220214
protected function get_completed_post_ids() {
221-
if ( null !== $this->completed_post_ids ) {
215+
if ( ! empty( $this->completed_post_ids ) ) {
222216
return $this->completed_post_ids;
223217
}
224218

225-
$this->completed_post_ids = [];
226-
$tasks = \progress_planner()->get_suggested_tasks_db()->get_tasks_by( [ 'provider_id' => $this->get_provider_id() ] );
219+
$tasks = \progress_planner()->get_suggested_tasks_db()->get_tasks_by( [ 'provider_id' => $this->get_provider_id() ] );
227220

228-
if ( ! empty( $tasks ) ) {
229-
foreach ( $tasks as $task ) {
230-
if ( 'trash' === $task->post_status ) {
231-
$this->completed_post_ids[] = $task->target_post_id;
232-
}
221+
foreach ( $tasks as $task ) {
222+
if ( 'trash' === $task->post_status ) {
223+
$this->completed_post_ids[] = $task->target_post_id;
233224
}
234225
}
235226

classes/suggested-tasks/providers/integrations/yoast/class-orphaned-content-workout.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,7 @@ protected function get_url() {
147147
* @return bool
148148
*/
149149
public function should_add_task() {
150-
if ( ! \defined( 'WPSEO_PREMIUM_VERSION' ) ) {
151-
return false;
152-
}
153-
154-
return ! $this->is_task_dismissed(
155-
[
156-
'provider_id' => $this->get_provider_id(),
157-
]
158-
);
150+
return \defined( 'WPSEO_PREMIUM_VERSION' )
151+
&& ! $this->is_task_dismissed( [ 'provider_id' => $this->get_provider_id() ] );
159152
}
160153
}

classes/suggested-tasks/providers/interactive/class-email-sending.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ protected function get_description( $task_data = [] ) {
151151
* @return void
152152
*/
153153
public function enqueue_scripts() {
154-
155154
// Don't enqueue the script if the task is already completed.
156155
if ( true === \progress_planner()->get_suggested_tasks()->was_task_completed( $this->get_task_id() ) ) {
157156
return;
@@ -179,13 +178,7 @@ public function enqueue_scripts() {
179178
*/
180179
public function check_if_wp_mail_is_filtered() {
181180
global $wp_filter;
182-
183-
$filters_to_check = [
184-
'phpmailer_init',
185-
'pre_wp_mail',
186-
];
187-
188-
foreach ( $filters_to_check as $filter ) {
181+
foreach ( [ 'phpmailer_init', 'pre_wp_mail' ] as $filter ) {
189182
$has_filter = isset( $wp_filter[ $filter ] ) && ! empty( $wp_filter[ $filter ]->callbacks ) ? true : false;
190183
$this->is_wp_mail_filtered = $this->is_wp_mail_filtered || $has_filter;
191184
}
@@ -197,7 +190,6 @@ public function check_if_wp_mail_is_filtered() {
197190
* @return void
198191
*/
199192
public function check_if_wp_mail_has_override() {
200-
201193
// Just in case, since it will trigger PHP fatal error if the function doesn't exist.
202194
if ( \function_exists( 'wp_mail' ) ) {
203195
$file_path = ( new \ReflectionFunction( 'wp_mail' ) )->getFileName();
@@ -221,7 +213,6 @@ protected function is_there_sending_email_override() {
221213
* @return void
222214
*/
223215
public function ajax_test_email_sending() {
224-
225216
// Check the nonce.
226217
\check_admin_referer( 'progress_planner' );
227218

classes/suggested-tasks/providers/traits/class-dismissable-task.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,9 @@ public function handle_task_dismissal( $post_id ) {
115115
* @return string|false The task identifier or false if not applicable.
116116
*/
117117
protected function get_task_identifier( $task_data ) {
118-
$task_identifier = $this->get_provider_id();
119-
120-
if ( isset( $task_data['target_post_id'] ) ) {
121-
$task_identifier .= '-' . $task_data['target_post_id'];
122-
}
123-
124-
if ( isset( $task_data['target_term_id'] ) ) {
125-
$task_identifier .= '-' . $task_data['target_term_id'];
126-
}
118+
$task_identifier = $this->get_provider_id();
119+
$task_identifier .= isset( $task_data['target_post_id'] ) ? '-' . $task_data['target_post_id'] : '';
120+
$task_identifier .= isset( $task_data['target_term_id'] ) ? '-' . $task_data['target_term_id'] : '';
127121

128122
return $task_identifier;
129123
}
@@ -183,8 +177,7 @@ protected function is_task_dismissed( $task_data ) {
183177
* @return array
184178
*/
185179
public function get_dismissed_tasks() {
186-
$dismissed_tasks = \progress_planner()->get_settings()->get( $this->dismissed_tasks_option, [] );
187-
return $dismissed_tasks[ $this->get_provider_id() ] ?? [];
180+
return \progress_planner()->get_settings()->get( $this->dismissed_tasks_option, [] )[ $this->get_provider_id() ] ?? [];
188181
}
189182

190183
/**
@@ -193,9 +186,7 @@ public function get_dismissed_tasks() {
193186
* @return void
194187
*/
195188
public function cleanup_old_dismissals() {
196-
$cleanup_recently_performed = \progress_planner()->get_utils__cache()->get( 'cleanup_dismissed_tasks' );
197-
198-
if ( $cleanup_recently_performed ) {
189+
if ( \progress_planner()->get_utils__cache()->get( 'cleanup_dismissed_tasks' ) ) {
199190
return;
200191
}
201192

0 commit comments

Comments
 (0)