Add checks around setup widget display when features are disabled (#31884)
* Add checks around setup widget display when features are disabled * Avoid refetching task list after initialization
This commit is contained in:
parent
f9cf24e50b
commit
7ebb561d98
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -20,6 +21,11 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
|
|||
*/
|
||||
class WC_Admin_Dashboard_Setup {
|
||||
|
||||
/**
|
||||
* Check for task list initialization.
|
||||
*/
|
||||
private $initalized = false;
|
||||
|
||||
/**
|
||||
* The task list.
|
||||
*/
|
||||
|
@ -102,11 +108,12 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
|
|||
* @return array
|
||||
*/
|
||||
public function get_task_list() {
|
||||
if ( $this->task_list ) {
|
||||
if ( $this->task_list || $this->initalized ) {
|
||||
return $this->task_list;
|
||||
}
|
||||
|
||||
$this->set_task_list( TaskLists::get_list( 'setup' ) );
|
||||
$this->initalized = true;
|
||||
return $this->task_list;
|
||||
}
|
||||
|
||||
|
@ -168,10 +175,23 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
|
|||
* @return bool
|
||||
*/
|
||||
public function should_display_widget() {
|
||||
return current_user_can( 'manage_woocommerce' ) &&
|
||||
WC()->is_wc_admin_active() &&
|
||||
! $this->get_task_list()->is_complete() &&
|
||||
! $this->get_task_list()->is_hidden();
|
||||
if ( ! class_exists( 'Automattic\WooCommerce\Admin\Features\Features' ) || ! class_exists( 'Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! Features::is_enabled( 'onboarding' ) || ! WC()->is_wc_admin_active() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_woocommerce' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $this->get_task_list() || $this->get_task_list()->is_complete() || $this->get_task_list()->is_hidden() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -129,6 +129,16 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
|
|||
$this->assertFalse( $widget->should_display_widget() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests widget does not display when task list is unavailable.
|
||||
*/
|
||||
public function test_widget_does_not_display_when_no_task_list() {
|
||||
$widget = $this->get_widget();
|
||||
$widget->set_task_list( null );
|
||||
|
||||
$this->assertFalse( $widget->should_display_widget() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the widget output when 1 task has been completed.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue