Bez popisu

woocommerce-admin.php 4.7KB

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