Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Use custom templates for the candle shape/colour radio fields in the form
- *
- * Copy the "/wp-content/plugins/site-reviews/templates/form/type-radio.php" file from the plugin to your theme:
- * 1. "/wp-content/themes/<your-child-theme>/site-reviews/form/type-radio-candle-color.php"
- * 2. "/wp-content/themes/<your-child-theme>/site-reviews/form/type-radio-candle-shape.php"
- *
- * @param string $view
- * @param array $data
- * @return string
- */
- add_filter('site-reviews/render/view', function ($view, $data) {
- if ('templates/form/type-radio' !== $view) {
- return $view;
- }
- $fieldname = glsr_get($data, 'field.path');
- if ('candle_color' === $fieldname) {
- return 'templates/form/type-radio-candle-color';
- }
- if ('candle_shape' === $fieldname) {
- return 'templates/form/type-radio-candle-shape';
- }
- return $view;
- }, 10, 2);
- /**
- * This will add a {{ rating_style_class }} template tag which you can use in the review template
- * of your custom form in the class="" attribute of the review which will allow you to target the
- * rating images on the review with custom CSS based on the submitted candle shape and colour.
- *
- * @param array $context
- * @param string $template
- * @param array $data
- * @return array
- */
- add_filter('site-reviews/interpolate/review', function ($context, $template, $data) {
- $context['rating_style_class'] = '';
- $color = glsr_get($data, 'review.custom.candle_color');
- $shape = glsr_get($data, 'review.custom.candle_shape');
- if (!empty($color) && !empty($shape)) {
- $context['rating_style_class'] = sprintf('rating-%s-%s', $shape, $color);
- }
- return $context;
- }, 10, 3);
Add Comment
Please, Sign In to add comment