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\Jetpack\Constants;
|
||||||
|
use Automattic\WooCommerce\Admin\Features\Features;
|
||||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
|
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
@ -20,6 +21,11 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
|
||||||
*/
|
*/
|
||||||
class WC_Admin_Dashboard_Setup {
|
class WC_Admin_Dashboard_Setup {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for task list initialization.
|
||||||
|
*/
|
||||||
|
private $initalized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The task list.
|
* The task list.
|
||||||
*/
|
*/
|
||||||
|
@ -102,11 +108,12 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_task_list() {
|
public function get_task_list() {
|
||||||
if ( $this->task_list ) {
|
if ( $this->task_list || $this->initalized ) {
|
||||||
return $this->task_list;
|
return $this->task_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_task_list( TaskLists::get_list( 'setup' ) );
|
$this->set_task_list( TaskLists::get_list( 'setup' ) );
|
||||||
|
$this->initalized = true;
|
||||||
return $this->task_list;
|
return $this->task_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,10 +175,23 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function should_display_widget() {
|
public function should_display_widget() {
|
||||||
return current_user_can( 'manage_woocommerce' ) &&
|
if ( ! class_exists( 'Automattic\WooCommerce\Admin\Features\Features' ) || ! class_exists( 'Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists' ) ) {
|
||||||
WC()->is_wc_admin_active() &&
|
return false;
|
||||||
! $this->get_task_list()->is_complete() &&
|
}
|
||||||
! $this->get_task_list()->is_hidden();
|
|
||||||
|
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() );
|
$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.
|
* Tests the widget output when 1 task has been completed.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue