Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 0fecf2b

Browse files
albarinnielslange
andauthored
Fix formatting (#7105)
Co-authored-by: Niels Lange <[email protected]>
1 parent 6cb49bc commit 0fecf2b

File tree

1 file changed

+55
-62
lines changed

1 file changed

+55
-62
lines changed
Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* Plugin Name: WooCommerce Blocks
54
* Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block
@@ -17,53 +16,51 @@
1716
* @internal This file is only used when running as a feature plugin.
1817
*/
1918

20-
defined('ABSPATH') || exit;
19+
defined( 'ABSPATH' ) || exit;
2120

2221
$minimum_wp_version = '6.0';
2322

24-
if (!defined('WC_BLOCKS_IS_FEATURE_PLUGIN')) {
25-
define('WC_BLOCKS_IS_FEATURE_PLUGIN', true);
23+
if ( ! defined( 'WC_BLOCKS_IS_FEATURE_PLUGIN' ) ) {
24+
define( 'WC_BLOCKS_IS_FEATURE_PLUGIN', true );
2625
}
2726
/**
2827
* Whether notices must be displayed in the current page (plugins and WooCommerce pages).
2928
*
3029
* @since 2.5.0
3130
*/
32-
function should_display_compatibility_notices()
33-
{
31+
function should_display_compatibility_notices() {
3432
$current_screen = get_current_screen();
3533

36-
if (!isset($current_screen)) {
34+
if ( ! isset( $current_screen ) ) {
3735
return false;
3836
}
3937

4038
$is_plugins_page =
41-
property_exists($current_screen, 'id') &&
39+
property_exists( $current_screen, 'id' ) &&
4240
'plugins' === $current_screen->id;
4341
$is_woocommerce_page =
44-
property_exists($current_screen, 'parent_base') &&
42+
property_exists( $current_screen, 'parent_base' ) &&
4543
'woocommerce' === $current_screen->parent_base;
4644

4745
return $is_plugins_page || $is_woocommerce_page;
4846
}
4947

50-
if (version_compare($GLOBALS['wp_version'], $minimum_wp_version, '<')) {
48+
if ( version_compare( $GLOBALS['wp_version'], $minimum_wp_version, '<' ) ) {
5149
/**
5250
* Outputs for an admin notice about running WooCommerce Blocks on outdated WordPress.
5351
*
5452
* @since 2.5.0
5553
*/
56-
function woocommerce_blocks_admin_unsupported_wp_notice()
57-
{
58-
if (should_display_compatibility_notices()) {
59-
?>
54+
function woocommerce_blocks_admin_unsupported_wp_notice() {
55+
if ( should_display_compatibility_notices() ) {
56+
?>
6057
<div class="notice notice-error">
61-
<p><?php esc_html_e('The WooCommerce Blocks feature plugin requires a more recent version of WordPress and has been paused. Please update WordPress to continue enjoying WooCommerce Blocks.', 'woo-gutenberg-products-block'); ?></p>
58+
<p><?php esc_html_e( 'The WooCommerce Blocks feature plugin requires a more recent version of WordPress and has been paused. Please update WordPress to continue enjoying WooCommerce Blocks.', 'woo-gutenberg-products-block' ); ?></p>
6259
</div>
63-
<?php
60+
<?php
6461
}
6562
}
66-
add_action('admin_notices', 'woocommerce_blocks_admin_unsupported_wp_notice');
63+
add_action( 'admin_notices', 'woocommerce_blocks_admin_unsupported_wp_notice' );
6764
return;
6865
}
6966

@@ -75,28 +72,27 @@ function woocommerce_blocks_admin_unsupported_wp_notice()
7572
*
7673
* @return bool True means the current version is a development version.
7774
*/
78-
function woocommerce_blocks_is_development_version()
79-
{
75+
function woocommerce_blocks_is_development_version() {
8076
$composer_file = __DIR__ . '/composer.json';
81-
if (!is_readable($composer_file)) {
77+
if ( ! is_readable( $composer_file ) ) {
8278
return false;
8379
}
8480
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- including local file
85-
$composer_config = json_decode(file_get_contents($composer_file), true);
86-
return !isset($composer_config['version']);
81+
$composer_config = json_decode( file_get_contents( $composer_file ), true );
82+
return ! isset( $composer_config['version'] );
8783
}
8884

8985
/**
9086
* If development version is detected and the Jetpack constant is not defined, show a notice.
9187
*/
92-
if (woocommerce_blocks_is_development_version() && !defined('JETPACK_AUTOLOAD_DEV')) {
88+
if ( woocommerce_blocks_is_development_version() && ! defined( 'JETPACK_AUTOLOAD_DEV' ) ) {
9389
add_action(
9490
'admin_notices',
9591
function () {
9692
echo '<div class="error"><p>';
9793
printf(
9894
/* translators: %1$s is referring to a php constant name, %2$s is referring to the wp-config.php file. */
99-
esc_html__('WooCommerce Blocks development mode requires the %1$s constant to be defined and true in your %2$s file. Otherwise you are loading the blocks package from WooCommerce core.', 'woo-gutenberg-products-block'),
95+
esc_html__( 'WooCommerce Blocks development mode requires the %1$s constant to be defined and true in your %2$s file. Otherwise you are loading the blocks package from WooCommerce core.', 'woo-gutenberg-products-block' ),
10096
'JETPACK_AUTOLOAD_DEV',
10197
'wp-config.php'
10298
);
@@ -116,16 +112,16 @@ function () {
116112
* If the autoloader is not present, let's log the failure and display a nice admin notice.
117113
*/
118114
$autoloader = __DIR__ . '/vendor/autoload_packages.php';
119-
if (is_readable($autoloader)) {
115+
if ( is_readable( $autoloader ) ) {
120116
require $autoloader;
121117
} else {
122-
if (defined('WP_DEBUG') && WP_DEBUG) {
118+
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
123119
error_log( // phpcs:ignore
124120
sprintf(
125121
/* translators: 1: composer command. 2: plugin directory */
126-
esc_html__('Your installation of the WooCommerce Blocks feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woo-gutenberg-products-block'),
122+
esc_html__( 'Your installation of the WooCommerce Blocks feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woo-gutenberg-products-block' ),
127123
'`composer install`',
128-
'`' . esc_html(str_replace(ABSPATH, '', __DIR__)) . '`'
124+
'`' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '`'
129125
)
130126
);
131127
}
@@ -135,26 +131,26 @@ function () {
135131
add_action(
136132
'admin_notices',
137133
function () {
138-
?>
134+
?>
139135
<div class="notice notice-error">
140136
<p>
141137
<?php
142138
printf(
143139
/* translators: 1: composer command. 2: plugin directory */
144-
esc_html__('Your installation of the WooCommerce Blocks feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woo-gutenberg-products-block'),
140+
esc_html__( 'Your installation of the WooCommerce Blocks feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woo-gutenberg-products-block' ),
145141
'<code>composer install</code>',
146-
'<code>' . esc_html(str_replace(ABSPATH, '', __DIR__)) . '</code>'
142+
'<code>' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '</code>'
147143
);
148144
?>
149145
</p>
150146
</div>
151-
<?php
147+
<?php
152148
}
153149
);
154150
return;
155151
}
156152

157-
add_action('plugins_loaded', array('\Automattic\WooCommerce\Blocks\Package', 'init'));
153+
add_action( 'plugins_loaded', array( '\Automattic\WooCommerce\Blocks\Package', 'init' ) );
158154

159155
/**
160156
* WordPress will look for translation in the following order:
@@ -171,9 +167,8 @@ function () {
171167
*
172168
* @return string|false Path to the translation file to load. False if there isn't one.
173169
*/
174-
function load_woocommerce_core_json_translation($file, $handle, $domain)
175-
{
176-
if ('woo-gutenberg-products-block' !== $domain) {
170+
function load_woocommerce_core_json_translation( $file, $handle, $domain ) {
171+
if ( 'woo-gutenberg-products-block' !== $domain ) {
177172
return $file;
178173
}
179174

@@ -183,32 +178,32 @@ function load_woocommerce_core_json_translation($file, $handle, $domain)
183178
* We only care about the translation file of the feature plugin in the
184179
* wp-content/languages folder.
185180
*/
186-
if (false === strpos($file, $lang_dir)) {
181+
if ( false === strpos( $file, $lang_dir ) ) {
187182
return $file;
188183
}
189184

190185
// If the translation file for feature plugin exist, use it.
191-
if (is_readable($file)) {
186+
if ( is_readable( $file ) ) {
192187
return $file;
193188
}
194189

195190
global $wp_scripts;
196191

197-
if (!isset($wp_scripts->registered[$handle], $wp_scripts->registered[$handle]->src)) {
192+
if ( ! isset( $wp_scripts->registered[ $handle ], $wp_scripts->registered[ $handle ]->src ) ) {
198193
return $file;
199194
}
200195

201-
$handle_src = explode('/build/', $wp_scripts->registered[$handle]->src);
196+
$handle_src = explode( '/build/', $wp_scripts->registered[ $handle ]->src );
202197
$handle_filename = $handle_src[1];
203198
$locale = determine_locale();
204199
$lang_dir = WP_LANG_DIR . '/plugins';
205200

206201
// Translations are always based on the unminified filename.
207-
if (substr($handle_filename, -7) === '.min.js') {
208-
$handle_filename = substr($handle_filename, 0, -7) . '.js';
202+
if ( substr( $handle_filename, -7 ) === '.min.js' ) {
203+
$handle_filename = substr( $handle_filename, 0, -7 ) . '.js';
209204
}
210205

211-
$core_path_md5 = md5('packages/woocommerce-blocks/build/' . $handle_filename);
206+
$core_path_md5 = md5( 'packages/woocommerce-blocks/build/' . $handle_filename );
212207

213208
/**
214209
* Return file path of the corresponding translation file in the WC Core is
@@ -218,7 +213,7 @@ function load_woocommerce_core_json_translation($file, $handle, $domain)
218213
return $lang_dir . '/woocommerce-' . $locale . '-' . $core_path_md5 . '.json';
219214
}
220215

221-
add_filter('load_script_translation_file', 'load_woocommerce_core_json_translation', 10, 3);
216+
add_filter( 'load_script_translation_file', 'load_woocommerce_core_json_translation', 10, 3 );
222217

223218
/**
224219
* Filter translations so we can retrieve translations from Core when the original and the translated
@@ -229,35 +224,33 @@ function load_woocommerce_core_json_translation($file, $handle, $domain)
229224
* @param string $domain The text domain.
230225
* @return string WC Blocks translation. In case it's the same as $text, Core translation.
231226
*/
232-
function woocommerce_blocks_get_php_translation_from_core($translation, $text, $domain)
233-
{
234-
if ('woo-gutenberg-products-block' !== $domain) {
227+
function woocommerce_blocks_get_php_translation_from_core( $translation, $text, $domain ) {
228+
if ( 'woo-gutenberg-products-block' !== $domain ) {
235229
return $translation;
236230
}
237231

238232
// When translation is the same, that could mean the string is not translated.
239233
// In that case, load it from core.
240-
if ($translation === $text) {
241-
return translate($text, 'woocommerce'); // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction, WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.TextDomainMismatch
234+
if ( $translation === $text ) {
235+
return translate( $text, 'woocommerce' ); // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction, WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.TextDomainMismatch
242236
}
243237
return $translation;
244238
}
245239

246-
add_filter('gettext', 'woocommerce_blocks_get_php_translation_from_core', 10, 3);
240+
add_filter( 'gettext', 'woocommerce_blocks_get_php_translation_from_core', 10, 3 );
247241

248242
/**
249243
* Add notice to the admin dashboard if the plugin is outdated.
250244
*
251245
* @see https://github.com/woocommerce/woocommerce-blocks/issues/5587
252246
*/
253-
function woocommerce_blocks_plugin_outdated_notice()
254-
{
247+
function woocommerce_blocks_plugin_outdated_notice() {
255248
$is_active =
256-
is_plugin_active('woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php') ||
257-
is_plugin_active('woocommerce-gutenberg-products-block/woocommerce-gutenberg-products-block.php') ||
258-
is_plugin_active('woocommerce-blocks/woocommerce-gutenberg-products-block.php');
249+
is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ||
250+
is_plugin_active( 'woocommerce-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ||
251+
is_plugin_active( 'woocommerce-blocks/woocommerce-gutenberg-products-block.php' );
259252

260-
if (!$is_active) {
253+
if ( ! $is_active ) {
261254
return;
262255
}
263256

@@ -268,17 +261,17 @@ function woocommerce_blocks_plugin_outdated_notice()
268261
* the current path is from the WC Core, we can consider the plugin is
269262
* outdated because Jetpack Autoloader always loads the newer package.
270263
*/
271-
if (!strpos($woocommerce_blocks_path, 'packages/woocommerce-blocks')) {
264+
if ( ! strpos( $woocommerce_blocks_path, 'packages/woocommerce-blocks' ) ) {
272265
return;
273266
}
274267

275-
if (should_display_compatibility_notices()) {
276-
?>
268+
if ( should_display_compatibility_notices() ) {
269+
?>
277270
<div class="notice notice-warning">
278-
<p><?php esc_html_e('You have WooCommerce Blocks installed, but the WooCommerce bundled version is running because it is more up-to-date. This may cause unexpected compatibility issues. Please update the WooCommerce Blocks plugin.', 'woo-gutenberg-products-block'); ?></p>
271+
<p><?php esc_html_e( 'You have WooCommerce Blocks installed, but the WooCommerce bundled version is running because it is more up-to-date. This may cause unexpected compatibility issues. Please update the WooCommerce Blocks plugin.', 'woo-gutenberg-products-block' ); ?></p>
279272
</div>
280-
<?php
273+
<?php
281274
}
282275
}
283276

284-
add_action('admin_notices', 'woocommerce_blocks_plugin_outdated_notice');
277+
add_action( 'admin_notices', 'woocommerce_blocks_plugin_outdated_notice' );

0 commit comments

Comments
 (0)