LLMS_Reviews::current_user_can_write_review( int $parent_id )

Check to see if we are allowed to write more than one review.


Description Description

If we are not, check to see if we have written a review already.


Top ↑

Parameters Parameters

$parent_id

(int) (Required) The ID of the parent post.


Top ↑

Return Return

(bool) True if the user can write a review, false if not.


Top ↑

Source Source

File: includes/class.llms.review.php

	public static function current_user_can_write_review( $parent_id ) {
		// Make sure the user is logged in.
		if ( ! is_user_logged_in() ) {
			return false;
		}

		// Make sure we have a post ID to check.
		if ( empty( $parent_id ) ) {
			return false;
		}

		// Check if reviews are disabled.
		if ( ! get_post_meta( $parent_id, '_llms_reviews_enabled', true ) ) {
			return false;
		}

		// Check if reviews are limited and the user has already written a review.
		$args        = array(
			'posts_per_page'   => 1,
			'post_type'        => 'llms_review',
			'post_status'      => 'publish',
			'post_parent'      => $parent_id,
			'author'           => get_current_user_id(),
			'suppress_filters' => true,
		);
		$posts_array = get_posts( $args );
		if ( get_post_meta( $parent_id, '_llms_multiple_reviews_disabled', true ) && $posts_array ) {
			return false;
		}

		// If we got here, we can write a review.
		return true;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.5.2 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.