Open justintadlock opened 1 month ago
Perfect! 👍 Thanks a lot for this feedback. The PHP code looks much cleaner and suitable for a blog post now.
@justintadlock, to avoid cache issues with CSS files, would it be correct to add the same $asset['version']
generated in the build process for JS files to the CSS files?
wp_enqueue_script(
'devblog-dataview-script',
$url . 'build/index.js',
$asset['dependencies'],
$asset['version'],
array(
'in_footer' => true,
)
);
wp_enqueue_style(
'devblog-dataview-styles',
$url . 'build/style-index.css',
array( 'wp-components' ),
$asset['dependencies']
);
Yes, you could definitely do that to get proper cache busting.
Edit: Note that your code references $asset['dependencies']
instead of $asset['version']
.
Edit: Note that your code references $asset['dependencies'] instead of $asset['version'].
Yes, thanks for the heads up. I also noticed that and fixed it in my code (forgot to update the snippet here).
Because of the limitations of the tutorial format, I think it'd be better to consolidate all the PHP (it's really only two functions) into the primary
plugin.php
file. This would let you get rid of some boilerplate stuff and simplify it. I've shared the code below.I made a few other changes too:
<h2>
for the admin page is now internationalized (shouldn't this be an<h1>
?).PLUGIN_*
constants (note that if you use these, they should be prefixed/namespaced).wp-components
as a dependency for your style instead of enqueueing it separately.devblog-
to match other prefixes used.Anyway, the overall code will be easier to share in a Dev Blog tutorial because it will require fewer files and less setup for the reader.
plugin.php