geminilabs

Untitled

Jul 15th, 2021 (edited)
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. /**
  2.  * Use custom templates for the candle shape/colour radio fields in the form
  3.  *
  4.  * Copy the "/wp-content/plugins/site-reviews/templates/form/type-radio.php" file from the plugin to your theme:
  5.  *   1. "/wp-content/themes/<your-child-theme>/site-reviews/form/type-radio-candle-color.php"
  6.  *   2. "/wp-content/themes/<your-child-theme>/site-reviews/form/type-radio-candle-shape.php"
  7.  *
  8.  * @param string $view
  9.  * @param array $data
  10.  * @return string
  11.  */
  12. add_filter('site-reviews/render/view', function ($view, $data) {
  13.     if ('templates/form/type-radio' !== $view) {
  14.         return $view;
  15.     }
  16.     $fieldname = glsr_get($data, 'field.path');
  17.     if ('candle_color' === $fieldname) {
  18.         return 'templates/form/type-radio-candle-color';
  19.     }
  20.     if ('candle_shape' === $fieldname) {
  21.         return 'templates/form/type-radio-candle-shape';
  22.     }
  23.     return $view;
  24. }, 10, 2);
  25.  
  26. /**
  27.  * This will add a {{ rating_style_class }} template tag which you can use in the review template
  28.  * of your custom form in the class="" attribute of the review which will allow you to target the
  29.  * rating images on the review with custom CSS based on the submitted candle shape and colour.
  30.  *
  31.  * @param array $context
  32.  * @param string $template
  33.  * @param array $data
  34.  * @return array
  35.  */
  36. add_filter('site-reviews/interpolate/review', function ($context, $template, $data) {
  37.     $context['rating_style_class'] = '';
  38.     $color = glsr_get($data, 'review.custom.candle_color');
  39.     $shape = glsr_get($data, 'review.custom.candle_shape');
  40.     if (!empty($color) && !empty($shape)) {
  41.         $context['rating_style_class'] = sprintf('rating-%s-%s', $shape, $color);
  42.     }
  43.     return $context;
  44. }, 10, 3);
  45.  
Add Comment
Please, Sign In to add comment