Can anyone tell me what is the easiest, and simplest way - without using a plugin (i.e. code I can put directly into my site-specific plugin) to achieve this:
I’m presently using a plugin to insert it, which is not ideal for a number of reasons, so I thought I’d ask if anyone knows how to insert a checkbox like that that is required and returns an error if submitted unchecked?
…using a plugin is the simplest way. Have you considered just copying that plugin’s code into your own site-specific plugin?
Aside of this, you could hook in on the comment_form filter to add a checkbox…but, that only adds it. You’d still need code to check the value, return to (and repopulate) the form if not checked, somewhere to store the fact that the user checked the box…and code to show/hide the checkbox depending on the activation state of Akismet… probably more.
In other words, it might as well just be a plugin.
I suppose it depends on how your plugin is coded and what you want to achieve. If you’re just looking to prevent people from submitting the form without them acknowledging that their comments will be checked by Akismet, you could do something simple with Javascript.
If using JS for this, then you’d have to pretty much hide the form altogether if JS is disabled to prevent people from getting around it. I tend to surf JS-free (allowing scripts only as-needed.)
I don’t disagree. Without having more detailed info, that was just intended to be a quick “here’s something to think about” rather than a complete solution.
For years, I used NoScript. But I eventually got fed up of having to enable Javascript on a site-by-site basis. I think JS has become more prevalent and accepted in recent years, especially given the increased use of frameworks like Vue, React and AngularJS, etc. Most GDPR notices depend on JS for instance, which is ironic in a way.