• Resolved digitali17

    (@digitali17)


    Hi

    I’m trying to modify the plugin so you can add comments to a review direct from the page (instead of the admin panel).

    I have added a comment section in the file templates/review.php. Now I need to get the review ID so I can link a comment to the review, when the user submit.

    How can I get the ID?

    • This topic was modified 4 years, 9 months ago by digitali17.
    • This topic was modified 4 years, 9 months ago by digitali17.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Are you talking about WordPress comments, or the review response that you can add to a review when editing it in the admin?

    You can get the Post ID of the review in the template like this:

    $postId = $review->ID;
    
    // OR with an extra check to make sure the $review object exists
    
    $postId = isset($review)
        ? $review->ID
        : 0;
    
    // OR using the glsr_get() helper function (using the safe apply_filters method)
    // Arguments are explained like this:
    //   1. function name
    //   2. arg1 = value to use if the plugin is not installed
    //   3. arg2 = object/array to search
    //   4. arg3 = object/array key to get the value from
    //   5. arg4 = value to return if the object/array key does not exist
    
    $postId = apply_filters('glsr_get', 0, $review, 'ID', 0);
    
    Thread Starter digitali17

    (@digitali17)

    Thank you very much ??

    I have one more question…
    I made this code. When an admin is logged in, there will be an input box to response to a review. How can I save the response into the database, when the form is submitted?

    	<?php
    	$current_user = wp_get_current_user();
    	if (user_can( $current_user, 'administrator' )) { ?>
    
    	<form autocomplete="off" action="/post-comment.php" method="post"> 
    		<div> 
    			<input type="hidden" id="reviewid" name="reviewid" value=<?= $postId = $review->ID; ?> readonly> 
    			<input type="text" id="comment" name="comment" placeholder="Indtast dit svar til overst?ende review"> 
    		</div> 
    		<input type="submit" value="Indsend"> 
    	</form> 
    	<?php } ?>
    
    • This reply was modified 4 years, 9 months ago by digitali17.
    Plugin Author Gemini Labs

    (@geminilabs)

    The response is saved as post meta of the review (using the _response meta_key).

    For example, this is what Site Reviews does:

    
    $allowedHtml = [
        'a' => [
            'href' => [],
            'title' => [],
        ],
        'em' => [],
        'strong' => [],
    ];
    $response = trim(wp_kses($responseText, $allowedHtml));
    update_post_meta($postId, '_response', $response);
    
    Thread Starter digitali17

    (@digitali17)

    How can I implement that in my example?

    Plugin Author Gemini Labs

    (@geminilabs)

    Use that in whichever function you use to handle your form submission. Since you are submitting your form to /post-comment.php, that’s probably where you would use it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Comments from UI’ is closed to new replies.