2018-04-17 21:03:14 +00:00
< ? php
/**
2018-07-10 12:48:06 +00:00
* Plugin Name : WooCommerce Admin
2018-04-17 23:51:48 +00:00
* Plugin URI : https :// woocommerce . com /
2018-07-10 12:48:06 +00:00
* Description : A feature plugin for a modern , javascript - driven WooCommerce admin experience .
2018-04-17 23:51:48 +00:00
* Author : Automattic
* Author URI : https :// woocommerce . com /
2018-09-24 15:24:08 +00:00
* Text Domain : wc - admin
2018-04-17 23:51:48 +00:00
* Domain Path : / languages
* Version : 0.1 . 0
2018-04-17 21:03:14 +00:00
*
2018-07-10 12:48:06 +00:00
* @ package WC_Admin
2018-04-17 21:03:14 +00:00
*/
2018-07-10 12:48:06 +00:00
if ( ! defined ( 'WC_ADMIN_APP' ) ) {
define ( 'WC_ADMIN_APP' , 'wc-admin-app' );
2018-04-17 23:51:48 +00:00
}
2018-09-17 18:36:29 +00:00
if ( ! defined ( 'WC_ADMIN_ABSPATH' ) ) {
define ( 'WC_ADMIN_ABSPATH' , dirname ( __FILE__ ) );
}
2018-09-21 10:14:08 +00:00
if ( ! defined ( 'WC_ADMIN_PLUGIN_FILE' ) ) {
define ( 'WC_ADMIN_PLUGIN_FILE' , __FILE__ );
}
2018-05-03 17:55:53 +00:00
/**
* Notify users of the plugin requirements
*/
2018-07-10 12:48:06 +00:00
function wc_admin_plugins_notice () {
2018-05-03 17:55:53 +00:00
$message = sprintf (
2018-09-24 15:24:08 +00:00
/* translators: 1: URL of Gutenberg plugin, 2: URL of WooCommerce plugin */
2018-10-15 19:23:09 +00:00
__ ( 'The WooCommerce Admin feature plugin requires both <a href="%1$s">Gutenberg</a> and <a href="%2$s">WooCommerce</a> (>3.5) to be installed and active.' , 'wc-admin' ),
2018-05-03 17:55:53 +00:00
'https://wordpress.org/plugins/gutenberg/' ,
'https://wordpress.org/plugins/woocommerce/'
);
printf ( '<div class="error"><p>%s</p></div>' , $message ); /* WPCS: xss ok. */
}
2018-04-17 23:51:48 +00:00
2018-09-24 15:24:08 +00:00
/**
* Returns true if all dependencies for the wc - admin plugin are loaded .
*
* @ return bool
*/
2018-09-21 10:14:08 +00:00
function dependencies_satisfied () {
return ( defined ( 'GUTENBERG_DEVELOPMENT_MODE' ) || defined ( 'GUTENBERG_VERSION' ) )
2018-10-15 19:23:09 +00:00
&& class_exists ( 'WooCommerce' ) && version_compare ( WC_VERSION , '3.5' , '>' );
2018-09-21 10:14:08 +00:00
}
2018-09-24 15:24:08 +00:00
/**
* Activates wc - admin plugin when installed .
*/
2018-09-21 10:14:08 +00:00
function activate_wc_admin_plugin () {
if ( ! dependencies_satisfied () ) {
return ;
}
// Initialize the WC API extensions.
require_once dirname ( __FILE__ ) . '/includes/class-wc-admin-api-init.php' ;
WC_Admin_Api_Init :: install ();
}
register_activation_hook ( WC_ADMIN_PLUGIN_FILE , 'activate_wc_admin_plugin' );
2018-10-18 18:37:49 +00:00
/**
* Deactivate wc - admin plugin if dependencies not satisfied .
*/
function deactivate_wc_admin_plugin () {
if ( ! dependencies_satisfied () ) {
deactivate_plugins ( plugin_basename ( WC_ADMIN_PLUGIN_FILE ) );
unset ( $_GET [ 'activate' ] );
}
}
add_action ( 'admin_init' , 'deactivate_wc_admin_plugin' );
2018-05-03 17:55:53 +00:00
/**
* Set up the plugin , only if we can detect both Gutenberg and WooCommerce
*/
2018-07-10 12:48:06 +00:00
function wc_admin_plugins_loaded () {
2018-09-21 10:14:08 +00:00
if ( ! dependencies_satisfied () ) {
2018-07-10 12:48:06 +00:00
add_action ( 'admin_notices' , 'wc_admin_plugins_notice' );
2018-05-03 17:55:53 +00:00
return ;
}
2018-09-17 14:32:03 +00:00
// Initialize the WC API extensions.
2018-09-17 18:20:00 +00:00
require_once dirname ( __FILE__ ) . '/includes/class-wc-admin-api-init.php' ;
2018-09-17 14:32:03 +00:00
2018-09-24 15:24:08 +00:00
// Some common utilities.
2018-05-03 17:55:53 +00:00
require_once dirname ( __FILE__ ) . '/lib/common.php' ;
2018-04-17 23:51:48 +00:00
2018-09-24 15:24:08 +00:00
// Register script files.
2018-05-03 17:55:53 +00:00
require_once dirname ( __FILE__ ) . '/lib/client-assets.php' ;
2018-04-17 23:51:48 +00:00
2018-09-24 15:24:08 +00:00
// Create the Admin pages.
2018-05-03 17:55:53 +00:00
require_once dirname ( __FILE__ ) . '/lib/admin.php' ;
}
2018-07-10 12:48:06 +00:00
add_action ( 'plugins_loaded' , 'wc_admin_plugins_loaded' );