| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * Description: Topic helps editors and agencies create content briefs in half the time. |
| 6 | 6 | * Author: Topic |
| 7 | 7 | * License: GPL v2 or later |
| 8 | 8 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 9 | - * Version: 1.0.22 | |
| 9 | + * Version: 1.0.36 | |
| 10 | 10 | */ |
| 11 | 11 | if( ! defined( 'ABSPATH') ) { |
| 12 | 12 | exit; |
| 13 | 13 | } |
| @@ -37,24 +37,66 @@ | ||
| 37 | 37 | $html .= '</div>'; |
| 38 | 38 | echo $html; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | + /** | |
| 42 | + * Function to find the file path for index.[hash].js or index-classic.[hash].js | |
| 43 | + * @param string $filePattern - The file pattern to search for (e.g., 'index' or 'index-classic') | |
| 44 | + * @param string $directory - The directory where the build files are located | |
| 45 | + * @return string|null - Returns the full file path or null if not found | |
| 46 | + */ | |
| 47 | + public function getHashedFilePath($filePattern, $directory = 'build') { | |
| 48 | + // Get the full path to the plugin directory | |
| 49 | + $plugin_dir = plugin_dir_path(__FILE__); | |
| 50 | + $full_directory_path = $plugin_dir . $directory; | |
| 51 | + | |
| 52 | + if (!is_dir($full_directory_path)) { | |
| 53 | + return null; | |
| 54 | + } | |
| 55 | + | |
| 56 | + // Define the regex pattern to match files like index.[hash].js or index-classic.[hash].js | |
| 57 | + $pattern = sprintf('/^%s\.[a-f0-9]{8}\.js$/', preg_quote($filePattern, '/')); | |
| 58 | + | |
| 59 | + // Scan the directory for files | |
| 60 | + $files = scandir($full_directory_path); | |
| 61 | + | |
| 62 | + // Iterate through the files to find a match | |
| 63 | + foreach ($files as $file) { | |
| 64 | + if (preg_match($pattern, $file)) { | |
| 65 | + // Return the relative path of the matched file | |
| 66 | + return $directory . '/' . $file; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + // If no match was found, return null | |
| 71 | + return null; | |
| 72 | + } | |
| 73 | + | |
| 41 | 74 | public function topic_enqueue_assets() { |
| 42 | - wp_enqueue_script( | |
| 43 | - 'topic-gutenberg-sidebar', | |
| 44 | - plugins_url( 'build/index.js', __FILE__ ), | |
| 45 | - array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' ) | |
| 46 | - ); | |
| 47 | - wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), time(), 'all'); | |
| 75 | + $index_file_path = $this->getHashedFilePath('index'); | |
| 76 | + if ($index_file_path === null) { | |
| 77 | + $index_file_path = 'build/index.js'; | |
| 78 | + } | |
| 79 | + wp_enqueue_script( | |
| 80 | + 'topic-gutenberg-sidebar', | |
| 81 | + plugins_url( $index_file_path, __FILE__ ), | |
| 82 | + array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' ), | |
| 83 | + null | |
| 84 | + ); | |
| 85 | + wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), 'all'); | |
| 48 | 86 | } |
| 49 | 87 | |
| 50 | 88 | public function topic_enqueue_assets_classic() { |
| 89 | + $index_file_path = $this->getHashedFilePath('index-classic'); | |
| 90 | + if ($index_file_path === null) { | |
| 91 | + $index_file_path = 'build/index-classic.js'; | |
| 92 | + } | |
| 51 | 93 | wp_enqueue_script( |
| 52 | 94 | 'topic-gutenberg-sidebar-classic', |
| 53 | - plugins_url( 'build/index-classic.js', __FILE__ ), array('wp-plugins'), time(), true | |
| 95 | + plugins_url( $index_file_path , __FILE__ ), array('wp-plugins'), null | |
| 54 | 96 | ); |
| 55 | - wp_enqueue_style('topic-classic-sidebar', plugins_url( 'classic-editor/classic.css', __FILE__ ), array(), time(), 'all'); | |
| 56 | - wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), time(), 'all'); | |
| 97 | + wp_enqueue_style('topic-classic-sidebar', plugins_url( 'classic-editor/classic.css', __FILE__ ), array(), 'all'); | |
| 98 | + wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), 'all'); | |
| 57 | 99 | } |
| 58 | 100 | |
| 59 | 101 | public function useTopicSeo_sidebar_box($data) { |
| 60 | 102 | echo '<div id="usetopicData"><div class="closeTopicdata"><strong>'.__( 'Topic SEO Content Optimization Tool', 'usetopic-plugin' ).'</strong><button type="button" class="close" aria-label="Close plugin"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false"><path d="M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"></path></svg><p class="usetopic-tooltip">Close Plugin</p></button></div><div class="content"></div></div>'; |