Respect/Validation library (or similar) in plugins
-
;TL/DR;
– Is the Respect/Validation library too heavy for a WordPress plugin?
– Can someone point to a repo that shows this library in use in a WordPress plugin?
– Is there a better general-purpose validation library for WordPress plugins?Context:
I’m creating a new plugin template for myself, as a base for actual plugins. Where a plugin can be a single file, and some are Huge multi-folder applications, even with only admin/dashboard functionality this template is already a bit heavy. So I’m concerned about adding more to it. I don’t want to create a tool that’s convenient for me to spin up new plugins, while being a runtime resource hog. The plan is to build in a lot of potential functionality, and then to strip out functionality that’s not used in specific plugins, whether CPTs, shortcodes, widgets, taxonomy, etc. My effectiveness in modularization will be measured in the amount of code that’s left in to support minimal functionality. For example, it’s not lean enough if I can’t remove classes with extensive dashboard code from a plugin that has no settings page.Any site that allows user input needs data sanitization and validation. We can, for example use the WP built-in functions like is_email(), sanitize_email() and esc_url() on output of a mailto: link.
For further data validation, like checking to see if text has some number of characters, if a date is within a range, etc, there is common code that every application needs, that we can either write from scratch for every field.
Or we can use a purpose-built library – which is what the Respect/Validation library is.
Reason for considering this library: I can define validation rules as data with fields, along with other details like type, label, description, display and sanitization callbacks, defaults, and options for select lists. Then a sanitization callback does not itself need validation code, it can invoke the validation rules in a single line. (Right now I do sanitization on submit callback and if form data is valid I use the pre_update_option filter for field-specific validation.)
To the questions:
I have not been able to find a plugin that includes this library/dependency. Outside of subjective taste and suggestions to monitor performance, is there some specific reason to not use this or other libraries for functionality like this?
Is there a guideline about dependencies in WP plugins?
I would especially like to hear from plugin developers who have use this or other validation libraries, and their considerations, concerns, and decisions.
Thanks for your time.
- The topic ‘Respect/Validation library (or similar) in plugins’ is closed to new replies.