Skip to content

Commit ea70bdd

Browse files
committed
fix: prevent early text domain loading in plugin triggering notice
1 parent 3b17059 commit ea70bdd

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

plugins/wp-graphql-headless-webhooks/access-functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
function register_webhook_type( string $type, array $args = [] ): void {
3434
/** @psalm-suppress HookNotFound */
3535
if ( did_action( 'graphql_register_webhooks' ) > 0 ) {
36-
_doing_it_wrong( 'register_webhook_type', __( 'Call this before WebhookRegistry::init', 'wp-graphql-headless-webhooks' ), '0.1.0' );
36+
_doing_it_wrong( 'register_webhook_type', 'Call this before WebhookRegistry::init', '0.1.0' );
3737

3838
return;
3939
}
@@ -137,7 +137,7 @@ function register_graphql_event( Event $event ): void {
137137
if ( did_action( 'graphql_register_events' ) ) {
138138
_doing_it_wrong(
139139
__FUNCTION__,
140-
esc_html__( 'Call this before EventRegistry::init', 'wp-graphql-webhooks' ),
140+
'Call this before EventRegistry::init',
141141
'0.0.1'
142142
);
143143
return;

plugins/wp-graphql-headless-webhooks/src/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected static function require_autoloader( string $autoloader_file ): bool {
6060
* Displays a notice if the autoloader is missing.
6161
*/
6262
protected static function missing_autoloader_notice(): void {
63-
$error_message = __( 'Headless Webhooks for WPGraphQL: The Composer autoloader was not found. If you installed the plugin from the GitHub source, make sure to run `composer install`.', 'wp-graphql-headless-webhooks' );
63+
$error_message = 'Headless Webhooks for WPGraphQL: The Composer autoloader was not found. If you installed the plugin from the GitHub source, make sure to run `composer install`.';
6464

6565
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
6666
error_log( esc_html( $error_message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a development notice.

plugins/wp-graphql-headless-webhooks/src/Plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ private function includes(): void {
102102
* Prevent cloning.
103103
*/
104104
public function __clone() {
105-
_doing_it_wrong( __FUNCTION__, esc_html__( 'The plugin main class should not be cloned.', 'wp-graphql-headless-webhooks' ), '0.0.1' );
105+
_doing_it_wrong( __FUNCTION__, 'The plugin main class should not be cloned.', '0.0.1' );
106106
}
107107

108108
/**
109109
* Prevent unserializing.
110110
*/
111111
public function __wakeup(): void {
112-
_doing_it_wrong( __FUNCTION__, esc_html__( 'De-serializing instances of the plugin main class is not allowed.', 'wp-graphql-headless-webhooks' ), '0.0.1' );
112+
_doing_it_wrong( __FUNCTION__, 'De-serializing instances of the plugin main class is not allowed.', '0.0.1' );
113113
}
114114
}
115115

plugins/wp-graphql-headless-webhooks/wp-graphql-headless-webhooks.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
exit;
3131
}
3232

33+
// Define text domain constant to use instead of string literals
34+
if ( ! defined( 'WPGRAPHQL_HEADLESS_WEBHOOKS_TEXT_DOMAIN' ) ) {
35+
define( 'WPGRAPHQL_HEADLESS_WEBHOOKS_TEXT_DOMAIN', 'wp-graphql-headless-webhooks' );
36+
}
37+
3338
// Load the autoloader.
3439
require_once __DIR__ . '/src/Autoloader.php';
3540
if ( ! \WPGraphQL\Webhooks\Autoloader::autoload() ) {
@@ -101,6 +106,9 @@ function graphql_headless_webhooks_init(): void {
101106
$not_ready = graphql_headless_webhooks_dependencies_not_ready();
102107

103108
if ( $not_ready === [] && defined( 'WPGRAPHQL_HEADLESS_WEBHOOKS_PLUGIN_DIR' ) ) {
109+
// Load text domain at the init hook
110+
add_action('init', 'WPGraphQL\Webhooks\graphql_headless_webhooks_load_textdomain');
111+
104112
require_once WPGRAPHQL_HEADLESS_WEBHOOKS_PLUGIN_DIR . 'src/Plugin.php';
105113
$plugin = new \WPGraphQL\Webhooks\Plugin();
106114
$plugin::instance();
@@ -115,9 +123,10 @@ static function () use ($dep) {
115123
<div class="error notice">
116124
<p>
117125
<?php
126+
// Using plain string to avoid early text domain loading
118127
printf(
119128
/* translators: dependency not ready error message */
120-
esc_html__( '%1$s must be active for WPGraphQL Plugin Name to work.', 'wp-graphql-headless-webhooks' ),
129+
'%1$s must be active for WPGraphQL Headless Webhooks to work.',
121130
esc_html( $dep )
122131
);
123132
?>
@@ -130,6 +139,20 @@ static function () use ($dep) {
130139
);
131140
}
132141
}
142+
/**
143+
* Load plugin text domain.
144+
*/
145+
function graphql_headless_webhooks_load_textdomain(): void {
146+
load_plugin_textdomain(
147+
'wp-graphql-headless-webhooks',
148+
false,
149+
dirname( plugin_basename( __FILE__ ) ) . '/languages'
150+
);
151+
}
152+
153+
// Load the text domain during init, not earlier
154+
add_action( 'init', 'WPGraphQL\Webhooks\graphql_headless_webhooks_load_textdomain', 1 );
155+
133156
/** @psalm-suppress HookNotFound */
134157
add_action( 'plugins_loaded', 'WPGraphQL\Webhooks\graphql_headless_webhooks_init' );
135158

0 commit comments

Comments
 (0)