Skip to content

Commit

Permalink
Merge branch 'develop' into filip/prototype-yoast-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath authored Dec 20, 2024
2 parents 554d635 + f74cead commit 2425aee
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
/**
* Add tasks for content updates.
*/
abstract class Content_Abstract {
abstract class Content_Abstract extends Local_Tasks_Abstract {

/**
* The capability required to perform the task.
*
* @var string
*/
protected $capability = 'edit_others_posts';

/**
* Get the task ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;
use Progress_Planner\Activities\Content_Helpers;

/**
* Add tasks for content creation.
*/
class Content_Create extends Content_Abstract implements Local_Tasks_Interface {
class Content_Create extends Content_Abstract {

/**
* The provider ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Local_Task_Factory;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;

/**
* Add tasks for content updates.
*/
class Content_Update extends Content_Abstract implements Local_Tasks_Interface {
class Content_Update extends Content_Abstract {

/**
* The provider ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;

/**
* Add tasks for Core updates.
*/
class Core_Update implements Local_Tasks_Interface {
class Core_Update extends Local_Tasks_Abstract {

/**
* The capability required to perform the task.
*
* @var string
*/
protected $capability = 'update_core';

/**
* The provider ID.
Expand All @@ -39,6 +44,11 @@ public function get_provider_type() {
*/
public function evaluate_task( $task_id ) {

// Early bail if the user does not have the capability to update the core, since \wp_get_update_data()['counts']['total'] will return 0.
if ( ! $this->capability_required() ) {
return false;
}

// Without this \wp_get_update_data() might not return correct data for the core updates (depending on the timing).
if ( ! function_exists( 'get_core_updates' ) ) {
require_once ABSPATH . 'wp-admin/includes/update.php'; // @phpstan-ignore requireOnce.fileNotFound
Expand All @@ -56,7 +66,9 @@ public function evaluate_task( $task_id ) {
* @return array
*/
public function get_tasks_to_inject() {
if ( true === $this->is_task_type_snoozed() ) {

// Early bail if the user does not have the capability to update the core or if the task is snoozed.
if ( true === $this->is_task_type_snoozed() || ! $this->capability_required() ) {
return [];
}

Expand Down Expand Up @@ -91,6 +103,7 @@ public function get_task_details( $task_id ) {
'priority' => 'high',
'type' => 'maintenance',
'points' => 1,
'url' => $this->capability_required() ? \esc_url( \admin_url( 'update-core.php' ) ) : '',
'description' => '<p>' . \esc_html__( 'Perform all updates to ensure your website is secure and up-to-date.', 'progress-planner' ) . '</p>',
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Abstract class for a local task provider.
*
* @package Progress_Planner
*/

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;

/**
* Add tasks for content updates.
*/
abstract class Local_Tasks_Abstract implements Local_Tasks_Interface {

/**
* The capability required to perform the task.
*
* @var string
*/
protected $capability = 'manage_options';

/**
* Check if the user has the capability to perform the task.
*
* @return bool
*/
public function capability_required() {
return $this->capability
? \current_user_can( $this->capability )
: true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ public function get_data_from_task_id( $task_id );
* @return string
*/
public function get_provider_type();

/**
* Check if the user has the capability to perform the task.
*
* @return bool
*/
public function capability_required();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;

/**
* Add tasks for settings saved.
*/
class Settings_Saved implements Local_Tasks_Interface {
class Settings_Saved extends Local_Tasks_Abstract {

/**
* The provider ID.
Expand All @@ -38,6 +36,12 @@ public function get_provider_type() {
* @return bool|string
*/
public function evaluate_task( $task_id ) {

// Early bail if the user does not have the capability to manage options.
if ( ! $this->capability_required() ) {
return false;
}

if ( 0 === strpos( $task_id, self::TYPE ) && false !== \get_option( 'progress_planner_pro_license_key', false ) ) {
return $task_id;
}
Expand All @@ -50,7 +54,9 @@ public function evaluate_task( $task_id ) {
* @return array
*/
public function get_tasks_to_inject() {
if ( true === $this->is_task_type_snoozed() ) {

// Early bail if the user does not have the capability to manage options or if the task is snoozed.
if ( true === $this->is_task_type_snoozed() || ! $this->capability_required() ) {
return [];
}

Expand Down Expand Up @@ -93,7 +99,7 @@ public function get_task_details( $task_id ) {
'priority' => 'high',
'type' => 'maintenance',
'points' => 1,
'url' => \esc_url( \admin_url( 'admin.php?page=progress-planner-settings' ) ),
'url' => \current_user_can( 'manage_options' ) ? \esc_url( \admin_url( 'admin.php?page=progress-planner-settings' ) ) : '',
'description' => '<p>' . \esc_html__( 'Head over to the settings page and fill in the required information.', 'progress-planner' ) . '</p>',
];
}
Expand Down
22 changes: 14 additions & 8 deletions classes/widgets/class-suggested-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Progress_Planner\Widget;
use Progress_Planner\Badges\Monthly;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Local_Task_Factory;

/**
* Suggested_Tasks class.
Expand Down Expand Up @@ -100,16 +101,21 @@ public function enqueue_scripts() {
// Insert the pending celebration tasks as high priority tasks, so they are shown always.
foreach ( $tasks['pending_celebration'] as $task_id ) {

$task_details = \progress_planner()->get_suggested_tasks()->get_local()->get_task_details( $task_id );
$task_object = ( new Local_Task_Factory( $task_id ) )->get_task();
$task_provider = \progress_planner()->get_suggested_tasks()->get_local()->get_task_provider( $task_object->get_provider_type() );

if ( $task_details ) {
$task_details['priority'] = 'high'; // Celebrate tasks are always on top.
$task_details['action'] = 'celebrate';
$tasks['details'][] = $task_details;
}
if ( $task_provider->capability_required() ) {
$task_details = \progress_planner()->get_suggested_tasks()->get_local()->get_task_details( $task_id );

if ( $task_details ) {
$task_details['priority'] = 'high'; // Celebrate tasks are always on top.
$task_details['action'] = 'celebrate';
$tasks['details'][] = $task_details;
}

// Mark the pending celebration tasks as completed.
\progress_planner()->get_suggested_tasks()->transition_task_status( $task_id, 'pending_celebration', 'completed' );
// Mark the pending celebration tasks as completed.
\progress_planner()->get_suggested_tasks()->transition_task_status( $task_id, 'pending_celebration', 'completed' );
}
}

// Localize the script.
Expand Down
14 changes: 8 additions & 6 deletions views/dashboard-widgets/score.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
<ul style="display:none"></ul>
<ul class="prpl-suggested-tasks-list"></ul>

<div class="prpl-dashboard-widget-footer">
<img src="<?php echo \esc_attr( PROGRESS_PLANNER_URL . '/assets/images/icon_progress_planner.svg' ); ?>" style="width:1.5em;" alt="" />
<a href="<?php echo \esc_url( \get_admin_url( null, 'admin.php?page=progress-planner' ) ); ?>">
<?php \esc_html_e( 'Check out all your stats and badges', 'progress-planner' ); ?>
</a>
</div>
<?php if ( \current_user_can( 'manage_options' ) ) : ?>
<div class="prpl-dashboard-widget-footer">
<img src="<?php echo \esc_attr( PROGRESS_PLANNER_URL . '/assets/images/icon_progress_planner.svg' ); ?>" style="width:1.5em;" alt="" />
<a href="<?php echo \esc_url( \get_admin_url( null, 'admin.php?page=progress-planner' ) ); ?>">
<?php \esc_html_e( 'Check out all your stats and badges', 'progress-planner' ); ?>
</a>
</div>
<?php endif; ?>

0 comments on commit 2425aee

Please sign in to comment.