HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/lib/review/review.php
<?php

/*//////////////////////////////////////
// Manage review meta
//////////////////////////////////////*/

add_action( 'init', 'gtm_register_review_meta_fields' );
function gtm_register_review_meta_fields() {
	register_post_meta( 'post', 'gtm_review_score', [
		'show_in_rest'  => true,
		'single'        => true,
		'type'          => 'number',
		'auth_callback' => function () {
			return current_user_can( 'edit_posts' );
		},
	] );
}

add_action( 'save_post', 'gtm_update_review_meta', 10, 2 );
function gtm_update_review_meta( $post_id, $post = '' ) {
	if ( empty( $post_id ) ) {
		return;
	}

	// Autosave, do nothing
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
		return;
	}

	// AJAX? Not used here
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
		return;
	}

	// Check user permissions
	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return;
	}

	// Return if it's a post revision
	if ( false !== wp_is_post_revision( $post_id ) ) {
		return;
	}

	if ( ! empty( $post ) ) {
		$post = get_post( $post_id );
	}

	if ( has_blocks( $post ) && preg_match_all( '|<!-- wp:gtm/review .*|i', $post->post_content, $blocks ) ) {
		// Do nothing

	} else {
		delete_post_meta( $post_id, 'gtm_review_score' );
	}
}

/*//////////////////////////////////////
// Template tags
//////////////////////////////////////*/

function gtm_has_review( $post_id = null ) {
	$post_id      = $post_id ?? get_the_ID();
	$review_score = get_post_meta( $post_id, 'gtm_review_score', true );

	return is_numeric( $review_score );
}

function gtm_get_review_star_number( $post_id = null ) {
	$post_id      = $post_id ?? get_the_ID();
	$review_score = floatval( get_post_meta( $post_id, 'gtm_review_score', true ) );

	return number_format_i18n( $review_score / 20, 1 );
}