# portfolio-block/trunk/includes/rootPlugin/ShortCode.php

Portfolio Block – show off your work with stunning layouts, version trunk. 54 lines.

- Page: https://pluginprobe.com/plugins/portfolio-block/trunk/code/includes/rootPlugin/ShortCode.php
- Raw: https://pluginprobe.com/plugins/portfolio-block/trunk/raw/includes/rootPlugin/ShortCode.php
- Modified: 2026-06-30T05:11:00+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/portfolio-block/trunk/code/includes/rootPlugin/ShortCode.php#L10-L20`.

```php
<?php
namespace PFB;

class Shortcode
{
	function __construct()
	{
		add_shortcode('pfb', [$this, 'onAddShortcode']);
	}

	function onAddShortcode($atts)
	{
		$post_id = $atts['id'];
		$post = get_post($post_id);

		if (!$post) {
			return '';
		}

		if (post_password_required($post)) {
			return get_the_password_form($post);
		}

		switch ($post->post_status) {
			case 'publish':
				return $this->displayContent($post);

			case 'private':
				if (current_user_can('read_private_posts')) {
					return $this->displayContent($post);
				}
				return '';

			case 'draft':
			case 'pending':
			case 'future':
				if (current_user_can('edit_post', $post_id)) {
					return $this->displayContent($post);
				}
				return '';

			default:
				return '';
		}
	}

	function displayContent($post)
	{
		$blocks = parse_blocks($post->post_content);
		return render_block($blocks[0]);

	}

}
```
