@@ -75,23 +75,23 @@ class Content_Review extends Tasks {
7575 /**
7676 * The snoozed post IDs.
7777 *
78- * @var array|null
78+ * @var array
7979 */
80- protected $ snoozed_post_ids = null ;
80+ protected $ snoozed_post_ids = [] ;
8181
8282 /**
8383 * The dismissed post IDs.
8484 *
85- * @var array|null
85+ * @var array
8686 */
87- protected $ dismissed_post_ids = null ;
87+ protected $ dismissed_post_ids = [] ;
8888
8989 /**
9090 * The post to update IDs.
9191 *
92- * @var array|null
92+ * @var array
9393 */
94- protected $ task_post_mappings = null ;
94+ protected $ task_post_mappings = [] ;
9595
9696 /**
9797 * The include post types.
@@ -209,14 +209,11 @@ protected function get_url_with_data( $task_data = [] ) {
209209 * @return bool
210210 */
211211 public function should_add_task () {
212- if ( null !== $ this ->task_post_mappings ) {
213- return 0 < \count ( $ this -> task_post_mappings ) ;
212+ if ( ! empty ( $ this ->task_post_mappings ) ) {
213+ return true ;
214214 }
215215
216- $ this ->task_post_mappings = [];
217-
218- $ number_of_posts_to_inject = static ::ITEMS_TO_INJECT ;
219- $ last_updated_posts = [];
216+ $ last_updated_posts = [];
220217
221218 // Check if there are any important pages to update.
222219 $ important_page_ids = [];
@@ -255,9 +252,7 @@ public function should_add_task() {
255252 }
256253
257254 // Lets check for other posts to update.
258- $ number_of_posts_to_inject = $ number_of_posts_to_inject - \count ( $ last_updated_posts );
259-
260- if ( 0 < $ number_of_posts_to_inject ) {
255+ if ( 0 < static ::ITEMS_TO_INJECT - \count ( $ last_updated_posts ) ) {
261256 // Get the post that was updated last.
262257 $ last_updated_posts = \array_merge (
263258 $ last_updated_posts ,
@@ -299,7 +294,7 @@ public function should_add_task() {
299294 ];
300295 }
301296
302- return 0 < \count ( $ this ->task_post_mappings );
297+ return ! empty ( $ this ->task_post_mappings );
303298 }
304299
305300 /**
@@ -313,28 +308,26 @@ public function get_tasks_to_inject() {
313308 }
314309
315310 $ task_to_inject = [];
316- if ( ! empty ( $ this ->task_post_mappings ) ) {
317- foreach ( $ this ->task_post_mappings as $ task_data ) {
318- if ( true === \progress_planner ()->get_suggested_tasks ()->was_task_completed ( $ task_data ['task_id ' ] ) ) {
319- continue ;
320- }
321-
322- $ task_to_inject [] = [
323- 'task_id ' => $ this ->get_task_id ( [ 'target_post_id ' => $ task_data ['target_post_id ' ] ] ),
324- 'provider_id ' => $ this ->get_provider_id (),
325- 'category ' => $ this ->get_provider_category (),
326- 'target_post_id ' => $ task_data ['target_post_id ' ],
327- 'target_post_type ' => $ task_data ['target_post_type ' ],
328- 'date ' => \gmdate ( 'YW ' ),
329- 'post_title ' => $ this ->get_title_with_data ( $ task_data ),
330- 'description ' => $ this ->get_description_with_data ( $ task_data ),
331- 'url ' => $ this ->get_url_with_data ( $ task_data ),
332- 'url_target ' => $ this ->get_url_target (),
333- 'dismissable ' => $ this ->is_dismissable (),
334- 'snoozable ' => $ this ->is_snoozable ,
335- 'points ' => $ this ->get_points (),
336- ];
311+ foreach ( $ this ->task_post_mappings as $ task_data ) {
312+ if ( true === \progress_planner ()->get_suggested_tasks ()->was_task_completed ( $ task_data ['task_id ' ] ) ) {
313+ continue ;
337314 }
315+
316+ $ task_to_inject [] = [
317+ 'task_id ' => $ this ->get_task_id ( [ 'target_post_id ' => $ task_data ['target_post_id ' ] ] ),
318+ 'provider_id ' => $ this ->get_provider_id (),
319+ 'category ' => $ this ->get_provider_category (),
320+ 'target_post_id ' => $ task_data ['target_post_id ' ],
321+ 'target_post_type ' => $ task_data ['target_post_type ' ],
322+ 'date ' => \gmdate ( 'YW ' ),
323+ 'post_title ' => $ this ->get_title_with_data ( $ task_data ),
324+ 'description ' => $ this ->get_description_with_data ( $ task_data ),
325+ 'url ' => $ this ->get_url_with_data ( $ task_data ),
326+ 'url_target ' => $ this ->get_url_target (),
327+ 'dismissable ' => $ this ->is_dismissable (),
328+ 'snoozable ' => $ this ->is_snoozable ,
329+ 'points ' => $ this ->get_points (),
330+ ];
338331 }
339332
340333 $ added_tasks = [];
@@ -440,10 +433,8 @@ public function filter_update_posts_args( $args ) {
440433 $ this ->get_snoozed_post_ids (),
441434 );
442435
443- $ dismissed_post_ids = $ this ->get_dismissed_post_ids ();
444-
445- if ( ! empty ( $ dismissed_post_ids ) ) {
446- $ args ['post__not_in ' ] = \array_merge ( $ args ['post__not_in ' ], $ dismissed_post_ids );
436+ if ( ! empty ( $ this ->get_dismissed_post_ids () ) ) {
437+ $ args ['post__not_in ' ] = \array_merge ( $ args ['post__not_in ' ], $ this ->get_dismissed_post_ids () );
447438 }
448439
449440 if ( \function_exists ( 'YoastSEO ' ) ) {
@@ -473,23 +464,20 @@ public function filter_update_posts_args( $args ) {
473464 * @return array
474465 */
475466 protected function get_snoozed_post_ids () {
476- if ( null !== $ this ->snoozed_post_ids ) {
467+ if ( ! empty ( $ this ->snoozed_post_ids ) ) {
477468 return $ this ->snoozed_post_ids ;
478469 }
479470
480- $ this ->snoozed_post_ids = [];
481- $ snoozed = \progress_planner ()->get_suggested_tasks_db ()->get_tasks_by ( [ 'post_status ' => 'future ' ] );
482-
483- if ( ! empty ( $ snoozed ) ) {
484- foreach ( $ snoozed as $ task ) {
485- /**
486- * The task object.
487- *
488- * @var \Progress_Planner\Suggested_Tasks\Task $task
489- */
490- if ( isset ( $ task ->provider ->slug ) && 'review-post ' === $ task ->provider ->slug ) {
491- $ this ->snoozed_post_ids [] = $ task ->target_post_id ;
492- }
471+ $ snoozed = \progress_planner ()->get_suggested_tasks_db ()->get_tasks_by ( [ 'post_status ' => 'future ' ] );
472+
473+ foreach ( $ snoozed as $ task ) {
474+ /**
475+ * The task object.
476+ *
477+ * @var \Progress_Planner\Suggested_Tasks\Task $task
478+ */
479+ if ( isset ( $ task ->provider ->slug ) && 'review-post ' === $ task ->provider ->slug ) {
480+ $ this ->snoozed_post_ids [] = $ task ->target_post_id ;
493481 }
494482 }
495483
@@ -502,12 +490,11 @@ protected function get_snoozed_post_ids() {
502490 * @return array
503491 */
504492 protected function get_dismissed_post_ids () {
505- if ( null !== $ this ->dismissed_post_ids ) {
493+ if ( ! empty ( $ this ->dismissed_post_ids ) ) {
506494 return $ this ->dismissed_post_ids ;
507495 }
508496
509- $ this ->dismissed_post_ids = [];
510- $ dismissed = $ this ->get_dismissed_tasks ();
497+ $ dismissed = $ this ->get_dismissed_tasks ();
511498
512499 if ( ! empty ( $ dismissed ) ) {
513500 $ this ->dismissed_post_ids = \array_values ( \wp_list_pluck ( $ dismissed , 'post_id ' ) );
0 commit comments