basename( plugin_dir_path( $manifest_path ) ), 'filter' => '__return_true', 'scripts' => [], 'styles' => [], ]; $opts = wp_parse_args( $opts, $defaults ); $assets = get_assets_list( $manifest_path ); if ( empty( $assets ) ) { // Trust the theme or pluign to handle its own asset loading. return false; } // Keep track of whether a CSS file has been encountered. $has_css = false; // There should only be one JS and one CSS file emitted per plugin or theme. foreach ( $assets as $asset_uri ) { if ( $opts['filter'] && ! $opts['filter']( $asset_uri ) ) { // Ignore file paths which do not pass the provided filter test. continue; } $is_js = preg_match( '/\.js$/', $asset_uri ); $is_css = preg_match( '/\.css$/', $asset_uri ); $is_chunk = preg_match( '/\.chunk\./', $asset_uri ); if ( ( ! $is_js && ! $is_css ) || $is_chunk ) { // Assets such as source maps and images are also listed; ignore these. continue; } if ( $is_js ) { wp_enqueue_script( $opts['handle'], $asset_uri, $opts['scripts'], filemtime( $manifest_path ), true ); if ($opts['handle'] === 'ai-bot') { $plugin_data = get_option( 'ai_bot_settings_option_name' ); $plugin_data['settings_page'] = admin_url( 'options-general.php?page=aibot-settings' ); wp_localize_script( $opts['handle'], 'aibot', $plugin_data ); } } elseif ( $is_css ) { $has_css = true; wp_enqueue_style( $opts['handle'], $asset_uri, $opts['styles'], filemtime( $manifest_path ) ); } } // Ensure CSS dependencies are always loaded, even when using CSS-in-JS in // development. if ( ! $has_css && ! empty( $opts['styles'] ) ) { wp_register_style( $opts['handle'], null, $opts['styles'] ); wp_enqueue_style( $opts['handle'] ); } // Signal that auto-loading occurred. return true; }