HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-rss-aggregator/v4/src/Util/NormalizeWpPostCapableTrait.php
<?php

namespace RebelCode\Wpra\Core\Util;

use OutOfRangeException;
use WP_Post;

/**
 * Functionality for normalizing a variable into a {@link WP_Post} instance.
 *
 * @since 4.13
 */
trait NormalizeWpPostCapableTrait
{
    /**
     * Normalizes the argument into a {@link WP_Post} instance.
     *
     * @since 4.13
     *
     * @param int|string|WP_Post $postOrId The WordPress post instance or post ID.
     *
     * @return array|WP_Post|null
     *
     * @throws OutOfRangeException If the argument is an ID and no post with the given ID was found.
     */
    protected function normalizeWpPost($postOrId)
    {
        $post = ($postOrId instanceof WP_Post) ? $postOrId : get_post($postOrId);

        if (!($post instanceof WP_Post)) {
            throw new OutOfRangeException(
                sprintf(__('Post with ID %s does not exist', 'wprss'), $post)
            );
        }

        return $post;
    }
}