Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 1. Create a custom Toggle field in your form and change the _Field Name_ and _Template Tag_ to "is_mystery_user"
- * 2. Add a "review_as_mystery_user" capability to the user role that can review as a mystery user (change this as needed)
- * 3. Add the code snippet to your website
- */
- /**
- * This changes the "is_mystery_user" Toggle field in the review form to a Hidden field for specific users.
- */
- function glsr_modify_is_mystery_user_field ($fields): array {
- // check if the user can review as a mystery user.
- // change as needed...
- if (!current_user_can('review_as_mystery_user')) {
- return $fields;
- }
- // This will change the "is_mystery_user" custom field type to a hidden field.
- // hidden field values cannot be tampered with!
- foreach ($fields as $field) {
- if ('is_mystery_user' === $field->original_name) {
- $field->id = '';
- $field->is_raw = true;
- $field->original_type = 'hidden';
- $field->type = 'hidden';
- break;
- }
- }
- return $fields;
- }
- add_filter('site-reviews-authors/update-review-form/fields/all', 'glsr_modify_is_mystery_user_field', 10, 2);
- add_filter('site-reviews/review-form/fields/all', 'glsr_modify_is_mystery_user_field', 10, 2);
- /**
- * This changes the HTML _value_ of the rendered {{ is_mystery_user }} template tag.
- */
- function glsr_modify_is_mystery_user_template_tag_value ($value, $tag): string {
- if (empty($value)) {
- return $value;
- }
- return 'đ»'; // change this to your custom html string...
- }
- add_filter('site-reviews/custom/value/is_mystery_user', 'glsr_modify_is_mystery_user_template_tag_value', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment