geminilabs

Untitled

Sep 25th, 2025 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. /**
  2.  * 1. Create a custom Toggle field in your form and change the _Field Name_ and _Template Tag_ to "is_mystery_user"
  3.  * 2. Add a "review_as_mystery_user" capability to the user role that can review as a mystery user (change this as needed)
  4.  * 3. Add the code snippet to your website
  5.  */
  6.  
  7. /**
  8.  * This changes the "is_mystery_user" Toggle field in the review form to a Hidden field for specific users.
  9.  */
  10. function glsr_modify_is_mystery_user_field ($fields): array {
  11.     // check if the user can review as a mystery user.
  12.     // change as needed...
  13.     if (!current_user_can('review_as_mystery_user')) {
  14.         return $fields;
  15.     }
  16.     // This will change the "is_mystery_user" custom field type to a hidden field.
  17.     // hidden field values cannot be tampered with!
  18.     foreach ($fields as $field) {
  19.         if ('is_mystery_user' === $field->original_name) {
  20.             $field->id = '';
  21.             $field->is_raw = true;
  22.             $field->original_type = 'hidden';
  23.             $field->type = 'hidden';
  24.             break;
  25.         }
  26.     }
  27.     return $fields;
  28. }
  29. add_filter('site-reviews-authors/update-review-form/fields/all', 'glsr_modify_is_mystery_user_field', 10, 2);
  30. add_filter('site-reviews/review-form/fields/all', 'glsr_modify_is_mystery_user_field', 10, 2);
  31.  
  32. /**
  33.  * This changes the HTML _value_ of the rendered {{ is_mystery_user }} template tag.
  34.  */
  35. function glsr_modify_is_mystery_user_template_tag_value ($value, $tag): string {
  36.     if (empty($value)) {
  37.         return $value;
  38.     }
  39.     return 'đŸ‘»'; // change this to your custom html string...
  40. }
  41. add_filter('site-reviews/custom/value/is_mystery_user', 'glsr_modify_is_mystery_user_template_tag_value', 10, 2);
  42.  
Advertisement
Add Comment
Please, Sign In to add comment