Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Restrict the title to 80 characters (client side)
- * @param array $field
- * @return array
- */
- add_filter('site-reviews/field/text', function ($field) {
- if ('title' === $field['path']) {
- $field['maxlength'] = 80;
- }
- return $field;
- });
- /**
- * Restrict the title to 80 characters (server side)
- * @param array $rules
- * @return array
- */
- add_filter('site-reviews/validation/rules', function ($rules) {
- if (array_key_exists('title', $rules)) {
- $rule = 'max:80';
- // change any existing max: rule
- $rules['title'] = preg_replace('/(max:\d+)/', $rule, $rules['title'], -1, $result);
- // if no max: rule was found, then add it
- if (0 === $result) {
- $parts = explode('|', $rules['title']);
- $parts[] = $rule;
- $rules['title'] = implode('|', $parts);
- }
- }
- return $rules;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement