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.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / packages / woocommerce-blocks / woocommerce-gutenberg-products-block.php
woocommerce / packages / woocommerce-blocks Last commit date
assets 5 years ago build 5 years ago packages 5 years ago src 5 years ago templates 5 years ago vendor 5 years ago readme.txt 5 years ago woocommerce-gutenberg-products-block.php 5 years ago
woocommerce-gutenberg-products-block.php
248 lines
1 <?php
2 /**
3 * Plugin Name: WooCommerce Blocks
4 * Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block
5 * Description: WooCommerce blocks for the Gutenberg editor.
6 * Version: 4.9.1
7 * Author: Automattic
8 * Author URI: https://woocommerce.com
9 * Text Domain: woo-gutenberg-products-block
10 * Requires at least: 5.5
11 * Requires PHP: 7.0
12 * WC requires at least: 4.9
13 * WC tested up to: 5.2
14 *
15 * @package WooCommerce\Blocks
16 * @internal This file is only used when running as a feature plugin.
17 */
18
19 defined( 'ABSPATH' ) || exit;
20
21 $minimum_wp_version = '5.5';
22
23 if ( ! defined( 'WC_BLOCKS_IS_FEATURE_PLUGIN' ) ) {
24 define( 'WC_BLOCKS_IS_FEATURE_PLUGIN', true );
25 }
26 /**
27 * Whether notices must be displayed in the current page (plugins and WooCommerce pages).
28 *
29 * @since 2.5.0
30 */
31 function should_display_compatibility_notices() {
32 $current_screen = get_current_screen();
33
34 if ( ! isset( $current_screen ) ) {
35 return false;
36 }
37
38 $is_plugins_page =
39 property_exists( $current_screen, 'id' ) &&
40 'plugins' === $current_screen->id;
41 $is_woocommerce_page =
42 property_exists( $current_screen, 'parent_base' ) &&
43 'woocommerce' === $current_screen->parent_base;
44
45 return $is_plugins_page || $is_woocommerce_page;
46 }
47
48 if ( version_compare( $GLOBALS['wp_version'], $minimum_wp_version, '<' ) ) {
49 /**
50 * Outputs for an admin notice about running WooCommerce Blocks on outdated WordPress.
51 *
52 * @since 2.5.0
53 */
54 function woocommerce_blocks_admin_unsupported_wp_notice() {
55 if ( should_display_compatibility_notices() ) {
56 ?>
57 <div class="notice notice-error is-dismissible">
58 <p><?php esc_html_e( 'WooCommerce Blocks requires a more recent version of WordPress and has been paused. Please update WordPress to continue enjoying WooCommerce Blocks.', 'woocommerce' ); ?></p>
59 </div>
60 <?php
61 }
62 }
63 add_action( 'admin_notices', 'woocommerce_blocks_admin_unsupported_wp_notice' );
64 return;
65 }
66
67 /**
68 * Returns whether the current version is a development version
69 * Note this relies on composer.json version, not plugin version.
70 * Development installs of the plugin don't have a version defined in
71 * composer json.
72 *
73 * @return bool True means the current version is a development version.
74 */
75 function woocommerce_blocks_is_development_version() {
76 $composer_file = __DIR__ . '/composer.json';
77 if ( ! is_readable( $composer_file ) ) {
78 return false;
79 }
80 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- including local file
81 $composer_config = json_decode( file_get_contents( $composer_file ), true );
82 return ! isset( $composer_config['version'] );
83 }
84
85 /**
86 * If development version is detected and the Jetpack constant is not defined, show a notice.
87 */
88 if ( woocommerce_blocks_is_development_version() && ! defined( 'JETPACK_AUTOLOAD_DEV' ) ) {
89 add_action(
90 'admin_notices',
91 function() {
92 echo '<div class="error"><p>';
93 printf(
94 /* translators: %1$s is referring to a php constant name, %2$s is referring to the wp-config.php file. */
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.', 'woocommerce' ),
96 'JETPACK_AUTOLOAD_DEV',
97 'wp-config.php'
98 );
99 echo '</p></div>';
100 }
101 );
102 }
103
104
105 /**
106 * Autoload packages.
107 *
108 * The package autoloader includes version information which prevents classes in this feature plugin
109 * conflicting with WooCommerce core.
110 *
111 * We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader.
112 * If the autoloader is not present, let's log the failure and display a nice admin notice.
113 */
114 $autoloader = __DIR__ . '/vendor/autoload_packages.php';
115 if ( is_readable( $autoloader ) ) {
116 require $autoloader;
117 } else {
118 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
119 error_log( // phpcs:ignore
120 sprintf(
121 /* translators: 1: composer command. 2: plugin directory */
122 esc_html__( 'Your installation of the WooCommerce Blocks feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce' ),
123 '`composer install`',
124 '`' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '`'
125 )
126 );
127 }
128 /**
129 * Outputs an admin notice if composer install has not been ran.
130 */
131 add_action(
132 'admin_notices',
133 function() {
134 ?>
135 <div class="notice notice-error">
136 <p>
137 <?php
138 printf(
139 /* translators: 1: composer command. 2: plugin directory */
140 esc_html__( 'Your installation of the WooCommerce Blocks feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce' ),
141 '<code>composer install</code>',
142 '<code>' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '</code>'
143 );
144 ?>
145 </p>
146 </div>
147 <?php
148 }
149 );
150 return;
151 }
152
153 add_action( 'plugins_loaded', array( '\Automattic\WooCommerce\Blocks\Package', 'init' ) );
154
155 /**
156 * Pre-filters script translations for the given file, script handle and text domain.
157 *
158 * @param string|false|null $translations JSON-encoded translation data. Default null.
159 * @param string|false $file Path to the translation file to load. False if there isn't one.
160 * @param string $handle Name of the script to register a translation domain to.
161 * @param string $domain The text domain.
162 * @return string JSON translations.
163 */
164 function woocommerce_blocks_get_i18n_data_json( $translations, $file, $handle, $domain ) {
165 if ( 'woo-gutenberg-products-block' !== $domain ) {
166 return $translations;
167 }
168
169 global $wp_scripts;
170
171 if ( ! isset( $wp_scripts->registered[ $handle ], $wp_scripts->registered[ $handle ]->src ) ) {
172 return $translations;
173 }
174
175 $handle_filename = basename( $wp_scripts->registered[ $handle ]->src );
176 $locale = determine_locale();
177 $lang_dir = WP_LANG_DIR . '/plugins';
178
179 // Translations are always based on the unminified filename.
180 if ( substr( $handle_filename, -7 ) === '.min.js' ) {
181 $handle_filename = substr( $handle_filename, 0, -7 ) . '.js';
182 }
183
184 // WordPress 5.0 uses md5 hashes of file paths to associate translation
185 // JSON files with the file they should be included for. This is an md5
186 // of 'packages/woocommerce-blocks/build/FILENAME.js'.
187 $core_path_md5 = md5( 'packages/woocommerce-blocks/build/' . $handle_filename );
188 $core_json_file = $lang_dir . '/woocommerce-' . $locale . '-' . $core_path_md5 . '.json';
189 $json_translations = is_file( $core_json_file ) && is_readable( $core_json_file ) ? file_get_contents( $core_json_file ) : false; // phpcs:ignore
190
191 if ( ! $json_translations ) {
192 return $translations;
193 }
194
195 // Rather than short circuit pre_load_script_translations, we will output
196 // core translations using an inline script. This will allow us to continue
197 // to load feature-plugin translations which may exist as well.
198 $output = <<<JS
199 ( function( domain, translations ) {
200 var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
201 localeData[""].domain = domain;
202 wp.i18n.setLocaleData( localeData, domain );
203 } )( "{$domain}", {$json_translations} );
204 JS;
205
206 printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); // phpcs:ignore
207
208 // Finally, short circuit the pre_load_script_translations hook by returning
209 // the translation JSON from the feature plugin, if it exists so this hook
210 // does not run again for the current handle.
211 $path_md5 = md5( 'build/' . $handle_filename );
212 $json_file = $lang_dir . '/' . $domain . '-' . $locale . '-' . $path_md5 . '.json';
213 $translations = is_file( $json_file ) && is_readable( $json_file ) ? file_get_contents( $json_file ) : false; // phpcs:ignore
214
215 if ( $translations ) {
216 return $translations;
217 }
218
219 // Return valid empty Jed locale.
220 return '{ "locale_data": { "messages": { "": {} } } }';
221 }
222
223 add_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 );
224
225 /**
226 * Filter translations so we can retrieve translations from Core when the original and the translated
227 * texts are the same (which happens when translations are missing).
228 *
229 * @param string $translation Translated text based on WC Blocks translations.
230 * @param string $text Text to translate.
231 * @param string $domain The text domain.
232 * @return string WC Blocks translation. In case it's the same as $text, Core translation.
233 */
234 function woocommerce_blocks_get_php_translation_from_core( $translation, $text, $domain ) {
235 if ( 'woo-gutenberg-products-block' !== $domain ) {
236 return $translation;
237 }
238
239 // When translation is the same, that could mean the string is not translated.
240 // In that case, load it from core.
241 if ( $translation === $text ) {
242 return translate( $text, 'woocommerce' ); // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction, WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.TextDomainMismatch
243 }
244 return $translation;
245 }
246
247 add_filter( 'gettext', 'woocommerce_blocks_get_php_translation_from_core', 10, 3 );
248