scripts->register_script('wu-shepherd', wu_get_asset('lib/shepherd.js', 'js'), []); WP_Ultimo()->scripts->register_script('wu-tours', wu_get_asset('tours.js', 'js'), ['wu-shepherd', 'underscore']); } /** * Enqueues the scripts, if we need to. * * @since 2.0.0 * @return void */ public function enqueue_scripts(): void { if ($this->has_tours()) { wp_localize_script('wu-tours', 'wu_tours', $this->tours); wp_localize_script( 'wu-tours', 'wu_tours_vars', [ 'ajaxurl' => wu_ajax_url(), 'nonce' => wp_create_nonce('wu_tour_finished'), 'i18n' => [ 'next' => __('Next', 'wp-multisite-waas'), 'finish' => __('Close', 'wp-multisite-waas'), ], ] ); wp_enqueue_script('wu-tours'); } } /** * Checks if we have registered tours. * * @since 2.0.0 * @return boolean */ public function has_tours() { return ! empty($this->tours); } /** * Register a new tour. * * @see https://shepherdjs.dev/docs/ * * @since 2.0.0 * * @param string $id The id of the tour. * @param array $steps The tour definition. Check shepherd.js docs. * @param boolean $once Whether or not we will show this more than once. * @return void */ public function create_tour($id, $steps = [], $once = true): void { if (did_action('in_admin_header')) { return; } add_action( 'in_admin_header', function () use ($id, $steps, $once) { $force_hide = wu_get_setting('hide_tours', false); if ($force_hide) { return; } $finished = (bool) get_user_setting("wu_tour_$id", false); $finished = apply_filters('wu_tour_finished', $finished, $id, get_current_user_id()); if ( ! $finished || ! $once) { foreach ($steps as &$step) { $step['text'] = is_array($step['text']) ? implode('

', $step['text']) : $step['text']; $step['text'] = sprintf('

%s

', $step['text']); } $this->tours[ $id ] = $steps; } } ); } }