1919 * @package HWP\Previews
2020 */
2121
22- declare ( strict_types=1 );
22+ declare (strict_types=1 );
2323
24+ use HWP \Previews \Autoloader ;
2425use HWP \Previews \Plugin ;
2526
2627if ( ! defined ( 'ABSPATH ' ) ) {
2930
3031// Load the autoloader.
3132require_once __DIR__ . '/src/Autoloader.php ' ;
32- if ( ! \ HWP \ Previews \ Autoloader::autoload () ) {
33+ if ( ! Autoloader::autoload () ) {
3334 return ;
3435}
3536
3637if ( file_exists ( __DIR__ . '/activation.php ' ) ) {
3738 require_once __DIR__ . '/activation.php ' ;
39+ // @phpstan-ignore-next-line
3840 register_activation_hook ( __FILE__ , 'hwp_previews_activation_callback ' );
3941}
4042
4143if ( file_exists ( __DIR__ . '/deactivation.php ' ) ) {
4244 require_once __DIR__ . '/deactivation.php ' ;
45+ // @phpstan-ignore-next-line
4346 register_deactivation_hook ( __FILE__ , 'hwp_previews_deactivation_callback ' );
4447}
4548
4649/**
4750 * Define plugin constants.
4851 */
4952function hwp_previews_constants (): void {
50- // Plugin version.
51- if ( ! defined ( 'HWP_PREVIEWS_VERSION ' ) ) {
52- define ( 'HWP_PREVIEWS_VERSION ' , '0.0.1 ' );
53- }
54-
55- // Plugin Folder Path.
56- if ( ! defined ( 'HWP_PREVIEWS_PLUGIN_DIR ' ) ) {
57- define ( 'HWP_PREVIEWS_PLUGIN_DIR ' , plugin_dir_path ( __FILE__ ) );
58- }
59-
60- // Plugin Folder URL.
61- if ( ! defined ( 'HWP_PREVIEWS_PLUGIN_URL ' ) ) {
62- define ( 'HWP_PREVIEWS_PLUGIN_URL ' , plugin_dir_url ( __FILE__ ) );
63- }
64-
65- // Plugin Root File.
66- if ( ! defined ( 'HWP_PREVIEWS_PLUGIN_FILE ' ) ) {
67- define ( 'HWP_PREVIEWS_PLUGIN_FILE ' , __FILE__ );
68- }
69-
70- // Whether to autoload the files or not.
71- if ( ! defined ( 'HWP_PREVIEWS_AUTOLOAD ' ) ) {
72- define ( 'HWP_PREVIEWS_AUTOLOAD ' , true );
73- }
74-
75- // Text Domain
76- if ( ! defined ( 'HWP_PREVIEWS_TEXT_DOMAIN ' ) ) {
77- define ( 'HWP_PREVIEWS_TEXT_DOMAIN ' , 'hwp-previews ' );
78- }
79-
80- // Plugin config settings group
81- if ( ! defined ( 'HWP_PREVIEWS_SETTINGS_GROUP ' ) ) {
82- define ( 'HWP_PREVIEWS_SETTINGS_GROUP ' , 'hwp_previews_settings_group ' );
83- }
84-
85- // Plugin config settings key.
86- if ( ! defined ( 'HWP_PREVIEWS_SETTINGS_KEY ' ) ) {
87- define ( 'HWP_PREVIEWS_SETTINGS_KEY ' , 'hwp_previews_settings ' );
53+ $ constants = [
54+ 'HWP_PREVIEWS_VERSION ' => '0.0.1 ' ,
55+ 'HWP_PREVIEWS_PLUGIN_DIR ' => plugin_dir_path ( __FILE__ ),
56+ 'HWP_PREVIEWS_PLUGIN_URL ' => plugin_dir_url ( __FILE__ ),
57+ 'HWP_PREVIEWS_PLUGIN_FILE ' => __FILE__ ,
58+ 'HWP_PREVIEWS_AUTOLOAD ' => true ,
59+ 'HWP_PREVIEWS_SETTINGS_GROUP ' => 'hwp_previews_settings_group ' ,
60+ 'HWP_PREVIEWS_SETTINGS_KEY ' => 'hwp_previews_settings ' ,
61+ 'HWP_PREVIEWS_TEXT_DOMAIN ' => 'hwp-previews ' ,
62+ ];
63+
64+ foreach ( $ constants as $ name => $ value ) {
65+ if ( ! defined ( $ name ) ) {
66+ // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
67+ define ( $ name , $ value );
68+ // phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
69+ }
8870 }
8971
9072 // Plugin Template Directory.
@@ -99,7 +81,6 @@ function hwp_previews_constants(): void {
9981function hwp_previews_init (): void {
10082 hwp_previews_constants ();
10183
102-
10384 if ( defined ( 'HWP_PREVIEWS_PLUGIN_DIR ' ) ) {
10485 require_once HWP_PREVIEWS_PLUGIN_DIR . 'src/Plugin.php ' ;
10586 Plugin::instance ();
@@ -110,14 +91,12 @@ function hwp_previews_init(): void {
11091
11192 add_action (
11293 'admin_notices ' ,
113- static function () {
94+ static function (): void {
11495 ?>
11596 <div class="error notice">
11697 <p>
11798 <?php
118- printf (
119- esc_html__ ( 'Composer vendor directory must be present for HWP Previews to work. ' , 'hwp-previews ' ),
120- );
99+ echo 'Composer vendor directory must be present for HWP Previews to work. '
121100 ?>
122101 </p>
123102 </div>
@@ -128,5 +107,14 @@ static function () {
128107 );
129108}
130109
110+ /**
111+ * Load plugin textdomain.
112+ */
113+ function hwp_previews_load_textdomain (): void {
114+ load_plugin_textdomain ( 'hwp-previews ' , false , dirname ( plugin_basename ( __FILE__ ) ) . '/languages ' );
115+ }
116+
117+ add_action ( 'init ' , 'hwp_previews_load_textdomain ' , 1 , 0 );
118+
131119/** @psalm-suppress HookNotFound */
132- add_action ( 'plugins_loaded ' , 'hwp_previews_init ' , 15 );
120+ add_action ( 'plugins_loaded ' , 'hwp_previews_init ' , 15 , 0 );
0 commit comments