-
Notifications
You must be signed in to change notification settings - Fork 0
/
wc-muse.php
158 lines (114 loc) · 3.77 KB
/
wc-muse.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* @link [email protected]
* @since 1.0.0
* @package Wc_Muse
*
* @wordpress-plugin
* Plugin Name: WooCommerce Muse
* Plugin URI: #
* Description: Woocommerce Muse Integration.
* Version: 1.0.0
* Author: Dinkum Interactive
* Author URI: [email protected]
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wc-muse
* Domain Path: /languages
* WC requires at least: 3.0
* WC tested up to: 3.2.3
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
/**
* Current plugin version.
*/
define( 'WC_MUSE_VERSION', '1.0.0' );
/**
* The code that runs during plugin activation.
*/
function activate_wc_muse() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-muse-activator.php';
Wc_Muse_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
*/
function deactivate_wc_muse() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-muse-deactivator.php';
Wc_Muse_Deactivator::deactivate();
}
function wc_muse_woocommerce_missing_notice() {
$class = 'notice notice-error';
$text = '<strong>'. __( 'Warning', 'wc-muse' ) .'</strong>' . __( ': WooCommerce Muse needs at least Woocommerce 3.0.0 to function properly.', 'wc-muse' );
$notice = "<div class='$class'><p>$text</p></div>";
echo $notice;
}
function wc_muse_woocommerce_missing() {
// WooCommerce is missing.
if (
// Require WooCommerce
is_admin() && in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) &&
// Require WooCommerce 3+
defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '3.0.0', '>=' )
) {
update_option( 'wc_muse_active', true );
return false;
} else {
update_option( 'wc_muse_active', false );
add_action( 'admin_notices', 'wc_muse_woocommerce_missing_notice' );
return true;
}
}
register_activation_hook( __FILE__, 'activate_wc_muse' );
register_deactivation_hook( __FILE__, 'deactivate_wc_muse' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-wc-muse.php';
/**
* Register constants
*
* @since 1.0.0
*/
function wc_muse_define_constants() {
define( 'WC_MUSE_ADMIN_TEMPLATE_DIR', plugin_dir_path( __FILE__ ) . 'admin/partials/' );
}
/**
* Begins execution of the plugin.
*
* @since 1.0.0
*/
function run_wc_muse() {
if ( wc_muse_woocommerce_missing() ) return false;
if ( ! get_option( 'wc_muse_active' ) ) return false;
wc_muse_define_constants();
$plugin = new Wc_Muse();
$plugin->init();
$plugin->run();
}
add_action( 'plugins_loaded', 'run_wc_muse' );
/**
* Add plugin cron interval.
*
* @since 1.0.0
*/
if ( 'yes' === get_option( 'wc-muse-enable_cron' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/core/class-wc-muse-core.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-muse-cron.php';
$cron = new Wc_Muse_Cron();
$core = new Wc_Muse_Core();
add_filter( 'cron_schedules', array( $cron, 'add_cron_schedules' ) );
add_action( 'wc_muse_order_export_success', array( $core, 'change_order_status' ), 10, 2 );
add_action( 'wc_muse_order_export_success', array( $core, 'update_success_meta' ), 10, 2 );
add_action( 'wc_muse_order_export_failed', array( $core, 'update_failed_meta' ), 10, 2 );
// Add cron event to queue.
$cron->add_cron_schedule();
}
add_action( 'wc_muse_cron_events', 'run_wc_muse_cron_events' );
function run_wc_muse_cron_events() {
$plugin = new Wc_Muse();
$plugin->load_dependencies();
Wc_Muse_Core::export_orders();
}