PluginProbe
Gift Up Gift Cards for WordPress and WooCommerce / trunk
Gift Up Gift Cards for WordPress and WooCommerce vtrunk
3.2.2 3.1.7 3.1.8 3.2 3.2.1 wp5.2 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2 1.2.1 1.2.2 1.2.3 1.2.4 All 131 releases
gift-up / includes / class-giftup-options.php

class-giftup-options.php in Gift Up Gift Cards for WordPress and WooCommerce trunk, at includes/class-giftup-options.php

124 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class GiftUp_Options
4 {
5 public function __construct()
6 {
7 $args = array(
8 'type' => 'string',
9 'show_in_rest' => true
10 );
11
12 register_setting( 'giftup', 'giftup_company_id', $args );
13 }
14
15 public function has_api_key() {
16 if ($this->get_api_key()) {
17 return true;
18 }
19
20 return false;
21 }
22
23 public function get_version() {
24 return $this->get_option( "version" );
25 }
26 public function set_version( $value ) {
27 return $this->update_option( "version", $value );
28 }
29
30 public function get_company_id() {
31 return $this->get_option( "company_id" );
32 }
33 public function set_company_id( $value ) {
34 return $this->update_option( "company_id", $value );
35 }
36
37 public function get_api_key() {
38 $key = $this->get_option( "api_key" );
39 return apply_filters('giftup_api_key', $key, 10);
40 }
41 public function set_api_key( $value ) {
42 return $this->update_option( "api_key", $value );
43 }
44
45 public function get_woocommerce_enabled() {
46 return $this->get_option( "woocommerce_enabled" );
47 }
48 public function set_woocommerce_enabled( $value ) {
49 return $this->update_option( "woocommerce_enabled", $value );
50 }
51
52 public function get_woocommerce_apply_to_shipping() {
53 return $this->get_option( "woocommerce_apply_to_shipping" );
54 }
55 public function set_woocommerce_apply_to_shipping( $value ) {
56 return $this->update_option( "woocommerce_apply_to_shipping", $value );
57 }
58
59 public function get_woocommerce_apply_to_taxes() {
60 return $this->get_option( "woocommerce_apply_to_taxes" );
61 }
62 public function set_woocommerce_apply_to_taxes( $value ) {
63 return $this->update_option( "woocommerce_apply_to_taxes", $value );
64 }
65
66 public function get_woocommerce_is_in_test_mode() {
67 return current_user_can('administrator') && isset($_COOKIE["giftup_test_mode"]) && $_COOKIE["giftup_test_mode"] == "test";
68 }
69
70 public function get_woocommerce_test_mode_cookie_set() {
71 return isset($_COOKIE["giftup_test_mode"]) && $_COOKIE["giftup_test_mode"] == "test";
72 }
73
74 public function get_woocommerce_diagnostics_mode() {
75 return isset($_COOKIE["giftup_diagnostics_mode"]) && $_COOKIE["giftup_diagnostics_mode"] == "on";
76 }
77
78 // Can be either 'DISCOUNT_COUPONS' or 'API'
79 public function get_woocommerce_operating_mode() {
80 $setting = $this->get_option( "woocommerce_operating_mode" );
81
82 if ($setting == null || strlen($setting) == 0) {
83 return GIFTUP_WOO_MODE_DISCOUNT_COUPONS;
84 }
85
86 return $setting;
87 }
88
89 public function set_woocommerce_operating_mode( $value ) {
90 return $this->update_option( "woocommerce_operating_mode", $value );
91 }
92
93 public function disconnect() {
94 GiftUp()->api->notify_disconnect_woocommerce();
95 GiftUp()->settings->delete_woocommerce_webhook();
96
97 delete_option( "giftup_company_id" );
98 delete_option( "giftup_api_key" );
99 delete_option( "giftup_version" );
100 delete_option( "giftup_woocommerce_operating_mode" );
101 delete_option( "giftup_woocommerce_enabled" );
102 delete_option( "giftup_woocommerce_apply_to_shipping" );
103 delete_option( "giftup_woocommerce_apply_to_taxes" );
104 }
105
106 public function upgrade_from_v1() {
107 // Fix options so that they have a giftup_ prefix due to a v1 plugin bug
108 if ( !get_option( "giftup_company_id" ) && get_option( "company_id" )) {
109 update_option( "giftup_company_id", get_option( "company_id" ));
110 delete_option( "company_id" );
111
112 update_option( "giftup_api_key", get_option( "api_key" ));
113 delete_option( "api_key" );
114 }
115 }
116
117 private function get_option( $option, $default = false ) {
118 return get_option( "giftup_$option", $default );
119 }
120 private function update_option( $option, $value ) {
121 return update_option( "giftup_$option", $value );
122 }
123 }
124