Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This will prefill the Rating field and an Assigned Posts custom field value using URL parameters
- *
- * Example: https://website.com?assigned_posts=123&rating=5
- *
- * @param array $fields
- * @param \GeminiLabs\SiteReviews\Arguments $args
- * @return array
- */
- add_filter('site-reviews/review-form/fields', function ($fields, $args) {
- // Assigned Posts
- $assignedPosts = filter_input(INPUT_GET, 'assigned_posts', FILTER_VALIDATE_INT);
- if (false !== $assignedPosts) {
- $key = array_search('assigned_posts', array_column($fields, 'name'));
- if (-1 !== $key) {
- $fields[$key]['value'] = $assignedPosts;
- }
- }
- // Rating
- $rating = filter_input(INPUT_GET, 'rating', FILTER_VALIDATE_INT, [
- 'options' => [
- 'min_range' => 0,
- 'max_range' => 5,
- ]
- ]);
- if (false !== $rating) {
- $key = array_search('rating', array_column($fields, 'name'));
- if (-1 !== $key) {
- $fields[$key]['value'] = $rating;
- }
- }
- return $fields;
- }, 30, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement