ATW_Bookly_Rest::url(), 'nonce' => wp_create_nonce('wp_rest'), 'providers' => array_values($providers), 'buttonLabel' => $settings['button_label'], 'preparingLabel' => __('Preparing your pass…', 'addtowallet-for-bookly'), 'errorLabel' => __('Pass unavailable', 'addtowallet-for-bookly'), 'backgroundColor' => $settings['background_color'], 'debug' => (bool) $settings['debug'], /** * Official Apple/Google badges, served from this plugin rather than a CDN so * merchant sites make no third-party request and the artwork cannot * disappear from under an installed copy. */ 'walletBadges' => [ 'apple' => ATW_BOOKLY_URL . 'assets/img/add_to_apple_wallet.png', 'google' => ATW_BOOKLY_URL . 'assets/img/add_to_google_wallet_add-wallet.png', ], 'appleLabel' => __('Add to Apple Wallet', 'addtowallet-for-bookly'), 'googleLabel' => __('Add to Google Wallet', 'addtowallet-for-bookly'), ]; } public static function enqueue() { $providers = self::providers_for_this_page(); if (!$providers) { return; } $settings = ATW_Bookly_Settings::get(); if (empty($settings['api_key'])) { return; } /** * The file's modification time rides along with the version, so an in-place * update that does not bump the version is never served from a browser cache. */ $file = ATW_BOOKLY_DIR . 'assets/js/bookly-addtowallet.js'; $ver = ATW_BOOKLY_VERSION . (file_exists($file) ? '.' . filemtime($file) : ''); wp_register_script(self::HANDLE, ATW_BOOKLY_URL . 'assets/js/bookly-addtowallet.js', [], $ver, true); wp_add_inline_script(self::HANDLE, 'var AtwBooklyConfig = ' . wp_json_encode(self::config($providers)) . ';', 'before'); wp_enqueue_script(self::HANDLE); } /** * @return string[] Ids of providers that are active and present on this page. */ private static function providers_for_this_page() { $available = ATW_Bookly_Providers::available(); if (!$available) { return []; } /** * Force the adapter on or off, for themes and page builders that render Bookly in * a way this cannot detect (widgets, template parts, Elementor, and so on). * * @param bool|null $force true to load, false to skip, null to auto-detect. */ $force = apply_filters('atw_bookly_force_enqueue', null); if ($force === false) { return []; } if ($force === true) { return array_keys($available); } if (!is_singular()) { return []; } $post = get_post(); if (!$post instanceof WP_Post) { return []; } $ids = []; foreach ($available as $id => $provider) { if ($provider->should_enqueue($post)) { $ids[] = $id; } } return $ids; } }