Inventory_Presser_Plugin::include_scripts_and_styles()
Registers JavaScripts and stylesheets for front-end users and dashboard users. Includes some inline styles and scripts depending on the plugin settings and page request.
Return Return
(void)
Source Source
File: inventory-presser.php
public static function include_scripts_and_styles() {
// This method might have run already.
if ( wp_script_is( 'invp-slider', 'registered' ) ) {
// Abort.
return;
}
// Allow dashicons use on frontend.
wp_enqueue_style( 'dashicons' );
/**
* Register stylesheets that will only be enqueued when specific
* widgets or shortcodes are used.
*/
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_style(
'invp-grid',
plugins_url( "css/widget-grid{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
wp_register_style(
'invp-maximum-price-filters',
plugins_url( "css/widget-maximum-price-filters{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
wp_register_style(
'invp-epa-fuel-economy',
plugins_url( "css/widget-epa-fuel-economy{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
wp_register_style(
'invp-slider',
plugins_url( "css/widget-slider{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
// Register a script without a .js URL for our inline invp object.
if ( ! wp_script_is( 'invp', 'registered' ) ) {
$settings = INVP::settings();
wp_register_script( 'invp', '', array(), INVP_PLUGIN_VERSION, true );
wp_add_inline_script(
'invp',
'var invp = ' . wp_json_encode(
array(
'hull_materials' => apply_filters(
'invp_default_hull_materials',
array(
__( 'Aluminum', 'inventory-presser' ),
__( 'Carbon Fiber', 'inventory-presser' ),
__( 'Composite', 'inventory-presser' ),
__( 'Ferro-Cement', 'inventory-presser' ),
__( 'Fiberglass', 'inventory-presser' ),
__( 'Hypalon', 'inventory-presser' ),
__( 'Other', 'inventory-presser' ),
__( 'PVC', 'inventory-presser' ),
__( 'Steel', 'inventory-presser' ),
__( 'Wood', 'inventory-presser' ),
)
),
'is_singular' => is_singular( INVP::POST_TYPE ), // Used by flexslider.js.
'meta_prefix' => INVP::meta_prefix(), // Used by classic-editor.js & editor-sidebar.js.
'odometer_label' => apply_filters( 'invp_odometer_word', __( 'Odometer', 'inventory-presser' ) ),
'odometer_units' => apply_filters( 'invp_odometer_word', __( 'miles', 'inventory-presser' ) ),
'payment_frequencies' => apply_filters(
'invp_default_payment_frequencies',
array(
'Monthly' => 'monthly',
'Weekly' => 'weekly',
'Bi-weekly' => 'biweekly',
'Semi-monthly' => 'semimonthly',
)
),
'taxonomies' => $settings['taxonomies'] ?? array(),
'title_statuses' => apply_filters(
'invp_default_title_statuses',
array(
__( 'Unspecified', 'inventory-presser' ),
__( 'Clear', 'inventory-presser' ),
__( 'Clean', 'inventory-presser' ),
__( 'Flood, Water Damage', 'inventory-presser' ),
__( 'Lemon and Manufacturers Buyback', 'inventory-presser' ),
__( 'Rebuild, Rebuildable, and Reconstructed', 'inventory-presser' ),
__( 'Salvage', 'inventory-presser' ),
__( 'Other', 'inventory-presser' ),
)
),
)
) . ';'
);
// Register a script for our blocks, also without a .js URL.
wp_register_script(
'invp-blocks',
'',
array(),
INVP_PLUGIN_VERSION,
true
);
// Provide the vehicle post type meta keys and prefix to JavaScript.
wp_add_inline_script(
'invp-blocks',
'const invp_blocks = ' . wp_json_encode(
array(
'currency_symbol' => INVP::currency_symbol(),
'keys' => INVP::keys_and_types(),
'meta_prefix' => INVP::meta_prefix(),
'odometer_units' => apply_filters( 'invp_odometer_word', __( 'Miles', 'inventory-presser' ) ),
'use_carfax' => $settings['use_carfax'],
'use_carfax_provided_buttons' => $settings['use_carfax_provided_buttons'],
)
),
'before'
);
/**
* Register a stylesheet for the Block Editor. This makes the
* blocks provided by this plugin more pleasant to work with.
*/
wp_register_style(
'invp-block-editor',
plugins_url( "css/block-editor{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
}
/**
* Register flexslider and provide overrides for scripts and styles
*/
$min_dash = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '-min'; // Dash not dot!
wp_register_script(
'flexslider',
plugins_url( "/vendor/woocommerce/FlexSlider/jquery.flexslider{$min_dash}.js", INVP_PLUGIN_FILE_PATH ),
array( 'invp', 'jquery' ),
INVP_PLUGIN_VERSION,
true
);
// Our overrides.
wp_register_script(
'invp-flexslider',
plugins_url( "/js/flexslider{$min}.js", INVP_PLUGIN_FILE_PATH ),
array( 'flexslider' ),
INVP_PLUGIN_VERSION,
true
);
// Another flexslider spin-up script for the Vehicle Slider widget.
wp_register_script(
'invp-slider',
plugins_url( "/js/widget-slider{$min}.js", INVP_PLUGIN_FILE_PATH ),
array( 'flexslider' ),
INVP_PLUGIN_VERSION,
true
);
wp_register_script(
'invp_sort_by',
plugins_url( "/js/shortcode-sort-by{$min}.js", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION,
true
);
// Sort by Vehicle Attributes (Order By) widget.
wp_register_script(
'order-by-widget-javascript',
plugins_url( "js/order-by-post-meta-widget{$min}.js", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION,
true
);
// Flexslider.
wp_register_style(
'flexslider',
plugins_url( ( ! empty( $min ) ? "/css/woocommerce-flexslider{$min}.css" : '/vendor/woocommerce/FlexSlider/flexslider.css' ), INVP_PLUGIN_FILE_PATH ),
null,
INVP_PLUGIN_VERSION
);
// Our Flexslider overrides.
wp_register_style(
'invp-flexslider',
plugins_url( "/css/flexslider{$min}.css", INVP_PLUGIN_FILE_PATH ),
array( 'flexslider' ),
INVP_PLUGIN_VERSION
);
// Register the iFrameResizer.js script for use by our shortcode and Iframe block.
wp_register_script(
'invp-iframe-resizer',
plugins_url( "/js/iframe-resizer/iframeResizer{$min}.js", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION,
true
);
/**
* Register a stylesheet that will be used by two shortcodes,
*
and
*/
wp_register_style(
'invp-attribute-table',
plugins_url( "/css/vehicle-attribute-table{$min}.css", INVP_PLUGIN_FILE_PATH ),
null,
INVP_PLUGIN_VERSION
);
// Register multiple stylesheets for the archive vehicle shortcode.
// This one always loads.
wp_register_style(
'invp_archive_vehicle',
plugins_url( "/css/shortcode-archive-vehicle{$min}.css", INVP_PLUGIN_FILE_PATH ),
null,
INVP_PLUGIN_VERSION
);
// This one loads only when the style is set to "a".
wp_register_style(
'invp_archive_vehicle_a',
plugins_url( "/css/shortcode-archive-vehicle-a{$min}.css", INVP_PLUGIN_FILE_PATH ),
array( 'invp_archive_vehicle' ),
INVP_PLUGIN_VERSION
);
// This one loads only when the style is set to "b".
wp_register_style(
'invp_archive_vehicle_b',
plugins_url( "/css/shortcode-archive-vehicle-b{$min}.css", INVP_PLUGIN_FILE_PATH ),
array( 'invp_archive_vehicle' ),
INVP_PLUGIN_VERSION
);
// Register a stylesheet for the single vehicle shortcode.
wp_register_style(
'invp_single_vehicle',
plugins_url( "/css/shortcode-single-vehicle{$min}.css", INVP_PLUGIN_FILE_PATH ),
null,
INVP_PLUGIN_VERSION
);
// Register leaflet.js script and style files used in Map widget.
wp_register_script(
Inventory_Presser_Map_Widget::SCRIPT_HANDLE_LEAFLET,
plugins_url( 'js/leaflet/leaflet.js', INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION,
true
);
wp_register_script(
'invp-maps',
plugins_url( "js/widget-map{$min}.js", INVP_PLUGIN_FILE_PATH ),
array( Inventory_Presser_Map_Widget::SCRIPT_HANDLE_LEAFLET ),
INVP_PLUGIN_VERSION,
true
);
wp_register_style(
Inventory_Presser_Map_Widget::SCRIPT_HANDLE_LEAFLET,
plugins_url( "js/leaflet/leaflet{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
wp_register_style(
Inventory_Presser_Map_Widget::ID_BASE,
plugins_url( "css/widget-map{$min}.css", INVP_PLUGIN_FILE_PATH ),
array(),
INVP_PLUGIN_VERSION
);
// Admin location meta scripts.
wp_register_script(
'inventory-presser-timepicker',
plugins_url( '/js/jquery.timepicker.min.js', INVP_PLUGIN_FILE_PATH ),
array( 'jquery' ),
INVP_PLUGIN_VERSION,
true
);
wp_register_script(
'inventory-presser-location',
plugins_url( "/js/tax-location{$min}.js", INVP_PLUGIN_FILE_PATH ),
array( 'inventory-presser-timepicker', 'jquery-ui-sortable' ),
INVP_PLUGIN_VERSION,
true
);
// Classic Editor scripts.
wp_register_script(
'invp-classic-editor',
plugins_url( "/js/classic-editor{$min}.js", INVP_PLUGIN_FILE_PATH ),
array( 'invp' ),
INVP_PLUGIN_VERSION,
true
);
// Google Maps widget scripts.
wp_register_script(
'invp_google_maps_v3',
plugins_url( "js/widget-google-maps-v3{$min}.js", INVP_PLUGIN_FILE_PATH ),
array( 'invp_google_maps_v3_goog' ),
INVP_PLUGIN_VERSION,
true
);
}
Expand full source codeCollapse full source codeView on Github