| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Initializers; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\WP_Tests_Conditional; |
| 6 |
|
| 7 |
/** |
| 8 |
* Silences load_textdomain_just_in_time issues when running WP tests. |
| 9 |
* |
| 10 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded |
| 11 |
*/ |
| 12 |
class Silence_Load_Textdomain_Just_In_Time_Notices implements Initializer_Interface { |
| 13 |
|
| 14 |
/** |
| 15 |
* Returns the conditionals based in which this loadable should be active. |
| 16 |
* |
| 17 |
* @return array<string> The array of conditionals. |
| 18 |
*/ |
| 19 |
public static function get_conditionals() { |
| 20 |
return [ WP_Tests_Conditional::class ]; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Hooks our required hooks. |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public function initialize() { |
| 29 |
\add_filter( 'doing_it_wrong_trigger_error', [ $this, 'silence_textdomain_notices' ], 10, 2 ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Silences textdomain notices. |
| 34 |
* |
| 35 |
* @param bool $trigger Whether to trigger the error. Default true. |
| 36 |
* @param string $function_name The function name that triggered the error. |
| 37 |
* |
| 38 |
* @return bool |
| 39 |
*/ |
| 40 |
public function silence_textdomain_notices( $trigger, $function_name ) { |
| 41 |
if ( $function_name === '_load_textdomain_just_in_time' ) { |
| 42 |
// Silence the notice. |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
return $trigger; |
| 47 |
} |
| 48 |
} |
| 49 |
|