"; } function is_assoc($arr): bool { if (!is_array($arr)) return false; if (array() === $arr) return false; return array_keys($arr) !== range(0, count($arr) - 1); } function set_default_value(array &$array, string $key, $value) { if (!isset($array[$key])) { $array[$key] = $value; } } add_shortcode(ASCIIPLAYER_TAG, 'handle_asciiplayer_code'); function load_scripts() { if (!is_single()) { return; } global $post; if (has_shortcode($post->post_content, ASCIIPLAYER_TAG)) { wp_enqueue_script( 'asciiplayer-adapter-js', get_adapter_url() . '/dist/bundle.js', array(), PLUGIN_VERSION ); wp_enqueue_style( 'asciiplayer-adapter-css', get_adapter_url() . '/dist/styles.css', array(), PLUGIN_VERSION ); } } add_action('wp_enqueue_scripts', 'load_scripts'); function get_adapter_url(): string { $use_local_resources = boolval(get_option(AP_OPTION_USE_LOCAL_RESOURCES, true)); $version = PLUGIN_VERSION; if ($use_local_resources) { return plugin_dir_url(__FILE__) . '/asciiplayer'; } else { return "https://cdn.jsdelivr.net/npm/wp-asciiplayer-adapter@$version"; } }