| 1 |
<?php |
| 2 |
/** |
| 3 |
* The onboarding class for enhancing the new user experience. |
| 4 |
* |
| 5 |
* @since 1.4.0 |
| 6 |
* |
| 7 |
* @package woo-additional-terms |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Woo_Additional_Terms\Enhancements; |
| 11 |
|
| 12 |
use Woo_Additional_Terms\Helper; |
| 13 |
|
| 14 |
/** |
| 15 |
* The onboarding class. |
| 16 |
*/ |
| 17 |
class OnBoarding { |
| 18 |
|
| 19 |
/** |
| 20 |
* Rated (already) transient name. |
| 21 |
* |
| 22 |
* @since 1.4.0 |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
const OPTION_NAME = 'woo_additional_terms_onboarding'; |
| 27 |
|
| 28 |
/** |
| 29 |
* Setup hooks and filters. |
| 30 |
* |
| 31 |
* @since 1.4.0 |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function setup() { |
| 36 |
|
| 37 |
add_action( 'woo_additional_terms_admin_notices', array( $this, 'admin_notice' ) ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Display the onboarding notice. |
| 42 |
* |
| 43 |
* @since 1.4.0 |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function admin_notice() { |
| 48 |
|
| 49 |
global $pagenow; |
| 50 |
|
| 51 |
// Bail out if not on the plugins page. |
| 52 |
if ( 'plugins.php' !== $pagenow ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
// Bail early, in case user can manage shop settings. |
| 57 |
if ( ! current_user_can( 'manage_woocommerce' ) ) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
// Bail out if the user has already dismissed the onboarding notice. |
| 62 |
if ( get_site_option( self::OPTION_NAME ) ) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
// Enqueue the assets. |
| 67 |
wp_enqueue_script( 'woo-additional-terms-dismiss' ); |
| 68 |
|
| 69 |
woo_additional_terms()->service( 'template_manager' )->echo_template( |
| 70 |
'notices/onboarding.php', |
| 71 |
array( |
| 72 |
'help_uri' => Helper\Links::docs_uri(), |
| 73 |
'settings_uri' => Helper\Settings::page_uri(), |
| 74 |
) |
| 75 |
); |
| 76 |
} |
| 77 |
} |
| 78 |
|