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
2019-02-14 17:24:02 +00:00
* Version : 0.7 . 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
/**
2019-02-12 20:22:16 +00:00
* Notify users of the plugin requirements .
2018-05-03 17:55:53 +00:00
*/
2018-07-10 12:48:06 +00:00
function wc_admin_plugins_notice () {
2018-11-07 19:53:05 +00:00
// The notice varies by WordPress version.
$wordpress_version = get_bloginfo ( 'version' );
$wordpress_includes_gutenberg = version_compare ( $wordpress_version , '4.9.9' , '>' );
if ( $wordpress_includes_gutenberg ) {
$message = sprintf (
/* translators: URL of WooCommerce plugin */
2019-02-15 19:41:19 +00:00
__ ( 'The WooCommerce Admin feature plugin requires <a href="%s">WooCommerce</a> 3.5 or greater to be installed and active.' , 'wc-admin' ),
2018-11-07 19:53:05 +00:00
'https://wordpress.org/plugins/woocommerce/'
);
} else {
$message = sprintf (
2019-02-12 20:22:16 +00:00
/* translators: 1: URL of WordPress.org, 2: URL of WooCommerce plugin */
__ ( 'The WooCommerce Admin feature plugin requires both <a href="%1$s">WordPress</a> 5.0 or greater and <a href="%2$s">WooCommerce</a> 3.5 or greater to be installed and active.' , 'wc-admin' ),
'https://wordpress.org/' ,
2018-11-07 19:53:05 +00:00
'https://wordpress.org/plugins/woocommerce/'
);
}
2018-05-03 17:55:53 +00:00
printf ( '<div class="error"><p>%s</p></div>' , $message ); /* WPCS: xss ok. */
}
2018-04-17 23:51:48 +00:00
2018-12-14 00:44:58 +00:00
/**
2019-02-12 20:22:16 +00:00
* Notify users that the plugin needs to be built .
2018-12-14 00:44:58 +00:00
*/
function wc_admin_build_notice () {
$message_one = __ ( 'You have installed a development version of WooCommerce Admin which requires files to be built. From the plugin directory, run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files.' , 'wc-admin' );
$message_two = sprintf (
/* translators: 1: URL of GitHub Repository build page */
__ ( 'Or you can download a pre-built version of the plugin by visiting <a href="%1$s">the releases page in the repository</a>.' , 'wc-admin' ),
'https://github.com/woocommerce/wc-admin/releases'
);
printf ( '<div class="error"><p>%s %s</p></div>' , $message_one , $message_two ); /* WPCS: xss ok. */
}
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 () {
2018-11-07 17:53:20 +00:00
$woocommerce_minimum_met = class_exists ( 'WooCommerce' ) && version_compare ( WC_VERSION , '3.5' , '>' );
2018-11-05 02:14:26 +00:00
if ( ! $woocommerce_minimum_met ) {
return false ;
}
2019-02-12 20:22:16 +00:00
$wordpress_version = get_bloginfo ( 'version' );
return version_compare ( $wordpress_version , '4.9.9' , '>' );
2018-09-21 10:14:08 +00:00
}
2018-12-14 00:44:58 +00:00
/**
* Returns true if build file exists .
*
* @ return bool
*/
function wc_admin_build_file_exists () {
return file_exists ( plugin_dir_path ( __FILE__ ) . '/dist/app/index.js' );
}
2018-10-18 23:41:43 +00:00
/**
* Daily events to run .
*/
2018-10-22 16:09:28 +00:00
function do_wc_admin_daily () {
2018-10-18 23:41:43 +00:00
WC_Admin_Notes_New_Sales_Record :: possibly_add_sales_record_note ();
}
2018-10-22 16:09:28 +00:00
add_action ( 'wc_admin_daily' , 'do_wc_admin_daily' );
2018-10-18 23:41:43 +00:00
2018-09-24 15:24:08 +00:00
/**
2019-02-08 19:27:39 +00:00
* Initializes wc - admin daily action when plugin activated .
2018-09-24 15:24:08 +00:00
*/
2018-09-21 10:14:08 +00:00
function activate_wc_admin_plugin () {
if ( ! dependencies_satisfied () ) {
return ;
}
2018-10-18 23:41:43 +00:00
if ( ! wp_next_scheduled ( 'wc_admin_daily' ) ) {
wp_schedule_event ( time (), 'daily' , 'wc_admin_daily' );
}
2018-09-21 10:14:08 +00:00
}
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 .
*/
2018-10-18 23:41:43 +00:00
function possibly_deactivate_wc_admin_plugin () {
2018-10-18 18:37:49 +00:00
if ( ! dependencies_satisfied () ) {
deactivate_plugins ( plugin_basename ( WC_ADMIN_PLUGIN_FILE ) );
unset ( $_GET [ 'activate' ] );
}
}
2018-10-18 23:41:43 +00:00
add_action ( 'admin_init' , 'possibly_deactivate_wc_admin_plugin' );
/**
* On deactivating the wc - admin plugin .
*/
function deactivate_wc_admin_plugin () {
wp_clear_scheduled_hook ( 'wc_admin_daily' );
}
register_deactivation_hook ( WC_ADMIN_PLUGIN_FILE , 'deactivate_wc_admin_plugin' );
2018-10-18 18:37:49 +00:00
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 ;
}
2019-02-12 20:02:02 +00:00
if ( ! function_exists ( 'wc_admin_get_feature_config' ) ) {
2019-02-15 20:03:32 +00:00
require_once WC_ADMIN_ABSPATH . '/includes/feature-config.php' ;
2019-02-12 20:02:02 +00:00
}
2018-09-17 14:32:03 +00:00
// Initialize the WC API extensions.
2019-02-15 20:03:32 +00:00
require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-reports-sync.php' ;
require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-install.php' ;
require_once WC_ADMIN_ABSPATH . '/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.
2019-02-15 20:03:32 +00:00
require_once WC_ADMIN_ABSPATH . '/lib/common.php' ;
2018-04-17 23:51:48 +00:00
2018-12-14 00:44:58 +00:00
// Admin note providers.
2019-02-15 20:03:32 +00:00
require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-notes-new-sales-record.php' ;
require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-notes-settings-notes.php' ;
require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-notes-woo-subscriptions-notes.php' ;
2018-12-14 00:44:58 +00:00
// Verify we have a proper build.
if ( ! wc_admin_build_file_exists () ) {
add_action ( 'admin_notices' , 'wc_admin_build_notice' );
return ;
}
2018-09-24 15:24:08 +00:00
// Register script files.
2019-02-15 20:03:32 +00:00
require_once WC_ADMIN_ABSPATH . '/lib/client-assets.php' ;
2018-04-17 23:51:48 +00:00
2018-09-24 15:24:08 +00:00
// Create the Admin pages.
2019-02-15 20:03:32 +00:00
require_once WC_ADMIN_ABSPATH . '/lib/admin.php' ;
2018-05-03 17:55:53 +00:00
}
2018-07-10 12:48:06 +00:00
add_action ( 'plugins_loaded' , 'wc_admin_plugins_loaded' );
2018-10-23 17:30:33 +00:00
/**
* Things to do after WooCommerce updates .
*/
function wc_admin_woocommerce_updated () {
WC_Admin_Notes_Settings_Notes :: add_notes_for_settings_that_have_moved ();
}
add_action ( 'woocommerce_updated' , 'wc_admin_woocommerce_updated' );
2019-01-22 02:18:55 +00:00
/*
* Remove the emoji script as it always defaults to replacing emojis with Twemoji images .
* Gutenberg has also disabled emojis . More on that here -> https :// github . com / WordPress / gutenberg / pull / 6151
*/
remove_action ( 'admin_print_scripts' , 'print_emoji_detection_script' );