PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.89
WindPress – Tailwind CSS integration for WordPress v3.2.89
3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 143 releases
windpress / src / Core / Scanner / SourceRevision.php

SourceRevision.php in WindPress – Tailwind CSS integration for WordPress 3.2.89, at src/Core/Scanner/SourceRevision.php

65 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WindPress\WindPress\Core\Scanner;
5
6 use RuntimeException;
7 /**
8 * Detect WordPress content mutations while a browser builds its CSS.
9 */
10 class SourceRevision
11 {
12 private const OPTION = 'windpress_source_revision';
13 public static function register_hooks(): void
14 {
15 foreach (['save_post', 'deleted_post', 'created_term', 'edited_term', 'delete_term', 'set_object_terms', 'deleted_term_relationships', 'added_term_meta', 'updated_term_meta', 'deleted_term_meta', 'profile_update', 'deleted_user', 'added_user_meta', 'updated_user_meta', 'deleted_user_meta', 'switch_theme', 'activated_plugin', 'deactivated_plugin', 'upgrader_process_complete'] as $hook) {
16 add_action($hook, [self::class, 'invalidate'], 10, 0);
17 }
18 foreach (['added_post_meta', 'updated_post_meta', 'deleted_post_meta'] as $hook) {
19 add_action($hook, [self::class, 'invalidate_post_meta'], 10, 3);
20 }
21 foreach (['added_option', 'updated_option', 'deleted_option'] as $hook) {
22 add_action($hook, [self::class, 'invalidate_option']);
23 }
24 }
25 public static function get(): string
26 {
27 wp_cache_delete(self::OPTION, 'options');
28 $revision = get_option(self::OPTION, \false);
29 if (!is_string($revision) || $revision === '') {
30 add_option(self::OPTION, wp_generate_uuid4(), '', \false);
31 wp_cache_delete(self::OPTION, 'options');
32 $revision = get_option(self::OPTION, \false);
33 if (!is_string($revision) || $revision === '') {
34 throw new RuntimeException(__('Unable to initialize the source revision.', 'windpress'));
35 }
36 }
37 return $revision;
38 }
39 public static function matches(string $revision): bool
40 {
41 return hash_equals(self::get(), $revision);
42 }
43 public static function invalidate(): void
44 {
45 update_option(self::OPTION, wp_generate_uuid4(), \false);
46 }
47 public static function invalidate_post_meta($meta_id, int $post_id, string $meta_key): void
48 {
49 // Editor heartbeat refreshes this lock while source content stays unchanged.
50 if ($meta_key !== '_edit_lock' && apply_filters('f!windpress/core/scanner/source_revision:track_post_meta', \true, $meta_key, $post_id)) {
51 self::invalidate();
52 }
53 }
54 public static function invalidate_option(string $option): void
55 {
56 // Scan checkpoints and routine runtime caches must not invalidate their own build.
57 if ($option === self::OPTION || strpos($option, 'windpress_scan_') === 0 || strpos($option, '_transient_') === 0 || strpos($option, '_site_transient_') === 0 || in_array($option, ['cron', 'rewrite_rules', 'recently_activated', 'auto_updater.lock', 'core_updater.lock'], \true)) {
58 return;
59 }
60 if (apply_filters('f!windpress/core/scanner/source_revision:track_option', \true, $option)) {
61 self::invalidate();
62 }
63 }
64 }
65