<?php
defined('ABSPATH') || exit;
use Automattic\WooCommerce\Admin\FeaturePlugin;
use Automattic\WooCommerce\Admin\Loader;
if (is_readable(__DIR__ . '/vendor/autoload_packages.php')) {
require __DIR__ . '/vendor/autoload_packages.php';
} else {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log(sprintf(esc_html__('Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce'), '`composer install`', '`' . esc_html(str_replace(ABSPATH, '', __DIR__)) . '`'));
}
add_action('admin_notices', function () {
?>
<div class="notice notice-error">
<p>
<?php
printf(esc_html__('Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce'), '<code>composer install</code>', '<code>' . esc_html(str_replace(ABSPATH, '', __DIR__)) . '</code>');
?>
</p>
</div>
<?php
});
return;
}
function woocommerce_admin_is_development_version()
{
$composer_file = __DIR__ . '/composer.json';
if (!is_readable($composer_file)) {
return false;
}
$composer_config = json_decode(file_get_contents($composer_file), true);
return !isset($composer_config['version']);
}
function woocommerce_admin_check_build_files()
{
$script_debug = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG;
$suffix = Loader::should_use_minified_js_file($script_debug) ? '.min' : '';
return file_exists(__DIR__ . "/dist/app/index{$suffix}.js");
}
if (woocommerce_admin_is_development_version() && !defined('JETPACK_AUTOLOAD_DEV')) {
add_action('admin_notices', function () {
echo '<div class="error"><p>';
printf(esc_html__('WooCommerce Admin development mode requires the %1$s constant to be defined and true in your %2$s file. Otherwise you are loading the admin package from WooCommerce core.', 'woocommerce'), '<code>JETPACK_AUTOLOAD_DEV</code>', '<code>wp-config.php</code>');
echo '</p></div>';
});
}
if (!woocommerce_admin_check_build_files()) {
add_action('admin_notices', function () {
echo '<div class="error"><p>';
printf(esc_html__('You have installed a development version of WooCommerce Admin which requires files to be built. From the plugin directory, run %1$s and %2$s to install dependencies, then %3$s to build the files.', 'woocommerce'), '<code>composer install</code>', '<code>npm install</code>', '<code>npm run build</code>');
printf(esc_html__('Or you can download a pre-built version of the plugin by visiting <a href="%1$s">the releases page in the repository</a>.', 'woocommerce'), 'https://github.com/woocommerce/woocommerce-admin/releases');
echo '</p></div>';
});
}
FeaturePlugin::instance()->init();