views
1 day ago
FinishOption.php
1 day ago
Onboarding.php
1 day ago
OptionAjaxUpdater.php
1 day ago
PopupData.php
1 day ago
Tracker.php
1 day ago
Onboarding.php
125 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Assets. |
| 4 | * |
| 5 | * @package WPDesk\FS\Onboarding |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\Onboarding\TableRate; |
| 9 | |
| 10 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 11 | use WPDesk\FS\Helpers\FlexibleShippingMethodsChecker; |
| 12 | use WPDesk\FS\Helpers\WooSettingsPageChecker; |
| 13 | |
| 14 | /** |
| 15 | * Onboarding hooks. |
| 16 | */ |
| 17 | class Onboarding implements Hookable { |
| 18 | |
| 19 | /** |
| 20 | * @var FinishOption . |
| 21 | */ |
| 22 | private $finish_option; |
| 23 | |
| 24 | /** |
| 25 | * @var string . |
| 26 | */ |
| 27 | private $scripts_version; |
| 28 | |
| 29 | /** |
| 30 | * @var string . |
| 31 | */ |
| 32 | private $plugin_assets_url; |
| 33 | |
| 34 | /** |
| 35 | * @var WooSettingsPageChecker |
| 36 | */ |
| 37 | private $setting_page_checker; |
| 38 | |
| 39 | /** |
| 40 | * @var FlexibleShippingMethodsChecker |
| 41 | */ |
| 42 | private $fs_methods_checker; |
| 43 | |
| 44 | /** |
| 45 | * @param FinishOption $finish_option . |
| 46 | * @param string $scripts_version . |
| 47 | * @param string $plugin_assets_url . |
| 48 | * @param WooSettingsPageChecker $setting_page_checker . |
| 49 | */ |
| 50 | public function __construct( |
| 51 | FinishOption $finish_option, |
| 52 | string $scripts_version, |
| 53 | string $plugin_assets_url, |
| 54 | WooSettingsPageChecker $setting_page_checker, |
| 55 | FlexibleShippingMethodsChecker $fs_methods_checker |
| 56 | ) { |
| 57 | $this->finish_option = $finish_option; |
| 58 | $this->scripts_version = $scripts_version; |
| 59 | $this->plugin_assets_url = $plugin_assets_url; |
| 60 | $this->setting_page_checker = $setting_page_checker; |
| 61 | $this->fs_methods_checker = $fs_methods_checker; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Hooks. |
| 66 | */ |
| 67 | public function hooks() { |
| 68 | add_action( 'flexible-shipping/admin/enqueue_scripts', [ $this, 'register_scripts' ] ); |
| 69 | add_action( 'flexible-shipping/method-rules-settings/table/before', [ $this, 'add_onboarding_container' ] ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Add onboarding container. |
| 74 | */ |
| 75 | public function add_onboarding_container() { |
| 76 | include wp_normalize_path( __DIR__ . '/views/before-table-method-rules-settings.php' ); |
| 77 | } |
| 78 | |
| 79 | public function register_scripts() { |
| 80 | if ( ! $this->setting_page_checker->is_fs_instance_method_edit() ) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | wp_enqueue_style( 'wpdesk_onboarding', sprintf( '%scss/onboarding.css', $this->plugin_assets_url ), [], $this->scripts_version ); |
| 85 | |
| 86 | wp_enqueue_script( |
| 87 | 'wpdesk_onboarding', |
| 88 | sprintf( '%sjs/onboarding.js', $this->plugin_assets_url ), |
| 89 | [ 'jquery' ], |
| 90 | $this->scripts_version, |
| 91 | true |
| 92 | ); |
| 93 | |
| 94 | wp_localize_script( |
| 95 | 'wpdesk_onboarding', |
| 96 | 'fs_onboarding_details', |
| 97 | [ |
| 98 | 'ajax' => [ |
| 99 | 'url' => admin_url( 'admin-ajax.php' ), |
| 100 | 'nonce' => wp_create_nonce( OptionAjaxUpdater::NONCE_ACTION ), |
| 101 | 'action' => [ |
| 102 | 'event' => OptionAjaxUpdater::AJAX_ACTION_EVENT, |
| 103 | 'click' => OptionAjaxUpdater::AJAX_ACTION_CLICK, |
| 104 | 'auto_show_popup' => OptionAjaxUpdater::AJAX_ACTION_AUTO_SHOP_POPUP, |
| 105 | ], |
| 106 | ], |
| 107 | 'assets_url' => untrailingslashit( $this->plugin_assets_url ), |
| 108 | 'label_step' => __( 'Step #', 'flexible-shipping' ), |
| 109 | 'logo_img' => 'logo-fs.svg', |
| 110 | 'steps' => 4, |
| 111 | 'locale' => get_user_locale(), |
| 112 | 'open_auto' => $this->should_auto_load(), |
| 113 | 'popups' => ( new PopupData() )->get_popups(), |
| 114 | ] |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @return bool |
| 120 | */ |
| 121 | private function should_auto_load(): bool { |
| 122 | return ! $this->finish_option->is_option_set() && $this->fs_methods_checker->is_new_shipping_method(); |
| 123 | } |
| 124 | } |
| 125 |