クラス
WishlistPage
Wishlist page HTML and JS
ソース ソース
ファイル: src/Views/WishlistPage/WishlistPage.php
class WishlistPage { const SCRIPT_HANDLE = 'wcexwl-wishlist'; /** * Master object * * @var Master */ protected $master; /** * Injects `Master` object * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param Master $master * @return void */ public function __construct(Master $master) { $this->master = $master; } /** * Registers hooks * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function init() { add_action('wp_enqueue_scripts', [$this, 'loadEssentialAssets']); add_filter('usces_filter_template_redirect', [$this, 'handleWishlistPageTemplateLoad'], 1, 1); // deprecated hook add_filter('asumil_filter_wishlist_batch_dropdown', 'wcexwl_get_wishlist_batch_action_section', 10, 1); } /** * If the current page is the wishlist page, loads theme's `wishlist.php` if it exists, * otherwise loads default HTML for wishlist page and exits. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param bool $flag * @return bool `false` when not exiting with template content */ public function handleWishlistPageTemplateLoad($flag) { if (!Utils::isWishlistPage($_SERVER['REQUEST_URI'])) { return $flag; } $parent_path = get_template_directory(); $child_path = get_stylesheet_directory(); /** * Filters the absolute path to the `wishlist.php` for the **parent theme** * * @important * @param string $parent_path Default: `get_template_directory() . '/wishlist.php'` */ $parent_file = apply_filters('wcexwl_filter_wishlist_page_parent_path', $parent_path . '/wishlist.php'); /** * Filters the absolute path to the `wishlist.php` for the **child theme** * * @important * @param string $child_path Default: `get_stylesheet_directory() . '/wishlist.php'` */ $child_file = apply_filters('wcexwl_filter_wishlist_page_child_path', $child_path . '/wishlist.php'); if (!file_exists($child_file) && !file_exists($parent_file)) { include(WCEXWL_PLUGIN_DIR . '/src/templates/wishlist.php'); exit; } return $flag; } /** * Loads CSS/JS for wishlist page * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global bool $usces_gp * @return void */ public function loadEssentialAssets() { if (!Utils::isWishlistPage($_SERVER['REQUEST_URI'])) { return; } /** * Return `false` with this hook to prevent wishlist page CSS from being loaded * * @important * @param bool $flag Default: `true` */ if (apply_filters('wcexwl_filter_wishlist_page_load_css', true)) { // load semantic-ui and common css Utils::loadCommonCss(); Semantic::loadButtonCss(); Semantic::loadLoaderCss(); Semantic::loadDividerCss(); Semantic::loadIconCss(); Semantic::loadImageCss(); Semantic::loadCheckboxCss(); // load css for page wp_enqueue_style( 'wcexwl-wishlist-page', WCEXWL_PLUGIN_URL . '/src/Styles/wishlist.css', [], WCEXWL_VERSION ); } // load JS client SDK $this->master->loadClientSdk(); wp_enqueue_script( 'wishlist-bootstrap', WCEXWL_PLUGIN_URL . '/src/Views/WishlistPage/bootstrap.js', [], WCEXWL_VERSION, true ); wp_localize_script('wishlist-bootstrap', 'wlbootstrap', ['theme' => Master::getThemeConfig()['name']]); /** * Fires after all wishlist page common/default JS/CSS has been enqueued * * Use this hook to enqueue your own JS/CSS on the wishlist page if necessary. * * @important */ do_action('wcexwl_wishlist_page_on_load_assets'); if (!usces_is_login()) { return; } $this->loadImplementationAssets(); } /** * Extend to load assets for the implementation view * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ protected function loadImplementationAssets() { wp_enqueue_script( self::SCRIPT_HANDLE, WCEXWL_PLUGIN_URL . '/src/Views/WishlistPage/wishlist.js', [], WCEXWL_VERSION, true ); wp_localize_script(self::SCRIPT_HANDLE, 'wcexwl', $this->master->getScriptInjectionVariables()); Snackbar::load([self::SCRIPT_HANDLE]); } }
- __construct — Injects Master object
- handleWishlistPageTemplateLoad — If the current page is the wishlist page, loads theme's wishlist.php if it exists, otherwise loads default HTML for wishlist page and exits.
- init — Registers hooks
- loadEssentialAssets — Loads CSS/JS for wishlist page
- loadImplementationAssets — Extend to load assets for the implementation view