Advertisement
geminilabs

[site-reviews] Add a category dropdown to the form

Oct 15th, 2018 (edited)
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. //
  2. // ADDING CUSTOM FIELDS TO THE SUBMISSION FORM IS NOT ACTIVELY SUPPORTED!
  3. // However, if you would like to add a category dropdown to the form, this should help get you started.
  4. // This will only work in Site Review v5
  5. //
  6.  
  7. /**
  8.  * Adds a category dropdown field to the Site Reviews submission form.
  9.  * Paste this in your active theme's functions.php file.
  10.  * @param array $fields
  11.  * @return array
  12.  */
  13. add_filter('site-reviews/config/forms/review-form', function ($fields) {
  14.     $categories = get_terms([
  15.         'count' => false,
  16.         'fields' => 'id=>name',
  17.         'hide_empty' => false,
  18.         'taxonomy' => glsr()->taxonomy,
  19.     ]);
  20.     if (is_wp_error($categories)) {
  21.         glsr_log()->error($categories->get_error_message());
  22.         return $fields;
  23.     }
  24.     $fields['assigned_terms'] = [
  25.         'label' => 'Category',
  26.         'required' => true,
  27.         'options' => ['' => __('Select a category', 'site-reviews')] + $categories,
  28.         'type' => 'select',
  29.     ];
  30.     return $fields;
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement