This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 144
/
woocommerce-admin.php
executable file
·143 lines (135 loc) · 4.86 KB
/
woocommerce-admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Plugin Name: WooCommerce Admin
* Plugin URI: https://github.com/woocommerce/woocommerce-admin
* Description: A new JavaScript-driven interface for managing your store. The plugin includes new and improved reports, and a dashboard to monitor all the important key metrics of your site.
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Text Domain: woocommerce-admin
* Domain Path: /languages
* Version: 3.4.0-dev
* Requires at least: 5.6
* Requires PHP: 7.0
*
* WC requires at least: 5.7.0
* WC tested up to: 5.9.0
*
* @package WooCommerce\Admin
*/
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Internal\Admin\FeaturePlugin;
use \Automattic\WooCommerce\Internal\Admin\Loader;
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
/**
* Autoload packages.
*
* We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader.
* If the autoloader is not present, let's log the failure and display a nice admin notice.
*/
if ( is_readable( __DIR__ . '/vendor/autoload_packages.php' ) ) {
require __DIR__ . '/vendor/autoload_packages.php';
} else {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( // phpcs:ignore
sprintf(
/* translators: 1: composer command. 2: plugin directory */
esc_html__( 'Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce-admin' ),
'`composer install`',
'`' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '`'
)
);
}
/**
* Outputs an admin notice if composer install has not been ran.
*/
add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: 1: composer command. 2: plugin directory */
esc_html__( 'Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce-admin' ),
'<code>composer install</code>',
'<code>' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '</code>'
);
?>
</p>
</div>
<?php
}
);
return;
}
/**
* Returns whether the current version is a development version
* Note this relies on composer.json version, not plugin version.
* Development installs of the plugin don't have a version defined in
* composer json.
*
* @return bool True means the current version is a development version.
*/
function woocommerce_admin_is_development_version() {
$composer_file = __DIR__ . '/composer.json';
if ( ! is_readable( $composer_file ) ) {
return false;
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- including local file
$composer_config = json_decode( file_get_contents( $composer_file ), true );
return ! isset( $composer_config['version'] );
}
/**
* Returns true if build file exists.
*
* @return bool
*/
function woocommerce_admin_check_build_files() {
$script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$suffix = WCAdminAssets::should_use_minified_js_file( $script_debug ) ? '.min' : '';
return file_exists( __DIR__ . "/dist/app/index{$suffix}.js" );
}
/**
* If development version is detected and the Jetpack constant is not defined, show a notice.
*/
if ( woocommerce_admin_is_development_version() && ! defined( 'JETPACK_AUTOLOAD_DEV' ) ) {
add_action(
'admin_notices',
function() {
echo '<div class="error"><p>';
printf(
/* Translators: %1$s is referring to a php constant name, %2$s is referring to the wp-config.php file. */
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-admin' ),
'<code>JETPACK_AUTOLOAD_DEV</code>',
'<code>wp-config.php</code>'
);
echo '</p></div>';
}
);
}
/**
* If we're missing expected files, notify users that the plugin needs to be built.
*/
if ( ! woocommerce_admin_check_build_files() ) {
add_action(
'admin_notices',
function() {
echo '<div class="error"><p>';
printf(
/* Translators: %1$s, %2$s, and %3$s are all build commands to be run in order. */
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-admin' ),
'<code>composer install</code>',
'<code>pnpm install</code>',
'<code>pnpm run build</code>'
);
printf(
/* translators: 1: URL of GitHub Repository build page */
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-admin' ),
'https://github.com/woocommerce/woocommerce-admin/releases'
);
echo '</p></div>';
}
);
}
FeaturePlugin::instance()->init();