Skip to content

Instantly share code, notes, and snippets.

@bgrgicak
Created March 3, 2026 06:09
Show Gist options
  • Select an option

  • Save bgrgicak/4d619e8f4aae0b06e4eb7ee6e619fd0b to your computer and use it in GitHub Desktop.

Select an option

Save bgrgicak/4d619e8f4aae0b06e4eb7ee6e619fd0b to your computer and use it in GitHub Desktop.
Mime type test
{
"landingPage": "/",
"preferredVersions": {
"php": "8.2",
"wp": "latest"
},
"steps": [
{
"step": "mkdir",
"path": "/wordpress/wp-content/plugins/test-cjs-mjs/assets"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/plugins/test-cjs-mjs/test-cjs-mjs.php",
"data": "<?php\n/**\n * Plugin Name: CJS & MJS Test Plugin\n * Description: A small plugin to test the enqueueing of .cjs and .mjs files.\n * Version: 1.0.0\n */\n\nif ( ! defined( 'ABSPATH' ) ) exit;\n\nadd_action( 'wp_enqueue_scripts', function() {\n\t$plugin_url = plugin_dir_url( __FILE__ );\n\twp_enqueue_script( 'test-cjs-script', $plugin_url . 'assets/script.cjs', [], '1.0.0', true );\n\tif ( function_exists( 'wp_enqueue_script_module' ) ) {\n\t\twp_enqueue_script_module( 'test-mjs-script', $plugin_url . 'assets/script.mjs', [], '1.0.0' );\n\t} else {\n\t\twp_enqueue_script( 'test-mjs-script-fallback', $plugin_url . 'assets/script.mjs', [], '1.0.0', true );\n\t\tadd_filter( 'script_loader_tag', function ( $tag, $handle ) {\n\t\t\tif ( 'test-mjs-script-fallback' === $handle ) return str_replace( '<script ', '<script type=\"module\" ', $tag );\n\t\t\treturn $tag;\n\t\t}, 10, 2 );\n\t}\n} );"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/plugins/test-cjs-mjs/assets/script.cjs",
"data": "console.log('Success: .cjs script file loaded and executed.');"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/plugins/test-cjs-mjs/assets/script.mjs",
"data": "console.log('Success: .mjs script file loaded and executed.');"
},
{
"step": "activatePlugin",
"pluginPath": "test-cjs-mjs/test-cjs-mjs.php"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment