' . __('Topic SEO Content Optimization Tool', 'usetopic-plugin') . '

'; $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; echo $html; } /** * Function to find the file path for index.[hash].js or index-classic.[hash].js * @param string $filePattern - The file pattern to search for (e.g., 'index' or 'index-classic') * @param string $directory - The directory where the build files are located * @return string|null - Returns the full file path or null if not found */ public function getHashedFilePath($filePattern, $directory = 'build') { // Get the full path to the plugin directory $plugin_dir = plugin_dir_path(__FILE__); $full_directory_path = $plugin_dir . $directory; if (!is_dir($full_directory_path)) { return null; } // Define the regex pattern to match files like index.[hash].js or index-classic.[hash].js $pattern = sprintf('/^%s\.[a-f0-9]{8}\.js$/', preg_quote($filePattern, '/')); // Scan the directory for files $files = scandir($full_directory_path); // Iterate through the files to find a match foreach ($files as $file) { if (preg_match($pattern, $file)) { // Return the relative path of the matched file return $directory . '/' . $file; } } // If no match was found, return null return null; } public function topic_enqueue_assets() { $index_file_path = $this->getHashedFilePath('index'); if ($index_file_path === null) { $index_file_path = 'build/index.js'; } wp_enqueue_script( 'topic-gutenberg-sidebar', plugins_url($index_file_path, __FILE__), array('wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element'), null ); wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all'); } public function topic_enqueue_assets_classic() { $index_file_path = $this->getHashedFilePath('index-classic'); if ($index_file_path === null) { $index_file_path = 'build/index-classic.js'; } wp_enqueue_script( 'topic-gutenberg-sidebar-classic', plugins_url($index_file_path, __FILE__), array('wp-plugins'), null ); wp_enqueue_style('topic-classic-sidebar', plugins_url('classic-editor/classic.css', __FILE__), array(), 'all'); wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all'); } public function useTopicSeo_sidebar_box($data) { echo '
' . __('Topic SEO Content Optimization Tool', 'usetopic-plugin') . '
'; } public function get_permalink_for_post_id() { if (isset($_POST['post_id'])) { $post_id = $_POST['post_id']; $permalink = get_permalink(intval($post_id)); wp_send_json([ 'permalink' => $permalink ]); } wp_die(); } public function search_posts() { if (isset($_POST['s'])) { $s = $_POST['s']; global $wpdb; $myposts = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND post_title LIKE '%s'", '%' . $wpdb->esc_like($s) . '%')); $post_array = array(); foreach ($myposts as $mypost) { // $post = get_post($mypost); $permalink = get_permalink(intval($mypost->ID)); $mypost->permalink = $permalink; $mypost->post_content = ""; array_push($post_array, $mypost); } wp_send_json([ 'posts' => $post_array ]); } wp_die(); } } $wpUseTopic = new useTopicSeo();