| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/excellentvege/wp-content/plugins/wp-coder/classes/Publisher/ |
Upload File : |
<?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
}
}