?php /** * Handle frontend scripts * * @class FI_Frontend_Scripts * @version 1.0 * @package FITheme/Classes/ * @category Class * @author NicoL */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * FI_Frontend_Scripts Class. */ class FI_Frontend_Scripts { /** * Contains an array of script handles registered by FI. * @var array */ private static $scripts = array(); /** * Contains an array of script handles registered by FI. * @var array */ private static $styles = array(); /** * Contains an array of script handles localized by FI. * @var array */ private static $wp_localize_scripts = array(); /** * Hook in methods. */ public static function init() { add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) ); add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); } /** * Get styles for the frontend. * @access private * @return array */ public static function get_styles() { return apply_filters( 'fitheme_enqueue_styles', array( 'pc-bootstrap' => array( 'src' => str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/css/bootstrap/styles.css', 'deps' => '', 'version' => FI_VERSION, 'media' => 'all' ), 'pc-sprite' => array( 'src' => str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/css/sprite.css', 'deps' => '', 'version' => FI_VERSION, 'media' => 'all' ), 'pc-select2' => array( 'src' => str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/css/external/select2.min.css', 'deps' => '', 'version' => FI_VERSION, 'media' => 'all' ), 'pc-theme' => array( 'src' => str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/css/theme.css', 'deps' => '', 'version' => FI_VERSION, 'media' => 'all' ), 'pc-responsive' => array( 'src' => str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/css/responsive.css', 'deps' => '', 'version' => FI_VERSION, 'media' => 'all' ), ) ); } /** * Register a script for use. * * @uses wp_register_script() * @access private * @param string $handle * @param string $path * @param string[] $deps * @param string $version * @param boolean $in_footer */ private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = FI_VERSION, $in_footer = true ) { self::$scripts[] = $handle; wp_register_script( $handle, $path, $deps, $version, $in_footer ); } /** * Register and enqueue a script for use. * * @uses wp_enqueue_script() * @access private * @param string $handle * @param string $path * @param string[] $deps * @param string $version * @param boolean $in_footer */ private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = FI_VERSION, $in_footer = true ) { if ( ! in_array( $handle, self::$scripts ) && $path ) { self::register_script( $handle, $path, $deps, $version, $in_footer ); } wp_enqueue_script( $handle ); } /** * Register a style for use. * * @uses wp_register_style() * @access private * @param string $handle * @param string $path * @param string[] $deps * @param string $version * @param string $media */ private static function register_style( $handle, $path, $deps = array(), $version = FI_VERSION, $media = 'all' ) { self::$styles[] = $handle; wp_register_style( $handle, $path, $deps, $version, $media ); } /** * Register and enqueue a styles for use. * * @uses wp_enqueue_style() * @access private * @param string $handle * @param string $path * @param string[] $deps * @param string $version * @param string $media */ private static function enqueue_style( $handle, $path = '', $deps = array(), $version = FI_VERSION, $media = 'all' ) { if ( ! in_array( $handle, self::$styles ) && $path ) { self::register_style( $handle, $path, $deps, $version, $media ); } wp_enqueue_style( $handle ); } /** * Register/queue frontend scripts. */ public static function load_scripts() { global $post; if ( ! did_action( 'before_fitheme_init' ) ) { return; } $suffix = ''; // defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; $enable_cookie = 'yes' === get_option( 'fitheme_enable_cookie' ); $assets_path = str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/js/'; $frontend_script_path = $assets_path . 'frontend/'; // Register any scripts for later use, or used as dependencies self::register_script( 'bootstrap', $assets_path . 'vendor/bootstrap/bootstrap.js' ); self::register_script( 'select2', $assets_path . 'vendor/select2.min.js' ); self::register_script( 'cycle2', $assets_path . 'vendor/jquery.cycle2.min.js' ); self::register_script( 'cycle2-center', $assets_path . 'vendor/jquery.cycle2.center.min.js', array('cycle2') ); self::register_script( 'cycle2-swipe', $assets_path . 'vendor/jquery.cycle2.swipe.min.js', array('cycle2') ); self::register_script( 'fitheme-front', $assets_path . 'main' . $suffix . '.js', array( 'jquery' ) ); // self::enqueue_script( 'bootstrap' ); self::enqueue_script( 'cycle2' ); self::enqueue_script( 'cycle2-center' ); self::enqueue_script( 'cycle2-swipe' ); self::enqueue_script( 'fitheme-front' ); self::enqueue_script( 'select2' ); wp_dequeue_script( 'jquery-ui' ); wp_localize_script( 'fitheme-front', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'opening_hours_action' => 'get_opening_hours' ) ); // CSS Styles if ( $enqueue_styles = self::get_styles() ) { foreach ( $enqueue_styles as $handle => $args ) { self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'] ); } } } /** * Localize a FI script once. * @access private * @since 1.0 this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0. * @param string $handle */ private static function localize_script( $handle ) { if ( ! in_array( $handle, self::$wp_localize_scripts ) && wp_script_is( $handle ) && ( $data = self::get_script_data( $handle ) ) ) { $name = str_replace( '-', '_', $handle ) . '_params'; self::$wp_localize_scripts[] = $handle; wp_localize_script( $handle, $name, apply_filters( $name, $data ) ); } } /** * Return data for script handles. * @access private * @param string $handle * @return array|bool */ private static function get_script_data( $handle ) { switch ( $handle ) { case 'some-handle' : return array( 'ajax_url' => FI()->ajax_url(), // 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ), // 'some_option' => get_option( 'fitheme_some_option' ), // 'some_nonce' => wp_create_nonce( 'some-fitheme' ), // 'some_variable' => json_encode( FI()->some_object->get_something() ), // 'i18n_required_text' => esc_attr__( 'required', 'fitheme' ), // 'some_filtered_name' => apply_filters( 'fitheme_some_filtered_name', 'fi_name_default' ), // 'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'fitheme' ), 'debug_mode' => defined('WP_DEBUG') && WP_DEBUG, ); break; case 'another-handle' : return array( // ); break; } return false; } /** * Localize scripts only when enqueued. */ public static function localize_printed_scripts() { foreach ( self::$scripts as $handle ) { self::localize_script( $handle ); } } } FI_Frontend_Scripts::init(); {"version":"1.0","provider_name":"Parc Floral de La Source","provider_url":"https:\/\/parcfloraldelasource.com","author_name":"Jean Weissenbacher","author_url":"https:\/\/parcfloraldelasource.com\/profile\/admin_pf\/","title":"Animation \u00ab\u00a0Soigneur d’1 Jour\u00a0\u00bb","type":"rich","width":600,"height":338,"html":"
Animation \u00ab\u00a0Soigneur d’1 Jour\u00a0\u00bb<\/a><\/blockquote>