|
46 | 46 | register_deactivation_hook( __FILE__, 'hwp_previews_deactivation_callback' ); |
47 | 47 | } |
48 | 48 |
|
49 | | -/** |
50 | | - * Define plugin constants. |
51 | | - * |
52 | | - * phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh |
53 | | - * phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh |
54 | | - */ |
55 | | -function hwp_previews_constants(): void { |
56 | | - if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) { |
57 | | - define( 'HWP_PREVIEWS_VERSION', '0.0.1-beta' ); |
58 | | - } |
59 | 49 |
|
60 | | - if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { |
61 | | - define( 'HWP_PREVIEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
62 | | - } |
63 | | - |
64 | | - if ( ! defined( 'HWP_PREVIEWS_PLUGIN_URL' ) ) { |
65 | | - define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
66 | | - } |
67 | | - |
68 | | - if ( ! defined( 'HWP_PREVIEWS_PLUGIN_FILE' ) ) { |
69 | | - define( 'HWP_PREVIEWS_PLUGIN_FILE', __FILE__ ); |
70 | | - } |
71 | | - |
72 | | - if ( ! defined( 'HWP_PREVIEWS_AUTOLOAD' ) ) { |
73 | | - define( 'HWP_PREVIEWS_AUTOLOAD', true ); |
74 | | - } |
75 | | - |
76 | | - if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) { |
77 | | - define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' ); |
78 | | - } |
| 50 | +// phpcs:enable Generic.Metrics.CyclomaticComplexity.TooHigh |
| 51 | +// phpcs:enable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh |
79 | 52 |
|
80 | | - if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) { |
81 | | - define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' ); |
| 53 | +if ( ! function_exists( 'hwp_previews_init' ) ) { |
| 54 | + /** |
| 55 | + * Initializes plugin. |
| 56 | + */ |
| 57 | + function hwp_previews_init(): void { |
| 58 | + hwp_previews_constants(); |
| 59 | + hwp_previews_plugin_init(); |
| 60 | + hwp_previews_plugin_admin_notice(); |
82 | 61 | } |
| 62 | +} |
83 | 63 |
|
84 | | - if ( ! defined( 'HWP_PREVIEWS_TEXT_DOMAIN' ) ) { |
85 | | - define( 'HWP_PREVIEWS_TEXT_DOMAIN', 'hwp-previews' ); |
| 64 | +if ( ! function_exists( 'hwp_previews_constants' ) ) { |
| 65 | + /** |
| 66 | + * Define plugin constants. |
| 67 | + * |
| 68 | + * phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh |
| 69 | + * phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh |
| 70 | + */ |
| 71 | + function hwp_previews_constants(): void { |
| 72 | + if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) { |
| 73 | + define( 'HWP_PREVIEWS_VERSION', '0.0.1-beta' ); |
| 74 | + } |
| 75 | + |
| 76 | + if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { |
| 77 | + define( 'HWP_PREVIEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 78 | + } |
| 79 | + |
| 80 | + if ( ! defined( 'HWP_PREVIEWS_PLUGIN_URL' ) ) { |
| 81 | + define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 82 | + } |
| 83 | + |
| 84 | + if ( ! defined( 'HWP_PREVIEWS_PLUGIN_FILE' ) ) { |
| 85 | + define( 'HWP_PREVIEWS_PLUGIN_FILE', __FILE__ ); |
| 86 | + } |
| 87 | + |
| 88 | + if ( ! defined( 'HWP_PREVIEWS_AUTOLOAD' ) ) { |
| 89 | + define( 'HWP_PREVIEWS_AUTOLOAD', true ); |
| 90 | + } |
| 91 | + |
| 92 | + if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) { |
| 93 | + define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' ); |
| 94 | + } |
| 95 | + |
| 96 | + if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) { |
| 97 | + define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' ); |
| 98 | + } |
| 99 | + |
| 100 | + if ( ! defined( 'HWP_PREVIEWS_TEXT_DOMAIN' ) ) { |
| 101 | + define( 'HWP_PREVIEWS_TEXT_DOMAIN', 'hwp-previews' ); |
| 102 | + } |
86 | 103 | } |
87 | 104 | } |
88 | 105 |
|
89 | | -// phpcs:enable Generic.Metrics.CyclomaticComplexity.TooHigh |
90 | | -// phpcs:enable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh |
91 | | - |
92 | | -/** |
93 | | - * Initializes plugin. |
94 | | - */ |
95 | | -function hwp_previews_init(): void { |
96 | | - hwp_previews_constants(); |
97 | | - |
98 | | - if ( defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { |
| 106 | +if ( ! function_exists( 'hwp_previews_plugin_init' ) ) { |
| 107 | + /** |
| 108 | + * Initialize the HWP Previews plugin. |
| 109 | + */ |
| 110 | + function hwp_previews_plugin_init(): ?Plugin { |
| 111 | + if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { |
| 112 | + return null; |
| 113 | + } |
99 | 114 | require_once HWP_PREVIEWS_PLUGIN_DIR . 'src/Plugin.php'; |
100 | | - Plugin::instance(); |
101 | | - |
102 | | - return; |
| 115 | + return Plugin::instance(); |
103 | 116 | } |
| 117 | +} |
104 | 118 |
|
105 | 119 |
|
106 | | - add_action( |
107 | | - 'admin_notices', |
108 | | - static function (): void { |
109 | | - ?> |
110 | | - <div class="error notice"> |
111 | | - <p> |
112 | | - <?php |
113 | | - echo 'Composer vendor directory must be present for HWP Previews to work.' |
114 | | - ?> |
115 | | - </p> |
116 | | - </div> |
117 | | - <?php |
118 | | - }, |
119 | | - 10, |
120 | | - 0 |
121 | | - ); |
| 120 | +if ( ! function_exists( 'hwp_previews_plugin_admin_notice' ) ) { |
| 121 | + /** |
| 122 | + * Display an admin notice if the plugin is not properly initialized. |
| 123 | + */ |
| 124 | + function hwp_previews_plugin_admin_notice(): void { |
| 125 | + if ( defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) { |
| 126 | + return; |
| 127 | + } |
| 128 | + |
| 129 | + add_action( |
| 130 | + 'admin_notices', |
| 131 | + static function (): void { |
| 132 | + ?> |
| 133 | + <div class="error notice"> |
| 134 | + <p> |
| 135 | + <?php |
| 136 | + echo 'Composer vendor directory must be present for HWP Previews to work.' |
| 137 | + ?> |
| 138 | + </p> |
| 139 | + </div> |
| 140 | + <?php |
| 141 | + }, |
| 142 | + 10, |
| 143 | + 0 |
| 144 | + ); |
| 145 | + } |
122 | 146 | } |
123 | 147 |
|
124 | 148 | /** |
|
0 commit comments