# wp-coder/4.5.1/classes/Publisher/ShortcodeFinder.php

WP Coder – Insert &amp; Manage Code Snippets, version 4.5.1. 37 lines.

- Page: https://pluginprobe.com/plugins/wp-coder/4.5.1/code/classes/Publisher/ShortcodeFinder.php
- Raw: https://pluginprobe.com/plugins/wp-coder/4.5.1/raw/classes/Publisher/ShortcodeFinder.php
- Modified: 2026-07-09T05:31:08+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/wp-coder/4.5.1/code/classes/Publisher/ShortcodeFinder.php#L10-L20`.

```php
<?php

namespace WPCoder\Publisher;

class ShortcodeFinder {

	private $shortcode_name;

	public function __construct($shortcode_name) {
		$this->shortcode_name = $shortcode_name;
	}

	public function getShortcodeId($post_id) {
		$post = get_post($post_id);

		if (!$post) {
			return false; // Return false if the post does not exist
		}

		// Use regex to find the shortcode
		$pattern = get_shortcode_regex([ $this->shortcode_name ]);
		if (preg_match('/' . $pattern . '/s', $post->post_content, $matches) && isset($matches[3])) {
			// Extract attributes string
			$attributes_string = $matches[3];

			// Parse attributes
			$attributes = shortcode_parse_atts($attributes_string);

			if (isset($attributes['id'])) {
				return $attributes['id']; // Return the ID attribute of the shortcode
			}
		}

		return false; // Return false if no matching shortcode found
	}
}

```
