-
Notifications
You must be signed in to change notification settings - Fork 56
/
wcs-importer-exporter.php
181 lines (158 loc) · 7.03 KB
/
wcs-importer-exporter.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* Plugin Name: WooCommerce Subscriptions CSV Importer and Exporter
* Plugin URI: https://github.com/Prospress/woocommerce-subscriptions-importer-exporter
* Description: Import or export subscriptions in your WooCommerce store via CSV.
* Version: 2.2.0
* Author: Prospress Inc
* Author URI: http://prospress.com
* License: GPLv3
*
* WC requires at least: 3.0.0
* WC tested up to: 4.4.1
*
* GitHub Plugin URI: Prospress/woocommerce-subscriptions-importer-exporter
* GitHub Branch: master
*
* Copyright 2019 Prospress, Inc. (email : [email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package WooCommerce Subscriptions Importer Exporter
* @author Prospress Inc.
* @since 1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'woothemes_queue_update' ) || ! function_exists( 'is_woocommerce_active' ) ) {
require_once( 'woo-includes/woo-functions.php' );
}
/**
* Declare plugin compatibility with WooCommerce HPOS.
*/
add_action(
'before_woocommerce_init',
function() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);
require_once( 'includes/wcsi-functions.php' );
class WCS_Importer_Exporter {
public static $wcs_importer;
public static $wcs_exporter;
public static $version = '2.2.0';
protected static $required_subscriptions_version = '2.2.0';
protected static $plugin_file = __FILE__;
/**
* Initialise filters for the Subscriptions CSV Importer
*
* @since 1.0
*/
public static function init() {
add_filter( 'plugins_loaded', __CLASS__ . '::setup_importer' );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __CLASS__ . '::action_links' );
add_action( 'wcs_export_cron', array( 'WCS_Exporter_Cron', 'cron_handler' ), 10, 2 );
add_action( 'wcs_export_scheduled_cleanup', array( 'WCS_Exporter_Cron', 'delete_export_file' ), 10, 1 );
spl_autoload_register( __CLASS__ . '::autoload' );
}
/**
* Create an instance of the importer on admin pages and check for WooCommerce Subscriptions dependency.
*
* @since 1.0
*/
public static function setup_importer() {
if ( is_admin() ) {
if ( class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, self::$required_subscriptions_version, '>=' ) ) {
self::$wcs_exporter = new WCS_Export_Admin();
self::$wcs_importer = new WCS_Import_Admin();
} else {
add_action( 'admin_notices', __CLASS__ . '::plugin_dependency_notice' );
}
}
}
/**
* Include Docs & Settings links on the Plugins administration screen
*
* @since 1.0
* @param mixed $links
*/
public static function action_links( $links ) {
$plugin_links = array(
'<a href="' . esc_url( admin_url( 'admin.php?page=import_subscription' ) ) . '">' . esc_html__( 'Import', 'wcs-import-export' ) . '</a>',
'<a href="https://github.com/Prospress/woocommerce-subscriptions-importer-exporter/blob/master/README.md">' . esc_html__( 'Docs', 'wcs-import-export' ) . '</a>',
'<a href="https://github.com/Prospress/woocommerce-subscriptions-importer-exporter/issues/new">' . esc_html__( 'Support', 'wcs-import-export' ) . '</a>',
);
return array_merge( $plugin_links, $links );
}
/**
* Display error message according to the missing dependency
*
* Will only show error for missing WC if Subscriptions is missing as well,
* this is to avoid duplicating messages printed by Subscriptions.
*
* @since 1.0
*/
public static function plugin_dependency_notice() {
if ( ! class_exists( 'WC_Subscriptions' ) || ! class_exists( 'WC_Subscriptions_Admin' ) ) :
if ( is_woocommerce_active() ) : ?>
<div id="message" class="error">
<p><?php printf( esc_html__( '%1$sWooCommerce Subscriptions CSV Importer and Exporter is inactive.%2$s The %3$sWooCommerce Subscriptions plugin%4$s must be active for WooCommerce Subscriptions CSV Importer and Exporter to work. Please %5$sinstall & activate%6$s WooCommerce Subscriptions.', 'wcs-import-export' ), '<strong>', '</strong>', '<a href="http://www.woocommerce.com/products/woocommerce-subscriptions/">', '</a>', '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', '</a>' ); ?></p>
</div>
<?php else : ?>
<div id="message" class="error">
<p><?php printf( esc_html__( '%1$sWooCommerce Subscriptions CSV Importer and Exporter is inactive.%2$s Both %3$sWooCommerce%4$s and %5$sWooCommerce Subscriptions%6$s plugins must be active for WooCommerce Subscriptions CSV Importer and Exporter to work. Please %7$sinstall & activate%8$s these plugins before continuing.', 'wcs-import-export' ), '<strong>', '</strong>', '<a href="http://wordpress.org/extend/plugins/woocommerce/">', '</a>', '<a href="http://www.woocommerce.com/products/woocommerce-subscriptions/">', '</a>', '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', '</a>' ); ?></p>
</div>
<?php endif;?>
<?php elseif ( ! class_exists( 'WC_Subscriptions' ) || version_compare( WC_Subscriptions::$version, self::$required_subscriptions_version, '<' ) ) : ?>
<div id="message" class="error">
<p><?php printf( esc_html__( '%1$sWooCommerce Subscriptions CSV Importer and Exporter is inactive.%2$s The %3$sWooCommerce Subscriptions%4$s version %7$s (or greater) is required to safely run WooCommerce Subscriptions CSV Importer and Exporter. Please %5$supdate & activate%6$s WooCommerce Subscriptions.', 'wcs-import-export' ), '<strong>', '</strong>', '<a href="http://www.woocommerce.com/products/woocommerce-subscriptions/">', '</a>', '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', ' »</a>', self::$required_subscriptions_version ); ?></p>
</div>
<?php endif;
}
/**
* Get the plugin's URL path for loading assets
*
* @since 2.0
* @return string
*/
public static function plugin_url() {
return plugin_dir_url( self::$plugin_file );
}
/**
* Get the plugin's path for loading files
*
* @since 2.0
* @return string
*/
public static function plugin_dir() {
return plugin_dir_path( self::$plugin_file );
}
/**
* Get the plugin's path for loading files
*
* @since 2.0
* @return string
*/
public static function autoload( $class ) {
$class = strtolower( $class );
$file = 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( 0 === strpos( $class, 'wcs_import' ) || 0 === strpos( $class, 'wcs_export' ) ) {
require_once( self::plugin_dir() . '/includes/' . $file );
}
}
}
WCS_Importer_Exporter::init();