woocommerce/woocommerce.php

73 lines
1.9 KiB
PHP

<?php
/**
* Plugin Name: WooCommerce
* Plugin URI: https://woocommerce.com/
* Description: An eCommerce toolkit that helps you sell anything. Beautifully.
* Version: 4.4.0-dev
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woocommerce
* Domain Path: /i18n/languages/
* Requires at least: 5.2
* Requires PHP: 7.0
*
* @package WooCommerce
*/
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Tools\DependencyManagement\ObjectContainer;
if ( ! defined( 'WC_PLUGIN_FILE' ) ) {
define( 'WC_PLUGIN_FILE', __FILE__ );
}
// Load core packages and the autoloader.
require __DIR__ . '/src/Autoloader.php';
require __DIR__ . '/src/Packages.php';
if ( ! \Automattic\WooCommerce\Autoloader::init() ) {
return;
}
\Automattic\WooCommerce\Packages::init();
// Define a simple autoloader for the object container to work.
// Function grabbed from https://container.thephpleague.com/3.x
spl_autoload_register(
function ( $class ) {
$prefix = 'Automattic\\WooCommerce\\';
$base_dir = __DIR__ . '/src/';
$len = strlen( $prefix );
if ( strncmp( $prefix, $class, $len ) !== 0 ) {
// no, move to the next registered autoloader
return;
}
$relative_class = substr( $class, $len );
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
if ( file_exists( $file ) ) {
require $file;
}
}
);
// Include the main WooCommerce class.
if ( ! class_exists( 'WooCommerce', false ) ) {
include_once dirname( WC_PLUGIN_FILE ) . '/includes/class-woocommerce.php';
}
// Initialize dependency injection.
ObjectContainer::init();
/**
* Returns the main instance of WC.
*
* @since 2.1
* @return WooCommerce
*/
function WC() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return ObjectContainer::get_instance_of( WooCommerce::class );
}
// Global for backwards compatibility.
$GLOBALS['woocommerce'] = WC();