Function Reference: geodir_save_rating

Summary

Save rating details for a comment.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$plugin_prefix
(string) (required) Geodirectory plugin table prefix.

Default: None
$user_ID
(int) (required) The current user ID.

Default: None

Package

GeoDirectory

Parameters

$comment
(int) (required) The comment ID.

Default: None

Change Log

Since: 1.0.0

Actions

‘geodir_after_save_comment’ [Line: 245]

Source File

geodir_save_rating() is located in geodirectory-functions/comments_functions.php [Line: 178]

Source Code

function geodir_save_rating($comment = 0)
{
    global $wpdb, $user_ID, $plugin_prefix;

    $comment_info = get_comment($comment);

    $post_id = $comment_info->comment_post_ID;
    $status = $comment_info->comment_approved;
    $rating_ip = getenv("REMOTE_ADDR");
	
    $post = geodir_get_post_info($post_id);
    if (empty($post)) {
        return;
    }

    if ($post->post_status == 'publish') {
        $post_status = '1';
    } else {
        $post_status = '0';
    }
	
    if (isset($_REQUEST['geodir_overallrating'])) {
        $overall_rating = $_REQUEST['geodir_overallrating'];
        
		if (isset($comment_info->comment_parent) && (int)$comment_info->comment_parent == 0) {
            $overall_rating = $overall_rating > 0 ? $overall_rating : '0';

            $sqlqry = $wpdb->prepare("INSERT INTO " . GEODIR_REVIEW_TABLE . " SET
					post_id		= %d,
					post_type = %s,
					post_title	= %s,
					user_id		= %d,
					comment_id	= %d,
					rating_ip	= %s,
					overall_rating = %f,
					status		= %s,
					post_status		= %s, 
					post_date		= %s, 
					post_city		= %s, 
					post_region		= %s, 
					post_country	= %s,
					post_longitude	= %s,
					post_latitude	= %s,
					comment_content	= %s 
					",
                array($post_id, $post->post_type, $post->post_title, $user_ID, $comment, $rating_ip, $overall_rating, $status, $post_status, date_i18n('Y-m-d H:i:s', current_time('timestamp')), $post->post_city, $post->post_region, $post->post_country, $post->post_latitude, $post->post_longitude, $comment_info->comment_content)
            );

            $wpdb->query($sqlqry);

            /**
             * Called after saving the comment.
             *
             * @since 1.0.0
             * @package GeoDirectory
             * @param array $_REQUEST {
             *    Attributes of the $_REQUEST variable.
             *
             *    @type string $geodir_overallrating Overall rating.
             *    @type string $comment Comment text.
             *    @type string $submit Submit button text.
             *    @type string $comment_post_ID Comment post ID.
             *    @type string $comment_parent Comment Parent ID.
             *    @type string $_wp_unfiltered_html_comment Unfiltered html comment string.
             *
             * }
             */
            do_action('geodir_after_save_comment', $_REQUEST, 'Comment Your Post');

            if ($status) {
                geodir_update_postrating($post_id);
            }
        }
    }
}