Version Description
Bug fixes, security improvements and improved i18n support
Download this release
Release Info
Developer | printful |
Plugin | Printful Integration for WooCommerce |
Version | 2.0.7 |
Comparing to | |
See all releases |
Code changes from version 2.0.6 to 2.0.7
- includes/class-printful-admin-dashboard.php +7 -6
- includes/class-printful-admin-settings.php +16 -11
- includes/class-printful-admin-status.php +36 -57
- includes/class-printful-admin.php +11 -10
- includes/class-printful-api-resource.php +4 -0
- includes/class-printful-carriers.php +1 -1
- includes/class-printful-integration.php +24 -17
- includes/class-printful-request-log.php +8 -4
- includes/{class-printful-rest-api.php → class-printful-rest-api-controller.php} +60 -12
- includes/class-printful-shipping.php +2 -5
- includes/class-printful-size-chart-tab.php +4 -7
- includes/class-printful-taxes.php +7 -6
- printful-shipping.php +24 -5
- readme.txt +7 -1
includes/class-printful-admin-dashboard.php
CHANGED
@@ -26,13 +26,14 @@ class Printful_Admin_Dashboard {
|
|
26 |
|
27 |
}
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
public static function view() {
|
33 |
|
34 |
$dashboard = self::instance();
|
35 |
-
$api_key = Printful_Integration::instance()->get_option('printful_key');
|
36 |
$connect_status = Printful_Integration::instance()->is_connected();
|
37 |
|
38 |
if ( $connect_status ) {
|
@@ -52,8 +53,8 @@ class Printful_Admin_Dashboard {
|
|
52 |
$status = Printful_Admin_Status::instance();
|
53 |
$issues = array();
|
54 |
|
55 |
-
$api_enabled = $status->run_single_test('check_WC_API_enabled');
|
56 |
-
$permalinks_set = $status->run_single_test('check_permalinks');
|
57 |
|
58 |
if ( $permalinks_set == Printful_Admin_Status::PF_STATUS_FAIL ) {
|
59 |
$message = 'WooCommerce API will not work unless your permalinks are set up correctly. Go to <a href="%s">Permalinks settings</a> and make sure that they are NOT set to "plain".';
|
26 |
|
27 |
}
|
28 |
|
29 |
+
/**
|
30 |
+
* Show the view
|
31 |
+
* @throws PrintfulException
|
32 |
+
*/
|
33 |
public static function view() {
|
34 |
|
35 |
$dashboard = self::instance();
|
36 |
+
$api_key = Printful_Integration::instance()->get_option( 'printful_key' );
|
37 |
$connect_status = Printful_Integration::instance()->is_connected();
|
38 |
|
39 |
if ( $connect_status ) {
|
53 |
$status = Printful_Admin_Status::instance();
|
54 |
$issues = array();
|
55 |
|
56 |
+
$api_enabled = $status->run_single_test( 'check_WC_API_enabled' );
|
57 |
+
$permalinks_set = $status->run_single_test( 'check_permalinks' );
|
58 |
|
59 |
if ( $permalinks_set == Printful_Admin_Status::PF_STATUS_FAIL ) {
|
60 |
$message = 'WooCommerce API will not work unless your permalinks are set up correctly. Go to <a href="%s">Permalinks settings</a> and make sure that they are NOT set to "plain".';
|
includes/class-printful-admin-settings.php
CHANGED
@@ -85,15 +85,17 @@ class Printful_Admin_Settings {
|
|
85 |
Printful_Admin::load_template( 'footer' );
|
86 |
}
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
91 |
public static function render_carriers_ajax() {
|
92 |
|
93 |
$carrier_settings = self::instance()->setup_carrier_fields();
|
94 |
Printful_Admin::load_template( 'setting-group', $carrier_settings );
|
95 |
$enable_submit = 'Printful_Settings.enable_submit_btn();';
|
96 |
-
Printful_Admin::load_template( 'inline-script', array('script' => $enable_submit) );
|
|
|
97 |
exit;
|
98 |
}
|
99 |
|
@@ -118,9 +120,10 @@ class Printful_Admin_Settings {
|
|
118 |
return $integration_settings;
|
119 |
}
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
124 |
public function setup_carrier_fields() {
|
125 |
|
126 |
$carrier_settings = array(
|
@@ -131,7 +134,8 @@ class Printful_Admin_Settings {
|
|
131 |
);
|
132 |
|
133 |
if ( ! Printful_Integration::instance()->is_connected() ) {
|
134 |
-
$carrier_settings['description'] = __('You need to be connected to Printful API to edit carrier settings!', 'printful' );
|
|
|
135 |
return $carrier_settings;
|
136 |
}
|
137 |
|
@@ -191,9 +195,10 @@ class Printful_Admin_Settings {
|
|
191 |
return $request_body;
|
192 |
}
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
197 |
public static function save_printful_settings() {
|
198 |
|
199 |
if ( ! empty( $_POST ) ) {
|
85 |
Printful_Admin::load_template( 'footer' );
|
86 |
}
|
87 |
|
88 |
+
/**
|
89 |
+
* Display the ajax content for carrier settings
|
90 |
+
* @throws PrintfulException
|
91 |
+
*/
|
92 |
public static function render_carriers_ajax() {
|
93 |
|
94 |
$carrier_settings = self::instance()->setup_carrier_fields();
|
95 |
Printful_Admin::load_template( 'setting-group', $carrier_settings );
|
96 |
$enable_submit = 'Printful_Settings.enable_submit_btn();';
|
97 |
+
Printful_Admin::load_template( 'inline-script', array( 'script' => $enable_submit ) );
|
98 |
+
|
99 |
exit;
|
100 |
}
|
101 |
|
120 |
return $integration_settings;
|
121 |
}
|
122 |
|
123 |
+
/**
|
124 |
+
* @internal param $carrier_settings
|
125 |
+
* @throws PrintfulException
|
126 |
+
*/
|
127 |
public function setup_carrier_fields() {
|
128 |
|
129 |
$carrier_settings = array(
|
134 |
);
|
135 |
|
136 |
if ( ! Printful_Integration::instance()->is_connected() ) {
|
137 |
+
$carrier_settings['description'] = __( 'You need to be connected to Printful API to edit carrier settings!', 'printful' );
|
138 |
+
|
139 |
return $carrier_settings;
|
140 |
}
|
141 |
|
195 |
return $request_body;
|
196 |
}
|
197 |
|
198 |
+
/**
|
199 |
+
* Ajax endpoint for saving the settings
|
200 |
+
* @throws PrintfulException
|
201 |
+
*/
|
202 |
public static function save_printful_settings() {
|
203 |
|
204 |
if ( ! empty( $_POST ) ) {
|
includes/class-printful-admin-status.php
CHANGED
@@ -19,90 +19,85 @@ class Printful_Admin_Status {
|
|
19 |
public static function getChecklistItems() {
|
20 |
return array(
|
21 |
array(
|
22 |
-
'name' => __('Connection to Printful API', 'printful'),
|
23 |
-
'description' => __('Is your store successfully connected to Printful API?', 'printful'),
|
24 |
'method' => 'check_PF_API_connect',
|
25 |
),
|
26 |
array(
|
27 |
-
'name' => __('Printful API key is set', 'printful'),
|
28 |
-
'description' => __('Your store needs access to Printful API to use most of it\'s features like shipping rates, tax rates and other settings.', 'printful'),
|
29 |
'method' => 'check_PF_API_key',
|
30 |
),
|
31 |
array(
|
32 |
-
'name' => __('WordPress Permalinks', 'printful'),
|
33 |
-
'description' => __('WooCommerce API will not work unless your permalinks in Settings > Permalinks are set up correctly. Make sure you that they are NOT set to "plain".', 'printful'),
|
34 |
'method' => 'check_permalinks',
|
35 |
),
|
36 |
array(
|
37 |
-
'name' => __('WordPress version', 'printful'),
|
38 |
-
'description' => __('WordPress should always be updated to the latest version. Updates can be installed from your WordPress admin dashboard.', 'printful'),
|
39 |
'method' => 'check_WP_version',
|
40 |
),
|
41 |
array(
|
42 |
-
'name' => __('WooCommerce API enabled', 'printful'),
|
43 |
-
'description' => __('Your site needs to enbable WooCommerce API so that Printful can connect to it.', 'printful'),
|
44 |
'method' => 'check_WC_API_enabled',
|
45 |
),
|
46 |
array(
|
47 |
-
'name' => __('WooCommerce Webhooks', 'printful'),
|
48 |
-
'description' => __('Printful requires WooCommerce webhooks to be set up to quickly capture you incoming orders, products updates etc.', 'printful'),
|
49 |
'method' => 'check_PF_webhooks',
|
50 |
),
|
51 |
array(
|
52 |
-
'name' => __('WooCommerce API keys are set', 'printful'),
|
53 |
-
'description' => __('Printful needs access to your WooCommerce API for the integration to work - otherwise we can\'t sync your store, push or pull your products etc.', 'printful'),
|
54 |
'method' => 'check_WC_API_access',
|
55 |
),
|
56 |
array(
|
57 |
-
'name' => __('WooCommerce authentication URL access', 'printful'),
|
58 |
-
'description' => __('Printful needs access to WooCommerce API authorize page. This sometimes may get blocked due to hosts having unnecessarily intrusive security checks in place that prevent WooCommerce API authentication from working (for example mod_security rule #1234234). If this check fails, you will not be able authorize Printful app.', 'printful'),
|
59 |
'method' => 'check_WC_auth_url_access',
|
60 |
),
|
61 |
array(
|
62 |
-
'name' => __('WordPress remote requests', 'printful'),
|
63 |
-
'description' => __('WordPress needs to be able to connect to Printful server to call webhooks. If this check fails, contact your hosting support.', 'printful'),
|
64 |
'method' => 'check_remote_requests',
|
65 |
),
|
66 |
array(
|
67 |
-
'name' => __('Recent store sync errors', 'printful'),
|
68 |
-
'description' => __('Printful will connect to your store\'s API regularly and sync your latest products, orders etc. If there have been any recent issues with sync, this check will fail.', 'printful'),
|
69 |
'method' => 'check_PF_sync_errors',
|
70 |
),
|
71 |
array(
|
72 |
-
'name' => __('Write permissions', 'printful'),
|
73 |
-
'description' => __('Make the uploads directory writable. This is required for mockup generator product push to work correctly. Contact your hosting provider if you need help with this.', 'printful'),
|
74 |
'method' => 'check_uploads_write',
|
75 |
),
|
76 |
array(
|
77 |
-
'name' => __('PHP memory limit', 'printful'),
|
78 |
-
'description' => __('Set PHP allocated memory limit to at least 128mb. Contact your hosting provider if you need help with this.', 'printful'),
|
79 |
'method' => 'check_PHP_memory_limit',
|
80 |
),
|
81 |
array(
|
82 |
-
'name' => __('PHP script time limit', 'printful'),
|
83 |
-
'description' => __('Set PHP script execution time limit to at least 30 seconds. This is required to successfully push products with many variants. Contact your hosting provider if you need help with this.', 'printful'),
|
84 |
'method' => 'check_PHP_time_limit',
|
85 |
),
|
86 |
-
// array(
|
87 |
-
// 'name' => __('Error logs', 'printful'),
|
88 |
-
// 'description' => __('Your WordPress site needs to have it\'s error logging set up correctly so in case of issues you can figure out what\'s wrong. Note: your hosting might already have an independent log from WordPress.', 'printful'),
|
89 |
-
// 'method' => 'check_WP_error_logs',
|
90 |
-
// ),
|
91 |
array(
|
92 |
-
'name' => __('W3 Total Cache DB Cache', 'printful'),
|
93 |
-
'description' => __('If you are using W3 Total Cache, the database caching feature needs to be disabled since it can cause issues with product push to store.', 'printful'),
|
94 |
'method' => 'check_W3_db_cache',
|
95 |
'silent' => true,
|
96 |
),
|
97 |
array(
|
98 |
-
'name' => __('WP SpamShield', 'printful'),
|
99 |
-
'description' => __('If you are using WP SpamShield, you might experience problems connecting to Printful and pushing products.', 'printful'),
|
100 |
'method' => 'check_wp_spamshield',
|
101 |
'silent' => true,
|
102 |
),
|
103 |
array(
|
104 |
-
'name' => __('Remove Print Aura plugin', 'printful'),
|
105 |
-
'description' => __('Print Aura plugin is known to cause issues so it needs to be removed.', 'printful'),
|
106 |
'method' => 'check_printaura_plugin',
|
107 |
'silent' => true,
|
108 |
),
|
@@ -166,11 +161,11 @@ class Printful_Admin_Status {
|
|
166 |
* @param bool $only_cached_results
|
167 |
* @return array
|
168 |
*/
|
169 |
-
public static function get_checklist($only_cached_results = false) {
|
170 |
|
171 |
$status = self::instance();
|
172 |
|
173 |
-
$list = get_transient(Printful_Admin_Status::PF_CACHED_CHECKLIST);
|
174 |
|
175 |
if ( $only_cached_results || $list ) {
|
176 |
return $list;
|
@@ -464,9 +459,9 @@ class Printful_Admin_Status {
|
|
464 |
*/
|
465 |
private function check_WC_API_enabled() {
|
466 |
|
467 |
-
$enabled = get_option('woocommerce_api_enabled', false);
|
468 |
|
469 |
-
if($enabled == 'yes') {
|
470 |
return self::PF_STATUS_OK;
|
471 |
}
|
472 |
|
@@ -569,20 +564,4 @@ class Printful_Admin_Status {
|
|
569 |
|
570 |
return self::PF_STATUS_FAIL;
|
571 |
}
|
572 |
-
|
573 |
-
/**
|
574 |
-
* @return int
|
575 |
-
*/
|
576 |
-
private function check_WP_error_logs() {
|
577 |
-
|
578 |
-
if (
|
579 |
-
( defined( 'WP_DEBUG' ) && WP_DEBUG == true )
|
580 |
-
&&
|
581 |
-
( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG == true )
|
582 |
-
) {
|
583 |
-
return self::PF_STATUS_OK;
|
584 |
-
}
|
585 |
-
|
586 |
-
return self::PF_STATUS_FAIL;
|
587 |
-
}
|
588 |
}
|
19 |
public static function getChecklistItems() {
|
20 |
return array(
|
21 |
array(
|
22 |
+
'name' => __( 'Connection to Printful API', 'printful' ),
|
23 |
+
'description' => __( 'Is your store successfully connected to Printful API?', 'printful' ),
|
24 |
'method' => 'check_PF_API_connect',
|
25 |
),
|
26 |
array(
|
27 |
+
'name' => __( 'Printful API key is set', 'printful' ),
|
28 |
+
'description' => __( 'Your store needs access to Printful API to use most of it\'s features like shipping rates, tax rates and other settings.', 'printful' ),
|
29 |
'method' => 'check_PF_API_key',
|
30 |
),
|
31 |
array(
|
32 |
+
'name' => __( 'WordPress Permalinks', 'printful' ),
|
33 |
+
'description' => __( 'WooCommerce API will not work unless your permalinks in Settings > Permalinks are set up correctly. Make sure you that they are NOT set to "plain".', 'printful' ),
|
34 |
'method' => 'check_permalinks',
|
35 |
),
|
36 |
array(
|
37 |
+
'name' => __( 'WordPress version', 'printful' ),
|
38 |
+
'description' => __( 'WordPress should always be updated to the latest version. Updates can be installed from your WordPress admin dashboard.', 'printful' ),
|
39 |
'method' => 'check_WP_version',
|
40 |
),
|
41 |
array(
|
42 |
+
'name' => __( 'WooCommerce API enabled', 'printful' ),
|
43 |
+
'description' => __( 'Your site needs to enbable WooCommerce API so that Printful can connect to it.', 'printful' ),
|
44 |
'method' => 'check_WC_API_enabled',
|
45 |
),
|
46 |
array(
|
47 |
+
'name' => __( 'WooCommerce Webhooks', 'printful' ),
|
48 |
+
'description' => __( 'Printful requires WooCommerce webhooks to be set up to quickly capture you incoming orders, products updates etc.', 'printful' ),
|
49 |
'method' => 'check_PF_webhooks',
|
50 |
),
|
51 |
array(
|
52 |
+
'name' => __( 'WooCommerce API keys are set', 'printful' ),
|
53 |
+
'description' => __( 'Printful needs access to your WooCommerce API for the integration to work - otherwise we can\'t sync your store, push or pull your products etc.', 'printful' ),
|
54 |
'method' => 'check_WC_API_access',
|
55 |
),
|
56 |
array(
|
57 |
+
'name' => __( 'WooCommerce authentication URL access', 'printful' ),
|
58 |
+
'description' => __( 'Printful needs access to WooCommerce API authorize page. This sometimes may get blocked due to hosts having unnecessarily intrusive security checks in place that prevent WooCommerce API authentication from working (for example mod_security rule #1234234). If this check fails, you will not be able authorize Printful app.', 'printful' ),
|
59 |
'method' => 'check_WC_auth_url_access',
|
60 |
),
|
61 |
array(
|
62 |
+
'name' => __( 'WordPress remote requests', 'printful' ),
|
63 |
+
'description' => __( 'WordPress needs to be able to connect to Printful server to call webhooks. If this check fails, contact your hosting support.', 'printful' ),
|
64 |
'method' => 'check_remote_requests',
|
65 |
),
|
66 |
array(
|
67 |
+
'name' => __( 'Recent store sync errors', 'printful' ),
|
68 |
+
'description' => __( 'Printful will connect to your store\'s API regularly and sync your latest products, orders etc. If there have been any recent issues with sync, this check will fail.', 'printful' ),
|
69 |
'method' => 'check_PF_sync_errors',
|
70 |
),
|
71 |
array(
|
72 |
+
'name' => __( 'Write permissions', 'printful' ),
|
73 |
+
'description' => __( 'Make the uploads directory writable. This is required for mockup generator product push to work correctly. Contact your hosting provider if you need help with this.', 'printful' ),
|
74 |
'method' => 'check_uploads_write',
|
75 |
),
|
76 |
array(
|
77 |
+
'name' => __( 'PHP memory limit', 'printful' ),
|
78 |
+
'description' => __( 'Set PHP allocated memory limit to at least 128mb. Contact your hosting provider if you need help with this.', 'printful' ),
|
79 |
'method' => 'check_PHP_memory_limit',
|
80 |
),
|
81 |
array(
|
82 |
+
'name' => __( 'PHP script time limit', 'printful' ),
|
83 |
+
'description' => __( 'Set PHP script execution time limit to at least 30 seconds. This is required to successfully push products with many variants. Contact your hosting provider if you need help with this.', 'printful' ),
|
84 |
'method' => 'check_PHP_time_limit',
|
85 |
),
|
|
|
|
|
|
|
|
|
|
|
86 |
array(
|
87 |
+
'name' => __( 'W3 Total Cache DB Cache', 'printful' ),
|
88 |
+
'description' => __( 'If you are using W3 Total Cache, the database caching feature needs to be disabled since it can cause issues with product push to store.', 'printful' ),
|
89 |
'method' => 'check_W3_db_cache',
|
90 |
'silent' => true,
|
91 |
),
|
92 |
array(
|
93 |
+
'name' => __( 'WP SpamShield', 'printful' ),
|
94 |
+
'description' => __( 'If you are using WP SpamShield, you might experience problems connecting to Printful and pushing products.', 'printful' ),
|
95 |
'method' => 'check_wp_spamshield',
|
96 |
'silent' => true,
|
97 |
),
|
98 |
array(
|
99 |
+
'name' => __( 'Remove Print Aura plugin', 'printful' ),
|
100 |
+
'description' => __( 'Print Aura plugin is known to cause issues so it needs to be removed.', 'printful' ),
|
101 |
'method' => 'check_printaura_plugin',
|
102 |
'silent' => true,
|
103 |
),
|
161 |
* @param bool $only_cached_results
|
162 |
* @return array
|
163 |
*/
|
164 |
+
public static function get_checklist( $only_cached_results = false ) {
|
165 |
|
166 |
$status = self::instance();
|
167 |
|
168 |
+
$list = get_transient( Printful_Admin_Status::PF_CACHED_CHECKLIST );
|
169 |
|
170 |
if ( $only_cached_results || $list ) {
|
171 |
return $list;
|
459 |
*/
|
460 |
private function check_WC_API_enabled() {
|
461 |
|
462 |
+
$enabled = get_option( 'woocommerce_api_enabled', false );
|
463 |
|
464 |
+
if ( $enabled == 'yes' ) {
|
465 |
return self::PF_STATUS_OK;
|
466 |
}
|
467 |
|
564 |
|
565 |
return self::PF_STATUS_FAIL;
|
566 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
567 |
}
|
includes/class-printful-admin.php
CHANGED
@@ -19,11 +19,11 @@ class Printful_Admin {
|
|
19 |
*/
|
20 |
public function register_admin() {
|
21 |
|
22 |
-
add_action( 'admin_menu', array($this, 'register_admin_menu_page'));
|
23 |
-
add_action( 'admin_enqueue_scripts', array($this, 'add_admin_styles'));
|
24 |
-
add_action( 'admin_enqueue_scripts', array($this, 'add_admin_scripts'));
|
25 |
-
add_action( 'wp_enqueue_scripts', array($this, 'add_global_style'));
|
26 |
-
add_action( 'admin_bar_menu', array($this, 'add_printful_status_toolbar'), 999 );
|
27 |
}
|
28 |
|
29 |
/**
|
@@ -70,7 +70,7 @@ class Printful_Admin {
|
|
70 |
public function register_admin_menu_page() {
|
71 |
|
72 |
add_menu_page(
|
73 |
-
__('Dashboard', 'printful'),
|
74 |
self::MENU_TITLE_TOP,
|
75 |
self::CAPABILITY,
|
76 |
self::MENU_SLUG_DASHBOARD,
|
@@ -98,10 +98,11 @@ class Printful_Admin {
|
|
98 |
}
|
99 |
}
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
105 |
public static function get_tabs() {
|
106 |
|
107 |
$tabs = array(
|
19 |
*/
|
20 |
public function register_admin() {
|
21 |
|
22 |
+
add_action( 'admin_menu', array( $this, 'register_admin_menu_page' ) );
|
23 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_styles' ) );
|
24 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts' ) );
|
25 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'add_global_style' ) );
|
26 |
+
add_action( 'admin_bar_menu', array( $this, 'add_printful_status_toolbar' ), 999 );
|
27 |
}
|
28 |
|
29 |
/**
|
70 |
public function register_admin_menu_page() {
|
71 |
|
72 |
add_menu_page(
|
73 |
+
__( 'Dashboard', 'printful' ),
|
74 |
self::MENU_TITLE_TOP,
|
75 |
self::CAPABILITY,
|
76 |
self::MENU_SLUG_DASHBOARD,
|
98 |
}
|
99 |
}
|
100 |
|
101 |
+
/**
|
102 |
+
* Get the tabs used in printful admin pages
|
103 |
+
* @return array
|
104 |
+
* @throws PrintfulException
|
105 |
+
*/
|
106 |
public static function get_tabs() {
|
107 |
|
108 |
$tabs = array(
|
includes/class-printful-api-resource.php
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
<?php
|
2 |
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
|
|
|
|
|
|
|
|
|
4 |
class Printful_API_Resource extends WC_API_Resource {
|
5 |
|
6 |
/** @var string $base the route base */
|
1 |
<?php
|
2 |
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
|
4 |
+
/**
|
5 |
+
* Class Printful_API_Resource
|
6 |
+
* @deprecated 2.0.3
|
7 |
+
*/
|
8 |
class Printful_API_Resource extends WC_API_Resource {
|
9 |
|
10 |
/** @var string $base the route base */
|
includes/class-printful-carriers.php
CHANGED
@@ -77,7 +77,7 @@ class Printful_Carriers {
|
|
77 |
$shipping->update_carrier_cache( $carriers );
|
78 |
} catch ( PrintfulApiException $e ) {
|
79 |
$carriers = false;
|
80 |
-
} catch (PrintfulException $e) {
|
81 |
$carriers = false;
|
82 |
}
|
83 |
|
77 |
$shipping->update_carrier_cache( $carriers );
|
78 |
} catch ( PrintfulApiException $e ) {
|
79 |
$carriers = false;
|
80 |
+
} catch ( PrintfulException $e ) {
|
81 |
$carriers = false;
|
82 |
}
|
83 |
|
includes/class-printful-integration.php
CHANGED
@@ -20,9 +20,10 @@ class Printful_Integration
|
|
20 |
self::$_instance = $this;
|
21 |
}
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
public function get_client() {
|
27 |
|
28 |
require_once 'class-printful-client.php';
|
@@ -31,17 +32,18 @@ class Printful_Integration
|
|
31 |
return $client;
|
32 |
}
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
$api_key = $this->get_option( 'printful_key' );
|
42 |
|
43 |
//dont need to show error - the plugin is simply not setup
|
44 |
-
if ( empty( $api_key )) {
|
45 |
return false;
|
46 |
}
|
47 |
|
@@ -51,6 +53,7 @@ class Printful_Integration
|
|
51 |
$settings_url = admin_url( 'admin.php?page=printful-dashboard&tab=settings' );
|
52 |
$printful_url = Printful_Base::get_printful_host() . 'dashboard/';
|
53 |
$this->set_connect_error(sprintf( $message, $settings_url, $printful_url ) );
|
|
|
54 |
return false;
|
55 |
}
|
56 |
|
@@ -59,6 +62,7 @@ class Printful_Integration
|
|
59 |
$connected = get_transient( self::PF_API_CONNECT_STATUS );
|
60 |
if ( $connected && $connected['status'] == 1 ) {
|
61 |
$this->clear_connect_error();
|
|
|
62 |
return true;
|
63 |
} else if ( $connected && $connected['status'] == 0 ) { //try again in a minute
|
64 |
return false;
|
@@ -106,30 +110,32 @@ class Printful_Integration
|
|
106 |
* @param string $error
|
107 |
*/
|
108 |
public function set_connect_error($error = '') {
|
109 |
-
update_option(self::PF_CONNECT_ERROR, $error);
|
110 |
}
|
111 |
|
112 |
/**
|
113 |
* Get current connect error message
|
114 |
*/
|
115 |
public function get_connect_error() {
|
116 |
-
return get_option(self::PF_CONNECT_ERROR, false);
|
117 |
}
|
118 |
|
119 |
/**
|
120 |
* Remove option used for storing current connect error
|
121 |
*/
|
122 |
public function clear_connect_error() {
|
123 |
-
delete_option(self::PF_CONNECT_ERROR);
|
124 |
}
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
129 |
public static function ajax_force_check_connect_status() {
|
130 |
if ( Printful_Integration::instance()->is_connected( true ) ) {
|
131 |
die( 'OK' );
|
132 |
}
|
|
|
133 |
die( 'FAIL' );
|
134 |
}
|
135 |
|
@@ -139,11 +145,12 @@ class Printful_Integration
|
|
139 |
* @param array $default
|
140 |
* @return bool
|
141 |
*/
|
142 |
-
public function get_option($name, $default = array()) {
|
143 |
$options = get_option( 'woocommerce_printful_settings', $default );
|
144 |
if ( ! empty( $options[ $name ] ) ) {
|
145 |
return $options[ $name ];
|
146 |
}
|
|
|
147 |
return false;
|
148 |
}
|
149 |
|
20 |
self::$_instance = $this;
|
21 |
}
|
22 |
|
23 |
+
/**
|
24 |
+
* @return Printful_Client
|
25 |
+
* @throws PrintfulException
|
26 |
+
*/
|
27 |
public function get_client() {
|
28 |
|
29 |
require_once 'class-printful-client.php';
|
32 |
return $client;
|
33 |
}
|
34 |
|
35 |
+
/**
|
36 |
+
* Check if the connection to printful is working
|
37 |
+
* @param bool $force
|
38 |
+
* @return bool
|
39 |
+
* @throws PrintfulException
|
40 |
+
*/
|
41 |
+
public function is_connected( $force = false ) {
|
42 |
|
43 |
$api_key = $this->get_option( 'printful_key' );
|
44 |
|
45 |
//dont need to show error - the plugin is simply not setup
|
46 |
+
if ( empty( $api_key ) ) {
|
47 |
return false;
|
48 |
}
|
49 |
|
53 |
$settings_url = admin_url( 'admin.php?page=printful-dashboard&tab=settings' );
|
54 |
$printful_url = Printful_Base::get_printful_host() . 'dashboard/';
|
55 |
$this->set_connect_error(sprintf( $message, $settings_url, $printful_url ) );
|
56 |
+
|
57 |
return false;
|
58 |
}
|
59 |
|
62 |
$connected = get_transient( self::PF_API_CONNECT_STATUS );
|
63 |
if ( $connected && $connected['status'] == 1 ) {
|
64 |
$this->clear_connect_error();
|
65 |
+
|
66 |
return true;
|
67 |
} else if ( $connected && $connected['status'] == 0 ) { //try again in a minute
|
68 |
return false;
|
110 |
* @param string $error
|
111 |
*/
|
112 |
public function set_connect_error($error = '') {
|
113 |
+
update_option( self::PF_CONNECT_ERROR, $error );
|
114 |
}
|
115 |
|
116 |
/**
|
117 |
* Get current connect error message
|
118 |
*/
|
119 |
public function get_connect_error() {
|
120 |
+
return get_option( self::PF_CONNECT_ERROR, false );
|
121 |
}
|
122 |
|
123 |
/**
|
124 |
* Remove option used for storing current connect error
|
125 |
*/
|
126 |
public function clear_connect_error() {
|
127 |
+
delete_option( self::PF_CONNECT_ERROR );
|
128 |
}
|
129 |
|
130 |
+
/**
|
131 |
+
* AJAX call endpoint for connect status check
|
132 |
+
* @throws PrintfulException
|
133 |
+
*/
|
134 |
public static function ajax_force_check_connect_status() {
|
135 |
if ( Printful_Integration::instance()->is_connected( true ) ) {
|
136 |
die( 'OK' );
|
137 |
}
|
138 |
+
|
139 |
die( 'FAIL' );
|
140 |
}
|
141 |
|
145 |
* @param array $default
|
146 |
* @return bool
|
147 |
*/
|
148 |
+
public function get_option( $name, $default = array() ) {
|
149 |
$options = get_option( 'woocommerce_printful_settings', $default );
|
150 |
if ( ! empty( $options[ $name ] ) ) {
|
151 |
return $options[ $name ];
|
152 |
}
|
153 |
+
|
154 |
return false;
|
155 |
}
|
156 |
|
includes/class-printful-request-log.php
CHANGED
@@ -13,7 +13,7 @@ class Printful_Request_log {
|
|
13 |
public static function init() {
|
14 |
$printful_log = new self;
|
15 |
add_filter( 'woocommerce_api_serve_request', array( $printful_log, 'log_incoming_printful_api_requests' ), 10, 3 );
|
16 |
-
add_filter
|
17 |
}
|
18 |
|
19 |
/**
|
@@ -60,6 +60,8 @@ class Printful_Request_log {
|
|
60 |
|
61 |
$original_result = $result;
|
62 |
$request['path'] = $url;
|
|
|
|
|
63 |
|
64 |
if ( ! is_wp_error( $result ) ) {
|
65 |
$result = json_decode( $result['body'], true );
|
@@ -76,9 +78,9 @@ class Printful_Request_log {
|
|
76 |
$response_hash = md5( serialize( array( 'request' => $request, 'results' => $result ) ) );
|
77 |
|
78 |
//save summary in database to be easily accessible for status page
|
79 |
-
$this->save_to_printful_log( $method . ' ' . $url, $result, $response_hash, self::PF_OPTION_OUTGOING_API_REQUEST_LOG);
|
80 |
|
81 |
-
return $original_result;
|
82 |
}
|
83 |
|
84 |
/**
|
@@ -89,7 +91,7 @@ class Printful_Request_log {
|
|
89 |
* @param string $context
|
90 |
* @return bool
|
91 |
*/
|
92 |
-
private function save_to_wc_log( $request, $result, $context) {
|
93 |
|
94 |
if ( ! function_exists( 'wc_get_logger' ) ) {
|
95 |
return false;
|
@@ -102,6 +104,8 @@ class Printful_Request_log {
|
|
102 |
'results' => (array) $result,
|
103 |
);
|
104 |
$logger->error( wc_print_r( $log_item, true ), $context );
|
|
|
|
|
105 |
}
|
106 |
|
107 |
/**
|
13 |
public static function init() {
|
14 |
$printful_log = new self;
|
15 |
add_filter( 'woocommerce_api_serve_request', array( $printful_log, 'log_incoming_printful_api_requests' ), 10, 3 );
|
16 |
+
add_filter( 'printful_api_result', array( $printful_log, 'log_outgoing_printful_api_requests'), 10, 4 );
|
17 |
}
|
18 |
|
19 |
/**
|
60 |
|
61 |
$original_result = $result;
|
62 |
$request['path'] = $url;
|
63 |
+
$params_set = null;
|
64 |
+
$code_success = null;
|
65 |
|
66 |
if ( ! is_wp_error( $result ) ) {
|
67 |
$result = json_decode( $result['body'], true );
|
78 |
$response_hash = md5( serialize( array( 'request' => $request, 'results' => $result ) ) );
|
79 |
|
80 |
//save summary in database to be easily accessible for status page
|
81 |
+
$this->save_to_printful_log( $method . ' ' . $url, $result, $response_hash, self::PF_OPTION_OUTGOING_API_REQUEST_LOG );
|
82 |
|
83 |
+
return $original_result; //don't change the result
|
84 |
}
|
85 |
|
86 |
/**
|
91 |
* @param string $context
|
92 |
* @return bool
|
93 |
*/
|
94 |
+
private function save_to_wc_log( $request, $result, $context ) {
|
95 |
|
96 |
if ( ! function_exists( 'wc_get_logger' ) ) {
|
97 |
return false;
|
104 |
'results' => (array) $result,
|
105 |
);
|
106 |
$logger->error( wc_print_r( $log_item, true ), $context );
|
107 |
+
|
108 |
+
return true;
|
109 |
}
|
110 |
|
111 |
/**
|
includes/{class-printful-rest-api.php → class-printful-rest-api-controller.php}
RENAMED
@@ -3,16 +3,31 @@
|
|
3 |
/**
|
4 |
* API class
|
5 |
*/
|
6 |
-
class
|
7 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
/**
|
9 |
* Register the REST API routes.
|
10 |
*/
|
11 |
-
public
|
12 |
-
register_rest_route('
|
13 |
array(
|
14 |
'methods' => WP_REST_Server::EDITABLE,
|
15 |
-
'callback' => array(
|
|
|
16 |
'args' => array(
|
17 |
'accessKey' => array(
|
18 |
'required' => false,
|
@@ -28,10 +43,11 @@ class Printful_REST_API
|
|
28 |
)
|
29 |
) );
|
30 |
|
31 |
-
register_rest_route('
|
32 |
array(
|
33 |
'methods' => WP_REST_Server::EDITABLE,
|
34 |
-
'callback' => array(
|
|
|
35 |
'args' => array(
|
36 |
'product_id' => array(
|
37 |
'description' => __( 'Unique identifier for the resource.', 'printful' ),
|
@@ -46,17 +62,19 @@ class Printful_REST_API
|
|
46 |
)
|
47 |
) );
|
48 |
|
49 |
-
register_rest_route('
|
50 |
array(
|
51 |
'methods' => WP_REST_Server::READABLE,
|
52 |
-
'
|
|
|
53 |
)
|
54 |
) );
|
55 |
|
56 |
-
register_rest_route('
|
57 |
array(
|
58 |
'methods' => WP_REST_Server::READABLE,
|
59 |
-
'
|
|
|
60 |
)
|
61 |
) );
|
62 |
}
|
@@ -131,11 +149,10 @@ class Printful_REST_API
|
|
131 |
* Allow remotely get plugin version for debug purposes
|
132 |
*/
|
133 |
public static function get_version() {
|
134 |
-
|
135 |
$error = false;
|
136 |
|
137 |
try {
|
138 |
-
$client
|
139 |
$store_data = $client->get( 'store' );
|
140 |
} catch ( Exception $exception ) {
|
141 |
$error = $exception->getMessage();
|
@@ -177,4 +194,35 @@ class Printful_REST_API
|
|
177 |
'name' => get_bloginfo( 'title', 'display' )
|
178 |
);
|
179 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
}
|
3 |
/**
|
4 |
* API class
|
5 |
*/
|
6 |
+
class Printful_REST_API_Controller extends WC_REST_Controller
|
7 |
{
|
8 |
+
/**
|
9 |
+
* Endpoint namespace.
|
10 |
+
*
|
11 |
+
* @var string
|
12 |
+
*/
|
13 |
+
protected $namespace = 'wc/v2';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Route base.
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
protected $rest_base = 'printful';
|
21 |
+
|
22 |
/**
|
23 |
* Register the REST API routes.
|
24 |
*/
|
25 |
+
public function register_routes() {
|
26 |
+
register_rest_route( $this->namespace, '/' . $this->rest_base . '/access', array(
|
27 |
array(
|
28 |
'methods' => WP_REST_Server::EDITABLE,
|
29 |
+
'callback' => array( $this, 'set_printful_access' ),
|
30 |
+
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
31 |
'args' => array(
|
32 |
'accessKey' => array(
|
33 |
'required' => false,
|
43 |
)
|
44 |
) );
|
45 |
|
46 |
+
register_rest_route( $this->namespace, '/' . $this->rest_base . '/products/(?P<product_id>\d+)/size-chart', array(
|
47 |
array(
|
48 |
'methods' => WP_REST_Server::EDITABLE,
|
49 |
+
'callback' => array( $this, 'post_size_guide' ),
|
50 |
+
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
51 |
'args' => array(
|
52 |
'product_id' => array(
|
53 |
'description' => __( 'Unique identifier for the resource.', 'printful' ),
|
62 |
)
|
63 |
) );
|
64 |
|
65 |
+
register_rest_route( $this->namespace, '/' . $this->rest_base . '/version', array(
|
66 |
array(
|
67 |
'methods' => WP_REST_Server::READABLE,
|
68 |
+
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
69 |
+
'callback' => array( $this, 'get_version' ),
|
70 |
)
|
71 |
) );
|
72 |
|
73 |
+
register_rest_route( $this->namespace, '/' . $this->rest_base . '/store_data', array(
|
74 |
array(
|
75 |
'methods' => WP_REST_Server::READABLE,
|
76 |
+
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
77 |
+
'callback' => array( $this, 'get_store_data' ),
|
78 |
)
|
79 |
) );
|
80 |
}
|
149 |
* Allow remotely get plugin version for debug purposes
|
150 |
*/
|
151 |
public static function get_version() {
|
|
|
152 |
$error = false;
|
153 |
|
154 |
try {
|
155 |
+
$client = Printful_Integration::instance()->get_client();
|
156 |
$store_data = $client->get( 'store' );
|
157 |
} catch ( Exception $exception ) {
|
158 |
$error = $exception->getMessage();
|
194 |
'name' => get_bloginfo( 'title', 'display' )
|
195 |
);
|
196 |
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Check whether a given request has permission to read printful endpoints.
|
200 |
+
*
|
201 |
+
* @param WP_REST_Request $request Full details about the request.
|
202 |
+
* @return WP_Error|boolean
|
203 |
+
*/
|
204 |
+
public function get_items_permissions_check( $request ) {
|
205 |
+
if ( ! wc_rest_check_user_permissions( 'read' ) ) {
|
206 |
+
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
|
207 |
+
}
|
208 |
+
|
209 |
+
return true;
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Check if a given request has access to update a product.
|
214 |
+
*
|
215 |
+
* @param WP_REST_Request $request Full details about the request.
|
216 |
+
* @return WP_Error|boolean
|
217 |
+
*/
|
218 |
+
public function update_item_permissions_check( $request ) {
|
219 |
+
$params = $request->get_url_params();
|
220 |
+
$post = get_post( (int) $params['product_id'] );
|
221 |
+
|
222 |
+
if ( $post && ! wc_rest_check_post_permissions( 'product', 'edit', $post->ID ) ) {
|
223 |
+
return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
|
224 |
+
}
|
225 |
+
|
226 |
+
return true;
|
227 |
+
}
|
228 |
}
|
includes/class-printful-shipping.php
CHANGED
@@ -84,6 +84,7 @@ class Printful_Shipping extends WC_Shipping_Method
|
|
84 |
public function woocommerce_load_shipping_methods( $package = array() ) {
|
85 |
|
86 |
$this->printful_package = false;
|
|
|
87 |
if ( $package && ! empty( $package['printful'] ) ) {
|
88 |
if ( $this->enabled == 'yes' ) {
|
89 |
$this->printful_package = true;
|
@@ -123,7 +124,6 @@ class Printful_Shipping extends WC_Shipping_Method
|
|
123 |
* @return array
|
124 |
*/
|
125 |
public function woocommerce_cart_shipping_packages( $packages = array() ) {
|
126 |
-
|
127 |
//Printful rates are turned off, do not split products
|
128 |
if ( $this->enabled !== 'yes' ) {
|
129 |
return $packages;
|
@@ -132,7 +132,6 @@ class Printful_Shipping extends WC_Shipping_Method
|
|
132 |
$return_packages = array();
|
133 |
|
134 |
foreach ( $packages as $package ) {
|
135 |
-
|
136 |
$ids = array();
|
137 |
foreach ( $package['contents'] as $key => $item ) {
|
138 |
$ids[ $key ] = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
|
@@ -223,7 +222,6 @@ class Printful_Shipping extends WC_Shipping_Method
|
|
223 |
* @return bool
|
224 |
*/
|
225 |
public function calculate_shipping( $package = array() ) {
|
226 |
-
|
227 |
$request = array(
|
228 |
'recipient' => array(
|
229 |
'address1' => $package['destination']['address'],
|
@@ -308,7 +306,6 @@ class Printful_Shipping extends WC_Shipping_Method
|
|
308 |
* @param $error
|
309 |
*/
|
310 |
private function set_error( $error ) {
|
311 |
-
|
312 |
if ( $this->show_warnings ) {
|
313 |
$this->last_error = $error;
|
314 |
add_filter( 'woocommerce_cart_no_shipping_available_html', array( $this, 'show_error' ) );
|
@@ -322,9 +319,9 @@ class Printful_Shipping extends WC_Shipping_Method
|
|
322 |
* @return string
|
323 |
*/
|
324 |
public function show_error( $data ) {
|
325 |
-
|
326 |
$error = $this->last_error;
|
327 |
$message = $error->getMessage();
|
|
|
328 |
if ( $error instanceof PrintfulApiException && $error->getCode() == 401 ) {
|
329 |
$message = 'Invalid API key';
|
330 |
}
|
84 |
public function woocommerce_load_shipping_methods( $package = array() ) {
|
85 |
|
86 |
$this->printful_package = false;
|
87 |
+
|
88 |
if ( $package && ! empty( $package['printful'] ) ) {
|
89 |
if ( $this->enabled == 'yes' ) {
|
90 |
$this->printful_package = true;
|
124 |
* @return array
|
125 |
*/
|
126 |
public function woocommerce_cart_shipping_packages( $packages = array() ) {
|
|
|
127 |
//Printful rates are turned off, do not split products
|
128 |
if ( $this->enabled !== 'yes' ) {
|
129 |
return $packages;
|
132 |
$return_packages = array();
|
133 |
|
134 |
foreach ( $packages as $package ) {
|
|
|
135 |
$ids = array();
|
136 |
foreach ( $package['contents'] as $key => $item ) {
|
137 |
$ids[ $key ] = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
|
222 |
* @return bool
|
223 |
*/
|
224 |
public function calculate_shipping( $package = array() ) {
|
|
|
225 |
$request = array(
|
226 |
'recipient' => array(
|
227 |
'address1' => $package['destination']['address'],
|
306 |
* @param $error
|
307 |
*/
|
308 |
private function set_error( $error ) {
|
|
|
309 |
if ( $this->show_warnings ) {
|
310 |
$this->last_error = $error;
|
311 |
add_filter( 'woocommerce_cart_no_shipping_available_html', array( $this, 'show_error' ) );
|
319 |
* @return string
|
320 |
*/
|
321 |
public function show_error( $data ) {
|
|
|
322 |
$error = $this->last_error;
|
323 |
$message = $error->getMessage();
|
324 |
+
|
325 |
if ( $error instanceof PrintfulApiException && $error->getCode() == 401 ) {
|
326 |
$message = 'Invalid API key';
|
327 |
}
|
includes/class-printful-size-chart-tab.php
CHANGED
@@ -16,7 +16,7 @@ class Printful_Size_Chart_Tab {
|
|
16 |
public static function init() {
|
17 |
$size_chart = new self;
|
18 |
add_filter( 'woocommerce_product_tabs', array( $size_chart, 'init_size_chart_tab' ) );
|
19 |
-
add_action( 'add_meta_boxes', array($size_chart, 'init_metabox'));
|
20 |
add_action( 'save_post', array( $size_chart, 'save_size_chart' ), 1, 2 );
|
21 |
}
|
22 |
|
@@ -24,7 +24,7 @@ class Printful_Size_Chart_Tab {
|
|
24 |
* Initialize meta boxes
|
25 |
*/
|
26 |
public function init_metabox() {
|
27 |
-
add_meta_box( 'pf_size_chart', __( 'Size chart', 'printful' ), array($this, 'size_chart_metabox'), 'product', 'normal' );
|
28 |
}
|
29 |
|
30 |
/**
|
@@ -33,7 +33,6 @@ class Printful_Size_Chart_Tab {
|
|
33 |
* @return mixed
|
34 |
*/
|
35 |
public function init_size_chart_tab( $tabs ) {
|
36 |
-
|
37 |
if ( strlen( $this->get_size_chart_content() ) > 0 ) {
|
38 |
$tabs['size_chart'] = array(
|
39 |
'title' => __( 'Size Chart', 'printful' ),
|
@@ -49,7 +48,6 @@ class Printful_Size_Chart_Tab {
|
|
49 |
* Display the size chart content
|
50 |
*/
|
51 |
public function size_chart_tab_content() {
|
52 |
-
|
53 |
echo '<h2>' . esc_html__( 'Size Chart', 'printful' ) . '</h2>';
|
54 |
echo $this->get_size_chart_content();
|
55 |
}
|
@@ -58,8 +56,8 @@ class Printful_Size_Chart_Tab {
|
|
58 |
* @return mixed
|
59 |
*/
|
60 |
public function get_size_chart_content() {
|
61 |
-
|
62 |
global $post;
|
|
|
63 |
return htmlspecialchars_decode(get_post_meta( $post->ID, 'pf_size_chart', true ));
|
64 |
}
|
65 |
|
@@ -67,7 +65,6 @@ class Printful_Size_Chart_Tab {
|
|
67 |
* @param $meta_id
|
68 |
*/
|
69 |
public function size_chart_metabox( $meta_id ) {
|
70 |
-
|
71 |
$settings = array(
|
72 |
'textarea_name' => 'pf_size_chart',
|
73 |
'tinymce' => array(
|
@@ -86,7 +83,7 @@ class Printful_Size_Chart_Tab {
|
|
86 |
* @param $post_id
|
87 |
* @param $post
|
88 |
*/
|
89 |
-
public function save_size_chart($post_id, $post ) {
|
90 |
|
91 |
// $post_id and $post are required
|
92 |
if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
|
16 |
public static function init() {
|
17 |
$size_chart = new self;
|
18 |
add_filter( 'woocommerce_product_tabs', array( $size_chart, 'init_size_chart_tab' ) );
|
19 |
+
add_action( 'add_meta_boxes', array( $size_chart, 'init_metabox' ) );
|
20 |
add_action( 'save_post', array( $size_chart, 'save_size_chart' ), 1, 2 );
|
21 |
}
|
22 |
|
24 |
* Initialize meta boxes
|
25 |
*/
|
26 |
public function init_metabox() {
|
27 |
+
add_meta_box( 'pf_size_chart', __( 'Size chart', 'printful' ), array( $this, 'size_chart_metabox' ), 'product', 'normal' );
|
28 |
}
|
29 |
|
30 |
/**
|
33 |
* @return mixed
|
34 |
*/
|
35 |
public function init_size_chart_tab( $tabs ) {
|
|
|
36 |
if ( strlen( $this->get_size_chart_content() ) > 0 ) {
|
37 |
$tabs['size_chart'] = array(
|
38 |
'title' => __( 'Size Chart', 'printful' ),
|
48 |
* Display the size chart content
|
49 |
*/
|
50 |
public function size_chart_tab_content() {
|
|
|
51 |
echo '<h2>' . esc_html__( 'Size Chart', 'printful' ) . '</h2>';
|
52 |
echo $this->get_size_chart_content();
|
53 |
}
|
56 |
* @return mixed
|
57 |
*/
|
58 |
public function get_size_chart_content() {
|
|
|
59 |
global $post;
|
60 |
+
|
61 |
return htmlspecialchars_decode(get_post_meta( $post->ID, 'pf_size_chart', true ));
|
62 |
}
|
63 |
|
65 |
* @param $meta_id
|
66 |
*/
|
67 |
public function size_chart_metabox( $meta_id ) {
|
|
|
68 |
$settings = array(
|
69 |
'textarea_name' => 'pf_size_chart',
|
70 |
'tinymce' => array(
|
83 |
* @param $post_id
|
84 |
* @param $post
|
85 |
*/
|
86 |
+
public function save_size_chart( $post_id, $post ) {
|
87 |
|
88 |
// $post_id and $post are required
|
89 |
if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
|
includes/class-printful-taxes.php
CHANGED
@@ -7,7 +7,6 @@ class Printful_Taxes {
|
|
7 |
* Initialize the values, hooks and actions
|
8 |
*/
|
9 |
public static function init() {
|
10 |
-
|
11 |
if ( Printful_Integration::instance()->get_option( 'calculate_tax' ) == 'yes' ) {
|
12 |
//Update tax options if taxes are enabled
|
13 |
if ( get_option( 'woocommerce_calc_taxes' ) != 'yes' ) {
|
@@ -19,7 +18,7 @@ class Printful_Taxes {
|
|
19 |
|
20 |
//Override tax rates calculated by Woocommerce
|
21 |
$taxes = new self;
|
22 |
-
add_filter( 'woocommerce_matched_tax_rates', array($taxes, 'calculate_tax' ), 10, 6 );
|
23 |
}
|
24 |
}
|
25 |
|
@@ -34,7 +33,6 @@ class Printful_Taxes {
|
|
34 |
* @return mixed
|
35 |
*/
|
36 |
public function calculate_tax( $matched_tax_rates, $country, $state, $postcode, $city, $tax_class ) {
|
37 |
-
|
38 |
//if a tax rate is already matched, avoid adding extra one
|
39 |
if ( ! empty( $matched_tax_rates ) ) {
|
40 |
return $matched_tax_rates;
|
@@ -44,6 +42,8 @@ class Printful_Taxes {
|
|
44 |
if ( isset( $countries[ $country ][ $state ] ) && !empty($postcode) ) { //only make the request if country, state and zip are set
|
45 |
$key = 'printful_tax_rate_' . $country . '-' . $state . '-' . $city . '-' . $postcode;
|
46 |
$rate = get_transient( $key );
|
|
|
|
|
47 |
if ( $rate === false ) {
|
48 |
try {
|
49 |
$client = Printful_Integration::instance()->get_client();
|
@@ -97,7 +97,6 @@ class Printful_Taxes {
|
|
97 |
* @return bool
|
98 |
*/
|
99 |
private function isRateUnique( $rate, $matched_tax_rates ) {
|
100 |
-
|
101 |
if ( empty( $matched_tax_rates ) ) {
|
102 |
return true;
|
103 |
}
|
@@ -116,10 +115,11 @@ class Printful_Taxes {
|
|
116 |
* @return array|mixed
|
117 |
*/
|
118 |
private function get_tax_countries() {
|
119 |
-
|
120 |
$countries = get_transient( 'printful_tax_countries' );
|
|
|
121 |
if ( ! $countries ) {
|
122 |
$countries = array();
|
|
|
123 |
try {
|
124 |
$client = Printful_Integration::instance()->get_client();
|
125 |
$list = $client->get( 'tax/countries' );
|
@@ -129,6 +129,7 @@ class Printful_Taxes {
|
|
129 |
$countries[ $country['code'] ][ $state['code'] ] = 1;
|
130 |
}
|
131 |
}
|
|
|
132 |
if ( ! empty( $countries ) ) {
|
133 |
set_transient( 'printful_tax_countries', $countries, 6 * 3600 );
|
134 |
}
|
@@ -156,7 +157,7 @@ class Printful_Taxes {
|
|
156 |
$includeShipping = (int) $includeShipping;
|
157 |
|
158 |
$states = WC()->countries->get_states( $cc );
|
159 |
-
$tax_title = ( isset( $states[ $state ] ) ? $states[ $state ] . ' ' : '' ) . 'Sales Tax';
|
160 |
$id = $wpdb->get_var(
|
161 |
$wpdb->prepare( "SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class='printful'
|
162 |
and tax_rate_country = %s AND tax_rate_state = %s AND tax_rate_shipping = %s LIMIT 1",
|
7 |
* Initialize the values, hooks and actions
|
8 |
*/
|
9 |
public static function init() {
|
|
|
10 |
if ( Printful_Integration::instance()->get_option( 'calculate_tax' ) == 'yes' ) {
|
11 |
//Update tax options if taxes are enabled
|
12 |
if ( get_option( 'woocommerce_calc_taxes' ) != 'yes' ) {
|
18 |
|
19 |
//Override tax rates calculated by Woocommerce
|
20 |
$taxes = new self;
|
21 |
+
add_filter( 'woocommerce_matched_tax_rates', array( $taxes, 'calculate_tax' ), 10, 6 );
|
22 |
}
|
23 |
}
|
24 |
|
33 |
* @return mixed
|
34 |
*/
|
35 |
public function calculate_tax( $matched_tax_rates, $country, $state, $postcode, $city, $tax_class ) {
|
|
|
36 |
//if a tax rate is already matched, avoid adding extra one
|
37 |
if ( ! empty( $matched_tax_rates ) ) {
|
38 |
return $matched_tax_rates;
|
42 |
if ( isset( $countries[ $country ][ $state ] ) && !empty($postcode) ) { //only make the request if country, state and zip are set
|
43 |
$key = 'printful_tax_rate_' . $country . '-' . $state . '-' . $city . '-' . $postcode;
|
44 |
$rate = get_transient( $key );
|
45 |
+
$response = null;
|
46 |
+
|
47 |
if ( $rate === false ) {
|
48 |
try {
|
49 |
$client = Printful_Integration::instance()->get_client();
|
97 |
* @return bool
|
98 |
*/
|
99 |
private function isRateUnique( $rate, $matched_tax_rates ) {
|
|
|
100 |
if ( empty( $matched_tax_rates ) ) {
|
101 |
return true;
|
102 |
}
|
115 |
* @return array|mixed
|
116 |
*/
|
117 |
private function get_tax_countries() {
|
|
|
118 |
$countries = get_transient( 'printful_tax_countries' );
|
119 |
+
|
120 |
if ( ! $countries ) {
|
121 |
$countries = array();
|
122 |
+
|
123 |
try {
|
124 |
$client = Printful_Integration::instance()->get_client();
|
125 |
$list = $client->get( 'tax/countries' );
|
129 |
$countries[ $country['code'] ][ $state['code'] ] = 1;
|
130 |
}
|
131 |
}
|
132 |
+
|
133 |
if ( ! empty( $countries ) ) {
|
134 |
set_transient( 'printful_tax_countries', $countries, 6 * 3600 );
|
135 |
}
|
157 |
$includeShipping = (int) $includeShipping;
|
158 |
|
159 |
$states = WC()->countries->get_states( $cc );
|
160 |
+
$tax_title = ( isset( $states[ $state ] ) ? $states[ $state ] . ' ' : '' ) . __( 'Sales Tax', 'printful' );
|
161 |
$id = $wpdb->get_var(
|
162 |
$wpdb->prepare( "SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class='printful'
|
163 |
and tax_rate_country = %s AND tax_rate_state = %s AND tax_rate_shipping = %s LIMIT 1",
|
printful-shipping.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Printful Integration for WooCommerce
|
4 |
Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
|
5 |
Description: Calculate correct shipping and tax rates for your Printful-Woocommerce integration.
|
6 |
-
Version: 2.0.
|
7 |
Author: Printful
|
8 |
Author URI: http://www.printful.com
|
9 |
License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -20,7 +20,7 @@ if ( ! defined( 'PF_PLUGIN_FILE' ) ) {
|
|
20 |
|
21 |
class Printful_Base {
|
22 |
|
23 |
-
const VERSION = '2.0.
|
24 |
const PF_HOST = 'https://www.printful.com/';
|
25 |
const PF_API_HOST = 'https://api.printful.com/';
|
26 |
|
@@ -30,7 +30,9 @@ class Printful_Base {
|
|
30 |
public function __construct() {
|
31 |
add_action( 'plugins_loaded', array( $this, 'init' ) );
|
32 |
add_action( 'plugins_loaded', array( $this, 'printful_load_plugin_textdomain') );
|
33 |
-
|
|
|
|
|
34 |
}
|
35 |
|
36 |
/**
|
@@ -61,7 +63,7 @@ class Printful_Base {
|
|
61 |
require_once 'includes/class-printful-admin-support.php';
|
62 |
require_once 'includes/class-printful-size-chart-tab.php';
|
63 |
require_once 'includes/class-printful-size-chart-tab.php';
|
64 |
-
require_once 'includes/class-printful-rest-api.php';
|
65 |
|
66 |
//launch init
|
67 |
Printful_Taxes::init();
|
@@ -96,7 +98,8 @@ class Printful_Base {
|
|
96 |
*/
|
97 |
public function add_api_resource($endpoints) {
|
98 |
require_once 'includes/class-printful-api-resource.php';
|
99 |
-
$endpoints[]= 'Printful_API_Resource';
|
|
|
100 |
return $endpoints;
|
101 |
}
|
102 |
|
@@ -140,6 +143,22 @@ class Printful_Base {
|
|
140 |
return self::PF_API_HOST;
|
141 |
}
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
new Printful_Base(); //let's go
|
3 |
Plugin Name: Printful Integration for WooCommerce
|
4 |
Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
|
5 |
Description: Calculate correct shipping and tax rates for your Printful-Woocommerce integration.
|
6 |
+
Version: 2.0.7
|
7 |
Author: Printful
|
8 |
Author URI: http://www.printful.com
|
9 |
License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
|
20 |
|
21 |
class Printful_Base {
|
22 |
|
23 |
+
const VERSION = '2.0.7';
|
24 |
const PF_HOST = 'https://www.printful.com/';
|
25 |
const PF_API_HOST = 'https://api.printful.com/';
|
26 |
|
30 |
public function __construct() {
|
31 |
add_action( 'plugins_loaded', array( $this, 'init' ) );
|
32 |
add_action( 'plugins_loaded', array( $this, 'printful_load_plugin_textdomain') );
|
33 |
+
|
34 |
+
// WP REST API.
|
35 |
+
$this->rest_api_init();
|
36 |
}
|
37 |
|
38 |
/**
|
63 |
require_once 'includes/class-printful-admin-support.php';
|
64 |
require_once 'includes/class-printful-size-chart-tab.php';
|
65 |
require_once 'includes/class-printful-size-chart-tab.php';
|
66 |
+
require_once 'includes/class-printful-rest-api-controller.php';
|
67 |
|
68 |
//launch init
|
69 |
Printful_Taxes::init();
|
98 |
*/
|
99 |
public function add_api_resource($endpoints) {
|
100 |
require_once 'includes/class-printful-api-resource.php';
|
101 |
+
$endpoints[] = 'Printful_API_Resource';
|
102 |
+
|
103 |
return $endpoints;
|
104 |
}
|
105 |
|
143 |
return self::PF_API_HOST;
|
144 |
}
|
145 |
|
146 |
+
private function rest_api_init()
|
147 |
+
{
|
148 |
+
// REST API was included starting WordPress 4.4.
|
149 |
+
if ( ! class_exists( 'WP_REST_Server' ) ) {
|
150 |
+
return;
|
151 |
+
}
|
152 |
+
|
153 |
+
// Init REST API routes.
|
154 |
+
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ));
|
155 |
+
}
|
156 |
+
|
157 |
+
public function register_rest_routes()
|
158 |
+
{
|
159 |
+
$printfulRestAPIController = new Printful_REST_API_Controller();
|
160 |
+
$printfulRestAPIController->register_routes();
|
161 |
+
}
|
162 |
}
|
163 |
|
164 |
new Printful_Base(); //let's go
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: girts_u, kievins, kberzins
|
|
3 |
Tags: woocommerce, printful, drop shipping, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout, t-shirts
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 5.0
|
6 |
-
Stable tag: 2.0.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -38,6 +38,9 @@ Go to https://www.printful.com/dashboard/store , select your WooCommerce store,
|
|
38 |
|
39 |
== Upgrade Notice ==
|
40 |
|
|
|
|
|
|
|
41 |
= 2.0.6 =
|
42 |
Improvement support for WordPress 5.0 and fixed various minor issues
|
43 |
|
@@ -106,6 +109,9 @@ First release
|
|
106 |
|
107 |
== Changelog ==
|
108 |
|
|
|
|
|
|
|
109 |
= 2.0.6 =
|
110 |
* Improvement support for WordPress 5.0 and fixed various minor issues
|
111 |
|
3 |
Tags: woocommerce, printful, drop shipping, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout, t-shirts
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 5.0
|
6 |
+
Stable tag: 2.0.7
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
38 |
|
39 |
== Upgrade Notice ==
|
40 |
|
41 |
+
= 2.0.7 =
|
42 |
+
Bug fixes, security improvements and improved i18n support
|
43 |
+
|
44 |
= 2.0.6 =
|
45 |
Improvement support for WordPress 5.0 and fixed various minor issues
|
46 |
|
109 |
|
110 |
== Changelog ==
|
111 |
|
112 |
+
= 2.0.7 =
|
113 |
+
* Bug fixes, security improvements and improved i18n support
|
114 |
+
|
115 |
= 2.0.6 =
|
116 |
* Improvement support for WordPress 5.0 and fixed various minor issues
|
117 |
|