Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype 3rd party plugin suggested tasks #150

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5056a86
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 9, 2024
d40b527
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 10, 2024
3268ced
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 11, 2024
858798c
put back 2 integration examples - Yoast and WP Core
ilicfilip Dec 11, 2024
2df1c5c
add method for removing tasks for which provider is not registered
ilicfilip Dec 11, 2024
649e209
Merge branch 'develop' into filip/prototype-yoast-integration
aristath Dec 11, 2024
131b6d8
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 12, 2024
2d26e69
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 16, 2024
cacc61a
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 18, 2024
681e039
Merge branch 'develop' into filip/prototype-yoast-integration
aristath Dec 18, 2024
554d635
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 20, 2024
2425aee
Merge branch 'develop' into filip/prototype-yoast-integration
aristath Dec 20, 2024
82efaef
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 23, 2024
54a514f
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Dec 25, 2024
3f30727
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Jan 6, 2025
afd67f2
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Jan 8, 2025
396efae
Merge branch 'develop' into filip/prototype-yoast-integration
ilicfilip Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion classes/suggested-tasks/class-local-tasks-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Content_Create;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Content_Update;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Core_Update;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Core_Blogdescription;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Settings_Saved;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Yoast_Organization_Logo;


/**
Expand Down Expand Up @@ -46,6 +48,7 @@
new Content_Create(),
new Content_Update(),
new Core_Update(),
new Core_Blogdescription(),
new Settings_Saved(),
];

Expand All @@ -62,7 +65,9 @@
* @return void
*/
public function add_plugin_integration() {
// Add the plugin integration here.
if ( defined( 'WPSEO_FILE' ) ) {
$this->task_providers[] = new Yoast_Organization_Logo();
}
}

/**
Expand Down Expand Up @@ -164,6 +169,23 @@
return $task_provider->evaluate_task( $task_id );
}

/**
* Removes pending tasks for which providers are not (longer) active.
*
* @return void
*/
public function cleanup_pending_tasks() {
$tasks = $this->get_pending_tasks();

foreach ( $tasks as $task ) {
$task_object = ( new Local_Task_Factory( $task ) )->get_task();
$provider = $this->get_task_provider( $task_object->get_provider_type() );
if ( ! $provider ) {
$this->remove_pending_task( $task );
}
}
}

/**
* Wrapper function for getting task details.
*
Expand Down Expand Up @@ -239,7 +261,7 @@
*
* @return void
*/
public function cleanup_pending_tasks() {

Check failure on line 264 in classes/suggested-tasks/class-local-tasks-manager.php

View workflow job for this annotation

GitHub Actions / Check code style

PHP syntax error: Cannot redeclare Progress_Planner\Suggested_Tasks\Local_Tasks_Manager::cleanup_pending_tasks()

Check failure on line 264 in classes/suggested-tasks/class-local-tasks-manager.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Cannot redeclare method Progress_Planner\Suggested_Tasks\Local_Tasks_Manager::cleanup_pending_tasks().

Check failure on line 264 in classes/suggested-tasks/class-local-tasks-manager.php

View workflow job for this annotation

GitHub Actions / Check code style

PHP syntax error: Cannot redeclare Progress_Planner\Suggested_Tasks\Local_Tasks_Manager::cleanup_pending_tasks()

Check failure on line 264 in classes/suggested-tasks/class-local-tasks-manager.php

View workflow job for this annotation

GitHub Actions / Lint: PHP 8.0

Fatal error: Cannot redeclare Progress_Planner\Suggested_Tasks\Local_Tasks_Manager::cleanup_pending_tasks() in ./classes/suggested-tasks/class-local-tasks-manager.php on line 264

Check failure on line 264 in classes/suggested-tasks/class-local-tasks-manager.php

View workflow job for this annotation

GitHub Actions / Lint: PHP 8.1

Fatal error: Cannot redeclare Progress_Planner\Suggested_Tasks\Local_Tasks_Manager::cleanup_pending_tasks() in ./classes/suggested-tasks/class-local-tasks-manager.php on line 264

$cleanup_recently_performed = \progress_planner()->get_cache()->get( 'cleanup_pending_tasks' );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* Add tasks for Core blogdescription.
*
* @package Progress_Planner
*/

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

/**
* Add tasks for Core blogdescription.
*/
class Core_Blogdescription implements \Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface {

Check failure on line 13 in classes/suggested-tasks/local-tasks/providers/class-core-blogdescription.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Non-abstract class Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Core_Blogdescription contains abstract method capability_required() from interface Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface.

/**
* The provider ID.
*
* @var string
*/
const TYPE = 'core-blogdescription';

/**
* Get the provider ID.
*
* @return string
*/
public function get_provider_type() {
return self::TYPE;
}

/**
* Evaluate a task.
*
* @param string $task_id The task ID.
*
* @return bool|string
*/
public function evaluate_task( $task_id ) {
if ( 0 === strpos( $task_id, self::TYPE ) && '' !== \get_bloginfo( 'description' ) ) {
return $task_id;
}
return false;
}

/**
* Get an array of tasks to inject.
*
* @return array
*/
public function get_tasks_to_inject() {
return true !== $this->is_task_type_snoozed() ? $this->get_tasks() : [];
}

/**
* Get the tasks to set the blogdescription.
*
* @return array
*/
public function get_tasks() {
// If all options are set, do not add the task.
if ( '' !== \get_bloginfo( 'description' ) ) {
return [];
}

return [
$this->get_task_details( self::TYPE . '-' . \gmdate( 'YW' ) ),
];
}

/**
* Get the task details.
*
* @param string $task_id The task ID.
*
* @return array
*/
public function get_task_details( $task_id ) {

return [
'task_id' => $task_id,
'title' => \esc_html__( 'Core: Set blogdescription', 'progress-planner' ),
'parent' => 0,
'priority' => 'high',
'type' => 'maintenance',
'points' => 1,
'description' => '<p>' . \esc_html__( 'Set the blogdescription to make your website look more professional.', 'progress-planner' ) . '</p>',
];
}

/**
* Get the data from a task-ID.
*
* @param string $task_id The task ID.
*
* @return array The data.
*/
public function get_data_from_task_id( $task_id ) {
$data = [
'type' => self::TYPE,
'id' => $task_id,
];

return $data;
}

/**
* Check if a task type is snoozed.
*
* @return bool
*/
public function is_task_type_snoozed() {
$snoozed = \progress_planner()->get_suggested_tasks()->get_snoozed_tasks();
if ( ! \is_array( $snoozed ) || empty( $snoozed ) ) {
return false;
}

foreach ( $snoozed as $task ) {
if ( self::TYPE === $task['id'] ) {
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* Add tasks for Yoast integration.
*
* @package Progress_Planner
*/

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

/**
* Add tasks for Yoast integration.
*/
class Yoast_Organization_Logo implements \Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface {

Check failure on line 13 in classes/suggested-tasks/local-tasks/providers/class-yoast-organization-logo.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Non-abstract class Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Yoast_Organization_Logo contains abstract method capability_required() from interface Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface.

/**
* The provider ID.
*
* @var string
*/
const TYPE = 'yoast-organization-logo';

/**
* Get the provider ID.
*
* @return string
*/
public function get_provider_type() {
return self::TYPE;
}

/**
* Evaluate a task.
*
* @param string $task_id The task ID.
*
* @return bool|string
*/
public function evaluate_task( $task_id ) {
if ( 0 === strpos( $task_id, self::TYPE ) && class_exists( '\WPSEO_Options' ) && '' !== \WPSEO_Options::get( 'company_logo' ) ) {
return $task_id;
}
return false;
}

/**
* Get an array of tasks to inject.
*
* @return array
*/
public function get_tasks_to_inject() {
return true !== $this->is_task_type_snoozed() ? $this->get_tasks() : [];
}

/**
* Get the tasks to set Yoast organization logo.
*
* @return array
*/
public function get_tasks() {
// If all options are set, do not add the task.
if ( class_exists( '\WPSEO_Options' ) && '' !== \WPSEO_Options::get( 'company_logo' ) ) {
return [];
}

return [
$this->get_task_details( self::TYPE . '-' . \gmdate( 'YW' ) ),
];
}

/**
* Get the task details.
*
* @param string $task_id The task ID.
*
* @return array
*/
public function get_task_details( $task_id ) {

return [
'task_id' => $task_id,
'title' => \esc_html__( 'Yoast: Set organization logo', 'progress-planner' ),
'parent' => 0,
'priority' => 'high',
'type' => 'maintenance',
'points' => 1,
'description' => '<p>' . \esc_html__( 'Set organization logo to make your website look more professional.', 'progress-planner' ) . '</p>',
];
}

/**
* Get the data from a task-ID.
*
* @param string $task_id The task ID.
*
* @return array The data.
*/
public function get_data_from_task_id( $task_id ) {
$data = [
'type' => self::TYPE,
'id' => $task_id,
];

return $data;
}

/**
* Check if a task type is snoozed.
*
* @return bool
*/
public function is_task_type_snoozed() {
$snoozed = \progress_planner()->get_suggested_tasks()->get_snoozed_tasks();
if ( ! \is_array( $snoozed ) || empty( $snoozed ) ) {
return false;
}

foreach ( $snoozed as $task ) {
if ( self::TYPE === $task['id'] ) {
return true;
}
}

return false;
}
}
Loading