<?php
/**
 * OrokuBlocks - Blog Functions
 * 
 * @package OrokuBlocks
 * @author OrokuBlocks (https://orokublocks.com/)
 * 
 * @since 1.0.0
 * 
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

if ( ! class_exists( 'OrokuBlocks_Blog' ) ) {
  final class OrokuBlocks_Blog {
    /**
     * Prevent more than one instance from being created
     * 
     * @since 1.0.0
     * 
     * @access private
     */
    private function __construct() {}

    /**
     * Prevent cloning
     * 
     * @since 1.0.0
     * 
     * @access private
     */
    private function __clone() {}

    /**
     * Returns thumbnail url.
     * 
     * @since 1.0.0
     * 
     * @param int     $thumbnail_post_id      Id of the thumbnail post to get the url from.
     * @return string $thumbnail_url          Post thumbnail url.
     */
    public static function thumbnailUrlGet( $thumbnail_post_id ) {
      $thumbnail_url = '';

      $thumbnail_post = get_post( $thumbnail_post_id );
      
      if ( $thumbnail_post instanceof WP_Post ) {
        $thumbnail_url = $thumbnail_post->guid;
      }

      return $thumbnail_url;
    }

    /**
     * Returns post thumbnail url.
     * 
     * @since 1.0.0
     * 
     * @param int     $post_id            Id of the post to get the thumbnail of.
     * @return string $thumbnail_url      Post thumbnail url.
     */
    public static function postThumbnailUrlGet( $post_id ) {
      $thumbnail_url = '';

      $thumbnail_post_id = get_post_thumbnail_id( $post_id );

      // if thumbnail exists
      if ( $thumbnail_post_id !== 0 ) {
        $thumbnail_url = self::thumbnailUrlGet( $thumbnail_post_id );
      }

      return $thumbnail_url;
    }
  }
}