Support » Plugin: Site Reviews » Modify form field type=’rating’ & rearrange form fields into various column

  • Resolved pdlbibek

    (@pdlbibek)


    Hi!

    Kuddos for the perfect plugin. I just want to accomplish a few things. I hope you can help.

    1. First of all, I wanted to modify the ‘your rating’ field. I don’t want the star rating images there and want to change the dropdown options to something different.

    2. I want to rearrange some of the input fields into various columns. I’ve tried to copy the field.php file in my theme folder in the following manner:
    /wp-content/themes/your-theme/site-reviews/form/field.php
    But, no changes are visible in the frontend. I see the elements are different from what is rendered and I don’t see any other template files for the same.

    Also, any changes in this template will affect every field out there, I just wanted to add column classes to some of the fields, which I wanted to divide into columns.

    Any help is appreciated. Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    To use a dropdown for the rating field instead of the star rating, use the filter hook below:

    /**
     * Removes the '.glsr-star-rating' class from the rating field.
     * This will prevent the rating dropdown from being converted into a star rating control.
     * @param string $field
     * @param string $fieldType
     * @param array $fieldValues
     * @return string
     */
    add_filter('site-reviews/rendered/field', function ($field, $fieldType, $fieldValues) {
        $fieldName = glsr_get($fieldValues, 'path');
        if ('rating' == $fieldName) {
            $field = str_replace('glsr-star-rating', '', $field);
        }
        return $field;
    }, 10, 3);

    To change the text of the rating dropdown options, please use the Translations page in the Site Reviews Settings.

    If you would like to add your own CSS class to specific fields, use the filter hook below:

    /**
     * Modifies the CSS classes used for the form fields
     * @param array $classes
     * @param array $field
     * @return array
     */
    add_filter('site-reviews/rendered/field/classes', function ($classes, $fieldValues) {
        $fieldName = glsr_get($fieldValues, 'path');
        $fieldNames = [
            'email',
            'name',
        ];
        if (in_array($fieldName, $fieldNames)) {
            $classes[] = 'column-class'; // add your class here as needed.
        }
        return $classes;
    }, 10, 2);
    Thread Starter pdlbibek

    (@pdlbibek)

    Thanks for the reply.

    I just tried the filter hook to add my own CSS class. It just throws a fatal error.
    atal error: Method GeminiLabs\SiteReviews\Modules\Html\Field::__toString() must not throw an exception, caught Error: Call to undefined function glsr_get() in /home/servgr1allaboutc/public_html/ryp-reviews-custom/wp-content/plugins/site-reviews/plugin/Modules/Html/Partials/SiteReviewsForm.php on line 0

    Also I want to change the way the review count is displayed (the stars) on individual reviews and wanted to show just the number and its corresponding value. eg instead of 2 stars images, I wanted to show the rating number 2 with its label “Average”.

    Plugin Author Gemini Labs

    (@geminilabs)

    1. Please make sure you are using the latest version of Site Reviews (v3.5.4). If you do not wish to do this, you can replace:

    $fieldName = glsr_get($fieldValues, 'path');
    

    With this:

    $fieldName = isset($fieldValues['path'])
        ? $fieldValues['path']
        : '';
    

    2. You can do something like this:

    /**
     * Customise the HTML for the review rating
     * @param array $renderedFields
     * @param GeminiLabs\SiteReviews\Review $review
     * @return array
     */
    add_filter('site-reviews/review/build/after', function ($renderedFields, $review) {
        if (isset($renderedFields['rating'])) {
            $levels = [
                'No Rating', // 0
                'Terrible', // 1
                'Poor', // 2
                'Average', // 3
                'Great', // 4
                'Outstanding', // 5
            ];
            $rating = intval($review->rating);
            $ratingText = sprintf('%d, %s', $review->rating, $levels[$rating]);
            $renderedFields['rating'] = '<div class="glsr-review-rating-text">'. $ratingText.'</div>';
        }
        return $renderedFields;
    }, 10, 2);
    Thread Starter pdlbibek

    (@pdlbibek)

    I am using the latest version of Site Reviews (v3.5.4). Replaced the $fieldName as mentioned and it works.

    Also, the filter to change the review stars to review count + label works flawlessly. Thanks

    Another Query:
    I have created a few custom fields via `add_filter( ‘site-reviews/config/forms/submission-form’, function( $config ) {}’. Now, how can I display them in the backend reviews list?

    Plugin Author Gemini Labs

    (@geminilabs)

    Thread Starter pdlbibek

    (@pdlbibek)

    Thanks, It worked. Now, I want to hide certain fields on certain pages but currently can’t. how can we hide those custom fields from the shortcode using hide=””?

    Plugin Author Gemini Labs

    (@geminilabs)

    This is currently not possible with custom fields.

    However, in v4.0 you will be able to do something like this:

    /**
     * Adds a shortcode/block option to hide a custom field.
     *
     * @param array $options
     * @param string $shortcode
     * @return array
     */
    add_filter('site-reviews/shortcode/hide-options', function ($options, $shortcode) {
        if (in_array($shortcode, ['site_reviews', 'site_reviews_form'])) {
            $options['name_of_your_custom_key'] = __('Hide the custom key');
        }
        return $options;
    }, 10, 2);
    /**
     * Renders the custom review fields.
     * In order to display the rendered custom fields, you will need to use a custom "review.php" 
     * template as shown in the plugin FAQ ("How do I change the order of the review fields?")
     * and you will need to add your custom keys to it, for example: {{ name_of_your_custom_key }}
     *
     * @param array $fields
     * @param \GeminiLabs\SiteReviews\Review $review
     * @param \GeminiLabs\SiteReviews\Modules\Html\Partials\SiteReviews $partial
     * @return array
     */
    add_filter('site-reviews/review/wrap', function ($fields, $review, $partial) {
        foreach ($review->custom as $key => $value) {
            if ($partial->isHidden($key) || array_key_exists($key, $fields)) {
                continue;
            }
            $fields[$key] = '<p>'.$value.'</p>';
        }
        return $fields;
    }, 10, 3);
    Plugin Author Gemini Labs

    (@geminilabs)

    As there has been no reply in over a week, I will mark this topic as resolved.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Modify form field type=’rating’ & rearrange form fields into various column’ is closed to new replies.