• Resolved Demian

    (@demian85)


    Hi,

    First off, I am a little surprised how this plugin is written. It seems that the writer is coming from a Magento environment, it’s not how WP plugins are being written, it’s therefore difficult to find what I am looking for. Hopefully the plugin won’t be suspended for this. Be aware!

    I am looking to find a way to replace the display_name for the name field. Where can I find a filter hook for this?

    With thanks,
    Demian

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

    (@geminilabs)

    Hi @demian85

    1. Actually I come from a Laravel/Symfony background and much of the architecture is inspired from that (i.e. Model-View-Controller, Routing, Inversion of Control, etc.). It also uses namespacing, and adheres to PSR-2. It also scores 9.22/10 on scrutinizer-ci for code quality.

    WordPress was initially written before PHP v5 was released (and therefore the code base is stuck using old coding standards to maintain compatibility), but that doesn’t mean plugin authors are limited to using the outdated non-standard method of coding that is still used by WordPress.

    Also, before a plugin is initially accepted in the WordPress plugin repository, it is reviewed by the WordPress team. So I’m not sure what you intended when you cautioned people to be aware.

    If you like, you can also review the code on github. It has always been open source for anyone to review. You can even find the v2 code there (which was not much different from v1): https://github.com/pryley/site-reviews/tree/v2.17.1

    Do you have any specific concerns about the way the code is written that I can address here for you and anyone else reading this?

    2. If you are hiding the name field from the form and the user submitting the review is logged in, Site Reviews will use the Display Name of the logged in user. It does this because the Display Name option in the WordPress User Profile settings is there to allow the user to decide how they want their name to appear publicly on the website.

    If you would prefer to override this user preference, then you can use the site-reviews/create/review-values hook to override the name before it is saved to the review.

    You can also find a full list of plugin hooks here: https://github.com/pryley/site-reviews/blob/main/HOOKS.md

    Thread Starter Demian

    (@demian85)

    Hi,

    Thanks for the quick reply. I am looking for the site-reviews/create/review-values hook. What is the exact hook for the name field?

    With thanks,
    Demian

    Plugin Author Gemini Labs

    (@geminilabs)

    Here is an example:

    /**
     * @param array $values
     * @return array
     */
    add_filter('site-reviews/create/review-values', function ($values) {
        if (!is_user_logged_in()) {
            return $values;
        }
        $user = wp_get_current_user();
        $name = trim(sprintf('%s %s', $user->user_firstname, $user->user_lastname));
        if (!empty($name)) {
            $values['name'] = $name;
        }
        return $values;
    });

    You can also use the glsr_log function to log the review values to the Site Reviews Console (found on the Site Reviews > Tools page; though you may need to change the Logging level to DEBUG). This will help you figure out which values you can override. For example:

    /**
     * @param array $values
     * @return array
     */
    add_filter('site-reviews/create/review-values', function ($values) {
        glsr_log($values);
        return $values;
    });
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change display name’ is closed to new replies.