# solid-post-likes/trunk/controllers/SolidPostLikesGetter.php

Solid Post Likes, version trunk. 51 lines.

- Page: https://pluginprobe.com/plugins/solid-post-likes/trunk/code/controllers/SolidPostLikesGetter.php
- Raw: https://pluginprobe.com/plugins/solid-post-likes/trunk/raw/controllers/SolidPostLikesGetter.php
- Modified: 2026-07-15T21:25:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/solid-post-likes/trunk/code/controllers/SolidPostLikesGetter.php#L10-L20`.

```php
<?php
namespace OACS\SolidPostLikes\Controllers;

use OACS\SolidPostLikes\Controllers\SolidPostLikesChecker as Checker;
use OACS\SolidPostLikes\Controllers\SolidPostLikesIcon as Icon;
use OACS\SolidPostLikes\Controllers\SolidPostLikesCounter as Counter;
use OACS\SolidPostLikes\Controllers\SolidPostLikesText as Text;
use OACS\SolidPostLikes\Controllers\SolidPostLikesStore as Store;

if ( ! defined( 'WPINC' ) ) { die; }
/** Read-only like info for pages served from a full page cache. */

class SolidPostLikesGetter
{
	function oacs_spl_get_like_info()
	{
		// Read-only endpoint: deliberately no nonce check — pages served from a full page
		// cache carry stale nonces, which is the very reason this endpoint exists.
        // Test if this is a comment
		$is_comment = (isset($_REQUEST['is_comment']) && $_REQUEST['is_comment'] == 1) ? 1 : 0;

		$post_id = (isset($_REQUEST['post_id']) && is_numeric($_REQUEST['post_id'])) ? (int) $_REQUEST['post_id'] : 0;
		if (!$post_id) {
			return;
		}

		$checker           = new Checker;
		$store             = new Store;
		$post_like_icon    = new Icon;
		$post_like_text    = new Text;
		$post_like_counter = new Counter;

		if ($checker->oacs_spl_already_liked($post_id, $is_comment)) {
			$response['status'] = "liked";
			$response['icon']   = $post_like_icon->oacs_spl_get_liked_icon();
			$response['text']   = $post_like_text->oacs_spl_get_unlike_text();
		} else {
			$response['status'] = "unliked";
			$response['icon']   = $post_like_icon->oacs_spl_get_unliked_icon();
			$response['text']   = $post_like_text->oacs_spl_get_like_text();
		}

		// insert a space so the button stays the same.
		$response['count']   = $post_like_counter->oacs_spl_get_like_count($store->display_count($post_id, $is_comment)) . ' ';
		$response['comment'] = $is_comment;
		// Fresh nonce so like clicks keep working on pages served from a stale full page cache.
		$response['nonce'] = wp_create_nonce('oacs_spl_likes_nonce');
		wp_send_json($response);
	}
}

```
