11<?php
22
3- declare ( strict_types=1 );
3+ declare (strict_types=1 );
44
55namespace HWP \Previews \Integration ;
66
@@ -16,6 +16,11 @@ class Faust_Integration {
1616 */
1717 public const FAUST_NOTICE_KEY = 'hwp_previews_faust_notice ' ;
1818
19+ /**
20+ * Whether Faust is enabled.
21+ */
22+ public bool $ faust_enabled = false ;
23+
1924 /**
2025 * The instance of the Faust integration.
2126 *
@@ -24,11 +29,10 @@ class Faust_Integration {
2429 protected static ?Faust_Integration $ instance = null ;
2530
2631 /**
27- * Whether Faust is enabled.
32+ * Faust_Integration constructor.
33+ *
34+ * Initializes the Faust integration if Faust is enabled.
2835 */
29- public bool $ faust_enabled = false ;
30-
31-
3236 public function __construct () {
3337 $ this ->faust_enabled = $ this ->is_faust_enabled ();
3438
@@ -39,6 +43,17 @@ public function __construct() {
3943 $ this ->configure_faust ();
4044 }
4145
46+ /**
47+ * Initialize the hooks for the preview functionality.
48+ */
49+ public static function init (): Faust_Integration {
50+ if ( ! isset ( self ::$ instance ) || ! ( is_a ( self ::$ instance , self ::class ) ) ) {
51+ self ::$ instance = new self ();
52+ }
53+
54+ return self ::$ instance ;
55+ }
56+
4257 /**
4358 * Checks if Faust is enabled.
4459 */
@@ -57,29 +72,6 @@ public function get_faust_enabled(): bool {
5772 return $ this ->faust_enabled ;
5873 }
5974
60- /**
61- * Initialize the hooks for the preview functionality.
62- */
63- public static function init (): Faust_Integration {
64- if ( ! isset ( self ::$ instance ) || ! ( is_a ( self ::$ instance , self ::class ) ) ) {
65- self ::$ instance = new self ();
66- }
67-
68- return self ::$ instance ;
69- }
70-
71- /**
72- * Configure Faust settings and remove conflicting filters.
73- */
74- protected function configure_faust (): void {
75- $ this ->set_default_faust_settings ();
76-
77- // Remove FaustWP post preview link filter to avoid conflicts with our custom preview link generation.
78- remove_filter ( 'preview_post_link ' , 'WPE\FaustWP\Replacement\post_preview_link ' , 1000 );
79-
80- $ this ->display_faust_admin_notice ();
81- }
82-
8375 /**
8476 * Returns the Faust frontend URL from settings or a default value.
8577 */
@@ -134,18 +126,11 @@ public function set_default_faust_settings(): void {
134126 update_option ( HWP_PREVIEWS_SETTINGS_KEY , $ default_settings );
135127 }
136128
137- /**
138- * Dismiss the Faust admin notice.
139- */
140- public function dismiss_faust_admin_notice (): void {
141- update_user_meta ( get_current_user_id (), self ::FAUST_NOTICE_KEY , 1 );
142- }
143-
144129 /**
145130 * Register admin notice to inform users about Faust integration.
146131 */
147132 public function register_faust_admin_notice (): void {
148- add_action ( 'admin_notices ' , function (): void {
133+ add_action ( 'admin_notices ' , static function (): void {
149134 $ screen = get_current_screen ();
150135
151136 // Exit if not this plugin's settings page.
@@ -181,6 +166,25 @@ public function register_faust_admin_notice(): void {
181166 }, 10 , 0 );
182167 }
183168
169+ /**
170+ * Dismiss the Faust admin notice.
171+ */
172+ public static function dismiss_faust_admin_notice (): void {
173+ update_user_meta ( get_current_user_id (), self ::FAUST_NOTICE_KEY , 1 );
174+ }
175+
176+ /**
177+ * Configure Faust settings and remove conflicting filters.
178+ */
179+ protected function configure_faust (): void {
180+ $ this ->set_default_faust_settings ();
181+
182+ // Remove FaustWP post preview link filter to avoid conflicts with our custom preview link generation.
183+ remove_filter ( 'preview_post_link ' , 'WPE\FaustWP\Replacement\post_preview_link ' , 1000 );
184+
185+ $ this ->display_faust_admin_notice ();
186+ }
187+
184188 /**
185189 * If Faust is enabled, show an admin notice about the migration on the settings page.
186190 */
@@ -195,7 +199,7 @@ protected function display_faust_admin_notice(): void {
195199 self ::register_faust_admin_notice ();
196200
197201 // Register the AJAX action for dismissing the notice.
198- add_action ( 'wp_ajax_ ' . self ::FAUST_NOTICE_KEY , function (): void {
202+ add_action ( 'wp_ajax_ ' . self ::FAUST_NOTICE_KEY , static function (): void {
199203 // Exit if the action is not set or does not match the expected key.
200204 if ( ! isset ( $ _POST ['action ' ] ) || esc_attr ( self ::FAUST_NOTICE_KEY ) !== $ _POST ['action ' ] ) {
201205 return ;
0 commit comments