• Resolved ekaboom

    (@ekaboom)


    Did this plugin change the way it creates a reviews via functions earlier in the year?

    I was grabbing data from another source and adding it to the reviews but that doesn’t seem to work anymore. Here was my code:

    // Add Reviews for Site Reviews wordpress Plugin
    				
    foreach($result->reviews as $data) {
    	$review = apply_filters('glsr_create_review', false, [
    		'assign_to' => $post_id,
    		'content' => $data->text,
    		'date' => date("Y-m-d", $data->time),
    		'name' => $data->author_name,
    		'rating' => $data->rating,
    		'title' => $data->author_name.' '.$data->name,
    	]);
    }
    print_r(json_decode($post_id));

    This worked earlier this year. I can’t remember what the previous documentation said so after looking at the current documentation, I tried changing the code to this:

    		'assigned_posts' => $post_id,
    

    and this:

    		'assigned_posts' => $post->ID,
    

    But neither of those seemed to work. Was ‘assign_to’ used previously or is my issue somewhere else?

    • This topic was modified 4 years ago by ekaboom.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    1. Are you using the latest version?
    2. Please verify the created review using the glsr_log or glsr_debug function. i.e. glsr_debug($review); or glsr_log($review);
    3. You can also verify the $data in the same way.

    Thread Starter ekaboom

    (@ekaboom)

    I am using the latest version.

    Does glsr_log($review); create a log file? If so, where does the log file appear?

    I tried adding glsr_debug($review); but didn’t see any debug notifications.

    • This reply was modified 4 years ago by ekaboom.
    Plugin Author Gemini Labs

    (@geminilabs)

    Please see the Help > Functions page which explains about those functions.

    Thread Starter ekaboom

    (@ekaboom)

    Cool thanks. Found it.

    I tried all three of these and none of them are actually creating a review.
    'assigned_posts' => $post->ID,
    'assigned_posts' => $post_id,
    'assign_to' => $post_id,

    In the log, the $data is being pulled on the line I added the code:

    it shows this: stdClass Object and then the content it’s pulling [author_name] [rating][time] [text] followed by the data related to each of these.

    The $review debug log just shows that a debug happened and doesn’t show any warnings or notices.

    Plugin Author Gemini Labs

    (@geminilabs)

    The glsr_create_review will not throw an error but will fail quietly and return false if there is an error.

    You will also need to make sure the values you are providing are not empty, as otherwise they will fail the “required” validation set in your Site Reviews > Settings > Submissions required value options.

    1. These both work if $post_id is a valid post ID

    'assign_to' => $post_id,
    'assigned_posts' => $post_id,
    

    2. This works if $data->text is not empty

    'content' => $data->text,
    

    3. This works if $data->author_name is not empty

    'name' => $data->author_name,
    

    4. This works if $data->rating is not empty and is between 0 and 5

    'rating' => $data->rating,
    

    5. This will not work because $data->name doesn’t exist (according to your last reply)

    'title' => $data->author_name.' '.$data->name,
    

    A simple way to make sure the values are not empty is to filter out empty values before creating the review. For example:

    $values = [
        'assign_to' => $post_id,
        'content' => $data->text,
        'date' => date("Y-m-d", $data->time),
        'name' => $data->author_name,
        'rating' => $data->rating,
        'title' => $data->author_name,
    ];
    $values = array_filter($values);
    $review = apply_filters('glsr_create_review', false, $values);
    

    You can also debug the result like this:

    $review = apply_filters('glsr_create_review', false, $values);
    if (false === $review) {
        glsr_debug('review values were invalid', '$values);
    }

    Or, by using the glsr_log function like this:

    $review = apply_filters('glsr_create_review', false, $values);
    if (false === $review) {
        glsr_log('review values were invalid')->debug('$values);
    }
    • This reply was modified 4 years ago by Gemini Labs.
    • This reply was modified 4 years ago by Gemini Labs.
    • This reply was modified 4 years ago by Gemini Labs.
    • This reply was modified 4 years ago by t-p.
    Thread Starter ekaboom

    (@ekaboom)

    I’m still working on getting this figured out.

    Questions.

    1. Do the required fields make the glsr_create_review fail if one of those required fields isn’t in the data? If so, how do you set the “Terms” to a default?
    2. Also, does limiting reviews by email address make the glsr_create_review fail if the function uses the same email?
    3. Previously in my plugin that added the reviews to your plugin, the email would default to the website admin email, but I don’t see that in my plugin’s code to add an email. It just added the default email of the site. Is it possible that it’s not working because now in your plugin you require the email added to the code and it now won’t default to any email? Is there a way to just tell the function to grab the site admin email or will that cause an issue?

    If this is the case with any of these questions, is there a way to have the settings under “Site Reviews > Settings > Submissions required value options” set to required and have the reviews limited by email set to true, but not have those two things be required for reviews added via a function?

    Plugin Author Gemini Labs

    (@geminilabs)

    1. The field will only be required in the glsr_create_review function if (a) it is required in the settings, and (b) if the field is passed to the function. If you are not passing a terms field to the function, then you don’t have to worry about it.

    Again, if you don’t want validation performed on fields with an empty value, make sure to remove empty value keys from the argument array before passing it into the function (as demonstrated above).

    2. No. The glsr_create_review function only performs basic field validation.

    3. Site Reviews v4 would fallback to the display name and email of the currently logged in user if no email or name were provided. This fallback was accidentally removed in version 5, but it will be added back in v5.2.0

    Plugin Author Gemini Labs

    (@geminilabs)

    v5.2.0 will also log glsr_create_review validation errors to the plugin console.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Did the Updated Earlier This Year Change How Reviews Functions Are Created?’ is closed to new replies.