Passed
Pull Request — master (#377)
by Brian
06:57
created
includes/class-wpinv.php 1 patch
Spacing   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -33,35 +33,35 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
 
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array(&$this, 'wpinv_actions'));
48 48
         
49
-        if ( class_exists( 'BuddyPress' ) ) {
50
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
49
+        if (class_exists('BuddyPress')) {
50
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
51 51
         }
52 52
 
53
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
-        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
55
-        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
56
-        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
53
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
54
+        add_action('wp_footer', array(&$this, 'wp_footer'));
55
+        add_action('widgets_init', array(&$this, 'register_widgets'));
56
+        add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
57 57
 
58
-        if ( is_admin() ) {
59
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
60
-            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
61
-            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
58
+        if (is_admin()) {
59
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
60
+            add_filter('admin_body_class', array(&$this, 'admin_body_class'));
61
+            add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
62 62
 
63 63
         } else {
64
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
64
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
65 65
         }
66 66
         
67 67
         /**
@@ -71,28 +71,28 @@  discard block
 block discarded – undo
71 71
          *
72 72
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
73 73
          */
74
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
74
+        do_action_ref_array('wpinv_actions', array(&$this));
75 75
 
76
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
76
+        add_action('admin_init', array(&$this, 'activation_redirect'));
77 77
     }
78 78
 
79 79
     /**
80 80
      * Maybe show the AyeCode Connect Notice.
81 81
      */
82
-    public function init_ayecode_connect_helper(){
82
+    public function init_ayecode_connect_helper() {
83 83
         // AyeCode Connect notice
84
-        if ( is_admin() ){
84
+        if (is_admin()) {
85 85
             // set the strings so they can be translated
86 86
             $strings = array(
87
-                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
88
-                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
89
-                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
90
-                'connect_button'    => __("Connect Site","invoicing"),
91
-                'connecting_button'    => __("Connecting...","invoicing"),
92
-                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
93
-                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
87
+                'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
88
+                'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
89
+                'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
90
+                'connect_button'    => __("Connect Site", "invoicing"),
91
+                'connecting_button'    => __("Connecting...", "invoicing"),
92
+                'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
93
+                'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
94 94
             );
95
-            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
95
+            new AyeCode_Connect_Helper($strings, array('wpi-addons'));
96 96
         }
97 97
     }
98 98
     
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
         /* Internationalize the text strings used. */
101 101
         $this->load_textdomain();
102 102
 
103
-        do_action( 'wpinv_loaded' );
103
+        do_action('wpinv_loaded');
104 104
 
105 105
         // Fix oxygen page builder conflict
106
-        if ( function_exists( 'ct_css_output' ) ) {
106
+        if (function_exists('ct_css_output')) {
107 107
             wpinv_oxygen_fix_conflict();
108 108
         }
109 109
     }
@@ -113,144 +113,144 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @since 1.0
115 115
      */
116
-    public function load_textdomain( $locale = NULL ) {
117
-        if ( empty( $locale ) ) {
118
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
116
+    public function load_textdomain($locale = NULL) {
117
+        if (empty($locale)) {
118
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
119 119
         }
120 120
 
121
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
121
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
122 122
         
123
-        unload_textdomain( 'invoicing' );
124
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
125
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
123
+        unload_textdomain('invoicing');
124
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
125
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
126 126
         
127 127
         /**
128 128
          * Define language constants.
129 129
          */
130
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
130
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
131 131
     }
132 132
 
133 133
     public function includes() {
134 134
         global $wpinv_options;
135 135
 
136
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
136
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
137 137
         $wpinv_options = wpinv_get_settings();
138 138
 
139 139
         // Load composer packages.
140
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
140
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
141 141
 
142 142
         // load AUI
143
-        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
143
+        require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
144 144
 
145 145
         // Load the action scheduler.
146
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
146
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
147 147
 
148 148
         // Load functions.
149
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
150
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
151
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
153
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
154
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
155
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
156
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
157
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
158
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
160
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
161
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
149
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
150
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
151
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
153
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
154
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
155
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
156
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
157
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
158
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
160
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
161
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
162 162
 
163 163
         // Register autoloader.
164 164
 		try {
165
-			spl_autoload_register( array( $this, 'autoload' ), true );
166
-		} catch ( Exception $e ) {
167
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
168
-        }
169
-
170
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
171
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
173
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
174
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
175
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
176
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
177
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
178
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
179
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
180
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
181
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
182
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
183
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
184
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
185
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
186
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
187
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
188
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
189
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
190
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
191
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
192
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
193
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
194
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
195
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
196
-        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
197
-        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
198
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
199
-
200
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
201
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
165
+			spl_autoload_register(array($this, 'autoload'), true);
166
+		} catch (Exception $e) {
167
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
168
+        }
169
+
170
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
171
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php');
173
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
174
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
175
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
176
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
177
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
178
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
179
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
180
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
181
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
182
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
183
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
184
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
185
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
186
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
187
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
188
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
189
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
190
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
191
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
192
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
193
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
194
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
195
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
196
+        require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
197
+        require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
198
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
199
+
200
+        if (!class_exists('WPInv_EUVat')) {
201
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
202 202
         }
203 203
         
204
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
205
-        if ( !empty( $gateways ) ) {
206
-            foreach ( $gateways as $gateway ) {
207
-                if ( $gateway == 'manual' ) {
204
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
205
+        if (!empty($gateways)) {
206
+            foreach ($gateways as $gateway) {
207
+                if ($gateway == 'manual') {
208 208
                     continue;
209 209
                 }
210 210
                 
211 211
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
212 212
                 
213
-                if ( file_exists( $gateway_file ) ) {
214
-                    require_once( $gateway_file );
213
+                if (file_exists($gateway_file)) {
214
+                    require_once($gateway_file);
215 215
                 }
216 216
             }
217 217
         }
218
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
218
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
219 219
         
220
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
221
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
222
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
223
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
220
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
221
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
222
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
223
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
224 224
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
225
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
226
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
227
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
228
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
229
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
230
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
231
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
232
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
233
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
225
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
226
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
227
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
228
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
229
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
230
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
231
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
232
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
233
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
234 234
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
235 235
             // load the user class only on the users.php page
236 236
             global $pagenow;
237
-            if($pagenow=='users.php'){
237
+            if ($pagenow == 'users.php') {
238 238
                 new WPInv_Admin_Users();
239 239
             }
240 240
         }
241 241
 
242 242
         // Register cli commands
243
-        if ( defined( 'WP_CLI' ) && WP_CLI ) {
244
-            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
245
-            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
243
+        if (defined('WP_CLI') && WP_CLI) {
244
+            require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
245
+            WP_CLI::add_command('invoicing', 'WPInv_CLI');
246 246
         }
247 247
         
248 248
         // include css inliner
249
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
250
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
249
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
250
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
251 251
         }
252 252
         
253
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
253
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
254 254
     }
255 255
 
256 256
     /**
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
 	 * @since       1.0.19
262 262
 	 * @return      void
263 263
 	 */
264
-	public function autoload( $class_name ) {
264
+	public function autoload($class_name) {
265 265
 
266 266
 		// Normalize the class name...
267
-		$class_name  = strtolower( $class_name );
267
+		$class_name = strtolower($class_name);
268 268
 
269 269
 		// ... and make sure it is our class.
270
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
270
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
271 271
 			return;
272 272
 		}
273 273
 
274 274
 		// Next, prepare the file name from the class.
275
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
275
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
276 276
 
277 277
 		// And an array of possible locations in order of importance.
278 278
 		$locations = array(
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
 		);
284 284
 
285 285
 		// Base path of the classes.
286
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
287 287
 
288
-		foreach ( $locations as $location ) {
288
+		foreach ($locations as $location) {
289 289
 
290
-			if ( file_exists( "$plugin_path/$location/$file_name" ) ) {
290
+			if (file_exists("$plugin_path/$location/$file_name")) {
291 291
 				include "$plugin_path/$location/$file_name";
292 292
 				break;
293 293
 			}
@@ -301,117 +301,117 @@  discard block
 block discarded – undo
301 301
     
302 302
     public function admin_init() {
303 303
         self::$instance->default_payment_form = wpinv_get_default_payment_form();
304
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
304
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
305 305
     }
306 306
 
307 307
     public function activation_redirect() {
308 308
         // Bail if no activation redirect
309
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
309
+        if (!get_transient('_wpinv_activation_redirect')) {
310 310
             return;
311 311
         }
312 312
 
313 313
         // Delete the redirect transient
314
-        delete_transient( '_wpinv_activation_redirect' );
314
+        delete_transient('_wpinv_activation_redirect');
315 315
 
316 316
         // Bail if activating from network, or bulk
317
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
317
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
318 318
             return;
319 319
         }
320 320
 
321
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
321
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
322 322
         exit;
323 323
     }
324 324
     
325 325
     public function enqueue_scripts() {
326
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
326
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
327 327
         
328
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
329
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
330
-        wp_enqueue_style( 'wpinv_front_style' );
328
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css');
329
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version);
330
+        wp_enqueue_style('wpinv_front_style');
331 331
                
332 332
         // Register scripts
333
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
334
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
333
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
334
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
335 335
 
336 336
         $localize                         = array();
337
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
338
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
337
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
338
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
339 339
         $localize['currency_symbol']      = wpinv_currency_symbol();
340 340
         $localize['currency_pos']         = wpinv_currency_position();
341 341
         $localize['thousand_sep']         = wpinv_thousands_separator();
342 342
         $localize['decimal_sep']          = wpinv_decimal_separator();
343 343
         $localize['decimals']             = wpinv_decimals();
344
-        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
344
+        $localize['txtComplete']          = __('Continue', 'invoicing');
345 345
         $localize['UseTaxes']             = wpinv_use_taxes();
346
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
347
-        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
348
-        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
346
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
347
+        $localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
348
+        $localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
349 349
 
350
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
350
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
351 351
         
352
-        wp_enqueue_script( 'jquery-blockui' );
352
+        wp_enqueue_script('jquery-blockui');
353 353
         $autofill_api = wpinv_get_option('address_autofill_api');
354 354
         $autofill_active = wpinv_get_option('address_autofill_active');
355
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
356
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
357
-                wp_dequeue_script( 'google-maps-api' );
355
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
356
+            if (wp_script_is('google-maps-api', 'enqueued')) {
357
+                wp_dequeue_script('google-maps-api');
358 358
             }
359
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
360
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
359
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
360
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
361 361
         }
362 362
 
363
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
364
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
363
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
364
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
365 365
 
366
-        wp_enqueue_script( 'wpinv-front-script' );
367
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
366
+        wp_enqueue_script('wpinv-front-script');
367
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
368 368
 
369
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
370
-        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
369
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
370
+        wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
371 371
     }
372 372
 
373
-    public function admin_enqueue_scripts( $hook ) {
373
+    public function admin_enqueue_scripts($hook) {
374 374
         global $post, $pagenow;
375 375
         
376 376
         $post_type  = wpinv_admin_post_type();
377
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
378
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
377
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
378
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
379 379
 
380 380
         $jquery_ui_css = false;
381
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
381
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
382 382
             $jquery_ui_css = true;
383
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
383
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
384 384
             $jquery_ui_css = true;
385 385
         }
386
-        if ( $jquery_ui_css ) {
387
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
388
-            wp_enqueue_style( 'jquery-ui-css' );
389
-            wp_deregister_style( 'yoast-seo-select2' );
390
-	        wp_deregister_style( 'yoast-seo-monorepo' );
386
+        if ($jquery_ui_css) {
387
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
388
+            wp_enqueue_style('jquery-ui-css');
389
+            wp_deregister_style('yoast-seo-select2');
390
+	        wp_deregister_style('yoast-seo-monorepo');
391 391
         }
392 392
 
393
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
394
-        wp_enqueue_style( 'wpinv_meta_box_style' );
393
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
394
+        wp_enqueue_style('wpinv_meta_box_style');
395 395
         
396
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
397
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
398
-        wp_enqueue_style( 'wpinv_admin_style' );
396
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
397
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
398
+        wp_enqueue_style('wpinv_admin_style');
399 399
 
400
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
401
-        if ( $page == 'wpinv-subscriptions' ) {
402
-            wp_enqueue_script( 'jquery-ui-datepicker' );
403
-            wp_deregister_style( 'yoast-seo-select2' );
404
-	        wp_deregister_style( 'yoast-seo-monorepo' );
400
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
401
+        if ($page == 'wpinv-subscriptions') {
402
+            wp_enqueue_script('jquery-ui-datepicker');
403
+            wp_deregister_style('yoast-seo-select2');
404
+	        wp_deregister_style('yoast-seo-monorepo');
405 405
         }
406 406
         
407
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
408
-            wp_enqueue_script( 'jquery-ui-datepicker' );
407
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
408
+            wp_enqueue_script('jquery-ui-datepicker');
409 409
         }
410 410
 
411
-        wp_enqueue_style( 'wp-color-picker' );
412
-        wp_enqueue_script( 'wp-color-picker' );
411
+        wp_enqueue_style('wp-color-picker');
412
+        wp_enqueue_script('wp-color-picker');
413 413
         
414
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
414
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
415 415
 
416 416
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
417 417
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -422,21 +422,21 @@  discard block
 block discarded – undo
422 422
             }
423 423
         }
424 424
 
425
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
426
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
425
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
426
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
427 427
 
428
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
429
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
430
-        wp_enqueue_script( 'wpinv-admin-script' );
428
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
429
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
430
+        wp_enqueue_script('wpinv-admin-script');
431 431
         
432 432
         $localize                               = array();
433
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
434
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
435
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
436
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
437
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
438
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
439
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
433
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
434
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
435
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
436
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
437
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
438
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
439
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
440 440
         $localize['tax']                        = wpinv_tax_amount();
441 441
         $localize['discount']                   = wpinv_discount_amount();
442 442
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -444,103 +444,103 @@  discard block
 block discarded – undo
444 444
         $localize['thousand_sep']               = wpinv_thousands_separator();
445 445
         $localize['decimal_sep']                = wpinv_decimal_separator();
446 446
         $localize['decimals']                   = wpinv_decimals();
447
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
448
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
449
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
450
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
451
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
452
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
453
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
454
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
455
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
456
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
457
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
458
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
459
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
460
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
461
-        $localize['item_description']           = __( 'Item Description', 'invoicing' );
462
-        $localize['discount_description']       = __( 'Discount Description', 'invoicing' );
463
-        $localize['invoice_description']        = __( 'Invoice Description', 'invoicing' );
464
-
465
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
466
-
467
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
447
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
448
+        $localize['status_publish']             = wpinv_status_nicename('publish');
449
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
450
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
451
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
452
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
453
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
454
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
455
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
456
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
457
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
458
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
459
+        $localize['action_edit']                = __('Edit', 'invoicing');
460
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
461
+        $localize['item_description']           = __('Item Description', 'invoicing');
462
+        $localize['discount_description']       = __('Discount Description', 'invoicing');
463
+        $localize['invoice_description']        = __('Invoice Description', 'invoicing');
464
+
465
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
466
+
467
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
468 468
 
469 469
         // Load payment form scripts on our admin pages only.
470
-        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
470
+        if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
471 471
 
472
-            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
473
-            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
474
-            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
472
+            wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
473
+            wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
474
+            wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
475 475
 
476
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
477
-            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
476
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
477
+            wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
478 478
         
479
-            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
479
+            wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
480 480
                 'elements'      => $this->form_elements->get_elements(),
481
-                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
481
+                'form_elements' => $this->form_elements->get_form_elements($post->ID),
482 482
                 'all_items'     => $this->form_elements->get_published_items(),
483 483
                 'currency'      => wpinv_currency_symbol(),
484 484
                 'position'      => wpinv_currency_position(),
485 485
                 'decimals'      => (int) wpinv_decimals(),
486 486
                 'thousands_sep' => wpinv_thousands_separator(),
487 487
                 'decimals_sep'  => wpinv_decimal_separator(),
488
-                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
488
+                'form_items'    => $this->form_elements->get_form_items($post->ID),
489 489
                 'is_default'    => $post->ID == $this->default_payment_form,
490
-            ) );
490
+            ));
491 491
 
492
-            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
492
+            wp_enqueue_script('wpinv-admin-payment-form-script');
493 493
         }
494 494
 
495
-        if ( $page == 'wpinv-subscriptions' ) {
496
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
497
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
495
+        if ($page == 'wpinv-subscriptions') {
496
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
497
+            wp_enqueue_script('wpinv-sub-admin-script');
498 498
         }
499 499
 
500
-        if ( $page == 'wpinv-reports' ) {
501
-            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
500
+        if ($page == 'wpinv-reports') {
501
+            wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
502 502
         }
503 503
 
504 504
     }
505 505
 
506
-    public function admin_body_class( $classes ) {
506
+    public function admin_body_class($classes) {
507 507
         global $pagenow, $post, $current_screen;
508 508
         
509
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
509
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
510 510
             $classes .= ' wpinv-cpt';
511 511
         }
512 512
         
513
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
513
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
514 514
 
515
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
516
-        if ( $add_class ) {
517
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
515
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
516
+        if ($add_class) {
517
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
518 518
         }
519 519
         
520 520
         $settings_class = array();
521
-        if ( $page == 'wpinv-settings' ) {
522
-            if ( !empty( $_REQUEST['tab'] ) ) {
523
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
521
+        if ($page == 'wpinv-settings') {
522
+            if (!empty($_REQUEST['tab'])) {
523
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
524 524
             }
525 525
             
526
-            if ( !empty( $_REQUEST['section'] ) ) {
527
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
526
+            if (!empty($_REQUEST['section'])) {
527
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
528 528
             }
529 529
             
530
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
530
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
531 531
         }
532 532
         
533
-        if ( !empty( $settings_class ) ) {
534
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
533
+        if (!empty($settings_class)) {
534
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
535 535
         }
536 536
         
537 537
         $post_type = wpinv_admin_post_type();
538 538
 
539
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
539
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
540 540
             return $classes .= ' wpinv';
541 541
         }
542 542
         
543
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
543
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
544 544
             $classes .= ' wpi-editable-n';
545 545
         }
546 546
 
@@ -552,21 +552,21 @@  discard block
 block discarded – undo
552 552
     }
553 553
     
554 554
     public function wpinv_actions() {
555
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
556
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
555
+        if (isset($_REQUEST['wpi_action'])) {
556
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
557 557
         }
558 558
     }
559 559
     
560
-    public function pre_get_posts( $wp_query ) {
561
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
562
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
560
+    public function pre_get_posts($wp_query) {
561
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
562
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
563 563
         }
564 564
         
565 565
         return $wp_query;
566 566
     }
567 567
     
568 568
     public function bp_invoicing_init() {
569
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
569
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
570 570
     }
571 571
 
572 572
 	/**
@@ -574,13 +574,13 @@  discard block
 block discarded – undo
574 574
 	 *
575 575
 	 */
576 576
 	public function register_widgets() {
577
-		register_widget( "WPInv_Checkout_Widget" );
578
-		register_widget( "WPInv_History_Widget" );
579
-		register_widget( "WPInv_Receipt_Widget" );
580
-		register_widget( "WPInv_Subscriptions_Widget" );
581
-		register_widget( "WPInv_Buy_Item_Widget" );
582
-        register_widget( "WPInv_Messages_Widget" );
583
-        register_widget( 'WPInv_GetPaid_Widget' );
577
+		register_widget("WPInv_Checkout_Widget");
578
+		register_widget("WPInv_History_Widget");
579
+		register_widget("WPInv_Receipt_Widget");
580
+		register_widget("WPInv_Subscriptions_Widget");
581
+		register_widget("WPInv_Buy_Item_Widget");
582
+        register_widget("WPInv_Messages_Widget");
583
+        register_widget('WPInv_GetPaid_Widget');
584 584
 	}
585 585
     
586 586
     /**
@@ -589,10 +589,10 @@  discard block
 block discarded – undo
589 589
      * @since 1.0.19
590 590
      * @param int[] $excluded_posts_ids
591 591
      */
592
-    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
592
+    public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
593 593
 
594 594
         // Ensure that we have an array.
595
-        if ( ! is_array( $excluded_posts_ids ) ) {
595
+        if (!is_array($excluded_posts_ids)) {
596 596
             $excluded_posts_ids = array();
597 597
         }
598 598
 
@@ -600,24 +600,24 @@  discard block
 block discarded – undo
600 600
         $our_pages = array();
601 601
     
602 602
         // Checkout page.
603
-        $our_pages[] = wpinv_get_option( 'checkout_page', false );
603
+        $our_pages[] = wpinv_get_option('checkout_page', false);
604 604
 
605 605
         // Success page.
606
-        $our_pages[] = wpinv_get_option( 'success_page', false );
606
+        $our_pages[] = wpinv_get_option('success_page', false);
607 607
 
608 608
         // Failure page.
609
-        $our_pages[] = wpinv_get_option( 'failure_page', false );
609
+        $our_pages[] = wpinv_get_option('failure_page', false);
610 610
 
611 611
         // History page.
612
-        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
612
+        $our_pages[] = wpinv_get_option('invoice_history_page', false);
613 613
 
614 614
         // Subscriptions page.
615
-        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
615
+        $our_pages[] = wpinv_get_option('invoice_subscription_page', false);
616 616
 
617
-        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
617
+        $our_pages   = array_map('intval', array_filter($our_pages));
618 618
 
619 619
         $excluded_posts_ids = $excluded_posts_ids + $our_pages;
620
-        return array_unique( $excluded_posts_ids );
620
+        return array_unique($excluded_posts_ids);
621 621
 
622 622
     }
623 623
 
Please login to merge, or discard this patch.
includes/class-getpaid-payment-form-submission.php 2 patches
Indentation   +707 added lines, -707 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,747 +10,747 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18 18
 
19
-	/**
20
-	 * Sets the associated payment form.
21
-	 *
22
-	 * @var GetPaid_Payment_Form
23
-	 */
19
+    /**
20
+     * Sets the associated payment form.
21
+     *
22
+     * @var GetPaid_Payment_Form
23
+     */
24 24
     protected $payment_form = null;
25 25
 
26 26
     /**
27
-	 * The country for the submission.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	public $country = null;
32
-
33
-    /**
34
-	 * The state for the submission.
35
-	 *
36
-	 * @since 1.0.19
37
-	 * @var string
38
-	 */
39
-	public $state = null;
40
-
41
-	/**
42
-	 * The invoice associated with the submission.
43
-	 *
44
-	 * @var WPInv_Invoice
45
-	 */
46
-	protected $invoice = null;
47
-
48
-	/**
49
-	 * The discount associated with the submission.
50
-	 *
51
-	 * @var WPInv_Discount
52
-	 */
53
-	protected $discount = null;
54
-
55
-	/**
56
-	 * The raw submission data.
57
-	 *
58
-	 * @var array
59
-	 */
60
-	protected $data = null;
61
-
62
-	/**
63
-	 * Whether this submission contains a recurring item.
64
-	 *
65
-	 * @var bool
66
-	 */
67
-	public $has_recurring = false;
68
-
69
-	/**
70
-	 * The sub total amount for the submission.
71
-	 *
72
-	 * @var float
73
-	 */
74
-	public $subtotal_amount = 0;
75
-
76
-	/**
77
-	 * The total discount amount for the submission.
78
-	 *
79
-	 * @var float
80
-	 */
81
-	protected $total_discount_amount = 0;
82
-
83
-	/**
84
-	 * The total tax amount for the submission.
85
-	 *
86
-	 * @var float
87
-	 */
88
-	protected $total_tax_amount = 0;
89
-
90
-	/**
91
-	 * The total fees amount for the submission.
92
-	 *
93
-	 * @var float
94
-	 */
95
-	protected $total_fees_amount = 0;
96
-
97
-	/**
98
-	 * An array of fees for the submission.
99
-	 *
100
-	 * @var array
101
-	 */
102
-	protected $fees = array();
103
-
104
-	/**
105
-	 * An array of discounts for the submission.
106
-	 *
107
-	 * @var array
108
-	 */
109
-	protected $discounts = array();
110
-
111
-	/**
112
-	 * An array of taxes for the submission.
113
-	 *
114
-	 * @var array
115
-	 */
116
-	protected $taxes = array();
117
-
118
-	/**
119
-	 * An array of items for the submission.
120
-	 *
121
-	 * @var GetPaid_Form_Item[]
122
-	 */
123
-	protected $items = array();
124
-
125
-	/**
126
-	 * The last error.
127
-	 *
128
-	 * @var string
129
-	 */
130
-	public $last_error = null;
131
-
132
-	/**
133
-	 * Is the discount valid?
134
-	 *
135
-	 * @var string
136
-	 */
137
-    public $is_discount_valid = true;
27
+     * The country for the submission.
28
+     *
29
+     * @var string
30
+     */
31
+    public $country = null;
32
+
33
+    /**
34
+     * The state for the submission.
35
+     *
36
+     * @since 1.0.19
37
+     * @var string
38
+     */
39
+    public $state = null;
40
+
41
+    /**
42
+     * The invoice associated with the submission.
43
+     *
44
+     * @var WPInv_Invoice
45
+     */
46
+    protected $invoice = null;
47
+
48
+    /**
49
+     * The discount associated with the submission.
50
+     *
51
+     * @var WPInv_Discount
52
+     */
53
+    protected $discount = null;
54
+
55
+    /**
56
+     * The raw submission data.
57
+     *
58
+     * @var array
59
+     */
60
+    protected $data = null;
61
+
62
+    /**
63
+     * Whether this submission contains a recurring item.
64
+     *
65
+     * @var bool
66
+     */
67
+    public $has_recurring = false;
68
+
69
+    /**
70
+     * The sub total amount for the submission.
71
+     *
72
+     * @var float
73
+     */
74
+    public $subtotal_amount = 0;
75
+
76
+    /**
77
+     * The total discount amount for the submission.
78
+     *
79
+     * @var float
80
+     */
81
+    protected $total_discount_amount = 0;
138 82
 
139 83
     /**
140
-	 * Class constructor.
141
-	 *
142
-	 */
143
-	public function __construct() {
84
+     * The total tax amount for the submission.
85
+     *
86
+     * @var float
87
+     */
88
+    protected $total_tax_amount = 0;
144 89
 
145
-		// Set the state and country to the default state and country.
146
-		$this->country = wpinv_default_billing_country();
147
-		$this->state = wpinv_get_default_state();
90
+    /**
91
+     * The total fees amount for the submission.
92
+     *
93
+     * @var float
94
+     */
95
+    protected $total_fees_amount = 0;
148 96
 
149
-		// Do we have an actual submission?
150
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
151
-			$this->load_data( $_POST );
152
-		}
153
-	}
97
+    /**
98
+     * An array of fees for the submission.
99
+     *
100
+     * @var array
101
+     */
102
+    protected $fees = array();
154 103
 
155
-	/**
156
-	 * Loads submission data.
157
-	 *
158
-	 * @param array $data
159
-	 */
160
-	public function load_data( $data ) {
104
+    /**
105
+     * An array of discounts for the submission.
106
+     *
107
+     * @var array
108
+     */
109
+    protected $discounts = array();
161 110
 
162
-		// Prepare submitted data...
163
-		$data = wp_unslash( $data );
111
+    /**
112
+     * An array of taxes for the submission.
113
+     *
114
+     * @var array
115
+     */
116
+    protected $taxes = array();
164 117
 
165
-		// Fitter the data.
166
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
118
+    /**
119
+     * An array of items for the submission.
120
+     *
121
+     * @var GetPaid_Form_Item[]
122
+     */
123
+    protected $items = array();
167 124
 
168
-		$this->data = $data;
125
+    /**
126
+     * The last error.
127
+     *
128
+     * @var string
129
+     */
130
+    public $last_error = null;
169 131
 
170
-		$this->id = md5( wp_json_encode( $data ) );
132
+    /**
133
+     * Is the discount valid?
134
+     *
135
+     * @var string
136
+     */
137
+    public $is_discount_valid = true;
138
+
139
+    /**
140
+     * Class constructor.
141
+     *
142
+     */
143
+    public function __construct() {
144
+
145
+        // Set the state and country to the default state and country.
146
+        $this->country = wpinv_default_billing_country();
147
+        $this->state = wpinv_get_default_state();
148
+
149
+        // Do we have an actual submission?
150
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
151
+            $this->load_data( $_POST );
152
+        }
153
+    }
154
+
155
+    /**
156
+     * Loads submission data.
157
+     *
158
+     * @param array $data
159
+     */
160
+    public function load_data( $data ) {
171 161
 
172
-		// Every submission needs an active payment form.
173
-		if ( empty( $data['form_id'] ) ) {
174
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
162
+        // Prepare submitted data...
163
+        $data = wp_unslash( $data );
164
+
165
+        // Fitter the data.
166
+        $data = apply_filters( 'getpaid_submission_data', $data, $this );
167
+
168
+        $this->data = $data;
169
+
170
+        $this->id = md5( wp_json_encode( $data ) );
171
+
172
+        // Every submission needs an active payment form.
173
+        if ( empty( $data['form_id'] ) ) {
174
+            $this->last_error = __( 'Missing payment form', 'invoicing' );
175 175
             return;
176
-		}
176
+        }
177 177
 
178
-		// Fetch the payment form.
179
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
178
+        // Fetch the payment form.
179
+        $form = new GetPaid_Payment_Form( $data['form_id'] );
180 180
 
181
-		if ( ! $form->is_active() ) {
182
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
183
-			return;
184
-		}
181
+        if ( ! $form->is_active() ) {
182
+            $this->last_error = __( 'Payment form not active', 'invoicing' );
183
+            return;
184
+        }
185 185
 
186
-		// Fetch the payment form.
187
-		$this->payment_form = $form;
186
+        // Fetch the payment form.
187
+        $this->payment_form = $form;
188 188
 
189
-		// For existing invoices, make sure that it is valid.
189
+        // For existing invoices, make sure that it is valid.
190 190
         if ( ! empty( $data['invoice_id'] ) ) {
191 191
             $invoice = wpinv_get_invoice( $data['invoice_id'] );
192 192
 
193 193
             if ( empty( $invoice ) ) {
194
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
194
+                $this->last_error = __( 'Invalid invoice', 'invoicing' );
195 195
                 return;
196 196
             }
197 197
 
198
-			$this->payment_form->set_items( $invoice->cart_details );
198
+            $this->payment_form->set_items( $invoice->cart_details );
199 199
 
200
-			$this->country = $invoice->country;
201
-			$this->state = $invoice->state;
200
+            $this->country = $invoice->country;
201
+            $this->state = $invoice->state;
202 202
 
203
-		// Default forms do not have items.
203
+        // Default forms do not have items.
204 204
         } else if ( $form->is_default() && isset( $data['form_items'] ) ) {
205
-			$this->payment_form->set_items( $data['form_items'] );
206
-		}
207
-
208
-		// User's country.
209
-		if ( ! empty( $data['wpinv_country'] ) ) {
210
-			$this->country = $data['wpinv_country'];
211
-		}
212
-
213
-		// User's state.
214
-		if ( ! empty( $data['wpinv_state'] ) ) {
215
-			$this->country = $data['wpinv_state'];
216
-		}
217
-
218
-		// Handle discounts.
219
-		$this->maybe_prepare_discount();
220
-
221
-		// Handle items.
222
-		$selected_items = array();
223
-		if ( ! empty( $data['getpaid-items'] ) ) {
224
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
225
-		}
226
-
227
-		foreach ( $this->payment_form->get_items() as $item ) {
228
-
229
-			// Continue if this is an optional item and it has not been selected.
230
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
231
-				continue;
232
-			}
233
-
234
-			// (maybe) let customers change the quantities and prices.
235
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
236
-
237
-				// Maybe change the quantities.
238
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
239
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
240
-				}
241
-
242
-				// Maybe change the price.
243
-				if ( $item->user_can_set_their_price() ) {
244
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
245
-
246
-					// But don't get lower than the minimum price.
247
-					if ( $price < $item->get_minimum_price() ) {
248
-						$price = $item->get_minimum_price();
249
-					}
250
-
251
-					$item->set_price( $price );
252
-
253
-				}
254
-
255
-			}
256
-
257
-			// Add the item to the form.
258
-			$this->add_item( $item );
259
-
260
-		}
261
-
262
-		// Fired when we are done processing a submission.
263
-		do_action( 'getpaid_process_submission', $this );
264
-
265
-		// Remove invalid discount.
266
-		$this->maybe_remove_discount();
267
-
268
-	}
269
-
270
-    /**
271
-	 * Returns the payment form.
272
-	 *
273
-	 * @since 1.0.19
274
-	 * @return GetPaid_Payment_Form
275
-	 */
276
-	public function get_payment_form() {
277
-		return $this->payment_form;
278
-	}
279
-
280
-	/**
281
-	 * Returns the associated invoice.
282
-	 *
283
-	 * @since 1.0.19
284
-	 * @return WPInv_Invoice
285
-	 */
286
-	public function get_invoice() {
287
-		return $this->invoice;
288
-	}
289
-
290
-	/**
291
-	 * Checks whether there is an invoice associated with this submission.
292
-	 *
293
-	 * @since 1.0.19
294
-	 * @return bool
295
-	 */
296
-	public function has_invoice() {
297
-		return ! empty( $this->invoice );
298
-	}
205
+            $this->payment_form->set_items( $data['form_items'] );
206
+        }
207
+
208
+        // User's country.
209
+        if ( ! empty( $data['wpinv_country'] ) ) {
210
+            $this->country = $data['wpinv_country'];
211
+        }
212
+
213
+        // User's state.
214
+        if ( ! empty( $data['wpinv_state'] ) ) {
215
+            $this->country = $data['wpinv_state'];
216
+        }
217
+
218
+        // Handle discounts.
219
+        $this->maybe_prepare_discount();
220
+
221
+        // Handle items.
222
+        $selected_items = array();
223
+        if ( ! empty( $data['getpaid-items'] ) ) {
224
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
225
+        }
226
+
227
+        foreach ( $this->payment_form->get_items() as $item ) {
228
+
229
+            // Continue if this is an optional item and it has not been selected.
230
+            if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
231
+                continue;
232
+            }
233
+
234
+            // (maybe) let customers change the quantities and prices.
235
+            if ( isset( $selected_items[ $item->get_id() ] ) ) {
236
+
237
+                // Maybe change the quantities.
238
+                if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
239
+                    $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
240
+                }
241
+
242
+                // Maybe change the price.
243
+                if ( $item->user_can_set_their_price() ) {
244
+                    $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
245
+
246
+                    // But don't get lower than the minimum price.
247
+                    if ( $price < $item->get_minimum_price() ) {
248
+                        $price = $item->get_minimum_price();
249
+                    }
250
+
251
+                    $item->set_price( $price );
252
+
253
+                }
254
+
255
+            }
256
+
257
+            // Add the item to the form.
258
+            $this->add_item( $item );
259
+
260
+        }
261
+
262
+        // Fired when we are done processing a submission.
263
+        do_action( 'getpaid_process_submission', $this );
264
+
265
+        // Remove invalid discount.
266
+        $this->maybe_remove_discount();
267
+
268
+    }
269
+
270
+    /**
271
+     * Returns the payment form.
272
+     *
273
+     * @since 1.0.19
274
+     * @return GetPaid_Payment_Form
275
+     */
276
+    public function get_payment_form() {
277
+        return $this->payment_form;
278
+    }
279
+
280
+    /**
281
+     * Returns the associated invoice.
282
+     *
283
+     * @since 1.0.19
284
+     * @return WPInv_Invoice
285
+     */
286
+    public function get_invoice() {
287
+        return $this->invoice;
288
+    }
289
+
290
+    /**
291
+     * Checks whether there is an invoice associated with this submission.
292
+     *
293
+     * @since 1.0.19
294
+     * @return bool
295
+     */
296
+    public function has_invoice() {
297
+        return ! empty( $this->invoice );
298
+    }
299 299
 	
300
-	/**
301
-	 * Returns the appropriate currency for the submission.
302
-	 *
303
-	 * @since 1.0.19
304
-	 * @return string
305
-	 */
306
-	public function get_currency() {
307
-		if ( $this->has_invoice() ) {
308
-			return $this->invoice->get_currency();
309
-		}
310
-		return wpinv_get_currency();
311
-    }
312
-
313
-    /**
314
-	 * Returns the raw submission data.
315
-	 *
316
-	 * @since 1.0.19
317
-	 * @return array
318
-	 */
319
-	public function get_data() {
320
-		return $this->data;
321
-	}
322
-
323
-	/**
324
-	 * Checks if a required field is set.
325
-	 *
326
-	 * @since 1.0.19
327
-	 */
328
-	public function is_required_field_set( $field ) {
329
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
330
-	}
331
-
332
-	///////// Items //////////////
333
-
334
-	/**
335
-	 * Adds an item to the submission.
336
-	 *
337
-	 * @since 1.0.19
338
-	 * @param GetPaid_Form_Item $item
339
-	 */
340
-	public function add_item( $item ) {
341
-
342
-		// Make sure that it is available for purchase.
343
-		if ( ! $item->can_purchase() ) {
344
-			return;
345
-		}
346
-
347
-		// Do we have a recurring item?
348
-		if ( $item->is_recurring() ) {
349
-			$this->has_recurring = true;
350
-		}
351
-
352
-		$this->items[ $item->get_id() ] = $item;
353
-
354
-		$this->subtotal_amount += $item->get_sub_total();
355
-
356
-		$this->process_item_discount( $item );
357
-
358
-		$this->process_item_tax( $item );
359
-	}
360
-
361
-	/**
362
-	 * Retrieves a specific item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 */
366
-	public function get_item( $item_id ) {
367
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
368
-	}
369
-
370
-	/**
371
-	 * Returns all items.
372
-	 *
373
-	 * @since 1.0.19
374
-	 * @return GetPaid_Form_Item[]
375
-	 */
376
-	public function get_items() {
377
-		return $this->items;
378
-	}
379
-
380
-	///////// TAXES //////////////
381
-
382
-	/**
383
-	 * Adds a tax to the submission.
384
-	 *
385
-	 * @since 1.0.19
386
-	 */
387
-	public function add_tax( $name, $amount ) {
388
-		$amount = (float) wpinv_sanitize_amount( $amount );
389
-
390
-		$this->total_tax_amount += $amount;
391
-
392
-		if ( isset( $this->taxes[ $name ] ) ) {
393
-			$this->taxes[ $name ] += $amount;
394
-		} else {
395
-			$this->taxes[ $name ] = $amount;
396
-		}
397
-
398
-	}
399
-
400
-	/**
401
-	 * Whether or not we'll use taxes for the submission.
402
-	 *
403
-	 * @since 1.0.19
404
-	 */
405
-	public function use_taxes() {
406
-
407
-		$use_taxes = wpinv_use_taxes();
408
-
409
-		if ( $this->has_invoice() && $this->invoice->disable_taxes ) {
410
-			$use_taxes = false;
411
-		}
412
-
413
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
414
-
415
-	}
416
-
417
-	/**
418
-	 * Maybe process tax.
419
-	 *
420
-	 * @since 1.0.19 
421
-	 * @param GetPaid_Form_Item $item
422
-	 */
423
-	public function process_item_tax( $item ) {
424
-
425
-		// Abort early if we're not using taxes.
426
-		if ( ! $this->use_taxes() ) {
427
-			return;
428
-		}
429
-
430
-		$rate  = wpinv_get_tax_rate( $this->country, $this->state, $item->get_id() );
431
-		$price = $item->get_sub_total();
432
-
433
-		if ( wpinv_prices_include_tax() ) {
434
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
435
-		} else {
436
-			$item_tax = $price * $rate * 0.01;
437
-		}
438
-
439
-		$this->add_tax( 'Tax', $item_tax );
440
-
441
-	}
442
-
443
-	/**
444
-	 * Returns the total tax amount.
445
-	 *
446
-	 * @since 1.0.19
447
-	 */
448
-	public function get_total_tax() {
449
-		return $this->total_tax_amount;
450
-	}
451
-
452
-	/**
453
-	 * Retrieves a specific tax.
454
-	 *
455
-	 * @since 1.0.19
456
-	 */
457
-	public function get_tax( $name ) {
458
-		return isset( $this->taxes[ $name ] ) ? $this->taxes[ $name ] : 0;
459
-	}
460
-
461
-	/**
462
-	 * Returns all taxes.
463
-	 *
464
-	 * @since 1.0.19
465
-	 */
466
-	public function get_taxes() {
467
-		return $this->taxes;
468
-	}
469
-
470
-	///////// DISCOUNTS //////////////
471
-
472
-	/**
473
-	 * Adds a discount to the submission.
474
-	 *
475
-	 * @since 1.0.19
476
-	 */
477
-	public function add_discount( $name, $amount ) {
478
-		$amount = wpinv_sanitize_amount( $amount );
479
-
480
-		$this->total_discount_amount += $amount;
481
-
482
-		if ( isset( $this->discounts[ $name ] ) ) {
483
-			$this->discounts[ $name ] += $amount;
484
-		} else {
485
-			$this->discounts[ $name ] = $amount;
486
-		}
487
-
488
-	}
489
-
490
-	/**
491
-	 * Removes a discount from the submission.
492
-	 *
493
-	 * @since 1.0.19
494
-	 */
495
-	public function remove_discount( $name ) {
496
-
497
-		if ( isset( $this->discounts[ $name ] ) ) {
498
-			$this->total_discount_amount -= $this->discounts[ $name ];
499
-			unset( $this->discounts[ $name ] );
500
-		}
501
-
502
-	}
503
-
504
-	/**
505
-	 * Checks whether there is a discount code associated with this submission.
506
-	 *
507
-	 * @since 1.0.19
508
-	 * @return bool
509
-	 */
510
-	public function has_discount_code() {
511
-		return ! empty( $this->discount );
512
-	}
513
-
514
-	/**
515
-	 * Returns the discount code.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @return bool
519
-	 */
520
-	public function get_discount_code() {
521
-		return $this->has_discount_code() ? $this->discount->code : '';
522
-	}
523
-
524
-	/**
525
-	 * Prepares an item discount.
526
-	 *
527
-	 * @since 1.0.19
528
-	 */
529
-	public function maybe_prepare_discount() {
530
-
531
-		// Do we have a discount?
532
-		if ( empty( $this->data['discount'] ) ) {
533
-			return;
534
-		}
535
-
536
-		// Fetch the discount.
537
-		$discount = wpinv_get_discount_obj( $this->data['discount'] );
538
-
539
-		// Ensure it is active.
300
+    /**
301
+     * Returns the appropriate currency for the submission.
302
+     *
303
+     * @since 1.0.19
304
+     * @return string
305
+     */
306
+    public function get_currency() {
307
+        if ( $this->has_invoice() ) {
308
+            return $this->invoice->get_currency();
309
+        }
310
+        return wpinv_get_currency();
311
+    }
312
+
313
+    /**
314
+     * Returns the raw submission data.
315
+     *
316
+     * @since 1.0.19
317
+     * @return array
318
+     */
319
+    public function get_data() {
320
+        return $this->data;
321
+    }
322
+
323
+    /**
324
+     * Checks if a required field is set.
325
+     *
326
+     * @since 1.0.19
327
+     */
328
+    public function is_required_field_set( $field ) {
329
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
330
+    }
331
+
332
+    ///////// Items //////////////
333
+
334
+    /**
335
+     * Adds an item to the submission.
336
+     *
337
+     * @since 1.0.19
338
+     * @param GetPaid_Form_Item $item
339
+     */
340
+    public function add_item( $item ) {
341
+
342
+        // Make sure that it is available for purchase.
343
+        if ( ! $item->can_purchase() ) {
344
+            return;
345
+        }
346
+
347
+        // Do we have a recurring item?
348
+        if ( $item->is_recurring() ) {
349
+            $this->has_recurring = true;
350
+        }
351
+
352
+        $this->items[ $item->get_id() ] = $item;
353
+
354
+        $this->subtotal_amount += $item->get_sub_total();
355
+
356
+        $this->process_item_discount( $item );
357
+
358
+        $this->process_item_tax( $item );
359
+    }
360
+
361
+    /**
362
+     * Retrieves a specific item.
363
+     *
364
+     * @since 1.0.19
365
+     */
366
+    public function get_item( $item_id ) {
367
+        return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
368
+    }
369
+
370
+    /**
371
+     * Returns all items.
372
+     *
373
+     * @since 1.0.19
374
+     * @return GetPaid_Form_Item[]
375
+     */
376
+    public function get_items() {
377
+        return $this->items;
378
+    }
379
+
380
+    ///////// TAXES //////////////
381
+
382
+    /**
383
+     * Adds a tax to the submission.
384
+     *
385
+     * @since 1.0.19
386
+     */
387
+    public function add_tax( $name, $amount ) {
388
+        $amount = (float) wpinv_sanitize_amount( $amount );
389
+
390
+        $this->total_tax_amount += $amount;
391
+
392
+        if ( isset( $this->taxes[ $name ] ) ) {
393
+            $this->taxes[ $name ] += $amount;
394
+        } else {
395
+            $this->taxes[ $name ] = $amount;
396
+        }
397
+
398
+    }
399
+
400
+    /**
401
+     * Whether or not we'll use taxes for the submission.
402
+     *
403
+     * @since 1.0.19
404
+     */
405
+    public function use_taxes() {
406
+
407
+        $use_taxes = wpinv_use_taxes();
408
+
409
+        if ( $this->has_invoice() && $this->invoice->disable_taxes ) {
410
+            $use_taxes = false;
411
+        }
412
+
413
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
414
+
415
+    }
416
+
417
+    /**
418
+     * Maybe process tax.
419
+     *
420
+     * @since 1.0.19 
421
+     * @param GetPaid_Form_Item $item
422
+     */
423
+    public function process_item_tax( $item ) {
424
+
425
+        // Abort early if we're not using taxes.
426
+        if ( ! $this->use_taxes() ) {
427
+            return;
428
+        }
429
+
430
+        $rate  = wpinv_get_tax_rate( $this->country, $this->state, $item->get_id() );
431
+        $price = $item->get_sub_total();
432
+
433
+        if ( wpinv_prices_include_tax() ) {
434
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
435
+        } else {
436
+            $item_tax = $price * $rate * 0.01;
437
+        }
438
+
439
+        $this->add_tax( 'Tax', $item_tax );
440
+
441
+    }
442
+
443
+    /**
444
+     * Returns the total tax amount.
445
+     *
446
+     * @since 1.0.19
447
+     */
448
+    public function get_total_tax() {
449
+        return $this->total_tax_amount;
450
+    }
451
+
452
+    /**
453
+     * Retrieves a specific tax.
454
+     *
455
+     * @since 1.0.19
456
+     */
457
+    public function get_tax( $name ) {
458
+        return isset( $this->taxes[ $name ] ) ? $this->taxes[ $name ] : 0;
459
+    }
460
+
461
+    /**
462
+     * Returns all taxes.
463
+     *
464
+     * @since 1.0.19
465
+     */
466
+    public function get_taxes() {
467
+        return $this->taxes;
468
+    }
469
+
470
+    ///////// DISCOUNTS //////////////
471
+
472
+    /**
473
+     * Adds a discount to the submission.
474
+     *
475
+     * @since 1.0.19
476
+     */
477
+    public function add_discount( $name, $amount ) {
478
+        $amount = wpinv_sanitize_amount( $amount );
479
+
480
+        $this->total_discount_amount += $amount;
481
+
482
+        if ( isset( $this->discounts[ $name ] ) ) {
483
+            $this->discounts[ $name ] += $amount;
484
+        } else {
485
+            $this->discounts[ $name ] = $amount;
486
+        }
487
+
488
+    }
489
+
490
+    /**
491
+     * Removes a discount from the submission.
492
+     *
493
+     * @since 1.0.19
494
+     */
495
+    public function remove_discount( $name ) {
496
+
497
+        if ( isset( $this->discounts[ $name ] ) ) {
498
+            $this->total_discount_amount -= $this->discounts[ $name ];
499
+            unset( $this->discounts[ $name ] );
500
+        }
501
+
502
+    }
503
+
504
+    /**
505
+     * Checks whether there is a discount code associated with this submission.
506
+     *
507
+     * @since 1.0.19
508
+     * @return bool
509
+     */
510
+    public function has_discount_code() {
511
+        return ! empty( $this->discount );
512
+    }
513
+
514
+    /**
515
+     * Returns the discount code.
516
+     *
517
+     * @since 1.0.19
518
+     * @return bool
519
+     */
520
+    public function get_discount_code() {
521
+        return $this->has_discount_code() ? $this->discount->code : '';
522
+    }
523
+
524
+    /**
525
+     * Prepares an item discount.
526
+     *
527
+     * @since 1.0.19
528
+     */
529
+    public function maybe_prepare_discount() {
530
+
531
+        // Do we have a discount?
532
+        if ( empty( $this->data['discount'] ) ) {
533
+            return;
534
+        }
535
+
536
+        // Fetch the discount.
537
+        $discount = wpinv_get_discount_obj( $this->data['discount'] );
538
+
539
+        // Ensure it is active.
540 540
         if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) {
541
-			$this->is_discount_valid = false;
542
-			$this->last_error = __( 'Invalid or expired discount code', 'invoicing' );
543
-			return;
544
-		}
545
-
546
-		// For single use discounts...
547
-		if ( $discount->is_single_use ) {
548
-
549
-			if ( ! $this->has_billing_email() ) {
550
-				$this->is_discount_valid = false;
551
-				$this->last_error = __( 'You need to enter your billing email before applying this discount', 'invoicing' );
552
-				return;
553
-			}
554
-
555
-			if ( ! $discount->is_valid_for_user( $this->get_billing_email() ) ) {
556
-				$this->is_discount_valid = false;
557
-				$this->last_error = __( 'You have already used this discount', 'invoicing' );
558
-				return;
559
-			}
560
-		}
561
-
562
-		// Set the discount.
563
-		$this->discount = $discount;
564
-
565
-	}
566
-
567
-	/**
568
-	 * Removes an invalid discount code.
569
-	 *
570
-	 * @since 1.0.19
571
-	 */
572
-	public function maybe_remove_discount() {
573
-
574
-		// Do we have a discount?
575
-		if ( empty( $this->has_discount_code() ) ) {
576
-			return;
577
-		}
578
-
579
-		// Fetch the discount amount.
580
-		$amount = $this->get_discount( 'Discount' );
581
-
582
-		// Abort early if this is a "zero" discount.
583
-		if ( empty( $amount ) ) {
584
-			return;
585
-		}
586
-
587
-		$total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
588
-
589
-		if ( ! $this->discount->is_minimum_amount_met( $total ) ) {
590
-			$this->is_discount_valid = false;
541
+            $this->is_discount_valid = false;
542
+            $this->last_error = __( 'Invalid or expired discount code', 'invoicing' );
543
+            return;
544
+        }
545
+
546
+        // For single use discounts...
547
+        if ( $discount->is_single_use ) {
548
+
549
+            if ( ! $this->has_billing_email() ) {
550
+                $this->is_discount_valid = false;
551
+                $this->last_error = __( 'You need to enter your billing email before applying this discount', 'invoicing' );
552
+                return;
553
+            }
554
+
555
+            if ( ! $discount->is_valid_for_user( $this->get_billing_email() ) ) {
556
+                $this->is_discount_valid = false;
557
+                $this->last_error = __( 'You have already used this discount', 'invoicing' );
558
+                return;
559
+            }
560
+        }
561
+
562
+        // Set the discount.
563
+        $this->discount = $discount;
564
+
565
+    }
566
+
567
+    /**
568
+     * Removes an invalid discount code.
569
+     *
570
+     * @since 1.0.19
571
+     */
572
+    public function maybe_remove_discount() {
573
+
574
+        // Do we have a discount?
575
+        if ( empty( $this->has_discount_code() ) ) {
576
+            return;
577
+        }
578
+
579
+        // Fetch the discount amount.
580
+        $amount = $this->get_discount( 'Discount' );
581
+
582
+        // Abort early if this is a "zero" discount.
583
+        if ( empty( $amount ) ) {
584
+            return;
585
+        }
586
+
587
+        $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
588
+
589
+        if ( ! $this->discount->is_minimum_amount_met( $total ) ) {
590
+            $this->is_discount_valid = false;
591 591
             $min = wpinv_price( wpinv_format_amount( $$this->discount->min_total ) );
592
-			$this->last_error = sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
592
+            $this->last_error = sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
593 593
         }
594 594
 
595 595
         if ( ! $$this->discount->is_maximum_amount_met( $total ) ) {
596
-			$this->is_discount_valid = false;
596
+            $this->is_discount_valid = false;
597 597
             $max = wpinv_price( wpinv_format_amount( $$this->discount->max_total ) );
598
-			$this->last_error = sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
599
-		}
600
-
601
-		if ( ! $this->is_discount_valid ) {
602
-			$this->discount = null;
603
-			$this->remove_discount( 'Discount' );
604
-		}
605
-
606
-    }
607
-
608
-	/**
609
-	 * Maybe process discount.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @param GetPaid_Form_Item $item
613
-	 */
614
-	public function process_item_discount( $item ) {
615
-
616
-		// Abort early if there is no discount.
617
-		if ( ! $this->has_discount_code() ) {
618
-			return;
619
-		}
620
-
621
-		// Ensure that it is valid for this item.
622
-		if ( ! $this->discount->is_valid_for_items( array( $item->get_id() ) ) ) {
623
-			return;
624
-		}
625
-
626
-		// Fetch the discounted amount.
627
-		$discount = $this->discount->get_discounted_amount( $item->get_price() * $item->get_qantity() );
628
-
629
-		$this->add_discount( 'Discount', $discount );
630
-
631
-	}
632
-
633
-	/**
634
-	 * Returns the total discount amount.
635
-	 *
636
-	 * @since 1.0.19
637
-	 */
638
-	public function get_total_discount() {
639
-		return $this->total_discount_amount;
640
-	}
641
-
642
-	/**
643
-	 * Gets a specific discount.
644
-	 *
645
-	 * @since 1.0.19
646
-	 */
647
-	public function get_discount( $name ) {
648
-		return isset( $this->discounts[ $name ] ) ? $this->discounts[ $name ] : 0;
649
-	}
650
-
651
-	/**
652
-	 * Returns all discounts.
653
-	 *
654
-	 * @since 1.0.19
655
-	 */
656
-	public function get_discounts() {
657
-		return $this->discounts;
658
-	}
659
-
660
-	///////// FEES //////////////
661
-
662
-	/**
663
-	 * Adds a fee to the submission.
664
-	 *
665
-	 * @since 1.0.19
666
-	 */
667
-	public function add_fee( $name, $amount ) {
668
-		$amount = wpinv_sanitize_amount( $amount );
669
-
670
-		$this->total_fees_amount += $amount;
671
-
672
-		if ( isset( $this->fees[ $name ] ) ) {
673
-			$this->fees[ $name ] += $amount;
674
-		} else {
675
-			$this->fees[ $name ] = $amount;
676
-		}
677
-
678
-	}
679
-
680
-	/**
681
-	 * Returns the total fees amount.
682
-	 *
683
-	 * @since 1.0.19
684
-	 */
685
-	public function get_total_fees() {
686
-		return $this->total_fees_amount;
687
-	}
688
-
689
-	/**
690
-	 * Retrieves a specific fee.
691
-	 *
692
-	 * @since 1.0.19
693
-	 */
694
-	public function get_fee( $name ) {
695
-		return isset( $this->fees[ $name ] ) ? $this->fees[ $name ] : 0;
696
-	}
697
-
698
-	/**
699
-	 * Returns all fees.
700
-	 *
701
-	 * @since 1.0.19
702
-	 */
703
-	public function get_fees() {
704
-		return $this->fees;
705
-	}
706
-
707
-	// MISC //
708
-
709
-	/**
710
-	 * Returns the total amount to collect for this submission.
711
-	 *
712
-	 * @since 1.0.19
713
-	 */
714
-	public function get_total() {
715
-		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
716
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
717
-		return wpinv_sanitize_amount( $total );
718
-	}
719
-
720
-	/**
721
-	 * Whether payment details should be collected for this submission.
722
-	 *
723
-	 * @since 1.0.19
724
-	 */
725
-	public function get_payment_details() {
726
-		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
727
-
728
-		if ( $this->has_recurring ) {
729
-			$collect = true;
730
-		}
731
-
732
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
733
-		return $collect;
734
-	}
735
-
736
-	/**
737
-	 * Returns the billing email of the user.
738
-	 *
739
-	 * @since 1.0.19
740
-	 */
741
-	public function get_billing_email() {
742
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
743
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
744
-	}
745
-
746
-	/**
747
-	 * Checks if the submitter has a billing email.
748
-	 *
749
-	 * @since 1.0.19
750
-	 */
751
-	public function has_billing_email() {
752
-		$billing_email = $this->get_billing_email();
753
-		return ! empty( $billing_email );
754
-	}
598
+            $this->last_error = sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
599
+        }
600
+
601
+        if ( ! $this->is_discount_valid ) {
602
+            $this->discount = null;
603
+            $this->remove_discount( 'Discount' );
604
+        }
605
+
606
+    }
607
+
608
+    /**
609
+     * Maybe process discount.
610
+     *
611
+     * @since 1.0.19
612
+     * @param GetPaid_Form_Item $item
613
+     */
614
+    public function process_item_discount( $item ) {
615
+
616
+        // Abort early if there is no discount.
617
+        if ( ! $this->has_discount_code() ) {
618
+            return;
619
+        }
620
+
621
+        // Ensure that it is valid for this item.
622
+        if ( ! $this->discount->is_valid_for_items( array( $item->get_id() ) ) ) {
623
+            return;
624
+        }
625
+
626
+        // Fetch the discounted amount.
627
+        $discount = $this->discount->get_discounted_amount( $item->get_price() * $item->get_qantity() );
628
+
629
+        $this->add_discount( 'Discount', $discount );
630
+
631
+    }
632
+
633
+    /**
634
+     * Returns the total discount amount.
635
+     *
636
+     * @since 1.0.19
637
+     */
638
+    public function get_total_discount() {
639
+        return $this->total_discount_amount;
640
+    }
641
+
642
+    /**
643
+     * Gets a specific discount.
644
+     *
645
+     * @since 1.0.19
646
+     */
647
+    public function get_discount( $name ) {
648
+        return isset( $this->discounts[ $name ] ) ? $this->discounts[ $name ] : 0;
649
+    }
650
+
651
+    /**
652
+     * Returns all discounts.
653
+     *
654
+     * @since 1.0.19
655
+     */
656
+    public function get_discounts() {
657
+        return $this->discounts;
658
+    }
659
+
660
+    ///////// FEES //////////////
661
+
662
+    /**
663
+     * Adds a fee to the submission.
664
+     *
665
+     * @since 1.0.19
666
+     */
667
+    public function add_fee( $name, $amount ) {
668
+        $amount = wpinv_sanitize_amount( $amount );
669
+
670
+        $this->total_fees_amount += $amount;
671
+
672
+        if ( isset( $this->fees[ $name ] ) ) {
673
+            $this->fees[ $name ] += $amount;
674
+        } else {
675
+            $this->fees[ $name ] = $amount;
676
+        }
677
+
678
+    }
679
+
680
+    /**
681
+     * Returns the total fees amount.
682
+     *
683
+     * @since 1.0.19
684
+     */
685
+    public function get_total_fees() {
686
+        return $this->total_fees_amount;
687
+    }
688
+
689
+    /**
690
+     * Retrieves a specific fee.
691
+     *
692
+     * @since 1.0.19
693
+     */
694
+    public function get_fee( $name ) {
695
+        return isset( $this->fees[ $name ] ) ? $this->fees[ $name ] : 0;
696
+    }
697
+
698
+    /**
699
+     * Returns all fees.
700
+     *
701
+     * @since 1.0.19
702
+     */
703
+    public function get_fees() {
704
+        return $this->fees;
705
+    }
706
+
707
+    // MISC //
708
+
709
+    /**
710
+     * Returns the total amount to collect for this submission.
711
+     *
712
+     * @since 1.0.19
713
+     */
714
+    public function get_total() {
715
+        $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
716
+        $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
717
+        return wpinv_sanitize_amount( $total );
718
+    }
719
+
720
+    /**
721
+     * Whether payment details should be collected for this submission.
722
+     *
723
+     * @since 1.0.19
724
+     */
725
+    public function get_payment_details() {
726
+        $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
727
+
728
+        if ( $this->has_recurring ) {
729
+            $collect = true;
730
+        }
731
+
732
+        $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
733
+        return $collect;
734
+    }
735
+
736
+    /**
737
+     * Returns the billing email of the user.
738
+     *
739
+     * @since 1.0.19
740
+     */
741
+    public function get_billing_email() {
742
+        $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
743
+        return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
744
+    }
745
+
746
+    /**
747
+     * Checks if the submitter has a billing email.
748
+     *
749
+     * @since 1.0.19
750
+     */
751
+    public function has_billing_email() {
752
+        $billing_email = $this->get_billing_email();
753
+        return ! empty( $billing_email );
754
+    }
755 755
 
756 756
 }
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 		$this->state = wpinv_get_default_state();
148 148
 
149 149
 		// Do we have an actual submission?
150
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
151
-			$this->load_data( $_POST );
150
+		if (isset($_POST['getpaid_payment_form_submission'])) {
151
+			$this->load_data($_POST);
152 152
 		}
153 153
 	}
154 154
 
@@ -157,29 +157,29 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param array $data
159 159
 	 */
160
-	public function load_data( $data ) {
160
+	public function load_data($data) {
161 161
 
162 162
 		// Prepare submitted data...
163
-		$data = wp_unslash( $data );
163
+		$data = wp_unslash($data);
164 164
 
165 165
 		// Fitter the data.
166
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
166
+		$data = apply_filters('getpaid_submission_data', $data, $this);
167 167
 
168 168
 		$this->data = $data;
169 169
 
170
-		$this->id = md5( wp_json_encode( $data ) );
170
+		$this->id = md5(wp_json_encode($data));
171 171
 
172 172
 		// Every submission needs an active payment form.
173
-		if ( empty( $data['form_id'] ) ) {
174
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
173
+		if (empty($data['form_id'])) {
174
+			$this->last_error = __('Missing payment form', 'invoicing');
175 175
             return;
176 176
 		}
177 177
 
178 178
 		// Fetch the payment form.
179
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
179
+		$form = new GetPaid_Payment_Form($data['form_id']);
180 180
 
181
-		if ( ! $form->is_active() ) {
182
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
181
+		if (!$form->is_active()) {
182
+			$this->last_error = __('Payment form not active', 'invoicing');
183 183
 			return;
184 184
 		}
185 185
 
@@ -187,31 +187,31 @@  discard block
 block discarded – undo
187 187
 		$this->payment_form = $form;
188 188
 
189 189
 		// For existing invoices, make sure that it is valid.
190
-        if ( ! empty( $data['invoice_id'] ) ) {
191
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
190
+        if (!empty($data['invoice_id'])) {
191
+            $invoice = wpinv_get_invoice($data['invoice_id']);
192 192
 
193
-            if ( empty( $invoice ) ) {
194
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
193
+            if (empty($invoice)) {
194
+				$this->last_error = __('Invalid invoice', 'invoicing');
195 195
                 return;
196 196
             }
197 197
 
198
-			$this->payment_form->set_items( $invoice->cart_details );
198
+			$this->payment_form->set_items($invoice->cart_details);
199 199
 
200 200
 			$this->country = $invoice->country;
201 201
 			$this->state = $invoice->state;
202 202
 
203 203
 		// Default forms do not have items.
204
-        } else if ( $form->is_default() && isset( $data['form_items'] ) ) {
205
-			$this->payment_form->set_items( $data['form_items'] );
204
+        } else if ($form->is_default() && isset($data['form_items'])) {
205
+			$this->payment_form->set_items($data['form_items']);
206 206
 		}
207 207
 
208 208
 		// User's country.
209
-		if ( ! empty( $data['wpinv_country'] ) ) {
209
+		if (!empty($data['wpinv_country'])) {
210 210
 			$this->country = $data['wpinv_country'];
211 211
 		}
212 212
 
213 213
 		// User's state.
214
-		if ( ! empty( $data['wpinv_state'] ) ) {
214
+		if (!empty($data['wpinv_state'])) {
215 215
 			$this->country = $data['wpinv_state'];
216 216
 		}
217 217
 
@@ -220,47 +220,47 @@  discard block
 block discarded – undo
220 220
 
221 221
 		// Handle items.
222 222
 		$selected_items = array();
223
-		if ( ! empty( $data['getpaid-items'] ) ) {
224
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
223
+		if (!empty($data['getpaid-items'])) {
224
+			$selected_items = wpinv_clean($data['getpaid-items']);
225 225
 		}
226 226
 
227
-		foreach ( $this->payment_form->get_items() as $item ) {
227
+		foreach ($this->payment_form->get_items() as $item) {
228 228
 
229 229
 			// Continue if this is an optional item and it has not been selected.
230
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
230
+			if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
231 231
 				continue;
232 232
 			}
233 233
 
234 234
 			// (maybe) let customers change the quantities and prices.
235
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
235
+			if (isset($selected_items[$item->get_id()])) {
236 236
 
237 237
 				// Maybe change the quantities.
238
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
239
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
238
+				if ($item->allows_quantities() && is_numeric($selected_items[$item->get_id()]['quantity'])) {
239
+					$item->set_quantity((int) $selected_items[$item->get_id()]['quantity']);
240 240
 				}
241 241
 
242 242
 				// Maybe change the price.
243
-				if ( $item->user_can_set_their_price() ) {
244
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
243
+				if ($item->user_can_set_their_price()) {
244
+					$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
245 245
 
246 246
 					// But don't get lower than the minimum price.
247
-					if ( $price < $item->get_minimum_price() ) {
247
+					if ($price < $item->get_minimum_price()) {
248 248
 						$price = $item->get_minimum_price();
249 249
 					}
250 250
 
251
-					$item->set_price( $price );
251
+					$item->set_price($price);
252 252
 
253 253
 				}
254 254
 
255 255
 			}
256 256
 
257 257
 			// Add the item to the form.
258
-			$this->add_item( $item );
258
+			$this->add_item($item);
259 259
 
260 260
 		}
261 261
 
262 262
 		// Fired when we are done processing a submission.
263
-		do_action( 'getpaid_process_submission', $this );
263
+		do_action('getpaid_process_submission', $this);
264 264
 
265 265
 		// Remove invalid discount.
266 266
 		$this->maybe_remove_discount();
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 * @return bool
295 295
 	 */
296 296
 	public function has_invoice() {
297
-		return ! empty( $this->invoice );
297
+		return !empty($this->invoice);
298 298
 	}
299 299
 	
300 300
 	/**
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @return string
305 305
 	 */
306 306
 	public function get_currency() {
307
-		if ( $this->has_invoice() ) {
307
+		if ($this->has_invoice()) {
308 308
 			return $this->invoice->get_currency();
309 309
 		}
310 310
 		return wpinv_get_currency();
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 	 *
326 326
 	 * @since 1.0.19
327 327
 	 */
328
-	public function is_required_field_set( $field ) {
329
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
328
+	public function is_required_field_set($field) {
329
+		return empty($field['required']) || !empty($this->data[$field['id']]);
330 330
 	}
331 331
 
332 332
 	///////// Items //////////////
@@ -337,25 +337,25 @@  discard block
 block discarded – undo
337 337
 	 * @since 1.0.19
338 338
 	 * @param GetPaid_Form_Item $item
339 339
 	 */
340
-	public function add_item( $item ) {
340
+	public function add_item($item) {
341 341
 
342 342
 		// Make sure that it is available for purchase.
343
-		if ( ! $item->can_purchase() ) {
343
+		if (!$item->can_purchase()) {
344 344
 			return;
345 345
 		}
346 346
 
347 347
 		// Do we have a recurring item?
348
-		if ( $item->is_recurring() ) {
348
+		if ($item->is_recurring()) {
349 349
 			$this->has_recurring = true;
350 350
 		}
351 351
 
352
-		$this->items[ $item->get_id() ] = $item;
352
+		$this->items[$item->get_id()] = $item;
353 353
 
354 354
 		$this->subtotal_amount += $item->get_sub_total();
355 355
 
356
-		$this->process_item_discount( $item );
356
+		$this->process_item_discount($item);
357 357
 
358
-		$this->process_item_tax( $item );
358
+		$this->process_item_tax($item);
359 359
 	}
360 360
 
361 361
 	/**
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @since 1.0.19
365 365
 	 */
366
-	public function get_item( $item_id ) {
367
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
366
+	public function get_item($item_id) {
367
+		return isset($this->items[$item_id]) ? $this->items[$item_id] : null;
368 368
 	}
369 369
 
370 370
 	/**
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
 	 *
385 385
 	 * @since 1.0.19
386 386
 	 */
387
-	public function add_tax( $name, $amount ) {
388
-		$amount = (float) wpinv_sanitize_amount( $amount );
387
+	public function add_tax($name, $amount) {
388
+		$amount = (float) wpinv_sanitize_amount($amount);
389 389
 
390 390
 		$this->total_tax_amount += $amount;
391 391
 
392
-		if ( isset( $this->taxes[ $name ] ) ) {
393
-			$this->taxes[ $name ] += $amount;
392
+		if (isset($this->taxes[$name])) {
393
+			$this->taxes[$name] += $amount;
394 394
 		} else {
395
-			$this->taxes[ $name ] = $amount;
395
+			$this->taxes[$name] = $amount;
396 396
 		}
397 397
 
398 398
 	}
@@ -406,11 +406,11 @@  discard block
 block discarded – undo
406 406
 
407 407
 		$use_taxes = wpinv_use_taxes();
408 408
 
409
-		if ( $this->has_invoice() && $this->invoice->disable_taxes ) {
409
+		if ($this->has_invoice() && $this->invoice->disable_taxes) {
410 410
 			$use_taxes = false;
411 411
 		}
412 412
 
413
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
413
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
414 414
 
415 415
 	}
416 416
 
@@ -420,23 +420,23 @@  discard block
 block discarded – undo
420 420
 	 * @since 1.0.19 
421 421
 	 * @param GetPaid_Form_Item $item
422 422
 	 */
423
-	public function process_item_tax( $item ) {
423
+	public function process_item_tax($item) {
424 424
 
425 425
 		// Abort early if we're not using taxes.
426
-		if ( ! $this->use_taxes() ) {
426
+		if (!$this->use_taxes()) {
427 427
 			return;
428 428
 		}
429 429
 
430
-		$rate  = wpinv_get_tax_rate( $this->country, $this->state, $item->get_id() );
430
+		$rate  = wpinv_get_tax_rate($this->country, $this->state, $item->get_id());
431 431
 		$price = $item->get_sub_total();
432 432
 
433
-		if ( wpinv_prices_include_tax() ) {
434
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
433
+		if (wpinv_prices_include_tax()) {
434
+			$item_tax = $price - ($price - $price * $rate * 0.01);
435 435
 		} else {
436 436
 			$item_tax = $price * $rate * 0.01;
437 437
 		}
438 438
 
439
-		$this->add_tax( 'Tax', $item_tax );
439
+		$this->add_tax('Tax', $item_tax);
440 440
 
441 441
 	}
442 442
 
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 *
455 455
 	 * @since 1.0.19
456 456
 	 */
457
-	public function get_tax( $name ) {
458
-		return isset( $this->taxes[ $name ] ) ? $this->taxes[ $name ] : 0;
457
+	public function get_tax($name) {
458
+		return isset($this->taxes[$name]) ? $this->taxes[$name] : 0;
459 459
 	}
460 460
 
461 461
 	/**
@@ -474,15 +474,15 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @since 1.0.19
476 476
 	 */
477
-	public function add_discount( $name, $amount ) {
478
-		$amount = wpinv_sanitize_amount( $amount );
477
+	public function add_discount($name, $amount) {
478
+		$amount = wpinv_sanitize_amount($amount);
479 479
 
480 480
 		$this->total_discount_amount += $amount;
481 481
 
482
-		if ( isset( $this->discounts[ $name ] ) ) {
483
-			$this->discounts[ $name ] += $amount;
482
+		if (isset($this->discounts[$name])) {
483
+			$this->discounts[$name] += $amount;
484 484
 		} else {
485
-			$this->discounts[ $name ] = $amount;
485
+			$this->discounts[$name] = $amount;
486 486
 		}
487 487
 
488 488
 	}
@@ -492,11 +492,11 @@  discard block
 block discarded – undo
492 492
 	 *
493 493
 	 * @since 1.0.19
494 494
 	 */
495
-	public function remove_discount( $name ) {
495
+	public function remove_discount($name) {
496 496
 
497
-		if ( isset( $this->discounts[ $name ] ) ) {
498
-			$this->total_discount_amount -= $this->discounts[ $name ];
499
-			unset( $this->discounts[ $name ] );
497
+		if (isset($this->discounts[$name])) {
498
+			$this->total_discount_amount -= $this->discounts[$name];
499
+			unset($this->discounts[$name]);
500 500
 		}
501 501
 
502 502
 	}
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 	 * @return bool
509 509
 	 */
510 510
 	public function has_discount_code() {
511
-		return ! empty( $this->discount );
511
+		return !empty($this->discount);
512 512
 	}
513 513
 
514 514
 	/**
@@ -529,32 +529,32 @@  discard block
 block discarded – undo
529 529
 	public function maybe_prepare_discount() {
530 530
 
531 531
 		// Do we have a discount?
532
-		if ( empty( $this->data['discount'] ) ) {
532
+		if (empty($this->data['discount'])) {
533 533
 			return;
534 534
 		}
535 535
 
536 536
 		// Fetch the discount.
537
-		$discount = wpinv_get_discount_obj( $this->data['discount'] );
537
+		$discount = wpinv_get_discount_obj($this->data['discount']);
538 538
 
539 539
 		// Ensure it is active.
540
-        if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) {
540
+        if (!$discount->exists() || !$discount->is_active() || !$discount->has_started() || $discount->is_expired()) {
541 541
 			$this->is_discount_valid = false;
542
-			$this->last_error = __( 'Invalid or expired discount code', 'invoicing' );
542
+			$this->last_error = __('Invalid or expired discount code', 'invoicing');
543 543
 			return;
544 544
 		}
545 545
 
546 546
 		// For single use discounts...
547
-		if ( $discount->is_single_use ) {
547
+		if ($discount->is_single_use) {
548 548
 
549
-			if ( ! $this->has_billing_email() ) {
549
+			if (!$this->has_billing_email()) {
550 550
 				$this->is_discount_valid = false;
551
-				$this->last_error = __( 'You need to enter your billing email before applying this discount', 'invoicing' );
551
+				$this->last_error = __('You need to enter your billing email before applying this discount', 'invoicing');
552 552
 				return;
553 553
 			}
554 554
 
555
-			if ( ! $discount->is_valid_for_user( $this->get_billing_email() ) ) {
555
+			if (!$discount->is_valid_for_user($this->get_billing_email())) {
556 556
 				$this->is_discount_valid = false;
557
-				$this->last_error = __( 'You have already used this discount', 'invoicing' );
557
+				$this->last_error = __('You have already used this discount', 'invoicing');
558 558
 				return;
559 559
 			}
560 560
 		}
@@ -572,35 +572,35 @@  discard block
 block discarded – undo
572 572
 	public function maybe_remove_discount() {
573 573
 
574 574
 		// Do we have a discount?
575
-		if ( empty( $this->has_discount_code() ) ) {
575
+		if (empty($this->has_discount_code())) {
576 576
 			return;
577 577
 		}
578 578
 
579 579
 		// Fetch the discount amount.
580
-		$amount = $this->get_discount( 'Discount' );
580
+		$amount = $this->get_discount('Discount');
581 581
 
582 582
 		// Abort early if this is a "zero" discount.
583
-		if ( empty( $amount ) ) {
583
+		if (empty($amount)) {
584 584
 			return;
585 585
 		}
586 586
 
587 587
 		$total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
588 588
 
589
-		if ( ! $this->discount->is_minimum_amount_met( $total ) ) {
589
+		if (!$this->discount->is_minimum_amount_met($total)) {
590 590
 			$this->is_discount_valid = false;
591
-            $min = wpinv_price( wpinv_format_amount( $$this->discount->min_total ) );
592
-			$this->last_error = sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
591
+            $min = wpinv_price(wpinv_format_amount($$this->discount->min_total));
592
+			$this->last_error = sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min);
593 593
         }
594 594
 
595
-        if ( ! $$this->discount->is_maximum_amount_met( $total ) ) {
595
+        if (!$$this->discount->is_maximum_amount_met($total)) {
596 596
 			$this->is_discount_valid = false;
597
-            $max = wpinv_price( wpinv_format_amount( $$this->discount->max_total ) );
598
-			$this->last_error = sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
597
+            $max = wpinv_price(wpinv_format_amount($$this->discount->max_total));
598
+			$this->last_error = sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max);
599 599
 		}
600 600
 
601
-		if ( ! $this->is_discount_valid ) {
601
+		if (!$this->is_discount_valid) {
602 602
 			$this->discount = null;
603
-			$this->remove_discount( 'Discount' );
603
+			$this->remove_discount('Discount');
604 604
 		}
605 605
 
606 606
     }
@@ -611,22 +611,22 @@  discard block
 block discarded – undo
611 611
 	 * @since 1.0.19
612 612
 	 * @param GetPaid_Form_Item $item
613 613
 	 */
614
-	public function process_item_discount( $item ) {
614
+	public function process_item_discount($item) {
615 615
 
616 616
 		// Abort early if there is no discount.
617
-		if ( ! $this->has_discount_code() ) {
617
+		if (!$this->has_discount_code()) {
618 618
 			return;
619 619
 		}
620 620
 
621 621
 		// Ensure that it is valid for this item.
622
-		if ( ! $this->discount->is_valid_for_items( array( $item->get_id() ) ) ) {
622
+		if (!$this->discount->is_valid_for_items(array($item->get_id()))) {
623 623
 			return;
624 624
 		}
625 625
 
626 626
 		// Fetch the discounted amount.
627
-		$discount = $this->discount->get_discounted_amount( $item->get_price() * $item->get_qantity() );
627
+		$discount = $this->discount->get_discounted_amount($item->get_price() * $item->get_qantity());
628 628
 
629
-		$this->add_discount( 'Discount', $discount );
629
+		$this->add_discount('Discount', $discount);
630 630
 
631 631
 	}
632 632
 
@@ -644,8 +644,8 @@  discard block
 block discarded – undo
644 644
 	 *
645 645
 	 * @since 1.0.19
646 646
 	 */
647
-	public function get_discount( $name ) {
648
-		return isset( $this->discounts[ $name ] ) ? $this->discounts[ $name ] : 0;
647
+	public function get_discount($name) {
648
+		return isset($this->discounts[$name]) ? $this->discounts[$name] : 0;
649 649
 	}
650 650
 
651 651
 	/**
@@ -664,15 +664,15 @@  discard block
 block discarded – undo
664 664
 	 *
665 665
 	 * @since 1.0.19
666 666
 	 */
667
-	public function add_fee( $name, $amount ) {
668
-		$amount = wpinv_sanitize_amount( $amount );
667
+	public function add_fee($name, $amount) {
668
+		$amount = wpinv_sanitize_amount($amount);
669 669
 
670 670
 		$this->total_fees_amount += $amount;
671 671
 
672
-		if ( isset( $this->fees[ $name ] ) ) {
673
-			$this->fees[ $name ] += $amount;
672
+		if (isset($this->fees[$name])) {
673
+			$this->fees[$name] += $amount;
674 674
 		} else {
675
-			$this->fees[ $name ] = $amount;
675
+			$this->fees[$name] = $amount;
676 676
 		}
677 677
 
678 678
 	}
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 	 *
692 692
 	 * @since 1.0.19
693 693
 	 */
694
-	public function get_fee( $name ) {
695
-		return isset( $this->fees[ $name ] ) ? $this->fees[ $name ] : 0;
694
+	public function get_fee($name) {
695
+		return isset($this->fees[$name]) ? $this->fees[$name] : 0;
696 696
 	}
697 697
 
698 698
 	/**
@@ -713,8 +713,8 @@  discard block
 block discarded – undo
713 713
 	 */
714 714
 	public function get_total() {
715 715
 		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
716
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
717
-		return wpinv_sanitize_amount( $total );
716
+		$total = apply_filters('getpaid_get_submission_total_amount', $total, $this);
717
+		return wpinv_sanitize_amount($total);
718 718
 	}
719 719
 
720 720
 	/**
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
 	public function get_payment_details() {
726 726
 		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
727 727
 
728
-		if ( $this->has_recurring ) {
728
+		if ($this->has_recurring) {
729 729
 			$collect = true;
730 730
 		}
731 731
 
732
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
732
+		$collect = apply_filters('getpaid_submission_collect_payment_details', $collect, $this);
733 733
 		return $collect;
734 734
 	}
735 735
 
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
 	 * @since 1.0.19
740 740
 	 */
741 741
 	public function get_billing_email() {
742
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
743
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
742
+		$billing_email = empty($this->data['billing_email']) ? '' : $this->data['billing_email'];
743
+		return apply_filters('getpaid_get_submission_billing_email', $billing_email, $this);
744 744
 	}
745 745
 
746 746
 	/**
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 	 */
751 751
 	public function has_billing_email() {
752 752
 		$billing_email = $this->get_billing_email();
753
-		return ! empty( $billing_email );
753
+		return !empty($billing_email);
754 754
 	}
755 755
 
756 756
 }
Please login to merge, or discard this patch.
includes/class-wpinv-discount.php 2 patches
Indentation   +1284 added lines, -1284 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Discount extends GetPaid_Data  {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23 23
     protected $data_store_name = 'discount';
24 24
 
25 25
     /**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'discount';
31
-
32
-	/**
33
-	 * Discount Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'status'               => 'draft',
40
-		'version'              => '',
41
-		'date_created'         => null,
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'discount';
31
+
32
+    /**
33
+     * Discount Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'status'               => 'draft',
40
+        'version'              => '',
41
+        'date_created'         => null,
42 42
         'date_modified'        => null,
43 43
         'name'                 => 'no-name',
44 44
         'description'          => null,
@@ -58,144 +58,144 @@  discard block
 block discarded – undo
58 58
         'amount'               => null,
59 59
     );
60 60
 
61
-	/**
62
-	 * Stores meta in cache for future reads.
63
-	 *
64
-	 * A group must be set to to enable caching.
65
-	 *
66
-	 * @var string
67
-	 */
68
-	protected $cache_group = 'getpaid_discounts';
61
+    /**
62
+     * Stores meta in cache for future reads.
63
+     *
64
+     * A group must be set to to enable caching.
65
+     *
66
+     * @var string
67
+     */
68
+    protected $cache_group = 'getpaid_discounts';
69 69
 
70 70
     /**
71 71
      * Stores a reference to the original WP_Post object
72 72
      *
73 73
      * @var WP_Post
74 74
      */
75
-	protected $post = null;
76
-
77
-	/**
78
-	 * Get the discount if ID is passed, otherwise the discount is new and empty.
79
-	 *
80
-	 * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code.
81
-	 */
82
-	public function __construct( $discount = 0 ) {
83
-		parent::__construct( $discount );
84
-
85
-		if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) {
86
-			$this->set_id( $discount );
87
-		} elseif ( $discount instanceof self ) {
88
-			$this->set_id( $discount->get_id() );
89
-		} elseif ( ! empty( $discount->ID ) ) {
90
-			$this->set_id( $discount->ID );
91
-		} elseif ( is_array( $discount ) ) {
92
-			$this->set_props( $discount );
93
-
94
-			if ( isset( $discount['ID'] ) ) {
95
-				$this->set_id( $discount['ID'] );
96
-			}
97
-
98
-		} elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) {
99
-			$this->set_id( $discount );
100
-		} else {
101
-			$this->set_object_read( true );
102
-		}
75
+    protected $post = null;
76
+
77
+    /**
78
+     * Get the discount if ID is passed, otherwise the discount is new and empty.
79
+     *
80
+     * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code.
81
+     */
82
+    public function __construct( $discount = 0 ) {
83
+        parent::__construct( $discount );
84
+
85
+        if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) {
86
+            $this->set_id( $discount );
87
+        } elseif ( $discount instanceof self ) {
88
+            $this->set_id( $discount->get_id() );
89
+        } elseif ( ! empty( $discount->ID ) ) {
90
+            $this->set_id( $discount->ID );
91
+        } elseif ( is_array( $discount ) ) {
92
+            $this->set_props( $discount );
93
+
94
+            if ( isset( $discount['ID'] ) ) {
95
+                $this->set_id( $discount['ID'] );
96
+            }
97
+
98
+        } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) {
99
+            $this->set_id( $discount );
100
+        } else {
101
+            $this->set_object_read( true );
102
+        }
103 103
 
104 104
         // Load the datastore.
105
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
105
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
106 106
 
107
-		if ( $this->get_id() > 0 ) {
107
+        if ( $this->get_id() > 0 ) {
108 108
             $this->post = get_post( $this->get_id() );
109 109
             $this->ID   = $this->get_id();
110
-			$this->data_store->read( $this );
110
+            $this->data_store->read( $this );
111
+        }
112
+
113
+    }
114
+
115
+    /**
116
+     * Fetch a discount from the db/cache
117
+     *
118
+     *
119
+     * @static
120
+     * @param string $field The field to query against: 'ID', 'discount_code'
121
+     * @param string|int $value The field value
122
+     * @deprecated
123
+     * @since 1.0.15
124
+     * @return array|bool array of discount details on success. False otherwise.
125
+     */
126
+    public static function get_data_by( $field, $value ) {
127
+
128
+        if ( 'id' == strtolower( $field ) ) {
129
+            // Make sure the value is numeric to avoid casting objects, for example,
130
+            // to int 1.
131
+            if ( ! is_numeric( $value ) )
132
+                return false;
133
+            $value = intval( $value );
134
+            if ( $value < 1 )
135
+                return false;
136
+        }
137
+
138
+        if ( ! $value || ! is_string( $field ) ) {
139
+            return false;
140
+        }
141
+
142
+        $field = trim( $field );
143
+
144
+        // prepare query args
145
+        switch ( strtolower( $field ) ) {
146
+            case 'id':
147
+                $discount_id = $value;
148
+                $args		 = array( 'include' => array( $value ) );
149
+                break;
150
+            case 'discount_code':
151
+            case 'code':
152
+                $value       = trim( $value );
153
+                $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
154
+                $args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
155
+                break;
156
+            case 'name':
157
+                $discount_id = 0;
158
+                $args		 = array( 'name' => trim( $value ) );
159
+                break;
160
+            default:
161
+                $args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
162
+                if ( ! is_array( $args ) ) {
163
+                    return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
164
+                }
165
+
166
+        }
167
+
168
+        // Check if there is a cached value.
169
+        if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
170
+            return $discount;
171
+        }
172
+
173
+        $args = array_merge(
174
+            $args,
175
+            array(
176
+                'post_type'      => 'wpi_discount',
177
+                'posts_per_page' => 1,
178
+                'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
179
+            )
180
+        );
181
+
182
+        $discount = get_posts( $args );
183
+
184
+        if( empty( $discount ) ) {
185
+            return false;
111 186
         }
112 187
 
113
-	}
114
-
115
-	/**
116
-	 * Fetch a discount from the db/cache
117
-	 *
118
-	 *
119
-	 * @static
120
-	 * @param string $field The field to query against: 'ID', 'discount_code'
121
-	 * @param string|int $value The field value
122
-	 * @deprecated
123
-	 * @since 1.0.15
124
-	 * @return array|bool array of discount details on success. False otherwise.
125
-	 */
126
-	public static function get_data_by( $field, $value ) {
127
-
128
-		if ( 'id' == strtolower( $field ) ) {
129
-			// Make sure the value is numeric to avoid casting objects, for example,
130
-			// to int 1.
131
-			if ( ! is_numeric( $value ) )
132
-				return false;
133
-			$value = intval( $value );
134
-			if ( $value < 1 )
135
-				return false;
136
-		}
137
-
138
-		if ( ! $value || ! is_string( $field ) ) {
139
-			return false;
140
-		}
141
-
142
-		$field = trim( $field );
143
-
144
-		// prepare query args
145
-		switch ( strtolower( $field ) ) {
146
-			case 'id':
147
-				$discount_id = $value;
148
-				$args		 = array( 'include' => array( $value ) );
149
-				break;
150
-			case 'discount_code':
151
-			case 'code':
152
-				$value       = trim( $value );
153
-				$discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
154
-				$args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
155
-				break;
156
-			case 'name':
157
-				$discount_id = 0;
158
-				$args		 = array( 'name' => trim( $value ) );
159
-				break;
160
-			default:
161
-				$args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
162
-				if ( ! is_array( $args ) ) {
163
-					return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
164
-				}
165
-
166
-		}
167
-
168
-		// Check if there is a cached value.
169
-		if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
170
-			return $discount;
171
-		}
172
-
173
-		$args = array_merge(
174
-			$args,
175
-			array(
176
-				'post_type'      => 'wpi_discount',
177
-				'posts_per_page' => 1,
178
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
179
-			)
180
-		);
181
-
182
-		$discount = get_posts( $args );
183
-
184
-		if( empty( $discount ) ) {
185
-			return false;
186
-		}
187
-
188
-		$discount = $discount[0];
189
-
190
-		// Prepare the return data.
191
-		$return = array(
188
+        $discount = $discount[0];
189
+
190
+        // Prepare the return data.
191
+        $return = array(
192 192
             'ID'                          => $discount->ID,
193 193
             'code'                        => get_post_meta( $discount->ID, '_wpi_discount_code', true ),
194 194
             'amount'                      => get_post_meta( $discount->ID, '_wpi_discount_amount', true ),
195 195
             'date_created'                => $discount->post_date,
196
-			'date_modified'               => $discount->post_modified,
197
-			'status'               		  => $discount->post_status,
198
-			'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
196
+            'date_modified'               => $discount->post_modified,
197
+            'status'               		  => $discount->post_status,
198
+            'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
199 199
             'expiration'                  => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ),
200 200
             'type'               		  => get_post_meta( $discount->ID, '_wpi_discount_type', true ),
201 201
             'description'                 => $discount->post_excerpt,
@@ -209,77 +209,77 @@  discard block
 block discarded – undo
209 209
             'max_total'                   => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ),
210 210
         );
211 211
 
212
-		$return = apply_filters( 'wpinv_discount_properties', $return );
213
-
214
-		// Update the cache with our data
215
-		wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
216
-		wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
217
-
218
-		return $return;
219
-	}
220
-
221
-	/**
222
-	 * Given a discount code, it returns a discount id.
223
-	 *
224
-	 *
225
-	 * @static
226
-	 * @param string $discount_code
227
-	 * @since 1.0.15
228
-	 * @return int
229
-	 */
230
-	public static function get_discount_id_by_code( $discount_code ) {
231
-
232
-		// Trim the code.
233
-		$discount_code = trim( $discount_code );
234
-
235
-		// Ensure a value has been passed.
236
-		if ( empty( $discount_code ) ) {
237
-			return 0;
238
-		}
239
-
240
-		// Maybe retrieve from the cache.
241
-		$discount_id   = wp_cache_get( $discount_code, 'getpaid_discount_codes' );
242
-		if ( ! empty( $discount_id ) ) {
243
-			return $discount_id;
244
-		}
245
-
246
-		// Fetch the first discount codes.
247
-		$discounts = get_posts(
248
-			array(
249
-				'meta_key'       => '_wpi_discount_code',
250
-				'meta_value'     => $discount_code,
251
-				'post_type'      => 'wpi_discount',
252
-				'posts_per_page' => 1,
253
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' ),
254
-				'fields'         => 'ids',
255
-			)
256
-		);
257
-
258
-		if ( empty( $discounts ) ) {
259
-			return 0;
260
-		}
261
-
262
-		$discount_id = $discounts[0];
263
-
264
-		// Update the cache with our data
265
-		wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' );
266
-
267
-		return $discount_id;
268
-	}
269
-
270
-	/**
271
-	 * Magic method for checking the existence of a certain custom field.
272
-	 *
273
-	 * @since 1.0.15
274
-	 * @access public
275
-	 *
276
-	 * @return bool Whether the given discount field is set.
277
-	 */
278
-	public function __isset( $key ){
279
-		return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
280
-	}
281
-
282
-	/*
212
+        $return = apply_filters( 'wpinv_discount_properties', $return );
213
+
214
+        // Update the cache with our data
215
+        wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
216
+        wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
217
+
218
+        return $return;
219
+    }
220
+
221
+    /**
222
+     * Given a discount code, it returns a discount id.
223
+     *
224
+     *
225
+     * @static
226
+     * @param string $discount_code
227
+     * @since 1.0.15
228
+     * @return int
229
+     */
230
+    public static function get_discount_id_by_code( $discount_code ) {
231
+
232
+        // Trim the code.
233
+        $discount_code = trim( $discount_code );
234
+
235
+        // Ensure a value has been passed.
236
+        if ( empty( $discount_code ) ) {
237
+            return 0;
238
+        }
239
+
240
+        // Maybe retrieve from the cache.
241
+        $discount_id   = wp_cache_get( $discount_code, 'getpaid_discount_codes' );
242
+        if ( ! empty( $discount_id ) ) {
243
+            return $discount_id;
244
+        }
245
+
246
+        // Fetch the first discount codes.
247
+        $discounts = get_posts(
248
+            array(
249
+                'meta_key'       => '_wpi_discount_code',
250
+                'meta_value'     => $discount_code,
251
+                'post_type'      => 'wpi_discount',
252
+                'posts_per_page' => 1,
253
+                'post_status'    => array( 'publish', 'pending', 'draft', 'expired' ),
254
+                'fields'         => 'ids',
255
+            )
256
+        );
257
+
258
+        if ( empty( $discounts ) ) {
259
+            return 0;
260
+        }
261
+
262
+        $discount_id = $discounts[0];
263
+
264
+        // Update the cache with our data
265
+        wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' );
266
+
267
+        return $discount_id;
268
+    }
269
+
270
+    /**
271
+     * Magic method for checking the existence of a certain custom field.
272
+     *
273
+     * @since 1.0.15
274
+     * @access public
275
+     *
276
+     * @return bool Whether the given discount field is set.
277
+     */
278
+    public function __isset( $key ){
279
+        return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
280
+    }
281
+
282
+    /*
283 283
 	|--------------------------------------------------------------------------
284 284
 	| CRUD methods
285 285
 	|--------------------------------------------------------------------------
@@ -294,440 +294,440 @@  discard block
 block discarded – undo
294 294
 	|--------------------------------------------------------------------------
295 295
 	*/
296 296
 
297
-	/**
298
-	 * Get discount status.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_status( $context = 'view' ) {
305
-		return $this->get_prop( 'status', $context );
297
+    /**
298
+     * Get discount status.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_status( $context = 'view' ) {
305
+        return $this->get_prop( 'status', $context );
306 306
     }
307 307
 
308 308
     /**
309
-	 * Get plugin version when the discount was created.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return string
314
-	 */
315
-	public function get_version( $context = 'view' ) {
316
-		return $this->get_prop( 'version', $context );
309
+     * Get plugin version when the discount was created.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return string
314
+     */
315
+    public function get_version( $context = 'view' ) {
316
+        return $this->get_prop( 'version', $context );
317 317
     }
318 318
 
319 319
     /**
320
-	 * Get date when the discount was created.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return string
325
-	 */
326
-	public function get_date_created( $context = 'view' ) {
327
-		return $this->get_prop( 'date_created', $context );
320
+     * Get date when the discount was created.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return string
325
+     */
326
+    public function get_date_created( $context = 'view' ) {
327
+        return $this->get_prop( 'date_created', $context );
328 328
     }
329 329
 
330 330
     /**
331
-	 * Get GMT date when the discount was created.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return string
336
-	 */
337
-	public function get_date_created_gmt( $context = 'view' ) {
331
+     * Get GMT date when the discount was created.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return string
336
+     */
337
+    public function get_date_created_gmt( $context = 'view' ) {
338 338
         $date = $this->get_date_created( $context );
339 339
 
340 340
         if ( $date ) {
341 341
             $date = get_gmt_from_date( $date );
342 342
         }
343
-		return $date;
343
+        return $date;
344 344
     }
345 345
 
346 346
     /**
347
-	 * Get date when the discount was last modified.
348
-	 *
349
-	 * @since 1.0.19
350
-	 * @param  string $context View or edit context.
351
-	 * @return string
352
-	 */
353
-	public function get_date_modified( $context = 'view' ) {
354
-		return $this->get_prop( 'date_modified', $context );
347
+     * Get date when the discount was last modified.
348
+     *
349
+     * @since 1.0.19
350
+     * @param  string $context View or edit context.
351
+     * @return string
352
+     */
353
+    public function get_date_modified( $context = 'view' ) {
354
+        return $this->get_prop( 'date_modified', $context );
355 355
     }
356 356
 
357 357
     /**
358
-	 * Get GMT date when the discount was last modified.
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  string $context View or edit context.
362
-	 * @return string
363
-	 */
364
-	public function get_date_modified_gmt( $context = 'view' ) {
358
+     * Get GMT date when the discount was last modified.
359
+     *
360
+     * @since 1.0.19
361
+     * @param  string $context View or edit context.
362
+     * @return string
363
+     */
364
+    public function get_date_modified_gmt( $context = 'view' ) {
365 365
         $date = $this->get_date_modified( $context );
366 366
 
367 367
         if ( $date ) {
368 368
             $date = get_gmt_from_date( $date );
369 369
         }
370
-		return $date;
370
+        return $date;
371 371
     }
372 372
 
373 373
     /**
374
-	 * Get the discount name.
375
-	 *
376
-	 * @since 1.0.19
377
-	 * @param  string $context View or edit context.
378
-	 * @return string
379
-	 */
380
-	public function get_name( $context = 'view' ) {
381
-		return $this->get_prop( 'name', $context );
374
+     * Get the discount name.
375
+     *
376
+     * @since 1.0.19
377
+     * @param  string $context View or edit context.
378
+     * @return string
379
+     */
380
+    public function get_name( $context = 'view' ) {
381
+        return $this->get_prop( 'name', $context );
382 382
     }
383 383
 
384 384
     /**
385
-	 * Alias of self::get_name().
386
-	 *
387
-	 * @since 1.0.19
388
-	 * @param  string $context View or edit context.
389
-	 * @return string
390
-	 */
391
-	public function get_title( $context = 'view' ) {
392
-		return $this->get_name( $context );
385
+     * Alias of self::get_name().
386
+     *
387
+     * @since 1.0.19
388
+     * @param  string $context View or edit context.
389
+     * @return string
390
+     */
391
+    public function get_title( $context = 'view' ) {
392
+        return $this->get_name( $context );
393 393
     }
394 394
 
395 395
     /**
396
-	 * Get the discount description.
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @param  string $context View or edit context.
400
-	 * @return string
401
-	 */
402
-	public function get_description( $context = 'view' ) {
403
-		return $this->get_prop( 'description', $context );
396
+     * Get the discount description.
397
+     *
398
+     * @since 1.0.19
399
+     * @param  string $context View or edit context.
400
+     * @return string
401
+     */
402
+    public function get_description( $context = 'view' ) {
403
+        return $this->get_prop( 'description', $context );
404 404
     }
405 405
 
406 406
     /**
407
-	 * Alias of self::get_description().
408
-	 *
409
-	 * @since 1.0.19
410
-	 * @param  string $context View or edit context.
411
-	 * @return string
412
-	 */
413
-	public function get_excerpt( $context = 'view' ) {
414
-		return $this->get_description( $context );
407
+     * Alias of self::get_description().
408
+     *
409
+     * @since 1.0.19
410
+     * @param  string $context View or edit context.
411
+     * @return string
412
+     */
413
+    public function get_excerpt( $context = 'view' ) {
414
+        return $this->get_description( $context );
415 415
     }
416 416
 
417 417
     /**
418
-	 * Alias of self::get_description().
419
-	 *
420
-	 * @since 1.0.19
421
-	 * @param  string $context View or edit context.
422
-	 * @return string
423
-	 */
424
-	public function get_summary( $context = 'view' ) {
425
-		return $this->get_description( $context );
418
+     * Alias of self::get_description().
419
+     *
420
+     * @since 1.0.19
421
+     * @param  string $context View or edit context.
422
+     * @return string
423
+     */
424
+    public function get_summary( $context = 'view' ) {
425
+        return $this->get_description( $context );
426 426
     }
427 427
 
428 428
     /**
429
-	 * Get the owner of the discount.
430
-	 *
431
-	 * @since 1.0.19
432
-	 * @param  string $context View or edit context.
433
-	 * @return string
434
-	 */
435
-	public function get_author( $context = 'view' ) {
436
-		return (int) $this->get_prop( 'author', $context );
437
-	}
429
+     * Get the owner of the discount.
430
+     *
431
+     * @since 1.0.19
432
+     * @param  string $context View or edit context.
433
+     * @return string
434
+     */
435
+    public function get_author( $context = 'view' ) {
436
+        return (int) $this->get_prop( 'author', $context );
437
+    }
438 438
 	
439
-	/**
440
-	 * Get the discount code.
441
-	 *
442
-	 * @since 1.0.19
443
-	 * @param  string $context View or edit context.
444
-	 * @return string
445
-	 */
446
-	public function get_code( $context = 'view' ) {
447
-		return $this->get_prop( 'code', $context );
448
-	}
439
+    /**
440
+     * Get the discount code.
441
+     *
442
+     * @since 1.0.19
443
+     * @param  string $context View or edit context.
444
+     * @return string
445
+     */
446
+    public function get_code( $context = 'view' ) {
447
+        return $this->get_prop( 'code', $context );
448
+    }
449 449
 	
450
-	/**
451
-	 * Alias for self::get_code().
452
-	 *
453
-	 * @since 1.0.19
454
-	 * @param  string $context View or edit context.
455
-	 * @return string
456
-	 */
457
-	public function get_coupon_code( $context = 'view' ) {
458
-		return $this->get_code( $context );
459
-	}
450
+    /**
451
+     * Alias for self::get_code().
452
+     *
453
+     * @since 1.0.19
454
+     * @param  string $context View or edit context.
455
+     * @return string
456
+     */
457
+    public function get_coupon_code( $context = 'view' ) {
458
+        return $this->get_code( $context );
459
+    }
460 460
 	
461
-	/**
462
-	 * Alias for self::get_code().
463
-	 *
464
-	 * @since 1.0.19
465
-	 * @param  string $context View or edit context.
466
-	 * @return string
467
-	 */
468
-	public function get_discount_code( $context = 'view' ) {
469
-		return $this->get_code( $context );
470
-	}
461
+    /**
462
+     * Alias for self::get_code().
463
+     *
464
+     * @since 1.0.19
465
+     * @param  string $context View or edit context.
466
+     * @return string
467
+     */
468
+    public function get_discount_code( $context = 'view' ) {
469
+        return $this->get_code( $context );
470
+    }
471 471
 	
472
-	/**
473
-	 * Get the discount's amount.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return float
478
-	 */
479
-	public function get_amount( $context = 'view' ) {
480
-		return $this->get_prop( 'amount', $context );
481
-	}
482
-
483
-	/**
484
-	 * Get the discount's formated amount/rate.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return string
488
-	 */
489
-	public function get_formatted_amount() {
490
-
491
-		if ( $this->is_type( 'flat' ) ) {
492
-			$rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) );
493
-		} else {
494
-			$rate = $this->get_amount() . '%';
495
-		}
496
-
497
-		return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() );
498
-	}
499
-
500
-	function wpinv_format_discount_rate( $type, $amount ) {
501
-		if ( $type == 'flat' ) {
502
-			$rate = wpinv_price( wpinv_format_amount( $amount ) );
503
-		} else {
504
-			$rate = $amount . '%';
505
-		}
472
+    /**
473
+     * Get the discount's amount.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return float
478
+     */
479
+    public function get_amount( $context = 'view' ) {
480
+        return $this->get_prop( 'amount', $context );
481
+    }
482
+
483
+    /**
484
+     * Get the discount's formated amount/rate.
485
+     *
486
+     * @since 1.0.19
487
+     * @return string
488
+     */
489
+    public function get_formatted_amount() {
490
+
491
+        if ( $this->is_type( 'flat' ) ) {
492
+            $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) );
493
+        } else {
494
+            $rate = $this->get_amount() . '%';
495
+        }
496
+
497
+        return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() );
498
+    }
499
+
500
+    function wpinv_format_discount_rate( $type, $amount ) {
501
+        if ( $type == 'flat' ) {
502
+            $rate = wpinv_price( wpinv_format_amount( $amount ) );
503
+        } else {
504
+            $rate = $amount . '%';
505
+        }
506 506
 	
507
-		return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount );
508
-	}
507
+        return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount );
508
+    }
509 509
 	
510
-	/**
511
-	 * Get the discount's start date.
512
-	 *
513
-	 * @since 1.0.19
514
-	 * @param  string $context View or edit context.
515
-	 * @return string
516
-	 */
517
-	public function get_start( $context = 'view' ) {
518
-		return $this->get_prop( 'start', $context );
519
-	}
510
+    /**
511
+     * Get the discount's start date.
512
+     *
513
+     * @since 1.0.19
514
+     * @param  string $context View or edit context.
515
+     * @return string
516
+     */
517
+    public function get_start( $context = 'view' ) {
518
+        return $this->get_prop( 'start', $context );
519
+    }
520 520
 	
521
-	/**
522
-	 * Alias for self::get_start().
523
-	 *
524
-	 * @since 1.0.19
525
-	 * @param  string $context View or edit context.
526
-	 * @return string
527
-	 */
528
-	public function get_start_date( $context = 'view' ) {
529
-		return $this->get_start( $context );
530
-	}
521
+    /**
522
+     * Alias for self::get_start().
523
+     *
524
+     * @since 1.0.19
525
+     * @param  string $context View or edit context.
526
+     * @return string
527
+     */
528
+    public function get_start_date( $context = 'view' ) {
529
+        return $this->get_start( $context );
530
+    }
531 531
 	
532
-	/**
533
-	 * Get the discount's expiration date.
534
-	 *
535
-	 * @since 1.0.19
536
-	 * @param  string $context View or edit context.
537
-	 * @return string
538
-	 */
539
-	public function get_expiration( $context = 'view' ) {
540
-		return $this->get_prop( 'expiration', $context );
541
-	}
532
+    /**
533
+     * Get the discount's expiration date.
534
+     *
535
+     * @since 1.0.19
536
+     * @param  string $context View or edit context.
537
+     * @return string
538
+     */
539
+    public function get_expiration( $context = 'view' ) {
540
+        return $this->get_prop( 'expiration', $context );
541
+    }
542 542
 	
543
-	/**
544
-	 * Alias for self::get_expiration().
545
-	 *
546
-	 * @since 1.0.19
547
-	 * @param  string $context View or edit context.
548
-	 * @return string
549
-	 */
550
-	public function get_expiration_date( $context = 'view' ) {
551
-		return $this->get_expiration( $context );
552
-	}
553
-
554
-	/**
555
-	 * Alias for self::get_expiration().
556
-	 *
557
-	 * @since 1.0.19
558
-	 * @param  string $context View or edit context.
559
-	 * @return string
560
-	 */
561
-	public function get_end_date( $context = 'view' ) {
562
-		return $this->get_expiration( $context );
563
-	}
543
+    /**
544
+     * Alias for self::get_expiration().
545
+     *
546
+     * @since 1.0.19
547
+     * @param  string $context View or edit context.
548
+     * @return string
549
+     */
550
+    public function get_expiration_date( $context = 'view' ) {
551
+        return $this->get_expiration( $context );
552
+    }
553
+
554
+    /**
555
+     * Alias for self::get_expiration().
556
+     *
557
+     * @since 1.0.19
558
+     * @param  string $context View or edit context.
559
+     * @return string
560
+     */
561
+    public function get_end_date( $context = 'view' ) {
562
+        return $this->get_expiration( $context );
563
+    }
564 564
 	
565
-	/**
566
-	 * Get the discount's type.
567
-	 *
568
-	 * @since 1.0.19
569
-	 * @param  string $context View or edit context.
570
-	 * @return string
571
-	 */
572
-	public function get_type( $context = 'view' ) {
573
-		return $this->get_prop( 'type', $context );
574
-	}
575
-
576
-	/**
577
-	 * Get the number of times a discount has been used.
578
-	 *
579
-	 * @since 1.0.19
580
-	 * @param  string $context View or edit context.
581
-	 * @return int
582
-	 */
583
-	public function get_uses( $context = 'view' ) {
584
-		return (int) $this->get_prop( 'uses', $context );
585
-	}
586
-
587
-	/**
588
-	 * Get the discount's usage, i.e uses / max uses.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @return string
592
-	 */
593
-	public function get_usage() {
594
-
595
-		if ( ! $this->has_limit() ) {
596
-			return $this->get_uses() . ' / ' . ' &infin;';
597
-		}
598
-
599
-		return $this->get_uses() . ' / ' . (int) $this->get_max_uses();
600
-
601
-	}
602
-
603
-	/**
604
-	 * Get the maximum number of time a discount can be used.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param  string $context View or edit context.
608
-	 * @return int
609
-	 */
610
-	public function get_max_uses( $context = 'view' ) {
611
-		$max_uses = $this->get_prop( 'max_uses', $context );
612
-		return empty( $max_uses ) ? null : $max_uses;
613
-	}
614
-
615
-	/**
616
-	 * Checks if this is a single use discount or not.
617
-	 *
618
-	 * @since 1.0.19
619
-	 * @param  string $context View or edit context.
620
-	 * @return bool
621
-	 */
622
-	public function get_is_single_use( $context = 'view' ) {
623
-		return $this->get_prop( 'is_single_use', $context );
624
-	}
625
-
626
-	/**
627
-	 * Get the items that can be used with this discount.
628
-	 *
629
-	 * @since 1.0.19
630
-	 * @param  string $context View or edit context.
631
-	 * @return array
632
-	 */
633
-	public function get_items( $context = 'view' ) {
634
-		return wpinv_parse_list( $this->get_prop( 'items', $context ) );
635
-	}
636
-
637
-	/**
638
-	 * Alias for self::get_items().
639
-	 *
640
-	 * @since 1.0.19
641
-	 * @param  string $context View or edit context.
642
-	 * @return array
643
-	 */
644
-	public function get_allowed_items( $context = 'view' ) {
645
-		return $this->get_items( $context );
646
-	}
647
-
648
-	/**
649
-	 * Get the items that are not allowed to use this discount.
650
-	 *
651
-	 * @since 1.0.19
652
-	 * @param  string $context View or edit context.
653
-	 * @return array
654
-	 */
655
-	public function get_excluded_items( $context = 'view' ) {
656
-		return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) );
657
-	}
658
-
659
-	/**
660
-	 * Checks if this is a recurring discount or not.
661
-	 *
662
-	 * @since 1.0.19
663
-	 * @param  string $context View or edit context.
664
-	 * @return int|string|bool
665
-	 */
666
-	public function get_is_recurring( $context = 'view' ) {
667
-		return $this->get_prop( 'is_recurring', $context );
668
-	}
669
-
670
-	/**
671
-	 * Get's the minimum total amount allowed for this discount.
672
-	 *
673
-	 * @since 1.0.19
674
-	 * @param  string $context View or edit context.
675
-	 * @return float
676
-	 */
677
-	public function get_min_total( $context = 'view' ) {
678
-		$minimum = $this->get_prop( 'min_total', $context );
679
-		return empty( $minimum ) ? null : $minimum;
680
-	}
681
-
682
-	/**
683
-	 * Alias for self::get_min_total().
684
-	 *
685
-	 * @since 1.0.19
686
-	 * @param  string $context View or edit context.
687
-	 * @return float
688
-	 */
689
-	public function get_minimum_total( $context = 'view' ) {
690
-		return $this->get_min_total( $context );
691
-	}
692
-
693
-	/**
694
-	 * Get's the maximum total amount allowed for this discount.
695
-	 *
696
-	 * @since 1.0.19
697
-	 * @param  string $context View or edit context.
698
-	 * @return float
699
-	 */
700
-	public function get_max_total( $context = 'view' ) {
701
-		$maximum = $this->get_prop( 'max_total', $context );
702
-		return empty( $maximum ) ? null : $maximum;
703
-	}
704
-
705
-	/**
706
-	 * Alias for self::get_max_total().
707
-	 *
708
-	 * @since 1.0.19
709
-	 * @param  string $context View or edit context.
710
-	 * @return float
711
-	 */
712
-	public function get_maximum_total( $context = 'view' ) {
713
-		return $this->get_max_total( $context );
714
-	}
715
-
716
-	/**
717
-	 * Magic method for accessing discount properties.
718
-	 *
719
-	 * @since 1.0.15
720
-	 * @access public
721
-	 *
722
-	 * @param string $key Discount data to retrieve
723
-	 * @param  string $context View or edit context.
724
-	 * @return mixed Value of the given discount property (if set).
725
-	 */
726
-	public function get( $key, $context = 'view' ) {
565
+    /**
566
+     * Get the discount's type.
567
+     *
568
+     * @since 1.0.19
569
+     * @param  string $context View or edit context.
570
+     * @return string
571
+     */
572
+    public function get_type( $context = 'view' ) {
573
+        return $this->get_prop( 'type', $context );
574
+    }
575
+
576
+    /**
577
+     * Get the number of times a discount has been used.
578
+     *
579
+     * @since 1.0.19
580
+     * @param  string $context View or edit context.
581
+     * @return int
582
+     */
583
+    public function get_uses( $context = 'view' ) {
584
+        return (int) $this->get_prop( 'uses', $context );
585
+    }
586
+
587
+    /**
588
+     * Get the discount's usage, i.e uses / max uses.
589
+     *
590
+     * @since 1.0.19
591
+     * @return string
592
+     */
593
+    public function get_usage() {
594
+
595
+        if ( ! $this->has_limit() ) {
596
+            return $this->get_uses() . ' / ' . ' &infin;';
597
+        }
598
+
599
+        return $this->get_uses() . ' / ' . (int) $this->get_max_uses();
600
+
601
+    }
602
+
603
+    /**
604
+     * Get the maximum number of time a discount can be used.
605
+     *
606
+     * @since 1.0.19
607
+     * @param  string $context View or edit context.
608
+     * @return int
609
+     */
610
+    public function get_max_uses( $context = 'view' ) {
611
+        $max_uses = $this->get_prop( 'max_uses', $context );
612
+        return empty( $max_uses ) ? null : $max_uses;
613
+    }
614
+
615
+    /**
616
+     * Checks if this is a single use discount or not.
617
+     *
618
+     * @since 1.0.19
619
+     * @param  string $context View or edit context.
620
+     * @return bool
621
+     */
622
+    public function get_is_single_use( $context = 'view' ) {
623
+        return $this->get_prop( 'is_single_use', $context );
624
+    }
625
+
626
+    /**
627
+     * Get the items that can be used with this discount.
628
+     *
629
+     * @since 1.0.19
630
+     * @param  string $context View or edit context.
631
+     * @return array
632
+     */
633
+    public function get_items( $context = 'view' ) {
634
+        return wpinv_parse_list( $this->get_prop( 'items', $context ) );
635
+    }
636
+
637
+    /**
638
+     * Alias for self::get_items().
639
+     *
640
+     * @since 1.0.19
641
+     * @param  string $context View or edit context.
642
+     * @return array
643
+     */
644
+    public function get_allowed_items( $context = 'view' ) {
645
+        return $this->get_items( $context );
646
+    }
647
+
648
+    /**
649
+     * Get the items that are not allowed to use this discount.
650
+     *
651
+     * @since 1.0.19
652
+     * @param  string $context View or edit context.
653
+     * @return array
654
+     */
655
+    public function get_excluded_items( $context = 'view' ) {
656
+        return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) );
657
+    }
658
+
659
+    /**
660
+     * Checks if this is a recurring discount or not.
661
+     *
662
+     * @since 1.0.19
663
+     * @param  string $context View or edit context.
664
+     * @return int|string|bool
665
+     */
666
+    public function get_is_recurring( $context = 'view' ) {
667
+        return $this->get_prop( 'is_recurring', $context );
668
+    }
669
+
670
+    /**
671
+     * Get's the minimum total amount allowed for this discount.
672
+     *
673
+     * @since 1.0.19
674
+     * @param  string $context View or edit context.
675
+     * @return float
676
+     */
677
+    public function get_min_total( $context = 'view' ) {
678
+        $minimum = $this->get_prop( 'min_total', $context );
679
+        return empty( $minimum ) ? null : $minimum;
680
+    }
681
+
682
+    /**
683
+     * Alias for self::get_min_total().
684
+     *
685
+     * @since 1.0.19
686
+     * @param  string $context View or edit context.
687
+     * @return float
688
+     */
689
+    public function get_minimum_total( $context = 'view' ) {
690
+        return $this->get_min_total( $context );
691
+    }
692
+
693
+    /**
694
+     * Get's the maximum total amount allowed for this discount.
695
+     *
696
+     * @since 1.0.19
697
+     * @param  string $context View or edit context.
698
+     * @return float
699
+     */
700
+    public function get_max_total( $context = 'view' ) {
701
+        $maximum = $this->get_prop( 'max_total', $context );
702
+        return empty( $maximum ) ? null : $maximum;
703
+    }
704
+
705
+    /**
706
+     * Alias for self::get_max_total().
707
+     *
708
+     * @since 1.0.19
709
+     * @param  string $context View or edit context.
710
+     * @return float
711
+     */
712
+    public function get_maximum_total( $context = 'view' ) {
713
+        return $this->get_max_total( $context );
714
+    }
715
+
716
+    /**
717
+     * Magic method for accessing discount properties.
718
+     *
719
+     * @since 1.0.15
720
+     * @access public
721
+     *
722
+     * @param string $key Discount data to retrieve
723
+     * @param  string $context View or edit context.
724
+     * @return mixed Value of the given discount property (if set).
725
+     */
726
+    public function get( $key, $context = 'view' ) {
727 727
         return $this->get_prop( $key, $context );
728
-	}
728
+    }
729 729
 
730
-	/*
730
+    /*
731 731
 	|--------------------------------------------------------------------------
732 732
 	| Setters
733 733
 	|--------------------------------------------------------------------------
@@ -737,41 +737,41 @@  discard block
 block discarded – undo
737 737
 	| object.
738 738
 	*/
739 739
 	
740
-	/**
741
-	 * Sets discount status.
742
-	 *
743
-	 * @since 1.0.19
744
-	 * @param  string $status New status.
745
-	 * @return array details of change.
746
-	 */
747
-	public function set_status( $status ) {
740
+    /**
741
+     * Sets discount status.
742
+     *
743
+     * @since 1.0.19
744
+     * @param  string $status New status.
745
+     * @return array details of change.
746
+     */
747
+    public function set_status( $status ) {
748 748
         $old_status = $this->get_status();
749 749
 
750 750
         $this->set_prop( 'status', $status );
751 751
 
752
-		return array(
753
-			'from' => $old_status,
754
-			'to'   => $status,
755
-		);
752
+        return array(
753
+            'from' => $old_status,
754
+            'to'   => $status,
755
+        );
756 756
     }
757 757
 
758 758
     /**
759
-	 * Set plugin version when the discount was created.
760
-	 *
761
-	 * @since 1.0.19
762
-	 */
763
-	public function set_version( $value ) {
764
-		$this->set_prop( 'version', $value );
759
+     * Set plugin version when the discount was created.
760
+     *
761
+     * @since 1.0.19
762
+     */
763
+    public function set_version( $value ) {
764
+        $this->set_prop( 'version', $value );
765 765
     }
766 766
 
767 767
     /**
768
-	 * Set date when the discount was created.
769
-	 *
770
-	 * @since 1.0.19
771
-	 * @param string $value Value to set.
768
+     * Set date when the discount was created.
769
+     *
770
+     * @since 1.0.19
771
+     * @param string $value Value to set.
772 772
      * @return bool Whether or not the date was set.
773
-	 */
774
-	public function set_date_created( $value ) {
773
+     */
774
+    public function set_date_created( $value ) {
775 775
         $date = strtotime( $value );
776 776
 
777 777
         if ( $date ) {
@@ -784,13 +784,13 @@  discard block
 block discarded – undo
784 784
     }
785 785
 
786 786
     /**
787
-	 * Set date when the discount was last modified.
788
-	 *
789
-	 * @since 1.0.19
790
-	 * @param string $value Value to set.
787
+     * Set date when the discount was last modified.
788
+     *
789
+     * @since 1.0.19
790
+     * @param string $value Value to set.
791 791
      * @return bool Whether or not the date was set.
792
-	 */
793
-	public function set_date_modified( $value ) {
792
+     */
793
+    public function set_date_modified( $value ) {
794 794
         $date = strtotime( $value );
795 795
 
796 796
         if ( $date ) {
@@ -803,324 +803,324 @@  discard block
 block discarded – undo
803 803
     }
804 804
 
805 805
     /**
806
-	 * Set the discount name.
807
-	 *
808
-	 * @since 1.0.19
809
-	 * @param  string $value New name.
810
-	 */
811
-	public function set_name( $value ) {
806
+     * Set the discount name.
807
+     *
808
+     * @since 1.0.19
809
+     * @param  string $value New name.
810
+     */
811
+    public function set_name( $value ) {
812 812
         $name = sanitize_text_field( $value );
813
-		$this->set_prop( 'name', $name );
813
+        $this->set_prop( 'name', $name );
814 814
     }
815 815
 
816 816
     /**
817
-	 * Alias of self::set_name().
818
-	 *
819
-	 * @since 1.0.19
820
-	 * @param  string $value New name.
821
-	 */
822
-	public function set_title( $value ) {
823
-		$this->set_name( $value );
817
+     * Alias of self::set_name().
818
+     *
819
+     * @since 1.0.19
820
+     * @param  string $value New name.
821
+     */
822
+    public function set_title( $value ) {
823
+        $this->set_name( $value );
824 824
     }
825 825
 
826 826
     /**
827
-	 * Set the discount description.
828
-	 *
829
-	 * @since 1.0.19
830
-	 * @param  string $value New description.
831
-	 */
832
-	public function set_description( $value ) {
827
+     * Set the discount description.
828
+     *
829
+     * @since 1.0.19
830
+     * @param  string $value New description.
831
+     */
832
+    public function set_description( $value ) {
833 833
         $description = wp_kses_post( $value );
834
-		return $this->set_prop( 'description', $description );
834
+        return $this->set_prop( 'description', $description );
835 835
     }
836 836
 
837 837
     /**
838
-	 * Alias of self::set_description().
839
-	 *
840
-	 * @since 1.0.19
841
-	 * @param  string $value New description.
842
-	 */
843
-	public function set_excerpt( $value ) {
844
-		$this->set_description( $value );
838
+     * Alias of self::set_description().
839
+     *
840
+     * @since 1.0.19
841
+     * @param  string $value New description.
842
+     */
843
+    public function set_excerpt( $value ) {
844
+        $this->set_description( $value );
845 845
     }
846 846
 
847 847
     /**
848
-	 * Alias of self::set_description().
849
-	 *
850
-	 * @since 1.0.19
851
-	 * @param  string $value New description.
852
-	 */
853
-	public function set_summary( $value ) {
854
-		$this->set_description( $value );
848
+     * Alias of self::set_description().
849
+     *
850
+     * @since 1.0.19
851
+     * @param  string $value New description.
852
+     */
853
+    public function set_summary( $value ) {
854
+        $this->set_description( $value );
855 855
     }
856 856
 
857 857
     /**
858
-	 * Set the owner of the discount.
859
-	 *
860
-	 * @since 1.0.19
861
-	 * @param  int $value New author.
862
-	 */
863
-	public function set_author( $value ) {
864
-		$this->set_prop( 'author', (int) $value );
865
-	}
858
+     * Set the owner of the discount.
859
+     *
860
+     * @since 1.0.19
861
+     * @param  int $value New author.
862
+     */
863
+    public function set_author( $value ) {
864
+        $this->set_prop( 'author', (int) $value );
865
+    }
866 866
 	
867
-	/**
868
-	 * Sets the discount code.
869
-	 *
870
-	 * @since 1.0.19
871
-	 * @param string $value New discount code.
872
-	 */
873
-	public function set_code( $value ) {
874
-		$code = sanitize_text_field( $value );
875
-		$this->set_prop( 'code', $code );
876
-	}
867
+    /**
868
+     * Sets the discount code.
869
+     *
870
+     * @since 1.0.19
871
+     * @param string $value New discount code.
872
+     */
873
+    public function set_code( $value ) {
874
+        $code = sanitize_text_field( $value );
875
+        $this->set_prop( 'code', $code );
876
+    }
877 877
 	
878
-	/**
879
-	 * Alias of self::set_code().
880
-	 *
881
-	 * @since 1.0.19
882
-	 * @param string $value New discount code.
883
-	 */
884
-	public function set_coupon_code( $value ) {
885
-		$this->set_code( $value );
886
-	}
878
+    /**
879
+     * Alias of self::set_code().
880
+     *
881
+     * @since 1.0.19
882
+     * @param string $value New discount code.
883
+     */
884
+    public function set_coupon_code( $value ) {
885
+        $this->set_code( $value );
886
+    }
887 887
 	
888
-	/**
889
-	 * Alias of self::set_code().
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @param string $value New discount code.
893
-	 */
894
-	public function set_discount_code( $value ) {
895
-		$this->set_code( $value );
896
-	}
888
+    /**
889
+     * Alias of self::set_code().
890
+     *
891
+     * @since 1.0.19
892
+     * @param string $value New discount code.
893
+     */
894
+    public function set_discount_code( $value ) {
895
+        $this->set_code( $value );
896
+    }
897 897
 	
898
-	/**
899
-	 * Sets the discount amount.
900
-	 *
901
-	 * @since 1.0.19
902
-	 * @param float $value New discount code.
903
-	 */
904
-	public function set_amount( $value ) {
905
-		$amount = floatval( wpinv_sanitize_amount( $value ) );
906
-		$this->set_prop( 'amount', $amount );
907
-	}
908
-
909
-	/**
910
-	 * Sets the discount's start date.
911
-	 *
912
-	 * @since 1.0.19
913
-	 * @param float $value New start date.
914
-	 */
915
-	public function set_start( $value ) {
916
-		$date = strtotime( $value );
898
+    /**
899
+     * Sets the discount amount.
900
+     *
901
+     * @since 1.0.19
902
+     * @param float $value New discount code.
903
+     */
904
+    public function set_amount( $value ) {
905
+        $amount = floatval( wpinv_sanitize_amount( $value ) );
906
+        $this->set_prop( 'amount', $amount );
907
+    }
908
+
909
+    /**
910
+     * Sets the discount's start date.
911
+     *
912
+     * @since 1.0.19
913
+     * @param float $value New start date.
914
+     */
915
+    public function set_start( $value ) {
916
+        $date = strtotime( $value );
917 917
 
918 918
         if ( $date ) {
919 919
             $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) );
920 920
             return true;
921
-		}
921
+        }
922 922
 		
923
-		$this->set_prop( 'start', '' );
923
+        $this->set_prop( 'start', '' );
924 924
 
925 925
         return false;
926
-	}
927
-
928
-	/**
929
-	 * Alias of self::set_start().
930
-	 *
931
-	 * @since 1.0.19
932
-	 * @param string $value New start date.
933
-	 */
934
-	public function set_start_date( $value ) {
935
-		$this->set_start( $value );
936
-	}
937
-
938
-	/**
939
-	 * Sets the discount's expiration date.
940
-	 *
941
-	 * @since 1.0.19
942
-	 * @param float $value New expiration date.
943
-	 */
944
-	public function set_expiration( $value ) {
945
-		$date = strtotime( $value );
926
+    }
927
+
928
+    /**
929
+     * Alias of self::set_start().
930
+     *
931
+     * @since 1.0.19
932
+     * @param string $value New start date.
933
+     */
934
+    public function set_start_date( $value ) {
935
+        $this->set_start( $value );
936
+    }
937
+
938
+    /**
939
+     * Sets the discount's expiration date.
940
+     *
941
+     * @since 1.0.19
942
+     * @param float $value New expiration date.
943
+     */
944
+    public function set_expiration( $value ) {
945
+        $date = strtotime( $value );
946 946
 
947 947
         if ( $date ) {
948 948
             $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) );
949 949
             return true;
950 950
         }
951 951
 
952
-		$this->set_prop( 'expiration', '' );
952
+        $this->set_prop( 'expiration', '' );
953 953
         return false;
954
-	}
955
-
956
-	/**
957
-	 * Alias of self::set_expiration().
958
-	 *
959
-	 * @since 1.0.19
960
-	 * @param string $value New expiration date.
961
-	 */
962
-	public function set_expiration_date( $value ) {
963
-		$this->set_expiration( $value );
964
-	}
965
-
966
-	/**
967
-	 * Alias of self::set_expiration().
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param string $value New expiration date.
971
-	 */
972
-	public function set_end_date( $value ) {
973
-		$this->set_expiration( $value );
974
-	}
975
-
976
-	/**
977
-	 * Sets the discount type.
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param string $value New discount type.
981
-	 */
982
-	public function set_type( $value ) {
983
-		if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) {
984
-			$this->set_prop( 'type', sanitize_text_field( $value ) );
985
-		}
986
-	}
987
-
988
-	/**
989
-	 * Sets the number of times a discount has been used.
990
-	 *
991
-	 * @since 1.0.19
992
-	 * @param int $value usage count.
993
-	 */
994
-	public function set_uses( $value ) {
995
-
996
-		$value = (int) $value;
997
-
998
-		if ( $value < 0 ) {
999
-			$value = 0;
1000
-		}
1001
-
1002
-		$this->set_prop( 'uses', (int) $value );
1003
-	}
1004
-
1005
-	/**
1006
-	 * Sets the maximum number of times a discount can be used.
1007
-	 *
1008
-	 * @since 1.0.19
1009
-	 * @param int $value maximum usage count.
1010
-	 */
1011
-	public function set_max_uses( $value ) {
1012
-		$this->set_prop( 'max_uses', absint( $value ) );
1013
-	}
1014
-
1015
-	/**
1016
-	 * Sets if this is a single use discount or not.
1017
-	 *
1018
-	 * @since 1.0.19
1019
-	 * @param int|bool $value is single use.
1020
-	 */
1021
-	public function set_is_single_use( $value ) {
1022
-		$this->set_prop( 'is_single_use', (bool) $value );
1023
-	}
1024
-
1025
-	/**
1026
-	 * Sets the items that can be used with this discount.
1027
-	 *
1028
-	 * @since 1.0.19
1029
-	 * @param array $value items.
1030
-	 */
1031
-	public function set_items( $value ) {
1032
-		$this->set_prop( 'items', wpinv_parse_list( $value ) );
1033
-	}
1034
-
1035
-	/**
1036
-	 * Alias for self::set_items().
1037
-	 *
1038
-	 * @since 1.0.19
1039
-	 * @param array $value items.
1040
-	 */
1041
-	public function set_allowed_items( $value ) {
1042
-		$this->set_items( $value );
1043
-	}
1044
-
1045
-	/**
1046
-	 * Sets the items that can not be used with this discount.
1047
-	 *
1048
-	 * @since 1.0.19
1049
-	 * @param array $value items.
1050
-	 */
1051
-	public function set_excluded_items( $value ) {
1052
-		$this->set_prop( 'excluded_items', wpinv_parse_list( $value ) );
1053
-	}
1054
-
1055
-	/**
1056
-	 * Sets if this is a recurring discounts or not.
1057
-	 *
1058
-	 * @since 1.0.19
1059
-	 * @param int|bool $value is recurring.
1060
-	 */
1061
-	public function set_is_recurring( $value ) {
1062
-		$this->set_prop( 'is_recurring', (bool) $value );
1063
-	}
1064
-
1065
-	/**
1066
-	 * Sets the minimum total that can not be used with this discount.
1067
-	 *
1068
-	 * @since 1.0.19
1069
-	 * @param float $value minimum total.
1070
-	 */
1071
-	public function set_min_total( $value ) {
1072
-		$this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) );
1073
-	}
1074
-
1075
-	/**
1076
-	 * Alias for self::set_min_total().
1077
-	 *
1078
-	 * @since 1.0.19
1079
-	 * @param float $value minimum total.
1080
-	 */
1081
-	public function set_minimum_total( $value ) {
1082
-		$this->set_min_total( $value );
1083
-	}
1084
-
1085
-	/**
1086
-	 * Sets the maximum total that can not be used with this discount.
1087
-	 *
1088
-	 * @since 1.0.19
1089
-	 * @param float $value maximum total.
1090
-	 */
1091
-	public function set_max_total( $value ) {
1092
-		$this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) );
1093
-	}
1094
-
1095
-	/**
1096
-	 * Alias for self::set_max_total().
1097
-	 *
1098
-	 * @since 1.0.19
1099
-	 * @param float $value maximum total.
1100
-	 */
1101
-	public function set_maximum_total( $value ) {
1102
-		$this->set_max_total( $value );
1103
-	}
1104
-
1105
-	/**
1106
-	 * @deprecated
1107
-	 */
1108
-	public function refresh(){}
1109
-
1110
-	/**
1111
-	 * @deprecated
1112
-	 *
1113
-	 */
1114
-	public function update_status( $status = 'publish' ){
1115
-
1116
-		if ( $this->exists() && $this->get_status() != $status ) {
1117
-			$this->set_status( $status );
1118
-			$this->save();
1119
-		}
1120
-
1121
-	}
1122
-
1123
-	/*
954
+    }
955
+
956
+    /**
957
+     * Alias of self::set_expiration().
958
+     *
959
+     * @since 1.0.19
960
+     * @param string $value New expiration date.
961
+     */
962
+    public function set_expiration_date( $value ) {
963
+        $this->set_expiration( $value );
964
+    }
965
+
966
+    /**
967
+     * Alias of self::set_expiration().
968
+     *
969
+     * @since 1.0.19
970
+     * @param string $value New expiration date.
971
+     */
972
+    public function set_end_date( $value ) {
973
+        $this->set_expiration( $value );
974
+    }
975
+
976
+    /**
977
+     * Sets the discount type.
978
+     *
979
+     * @since 1.0.19
980
+     * @param string $value New discount type.
981
+     */
982
+    public function set_type( $value ) {
983
+        if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) {
984
+            $this->set_prop( 'type', sanitize_text_field( $value ) );
985
+        }
986
+    }
987
+
988
+    /**
989
+     * Sets the number of times a discount has been used.
990
+     *
991
+     * @since 1.0.19
992
+     * @param int $value usage count.
993
+     */
994
+    public function set_uses( $value ) {
995
+
996
+        $value = (int) $value;
997
+
998
+        if ( $value < 0 ) {
999
+            $value = 0;
1000
+        }
1001
+
1002
+        $this->set_prop( 'uses', (int) $value );
1003
+    }
1004
+
1005
+    /**
1006
+     * Sets the maximum number of times a discount can be used.
1007
+     *
1008
+     * @since 1.0.19
1009
+     * @param int $value maximum usage count.
1010
+     */
1011
+    public function set_max_uses( $value ) {
1012
+        $this->set_prop( 'max_uses', absint( $value ) );
1013
+    }
1014
+
1015
+    /**
1016
+     * Sets if this is a single use discount or not.
1017
+     *
1018
+     * @since 1.0.19
1019
+     * @param int|bool $value is single use.
1020
+     */
1021
+    public function set_is_single_use( $value ) {
1022
+        $this->set_prop( 'is_single_use', (bool) $value );
1023
+    }
1024
+
1025
+    /**
1026
+     * Sets the items that can be used with this discount.
1027
+     *
1028
+     * @since 1.0.19
1029
+     * @param array $value items.
1030
+     */
1031
+    public function set_items( $value ) {
1032
+        $this->set_prop( 'items', wpinv_parse_list( $value ) );
1033
+    }
1034
+
1035
+    /**
1036
+     * Alias for self::set_items().
1037
+     *
1038
+     * @since 1.0.19
1039
+     * @param array $value items.
1040
+     */
1041
+    public function set_allowed_items( $value ) {
1042
+        $this->set_items( $value );
1043
+    }
1044
+
1045
+    /**
1046
+     * Sets the items that can not be used with this discount.
1047
+     *
1048
+     * @since 1.0.19
1049
+     * @param array $value items.
1050
+     */
1051
+    public function set_excluded_items( $value ) {
1052
+        $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) );
1053
+    }
1054
+
1055
+    /**
1056
+     * Sets if this is a recurring discounts or not.
1057
+     *
1058
+     * @since 1.0.19
1059
+     * @param int|bool $value is recurring.
1060
+     */
1061
+    public function set_is_recurring( $value ) {
1062
+        $this->set_prop( 'is_recurring', (bool) $value );
1063
+    }
1064
+
1065
+    /**
1066
+     * Sets the minimum total that can not be used with this discount.
1067
+     *
1068
+     * @since 1.0.19
1069
+     * @param float $value minimum total.
1070
+     */
1071
+    public function set_min_total( $value ) {
1072
+        $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) );
1073
+    }
1074
+
1075
+    /**
1076
+     * Alias for self::set_min_total().
1077
+     *
1078
+     * @since 1.0.19
1079
+     * @param float $value minimum total.
1080
+     */
1081
+    public function set_minimum_total( $value ) {
1082
+        $this->set_min_total( $value );
1083
+    }
1084
+
1085
+    /**
1086
+     * Sets the maximum total that can not be used with this discount.
1087
+     *
1088
+     * @since 1.0.19
1089
+     * @param float $value maximum total.
1090
+     */
1091
+    public function set_max_total( $value ) {
1092
+        $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) );
1093
+    }
1094
+
1095
+    /**
1096
+     * Alias for self::set_max_total().
1097
+     *
1098
+     * @since 1.0.19
1099
+     * @param float $value maximum total.
1100
+     */
1101
+    public function set_maximum_total( $value ) {
1102
+        $this->set_max_total( $value );
1103
+    }
1104
+
1105
+    /**
1106
+     * @deprecated
1107
+     */
1108
+    public function refresh(){}
1109
+
1110
+    /**
1111
+     * @deprecated
1112
+     *
1113
+     */
1114
+    public function update_status( $status = 'publish' ){
1115
+
1116
+        if ( $this->exists() && $this->get_status() != $status ) {
1117
+            $this->set_status( $status );
1118
+            $this->save();
1119
+        }
1120
+
1121
+    }
1122
+
1123
+    /*
1124 1124
 	|--------------------------------------------------------------------------
1125 1125
 	| Conditionals
1126 1126
 	|--------------------------------------------------------------------------
@@ -1129,263 +1129,263 @@  discard block
 block discarded – undo
1129 1129
 	|
1130 1130
 	*/
1131 1131
 
1132
-	/**
1133
-	 * Checks whether a discount exists in the database or not
1134
-	 *
1135
-	 * @since 1.0.15
1136
-	 */
1137
-	public function exists(){
1138
-		$id = $this->get_id();
1139
-		return ! empty( $id );
1140
-	}
1141
-
1142
-	/**
1143
-	 * Checks the discount type.
1144
-	 *
1145
-	 *
1146
-	 * @param  string $type the discount type to check against
1147
-	 * @since 1.0.15
1148
-	 * @return bool
1149
-	 */
1150
-	public function is_type( $type ) {
1151
-		return $this->get_type() == $type;
1152
-	}
1153
-
1154
-	/**
1155
-	 * Checks whether the discount is published or not
1156
-	 *
1157
-	 * @since 1.0.15
1158
-	 * @return bool
1159
-	 */
1160
-	public function is_active() {
1161
-		return $this->get_status() == 'publish';
1162
-	}
1163
-
1164
-	/**
1165
-	 * Checks whether the discount has max uses
1166
-	 *
1167
-	 * @since 1.0.15
1168
-	 * @return bool
1169
-	 */
1170
-	public function has_limit() {
1171
-		$limit = $this->get_max_uses();
1172
-		return ! empty( $limit );
1173
-	}
1174
-
1175
-	/**
1176
-	 * Checks whether the discount has ever been used.
1177
-	 *
1178
-	 * @since 1.0.15
1179
-	 * @return bool
1180
-	 */
1181
-	public function has_uses() {
1182
-		return $this->get_uses() > 0;
1183
-	}
1184
-
1185
-	/**
1186
-	 * Checks whether the discount is has exided the usage limit or not
1187
-	 *
1188
-	 * @since 1.0.15
1189
-	 * @return bool
1190
-	 */
1191
-	public function has_exceeded_limit() {
1192
-
1193
-		if ( ! $this->has_limit() || ! $this->has_uses() ) {
1194
-			$exceeded = false ;
1195
-		} else {
1196
-			$exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() );
1197
-		}
1198
-
1199
-		return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code );
1200
-	}
1201
-
1202
-	/**
1203
-	 * Checks whether the discount has an expiration date.
1204
-	 *
1205
-	 * @since 1.0.15
1206
-	 * @return bool
1207
-	 */
1208
-	public function has_expiration_date() {
1209
-		$date = $this->get_expiration_date();
1210
-		return ! empty( $date );
1211
-	}
1212
-
1213
-	/**
1214
-	 * Checks if the discount is expired
1215
-	 *
1216
-	 * @since 1.0.15
1217
-	 * @return bool
1218
-	 */
1219
-	public function is_expired() {
1220
-		$expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false;
1221
-		return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code );
1222
-	}
1223
-
1224
-	/**
1225
-	 * Checks whether the discount has a start date.
1226
-	 *
1227
-	 * @since 1.0.15
1228
-	 * @return bool
1229
-	 */
1230
-	public function has_start_date() {
1231
-		$date = $this->get_start_date();
1232
-		return ! empty( $date );
1233
-	}
1234
-
1235
-	/**
1236
-	 * Checks the discount start date.
1237
-	 *
1238
-	 * @since 1.0.15
1239
-	 * @return bool
1240
-	 */
1241
-	public function has_started() {
1242
-		$started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() );
1243
-		return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code );
1244
-	}
1245
-
1246
-	/**
1247
-	 * Checks the discount has allowed items or not.
1248
-	 *
1249
-	 * @since 1.0.15
1250
-	 * @return bool
1251
-	 */
1252
-	public function has_allowed_items() {
1253
-		$allowed_items = $this->get_allowed_items();
1254
-		return empty( $allowed_items );
1255
-	}
1256
-
1257
-	/**
1258
-	 * Checks the discount has excluded items or not.
1259
-	 *
1260
-	 * @since 1.0.15
1261
-	 * @return bool
1262
-	 */
1263
-	public function has_excluded_items() {
1264
-		$excluded_items = $this->get_excluded_items();
1265
-		return empty( $excluded_items );
1266
-	}
1267
-
1268
-	/**
1269
-	 * Check if a discount is valid for a given item id.
1270
-	 *
1271
-	 * @param  int|int[]  $item_ids
1272
-	 * @since 1.0.15
1273
-	 * @return boolean
1274
-	 */
1275
-	public function is_valid_for_items( $item_ids ) {
1276
-
1277
-		$item_ids = array_map( 'intval',  wpinv_parse_list( $item_ids ) );
1278
-		$included = array_intersect( $item_ids, $this->get_allowed_items() );
1279
-		$excluded = array_intersect( $item_ids, $this->get_excluded_items() );
1280
-
1281
-		if ( $this->has_excluded_items() && ! empty( $excluded ) ) {
1282
-			return false;
1283
-		}
1284
-
1285
-		if ( $this->has_allowed_items() && empty( $included ) ) {
1286
-			return false;
1287
-		}
1288
-		return true;
1289
-	}
1290
-
1291
-	/**
1292
-	 * Check if a discount is valid for the given amount
1293
-	 *
1294
-	 * @param  float  $amount The amount to check against
1295
-	 * @since 1.0.15
1296
-	 * @return boolean
1297
-	 */
1298
-	public function is_valid_for_amount( $amount ) {
1299
-		return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
1300
-	}
1301
-
1302
-	/**
1303
-	 * Checks if the minimum amount is set
1304
-	 *
1305
-	 * @since 1.0.15
1306
-	 * @return boolean
1307
-	 */
1308
-	public function has_minimum_amount() {
1309
-		$minimum = $this->get_minimum_total();
1310
-		return ! empty( $minimum );
1311
-	}
1312
-
1313
-	/**
1314
-	 * Checks if the minimum amount is met
1315
-	 *
1316
-	 * @param  float  $amount The amount to check against
1317
-	 * @since 1.0.15
1318
-	 * @return boolean
1319
-	 */
1320
-	public function is_minimum_amount_met( $amount ) {
1321
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1322
-		$min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) );
1323
-		return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount );
1324
-	}
1325
-
1326
-	/**
1327
-	 * Checks if the maximum amount is set
1328
-	 *
1329
-	 * @since 1.0.15
1330
-	 * @return boolean
1331
-	 */
1332
-	public function has_maximum_amount() {
1333
-		$maximum = $this->get_maximum_total();
1334
-		return ! empty( $maximum );
1335
-	}
1336
-
1337
-	/**
1338
-	 * Checks if the maximum amount is met
1339
-	 *
1340
-	 * @param  float  $amount The amount to check against
1341
-	 * @since 1.0.15
1342
-	 * @return boolean
1343
-	 */
1344
-	public function is_maximum_amount_met( $amount ) {
1345
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1346
-		$max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) );
1347
-		return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount );
1348
-	}
1349
-
1350
-	/**
1351
-	 * Checks if the discount is recurring.
1352
-	 *
1353
-	 * @since 1.0.15
1354
-	 * @return boolean
1355
-	 */
1356
-	public function is_recurring() {
1357
-		$recurring = $this->get_is_recurring();
1358
-		return ! empty( $recurring );
1359
-	}
1360
-
1361
-	/**
1362
-	 * Checks if the discount is single use.
1363
-	 *
1364
-	 * @since 1.0.15
1365
-	 * @return boolean
1366
-	 */
1367
-	public function is_single_use() {
1368
-		$usage = $this->get_is_single_use();
1369
-		return ! empty( $usage );
1370
-	}
1371
-
1372
-	/**
1373
-	 * Check if a discount is valid for the given user
1374
-	 *
1375
-	 * @param  int|string  $user
1376
-	 * @since 1.0.15
1377
-	 * @return boolean
1378
-	 */
1379
-	public function is_valid_for_user( $user ) {
1380
-		global $wpi_checkout_id;
1381
-
1382
-		// Ensure that the discount is single use.
1383
-		if ( empty( $user ) || ! $this->is_single_use() ) {
1384
-			return true;
1385
-		}
1386
-
1387
-		// Prepare the user id.
1388
-		$user_id = 0;
1132
+    /**
1133
+     * Checks whether a discount exists in the database or not
1134
+     *
1135
+     * @since 1.0.15
1136
+     */
1137
+    public function exists(){
1138
+        $id = $this->get_id();
1139
+        return ! empty( $id );
1140
+    }
1141
+
1142
+    /**
1143
+     * Checks the discount type.
1144
+     *
1145
+     *
1146
+     * @param  string $type the discount type to check against
1147
+     * @since 1.0.15
1148
+     * @return bool
1149
+     */
1150
+    public function is_type( $type ) {
1151
+        return $this->get_type() == $type;
1152
+    }
1153
+
1154
+    /**
1155
+     * Checks whether the discount is published or not
1156
+     *
1157
+     * @since 1.0.15
1158
+     * @return bool
1159
+     */
1160
+    public function is_active() {
1161
+        return $this->get_status() == 'publish';
1162
+    }
1163
+
1164
+    /**
1165
+     * Checks whether the discount has max uses
1166
+     *
1167
+     * @since 1.0.15
1168
+     * @return bool
1169
+     */
1170
+    public function has_limit() {
1171
+        $limit = $this->get_max_uses();
1172
+        return ! empty( $limit );
1173
+    }
1174
+
1175
+    /**
1176
+     * Checks whether the discount has ever been used.
1177
+     *
1178
+     * @since 1.0.15
1179
+     * @return bool
1180
+     */
1181
+    public function has_uses() {
1182
+        return $this->get_uses() > 0;
1183
+    }
1184
+
1185
+    /**
1186
+     * Checks whether the discount is has exided the usage limit or not
1187
+     *
1188
+     * @since 1.0.15
1189
+     * @return bool
1190
+     */
1191
+    public function has_exceeded_limit() {
1192
+
1193
+        if ( ! $this->has_limit() || ! $this->has_uses() ) {
1194
+            $exceeded = false ;
1195
+        } else {
1196
+            $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() );
1197
+        }
1198
+
1199
+        return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code );
1200
+    }
1201
+
1202
+    /**
1203
+     * Checks whether the discount has an expiration date.
1204
+     *
1205
+     * @since 1.0.15
1206
+     * @return bool
1207
+     */
1208
+    public function has_expiration_date() {
1209
+        $date = $this->get_expiration_date();
1210
+        return ! empty( $date );
1211
+    }
1212
+
1213
+    /**
1214
+     * Checks if the discount is expired
1215
+     *
1216
+     * @since 1.0.15
1217
+     * @return bool
1218
+     */
1219
+    public function is_expired() {
1220
+        $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false;
1221
+        return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code );
1222
+    }
1223
+
1224
+    /**
1225
+     * Checks whether the discount has a start date.
1226
+     *
1227
+     * @since 1.0.15
1228
+     * @return bool
1229
+     */
1230
+    public function has_start_date() {
1231
+        $date = $this->get_start_date();
1232
+        return ! empty( $date );
1233
+    }
1234
+
1235
+    /**
1236
+     * Checks the discount start date.
1237
+     *
1238
+     * @since 1.0.15
1239
+     * @return bool
1240
+     */
1241
+    public function has_started() {
1242
+        $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() );
1243
+        return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code );
1244
+    }
1245
+
1246
+    /**
1247
+     * Checks the discount has allowed items or not.
1248
+     *
1249
+     * @since 1.0.15
1250
+     * @return bool
1251
+     */
1252
+    public function has_allowed_items() {
1253
+        $allowed_items = $this->get_allowed_items();
1254
+        return empty( $allowed_items );
1255
+    }
1256
+
1257
+    /**
1258
+     * Checks the discount has excluded items or not.
1259
+     *
1260
+     * @since 1.0.15
1261
+     * @return bool
1262
+     */
1263
+    public function has_excluded_items() {
1264
+        $excluded_items = $this->get_excluded_items();
1265
+        return empty( $excluded_items );
1266
+    }
1267
+
1268
+    /**
1269
+     * Check if a discount is valid for a given item id.
1270
+     *
1271
+     * @param  int|int[]  $item_ids
1272
+     * @since 1.0.15
1273
+     * @return boolean
1274
+     */
1275
+    public function is_valid_for_items( $item_ids ) {
1276
+
1277
+        $item_ids = array_map( 'intval',  wpinv_parse_list( $item_ids ) );
1278
+        $included = array_intersect( $item_ids, $this->get_allowed_items() );
1279
+        $excluded = array_intersect( $item_ids, $this->get_excluded_items() );
1280
+
1281
+        if ( $this->has_excluded_items() && ! empty( $excluded ) ) {
1282
+            return false;
1283
+        }
1284
+
1285
+        if ( $this->has_allowed_items() && empty( $included ) ) {
1286
+            return false;
1287
+        }
1288
+        return true;
1289
+    }
1290
+
1291
+    /**
1292
+     * Check if a discount is valid for the given amount
1293
+     *
1294
+     * @param  float  $amount The amount to check against
1295
+     * @since 1.0.15
1296
+     * @return boolean
1297
+     */
1298
+    public function is_valid_for_amount( $amount ) {
1299
+        return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
1300
+    }
1301
+
1302
+    /**
1303
+     * Checks if the minimum amount is set
1304
+     *
1305
+     * @since 1.0.15
1306
+     * @return boolean
1307
+     */
1308
+    public function has_minimum_amount() {
1309
+        $minimum = $this->get_minimum_total();
1310
+        return ! empty( $minimum );
1311
+    }
1312
+
1313
+    /**
1314
+     * Checks if the minimum amount is met
1315
+     *
1316
+     * @param  float  $amount The amount to check against
1317
+     * @since 1.0.15
1318
+     * @return boolean
1319
+     */
1320
+    public function is_minimum_amount_met( $amount ) {
1321
+        $amount = floatval( wpinv_sanitize_amount( $amount ) );
1322
+        $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) );
1323
+        return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount );
1324
+    }
1325
+
1326
+    /**
1327
+     * Checks if the maximum amount is set
1328
+     *
1329
+     * @since 1.0.15
1330
+     * @return boolean
1331
+     */
1332
+    public function has_maximum_amount() {
1333
+        $maximum = $this->get_maximum_total();
1334
+        return ! empty( $maximum );
1335
+    }
1336
+
1337
+    /**
1338
+     * Checks if the maximum amount is met
1339
+     *
1340
+     * @param  float  $amount The amount to check against
1341
+     * @since 1.0.15
1342
+     * @return boolean
1343
+     */
1344
+    public function is_maximum_amount_met( $amount ) {
1345
+        $amount = floatval( wpinv_sanitize_amount( $amount ) );
1346
+        $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) );
1347
+        return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount );
1348
+    }
1349
+
1350
+    /**
1351
+     * Checks if the discount is recurring.
1352
+     *
1353
+     * @since 1.0.15
1354
+     * @return boolean
1355
+     */
1356
+    public function is_recurring() {
1357
+        $recurring = $this->get_is_recurring();
1358
+        return ! empty( $recurring );
1359
+    }
1360
+
1361
+    /**
1362
+     * Checks if the discount is single use.
1363
+     *
1364
+     * @since 1.0.15
1365
+     * @return boolean
1366
+     */
1367
+    public function is_single_use() {
1368
+        $usage = $this->get_is_single_use();
1369
+        return ! empty( $usage );
1370
+    }
1371
+
1372
+    /**
1373
+     * Check if a discount is valid for the given user
1374
+     *
1375
+     * @param  int|string  $user
1376
+     * @since 1.0.15
1377
+     * @return boolean
1378
+     */
1379
+    public function is_valid_for_user( $user ) {
1380
+        global $wpi_checkout_id;
1381
+
1382
+        // Ensure that the discount is single use.
1383
+        if ( empty( $user ) || ! $this->is_single_use() ) {
1384
+            return true;
1385
+        }
1386
+
1387
+        // Prepare the user id.
1388
+        $user_id = 0;
1389 1389
         if ( is_int( $user ) ) {
1390 1390
             $user_id = absint( $user );
1391 1391
         } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
@@ -1394,135 +1394,135 @@  discard block
 block discarded – undo
1394 1394
             $user_id = $user_data->ID;
1395 1395
         } else if ( absint( $user ) > 0 ) {
1396 1396
             $user_id = absint( $user );
1397
-		}
1397
+        }
1398 1398
 
1399
-		// Ensure that we have a user.
1400
-		if ( empty( $user_id ) ) {
1401
-			return true;
1402
-		}
1399
+        // Ensure that we have a user.
1400
+        if ( empty( $user_id ) ) {
1401
+            return true;
1402
+        }
1403 1403
 
1404
-		// Get all payments with matching user id.
1404
+        // Get all payments with matching user id.
1405 1405
         $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) );
1406
-		$code     = strtolower( $this->get_code() );
1407
-
1408
-		// For each payment...
1409
-		foreach ( $payments as $payment ) {
1410
-
1411
-			// ... skip the current payment.
1412
-			if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
1413
-				continue;
1414
-			}
1415
-
1416
-			// And failed payments.
1417
-			if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
1418
-				continue;
1419
-			}
1420
-
1421
-			// Retrieve all the discounts for the payment.
1422
-			$discounts = $payment->get_discounts( true );
1423
-			if ( empty( $discounts ) ) {
1424
-				continue;
1425
-			}
1426
-
1427
-			// And check if the current discount is amongst them.
1428
-			$discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) );
1429
-			if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) {
1430
-				return false;
1431
-			}
1432
-		}
1433
-
1434
-		return true;
1435
-	}
1436
-
1437
-	/**
1438
-	 * Deletes the discount from the database
1439
-	 *
1440
-	 * @since 1.0.15
1441
-	 * @return boolean
1442
-	 */
1443
-	public function remove() {
1444
-		return $this->delete();
1445
-	}
1446
-
1447
-	/**
1448
-	 * Increases a discount's usage.
1449
-	 *
1450
-	 * @since 1.0.15
1451
-	 * @param int $by The number of usages to increas by.
1452
-	 * @return int
1453
-	 */
1454
-	public function increase_usage( $by = 1 ) {
1455
-
1456
-		// Abort if zero.
1457
-		if ( empty( $by ) ) {
1458
-			return;
1459
-		}
1460
-
1461
-		// Increase the usage.
1462
-		$this->set_uses( $this->get_uses() + (int) $by );
1463
-
1464
-		// Save the discount.
1465
-		$this->save();
1466
-
1467
-		// Fire relevant hooks.
1468
-		if( (int) $by > 0 ) {
1469
-			do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code,  absint( $by ) );
1470
-		} else {
1471
-			do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) );
1472
-		}
1473
-
1474
-		// Return the number of times the discount has been used.
1475
-		return $this->get_uses();
1476
-	}
1477
-
1478
-	/**
1479
-	 * Alias of self::__toString()
1480
-	 *
1481
-	 * @since 1.0.15
1482
-	 * @return string|false
1483
-	 */
1484
-	public function get_data_as_json() {
1485
-		return $this->__toString();
1486
-	}
1487
-
1488
-	/**
1489
-	 * Returns a discount's discounted amount.
1490
-	 *
1491
-	 * @since 1.0.15
1492
-	 * @param float $amount
1493
-	 * @return float
1494
-	 */
1495
-	public function get_discounted_amount( $amount ) {
1496
-
1497
-		// Convert amount to float.
1498
-		$amount = (float) $amount;
1499
-
1500
-		// Get discount amount.
1501
-		$discount_amount = $this->get_amount();
1502
-
1503
-		if ( empty( $discount_amount ) ) {
1504
-			return 0;
1505
-		}
1506
-
1507
-		// Format the amount.
1508
-		$discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) );
1406
+        $code     = strtolower( $this->get_code() );
1407
+
1408
+        // For each payment...
1409
+        foreach ( $payments as $payment ) {
1410
+
1411
+            // ... skip the current payment.
1412
+            if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
1413
+                continue;
1414
+            }
1415
+
1416
+            // And failed payments.
1417
+            if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
1418
+                continue;
1419
+            }
1420
+
1421
+            // Retrieve all the discounts for the payment.
1422
+            $discounts = $payment->get_discounts( true );
1423
+            if ( empty( $discounts ) ) {
1424
+                continue;
1425
+            }
1426
+
1427
+            // And check if the current discount is amongst them.
1428
+            $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) );
1429
+            if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) {
1430
+                return false;
1431
+            }
1432
+        }
1433
+
1434
+        return true;
1435
+    }
1436
+
1437
+    /**
1438
+     * Deletes the discount from the database
1439
+     *
1440
+     * @since 1.0.15
1441
+     * @return boolean
1442
+     */
1443
+    public function remove() {
1444
+        return $this->delete();
1445
+    }
1446
+
1447
+    /**
1448
+     * Increases a discount's usage.
1449
+     *
1450
+     * @since 1.0.15
1451
+     * @param int $by The number of usages to increas by.
1452
+     * @return int
1453
+     */
1454
+    public function increase_usage( $by = 1 ) {
1455
+
1456
+        // Abort if zero.
1457
+        if ( empty( $by ) ) {
1458
+            return;
1459
+        }
1460
+
1461
+        // Increase the usage.
1462
+        $this->set_uses( $this->get_uses() + (int) $by );
1463
+
1464
+        // Save the discount.
1465
+        $this->save();
1466
+
1467
+        // Fire relevant hooks.
1468
+        if( (int) $by > 0 ) {
1469
+            do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code,  absint( $by ) );
1470
+        } else {
1471
+            do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) );
1472
+        }
1473
+
1474
+        // Return the number of times the discount has been used.
1475
+        return $this->get_uses();
1476
+    }
1477
+
1478
+    /**
1479
+     * Alias of self::__toString()
1480
+     *
1481
+     * @since 1.0.15
1482
+     * @return string|false
1483
+     */
1484
+    public function get_data_as_json() {
1485
+        return $this->__toString();
1486
+    }
1487
+
1488
+    /**
1489
+     * Returns a discount's discounted amount.
1490
+     *
1491
+     * @since 1.0.15
1492
+     * @param float $amount
1493
+     * @return float
1494
+     */
1495
+    public function get_discounted_amount( $amount ) {
1496
+
1497
+        // Convert amount to float.
1498
+        $amount = (float) $amount;
1499
+
1500
+        // Get discount amount.
1501
+        $discount_amount = $this->get_amount();
1502
+
1503
+        if ( empty( $discount_amount ) ) {
1504
+            return 0;
1505
+        }
1506
+
1507
+        // Format the amount.
1508
+        $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) );
1509 1509
 		
1510
-		// If this is a percentage discount.
1511
-		if ( $this->is_type( 'percent' ) ) {
1510
+        // If this is a percentage discount.
1511
+        if ( $this->is_type( 'percent' ) ) {
1512 1512
             $discount_amount = $amount * ( $discount_amount / 100 );
1513
-		}
1513
+        }
1514 1514
 
1515
-		// Discount can not be less than zero...
1516
-		if ( $discount_amount < 0 ) {
1517
-			$discount_amount = 0;
1518
-		}
1515
+        // Discount can not be less than zero...
1516
+        if ( $discount_amount < 0 ) {
1517
+            $discount_amount = 0;
1518
+        }
1519 1519
 
1520
-		// ... or more than the amount.
1521
-		if ( $discount_amount > $amount ) {
1522
-			$discount_amount = $amount;
1523
-		}
1520
+        // ... or more than the amount.
1521
+        if ( $discount_amount > $amount ) {
1522
+            $discount_amount = $amount;
1523
+        }
1524 1524
 
1525
-		return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this );
1526
-	}
1525
+        return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this );
1526
+    }
1527 1527
 
1528 1528
 }
Please login to merge, or discard this patch.
Spacing   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since   1.0.15
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Discount class.
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @since 1.0.15
14 14
  *
15 15
  */
16
-class WPInv_Discount extends GetPaid_Data  {
16
+class WPInv_Discount extends GetPaid_Data {
17 17
 
18 18
 	/**
19 19
 	 * Which data store to load.
@@ -79,35 +79,35 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code.
81 81
 	 */
82
-	public function __construct( $discount = 0 ) {
83
-		parent::__construct( $discount );
82
+	public function __construct($discount = 0) {
83
+		parent::__construct($discount);
84 84
 
85
-		if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) {
86
-			$this->set_id( $discount );
87
-		} elseif ( $discount instanceof self ) {
88
-			$this->set_id( $discount->get_id() );
89
-		} elseif ( ! empty( $discount->ID ) ) {
90
-			$this->set_id( $discount->ID );
91
-		} elseif ( is_array( $discount ) ) {
92
-			$this->set_props( $discount );
85
+		if (is_numeric($discount) && 'wpi_discount' === get_post_type($discount)) {
86
+			$this->set_id($discount);
87
+		} elseif ($discount instanceof self) {
88
+			$this->set_id($discount->get_id());
89
+		} elseif (!empty($discount->ID)) {
90
+			$this->set_id($discount->ID);
91
+		} elseif (is_array($discount)) {
92
+			$this->set_props($discount);
93 93
 
94
-			if ( isset( $discount['ID'] ) ) {
95
-				$this->set_id( $discount['ID'] );
94
+			if (isset($discount['ID'])) {
95
+				$this->set_id($discount['ID']);
96 96
 			}
97 97
 
98
-		} elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) {
99
-			$this->set_id( $discount );
98
+		} elseif (is_scalar($discount) && $discount = self::get_discount_id_by_code($discount)) {
99
+			$this->set_id($discount);
100 100
 		} else {
101
-			$this->set_object_read( true );
101
+			$this->set_object_read(true);
102 102
 		}
103 103
 
104 104
         // Load the datastore.
105
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
105
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
106 106
 
107
-		if ( $this->get_id() > 0 ) {
108
-            $this->post = get_post( $this->get_id() );
107
+		if ($this->get_id() > 0) {
108
+            $this->post = get_post($this->get_id());
109 109
             $this->ID   = $this->get_id();
110
-			$this->data_store->read( $this );
110
+			$this->data_store->read($this);
111 111
         }
112 112
 
113 113
 	}
@@ -123,50 +123,50 @@  discard block
 block discarded – undo
123 123
 	 * @since 1.0.15
124 124
 	 * @return array|bool array of discount details on success. False otherwise.
125 125
 	 */
126
-	public static function get_data_by( $field, $value ) {
126
+	public static function get_data_by($field, $value) {
127 127
 
128
-		if ( 'id' == strtolower( $field ) ) {
128
+		if ('id' == strtolower($field)) {
129 129
 			// Make sure the value is numeric to avoid casting objects, for example,
130 130
 			// to int 1.
131
-			if ( ! is_numeric( $value ) )
131
+			if (!is_numeric($value))
132 132
 				return false;
133
-			$value = intval( $value );
134
-			if ( $value < 1 )
133
+			$value = intval($value);
134
+			if ($value < 1)
135 135
 				return false;
136 136
 		}
137 137
 
138
-		if ( ! $value || ! is_string( $field ) ) {
138
+		if (!$value || !is_string($field)) {
139 139
 			return false;
140 140
 		}
141 141
 
142
-		$field = trim( $field );
142
+		$field = trim($field);
143 143
 
144 144
 		// prepare query args
145
-		switch ( strtolower( $field ) ) {
145
+		switch (strtolower($field)) {
146 146
 			case 'id':
147 147
 				$discount_id = $value;
148
-				$args		 = array( 'include' => array( $value ) );
148
+				$args = array('include' => array($value));
149 149
 				break;
150 150
 			case 'discount_code':
151 151
 			case 'code':
152
-				$value       = trim( $value );
153
-				$discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
154
-				$args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
152
+				$value       = trim($value);
153
+				$discount_id = wp_cache_get($value, 'WPInv_Discount_Codes');
154
+				$args = array('meta_key' => '_wpi_discount_code', 'meta_value' => $value);
155 155
 				break;
156 156
 			case 'name':
157 157
 				$discount_id = 0;
158
-				$args		 = array( 'name' => trim( $value ) );
158
+				$args		 = array('name' => trim($value));
159 159
 				break;
160 160
 			default:
161
-				$args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
162
-				if ( ! is_array( $args ) ) {
163
-					return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
161
+				$args		 = apply_filters("wpinv_discount_get_data_by_{$field}_args", null, $value);
162
+				if (!is_array($args)) {
163
+					return apply_filters("wpinv_discount_get_data_by_$field", false, $value);
164 164
 				}
165 165
 
166 166
 		}
167 167
 
168 168
 		// Check if there is a cached value.
169
-		if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
169
+		if (!empty($discount_id) && $discount = wp_cache_get((int) $discount_id, 'WPInv_Discounts')) {
170 170
 			return $discount;
171 171
 		}
172 172
 
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
 			array(
176 176
 				'post_type'      => 'wpi_discount',
177 177
 				'posts_per_page' => 1,
178
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
178
+				'post_status'    => array('publish', 'pending', 'draft', 'expired')
179 179
 			)
180 180
 		);
181 181
 
182
-		$discount = get_posts( $args );
182
+		$discount = get_posts($args);
183 183
 
184
-		if( empty( $discount ) ) {
184
+		if (empty($discount)) {
185 185
 			return false;
186 186
 		}
187 187
 
@@ -190,30 +190,30 @@  discard block
 block discarded – undo
190 190
 		// Prepare the return data.
191 191
 		$return = array(
192 192
             'ID'                          => $discount->ID,
193
-            'code'                        => get_post_meta( $discount->ID, '_wpi_discount_code', true ),
194
-            'amount'                      => get_post_meta( $discount->ID, '_wpi_discount_amount', true ),
193
+            'code'                        => get_post_meta($discount->ID, '_wpi_discount_code', true),
194
+            'amount'                      => get_post_meta($discount->ID, '_wpi_discount_amount', true),
195 195
             'date_created'                => $discount->post_date,
196 196
 			'date_modified'               => $discount->post_modified,
197 197
 			'status'               		  => $discount->post_status,
198
-			'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
199
-            'expiration'                  => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ),
200
-            'type'               		  => get_post_meta( $discount->ID, '_wpi_discount_type', true ),
198
+			'start'                  	  => get_post_meta($discount->ID, '_wpi_discount_start', true),
199
+            'expiration'                  => get_post_meta($discount->ID, '_wpi_discount_expiration', true),
200
+            'type'               		  => get_post_meta($discount->ID, '_wpi_discount_type', true),
201 201
             'description'                 => $discount->post_excerpt,
202
-            'uses'                 		  => get_post_meta( $discount->ID, '_wpi_discount_uses', true ),
203
-            'is_single_use'               => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ),
204
-            'items'              	      => get_post_meta( $discount->ID, '_wpi_discount_items', true ),
205
-            'excluded_items'              => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ),
206
-            'max_uses'                    => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ),
207
-            'is_recurring'                => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ),
208
-            'min_total'                   => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ),
209
-            'max_total'                   => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ),
202
+            'uses'                 		  => get_post_meta($discount->ID, '_wpi_discount_uses', true),
203
+            'is_single_use'               => get_post_meta($discount->ID, '_wpi_discount_is_single_use', true),
204
+            'items'              	      => get_post_meta($discount->ID, '_wpi_discount_items', true),
205
+            'excluded_items'              => get_post_meta($discount->ID, '_wpi_discount_excluded_items', true),
206
+            'max_uses'                    => get_post_meta($discount->ID, '_wpi_discount_max_uses', true),
207
+            'is_recurring'                => get_post_meta($discount->ID, '_wpi_discount_is_recurring', true),
208
+            'min_total'                   => get_post_meta($discount->ID, '_wpi_discount_min_total', true),
209
+            'max_total'                   => get_post_meta($discount->ID, '_wpi_discount_max_total', true),
210 210
         );
211 211
 
212
-		$return = apply_filters( 'wpinv_discount_properties', $return );
212
+		$return = apply_filters('wpinv_discount_properties', $return);
213 213
 
214 214
 		// Update the cache with our data
215
-		wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
216
-		wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
215
+		wp_cache_add($discount->ID, $return, 'WPInv_Discounts');
216
+		wp_cache_add($return['code'], $discount->ID, 'WPInv_Discount_Codes');
217 217
 
218 218
 		return $return;
219 219
 	}
@@ -227,19 +227,19 @@  discard block
 block discarded – undo
227 227
 	 * @since 1.0.15
228 228
 	 * @return int
229 229
 	 */
230
-	public static function get_discount_id_by_code( $discount_code ) {
230
+	public static function get_discount_id_by_code($discount_code) {
231 231
 
232 232
 		// Trim the code.
233
-		$discount_code = trim( $discount_code );
233
+		$discount_code = trim($discount_code);
234 234
 
235 235
 		// Ensure a value has been passed.
236
-		if ( empty( $discount_code ) ) {
236
+		if (empty($discount_code)) {
237 237
 			return 0;
238 238
 		}
239 239
 
240 240
 		// Maybe retrieve from the cache.
241
-		$discount_id   = wp_cache_get( $discount_code, 'getpaid_discount_codes' );
242
-		if ( ! empty( $discount_id ) ) {
241
+		$discount_id = wp_cache_get($discount_code, 'getpaid_discount_codes');
242
+		if (!empty($discount_id)) {
243 243
 			return $discount_id;
244 244
 		}
245 245
 
@@ -250,19 +250,19 @@  discard block
 block discarded – undo
250 250
 				'meta_value'     => $discount_code,
251 251
 				'post_type'      => 'wpi_discount',
252 252
 				'posts_per_page' => 1,
253
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' ),
253
+				'post_status'    => array('publish', 'pending', 'draft', 'expired'),
254 254
 				'fields'         => 'ids',
255 255
 			)
256 256
 		);
257 257
 
258
-		if ( empty( $discounts ) ) {
258
+		if (empty($discounts)) {
259 259
 			return 0;
260 260
 		}
261 261
 
262 262
 		$discount_id = $discounts[0];
263 263
 
264 264
 		// Update the cache with our data
265
-		wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' );
265
+		wp_cache_add(get_post_meta($discount_id, '_wpi_discount_code', true), $discount_id, 'getpaid_discount_codes');
266 266
 
267 267
 		return $discount_id;
268 268
 	}
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @return bool Whether the given discount field is set.
277 277
 	 */
278
-	public function __isset( $key ){
279
-		return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
278
+	public function __isset($key) {
279
+		return isset($this->data[$key]) || method_exists($this, "get_$key");
280 280
 	}
281 281
 
282 282
 	/*
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @param  string $context View or edit context.
302 302
 	 * @return string
303 303
 	 */
304
-	public function get_status( $context = 'view' ) {
305
-		return $this->get_prop( 'status', $context );
304
+	public function get_status($context = 'view') {
305
+		return $this->get_prop('status', $context);
306 306
     }
307 307
 
308 308
     /**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 	 * @param  string $context View or edit context.
313 313
 	 * @return string
314 314
 	 */
315
-	public function get_version( $context = 'view' ) {
316
-		return $this->get_prop( 'version', $context );
315
+	public function get_version($context = 'view') {
316
+		return $this->get_prop('version', $context);
317 317
     }
318 318
 
319 319
     /**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context View or edit context.
324 324
 	 * @return string
325 325
 	 */
326
-	public function get_date_created( $context = 'view' ) {
327
-		return $this->get_prop( 'date_created', $context );
326
+	public function get_date_created($context = 'view') {
327
+		return $this->get_prop('date_created', $context);
328 328
     }
329 329
 
330 330
     /**
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 	 * @param  string $context View or edit context.
335 335
 	 * @return string
336 336
 	 */
337
-	public function get_date_created_gmt( $context = 'view' ) {
338
-        $date = $this->get_date_created( $context );
337
+	public function get_date_created_gmt($context = 'view') {
338
+        $date = $this->get_date_created($context);
339 339
 
340
-        if ( $date ) {
341
-            $date = get_gmt_from_date( $date );
340
+        if ($date) {
341
+            $date = get_gmt_from_date($date);
342 342
         }
343 343
 		return $date;
344 344
     }
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 	 * @param  string $context View or edit context.
351 351
 	 * @return string
352 352
 	 */
353
-	public function get_date_modified( $context = 'view' ) {
354
-		return $this->get_prop( 'date_modified', $context );
353
+	public function get_date_modified($context = 'view') {
354
+		return $this->get_prop('date_modified', $context);
355 355
     }
356 356
 
357 357
     /**
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
 	 * @param  string $context View or edit context.
362 362
 	 * @return string
363 363
 	 */
364
-	public function get_date_modified_gmt( $context = 'view' ) {
365
-        $date = $this->get_date_modified( $context );
364
+	public function get_date_modified_gmt($context = 'view') {
365
+        $date = $this->get_date_modified($context);
366 366
 
367
-        if ( $date ) {
368
-            $date = get_gmt_from_date( $date );
367
+        if ($date) {
368
+            $date = get_gmt_from_date($date);
369 369
         }
370 370
 		return $date;
371 371
     }
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 * @param  string $context View or edit context.
378 378
 	 * @return string
379 379
 	 */
380
-	public function get_name( $context = 'view' ) {
381
-		return $this->get_prop( 'name', $context );
380
+	public function get_name($context = 'view') {
381
+		return $this->get_prop('name', $context);
382 382
     }
383 383
 
384 384
     /**
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
 	 * @param  string $context View or edit context.
389 389
 	 * @return string
390 390
 	 */
391
-	public function get_title( $context = 'view' ) {
392
-		return $this->get_name( $context );
391
+	public function get_title($context = 'view') {
392
+		return $this->get_name($context);
393 393
     }
394 394
 
395 395
     /**
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 	 * @param  string $context View or edit context.
400 400
 	 * @return string
401 401
 	 */
402
-	public function get_description( $context = 'view' ) {
403
-		return $this->get_prop( 'description', $context );
402
+	public function get_description($context = 'view') {
403
+		return $this->get_prop('description', $context);
404 404
     }
405 405
 
406 406
     /**
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
 	 * @param  string $context View or edit context.
411 411
 	 * @return string
412 412
 	 */
413
-	public function get_excerpt( $context = 'view' ) {
414
-		return $this->get_description( $context );
413
+	public function get_excerpt($context = 'view') {
414
+		return $this->get_description($context);
415 415
     }
416 416
 
417 417
     /**
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	 * @param  string $context View or edit context.
422 422
 	 * @return string
423 423
 	 */
424
-	public function get_summary( $context = 'view' ) {
425
-		return $this->get_description( $context );
424
+	public function get_summary($context = 'view') {
425
+		return $this->get_description($context);
426 426
     }
427 427
 
428 428
     /**
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 	 * @param  string $context View or edit context.
433 433
 	 * @return string
434 434
 	 */
435
-	public function get_author( $context = 'view' ) {
436
-		return (int) $this->get_prop( 'author', $context );
435
+	public function get_author($context = 'view') {
436
+		return (int) $this->get_prop('author', $context);
437 437
 	}
438 438
 	
439 439
 	/**
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 * @param  string $context View or edit context.
444 444
 	 * @return string
445 445
 	 */
446
-	public function get_code( $context = 'view' ) {
447
-		return $this->get_prop( 'code', $context );
446
+	public function get_code($context = 'view') {
447
+		return $this->get_prop('code', $context);
448 448
 	}
449 449
 	
450 450
 	/**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param  string $context View or edit context.
455 455
 	 * @return string
456 456
 	 */
457
-	public function get_coupon_code( $context = 'view' ) {
458
-		return $this->get_code( $context );
457
+	public function get_coupon_code($context = 'view') {
458
+		return $this->get_code($context);
459 459
 	}
460 460
 	
461 461
 	/**
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 	 * @param  string $context View or edit context.
466 466
 	 * @return string
467 467
 	 */
468
-	public function get_discount_code( $context = 'view' ) {
469
-		return $this->get_code( $context );
468
+	public function get_discount_code($context = 'view') {
469
+		return $this->get_code($context);
470 470
 	}
471 471
 	
472 472
 	/**
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
 	 * @param  string $context View or edit context.
477 477
 	 * @return float
478 478
 	 */
479
-	public function get_amount( $context = 'view' ) {
480
-		return $this->get_prop( 'amount', $context );
479
+	public function get_amount($context = 'view') {
480
+		return $this->get_prop('amount', $context);
481 481
 	}
482 482
 
483 483
 	/**
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
 	 */
489 489
 	public function get_formatted_amount() {
490 490
 
491
-		if ( $this->is_type( 'flat' ) ) {
492
-			$rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) );
491
+		if ($this->is_type('flat')) {
492
+			$rate = wpinv_price(wpinv_format_amount($this->get_amount()));
493 493
 		} else {
494 494
 			$rate = $this->get_amount() . '%';
495 495
 		}
496 496
 
497
-		return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() );
497
+		return apply_filters('wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount());
498 498
 	}
499 499
 
500
-	function wpinv_format_discount_rate( $type, $amount ) {
501
-		if ( $type == 'flat' ) {
502
-			$rate = wpinv_price( wpinv_format_amount( $amount ) );
500
+	function wpinv_format_discount_rate($type, $amount) {
501
+		if ($type == 'flat') {
502
+			$rate = wpinv_price(wpinv_format_amount($amount));
503 503
 		} else {
504 504
 			$rate = $amount . '%';
505 505
 		}
506 506
 	
507
-		return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount );
507
+		return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount);
508 508
 	}
509 509
 	
510 510
 	/**
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
 	 * @param  string $context View or edit context.
515 515
 	 * @return string
516 516
 	 */
517
-	public function get_start( $context = 'view' ) {
518
-		return $this->get_prop( 'start', $context );
517
+	public function get_start($context = 'view') {
518
+		return $this->get_prop('start', $context);
519 519
 	}
520 520
 	
521 521
 	/**
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
 	 * @param  string $context View or edit context.
526 526
 	 * @return string
527 527
 	 */
528
-	public function get_start_date( $context = 'view' ) {
529
-		return $this->get_start( $context );
528
+	public function get_start_date($context = 'view') {
529
+		return $this->get_start($context);
530 530
 	}
531 531
 	
532 532
 	/**
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
 	 * @param  string $context View or edit context.
537 537
 	 * @return string
538 538
 	 */
539
-	public function get_expiration( $context = 'view' ) {
540
-		return $this->get_prop( 'expiration', $context );
539
+	public function get_expiration($context = 'view') {
540
+		return $this->get_prop('expiration', $context);
541 541
 	}
542 542
 	
543 543
 	/**
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
 	 * @param  string $context View or edit context.
548 548
 	 * @return string
549 549
 	 */
550
-	public function get_expiration_date( $context = 'view' ) {
551
-		return $this->get_expiration( $context );
550
+	public function get_expiration_date($context = 'view') {
551
+		return $this->get_expiration($context);
552 552
 	}
553 553
 
554 554
 	/**
@@ -558,8 +558,8 @@  discard block
 block discarded – undo
558 558
 	 * @param  string $context View or edit context.
559 559
 	 * @return string
560 560
 	 */
561
-	public function get_end_date( $context = 'view' ) {
562
-		return $this->get_expiration( $context );
561
+	public function get_end_date($context = 'view') {
562
+		return $this->get_expiration($context);
563 563
 	}
564 564
 	
565 565
 	/**
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 	 * @param  string $context View or edit context.
570 570
 	 * @return string
571 571
 	 */
572
-	public function get_type( $context = 'view' ) {
573
-		return $this->get_prop( 'type', $context );
572
+	public function get_type($context = 'view') {
573
+		return $this->get_prop('type', $context);
574 574
 	}
575 575
 
576 576
 	/**
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @param  string $context View or edit context.
581 581
 	 * @return int
582 582
 	 */
583
-	public function get_uses( $context = 'view' ) {
584
-		return (int) $this->get_prop( 'uses', $context );
583
+	public function get_uses($context = 'view') {
584
+		return (int) $this->get_prop('uses', $context);
585 585
 	}
586 586
 
587 587
 	/**
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 	 */
593 593
 	public function get_usage() {
594 594
 
595
-		if ( ! $this->has_limit() ) {
595
+		if (!$this->has_limit()) {
596 596
 			return $this->get_uses() . ' / ' . ' &infin;';
597 597
 		}
598 598
 
@@ -607,9 +607,9 @@  discard block
 block discarded – undo
607 607
 	 * @param  string $context View or edit context.
608 608
 	 * @return int
609 609
 	 */
610
-	public function get_max_uses( $context = 'view' ) {
611
-		$max_uses = $this->get_prop( 'max_uses', $context );
612
-		return empty( $max_uses ) ? null : $max_uses;
610
+	public function get_max_uses($context = 'view') {
611
+		$max_uses = $this->get_prop('max_uses', $context);
612
+		return empty($max_uses) ? null : $max_uses;
613 613
 	}
614 614
 
615 615
 	/**
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
 	 * @param  string $context View or edit context.
620 620
 	 * @return bool
621 621
 	 */
622
-	public function get_is_single_use( $context = 'view' ) {
623
-		return $this->get_prop( 'is_single_use', $context );
622
+	public function get_is_single_use($context = 'view') {
623
+		return $this->get_prop('is_single_use', $context);
624 624
 	}
625 625
 
626 626
 	/**
@@ -630,8 +630,8 @@  discard block
 block discarded – undo
630 630
 	 * @param  string $context View or edit context.
631 631
 	 * @return array
632 632
 	 */
633
-	public function get_items( $context = 'view' ) {
634
-		return wpinv_parse_list( $this->get_prop( 'items', $context ) );
633
+	public function get_items($context = 'view') {
634
+		return wpinv_parse_list($this->get_prop('items', $context));
635 635
 	}
636 636
 
637 637
 	/**
@@ -641,8 +641,8 @@  discard block
 block discarded – undo
641 641
 	 * @param  string $context View or edit context.
642 642
 	 * @return array
643 643
 	 */
644
-	public function get_allowed_items( $context = 'view' ) {
645
-		return $this->get_items( $context );
644
+	public function get_allowed_items($context = 'view') {
645
+		return $this->get_items($context);
646 646
 	}
647 647
 
648 648
 	/**
@@ -652,8 +652,8 @@  discard block
 block discarded – undo
652 652
 	 * @param  string $context View or edit context.
653 653
 	 * @return array
654 654
 	 */
655
-	public function get_excluded_items( $context = 'view' ) {
656
-		return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) );
655
+	public function get_excluded_items($context = 'view') {
656
+		return wpinv_parse_list($this->get_prop('excluded_items', $context));
657 657
 	}
658 658
 
659 659
 	/**
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
 	 * @param  string $context View or edit context.
664 664
 	 * @return int|string|bool
665 665
 	 */
666
-	public function get_is_recurring( $context = 'view' ) {
667
-		return $this->get_prop( 'is_recurring', $context );
666
+	public function get_is_recurring($context = 'view') {
667
+		return $this->get_prop('is_recurring', $context);
668 668
 	}
669 669
 
670 670
 	/**
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 	 * @param  string $context View or edit context.
675 675
 	 * @return float
676 676
 	 */
677
-	public function get_min_total( $context = 'view' ) {
678
-		$minimum = $this->get_prop( 'min_total', $context );
679
-		return empty( $minimum ) ? null : $minimum;
677
+	public function get_min_total($context = 'view') {
678
+		$minimum = $this->get_prop('min_total', $context);
679
+		return empty($minimum) ? null : $minimum;
680 680
 	}
681 681
 
682 682
 	/**
@@ -686,8 +686,8 @@  discard block
 block discarded – undo
686 686
 	 * @param  string $context View or edit context.
687 687
 	 * @return float
688 688
 	 */
689
-	public function get_minimum_total( $context = 'view' ) {
690
-		return $this->get_min_total( $context );
689
+	public function get_minimum_total($context = 'view') {
690
+		return $this->get_min_total($context);
691 691
 	}
692 692
 
693 693
 	/**
@@ -697,9 +697,9 @@  discard block
 block discarded – undo
697 697
 	 * @param  string $context View or edit context.
698 698
 	 * @return float
699 699
 	 */
700
-	public function get_max_total( $context = 'view' ) {
701
-		$maximum = $this->get_prop( 'max_total', $context );
702
-		return empty( $maximum ) ? null : $maximum;
700
+	public function get_max_total($context = 'view') {
701
+		$maximum = $this->get_prop('max_total', $context);
702
+		return empty($maximum) ? null : $maximum;
703 703
 	}
704 704
 
705 705
 	/**
@@ -709,8 +709,8 @@  discard block
 block discarded – undo
709 709
 	 * @param  string $context View or edit context.
710 710
 	 * @return float
711 711
 	 */
712
-	public function get_maximum_total( $context = 'view' ) {
713
-		return $this->get_max_total( $context );
712
+	public function get_maximum_total($context = 'view') {
713
+		return $this->get_max_total($context);
714 714
 	}
715 715
 
716 716
 	/**
@@ -723,8 +723,8 @@  discard block
 block discarded – undo
723 723
 	 * @param  string $context View or edit context.
724 724
 	 * @return mixed Value of the given discount property (if set).
725 725
 	 */
726
-	public function get( $key, $context = 'view' ) {
727
-        return $this->get_prop( $key, $context );
726
+	public function get($key, $context = 'view') {
727
+        return $this->get_prop($key, $context);
728 728
 	}
729 729
 
730 730
 	/*
@@ -744,10 +744,10 @@  discard block
 block discarded – undo
744 744
 	 * @param  string $status New status.
745 745
 	 * @return array details of change.
746 746
 	 */
747
-	public function set_status( $status ) {
747
+	public function set_status($status) {
748 748
         $old_status = $this->get_status();
749 749
 
750
-        $this->set_prop( 'status', $status );
750
+        $this->set_prop('status', $status);
751 751
 
752 752
 		return array(
753 753
 			'from' => $old_status,
@@ -760,8 +760,8 @@  discard block
 block discarded – undo
760 760
 	 *
761 761
 	 * @since 1.0.19
762 762
 	 */
763
-	public function set_version( $value ) {
764
-		$this->set_prop( 'version', $value );
763
+	public function set_version($value) {
764
+		$this->set_prop('version', $value);
765 765
     }
766 766
 
767 767
     /**
@@ -771,11 +771,11 @@  discard block
 block discarded – undo
771 771
 	 * @param string $value Value to set.
772 772
      * @return bool Whether or not the date was set.
773 773
 	 */
774
-	public function set_date_created( $value ) {
775
-        $date = strtotime( $value );
774
+	public function set_date_created($value) {
775
+        $date = strtotime($value);
776 776
 
777
-        if ( $date ) {
778
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
777
+        if ($date) {
778
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
779 779
             return true;
780 780
         }
781 781
 
@@ -790,11 +790,11 @@  discard block
 block discarded – undo
790 790
 	 * @param string $value Value to set.
791 791
      * @return bool Whether or not the date was set.
792 792
 	 */
793
-	public function set_date_modified( $value ) {
794
-        $date = strtotime( $value );
793
+	public function set_date_modified($value) {
794
+        $date = strtotime($value);
795 795
 
796
-        if ( $date ) {
797
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
796
+        if ($date) {
797
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
798 798
             return true;
799 799
         }
800 800
 
@@ -808,9 +808,9 @@  discard block
 block discarded – undo
808 808
 	 * @since 1.0.19
809 809
 	 * @param  string $value New name.
810 810
 	 */
811
-	public function set_name( $value ) {
812
-        $name = sanitize_text_field( $value );
813
-		$this->set_prop( 'name', $name );
811
+	public function set_name($value) {
812
+        $name = sanitize_text_field($value);
813
+		$this->set_prop('name', $name);
814 814
     }
815 815
 
816 816
     /**
@@ -819,8 +819,8 @@  discard block
 block discarded – undo
819 819
 	 * @since 1.0.19
820 820
 	 * @param  string $value New name.
821 821
 	 */
822
-	public function set_title( $value ) {
823
-		$this->set_name( $value );
822
+	public function set_title($value) {
823
+		$this->set_name($value);
824 824
     }
825 825
 
826 826
     /**
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
 	 * @since 1.0.19
830 830
 	 * @param  string $value New description.
831 831
 	 */
832
-	public function set_description( $value ) {
833
-        $description = wp_kses_post( $value );
834
-		return $this->set_prop( 'description', $description );
832
+	public function set_description($value) {
833
+        $description = wp_kses_post($value);
834
+		return $this->set_prop('description', $description);
835 835
     }
836 836
 
837 837
     /**
@@ -840,8 +840,8 @@  discard block
 block discarded – undo
840 840
 	 * @since 1.0.19
841 841
 	 * @param  string $value New description.
842 842
 	 */
843
-	public function set_excerpt( $value ) {
844
-		$this->set_description( $value );
843
+	public function set_excerpt($value) {
844
+		$this->set_description($value);
845 845
     }
846 846
 
847 847
     /**
@@ -850,8 +850,8 @@  discard block
 block discarded – undo
850 850
 	 * @since 1.0.19
851 851
 	 * @param  string $value New description.
852 852
 	 */
853
-	public function set_summary( $value ) {
854
-		$this->set_description( $value );
853
+	public function set_summary($value) {
854
+		$this->set_description($value);
855 855
     }
856 856
 
857 857
     /**
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
 	 * @since 1.0.19
861 861
 	 * @param  int $value New author.
862 862
 	 */
863
-	public function set_author( $value ) {
864
-		$this->set_prop( 'author', (int) $value );
863
+	public function set_author($value) {
864
+		$this->set_prop('author', (int) $value);
865 865
 	}
866 866
 	
867 867
 	/**
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
 	 * @since 1.0.19
871 871
 	 * @param string $value New discount code.
872 872
 	 */
873
-	public function set_code( $value ) {
874
-		$code = sanitize_text_field( $value );
875
-		$this->set_prop( 'code', $code );
873
+	public function set_code($value) {
874
+		$code = sanitize_text_field($value);
875
+		$this->set_prop('code', $code);
876 876
 	}
877 877
 	
878 878
 	/**
@@ -881,8 +881,8 @@  discard block
 block discarded – undo
881 881
 	 * @since 1.0.19
882 882
 	 * @param string $value New discount code.
883 883
 	 */
884
-	public function set_coupon_code( $value ) {
885
-		$this->set_code( $value );
884
+	public function set_coupon_code($value) {
885
+		$this->set_code($value);
886 886
 	}
887 887
 	
888 888
 	/**
@@ -891,8 +891,8 @@  discard block
 block discarded – undo
891 891
 	 * @since 1.0.19
892 892
 	 * @param string $value New discount code.
893 893
 	 */
894
-	public function set_discount_code( $value ) {
895
-		$this->set_code( $value );
894
+	public function set_discount_code($value) {
895
+		$this->set_code($value);
896 896
 	}
897 897
 	
898 898
 	/**
@@ -901,9 +901,9 @@  discard block
 block discarded – undo
901 901
 	 * @since 1.0.19
902 902
 	 * @param float $value New discount code.
903 903
 	 */
904
-	public function set_amount( $value ) {
905
-		$amount = floatval( wpinv_sanitize_amount( $value ) );
906
-		$this->set_prop( 'amount', $amount );
904
+	public function set_amount($value) {
905
+		$amount = floatval(wpinv_sanitize_amount($value));
906
+		$this->set_prop('amount', $amount);
907 907
 	}
908 908
 
909 909
 	/**
@@ -912,15 +912,15 @@  discard block
 block discarded – undo
912 912
 	 * @since 1.0.19
913 913
 	 * @param float $value New start date.
914 914
 	 */
915
-	public function set_start( $value ) {
916
-		$date = strtotime( $value );
915
+	public function set_start($value) {
916
+		$date = strtotime($value);
917 917
 
918
-        if ( $date ) {
919
-            $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) );
918
+        if ($date) {
919
+            $this->set_prop('start', date('Y-m-d H:i', $date));
920 920
             return true;
921 921
 		}
922 922
 		
923
-		$this->set_prop( 'start', '' );
923
+		$this->set_prop('start', '');
924 924
 
925 925
         return false;
926 926
 	}
@@ -931,8 +931,8 @@  discard block
 block discarded – undo
931 931
 	 * @since 1.0.19
932 932
 	 * @param string $value New start date.
933 933
 	 */
934
-	public function set_start_date( $value ) {
935
-		$this->set_start( $value );
934
+	public function set_start_date($value) {
935
+		$this->set_start($value);
936 936
 	}
937 937
 
938 938
 	/**
@@ -941,15 +941,15 @@  discard block
 block discarded – undo
941 941
 	 * @since 1.0.19
942 942
 	 * @param float $value New expiration date.
943 943
 	 */
944
-	public function set_expiration( $value ) {
945
-		$date = strtotime( $value );
944
+	public function set_expiration($value) {
945
+		$date = strtotime($value);
946 946
 
947
-        if ( $date ) {
948
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) );
947
+        if ($date) {
948
+            $this->set_prop('expiration', date('Y-m-d H:i', $date));
949 949
             return true;
950 950
         }
951 951
 
952
-		$this->set_prop( 'expiration', '' );
952
+		$this->set_prop('expiration', '');
953 953
         return false;
954 954
 	}
955 955
 
@@ -959,8 +959,8 @@  discard block
 block discarded – undo
959 959
 	 * @since 1.0.19
960 960
 	 * @param string $value New expiration date.
961 961
 	 */
962
-	public function set_expiration_date( $value ) {
963
-		$this->set_expiration( $value );
962
+	public function set_expiration_date($value) {
963
+		$this->set_expiration($value);
964 964
 	}
965 965
 
966 966
 	/**
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 	 * @since 1.0.19
970 970
 	 * @param string $value New expiration date.
971 971
 	 */
972
-	public function set_end_date( $value ) {
973
-		$this->set_expiration( $value );
972
+	public function set_end_date($value) {
973
+		$this->set_expiration($value);
974 974
 	}
975 975
 
976 976
 	/**
@@ -979,9 +979,9 @@  discard block
 block discarded – undo
979 979
 	 * @since 1.0.19
980 980
 	 * @param string $value New discount type.
981 981
 	 */
982
-	public function set_type( $value ) {
983
-		if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) {
984
-			$this->set_prop( 'type', sanitize_text_field( $value ) );
982
+	public function set_type($value) {
983
+		if ($value && array_key_exists(sanitize_text_field($value), wpinv_get_discount_types())) {
984
+			$this->set_prop('type', sanitize_text_field($value));
985 985
 		}
986 986
 	}
987 987
 
@@ -991,15 +991,15 @@  discard block
 block discarded – undo
991 991
 	 * @since 1.0.19
992 992
 	 * @param int $value usage count.
993 993
 	 */
994
-	public function set_uses( $value ) {
994
+	public function set_uses($value) {
995 995
 
996 996
 		$value = (int) $value;
997 997
 
998
-		if ( $value < 0 ) {
998
+		if ($value < 0) {
999 999
 			$value = 0;
1000 1000
 		}
1001 1001
 
1002
-		$this->set_prop( 'uses', (int) $value );
1002
+		$this->set_prop('uses', (int) $value);
1003 1003
 	}
1004 1004
 
1005 1005
 	/**
@@ -1008,8 +1008,8 @@  discard block
 block discarded – undo
1008 1008
 	 * @since 1.0.19
1009 1009
 	 * @param int $value maximum usage count.
1010 1010
 	 */
1011
-	public function set_max_uses( $value ) {
1012
-		$this->set_prop( 'max_uses', absint( $value ) );
1011
+	public function set_max_uses($value) {
1012
+		$this->set_prop('max_uses', absint($value));
1013 1013
 	}
1014 1014
 
1015 1015
 	/**
@@ -1018,8 +1018,8 @@  discard block
 block discarded – undo
1018 1018
 	 * @since 1.0.19
1019 1019
 	 * @param int|bool $value is single use.
1020 1020
 	 */
1021
-	public function set_is_single_use( $value ) {
1022
-		$this->set_prop( 'is_single_use', (bool) $value );
1021
+	public function set_is_single_use($value) {
1022
+		$this->set_prop('is_single_use', (bool) $value);
1023 1023
 	}
1024 1024
 
1025 1025
 	/**
@@ -1028,8 +1028,8 @@  discard block
 block discarded – undo
1028 1028
 	 * @since 1.0.19
1029 1029
 	 * @param array $value items.
1030 1030
 	 */
1031
-	public function set_items( $value ) {
1032
-		$this->set_prop( 'items', wpinv_parse_list( $value ) );
1031
+	public function set_items($value) {
1032
+		$this->set_prop('items', wpinv_parse_list($value));
1033 1033
 	}
1034 1034
 
1035 1035
 	/**
@@ -1038,8 +1038,8 @@  discard block
 block discarded – undo
1038 1038
 	 * @since 1.0.19
1039 1039
 	 * @param array $value items.
1040 1040
 	 */
1041
-	public function set_allowed_items( $value ) {
1042
-		$this->set_items( $value );
1041
+	public function set_allowed_items($value) {
1042
+		$this->set_items($value);
1043 1043
 	}
1044 1044
 
1045 1045
 	/**
@@ -1048,8 +1048,8 @@  discard block
 block discarded – undo
1048 1048
 	 * @since 1.0.19
1049 1049
 	 * @param array $value items.
1050 1050
 	 */
1051
-	public function set_excluded_items( $value ) {
1052
-		$this->set_prop( 'excluded_items', wpinv_parse_list( $value ) );
1051
+	public function set_excluded_items($value) {
1052
+		$this->set_prop('excluded_items', wpinv_parse_list($value));
1053 1053
 	}
1054 1054
 
1055 1055
 	/**
@@ -1058,8 +1058,8 @@  discard block
 block discarded – undo
1058 1058
 	 * @since 1.0.19
1059 1059
 	 * @param int|bool $value is recurring.
1060 1060
 	 */
1061
-	public function set_is_recurring( $value ) {
1062
-		$this->set_prop( 'is_recurring', (bool) $value );
1061
+	public function set_is_recurring($value) {
1062
+		$this->set_prop('is_recurring', (bool) $value);
1063 1063
 	}
1064 1064
 
1065 1065
 	/**
@@ -1068,8 +1068,8 @@  discard block
 block discarded – undo
1068 1068
 	 * @since 1.0.19
1069 1069
 	 * @param float $value minimum total.
1070 1070
 	 */
1071
-	public function set_min_total( $value ) {
1072
-		$this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) );
1071
+	public function set_min_total($value) {
1072
+		$this->set_prop('min_total', (float) wpinv_sanitize_amount($value));
1073 1073
 	}
1074 1074
 
1075 1075
 	/**
@@ -1078,8 +1078,8 @@  discard block
 block discarded – undo
1078 1078
 	 * @since 1.0.19
1079 1079
 	 * @param float $value minimum total.
1080 1080
 	 */
1081
-	public function set_minimum_total( $value ) {
1082
-		$this->set_min_total( $value );
1081
+	public function set_minimum_total($value) {
1082
+		$this->set_min_total($value);
1083 1083
 	}
1084 1084
 
1085 1085
 	/**
@@ -1088,8 +1088,8 @@  discard block
 block discarded – undo
1088 1088
 	 * @since 1.0.19
1089 1089
 	 * @param float $value maximum total.
1090 1090
 	 */
1091
-	public function set_max_total( $value ) {
1092
-		$this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) );
1091
+	public function set_max_total($value) {
1092
+		$this->set_prop('max_total', (float) wpinv_sanitize_amount($value));
1093 1093
 	}
1094 1094
 
1095 1095
 	/**
@@ -1098,23 +1098,23 @@  discard block
 block discarded – undo
1098 1098
 	 * @since 1.0.19
1099 1099
 	 * @param float $value maximum total.
1100 1100
 	 */
1101
-	public function set_maximum_total( $value ) {
1102
-		$this->set_max_total( $value );
1101
+	public function set_maximum_total($value) {
1102
+		$this->set_max_total($value);
1103 1103
 	}
1104 1104
 
1105 1105
 	/**
1106 1106
 	 * @deprecated
1107 1107
 	 */
1108
-	public function refresh(){}
1108
+	public function refresh() {}
1109 1109
 
1110 1110
 	/**
1111 1111
 	 * @deprecated
1112 1112
 	 *
1113 1113
 	 */
1114
-	public function update_status( $status = 'publish' ){
1114
+	public function update_status($status = 'publish') {
1115 1115
 
1116
-		if ( $this->exists() && $this->get_status() != $status ) {
1117
-			$this->set_status( $status );
1116
+		if ($this->exists() && $this->get_status() != $status) {
1117
+			$this->set_status($status);
1118 1118
 			$this->save();
1119 1119
 		}
1120 1120
 
@@ -1134,9 +1134,9 @@  discard block
 block discarded – undo
1134 1134
 	 *
1135 1135
 	 * @since 1.0.15
1136 1136
 	 */
1137
-	public function exists(){
1137
+	public function exists() {
1138 1138
 		$id = $this->get_id();
1139
-		return ! empty( $id );
1139
+		return !empty($id);
1140 1140
 	}
1141 1141
 
1142 1142
 	/**
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
 	 * @since 1.0.15
1148 1148
 	 * @return bool
1149 1149
 	 */
1150
-	public function is_type( $type ) {
1150
+	public function is_type($type) {
1151 1151
 		return $this->get_type() == $type;
1152 1152
 	}
1153 1153
 
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 	 */
1170 1170
 	public function has_limit() {
1171 1171
 		$limit = $this->get_max_uses();
1172
-		return ! empty( $limit );
1172
+		return !empty($limit);
1173 1173
 	}
1174 1174
 
1175 1175
 	/**
@@ -1190,13 +1190,13 @@  discard block
 block discarded – undo
1190 1190
 	 */
1191 1191
 	public function has_exceeded_limit() {
1192 1192
 
1193
-		if ( ! $this->has_limit() || ! $this->has_uses() ) {
1194
-			$exceeded = false ;
1193
+		if (!$this->has_limit() || !$this->has_uses()) {
1194
+			$exceeded = false;
1195 1195
 		} else {
1196
-			$exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() );
1196
+			$exceeded = !((int) $this->get_max_uses() < $this->get_uses());
1197 1197
 		}
1198 1198
 
1199
-		return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code );
1199
+		return apply_filters('wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code);
1200 1200
 	}
1201 1201
 
1202 1202
 	/**
@@ -1207,7 +1207,7 @@  discard block
 block discarded – undo
1207 1207
 	 */
1208 1208
 	public function has_expiration_date() {
1209 1209
 		$date = $this->get_expiration_date();
1210
-		return ! empty( $date );
1210
+		return !empty($date);
1211 1211
 	}
1212 1212
 
1213 1213
 	/**
@@ -1217,8 +1217,8 @@  discard block
 block discarded – undo
1217 1217
 	 * @return bool
1218 1218
 	 */
1219 1219
 	public function is_expired() {
1220
-		$expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false;
1221
-		return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code );
1220
+		$expired = $this->has_expiration_date() ? current_time('timestamp') > strtotime($this->get_expiration_date()) : false;
1221
+		return apply_filters('wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code);
1222 1222
 	}
1223 1223
 
1224 1224
 	/**
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 	 */
1230 1230
 	public function has_start_date() {
1231 1231
 		$date = $this->get_start_date();
1232
-		return ! empty( $date );
1232
+		return !empty($date);
1233 1233
 	}
1234 1234
 
1235 1235
 	/**
@@ -1239,8 +1239,8 @@  discard block
 block discarded – undo
1239 1239
 	 * @return bool
1240 1240
 	 */
1241 1241
 	public function has_started() {
1242
-		$started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() );
1243
-		return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code );
1242
+		$started = $this->has_start_date() ? true : current_time('timestamp') > strtotime($this->get_start_date());
1243
+		return apply_filters('wpinv_is_discount_started', $started, $this->ID, $this, $this->code);
1244 1244
 	}
1245 1245
 
1246 1246
 	/**
@@ -1251,7 +1251,7 @@  discard block
 block discarded – undo
1251 1251
 	 */
1252 1252
 	public function has_allowed_items() {
1253 1253
 		$allowed_items = $this->get_allowed_items();
1254
-		return empty( $allowed_items );
1254
+		return empty($allowed_items);
1255 1255
 	}
1256 1256
 
1257 1257
 	/**
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 	 */
1263 1263
 	public function has_excluded_items() {
1264 1264
 		$excluded_items = $this->get_excluded_items();
1265
-		return empty( $excluded_items );
1265
+		return empty($excluded_items);
1266 1266
 	}
1267 1267
 
1268 1268
 	/**
@@ -1272,17 +1272,17 @@  discard block
 block discarded – undo
1272 1272
 	 * @since 1.0.15
1273 1273
 	 * @return boolean
1274 1274
 	 */
1275
-	public function is_valid_for_items( $item_ids ) {
1275
+	public function is_valid_for_items($item_ids) {
1276 1276
 
1277
-		$item_ids = array_map( 'intval',  wpinv_parse_list( $item_ids ) );
1278
-		$included = array_intersect( $item_ids, $this->get_allowed_items() );
1279
-		$excluded = array_intersect( $item_ids, $this->get_excluded_items() );
1277
+		$item_ids = array_map('intval', wpinv_parse_list($item_ids));
1278
+		$included = array_intersect($item_ids, $this->get_allowed_items());
1279
+		$excluded = array_intersect($item_ids, $this->get_excluded_items());
1280 1280
 
1281
-		if ( $this->has_excluded_items() && ! empty( $excluded ) ) {
1281
+		if ($this->has_excluded_items() && !empty($excluded)) {
1282 1282
 			return false;
1283 1283
 		}
1284 1284
 
1285
-		if ( $this->has_allowed_items() && empty( $included ) ) {
1285
+		if ($this->has_allowed_items() && empty($included)) {
1286 1286
 			return false;
1287 1287
 		}
1288 1288
 		return true;
@@ -1295,8 +1295,8 @@  discard block
 block discarded – undo
1295 1295
 	 * @since 1.0.15
1296 1296
 	 * @return boolean
1297 1297
 	 */
1298
-	public function is_valid_for_amount( $amount ) {
1299
-		return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
1298
+	public function is_valid_for_amount($amount) {
1299
+		return $this->is_minimum_amount_met($amount) && $this->is_maximum_amount_met($amount);
1300 1300
 	}
1301 1301
 
1302 1302
 	/**
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	 */
1308 1308
 	public function has_minimum_amount() {
1309 1309
 		$minimum = $this->get_minimum_total();
1310
-		return ! empty( $minimum );
1310
+		return !empty($minimum);
1311 1311
 	}
1312 1312
 
1313 1313
 	/**
@@ -1317,10 +1317,10 @@  discard block
 block discarded – undo
1317 1317
 	 * @since 1.0.15
1318 1318
 	 * @return boolean
1319 1319
 	 */
1320
-	public function is_minimum_amount_met( $amount ) {
1321
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1322
-		$min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) );
1323
-		return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount );
1320
+	public function is_minimum_amount_met($amount) {
1321
+		$amount = floatval(wpinv_sanitize_amount($amount));
1322
+		$min_met = !($this->has_minimum_amount() && $amount < floatval(wpinv_sanitize_amount($this->get_minimum_total())));
1323
+		return apply_filters('wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount);
1324 1324
 	}
1325 1325
 
1326 1326
 	/**
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 	 */
1332 1332
 	public function has_maximum_amount() {
1333 1333
 		$maximum = $this->get_maximum_total();
1334
-		return ! empty( $maximum );
1334
+		return !empty($maximum);
1335 1335
 	}
1336 1336
 
1337 1337
 	/**
@@ -1341,10 +1341,10 @@  discard block
 block discarded – undo
1341 1341
 	 * @since 1.0.15
1342 1342
 	 * @return boolean
1343 1343
 	 */
1344
-	public function is_maximum_amount_met( $amount ) {
1345
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1346
-		$max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) );
1347
-		return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount );
1344
+	public function is_maximum_amount_met($amount) {
1345
+		$amount = floatval(wpinv_sanitize_amount($amount));
1346
+		$max_met = !($this->has_maximum_amount() && $amount > floatval(wpinv_sanitize_amount($this->get_maximum_total())));
1347
+		return apply_filters('wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount);
1348 1348
 	}
1349 1349
 
1350 1350
 	/**
@@ -1355,7 +1355,7 @@  discard block
 block discarded – undo
1355 1355
 	 */
1356 1356
 	public function is_recurring() {
1357 1357
 		$recurring = $this->get_is_recurring();
1358
-		return ! empty( $recurring );
1358
+		return !empty($recurring);
1359 1359
 	}
1360 1360
 
1361 1361
 	/**
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
 	 */
1367 1367
 	public function is_single_use() {
1368 1368
 		$usage = $this->get_is_single_use();
1369
-		return ! empty( $usage );
1369
+		return !empty($usage);
1370 1370
 	}
1371 1371
 
1372 1372
 	/**
@@ -1376,57 +1376,57 @@  discard block
 block discarded – undo
1376 1376
 	 * @since 1.0.15
1377 1377
 	 * @return boolean
1378 1378
 	 */
1379
-	public function is_valid_for_user( $user ) {
1379
+	public function is_valid_for_user($user) {
1380 1380
 		global $wpi_checkout_id;
1381 1381
 
1382 1382
 		// Ensure that the discount is single use.
1383
-		if ( empty( $user ) || ! $this->is_single_use() ) {
1383
+		if (empty($user) || !$this->is_single_use()) {
1384 1384
 			return true;
1385 1385
 		}
1386 1386
 
1387 1387
 		// Prepare the user id.
1388 1388
 		$user_id = 0;
1389
-        if ( is_int( $user ) ) {
1390
-            $user_id = absint( $user );
1391
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
1389
+        if (is_int($user)) {
1390
+            $user_id = absint($user);
1391
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
1392 1392
             $user_id = $user_data->ID;
1393
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
1393
+        } else if ($user_data = get_user_by('login', $user)) {
1394 1394
             $user_id = $user_data->ID;
1395
-        } else if ( absint( $user ) > 0 ) {
1396
-            $user_id = absint( $user );
1395
+        } else if (absint($user) > 0) {
1396
+            $user_id = absint($user);
1397 1397
 		}
1398 1398
 
1399 1399
 		// Ensure that we have a user.
1400
-		if ( empty( $user_id ) ) {
1400
+		if (empty($user_id)) {
1401 1401
 			return true;
1402 1402
 		}
1403 1403
 
1404 1404
 		// Get all payments with matching user id.
1405
-        $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) );
1406
-		$code     = strtolower( $this->get_code() );
1405
+        $payments = wpinv_get_invoices(array('user' => $user_id, 'limit' => false));
1406
+		$code = strtolower($this->get_code());
1407 1407
 
1408 1408
 		// For each payment...
1409
-		foreach ( $payments as $payment ) {
1409
+		foreach ($payments as $payment) {
1410 1410
 
1411 1411
 			// ... skip the current payment.
1412
-			if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
1412
+			if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
1413 1413
 				continue;
1414 1414
 			}
1415 1415
 
1416 1416
 			// And failed payments.
1417
-			if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
1417
+			if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
1418 1418
 				continue;
1419 1419
 			}
1420 1420
 
1421 1421
 			// Retrieve all the discounts for the payment.
1422
-			$discounts = $payment->get_discounts( true );
1423
-			if ( empty( $discounts ) ) {
1422
+			$discounts = $payment->get_discounts(true);
1423
+			if (empty($discounts)) {
1424 1424
 				continue;
1425 1425
 			}
1426 1426
 
1427 1427
 			// And check if the current discount is amongst them.
1428
-			$discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) );
1429
-			if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) {
1428
+			$discounts = array_map('strtolower', wpinv_parse_list($discounts));
1429
+			if (!empty($discounts) && in_array($code, $discounts)) {
1430 1430
 				return false;
1431 1431
 			}
1432 1432
 		}
@@ -1451,24 +1451,24 @@  discard block
 block discarded – undo
1451 1451
 	 * @param int $by The number of usages to increas by.
1452 1452
 	 * @return int
1453 1453
 	 */
1454
-	public function increase_usage( $by = 1 ) {
1454
+	public function increase_usage($by = 1) {
1455 1455
 
1456 1456
 		// Abort if zero.
1457
-		if ( empty( $by ) ) {
1457
+		if (empty($by)) {
1458 1458
 			return;
1459 1459
 		}
1460 1460
 
1461 1461
 		// Increase the usage.
1462
-		$this->set_uses( $this->get_uses() + (int) $by );
1462
+		$this->set_uses($this->get_uses() + (int) $by);
1463 1463
 
1464 1464
 		// Save the discount.
1465 1465
 		$this->save();
1466 1466
 
1467 1467
 		// Fire relevant hooks.
1468
-		if( (int) $by > 0 ) {
1469
-			do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code,  absint( $by ) );
1468
+		if ((int) $by > 0) {
1469
+			do_action('wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, absint($by));
1470 1470
 		} else {
1471
-			do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) );
1471
+			do_action('wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint($by));
1472 1472
 		}
1473 1473
 
1474 1474
 		// Return the number of times the discount has been used.
@@ -1492,7 +1492,7 @@  discard block
 block discarded – undo
1492 1492
 	 * @param float $amount
1493 1493
 	 * @return float
1494 1494
 	 */
1495
-	public function get_discounted_amount( $amount ) {
1495
+	public function get_discounted_amount($amount) {
1496 1496
 
1497 1497
 		// Convert amount to float.
1498 1498
 		$amount = (float) $amount;
@@ -1500,29 +1500,29 @@  discard block
 block discarded – undo
1500 1500
 		// Get discount amount.
1501 1501
 		$discount_amount = $this->get_amount();
1502 1502
 
1503
-		if ( empty( $discount_amount ) ) {
1503
+		if (empty($discount_amount)) {
1504 1504
 			return 0;
1505 1505
 		}
1506 1506
 
1507 1507
 		// Format the amount.
1508
-		$discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) );
1508
+		$discount_amount = floatval(wpinv_sanitize_amount($discount_amount));
1509 1509
 		
1510 1510
 		// If this is a percentage discount.
1511
-		if ( $this->is_type( 'percent' ) ) {
1512
-            $discount_amount = $amount * ( $discount_amount / 100 );
1511
+		if ($this->is_type('percent')) {
1512
+            $discount_amount = $amount * ($discount_amount / 100);
1513 1513
 		}
1514 1514
 
1515 1515
 		// Discount can not be less than zero...
1516
-		if ( $discount_amount < 0 ) {
1516
+		if ($discount_amount < 0) {
1517 1517
 			$discount_amount = 0;
1518 1518
 		}
1519 1519
 
1520 1520
 		// ... or more than the amount.
1521
-		if ( $discount_amount > $amount ) {
1521
+		if ($discount_amount > $amount) {
1522 1522
 			$discount_amount = $amount;
1523 1523
 		}
1524 1524
 
1525
-		return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this );
1525
+		return apply_filters('wpinv_discount_total_discount_amount', $discount_amount, $amount, $this);
1526 1526
 	}
1527 1527
 
1528 1528
 }
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
Spacing   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -78,26 +78,26 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80 80
 	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
81
+	public function __construct($item = 0) {
82
+		parent::__construct($item);
83 83
 
84
-		if ( is_numeric( $item ) && $item > 0 ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
84
+		if (is_numeric($item) && $item > 0) {
85
+			$this->set_id($item);
86
+		} elseif ($item instanceof self) {
87
+			$this->set_id($item->get_id());
88
+		} elseif (!empty($item->ID)) {
89
+			$this->set_id($item->ID);
90 90
 		} else {
91
-			$this->set_object_read( true );
91
+			$this->set_object_read(true);
92 92
 		}
93 93
 
94 94
         // Load the datastore.
95
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
95
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
96 96
 
97
-		if ( $this->get_id() > 0 ) {
98
-            $this->post = get_post( $this->get_id() );
97
+		if ($this->get_id() > 0) {
98
+            $this->post = get_post($this->get_id());
99 99
             $this->ID   = $this->get_id();
100
-			$this->data_store->read( $this );
100
+			$this->data_store->read($this);
101 101
         }
102 102
 
103 103
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @param  string $context View or edit context.
125 125
 	 * @return int
126 126
 	 */
127
-	public function get_parent_id( $context = 'view' ) {
128
-		return (int) $this->get_prop( 'parent_id', $context );
127
+	public function get_parent_id($context = 'view') {
128
+		return (int) $this->get_prop('parent_id', $context);
129 129
     }
130 130
 
131 131
     /**
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @param  string $context View or edit context.
136 136
 	 * @return string
137 137
 	 */
138
-	public function get_status( $context = 'view' ) {
139
-		return $this->get_prop( 'status', $context );
138
+	public function get_status($context = 'view') {
139
+		return $this->get_prop('status', $context);
140 140
     }
141 141
 
142 142
     /**
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 	 * @param  string $context View or edit context.
147 147
 	 * @return string
148 148
 	 */
149
-	public function get_version( $context = 'view' ) {
150
-		return $this->get_prop( 'version', $context );
149
+	public function get_version($context = 'view') {
150
+		return $this->get_prop('version', $context);
151 151
     }
152 152
 
153 153
     /**
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @param  string $context View or edit context.
158 158
 	 * @return string
159 159
 	 */
160
-	public function get_date_created( $context = 'view' ) {
161
-		return $this->get_prop( 'date_created', $context );
160
+	public function get_date_created($context = 'view') {
161
+		return $this->get_prop('date_created', $context);
162 162
     }
163 163
 
164 164
     /**
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 	 * @param  string $context View or edit context.
169 169
 	 * @return string
170 170
 	 */
171
-	public function get_date_created_gmt( $context = 'view' ) {
172
-        $date = $this->get_date_created( $context );
171
+	public function get_date_created_gmt($context = 'view') {
172
+        $date = $this->get_date_created($context);
173 173
 
174
-        if ( $date ) {
175
-            $date = get_gmt_from_date( $date );
174
+        if ($date) {
175
+            $date = get_gmt_from_date($date);
176 176
         }
177 177
 		return $date;
178 178
     }
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param  string $context View or edit context.
185 185
 	 * @return string
186 186
 	 */
187
-	public function get_date_modified( $context = 'view' ) {
188
-		return $this->get_prop( 'date_modified', $context );
187
+	public function get_date_modified($context = 'view') {
188
+		return $this->get_prop('date_modified', $context);
189 189
     }
190 190
 
191 191
     /**
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
 	 * @param  string $context View or edit context.
196 196
 	 * @return string
197 197
 	 */
198
-	public function get_date_modified_gmt( $context = 'view' ) {
199
-        $date = $this->get_date_modified( $context );
198
+	public function get_date_modified_gmt($context = 'view') {
199
+        $date = $this->get_date_modified($context);
200 200
 
201
-        if ( $date ) {
202
-            $date = get_gmt_from_date( $date );
201
+        if ($date) {
202
+            $date = get_gmt_from_date($date);
203 203
         }
204 204
 		return $date;
205 205
     }
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	 * @param  string $context View or edit context.
212 212
 	 * @return string
213 213
 	 */
214
-	public function get_name( $context = 'view' ) {
215
-		return $this->get_prop( 'name', $context );
214
+	public function get_name($context = 'view') {
215
+		return $this->get_prop('name', $context);
216 216
     }
217 217
 
218 218
     /**
@@ -222,8 +222,8 @@  discard block
 block discarded – undo
222 222
 	 * @param  string $context View or edit context.
223 223
 	 * @return string
224 224
 	 */
225
-	public function get_title( $context = 'view' ) {
226
-		return $this->get_name( $context );
225
+	public function get_title($context = 'view') {
226
+		return $this->get_name($context);
227 227
     }
228 228
 
229 229
     /**
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 	 * @param  string $context View or edit context.
234 234
 	 * @return string
235 235
 	 */
236
-	public function get_description( $context = 'view' ) {
237
-		return $this->get_prop( 'description', $context );
236
+	public function get_description($context = 'view') {
237
+		return $this->get_prop('description', $context);
238 238
     }
239 239
 
240 240
     /**
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @param  string $context View or edit context.
245 245
 	 * @return string
246 246
 	 */
247
-	public function get_excerpt( $context = 'view' ) {
248
-		return $this->get_description( $context );
247
+	public function get_excerpt($context = 'view') {
248
+		return $this->get_description($context);
249 249
     }
250 250
 
251 251
     /**
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 	 * @param  string $context View or edit context.
256 256
 	 * @return string
257 257
 	 */
258
-	public function get_summary( $context = 'view' ) {
259
-		return $this->get_description( $context );
258
+	public function get_summary($context = 'view') {
259
+		return $this->get_description($context);
260 260
     }
261 261
 
262 262
     /**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @param  string $context View or edit context.
267 267
 	 * @return string
268 268
 	 */
269
-	public function get_author( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'author', $context );
269
+	public function get_author($context = 'view') {
270
+		return (int) $this->get_prop('author', $context);
271 271
     }
272 272
 
273 273
     /**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * @param  string $context View or edit context.
278 278
 	 * @return float
279 279
 	 */
280
-	public function get_price( $context = 'view' ) {
281
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
280
+	public function get_price($context = 'view') {
281
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
282 282
 	}
283 283
 	
284 284
 	/**
@@ -288,14 +288,14 @@  discard block
 block discarded – undo
288 288
 	 * @param  string $context View or edit context.
289 289
 	 * @return float
290 290
 	 */
291
-	public function get_initial_price( $context = 'view' ) {
291
+	public function get_initial_price($context = 'view') {
292 292
 
293
-		$price = $this->get_price( $context );
293
+		$price = $this->get_price($context);
294 294
 
295
-		if ( $this->has_free_trial() ) {
296
-			$price = wpinv_sanitize_amount( 0 );
295
+		if ($this->has_free_trial()) {
296
+			$price = wpinv_sanitize_amount(0);
297 297
 		}
298
-        return apply_filters( 'wpinv_get_initial_item_price', $price, $this );
298
+        return apply_filters('wpinv_get_initial_item_price', $price, $this);
299 299
     }
300 300
 
301 301
     /**
@@ -306,9 +306,9 @@  discard block
 block discarded – undo
306 306
 	 * @return string
307 307
 	 */
308 308
     public function get_the_price() {
309
-        $item_price = wpinv_price( $this->get_price() );
309
+        $item_price = wpinv_price($this->get_price());
310 310
 
311
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
311
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
312 312
     }
313 313
 
314 314
     /**
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param  string $context View or edit context.
319 319
 	 * @return string
320 320
 	 */
321
-	public function get_vat_rule( $context = 'view' ) {
322
-        return $this->get_prop( 'vat_rule', $context );
321
+	public function get_vat_rule($context = 'view') {
322
+        return $this->get_prop('vat_rule', $context);
323 323
     }
324 324
 
325 325
     /**
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 	 * @param  string $context View or edit context.
330 330
 	 * @return string
331 331
 	 */
332
-	public function get_vat_class( $context = 'view' ) {
333
-        return $this->get_prop( 'vat_class', $context );
332
+	public function get_vat_class($context = 'view') {
333
+        return $this->get_prop('vat_class', $context);
334 334
     }
335 335
 
336 336
     /**
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 	 * @param  string $context View or edit context.
341 341
 	 * @return string
342 342
 	 */
343
-	public function get_type( $context = 'view' ) {
344
-        return $this->get_prop( 'type', $context );
343
+	public function get_type($context = 'view') {
344
+        return $this->get_prop('type', $context);
345 345
     }
346 346
 
347 347
     /**
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
 	 * @param  string $context View or edit context.
352 352
 	 * @return string
353 353
 	 */
354
-	public function get_custom_id( $context = 'view' ) {
355
-        return $this->get_prop( 'custom_id', $context );
354
+	public function get_custom_id($context = 'view') {
355
+        return $this->get_prop('custom_id', $context);
356 356
     }
357 357
 
358 358
     /**
@@ -362,8 +362,8 @@  discard block
 block discarded – undo
362 362
 	 * @param  string $context View or edit context.
363 363
 	 * @return string
364 364
 	 */
365
-	public function get_custom_name( $context = 'view' ) {
366
-        return $this->get_prop( 'custom_name', $context );
365
+	public function get_custom_name($context = 'view') {
366
+        return $this->get_prop('custom_name', $context);
367 367
     }
368 368
 
369 369
     /**
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 	 * @param  string $context View or edit context.
374 374
 	 * @return string
375 375
 	 */
376
-	public function get_custom_singular_name( $context = 'view' ) {
377
-        return $this->get_prop( 'custom_singular_name', $context );
376
+	public function get_custom_singular_name($context = 'view') {
377
+        return $this->get_prop('custom_singular_name', $context);
378 378
     }
379 379
 
380 380
     /**
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 	 * @param  string $context View or edit context.
385 385
 	 * @return int
386 386
 	 */
387
-	public function get_is_editable( $context = 'view' ) {
388
-        return (int) $this->get_prop( 'is_editable', $context );
387
+	public function get_is_editable($context = 'view') {
388
+        return (int) $this->get_prop('is_editable', $context);
389 389
     }
390 390
 
391 391
     /**
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
 	 * @param  string $context View or edit context.
396 396
 	 * @return int
397 397
 	 */
398
-	public function get_editable( $context = 'view' ) {
399
-		return $this->get_is_editable( $context );
398
+	public function get_editable($context = 'view') {
399
+		return $this->get_is_editable($context);
400 400
     }
401 401
 
402 402
     /**
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
 	 * @param  string $context View or edit context.
407 407
 	 * @return int
408 408
 	 */
409
-	public function get_is_dynamic_pricing( $context = 'view' ) {
410
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
409
+	public function get_is_dynamic_pricing($context = 'view') {
410
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
411 411
     }
412 412
 
413 413
     /**
@@ -417,8 +417,8 @@  discard block
 block discarded – undo
417 417
 	 * @param  string $context View or edit context.
418 418
 	 * @return float
419 419
 	 */
420
-	public function get_minimum_price( $context = 'view' ) {
421
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
420
+	public function get_minimum_price($context = 'view') {
421
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
422 422
     }
423 423
 
424 424
     /**
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 	 * @param  string $context View or edit context.
429 429
 	 * @return int
430 430
 	 */
431
-	public function get_is_recurring( $context = 'view' ) {
432
-        return (int) $this->get_prop( 'is_recurring', $context );
431
+	public function get_is_recurring($context = 'view') {
432
+        return (int) $this->get_prop('is_recurring', $context);
433 433
 	}
434 434
 	
435 435
 	/**
@@ -439,9 +439,9 @@  discard block
 block discarded – undo
439 439
 	 * @param  string $context View or edit context.
440 440
 	 * @return float
441 441
 	 */
442
-	public function get_recurring_price( $context = 'view' ) {
443
-		$price = $this->get_price( $context );
444
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
442
+	public function get_recurring_price($context = 'view') {
443
+		$price = $this->get_price($context);
444
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
445 445
 	}
446 446
 
447 447
 	/**
@@ -462,15 +462,15 @@  discard block
 block discarded – undo
462 462
 		$period   = $this->get_recurring_period();
463 463
 		$interval = $this->get_recurring_interval();
464 464
 
465
-		if ( $this->has_free_trial() ) {
465
+		if ($this->has_free_trial()) {
466 466
 			$period   = $this->get_trial_period();
467 467
 			$interval = $this->get_trial_interval();
468 468
 		}
469 469
 
470
-		$period       = $periods[ $period ];
471
-		$interval     = empty( $interval ) ? 1 : $interval;
472
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
473
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
470
+		$period       = $periods[$period];
471
+		$interval     = empty($interval) ? 1 : $interval;
472
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
473
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
474 474
     }
475 475
 
476 476
     /**
@@ -480,14 +480,14 @@  discard block
 block discarded – undo
480 480
 	 * @param  bool $full Return abbreviation or in full.
481 481
 	 * @return string
482 482
 	 */
483
-	public function get_recurring_period( $full = false ) {
484
-        $period = $this->get_prop( 'recurring_period', 'view' );
483
+	public function get_recurring_period($full = false) {
484
+        $period = $this->get_prop('recurring_period', 'view');
485 485
 
486
-        if ( $full && ! is_bool( $full ) ) {
486
+        if ($full && !is_bool($full)) {
487 487
             $full = false;
488 488
         }
489 489
 
490
-        return getpaid_sanitize_recurring_period( $period, $full );
490
+        return getpaid_sanitize_recurring_period($period, $full);
491 491
     }
492 492
 
493 493
     /**
@@ -497,10 +497,10 @@  discard block
 block discarded – undo
497 497
 	 * @param  string $context View or edit context.
498 498
 	 * @return int
499 499
 	 */
500
-	public function get_recurring_interval( $context = 'view' ) {
501
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
500
+	public function get_recurring_interval($context = 'view') {
501
+		$interval = absint($this->get_prop('recurring_interval', $context));
502 502
 
503
-		if ( $interval < 1 ) {
503
+		if ($interval < 1) {
504 504
 			$interval = 1;
505 505
 		}
506 506
 
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
 	 * @param  string $context View or edit context.
515 515
 	 * @return int
516 516
 	 */
517
-	public function get_recurring_limit( $context = 'view' ) {
518
-        return (int) $this->get_prop( 'recurring_limit', $context );
517
+	public function get_recurring_limit($context = 'view') {
518
+        return (int) $this->get_prop('recurring_limit', $context);
519 519
     }
520 520
 
521 521
     /**
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
 	 * @param  string $context View or edit context.
526 526
 	 * @return int
527 527
 	 */
528
-	public function get_is_free_trial( $context = 'view' ) {
529
-        return (int) $this->get_prop( 'is_free_trial', $context );
528
+	public function get_is_free_trial($context = 'view') {
529
+        return (int) $this->get_prop('is_free_trial', $context);
530 530
     }
531 531
 
532 532
     /**
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
 	 * @param  string $context View or edit context.
537 537
 	 * @return int
538 538
 	 */
539
-	public function get_free_trial( $context = 'view' ) {
540
-        return $this->get_is_free_trial( $context );
539
+	public function get_free_trial($context = 'view') {
540
+        return $this->get_is_free_trial($context);
541 541
     }
542 542
 
543 543
     /**
@@ -547,14 +547,14 @@  discard block
 block discarded – undo
547 547
 	 * @param  bool $full Return abbreviation or in full.
548 548
 	 * @return string
549 549
 	 */
550
-	public function get_trial_period( $full = false ) {
551
-        $period = $this->get_prop( 'trial_period', 'view' );
550
+	public function get_trial_period($full = false) {
551
+        $period = $this->get_prop('trial_period', 'view');
552 552
 
553
-        if ( $full && ! is_bool( $full ) ) {
553
+        if ($full && !is_bool($full)) {
554 554
             $full = false;
555 555
         }
556 556
 
557
-        return getpaid_sanitize_recurring_period( $period, $full );
557
+        return getpaid_sanitize_recurring_period($period, $full);
558 558
     }
559 559
 
560 560
     /**
@@ -564,26 +564,26 @@  discard block
 block discarded – undo
564 564
 	 * @param  string $context View or edit context.
565 565
 	 * @return int
566 566
 	 */
567
-	public function get_trial_interval( $context = 'view' ) {
568
-        return (int) $this->get_prop( 'trial_interval', $context );
567
+	public function get_trial_interval($context = 'view') {
568
+        return (int) $this->get_prop('trial_interval', $context);
569 569
     }
570 570
 
571 571
     /**
572 572
      * Margic method for retrieving a property.
573 573
      */
574
-    public function __get( $key ) {
574
+    public function __get($key) {
575 575
 
576 576
         // Check if we have a helper method for that.
577
-        if ( method_exists( $this, 'get_' . $key ) ) {
578
-            return call_user_func( array( $this, 'get_' . $key ) );
577
+        if (method_exists($this, 'get_' . $key)) {
578
+            return call_user_func(array($this, 'get_' . $key));
579 579
         }
580 580
 
581 581
         // Check if the key is in the associated $post object.
582
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
582
+        if (!empty($this->post) && isset($this->post->$key)) {
583 583
             return $this->post->$key;
584 584
         }
585 585
 
586
-        return $this->get_prop( $key );
586
+        return $this->get_prop($key);
587 587
 
588 588
     }
589 589
 
@@ -602,11 +602,11 @@  discard block
 block discarded – undo
602 602
 	 *
603 603
 	 * @since 1.0.19
604 604
 	 */
605
-	public function set_parent_id( $value ) {
606
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
605
+	public function set_parent_id($value) {
606
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
607 607
 			return;
608 608
 		}
609
-		$this->set_prop( 'parent_id', absint( $value ) );
609
+		$this->set_prop('parent_id', absint($value));
610 610
 	}
611 611
 
612 612
     /**
@@ -616,10 +616,10 @@  discard block
 block discarded – undo
616 616
 	 * @param  string $status New status.
617 617
 	 * @return array details of change.
618 618
 	 */
619
-	public function set_status( $status ) {
619
+	public function set_status($status) {
620 620
         $old_status = $this->get_status();
621 621
 
622
-        $this->set_prop( 'status', $status );
622
+        $this->set_prop('status', $status);
623 623
 
624 624
 		return array(
625 625
 			'from' => $old_status,
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
 	 *
633 633
 	 * @since 1.0.19
634 634
 	 */
635
-	public function set_version( $value ) {
636
-		$this->set_prop( 'version', $value );
635
+	public function set_version($value) {
636
+		$this->set_prop('version', $value);
637 637
     }
638 638
 
639 639
     /**
@@ -643,11 +643,11 @@  discard block
 block discarded – undo
643 643
 	 * @param string $value Value to set.
644 644
      * @return bool Whether or not the date was set.
645 645
 	 */
646
-	public function set_date_created( $value ) {
647
-        $date = strtotime( $value );
646
+	public function set_date_created($value) {
647
+        $date = strtotime($value);
648 648
 
649
-        if ( $date ) {
650
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
649
+        if ($date) {
650
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
651 651
             return true;
652 652
         }
653 653
 
@@ -662,11 +662,11 @@  discard block
 block discarded – undo
662 662
 	 * @param string $value Value to set.
663 663
      * @return bool Whether or not the date was set.
664 664
 	 */
665
-	public function set_date_modified( $value ) {
666
-        $date = strtotime( $value );
665
+	public function set_date_modified($value) {
666
+        $date = strtotime($value);
667 667
 
668
-        if ( $date ) {
669
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
668
+        if ($date) {
669
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
670 670
             return true;
671 671
         }
672 672
 
@@ -680,9 +680,9 @@  discard block
 block discarded – undo
680 680
 	 * @since 1.0.19
681 681
 	 * @param  string $value New name.
682 682
 	 */
683
-	public function set_name( $value ) {
684
-        $name = sanitize_text_field( $value );
685
-		$this->set_prop( 'name', $name );
683
+	public function set_name($value) {
684
+        $name = sanitize_text_field($value);
685
+		$this->set_prop('name', $name);
686 686
     }
687 687
 
688 688
     /**
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 	 * @since 1.0.19
692 692
 	 * @param  string $value New name.
693 693
 	 */
694
-	public function set_title( $value ) {
695
-		$this->set_name( $value );
694
+	public function set_title($value) {
695
+		$this->set_name($value);
696 696
     }
697 697
 
698 698
     /**
@@ -701,9 +701,9 @@  discard block
 block discarded – undo
701 701
 	 * @since 1.0.19
702 702
 	 * @param  string $value New description.
703 703
 	 */
704
-	public function set_description( $value ) {
705
-        $description = wp_kses_post( $value );
706
-		return $this->set_prop( 'description', $description );
704
+	public function set_description($value) {
705
+        $description = wp_kses_post($value);
706
+		return $this->set_prop('description', $description);
707 707
     }
708 708
 
709 709
     /**
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
 	 * @since 1.0.19
713 713
 	 * @param  string $value New description.
714 714
 	 */
715
-	public function set_excerpt( $value ) {
716
-		$this->set_description( $value );
715
+	public function set_excerpt($value) {
716
+		$this->set_description($value);
717 717
     }
718 718
 
719 719
     /**
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
 	 * @since 1.0.19
723 723
 	 * @param  string $value New description.
724 724
 	 */
725
-	public function set_summary( $value ) {
726
-		$this->set_description( $value );
725
+	public function set_summary($value) {
726
+		$this->set_description($value);
727 727
     }
728 728
 
729 729
     /**
@@ -732,8 +732,8 @@  discard block
 block discarded – undo
732 732
 	 * @since 1.0.19
733 733
 	 * @param  int $value New author.
734 734
 	 */
735
-	public function set_author( $value ) {
736
-		$this->set_prop( 'author', (int) $value );
735
+	public function set_author($value) {
736
+		$this->set_prop('author', (int) $value);
737 737
     }
738 738
 
739 739
     /**
@@ -742,8 +742,8 @@  discard block
 block discarded – undo
742 742
 	 * @since 1.0.19
743 743
 	 * @param  float $value New price.
744 744
 	 */
745
-	public function set_price( $value ) {
746
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
745
+	public function set_price($value) {
746
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
747 747
     }
748 748
 
749 749
     /**
@@ -752,8 +752,8 @@  discard block
 block discarded – undo
752 752
 	 * @since 1.0.19
753 753
 	 * @param  string $value new rule.
754 754
 	 */
755
-	public function set_vat_rule( $value ) {
756
-        $this->set_prop( 'vat_rule', $value );
755
+	public function set_vat_rule($value) {
756
+        $this->set_prop('vat_rule', $value);
757 757
     }
758 758
 
759 759
     /**
@@ -762,8 +762,8 @@  discard block
 block discarded – undo
762 762
 	 * @since 1.0.19
763 763
 	 * @param  string $value new class.
764 764
 	 */
765
-	public function set_vat_class( $value ) {
766
-        $this->set_prop( 'vat_class', $value );
765
+	public function set_vat_class($value) {
766
+        $this->set_prop('vat_class', $value);
767 767
     }
768 768
 
769 769
     /**
@@ -773,13 +773,13 @@  discard block
 block discarded – undo
773 773
 	 * @param  string $value new item type.
774 774
 	 * @return string
775 775
 	 */
776
-	public function set_type( $value ) {
776
+	public function set_type($value) {
777 777
 
778
-        if ( empty( $value ) ) {
778
+        if (empty($value)) {
779 779
             $value = 'custom';
780 780
         }
781 781
 
782
-        $this->set_prop( 'type', $value );
782
+        $this->set_prop('type', $value);
783 783
     }
784 784
 
785 785
     /**
@@ -788,8 +788,8 @@  discard block
 block discarded – undo
788 788
 	 * @since 1.0.19
789 789
 	 * @param  string $value new custom id.
790 790
 	 */
791
-	public function set_custom_id( $value ) {
792
-        $this->set_prop( 'custom_id', $value );
791
+	public function set_custom_id($value) {
792
+        $this->set_prop('custom_id', $value);
793 793
     }
794 794
 
795 795
     /**
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
 	 * @since 1.0.19
799 799
 	 * @param  string $value new custom name.
800 800
 	 */
801
-	public function set_custom_name( $value ) {
802
-        $this->set_prop( 'custom_name', $value );
801
+	public function set_custom_name($value) {
802
+        $this->set_prop('custom_name', $value);
803 803
     }
804 804
 
805 805
     /**
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
 	 * @since 1.0.19
809 809
 	 * @param  string $value new custom singular name.
810 810
 	 */
811
-	public function set_custom_singular_name( $value ) {
812
-        $this->set_prop( 'custom_singular_name', $value );
811
+	public function set_custom_singular_name($value) {
812
+        $this->set_prop('custom_singular_name', $value);
813 813
     }
814 814
 
815 815
     /**
@@ -818,9 +818,9 @@  discard block
 block discarded – undo
818 818
 	 * @since 1.0.19
819 819
 	 * @param  int|bool $value whether or not the item is editable.
820 820
 	 */
821
-	public function set_is_editable( $value ) {
822
-		if ( is_numeric( $value ) ) {
823
-			$this->set_prop( 'is_editable', (int) $value );
821
+	public function set_is_editable($value) {
822
+		if (is_numeric($value)) {
823
+			$this->set_prop('is_editable', (int) $value);
824 824
 		}
825 825
     }
826 826
 
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
 	 * @since 1.0.19
831 831
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
832 832
 	 */
833
-	public function set_is_dynamic_pricing( $value ) {
834
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
833
+	public function set_is_dynamic_pricing($value) {
834
+        $this->set_prop('is_dynamic_pricing', (int) $value);
835 835
     }
836 836
 
837 837
     /**
@@ -840,8 +840,8 @@  discard block
 block discarded – undo
840 840
 	 * @since 1.0.19
841 841
 	 * @param  float $value minimum price.
842 842
 	 */
843
-	public function set_minimum_price( $value ) {
844
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
843
+	public function set_minimum_price($value) {
844
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
845 845
     }
846 846
 
847 847
     /**
@@ -850,8 +850,8 @@  discard block
 block discarded – undo
850 850
 	 * @since 1.0.19
851 851
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
852 852
 	 */
853
-	public function set_is_recurring( $value ) {
854
-        $this->set_prop( 'is_recurring', (int) $value );
853
+	public function set_is_recurring($value) {
854
+        $this->set_prop('is_recurring', (int) $value);
855 855
     }
856 856
 
857 857
     /**
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
 	 * @since 1.0.19
861 861
 	 * @param  string $value new period.
862 862
 	 */
863
-	public function set_recurring_period( $value ) {
864
-        $this->set_prop( 'recurring_period', $value );
863
+	public function set_recurring_period($value) {
864
+        $this->set_prop('recurring_period', $value);
865 865
     }
866 866
 
867 867
     /**
@@ -870,8 +870,8 @@  discard block
 block discarded – undo
870 870
 	 * @since 1.0.19
871 871
 	 * @param  int $value recurring interval.
872 872
 	 */
873
-	public function set_recurring_interval( $value ) {
874
-        return $this->set_prop( 'recurring_interval', (int) $value );
873
+	public function set_recurring_interval($value) {
874
+        return $this->set_prop('recurring_interval', (int) $value);
875 875
     }
876 876
 
877 877
     /**
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
 	 * @param  int $value The recurring limit.
881 881
 	 * @return int
882 882
 	 */
883
-	public function set_recurring_limit( $value ) {
884
-        $this->set_prop( 'recurring_limit', (int) $value );
883
+	public function set_recurring_limit($value) {
884
+        $this->set_prop('recurring_limit', (int) $value);
885 885
     }
886 886
 
887 887
     /**
@@ -890,8 +890,8 @@  discard block
 block discarded – undo
890 890
 	 * @since 1.0.19
891 891
 	 * @param  int|bool $value whether or not it has a free trial.
892 892
 	 */
893
-	public function set_is_free_trial( $value ) {
894
-        $this->set_prop( 'is_free_trial', (int) $value );
893
+	public function set_is_free_trial($value) {
894
+        $this->set_prop('is_free_trial', (int) $value);
895 895
     }
896 896
 
897 897
     /**
@@ -900,8 +900,8 @@  discard block
 block discarded – undo
900 900
 	 * @since 1.0.19
901 901
 	 * @param  string $value trial period.
902 902
 	 */
903
-	public function set_trial_period( $value ) {
904
-        $this->set_prop( 'trial_period', $value );
903
+	public function set_trial_period($value) {
904
+        $this->set_prop('trial_period', $value);
905 905
     }
906 906
 
907 907
     /**
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
 	 * @since 1.0.19
911 911
 	 * @param  int $value trial interval.
912 912
 	 */
913
-	public function set_trial_interval( $value ) {
914
-        $this->set_prop( 'trial_interval', $value );
913
+	public function set_trial_interval($value) {
914
+        $this->set_prop('trial_interval', $value);
915 915
     }
916 916
 
917 917
     /**
@@ -920,11 +920,11 @@  discard block
 block discarded – undo
920 920
      * @deprecated
921 921
 	 * @return int item id
922 922
      */
923
-    public function create( $data = array() ) {
923
+    public function create($data = array()) {
924 924
 
925 925
 		// Set the properties.
926
-		if ( is_array( $data ) ) {
927
-			$this->set_props( $data );
926
+		if (is_array($data)) {
927
+			$this->set_props($data);
928 928
 		}
929 929
 
930 930
 		// Save the item.
@@ -938,8 +938,8 @@  discard block
 block discarded – undo
938 938
      * @deprecated
939 939
 	 * @return int item id
940 940
      */
941
-    public function update( $data = array() ) {
942
-        return $this->create( $data );
941
+    public function update($data = array()) {
942
+        return $this->create($data);
943 943
     }
944 944
 
945 945
     /*
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 	 */
980 980
     public function has_free_trial() {
981 981
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
982
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
982
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
983 983
     }
984 984
 
985 985
     /**
@@ -989,8 +989,8 @@  discard block
 block discarded – undo
989 989
 	 * @return bool
990 990
 	 */
991 991
     public function is_free() {
992
-        $is_free   = $this->get_price() == 0;
993
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
992
+        $is_free = $this->get_price() == 0;
993
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
994 994
     }
995 995
 
996 996
     /**
@@ -999,9 +999,9 @@  discard block
 block discarded – undo
999 999
 	 * @param array|string $status Status to check.
1000 1000
 	 * @return bool
1001 1001
 	 */
1002
-	public function has_status( $status ) {
1003
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1004
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1002
+	public function has_status($status) {
1003
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1004
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1005 1005
     }
1006 1006
 
1007 1007
     /**
@@ -1010,9 +1010,9 @@  discard block
 block discarded – undo
1010 1010
 	 * @param array|string $type Type to check.
1011 1011
 	 * @return bool
1012 1012
 	 */
1013
-	public function is_type( $type ) {
1014
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1015
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1013
+	public function is_type($type) {
1014
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1015
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1016 1016
 	}
1017 1017
 
1018 1018
     /**
@@ -1023,53 +1023,53 @@  discard block
 block discarded – undo
1023 1023
 	 */
1024 1024
     public function is_editable() {
1025 1025
         $is_editable = $this->get_is_editable();
1026
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1026
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1027 1027
 	}
1028 1028
 
1029 1029
 	/**
1030 1030
 	 * Returns an array of cart fees.
1031 1031
 	 */
1032
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1032
+	public function get_fees($type = 'fee', $item_id = 0) {
1033 1033
         global $wpi_session;
1034 1034
         
1035
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
1035
+        $fees = $wpi_session->get('wpi_cart_fees');
1036 1036
 
1037
-        if ( ! wpinv_get_cart_contents() ) {
1037
+        if (!wpinv_get_cart_contents()) {
1038 1038
             // We can only get item type fees when the cart is empty
1039 1039
             $type = 'custom';
1040 1040
         }
1041 1041
 
1042
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
1043
-            foreach( $fees as $key => $fee ) {
1044
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1045
-                    unset( $fees[ $key ] );
1042
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
1043
+            foreach ($fees as $key => $fee) {
1044
+                if (!empty($fee['type']) && $type != $fee['type']) {
1045
+                    unset($fees[$key]);
1046 1046
                 }
1047 1047
             }
1048 1048
         }
1049 1049
 
1050
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
1050
+        if (!empty($fees) && !empty($item_id)) {
1051 1051
             // Remove fees that don't belong to the specified Item
1052
-            foreach ( $fees as $key => $fee ) {
1053
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
1054
-                    unset( $fees[ $key ] );
1052
+            foreach ($fees as $key => $fee) {
1053
+                if ((int) $item_id !== (int) $fee['custom_id']) {
1054
+                    unset($fees[$key]);
1055 1055
                 }
1056 1056
             }
1057 1057
         }
1058 1058
 
1059
-        if ( ! empty( $fees ) ) {
1059
+        if (!empty($fees)) {
1060 1060
             // Remove fees that belong to a specific item but are not in the cart
1061
-            foreach( $fees as $key => $fee ) {
1062
-                if( empty( $fee['custom_id'] ) ) {
1061
+            foreach ($fees as $key => $fee) {
1062
+                if (empty($fee['custom_id'])) {
1063 1063
                     continue;
1064 1064
                 }
1065 1065
 
1066
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
1067
-                    unset( $fees[ $key ] );
1066
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
1067
+                    unset($fees[$key]);
1068 1068
                 }
1069 1069
             }
1070 1070
         }
1071 1071
 
1072
-        return ! empty( $fees ) ? $fees : array();
1072
+        return !empty($fees) ? $fees : array();
1073 1073
     }
1074 1074
 
1075 1075
     /**
@@ -1081,11 +1081,11 @@  discard block
 block discarded – undo
1081 1081
     public function can_purchase() {
1082 1082
         $can_purchase = null !== $this->get_id();
1083 1083
 
1084
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1084
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1085 1085
             $can_purchase = false;
1086 1086
         }
1087 1087
 
1088
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1088
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1089 1089
     }
1090 1090
 
1091 1091
     /**
@@ -1095,6 +1095,6 @@  discard block
 block discarded – undo
1095 1095
 	 * @return bool
1096 1096
 	 */
1097 1097
     public function supports_dynamic_pricing() {
1098
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1098
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1099 1099
     }
1100 1100
 }
Please login to merge, or discard this patch.
Indentation   +604 added lines, -604 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,33 +74,33 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( is_numeric( $item ) && $item > 0 ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} else {
91
-			$this->set_object_read( true );
92
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( is_numeric( $item ) && $item > 0 ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } else {
91
+            $this->set_object_read( true );
92
+        }
93 93
 
94 94
         // Load the datastore.
95
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
95
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
96 96
 
97
-		if ( $this->get_id() > 0 ) {
97
+        if ( $this->get_id() > 0 ) {
98 98
             $this->post = get_post( $this->get_id() );
99 99
             $this->ID   = $this->get_id();
100
-			$this->data_store->read( $this );
100
+            $this->data_store->read( $this );
101 101
         }
102 102
 
103
-	}
103
+    }
104 104
 
105 105
     /*
106 106
 	|--------------------------------------------------------------------------
@@ -118,194 +118,194 @@  discard block
 block discarded – undo
118 118
     */
119 119
 
120 120
     /**
121
-	 * Get parent item ID.
122
-	 *
123
-	 * @since 1.0.19
124
-	 * @param  string $context View or edit context.
125
-	 * @return int
126
-	 */
127
-	public function get_parent_id( $context = 'view' ) {
128
-		return (int) $this->get_prop( 'parent_id', $context );
121
+     * Get parent item ID.
122
+     *
123
+     * @since 1.0.19
124
+     * @param  string $context View or edit context.
125
+     * @return int
126
+     */
127
+    public function get_parent_id( $context = 'view' ) {
128
+        return (int) $this->get_prop( 'parent_id', $context );
129 129
     }
130 130
 
131 131
     /**
132
-	 * Get item status.
133
-	 *
134
-	 * @since 1.0.19
135
-	 * @param  string $context View or edit context.
136
-	 * @return string
137
-	 */
138
-	public function get_status( $context = 'view' ) {
139
-		return $this->get_prop( 'status', $context );
132
+     * Get item status.
133
+     *
134
+     * @since 1.0.19
135
+     * @param  string $context View or edit context.
136
+     * @return string
137
+     */
138
+    public function get_status( $context = 'view' ) {
139
+        return $this->get_prop( 'status', $context );
140 140
     }
141 141
 
142 142
     /**
143
-	 * Get plugin version when the item was created.
144
-	 *
145
-	 * @since 1.0.19
146
-	 * @param  string $context View or edit context.
147
-	 * @return string
148
-	 */
149
-	public function get_version( $context = 'view' ) {
150
-		return $this->get_prop( 'version', $context );
143
+     * Get plugin version when the item was created.
144
+     *
145
+     * @since 1.0.19
146
+     * @param  string $context View or edit context.
147
+     * @return string
148
+     */
149
+    public function get_version( $context = 'view' ) {
150
+        return $this->get_prop( 'version', $context );
151 151
     }
152 152
 
153 153
     /**
154
-	 * Get date when the item was created.
155
-	 *
156
-	 * @since 1.0.19
157
-	 * @param  string $context View or edit context.
158
-	 * @return string
159
-	 */
160
-	public function get_date_created( $context = 'view' ) {
161
-		return $this->get_prop( 'date_created', $context );
154
+     * Get date when the item was created.
155
+     *
156
+     * @since 1.0.19
157
+     * @param  string $context View or edit context.
158
+     * @return string
159
+     */
160
+    public function get_date_created( $context = 'view' ) {
161
+        return $this->get_prop( 'date_created', $context );
162 162
     }
163 163
 
164 164
     /**
165
-	 * Get GMT date when the item was created.
166
-	 *
167
-	 * @since 1.0.19
168
-	 * @param  string $context View or edit context.
169
-	 * @return string
170
-	 */
171
-	public function get_date_created_gmt( $context = 'view' ) {
165
+     * Get GMT date when the item was created.
166
+     *
167
+     * @since 1.0.19
168
+     * @param  string $context View or edit context.
169
+     * @return string
170
+     */
171
+    public function get_date_created_gmt( $context = 'view' ) {
172 172
         $date = $this->get_date_created( $context );
173 173
 
174 174
         if ( $date ) {
175 175
             $date = get_gmt_from_date( $date );
176 176
         }
177
-		return $date;
177
+        return $date;
178 178
     }
179 179
 
180 180
     /**
181
-	 * Get date when the item was last modified.
182
-	 *
183
-	 * @since 1.0.19
184
-	 * @param  string $context View or edit context.
185
-	 * @return string
186
-	 */
187
-	public function get_date_modified( $context = 'view' ) {
188
-		return $this->get_prop( 'date_modified', $context );
181
+     * Get date when the item was last modified.
182
+     *
183
+     * @since 1.0.19
184
+     * @param  string $context View or edit context.
185
+     * @return string
186
+     */
187
+    public function get_date_modified( $context = 'view' ) {
188
+        return $this->get_prop( 'date_modified', $context );
189 189
     }
190 190
 
191 191
     /**
192
-	 * Get GMT date when the item was last modified.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return string
197
-	 */
198
-	public function get_date_modified_gmt( $context = 'view' ) {
192
+     * Get GMT date when the item was last modified.
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return string
197
+     */
198
+    public function get_date_modified_gmt( $context = 'view' ) {
199 199
         $date = $this->get_date_modified( $context );
200 200
 
201 201
         if ( $date ) {
202 202
             $date = get_gmt_from_date( $date );
203 203
         }
204
-		return $date;
204
+        return $date;
205 205
     }
206 206
 
207 207
     /**
208
-	 * Get the item name.
209
-	 *
210
-	 * @since 1.0.19
211
-	 * @param  string $context View or edit context.
212
-	 * @return string
213
-	 */
214
-	public function get_name( $context = 'view' ) {
215
-		return $this->get_prop( 'name', $context );
208
+     * Get the item name.
209
+     *
210
+     * @since 1.0.19
211
+     * @param  string $context View or edit context.
212
+     * @return string
213
+     */
214
+    public function get_name( $context = 'view' ) {
215
+        return $this->get_prop( 'name', $context );
216 216
     }
217 217
 
218 218
     /**
219
-	 * Alias of self::get_name().
220
-	 *
221
-	 * @since 1.0.19
222
-	 * @param  string $context View or edit context.
223
-	 * @return string
224
-	 */
225
-	public function get_title( $context = 'view' ) {
226
-		return $this->get_name( $context );
219
+     * Alias of self::get_name().
220
+     *
221
+     * @since 1.0.19
222
+     * @param  string $context View or edit context.
223
+     * @return string
224
+     */
225
+    public function get_title( $context = 'view' ) {
226
+        return $this->get_name( $context );
227 227
     }
228 228
 
229 229
     /**
230
-	 * Get the item description.
231
-	 *
232
-	 * @since 1.0.19
233
-	 * @param  string $context View or edit context.
234
-	 * @return string
235
-	 */
236
-	public function get_description( $context = 'view' ) {
237
-		return $this->get_prop( 'description', $context );
230
+     * Get the item description.
231
+     *
232
+     * @since 1.0.19
233
+     * @param  string $context View or edit context.
234
+     * @return string
235
+     */
236
+    public function get_description( $context = 'view' ) {
237
+        return $this->get_prop( 'description', $context );
238 238
     }
239 239
 
240 240
     /**
241
-	 * Alias of self::get_description().
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return string
246
-	 */
247
-	public function get_excerpt( $context = 'view' ) {
248
-		return $this->get_description( $context );
241
+     * Alias of self::get_description().
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return string
246
+     */
247
+    public function get_excerpt( $context = 'view' ) {
248
+        return $this->get_description( $context );
249 249
     }
250 250
 
251 251
     /**
252
-	 * Alias of self::get_description().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return string
257
-	 */
258
-	public function get_summary( $context = 'view' ) {
259
-		return $this->get_description( $context );
252
+     * Alias of self::get_description().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return string
257
+     */
258
+    public function get_summary( $context = 'view' ) {
259
+        return $this->get_description( $context );
260 260
     }
261 261
 
262 262
     /**
263
-	 * Get the owner of the item.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return string
268
-	 */
269
-	public function get_author( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'author', $context );
263
+     * Get the owner of the item.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return string
268
+     */
269
+    public function get_author( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'author', $context );
271 271
     }
272 272
 
273 273
     /**
274
-	 * Get the price of the item.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return float
279
-	 */
280
-	public function get_price( $context = 'view' ) {
274
+     * Get the price of the item.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return float
279
+     */
280
+    public function get_price( $context = 'view' ) {
281 281
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
282
-	}
282
+    }
283 283
 	
284
-	/**
285
-	 * Get the inital price of the item.
286
-	 *
287
-	 * @since 1.0.19
288
-	 * @param  string $context View or edit context.
289
-	 * @return float
290
-	 */
291
-	public function get_initial_price( $context = 'view' ) {
284
+    /**
285
+     * Get the inital price of the item.
286
+     *
287
+     * @since 1.0.19
288
+     * @param  string $context View or edit context.
289
+     * @return float
290
+     */
291
+    public function get_initial_price( $context = 'view' ) {
292 292
 
293
-		$price = $this->get_price( $context );
293
+        $price = $this->get_price( $context );
294 294
 
295
-		if ( $this->has_free_trial() ) {
296
-			$price = wpinv_sanitize_amount( 0 );
297
-		}
295
+        if ( $this->has_free_trial() ) {
296
+            $price = wpinv_sanitize_amount( 0 );
297
+        }
298 298
 
299 299
         return apply_filters( 'wpinv_get_initial_item_price', $price, $this );
300 300
     }
301 301
 
302 302
     /**
303
-	 * Returns a formated price.
304
-	 *
305
-	 * @since 1.0.19
306
-	 * @param  string $context View or edit context.
307
-	 * @return string
308
-	 */
303
+     * Returns a formated price.
304
+     *
305
+     * @since 1.0.19
306
+     * @param  string $context View or edit context.
307
+     * @return string
308
+     */
309 309
     public function get_the_price() {
310 310
         $item_price = wpinv_price( $this->get_price() );
311 311
 
@@ -313,175 +313,175 @@  discard block
 block discarded – undo
313 313
     }
314 314
 
315 315
     /**
316
-	 * Get the VAT rule of the item.
317
-	 *
318
-	 * @since 1.0.19
319
-	 * @param  string $context View or edit context.
320
-	 * @return string
321
-	 */
322
-	public function get_vat_rule( $context = 'view' ) {
316
+     * Get the VAT rule of the item.
317
+     *
318
+     * @since 1.0.19
319
+     * @param  string $context View or edit context.
320
+     * @return string
321
+     */
322
+    public function get_vat_rule( $context = 'view' ) {
323 323
         return $this->get_prop( 'vat_rule', $context );
324 324
     }
325 325
 
326 326
     /**
327
-	 * Get the VAT class of the item.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  string $context View or edit context.
331
-	 * @return string
332
-	 */
333
-	public function get_vat_class( $context = 'view' ) {
327
+     * Get the VAT class of the item.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  string $context View or edit context.
331
+     * @return string
332
+     */
333
+    public function get_vat_class( $context = 'view' ) {
334 334
         return $this->get_prop( 'vat_class', $context );
335 335
     }
336 336
 
337 337
     /**
338
-	 * Get the type of the item.
339
-	 *
340
-	 * @since 1.0.19
341
-	 * @param  string $context View or edit context.
342
-	 * @return string
343
-	 */
344
-	public function get_type( $context = 'view' ) {
338
+     * Get the type of the item.
339
+     *
340
+     * @since 1.0.19
341
+     * @param  string $context View or edit context.
342
+     * @return string
343
+     */
344
+    public function get_type( $context = 'view' ) {
345 345
         return $this->get_prop( 'type', $context );
346 346
     }
347 347
 
348 348
     /**
349
-	 * Get the custom id of the item.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @param  string $context View or edit context.
353
-	 * @return string
354
-	 */
355
-	public function get_custom_id( $context = 'view' ) {
349
+     * Get the custom id of the item.
350
+     *
351
+     * @since 1.0.19
352
+     * @param  string $context View or edit context.
353
+     * @return string
354
+     */
355
+    public function get_custom_id( $context = 'view' ) {
356 356
         return $this->get_prop( 'custom_id', $context );
357 357
     }
358 358
 
359 359
     /**
360
-	 * Get the custom name of the item.
361
-	 *
362
-	 * @since 1.0.19
363
-	 * @param  string $context View or edit context.
364
-	 * @return string
365
-	 */
366
-	public function get_custom_name( $context = 'view' ) {
360
+     * Get the custom name of the item.
361
+     *
362
+     * @since 1.0.19
363
+     * @param  string $context View or edit context.
364
+     * @return string
365
+     */
366
+    public function get_custom_name( $context = 'view' ) {
367 367
         return $this->get_prop( 'custom_name', $context );
368 368
     }
369 369
 
370 370
     /**
371
-	 * Get the custom singular name of the item.
372
-	 *
373
-	 * @since 1.0.19
374
-	 * @param  string $context View or edit context.
375
-	 * @return string
376
-	 */
377
-	public function get_custom_singular_name( $context = 'view' ) {
371
+     * Get the custom singular name of the item.
372
+     *
373
+     * @since 1.0.19
374
+     * @param  string $context View or edit context.
375
+     * @return string
376
+     */
377
+    public function get_custom_singular_name( $context = 'view' ) {
378 378
         return $this->get_prop( 'custom_singular_name', $context );
379 379
     }
380 380
 
381 381
     /**
382
-	 * Checks if an item is editable..
383
-	 *
384
-	 * @since 1.0.19
385
-	 * @param  string $context View or edit context.
386
-	 * @return int
387
-	 */
388
-	public function get_is_editable( $context = 'view' ) {
382
+     * Checks if an item is editable..
383
+     *
384
+     * @since 1.0.19
385
+     * @param  string $context View or edit context.
386
+     * @return int
387
+     */
388
+    public function get_is_editable( $context = 'view' ) {
389 389
         return (int) $this->get_prop( 'is_editable', $context );
390 390
     }
391 391
 
392 392
     /**
393
-	 * Alias of self::get_is_editable().
394
-	 *
395
-	 * @since 1.0.19
396
-	 * @param  string $context View or edit context.
397
-	 * @return int
398
-	 */
399
-	public function get_editable( $context = 'view' ) {
400
-		return $this->get_is_editable( $context );
393
+     * Alias of self::get_is_editable().
394
+     *
395
+     * @since 1.0.19
396
+     * @param  string $context View or edit context.
397
+     * @return int
398
+     */
399
+    public function get_editable( $context = 'view' ) {
400
+        return $this->get_is_editable( $context );
401 401
     }
402 402
 
403 403
     /**
404
-	 * Checks if dynamic pricing is enabled.
405
-	 *
406
-	 * @since 1.0.19
407
-	 * @param  string $context View or edit context.
408
-	 * @return int
409
-	 */
410
-	public function get_is_dynamic_pricing( $context = 'view' ) {
404
+     * Checks if dynamic pricing is enabled.
405
+     *
406
+     * @since 1.0.19
407
+     * @param  string $context View or edit context.
408
+     * @return int
409
+     */
410
+    public function get_is_dynamic_pricing( $context = 'view' ) {
411 411
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
412 412
     }
413 413
 
414 414
     /**
415
-	 * Returns the minimum price if dynamic pricing is enabled.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return float
420
-	 */
421
-	public function get_minimum_price( $context = 'view' ) {
415
+     * Returns the minimum price if dynamic pricing is enabled.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return float
420
+     */
421
+    public function get_minimum_price( $context = 'view' ) {
422 422
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
423 423
     }
424 424
 
425 425
     /**
426
-	 * Checks if this is a recurring item.
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return int
431
-	 */
432
-	public function get_is_recurring( $context = 'view' ) {
426
+     * Checks if this is a recurring item.
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return int
431
+     */
432
+    public function get_is_recurring( $context = 'view' ) {
433 433
         return (int) $this->get_prop( 'is_recurring', $context );
434
-	}
434
+    }
435 435
 	
436
-	/**
437
-	 * Get the recurring price of the item.
438
-	 *
439
-	 * @since 1.0.19
440
-	 * @param  string $context View or edit context.
441
-	 * @return float
442
-	 */
443
-	public function get_recurring_price( $context = 'view' ) {
444
-		$price = $this->get_price( $context );
436
+    /**
437
+     * Get the recurring price of the item.
438
+     *
439
+     * @since 1.0.19
440
+     * @param  string $context View or edit context.
441
+     * @return float
442
+     */
443
+    public function get_recurring_price( $context = 'view' ) {
444
+        $price = $this->get_price( $context );
445 445
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
446
-	}
447
-
448
-	/**
449
-	 * Get the first renewal date (in timestamps) of the item.
450
-	 *
451
-	 * @since 1.0.19
452
-	 * @return int
453
-	 */
454
-	public function get_first_renewal_date() {
455
-
456
-		$periods = array(
457
-			'D' => 'days',
458
-			'W' => 'weeks',
459
-			'M' => 'months',
460
-			'Y' => 'years',
461
-		);
462
-
463
-		$period   = $this->get_recurring_period();
464
-		$interval = $this->get_recurring_interval();
465
-
466
-		if ( $this->has_free_trial() ) {
467
-			$period   = $this->get_trial_period();
468
-			$interval = $this->get_trial_interval();
469
-		}
470
-
471
-		$period       = $periods[ $period ];
472
-		$interval     = empty( $interval ) ? 1 : $interval;
473
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
446
+    }
447
+
448
+    /**
449
+     * Get the first renewal date (in timestamps) of the item.
450
+     *
451
+     * @since 1.0.19
452
+     * @return int
453
+     */
454
+    public function get_first_renewal_date() {
455
+
456
+        $periods = array(
457
+            'D' => 'days',
458
+            'W' => 'weeks',
459
+            'M' => 'months',
460
+            'Y' => 'years',
461
+        );
462
+
463
+        $period   = $this->get_recurring_period();
464
+        $interval = $this->get_recurring_interval();
465
+
466
+        if ( $this->has_free_trial() ) {
467
+            $period   = $this->get_trial_period();
468
+            $interval = $this->get_trial_interval();
469
+        }
470
+
471
+        $period       = $periods[ $period ];
472
+        $interval     = empty( $interval ) ? 1 : $interval;
473
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
474 474
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
475 475
     }
476 476
 
477 477
     /**
478
-	 * Get the recurring period.
479
-	 *
480
-	 * @since 1.0.19
481
-	 * @param  bool $full Return abbreviation or in full.
482
-	 * @return string
483
-	 */
484
-	public function get_recurring_period( $full = false ) {
478
+     * Get the recurring period.
479
+     *
480
+     * @since 1.0.19
481
+     * @param  bool $full Return abbreviation or in full.
482
+     * @return string
483
+     */
484
+    public function get_recurring_period( $full = false ) {
485 485
         $period = $this->get_prop( 'recurring_period', 'view' );
486 486
 
487 487
         if ( $full && ! is_bool( $full ) ) {
@@ -492,63 +492,63 @@  discard block
 block discarded – undo
492 492
     }
493 493
 
494 494
     /**
495
-	 * Get the recurring interval.
496
-	 *
497
-	 * @since 1.0.19
498
-	 * @param  string $context View or edit context.
499
-	 * @return int
500
-	 */
501
-	public function get_recurring_interval( $context = 'view' ) {
502
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
495
+     * Get the recurring interval.
496
+     *
497
+     * @since 1.0.19
498
+     * @param  string $context View or edit context.
499
+     * @return int
500
+     */
501
+    public function get_recurring_interval( $context = 'view' ) {
502
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
503 503
 
504
-		if ( $interval < 1 ) {
505
-			$interval = 1;
506
-		}
504
+        if ( $interval < 1 ) {
505
+            $interval = 1;
506
+        }
507 507
 
508 508
         return $interval;
509 509
     }
510 510
 
511 511
     /**
512
-	 * Get the recurring limit.
513
-	 *
514
-	 * @since 1.0.19
515
-	 * @param  string $context View or edit context.
516
-	 * @return int
517
-	 */
518
-	public function get_recurring_limit( $context = 'view' ) {
512
+     * Get the recurring limit.
513
+     *
514
+     * @since 1.0.19
515
+     * @param  string $context View or edit context.
516
+     * @return int
517
+     */
518
+    public function get_recurring_limit( $context = 'view' ) {
519 519
         return (int) $this->get_prop( 'recurring_limit', $context );
520 520
     }
521 521
 
522 522
     /**
523
-	 * Checks if we have a free trial.
524
-	 *
525
-	 * @since 1.0.19
526
-	 * @param  string $context View or edit context.
527
-	 * @return int
528
-	 */
529
-	public function get_is_free_trial( $context = 'view' ) {
523
+     * Checks if we have a free trial.
524
+     *
525
+     * @since 1.0.19
526
+     * @param  string $context View or edit context.
527
+     * @return int
528
+     */
529
+    public function get_is_free_trial( $context = 'view' ) {
530 530
         return (int) $this->get_prop( 'is_free_trial', $context );
531 531
     }
532 532
 
533 533
     /**
534
-	 * Alias for self::get_is_free_trial().
535
-	 *
536
-	 * @since 1.0.19
537
-	 * @param  string $context View or edit context.
538
-	 * @return int
539
-	 */
540
-	public function get_free_trial( $context = 'view' ) {
534
+     * Alias for self::get_is_free_trial().
535
+     *
536
+     * @since 1.0.19
537
+     * @param  string $context View or edit context.
538
+     * @return int
539
+     */
540
+    public function get_free_trial( $context = 'view' ) {
541 541
         return $this->get_is_free_trial( $context );
542 542
     }
543 543
 
544 544
     /**
545
-	 * Get the trial period.
546
-	 *
547
-	 * @since 1.0.19
548
-	 * @param  bool $full Return abbreviation or in full.
549
-	 * @return string
550
-	 */
551
-	public function get_trial_period( $full = false ) {
545
+     * Get the trial period.
546
+     *
547
+     * @since 1.0.19
548
+     * @param  bool $full Return abbreviation or in full.
549
+     * @return string
550
+     */
551
+    public function get_trial_period( $full = false ) {
552 552
         $period = $this->get_prop( 'trial_period', 'view' );
553 553
 
554 554
         if ( $full && ! is_bool( $full ) ) {
@@ -559,13 +559,13 @@  discard block
 block discarded – undo
559 559
     }
560 560
 
561 561
     /**
562
-	 * Get the trial interval.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param  string $context View or edit context.
566
-	 * @return int
567
-	 */
568
-	public function get_trial_interval( $context = 'view' ) {
562
+     * Get the trial interval.
563
+     *
564
+     * @since 1.0.19
565
+     * @param  string $context View or edit context.
566
+     * @return int
567
+     */
568
+    public function get_trial_interval( $context = 'view' ) {
569 569
         return (int) $this->get_prop( 'trial_interval', $context );
570 570
     }
571 571
 
@@ -599,52 +599,52 @@  discard block
 block discarded – undo
599 599
     */
600 600
 
601 601
     /**
602
-	 * Set parent order ID.
603
-	 *
604
-	 * @since 1.0.19
605
-	 */
606
-	public function set_parent_id( $value ) {
607
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
608
-			return;
609
-		}
610
-		$this->set_prop( 'parent_id', absint( $value ) );
611
-	}
612
-
613
-    /**
614
-	 * Sets item status.
615
-	 *
616
-	 * @since 1.0.19
617
-	 * @param  string $status New status.
618
-	 * @return array details of change.
619
-	 */
620
-	public function set_status( $status ) {
602
+     * Set parent order ID.
603
+     *
604
+     * @since 1.0.19
605
+     */
606
+    public function set_parent_id( $value ) {
607
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
608
+            return;
609
+        }
610
+        $this->set_prop( 'parent_id', absint( $value ) );
611
+    }
612
+
613
+    /**
614
+     * Sets item status.
615
+     *
616
+     * @since 1.0.19
617
+     * @param  string $status New status.
618
+     * @return array details of change.
619
+     */
620
+    public function set_status( $status ) {
621 621
         $old_status = $this->get_status();
622 622
 
623 623
         $this->set_prop( 'status', $status );
624 624
 
625
-		return array(
626
-			'from' => $old_status,
627
-			'to'   => $status,
628
-		);
625
+        return array(
626
+            'from' => $old_status,
627
+            'to'   => $status,
628
+        );
629 629
     }
630 630
 
631 631
     /**
632
-	 * Set plugin version when the item was created.
633
-	 *
634
-	 * @since 1.0.19
635
-	 */
636
-	public function set_version( $value ) {
637
-		$this->set_prop( 'version', $value );
632
+     * Set plugin version when the item was created.
633
+     *
634
+     * @since 1.0.19
635
+     */
636
+    public function set_version( $value ) {
637
+        $this->set_prop( 'version', $value );
638 638
     }
639 639
 
640 640
     /**
641
-	 * Set date when the item was created.
642
-	 *
643
-	 * @since 1.0.19
644
-	 * @param string $value Value to set.
641
+     * Set date when the item was created.
642
+     *
643
+     * @since 1.0.19
644
+     * @param string $value Value to set.
645 645
      * @return bool Whether or not the date was set.
646
-	 */
647
-	public function set_date_created( $value ) {
646
+     */
647
+    public function set_date_created( $value ) {
648 648
         $date = strtotime( $value );
649 649
 
650 650
         if ( $date ) {
@@ -657,13 +657,13 @@  discard block
 block discarded – undo
657 657
     }
658 658
 
659 659
     /**
660
-	 * Set date when the item was last modified.
661
-	 *
662
-	 * @since 1.0.19
663
-	 * @param string $value Value to set.
660
+     * Set date when the item was last modified.
661
+     *
662
+     * @since 1.0.19
663
+     * @param string $value Value to set.
664 664
      * @return bool Whether or not the date was set.
665
-	 */
666
-	public function set_date_modified( $value ) {
665
+     */
666
+    public function set_date_modified( $value ) {
667 667
         $date = strtotime( $value );
668 668
 
669 669
         if ( $date ) {
@@ -676,105 +676,105 @@  discard block
 block discarded – undo
676 676
     }
677 677
 
678 678
     /**
679
-	 * Set the item name.
680
-	 *
681
-	 * @since 1.0.19
682
-	 * @param  string $value New name.
683
-	 */
684
-	public function set_name( $value ) {
679
+     * Set the item name.
680
+     *
681
+     * @since 1.0.19
682
+     * @param  string $value New name.
683
+     */
684
+    public function set_name( $value ) {
685 685
         $name = sanitize_text_field( $value );
686
-		$this->set_prop( 'name', $name );
686
+        $this->set_prop( 'name', $name );
687 687
     }
688 688
 
689 689
     /**
690
-	 * Alias of self::set_name().
691
-	 *
692
-	 * @since 1.0.19
693
-	 * @param  string $value New name.
694
-	 */
695
-	public function set_title( $value ) {
696
-		$this->set_name( $value );
690
+     * Alias of self::set_name().
691
+     *
692
+     * @since 1.0.19
693
+     * @param  string $value New name.
694
+     */
695
+    public function set_title( $value ) {
696
+        $this->set_name( $value );
697 697
     }
698 698
 
699 699
     /**
700
-	 * Set the item description.
701
-	 *
702
-	 * @since 1.0.19
703
-	 * @param  string $value New description.
704
-	 */
705
-	public function set_description( $value ) {
700
+     * Set the item description.
701
+     *
702
+     * @since 1.0.19
703
+     * @param  string $value New description.
704
+     */
705
+    public function set_description( $value ) {
706 706
         $description = wp_kses_post( $value );
707
-		return $this->set_prop( 'description', $description );
707
+        return $this->set_prop( 'description', $description );
708 708
     }
709 709
 
710 710
     /**
711
-	 * Alias of self::set_description().
712
-	 *
713
-	 * @since 1.0.19
714
-	 * @param  string $value New description.
715
-	 */
716
-	public function set_excerpt( $value ) {
717
-		$this->set_description( $value );
711
+     * Alias of self::set_description().
712
+     *
713
+     * @since 1.0.19
714
+     * @param  string $value New description.
715
+     */
716
+    public function set_excerpt( $value ) {
717
+        $this->set_description( $value );
718 718
     }
719 719
 
720 720
     /**
721
-	 * Alias of self::set_description().
722
-	 *
723
-	 * @since 1.0.19
724
-	 * @param  string $value New description.
725
-	 */
726
-	public function set_summary( $value ) {
727
-		$this->set_description( $value );
721
+     * Alias of self::set_description().
722
+     *
723
+     * @since 1.0.19
724
+     * @param  string $value New description.
725
+     */
726
+    public function set_summary( $value ) {
727
+        $this->set_description( $value );
728 728
     }
729 729
 
730 730
     /**
731
-	 * Set the owner of the item.
732
-	 *
733
-	 * @since 1.0.19
734
-	 * @param  int $value New author.
735
-	 */
736
-	public function set_author( $value ) {
737
-		$this->set_prop( 'author', (int) $value );
731
+     * Set the owner of the item.
732
+     *
733
+     * @since 1.0.19
734
+     * @param  int $value New author.
735
+     */
736
+    public function set_author( $value ) {
737
+        $this->set_prop( 'author', (int) $value );
738 738
     }
739 739
 
740 740
     /**
741
-	 * Set the price of the item.
742
-	 *
743
-	 * @since 1.0.19
744
-	 * @param  float $value New price.
745
-	 */
746
-	public function set_price( $value ) {
741
+     * Set the price of the item.
742
+     *
743
+     * @since 1.0.19
744
+     * @param  float $value New price.
745
+     */
746
+    public function set_price( $value ) {
747 747
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
748 748
     }
749 749
 
750 750
     /**
751
-	 * Set the VAT rule of the item.
752
-	 *
753
-	 * @since 1.0.19
754
-	 * @param  string $value new rule.
755
-	 */
756
-	public function set_vat_rule( $value ) {
751
+     * Set the VAT rule of the item.
752
+     *
753
+     * @since 1.0.19
754
+     * @param  string $value new rule.
755
+     */
756
+    public function set_vat_rule( $value ) {
757 757
         $this->set_prop( 'vat_rule', $value );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Set the VAT class of the item.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param  string $value new class.
765
-	 */
766
-	public function set_vat_class( $value ) {
761
+     * Set the VAT class of the item.
762
+     *
763
+     * @since 1.0.19
764
+     * @param  string $value new class.
765
+     */
766
+    public function set_vat_class( $value ) {
767 767
         $this->set_prop( 'vat_class', $value );
768 768
     }
769 769
 
770 770
     /**
771
-	 * Set the type of the item.
772
-	 *
773
-	 * @since 1.0.19
774
-	 * @param  string $value new item type.
775
-	 * @return string
776
-	 */
777
-	public function set_type( $value ) {
771
+     * Set the type of the item.
772
+     *
773
+     * @since 1.0.19
774
+     * @param  string $value new item type.
775
+     * @return string
776
+     */
777
+    public function set_type( $value ) {
778 778
 
779 779
         if ( empty( $value ) ) {
780 780
             $value = 'custom';
@@ -784,134 +784,134 @@  discard block
 block discarded – undo
784 784
     }
785 785
 
786 786
     /**
787
-	 * Set the custom id of the item.
788
-	 *
789
-	 * @since 1.0.19
790
-	 * @param  string $value new custom id.
791
-	 */
792
-	public function set_custom_id( $value ) {
787
+     * Set the custom id of the item.
788
+     *
789
+     * @since 1.0.19
790
+     * @param  string $value new custom id.
791
+     */
792
+    public function set_custom_id( $value ) {
793 793
         $this->set_prop( 'custom_id', $value );
794 794
     }
795 795
 
796 796
     /**
797
-	 * Set the custom name of the item.
798
-	 *
799
-	 * @since 1.0.19
800
-	 * @param  string $value new custom name.
801
-	 */
802
-	public function set_custom_name( $value ) {
797
+     * Set the custom name of the item.
798
+     *
799
+     * @since 1.0.19
800
+     * @param  string $value new custom name.
801
+     */
802
+    public function set_custom_name( $value ) {
803 803
         $this->set_prop( 'custom_name', $value );
804 804
     }
805 805
 
806 806
     /**
807
-	 * Set the custom singular name of the item.
808
-	 *
809
-	 * @since 1.0.19
810
-	 * @param  string $value new custom singular name.
811
-	 */
812
-	public function set_custom_singular_name( $value ) {
807
+     * Set the custom singular name of the item.
808
+     *
809
+     * @since 1.0.19
810
+     * @param  string $value new custom singular name.
811
+     */
812
+    public function set_custom_singular_name( $value ) {
813 813
         $this->set_prop( 'custom_singular_name', $value );
814 814
     }
815 815
 
816 816
     /**
817
-	 * Sets if an item is editable..
818
-	 *
819
-	 * @since 1.0.19
820
-	 * @param  int|bool $value whether or not the item is editable.
821
-	 */
822
-	public function set_is_editable( $value ) {
823
-		if ( is_numeric( $value ) ) {
824
-			$this->set_prop( 'is_editable', (int) $value );
825
-		}
817
+     * Sets if an item is editable..
818
+     *
819
+     * @since 1.0.19
820
+     * @param  int|bool $value whether or not the item is editable.
821
+     */
822
+    public function set_is_editable( $value ) {
823
+        if ( is_numeric( $value ) ) {
824
+            $this->set_prop( 'is_editable', (int) $value );
825
+        }
826 826
     }
827 827
 
828 828
     /**
829
-	 * Sets if dynamic pricing is enabled.
830
-	 *
831
-	 * @since 1.0.19
832
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
833
-	 */
834
-	public function set_is_dynamic_pricing( $value ) {
829
+     * Sets if dynamic pricing is enabled.
830
+     *
831
+     * @since 1.0.19
832
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
833
+     */
834
+    public function set_is_dynamic_pricing( $value ) {
835 835
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
836 836
     }
837 837
 
838 838
     /**
839
-	 * Sets the minimum price if dynamic pricing is enabled.
840
-	 *
841
-	 * @since 1.0.19
842
-	 * @param  float $value minimum price.
843
-	 */
844
-	public function set_minimum_price( $value ) {
839
+     * Sets the minimum price if dynamic pricing is enabled.
840
+     *
841
+     * @since 1.0.19
842
+     * @param  float $value minimum price.
843
+     */
844
+    public function set_minimum_price( $value ) {
845 845
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
846 846
     }
847 847
 
848 848
     /**
849
-	 * Sets if this is a recurring item.
850
-	 *
851
-	 * @since 1.0.19
852
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
853
-	 */
854
-	public function set_is_recurring( $value ) {
849
+     * Sets if this is a recurring item.
850
+     *
851
+     * @since 1.0.19
852
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
853
+     */
854
+    public function set_is_recurring( $value ) {
855 855
         $this->set_prop( 'is_recurring', (int) $value );
856 856
     }
857 857
 
858 858
     /**
859
-	 * Set the recurring period.
860
-	 *
861
-	 * @since 1.0.19
862
-	 * @param  string $value new period.
863
-	 */
864
-	public function set_recurring_period( $value ) {
859
+     * Set the recurring period.
860
+     *
861
+     * @since 1.0.19
862
+     * @param  string $value new period.
863
+     */
864
+    public function set_recurring_period( $value ) {
865 865
         $this->set_prop( 'recurring_period', $value );
866 866
     }
867 867
 
868 868
     /**
869
-	 * Set the recurring interval.
870
-	 *
871
-	 * @since 1.0.19
872
-	 * @param  int $value recurring interval.
873
-	 */
874
-	public function set_recurring_interval( $value ) {
869
+     * Set the recurring interval.
870
+     *
871
+     * @since 1.0.19
872
+     * @param  int $value recurring interval.
873
+     */
874
+    public function set_recurring_interval( $value ) {
875 875
         return $this->set_prop( 'recurring_interval', (int) $value );
876 876
     }
877 877
 
878 878
     /**
879
-	 * Get the recurring limit.
880
-	 * @since 1.0.19
881
-	 * @param  int $value The recurring limit.
882
-	 * @return int
883
-	 */
884
-	public function set_recurring_limit( $value ) {
879
+     * Get the recurring limit.
880
+     * @since 1.0.19
881
+     * @param  int $value The recurring limit.
882
+     * @return int
883
+     */
884
+    public function set_recurring_limit( $value ) {
885 885
         $this->set_prop( 'recurring_limit', (int) $value );
886 886
     }
887 887
 
888 888
     /**
889
-	 * Checks if we have a free trial.
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @param  int|bool $value whether or not it has a free trial.
893
-	 */
894
-	public function set_is_free_trial( $value ) {
889
+     * Checks if we have a free trial.
890
+     *
891
+     * @since 1.0.19
892
+     * @param  int|bool $value whether or not it has a free trial.
893
+     */
894
+    public function set_is_free_trial( $value ) {
895 895
         $this->set_prop( 'is_free_trial', (int) $value );
896 896
     }
897 897
 
898 898
     /**
899
-	 * Set the trial period.
900
-	 *
901
-	 * @since 1.0.19
902
-	 * @param  string $value trial period.
903
-	 */
904
-	public function set_trial_period( $value ) {
899
+     * Set the trial period.
900
+     *
901
+     * @since 1.0.19
902
+     * @param  string $value trial period.
903
+     */
904
+    public function set_trial_period( $value ) {
905 905
         $this->set_prop( 'trial_period', $value );
906 906
     }
907 907
 
908 908
     /**
909
-	 * Set the trial interval.
910
-	 *
911
-	 * @since 1.0.19
912
-	 * @param  int $value trial interval.
913
-	 */
914
-	public function set_trial_interval( $value ) {
909
+     * Set the trial interval.
910
+     *
911
+     * @since 1.0.19
912
+     * @param  int $value trial interval.
913
+     */
914
+    public function set_trial_interval( $value ) {
915 915
         $this->set_prop( 'trial_interval', $value );
916 916
     }
917 917
 
@@ -919,17 +919,17 @@  discard block
 block discarded – undo
919 919
      * Create an item. For backwards compatibilty.
920 920
      * 
921 921
      * @deprecated
922
-	 * @return int item id
922
+     * @return int item id
923 923
      */
924 924
     public function create( $data = array() ) {
925 925
 
926
-		// Set the properties.
927
-		if ( is_array( $data ) ) {
928
-			$this->set_props( $data );
929
-		}
926
+        // Set the properties.
927
+        if ( is_array( $data ) ) {
928
+            $this->set_props( $data );
929
+        }
930 930
 
931
-		// Save the item.
932
-		return $this->save();
931
+        // Save the item.
932
+        return $this->save();
933 933
 
934 934
     }
935 935
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      * Updates an item. For backwards compatibilty.
938 938
      * 
939 939
      * @deprecated
940
-	 * @return int item id
940
+     * @return int item id
941 941
      */
942 942
     public function update( $data = array() ) {
943 943
         return $this->create( $data );
@@ -953,84 +953,84 @@  discard block
 block discarded – undo
953 953
 	*/
954 954
 
955 955
     /**
956
-	 * Checks whether the item has enabled dynamic pricing.
957
-	 *
958
-	 * @since 1.0.19
959
-	 * @return bool
960
-	 */
961
-	public function user_can_set_their_price() {
956
+     * Checks whether the item has enabled dynamic pricing.
957
+     *
958
+     * @since 1.0.19
959
+     * @return bool
960
+     */
961
+    public function user_can_set_their_price() {
962 962
         return (bool) $this->get_is_dynamic_pricing();
963
-	}
963
+    }
964 964
 	
965
-	/**
966
-	 * Checks whether the item is recurring.
967
-	 *
968
-	 * @since 1.0.19
969
-	 * @return bool
970
-	 */
971
-	public function is_recurring() {
965
+    /**
966
+     * Checks whether the item is recurring.
967
+     *
968
+     * @since 1.0.19
969
+     * @return bool
970
+     */
971
+    public function is_recurring() {
972 972
         return (bool) $this->get_is_recurring();
973 973
     }
974 974
 
975 975
     /**
976
-	 * Checks whether the item has a free trial.
977
-	 *
978
-	 * @since 1.0.19
979
-	 * @return bool
980
-	 */
976
+     * Checks whether the item has a free trial.
977
+     *
978
+     * @since 1.0.19
979
+     * @return bool
980
+     */
981 981
     public function has_free_trial() {
982 982
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
983 983
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
984 984
     }
985 985
 
986 986
     /**
987
-	 * Checks whether the item is free.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @return bool
991
-	 */
987
+     * Checks whether the item is free.
988
+     *
989
+     * @since 1.0.19
990
+     * @return bool
991
+     */
992 992
     public function is_free() {
993 993
         $is_free   = $this->get_price() == 0;
994 994
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
995 995
     }
996 996
 
997 997
     /**
998
-	 * Checks the item status against a passed in status.
999
-	 *
1000
-	 * @param array|string $status Status to check.
1001
-	 * @return bool
1002
-	 */
1003
-	public function has_status( $status ) {
1004
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1005
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
998
+     * Checks the item status against a passed in status.
999
+     *
1000
+     * @param array|string $status Status to check.
1001
+     * @return bool
1002
+     */
1003
+    public function has_status( $status ) {
1004
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1005
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1006 1006
     }
1007 1007
 
1008 1008
     /**
1009
-	 * Checks the item type against a passed in types.
1010
-	 *
1011
-	 * @param array|string $type Type to check.
1012
-	 * @return bool
1013
-	 */
1014
-	public function is_type( $type ) {
1015
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1016
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1017
-	}
1009
+     * Checks the item type against a passed in types.
1010
+     *
1011
+     * @param array|string $type Type to check.
1012
+     * @return bool
1013
+     */
1014
+    public function is_type( $type ) {
1015
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1016
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1017
+    }
1018 1018
 
1019 1019
     /**
1020
-	 * Checks whether the item is editable.
1021
-	 *
1022
-	 * @since 1.0.19
1023
-	 * @return bool
1024
-	 */
1020
+     * Checks whether the item is editable.
1021
+     *
1022
+     * @since 1.0.19
1023
+     * @return bool
1024
+     */
1025 1025
     public function is_editable() {
1026 1026
         $is_editable = $this->get_is_editable();
1027 1027
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1028
-	}
1028
+    }
1029 1029
 
1030
-	/**
1031
-	 * Returns an array of cart fees.
1032
-	 */
1033
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1030
+    /**
1031
+     * Returns an array of cart fees.
1032
+     */
1033
+    public function get_fees( $type = 'fee', $item_id = 0 ) {
1034 1034
         global $wpi_session;
1035 1035
         
1036 1036
         $fees = $wpi_session->get( 'wpi_cart_fees' );
@@ -1074,11 +1074,11 @@  discard block
 block discarded – undo
1074 1074
     }
1075 1075
 
1076 1076
     /**
1077
-	 * Checks whether the item is purchasable.
1078
-	 *
1079
-	 * @since 1.0.19
1080
-	 * @return bool
1081
-	 */
1077
+     * Checks whether the item is purchasable.
1078
+     *
1079
+     * @since 1.0.19
1080
+     * @return bool
1081
+     */
1082 1082
     public function can_purchase() {
1083 1083
         $can_purchase = null !== $this->get_id();
1084 1084
 
@@ -1090,11 +1090,11 @@  discard block
 block discarded – undo
1090 1090
     }
1091 1091
 
1092 1092
     /**
1093
-	 * Checks whether the item supports dynamic pricing.
1094
-	 *
1095
-	 * @since 1.0.19
1096
-	 * @return bool
1097
-	 */
1093
+     * Checks whether the item supports dynamic pricing.
1094
+     *
1095
+     * @since 1.0.19
1096
+     * @return bool
1097
+     */
1098 1098
     public function supports_dynamic_pricing() {
1099 1099
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1100 1100
     }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -11,185 +11,185 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Data_Store {
13 13
 
14
-	/**
15
-	 * Contains an instance of the data store class that we are working with.
16
-	 *
17
-	 * @var GetPaid_Data_Store
18
-	 */
19
-	private $instance = null;
20
-
21
-	/**
22
-	 * Contains an array of default supported data stores.
23
-	 * Format of object name => class name.
24
-	 * Example: 'item' => 'GetPaid_Item_Data_Store'
25
-	 * You can also pass something like item-<type> for item stores and
26
-	 * that type will be used first when available, if a store is requested like
27
-	 * this and doesn't exist, then the store would fall back to 'item'.
28
-	 * Ran through `getpaid_data_stores`.
29
-	 *
30
-	 * @var array
31
-	 */
32
-	private $stores = array(
33
-		'item'         => 'GetPaid_Item_Data_Store',
34
-		'payment_form' => 'GetPaid_Payment_Form_Data_Store',
35
-		'discount'     => 'GetPaid_Discount_Data_Store',
36
-		'invoice'      => 'GetPaid_Invoice_Data_Store',
37
-	);
38
-
39
-	/**
40
-	 * Contains the name of the current data store's class name.
41
-	 *
42
-	 * @var string
43
-	 */
44
-	private $current_class_name = '';
45
-
46
-	/**
47
-	 * The object type this store works with.
48
-	 *
49
-	 * @var string
50
-	 */
51
-	private $object_type = '';
52
-
53
-	/**
54
-	 * Tells GetPaid_Data_Store which object
55
-	 * store we want to work with.
56
-	 *
57
-	 * @param string $object_type Name of object.
58
-	 */
59
-	public function __construct( $object_type ) {
60
-		$this->object_type = $object_type;
61
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
62
-
63
-		// If this object type can't be found, check to see if we can load one
64
-		// level up (so if item-type isn't found, we try item).
65
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
66
-			$pieces      = explode( '-', $object_type );
67
-			$object_type = $pieces[0];
68
-		}
69
-
70
-		if ( array_key_exists( $object_type, $this->stores ) ) {
71
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
72
-			if ( is_object( $store ) ) {
73
-				$this->current_class_name = get_class( $store );
74
-				$this->instance           = $store;
75
-			} else {
76
-				if ( ! class_exists( $store ) ) {
77
-					throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) );
78
-				}
79
-				$this->current_class_name = $store;
80
-				$this->instance           = new $store();
81
-			}
82
-		} else {
83
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
84
-		}
85
-	}
86
-
87
-	/**
88
-	 * Only store the object type to avoid serializing the data store instance.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public function __sleep() {
93
-		return array( 'object_type' );
94
-	}
95
-
96
-	/**
97
-	 * Re-run the constructor with the object type.
98
-	 *
99
-	 * @throws Exception When validation fails.
100
-	 */
101
-	public function __wakeup() {
102
-		$this->__construct( $this->object_type );
103
-	}
104
-
105
-	/**
106
-	 * Loads a data store.
107
-	 *
108
-	 * @param string $object_type Name of object.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @throws Exception When validation fails.
112
-	 * @return GetPaid_Data_Store
113
-	 */
114
-	public static function load( $object_type ) {
115
-		return new GetPaid_Data_Store( $object_type );
116
-	}
117
-
118
-	/**
119
-	 * Returns the class name of the current data store.
120
-	 *
121
-	 * @since 1.0.19
122
-	 * @return string
123
-	 */
124
-	public function get_current_class_name() {
125
-		return $this->current_class_name;
126
-	}
127
-
128
-	/**
129
-	 * Returns the object type of the current data store.
130
-	 *
131
-	 * @since 1.0.19
132
-	 * @return string
133
-	 */
134
-	public function get_object_type() {
135
-		return $this->object_type;
136
-	}
137
-
138
-	/**
139
-	 * Reads an object from the data store.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param GetPaid_Data $data GetPaid data instance.
143
-	 */
144
-	public function read( &$data ) {
145
-		$this->instance->read( $data );
146
-	}
147
-
148
-	/**
149
-	 * Create an object in the data store.
150
-	 *
151
-	 * @since 1.0.19
152
-	 * @param GetPaid_Data $data GetPaid data instance.
153
-	 */
154
-	public function create( &$data ) {
155
-		$this->instance->create( $data );
156
-	}
157
-
158
-	/**
159
-	 * Update an object in the data store.
160
-	 *
161
-	 * @since 1.0.19
162
-	 * @param GetPaid_Data $data GetPaid data instance.
163
-	 */
164
-	public function update( &$data ) {
165
-		$this->instance->update( $data );
166
-	}
167
-
168
-	/**
169
-	 * Delete an object from the data store.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param GetPaid_Data $data GetPaid data instance.
173
-	 * @param array   $args Array of args to pass to the delete method.
174
-	 */
175
-	public function delete( &$data, $args = array() ) {
176
-		$this->instance->delete( $data, $args );
177
-	}
178
-
179
-	/**
180
-	 * Data stores can define additional function. This passes
181
-	 * through to the instance if that function exists.
182
-	 *
183
-	 * @since 1.0.19
184
-	 * @param string $method     Method.
185
-	 * @return mixed
186
-	 */
187
-	public function __call( $method, $parameters ) {
188
-		if ( is_callable( array( $this->instance, $method ) ) ) {
189
-			$object     = array_shift( $parameters );
190
-			$parameters = array_merge( array( &$object ), $parameters );
191
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
192
-		}
193
-	}
14
+    /**
15
+     * Contains an instance of the data store class that we are working with.
16
+     *
17
+     * @var GetPaid_Data_Store
18
+     */
19
+    private $instance = null;
20
+
21
+    /**
22
+     * Contains an array of default supported data stores.
23
+     * Format of object name => class name.
24
+     * Example: 'item' => 'GetPaid_Item_Data_Store'
25
+     * You can also pass something like item-<type> for item stores and
26
+     * that type will be used first when available, if a store is requested like
27
+     * this and doesn't exist, then the store would fall back to 'item'.
28
+     * Ran through `getpaid_data_stores`.
29
+     *
30
+     * @var array
31
+     */
32
+    private $stores = array(
33
+        'item'         => 'GetPaid_Item_Data_Store',
34
+        'payment_form' => 'GetPaid_Payment_Form_Data_Store',
35
+        'discount'     => 'GetPaid_Discount_Data_Store',
36
+        'invoice'      => 'GetPaid_Invoice_Data_Store',
37
+    );
38
+
39
+    /**
40
+     * Contains the name of the current data store's class name.
41
+     *
42
+     * @var string
43
+     */
44
+    private $current_class_name = '';
45
+
46
+    /**
47
+     * The object type this store works with.
48
+     *
49
+     * @var string
50
+     */
51
+    private $object_type = '';
52
+
53
+    /**
54
+     * Tells GetPaid_Data_Store which object
55
+     * store we want to work with.
56
+     *
57
+     * @param string $object_type Name of object.
58
+     */
59
+    public function __construct( $object_type ) {
60
+        $this->object_type = $object_type;
61
+        $this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
62
+
63
+        // If this object type can't be found, check to see if we can load one
64
+        // level up (so if item-type isn't found, we try item).
65
+        if ( ! array_key_exists( $object_type, $this->stores ) ) {
66
+            $pieces      = explode( '-', $object_type );
67
+            $object_type = $pieces[0];
68
+        }
69
+
70
+        if ( array_key_exists( $object_type, $this->stores ) ) {
71
+            $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
72
+            if ( is_object( $store ) ) {
73
+                $this->current_class_name = get_class( $store );
74
+                $this->instance           = $store;
75
+            } else {
76
+                if ( ! class_exists( $store ) ) {
77
+                    throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) );
78
+                }
79
+                $this->current_class_name = $store;
80
+                $this->instance           = new $store();
81
+            }
82
+        } else {
83
+            throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
84
+        }
85
+    }
86
+
87
+    /**
88
+     * Only store the object type to avoid serializing the data store instance.
89
+     *
90
+     * @return array
91
+     */
92
+    public function __sleep() {
93
+        return array( 'object_type' );
94
+    }
95
+
96
+    /**
97
+     * Re-run the constructor with the object type.
98
+     *
99
+     * @throws Exception When validation fails.
100
+     */
101
+    public function __wakeup() {
102
+        $this->__construct( $this->object_type );
103
+    }
104
+
105
+    /**
106
+     * Loads a data store.
107
+     *
108
+     * @param string $object_type Name of object.
109
+     *
110
+     * @since 1.0.19
111
+     * @throws Exception When validation fails.
112
+     * @return GetPaid_Data_Store
113
+     */
114
+    public static function load( $object_type ) {
115
+        return new GetPaid_Data_Store( $object_type );
116
+    }
117
+
118
+    /**
119
+     * Returns the class name of the current data store.
120
+     *
121
+     * @since 1.0.19
122
+     * @return string
123
+     */
124
+    public function get_current_class_name() {
125
+        return $this->current_class_name;
126
+    }
127
+
128
+    /**
129
+     * Returns the object type of the current data store.
130
+     *
131
+     * @since 1.0.19
132
+     * @return string
133
+     */
134
+    public function get_object_type() {
135
+        return $this->object_type;
136
+    }
137
+
138
+    /**
139
+     * Reads an object from the data store.
140
+     *
141
+     * @since 1.0.19
142
+     * @param GetPaid_Data $data GetPaid data instance.
143
+     */
144
+    public function read( &$data ) {
145
+        $this->instance->read( $data );
146
+    }
147
+
148
+    /**
149
+     * Create an object in the data store.
150
+     *
151
+     * @since 1.0.19
152
+     * @param GetPaid_Data $data GetPaid data instance.
153
+     */
154
+    public function create( &$data ) {
155
+        $this->instance->create( $data );
156
+    }
157
+
158
+    /**
159
+     * Update an object in the data store.
160
+     *
161
+     * @since 1.0.19
162
+     * @param GetPaid_Data $data GetPaid data instance.
163
+     */
164
+    public function update( &$data ) {
165
+        $this->instance->update( $data );
166
+    }
167
+
168
+    /**
169
+     * Delete an object from the data store.
170
+     *
171
+     * @since 1.0.19
172
+     * @param GetPaid_Data $data GetPaid data instance.
173
+     * @param array   $args Array of args to pass to the delete method.
174
+     */
175
+    public function delete( &$data, $args = array() ) {
176
+        $this->instance->delete( $data, $args );
177
+    }
178
+
179
+    /**
180
+     * Data stores can define additional function. This passes
181
+     * through to the instance if that function exists.
182
+     *
183
+     * @since 1.0.19
184
+     * @param string $method     Method.
185
+     * @return mixed
186
+     */
187
+    public function __call( $method, $parameters ) {
188
+        if ( is_callable( array( $this->instance, $method ) ) ) {
189
+            $object     = array_shift( $parameters );
190
+            $parameters = array_merge( array( &$object ), $parameters );
191
+            return call_user_func_array( array( $this->instance, $method ), $parameters );
192
+        }
193
+    }
194 194
 
195 195
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-payment-form-data-store.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,178 +14,178 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for a form.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'wpinv_form_elements',
25
-		'wpinv_form_items',
26
-		'wpinv_form_earned',
27
-		'wpinv_form_refunded',
28
-		'wpinv_form_cancelled',
29
-		'wpinv_form_failed'
30
-	);
31
-
32
-	/**
33
-	 * A map of meta keys to data props.
34
-	 *
35
-	 * @since 1.0.19
36
-	 *
37
-	 * @var array
38
-	 */
39
-	protected $meta_key_to_props = array(
40
-		'wpinv_form_elements'  => 'elements',
41
-		'wpinv_form_items'     => 'items',
42
-		'wpinv_form_earned'    => 'earned',
43
-		'wpinv_form_refunded'  => 'refunded',
44
-		'wpinv_form_cancelled' => 'cancelled',
45
-		'wpinv_form_failed'    => 'failed',
46
-	);
47
-
48
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for a form.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        'wpinv_form_elements',
25
+        'wpinv_form_items',
26
+        'wpinv_form_earned',
27
+        'wpinv_form_refunded',
28
+        'wpinv_form_cancelled',
29
+        'wpinv_form_failed'
30
+    );
31
+
32
+    /**
33
+     * A map of meta keys to data props.
34
+     *
35
+     * @since 1.0.19
36
+     *
37
+     * @var array
38
+     */
39
+    protected $meta_key_to_props = array(
40
+        'wpinv_form_elements'  => 'elements',
41
+        'wpinv_form_items'     => 'items',
42
+        'wpinv_form_earned'    => 'earned',
43
+        'wpinv_form_refunded'  => 'refunded',
44
+        'wpinv_form_cancelled' => 'cancelled',
45
+        'wpinv_form_failed'    => 'failed',
46
+    );
47
+
48
+    /*
49 49
 	|--------------------------------------------------------------------------
50 50
 	| CRUD Methods
51 51
 	|--------------------------------------------------------------------------
52 52
 	*/
53 53
 
54
-	/**
55
-	 * Method to create a new form in the database.
56
-	 *
57
-	 * @param GetPaid_Payment_Form $form Form object.
58
-	 */
59
-	public function create( &$form ) {
60
-		$form->set_version( WPINV_VERSION );
61
-		$form->set_date_created( current_time('mysql') );
62
-
63
-		// Create a new post.
64
-		$id = wp_insert_post(
65
-			apply_filters(
66
-				'getpaid_new_payment_form_data',
67
-				array(
68
-					'post_date'     => $form->get_date_created( 'edit' ),
69
-					'post_type'     => 'wpi_payment_form',
70
-					'post_status'   => $this->get_post_status( $form ),
71
-					'ping_status'   => 'closed',
72
-					'post_author'   => $form->get_author( 'edit' ),
73
-					'post_title'    => $form->get_name( 'edit' ),
74
-				)
75
-			),
76
-			true
77
-		);
78
-
79
-		if ( $id && ! is_wp_error( $id ) ) {
80
-			$form->set_id( $id );
81
-			$this->update_post_meta( $form );
82
-			$form->save_meta_data();
83
-			$form->apply_changes();
84
-			$this->clear_caches( $form );
85
-			do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
86
-			return true;
87
-		}
88
-
89
-		if ( is_wp_error( $id ) ) {
90
-			$form->last_error = $id->get_error_message();
91
-		}
92
-
93
-		return false;
94
-	}
95
-
96
-	/**
97
-	 * Method to read a form from the database.
98
-	 *
99
-	 * @param GetPaid_Payment_Form $form Form object.
100
-	 *
101
-	 */
102
-	public function read( &$form ) {
103
-
104
-		$form->set_defaults();
105
-		$form_object = get_post( $form->get_id() );
106
-
107
-		if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
-			$form->last_error = __( 'Invalid form.', 'invoicing' );
109
-			return false;
110
-		}
111
-
112
-		$form->set_props(
113
-			array(
114
-				'date_created'  => 0 < $form_object->post_date ? $form_object->post_date : null,
115
-				'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null,
116
-				'status'        => $form_object->post_status,
117
-				'name'          => $form_object->post_title,
118
-				'author'        => $form_object->post_author,
119
-			)
120
-		);
121
-
122
-		$this->read_object_data( $form, $form_object );
123
-		$form->read_meta_data();
124
-		$form->set_object_read( true );
125
-		do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
126
-
127
-	}
128
-
129
-	/**
130
-	 * Method to update a form in the database.
131
-	 *
132
-	 * @param GetPaid_Payment_Form $form Form object.
133
-	 */
134
-	public function update( &$form ) {
135
-		$form->save_meta_data();
136
-		$form->set_version( WPINV_VERSION );
137
-
138
-		if ( null === $form->get_date_created( 'edit' ) ) {
139
-			$form->set_date_created(  current_time('mysql') );
140
-		}
141
-
142
-		// Grab the current status so we can compare.
143
-		$previous_status = get_post_status( $form->get_id() );
144
-
145
-		$changes = $form->get_changes();
146
-
147
-		// Only update the post when the post data changes.
148
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
149
-			$post_data = array(
150
-				'post_date'         => $form->get_date_created( 'edit' ),
151
-				'post_status'       => $form->get_status( 'edit' ),
152
-				'post_title'        => $form->get_name( 'edit' ),
153
-				'post_author'       => $form->get_author( 'edit' ),
154
-				'post_modified'     => $form->get_date_modified( 'edit' ),
155
-			);
156
-
157
-			/**
158
-			 * When updating this object, to prevent infinite loops, use $wpdb
159
-			 * to update data, since wp_update_post spawns more calls to the
160
-			 * save_post action.
161
-			 *
162
-			 * This ensures hooks are fired by either WP itself (admin screen save),
163
-			 * or an update purely from CRUD.
164
-			 */
165
-			if ( doing_action( 'save_post' ) ) {
166
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
167
-				clean_post_cache( $form->get_id() );
168
-			} else {
169
-				wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
170
-			}
171
-			$form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
172
-		}
173
-		$this->update_post_meta( $form );
174
-		$form->apply_changes();
175
-		$this->clear_caches( $form );
176
-
177
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
178
-		$new_status = $form->get_status( 'edit' );
179
-
180
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
181
-			do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
182
-		} else {
183
-			do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
184
-		}
185
-
186
-	}
187
-
188
-	/*
54
+    /**
55
+     * Method to create a new form in the database.
56
+     *
57
+     * @param GetPaid_Payment_Form $form Form object.
58
+     */
59
+    public function create( &$form ) {
60
+        $form->set_version( WPINV_VERSION );
61
+        $form->set_date_created( current_time('mysql') );
62
+
63
+        // Create a new post.
64
+        $id = wp_insert_post(
65
+            apply_filters(
66
+                'getpaid_new_payment_form_data',
67
+                array(
68
+                    'post_date'     => $form->get_date_created( 'edit' ),
69
+                    'post_type'     => 'wpi_payment_form',
70
+                    'post_status'   => $this->get_post_status( $form ),
71
+                    'ping_status'   => 'closed',
72
+                    'post_author'   => $form->get_author( 'edit' ),
73
+                    'post_title'    => $form->get_name( 'edit' ),
74
+                )
75
+            ),
76
+            true
77
+        );
78
+
79
+        if ( $id && ! is_wp_error( $id ) ) {
80
+            $form->set_id( $id );
81
+            $this->update_post_meta( $form );
82
+            $form->save_meta_data();
83
+            $form->apply_changes();
84
+            $this->clear_caches( $form );
85
+            do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
86
+            return true;
87
+        }
88
+
89
+        if ( is_wp_error( $id ) ) {
90
+            $form->last_error = $id->get_error_message();
91
+        }
92
+
93
+        return false;
94
+    }
95
+
96
+    /**
97
+     * Method to read a form from the database.
98
+     *
99
+     * @param GetPaid_Payment_Form $form Form object.
100
+     *
101
+     */
102
+    public function read( &$form ) {
103
+
104
+        $form->set_defaults();
105
+        $form_object = get_post( $form->get_id() );
106
+
107
+        if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
+            $form->last_error = __( 'Invalid form.', 'invoicing' );
109
+            return false;
110
+        }
111
+
112
+        $form->set_props(
113
+            array(
114
+                'date_created'  => 0 < $form_object->post_date ? $form_object->post_date : null,
115
+                'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null,
116
+                'status'        => $form_object->post_status,
117
+                'name'          => $form_object->post_title,
118
+                'author'        => $form_object->post_author,
119
+            )
120
+        );
121
+
122
+        $this->read_object_data( $form, $form_object );
123
+        $form->read_meta_data();
124
+        $form->set_object_read( true );
125
+        do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
126
+
127
+    }
128
+
129
+    /**
130
+     * Method to update a form in the database.
131
+     *
132
+     * @param GetPaid_Payment_Form $form Form object.
133
+     */
134
+    public function update( &$form ) {
135
+        $form->save_meta_data();
136
+        $form->set_version( WPINV_VERSION );
137
+
138
+        if ( null === $form->get_date_created( 'edit' ) ) {
139
+            $form->set_date_created(  current_time('mysql') );
140
+        }
141
+
142
+        // Grab the current status so we can compare.
143
+        $previous_status = get_post_status( $form->get_id() );
144
+
145
+        $changes = $form->get_changes();
146
+
147
+        // Only update the post when the post data changes.
148
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
149
+            $post_data = array(
150
+                'post_date'         => $form->get_date_created( 'edit' ),
151
+                'post_status'       => $form->get_status( 'edit' ),
152
+                'post_title'        => $form->get_name( 'edit' ),
153
+                'post_author'       => $form->get_author( 'edit' ),
154
+                'post_modified'     => $form->get_date_modified( 'edit' ),
155
+            );
156
+
157
+            /**
158
+             * When updating this object, to prevent infinite loops, use $wpdb
159
+             * to update data, since wp_update_post spawns more calls to the
160
+             * save_post action.
161
+             *
162
+             * This ensures hooks are fired by either WP itself (admin screen save),
163
+             * or an update purely from CRUD.
164
+             */
165
+            if ( doing_action( 'save_post' ) ) {
166
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
167
+                clean_post_cache( $form->get_id() );
168
+            } else {
169
+                wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
170
+            }
171
+            $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
172
+        }
173
+        $this->update_post_meta( $form );
174
+        $form->apply_changes();
175
+        $this->clear_caches( $form );
176
+
177
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
178
+        $new_status = $form->get_status( 'edit' );
179
+
180
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
181
+            do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
182
+        } else {
183
+            do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
184
+        }
185
+
186
+    }
187
+
188
+    /*
189 189
 	|--------------------------------------------------------------------------
190 190
 	| Additional Methods
191 191
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Payment_Form_Data_Store class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -56,37 +56,37 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @param GetPaid_Payment_Form $form Form object.
58 58
 	 */
59
-	public function create( &$form ) {
60
-		$form->set_version( WPINV_VERSION );
61
-		$form->set_date_created( current_time('mysql') );
59
+	public function create(&$form) {
60
+		$form->set_version(WPINV_VERSION);
61
+		$form->set_date_created(current_time('mysql'));
62 62
 
63 63
 		// Create a new post.
64 64
 		$id = wp_insert_post(
65 65
 			apply_filters(
66 66
 				'getpaid_new_payment_form_data',
67 67
 				array(
68
-					'post_date'     => $form->get_date_created( 'edit' ),
68
+					'post_date'     => $form->get_date_created('edit'),
69 69
 					'post_type'     => 'wpi_payment_form',
70
-					'post_status'   => $this->get_post_status( $form ),
70
+					'post_status'   => $this->get_post_status($form),
71 71
 					'ping_status'   => 'closed',
72
-					'post_author'   => $form->get_author( 'edit' ),
73
-					'post_title'    => $form->get_name( 'edit' ),
72
+					'post_author'   => $form->get_author('edit'),
73
+					'post_title'    => $form->get_name('edit'),
74 74
 				)
75 75
 			),
76 76
 			true
77 77
 		);
78 78
 
79
-		if ( $id && ! is_wp_error( $id ) ) {
80
-			$form->set_id( $id );
81
-			$this->update_post_meta( $form );
79
+		if ($id && !is_wp_error($id)) {
80
+			$form->set_id($id);
81
+			$this->update_post_meta($form);
82 82
 			$form->save_meta_data();
83 83
 			$form->apply_changes();
84
-			$this->clear_caches( $form );
85
-			do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
84
+			$this->clear_caches($form);
85
+			do_action('getpaid_create_payment_form', $form->get_id(), $form);
86 86
 			return true;
87 87
 		}
88 88
 
89
-		if ( is_wp_error( $id ) ) {
89
+		if (is_wp_error($id)) {
90 90
 			$form->last_error = $id->get_error_message();
91 91
 		}
92 92
 
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	 * @param GetPaid_Payment_Form $form Form object.
100 100
 	 *
101 101
 	 */
102
-	public function read( &$form ) {
102
+	public function read(&$form) {
103 103
 
104 104
 		$form->set_defaults();
105
-		$form_object = get_post( $form->get_id() );
105
+		$form_object = get_post($form->get_id());
106 106
 
107
-		if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
-			$form->last_error = __( 'Invalid form.', 'invoicing' );
107
+		if (!$form->get_id() || !$form_object || $form_object->post_type != 'wpi_payment_form') {
108
+			$form->last_error = __('Invalid form.', 'invoicing');
109 109
 			return false;
110 110
 		}
111 111
 
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 			)
120 120
 		);
121 121
 
122
-		$this->read_object_data( $form, $form_object );
122
+		$this->read_object_data($form, $form_object);
123 123
 		$form->read_meta_data();
124
-		$form->set_object_read( true );
125
-		do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
124
+		$form->set_object_read(true);
125
+		do_action('getpaid_read_payment_form', $form->get_id(), $form);
126 126
 
127 127
 	}
128 128
 
@@ -131,27 +131,27 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @param GetPaid_Payment_Form $form Form object.
133 133
 	 */
134
-	public function update( &$form ) {
134
+	public function update(&$form) {
135 135
 		$form->save_meta_data();
136
-		$form->set_version( WPINV_VERSION );
136
+		$form->set_version(WPINV_VERSION);
137 137
 
138
-		if ( null === $form->get_date_created( 'edit' ) ) {
139
-			$form->set_date_created(  current_time('mysql') );
138
+		if (null === $form->get_date_created('edit')) {
139
+			$form->set_date_created(current_time('mysql'));
140 140
 		}
141 141
 
142 142
 		// Grab the current status so we can compare.
143
-		$previous_status = get_post_status( $form->get_id() );
143
+		$previous_status = get_post_status($form->get_id());
144 144
 
145 145
 		$changes = $form->get_changes();
146 146
 
147 147
 		// Only update the post when the post data changes.
148
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
148
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author'), array_keys($changes))) {
149 149
 			$post_data = array(
150
-				'post_date'         => $form->get_date_created( 'edit' ),
151
-				'post_status'       => $form->get_status( 'edit' ),
152
-				'post_title'        => $form->get_name( 'edit' ),
153
-				'post_author'       => $form->get_author( 'edit' ),
154
-				'post_modified'     => $form->get_date_modified( 'edit' ),
150
+				'post_date'         => $form->get_date_created('edit'),
151
+				'post_status'       => $form->get_status('edit'),
152
+				'post_title'        => $form->get_name('edit'),
153
+				'post_author'       => $form->get_author('edit'),
154
+				'post_modified'     => $form->get_date_modified('edit'),
155 155
 			);
156 156
 
157 157
 			/**
@@ -162,25 +162,25 @@  discard block
 block discarded – undo
162 162
 			 * This ensures hooks are fired by either WP itself (admin screen save),
163 163
 			 * or an update purely from CRUD.
164 164
 			 */
165
-			if ( doing_action( 'save_post' ) ) {
166
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
167
-				clean_post_cache( $form->get_id() );
165
+			if (doing_action('save_post')) {
166
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $form->get_id()));
167
+				clean_post_cache($form->get_id());
168 168
 			} else {
169
-				wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
169
+				wp_update_post(array_merge(array('ID' => $form->get_id()), $post_data));
170 170
 			}
171
-			$form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
171
+			$form->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
172 172
 		}
173
-		$this->update_post_meta( $form );
173
+		$this->update_post_meta($form);
174 174
 		$form->apply_changes();
175
-		$this->clear_caches( $form );
175
+		$this->clear_caches($form);
176 176
 
177 177
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
178
-		$new_status = $form->get_status( 'edit' );
178
+		$new_status = $form->get_status('edit');
179 179
 
180
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
181
-			do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
180
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
181
+			do_action('getpaid_new_payment_form', $form->get_id(), $form);
182 182
 		} else {
183
-			do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
183
+			do_action('getpaid_update_payment_form', $form->get_id(), $form);
184 184
 		}
185 185
 
186 186
 	}
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-item-data-store.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,227 +14,227 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for an item.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'_wpinv_price',
25
-		'_wpinv_vat_rule',
26
-		'_wpinv_vat_class',
27
-		'_wpinv_type',
28
-		'_wpinv_custom_id',
29
-		'_wpinv_custom_name',
30
-		'_wpinv_custom_singular_name',
31
-		'_wpinv_editable',
32
-		'_wpinv_dynamic_pricing',
33
-		'_minimum_price',
34
-		'_wpinv_is_recurring',
35
-		'_wpinv_recurring_period',
36
-		'_wpinv_recurring_interval',
37
-		'_wpinv_recurring_limit',
38
-		'_wpinv_free_trial',
39
-		'_wpinv_trial_period',
40
-		'_wpinv_trial_interval'
41
-	);
42
-
43
-	/**
44
-	 * A map of meta keys to data props.
45
-	 *
46
-	 * @since 1.0.19
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $meta_key_to_props = array(
51
-		'_wpinv_price'                => 'price',
52
-		'_wpinv_vat_rule'             => 'vat_rule',
53
-		'_wpinv_vat_class'            => 'vat_class',
54
-		'_wpinv_type'                 => 'type',
55
-		'_wpinv_custom_id'            => 'custom_id',
56
-		'_wpinv_custom_name'          => 'custom_name',
57
-		'_wpinv_custom_singular_name' => 'custom_singular_name',
58
-		'_wpinv_editable'             => 'is_editable',
59
-		'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
-		'_minimum_price'              => 'minimum_price',
61
-		'_wpinv_custom_name'          => 'custom_name',
62
-		'_wpinv_is_recurring'         => 'is_recurring',
63
-		'_wpinv_recurring_period'     => 'recurring_period',
64
-		'_wpinv_recurring_interval'   => 'recurring_interval',
65
-		'_wpinv_recurring_limit'      => 'recurring_limit',
66
-		'_wpinv_free_trial'           => 'is_free_trial',
67
-		'_wpinv_trial_period'         => 'trial_period',
68
-		'_wpinv_trial_interval'       => 'trial_interval',
69
-		'_wpinv_version'              => 'version',
70
-	);
71
-
72
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for an item.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        '_wpinv_price',
25
+        '_wpinv_vat_rule',
26
+        '_wpinv_vat_class',
27
+        '_wpinv_type',
28
+        '_wpinv_custom_id',
29
+        '_wpinv_custom_name',
30
+        '_wpinv_custom_singular_name',
31
+        '_wpinv_editable',
32
+        '_wpinv_dynamic_pricing',
33
+        '_minimum_price',
34
+        '_wpinv_is_recurring',
35
+        '_wpinv_recurring_period',
36
+        '_wpinv_recurring_interval',
37
+        '_wpinv_recurring_limit',
38
+        '_wpinv_free_trial',
39
+        '_wpinv_trial_period',
40
+        '_wpinv_trial_interval'
41
+    );
42
+
43
+    /**
44
+     * A map of meta keys to data props.
45
+     *
46
+     * @since 1.0.19
47
+     *
48
+     * @var array
49
+     */
50
+    protected $meta_key_to_props = array(
51
+        '_wpinv_price'                => 'price',
52
+        '_wpinv_vat_rule'             => 'vat_rule',
53
+        '_wpinv_vat_class'            => 'vat_class',
54
+        '_wpinv_type'                 => 'type',
55
+        '_wpinv_custom_id'            => 'custom_id',
56
+        '_wpinv_custom_name'          => 'custom_name',
57
+        '_wpinv_custom_singular_name' => 'custom_singular_name',
58
+        '_wpinv_editable'             => 'is_editable',
59
+        '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
+        '_minimum_price'              => 'minimum_price',
61
+        '_wpinv_custom_name'          => 'custom_name',
62
+        '_wpinv_is_recurring'         => 'is_recurring',
63
+        '_wpinv_recurring_period'     => 'recurring_period',
64
+        '_wpinv_recurring_interval'   => 'recurring_interval',
65
+        '_wpinv_recurring_limit'      => 'recurring_limit',
66
+        '_wpinv_free_trial'           => 'is_free_trial',
67
+        '_wpinv_trial_period'         => 'trial_period',
68
+        '_wpinv_trial_interval'       => 'trial_interval',
69
+        '_wpinv_version'              => 'version',
70
+    );
71
+
72
+    /*
73 73
 	|--------------------------------------------------------------------------
74 74
 	| CRUD Methods
75 75
 	|--------------------------------------------------------------------------
76 76
 	*/
77 77
 
78
-	/**
79
-	 * Method to create a new item in the database.
80
-	 *
81
-	 * @param WPInv_Item $item Item object.
82
-	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time('mysql') );
86
-
87
-		// Create a new post.
88
-		$id = wp_insert_post(
89
-			apply_filters(
90
-				'getpaid_new_item_data',
91
-				array(
92
-					'post_date'     => $item->get_date_created( 'edit' ),
93
-					'post_type'     => 'wpi_item',
94
-					'post_status'   => $this->get_post_status( $item ),
95
-					'ping_status'   => 'closed',
96
-					'post_author'   => $item->get_author( 'edit' ),
97
-					'post_title'    => $item->get_name( 'edit' ),
98
-					'post_parent'   => 0,
99
-					'post_excerpt'  => $item->get_description( 'edit' ),
100
-				)
101
-			),
102
-			true
103
-		);
104
-
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
108
-			$item->save_meta_data();
109
-			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
112
-			return true;
113
-		}
114
-
115
-		if ( is_wp_error( $id ) ) {
116
-			$item->last_error = $id->get_error_message();
117
-		}
78
+    /**
79
+     * Method to create a new item in the database.
80
+     *
81
+     * @param WPInv_Item $item Item object.
82
+     */
83
+    public function create( &$item ) {
84
+        $item->set_version( WPINV_VERSION );
85
+        $item->set_date_created( current_time('mysql') );
86
+
87
+        // Create a new post.
88
+        $id = wp_insert_post(
89
+            apply_filters(
90
+                'getpaid_new_item_data',
91
+                array(
92
+                    'post_date'     => $item->get_date_created( 'edit' ),
93
+                    'post_type'     => 'wpi_item',
94
+                    'post_status'   => $this->get_post_status( $item ),
95
+                    'ping_status'   => 'closed',
96
+                    'post_author'   => $item->get_author( 'edit' ),
97
+                    'post_title'    => $item->get_name( 'edit' ),
98
+                    'post_parent'   => 0,
99
+                    'post_excerpt'  => $item->get_description( 'edit' ),
100
+                )
101
+            ),
102
+            true
103
+        );
104
+
105
+        if ( $id && ! is_wp_error( $id ) ) {
106
+            $item->set_id( $id );
107
+            $this->update_post_meta( $item );
108
+            $item->save_meta_data();
109
+            $item->apply_changes();
110
+            $this->clear_caches( $item );
111
+            do_action( 'getpaid_new_item', $item->get_id(), $item );
112
+            return true;
113
+        }
114
+
115
+        if ( is_wp_error( $id ) ) {
116
+            $item->last_error = $id->get_error_message();
117
+        }
118 118
 		
119
-		return false;
120
-	}
121
-
122
-	/**
123
-	 * Method to read an item from the database.
124
-	 *
125
-	 * @param WPInv_Item $item Item object.
126
-	 *
127
-	 */
128
-	public function read( &$item ) {
129
-
130
-		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
132
-
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
135
-			return false;
136
-		}
137
-
138
-		$item->set_props(
139
-			array(
140
-				'parent_id'     => $item_object->post_parent,
141
-				'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
142
-				'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
143
-				'status'        => $item_object->post_status,
144
-				'name'          => $item_object->post_title,
145
-				'description'   => $item_object->post_excerpt,
146
-				'author'        => $item_object->post_author,
147
-			)
148
-		);
149
-
150
-		$this->read_object_data( $item, $item_object );
151
-		$item->read_meta_data();
152
-		$item->set_object_read( true );
153
-		do_action( 'getpaid_read_item', $item->get_id(), $item );
154
-
155
-	}
156
-
157
-	/**
158
-	 * Method to update an item in the database.
159
-	 *
160
-	 * @param WPInv_Item $item Item object.
161
-	 */
162
-	public function update( &$item ) {
163
-		$item->save_meta_data();
164
-		$item->set_version( WPINV_VERSION );
165
-
166
-		if ( null === $item->get_date_created( 'edit' ) ) {
167
-			$item->set_date_created(  current_time('mysql') );
168
-		}
169
-
170
-		// Grab the current status so we can compare.
171
-		$previous_status = get_post_status( $item->get_id() );
172
-
173
-		$changes = $item->get_changes();
174
-
175
-		// Only update the post when the post data changes.
176
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
177
-			$post_data = array(
178
-				'post_date'         => $item->get_date_created( 'edit' ),
179
-				'post_status'       => $item->get_status( 'edit' ),
180
-				'post_parent'       => $item->get_parent_id( 'edit' ),
181
-				'post_excerpt'      => $item->get_description( 'edit' ),
182
-				'post_modified'     => $item->get_date_modified( 'edit' ),
183
-				'post_title'        => $item->get_name( 'edit' ),
184
-				'post_author'       => $item->get_author( 'edit' ),
185
-			);
186
-
187
-			/**
188
-			 * When updating this object, to prevent infinite loops, use $wpdb
189
-			 * to update data, since wp_update_post spawns more calls to the
190
-			 * save_post action.
191
-			 *
192
-			 * This ensures hooks are fired by either WP itself (admin screen save),
193
-			 * or an update purely from CRUD.
194
-			 */
195
-			if ( doing_action( 'save_post' ) ) {
196
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
197
-				clean_post_cache( $item->get_id() );
198
-			} else {
199
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
200
-			}
201
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202
-		}
203
-		$this->update_post_meta( $item );
204
-		$item->apply_changes();
205
-		$this->clear_caches( $item );
206
-
207
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
208
-		$new_status = $item->get_status( 'edit' );
209
-
210
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
211
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
212
-		} else {
213
-			do_action( 'getpaid_update_item', $item->get_id(), $item );
214
-		}
215
-
216
-	}
217
-
218
-	/*
119
+        return false;
120
+    }
121
+
122
+    /**
123
+     * Method to read an item from the database.
124
+     *
125
+     * @param WPInv_Item $item Item object.
126
+     *
127
+     */
128
+    public function read( &$item ) {
129
+
130
+        $item->set_defaults();
131
+        $item_object = get_post( $item->get_id() );
132
+
133
+        if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
+            $item->last_error = __( 'Invalid item.', 'invoicing' );
135
+            return false;
136
+        }
137
+
138
+        $item->set_props(
139
+            array(
140
+                'parent_id'     => $item_object->post_parent,
141
+                'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
142
+                'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
143
+                'status'        => $item_object->post_status,
144
+                'name'          => $item_object->post_title,
145
+                'description'   => $item_object->post_excerpt,
146
+                'author'        => $item_object->post_author,
147
+            )
148
+        );
149
+
150
+        $this->read_object_data( $item, $item_object );
151
+        $item->read_meta_data();
152
+        $item->set_object_read( true );
153
+        do_action( 'getpaid_read_item', $item->get_id(), $item );
154
+
155
+    }
156
+
157
+    /**
158
+     * Method to update an item in the database.
159
+     *
160
+     * @param WPInv_Item $item Item object.
161
+     */
162
+    public function update( &$item ) {
163
+        $item->save_meta_data();
164
+        $item->set_version( WPINV_VERSION );
165
+
166
+        if ( null === $item->get_date_created( 'edit' ) ) {
167
+            $item->set_date_created(  current_time('mysql') );
168
+        }
169
+
170
+        // Grab the current status so we can compare.
171
+        $previous_status = get_post_status( $item->get_id() );
172
+
173
+        $changes = $item->get_changes();
174
+
175
+        // Only update the post when the post data changes.
176
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
177
+            $post_data = array(
178
+                'post_date'         => $item->get_date_created( 'edit' ),
179
+                'post_status'       => $item->get_status( 'edit' ),
180
+                'post_parent'       => $item->get_parent_id( 'edit' ),
181
+                'post_excerpt'      => $item->get_description( 'edit' ),
182
+                'post_modified'     => $item->get_date_modified( 'edit' ),
183
+                'post_title'        => $item->get_name( 'edit' ),
184
+                'post_author'       => $item->get_author( 'edit' ),
185
+            );
186
+
187
+            /**
188
+             * When updating this object, to prevent infinite loops, use $wpdb
189
+             * to update data, since wp_update_post spawns more calls to the
190
+             * save_post action.
191
+             *
192
+             * This ensures hooks are fired by either WP itself (admin screen save),
193
+             * or an update purely from CRUD.
194
+             */
195
+            if ( doing_action( 'save_post' ) ) {
196
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
197
+                clean_post_cache( $item->get_id() );
198
+            } else {
199
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
200
+            }
201
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202
+        }
203
+        $this->update_post_meta( $item );
204
+        $item->apply_changes();
205
+        $this->clear_caches( $item );
206
+
207
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
208
+        $new_status = $item->get_status( 'edit' );
209
+
210
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
211
+            do_action( 'getpaid_new_item', $item->get_id(), $item );
212
+        } else {
213
+            do_action( 'getpaid_update_item', $item->get_id(), $item );
214
+        }
215
+
216
+    }
217
+
218
+    /*
219 219
 	|--------------------------------------------------------------------------
220 220
 	| Additional Methods
221 221
 	|--------------------------------------------------------------------------
222 222
 	*/
223 223
 
224
-	/**
225
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
226
-	 *
227
-	 * @param WPInv_Item $item WPInv_Item object.
228
-	 * @since 1.0.19
229
-	 */
230
-	protected function update_post_meta( &$item ) {
224
+    /**
225
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
226
+     *
227
+     * @param WPInv_Item $item WPInv_Item object.
228
+     * @since 1.0.19
229
+     */
230
+    protected function update_post_meta( &$item ) {
231 231
 
232
-		// Ensure that we have a custom id.
232
+        // Ensure that we have a custom id.
233 233
         if ( ! $item->get_custom_id() ) {
234 234
             $item->set_custom_id( $item->get_id() );
235
-		}
235
+        }
236 236
 
237
-		parent::update_post_meta( $item );
238
-	}
237
+        parent::update_post_meta( $item );
238
+    }
239 239
 
240 240
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Item_Data_Store class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -80,39 +80,39 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @param WPInv_Item $item Item object.
82 82
 	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time('mysql') );
83
+	public function create(&$item) {
84
+		$item->set_version(WPINV_VERSION);
85
+		$item->set_date_created(current_time('mysql'));
86 86
 
87 87
 		// Create a new post.
88 88
 		$id = wp_insert_post(
89 89
 			apply_filters(
90 90
 				'getpaid_new_item_data',
91 91
 				array(
92
-					'post_date'     => $item->get_date_created( 'edit' ),
92
+					'post_date'     => $item->get_date_created('edit'),
93 93
 					'post_type'     => 'wpi_item',
94
-					'post_status'   => $this->get_post_status( $item ),
94
+					'post_status'   => $this->get_post_status($item),
95 95
 					'ping_status'   => 'closed',
96
-					'post_author'   => $item->get_author( 'edit' ),
97
-					'post_title'    => $item->get_name( 'edit' ),
96
+					'post_author'   => $item->get_author('edit'),
97
+					'post_title'    => $item->get_name('edit'),
98 98
 					'post_parent'   => 0,
99
-					'post_excerpt'  => $item->get_description( 'edit' ),
99
+					'post_excerpt'  => $item->get_description('edit'),
100 100
 				)
101 101
 			),
102 102
 			true
103 103
 		);
104 104
 
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
105
+		if ($id && !is_wp_error($id)) {
106
+			$item->set_id($id);
107
+			$this->update_post_meta($item);
108 108
 			$item->save_meta_data();
109 109
 			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
110
+			$this->clear_caches($item);
111
+			do_action('getpaid_new_item', $item->get_id(), $item);
112 112
 			return true;
113 113
 		}
114 114
 
115
-		if ( is_wp_error( $id ) ) {
115
+		if (is_wp_error($id)) {
116 116
 			$item->last_error = $id->get_error_message();
117 117
 		}
118 118
 		
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 * @param WPInv_Item $item Item object.
126 126
 	 *
127 127
 	 */
128
-	public function read( &$item ) {
128
+	public function read(&$item) {
129 129
 
130 130
 		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
131
+		$item_object = get_post($item->get_id());
132 132
 
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
133
+		if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') {
134
+			$item->last_error = __('Invalid item.', 'invoicing');
135 135
 			return false;
136 136
 		}
137 137
 
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 			)
148 148
 		);
149 149
 
150
-		$this->read_object_data( $item, $item_object );
150
+		$this->read_object_data($item, $item_object);
151 151
 		$item->read_meta_data();
152
-		$item->set_object_read( true );
153
-		do_action( 'getpaid_read_item', $item->get_id(), $item );
152
+		$item->set_object_read(true);
153
+		do_action('getpaid_read_item', $item->get_id(), $item);
154 154
 
155 155
 	}
156 156
 
@@ -159,29 +159,29 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @param WPInv_Item $item Item object.
161 161
 	 */
162
-	public function update( &$item ) {
162
+	public function update(&$item) {
163 163
 		$item->save_meta_data();
164
-		$item->set_version( WPINV_VERSION );
164
+		$item->set_version(WPINV_VERSION);
165 165
 
166
-		if ( null === $item->get_date_created( 'edit' ) ) {
167
-			$item->set_date_created(  current_time('mysql') );
166
+		if (null === $item->get_date_created('edit')) {
167
+			$item->set_date_created(current_time('mysql'));
168 168
 		}
169 169
 
170 170
 		// Grab the current status so we can compare.
171
-		$previous_status = get_post_status( $item->get_id() );
171
+		$previous_status = get_post_status($item->get_id());
172 172
 
173 173
 		$changes = $item->get_changes();
174 174
 
175 175
 		// Only update the post when the post data changes.
176
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
176
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author'), array_keys($changes))) {
177 177
 			$post_data = array(
178
-				'post_date'         => $item->get_date_created( 'edit' ),
179
-				'post_status'       => $item->get_status( 'edit' ),
180
-				'post_parent'       => $item->get_parent_id( 'edit' ),
181
-				'post_excerpt'      => $item->get_description( 'edit' ),
182
-				'post_modified'     => $item->get_date_modified( 'edit' ),
183
-				'post_title'        => $item->get_name( 'edit' ),
184
-				'post_author'       => $item->get_author( 'edit' ),
178
+				'post_date'         => $item->get_date_created('edit'),
179
+				'post_status'       => $item->get_status('edit'),
180
+				'post_parent'       => $item->get_parent_id('edit'),
181
+				'post_excerpt'      => $item->get_description('edit'),
182
+				'post_modified'     => $item->get_date_modified('edit'),
183
+				'post_title'        => $item->get_name('edit'),
184
+				'post_author'       => $item->get_author('edit'),
185 185
 			);
186 186
 
187 187
 			/**
@@ -192,25 +192,25 @@  discard block
 block discarded – undo
192 192
 			 * This ensures hooks are fired by either WP itself (admin screen save),
193 193
 			 * or an update purely from CRUD.
194 194
 			 */
195
-			if ( doing_action( 'save_post' ) ) {
196
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
197
-				clean_post_cache( $item->get_id() );
195
+			if (doing_action('save_post')) {
196
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id()));
197
+				clean_post_cache($item->get_id());
198 198
 			} else {
199
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
199
+				wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data));
200 200
 			}
201
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
201
+			$item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202 202
 		}
203
-		$this->update_post_meta( $item );
203
+		$this->update_post_meta($item);
204 204
 		$item->apply_changes();
205
-		$this->clear_caches( $item );
205
+		$this->clear_caches($item);
206 206
 
207 207
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
208
-		$new_status = $item->get_status( 'edit' );
208
+		$new_status = $item->get_status('edit');
209 209
 
210
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
211
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
210
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
211
+			do_action('getpaid_new_item', $item->get_id(), $item);
212 212
 		} else {
213
-			do_action( 'getpaid_update_item', $item->get_id(), $item );
213
+			do_action('getpaid_update_item', $item->get_id(), $item);
214 214
 		}
215 215
 
216 216
 	}
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 	 * @param WPInv_Item $item WPInv_Item object.
228 228
 	 * @since 1.0.19
229 229
 	 */
230
-	protected function update_post_meta( &$item ) {
230
+	protected function update_post_meta(&$item) {
231 231
 
232 232
 		// Ensure that we have a custom id.
233
-        if ( ! $item->get_custom_id() ) {
234
-            $item->set_custom_id( $item->get_id() );
233
+        if (!$item->get_custom_id()) {
234
+            $item->set_custom_id($item->get_id());
235 235
 		}
236 236
 
237
-		parent::update_post_meta( $item );
237
+		parent::update_post_meta($item);
238 238
 	}
239 239
 
240 240
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store-wp.php 2 patches
Indentation   +338 added lines, -338 removed lines patch added patch discarded remove patch
@@ -14,346 +14,346 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Meta type. This should match up with
19
-	 * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
20
-	 * WP defines 'post', 'user', 'comment', and 'term'.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $meta_type = 'post';
25
-
26
-	/**
27
-	 * This only needs set if you are using a custom metadata type.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	protected $object_id_field_for_meta = '';
32
-
33
-	/**
34
-	 * Data stored in meta keys, but not considered "meta" for an object.
35
-	 *
36
-	 * @since 1.0.19
37
-	 *
38
-	 * @var array
39
-	 */
40
-	protected $internal_meta_keys = array();
41
-
42
-	/**
43
-	 * Meta data which should exist in the DB, even if empty.
44
-	 *
45
-	 * @since 1.0.19
46
-	 *
47
-	 * @var array
48
-	 */
49
-	protected $must_exist_meta_keys = array();
50
-
51
-	/**
52
-	 * A map of meta keys to data props.
53
-	 *
54
-	 * @since 1.0.19
55
-	 *
56
-	 * @var array
57
-	 */
58
-	protected $meta_key_to_props = array();
59
-
60
-	/**
61
-	 * Returns an array of meta for an object.
62
-	 *
63
-	 * @since  1.0.19
64
-	 * @param  GetPaid_Data $object GetPaid_Data object.
65
-	 * @return array
66
-	 */
67
-	public function read_meta( &$object ) {
68
-		global $wpdb;
69
-		$db_info       = $this->get_db_info();
70
-		$raw_meta_data = $wpdb->get_results(
71
-			$wpdb->prepare(
72
-				"SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
17
+    /**
18
+     * Meta type. This should match up with
19
+     * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
20
+     * WP defines 'post', 'user', 'comment', and 'term'.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $meta_type = 'post';
25
+
26
+    /**
27
+     * This only needs set if you are using a custom metadata type.
28
+     *
29
+     * @var string
30
+     */
31
+    protected $object_id_field_for_meta = '';
32
+
33
+    /**
34
+     * Data stored in meta keys, but not considered "meta" for an object.
35
+     *
36
+     * @since 1.0.19
37
+     *
38
+     * @var array
39
+     */
40
+    protected $internal_meta_keys = array();
41
+
42
+    /**
43
+     * Meta data which should exist in the DB, even if empty.
44
+     *
45
+     * @since 1.0.19
46
+     *
47
+     * @var array
48
+     */
49
+    protected $must_exist_meta_keys = array();
50
+
51
+    /**
52
+     * A map of meta keys to data props.
53
+     *
54
+     * @since 1.0.19
55
+     *
56
+     * @var array
57
+     */
58
+    protected $meta_key_to_props = array();
59
+
60
+    /**
61
+     * Returns an array of meta for an object.
62
+     *
63
+     * @since  1.0.19
64
+     * @param  GetPaid_Data $object GetPaid_Data object.
65
+     * @return array
66
+     */
67
+    public function read_meta( &$object ) {
68
+        global $wpdb;
69
+        $db_info       = $this->get_db_info();
70
+        $raw_meta_data = $wpdb->get_results(
71
+            $wpdb->prepare(
72
+                "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
73 73
 				FROM {$db_info['table']}
74 74
 				WHERE {$db_info['object_id_field']} = %d
75 75
 				ORDER BY {$db_info['meta_id_field']}",
76
-				$object->get_id()
77
-			)
78
-		);
79
-
80
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
83
-	}
84
-
85
-	/**
86
-	 * Deletes meta based on meta ID.
87
-	 *
88
-	 * @since  1.0.19
89
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
90
-	 * @param  stdClass $meta (containing at least ->id).
91
-	 */
92
-	public function delete_meta( &$object, $meta ) {
93
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
94
-	}
95
-
96
-	/**
97
-	 * Add new piece of meta.
98
-	 *
99
-	 * @since  1.0.19
100
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
101
-	 * @param  stdClass $meta (containing ->key and ->value).
102
-	 * @return int meta ID
103
-	 */
104
-	public function add_meta( &$object, $meta ) {
105
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
106
-	}
107
-
108
-	/**
109
-	 * Update meta.
110
-	 *
111
-	 * @since  1.0.19
112
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
113
-	 * @param  stdClass $meta (containing ->id, ->key and ->value).
114
-	 */
115
-	public function update_meta( &$object, $meta ) {
116
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
117
-	}
118
-
119
-	/**
120
-	 * Table structure is slightly different between meta types, this function will return what we need to know.
121
-	 *
122
-	 * @since  1.0.19
123
-	 * @return array Array elements: table, object_id_field, meta_id_field
124
-	 */
125
-	protected function get_db_info() {
126
-		global $wpdb;
127
-
128
-		$meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well.
129
-		$table         = $wpdb->prefix;
130
-
131
-		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
133
-			$table .= 'getpaid_';
134
-		}
135
-
136
-		$table          .= $this->meta_type . 'meta';
137
-		$object_id_field = $this->meta_type . '_id';
138
-
139
-		// Figure out our field names.
140
-		if ( 'user' === $this->meta_type ) {
141
-			$meta_id_field = 'umeta_id';
142
-			$table         = $wpdb->usermeta;
143
-		}
144
-
145
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
146
-			$object_id_field = $this->object_id_field_for_meta;
147
-		}
148
-
149
-		return array(
150
-			'table'           => $table,
151
-			'object_id_field' => $object_id_field,
152
-			'meta_id_field'   => $meta_id_field,
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Internal meta keys we don't want exposed as part of meta_data. This is in
158
-	 * addition to all data props with _ prefix.
159
-	 *
160
-	 * @since 1.0.19
161
-	 *
162
-	 * @param string $key Prefix to be added to meta keys.
163
-	 * @return string
164
-	 */
165
-	protected function prefix_key( $key ) {
166
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
167
-	}
168
-
169
-	/**
170
-	 * Callback to remove unwanted meta data.
171
-	 *
172
-	 * @param object $meta Meta object to check if it should be excluded or not.
173
-	 * @return bool
174
-	 */
175
-	protected function exclude_internal_meta_keys( $meta ) {
176
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
177
-	}
178
-
179
-	/**
180
-	 * Gets a list of props and meta keys that need updated based on change state
181
-	 * or if they are present in the database or not.
182
-	 *
183
-	 * @param  GetPaid_Data $object         The GetPaid_Data object.
184
-	 * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
185
-	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186
-	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187
-	 */
188
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
189
-		$props_to_update = array();
190
-		$changed_props   = $object->get_changes();
191
-
192
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
193
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
-				$props_to_update[ $meta_key ] = $prop;
196
-			}
197
-		}
198
-
199
-		return $props_to_update;
200
-	}
201
-
202
-	/**
203
-	 * Read object data.
204
-	 *
205
-	 * @param GetPaid_Data $object GetPaid_Data object.
206
-	 * @param WP_Post   $post_object Post object.
207
-	 * @since 1.0.19
208
-	 */
209
-	protected function read_object_data( &$object, $post_object ) {
210
-		$id    = $object->get_id();
211
-		$props = array();
212
-
213
-		foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
-			$props[ $prop ] = get_post_meta( $id, $meta_key, true );
215
-		}
216
-
217
-		// Set object properties.
218
-		$object->set_props( $props );
219
-
220
-		// Gets extra data associated with the object if needed.
221
-		foreach ( $object->get_extra_data_keys() as $key ) {
222
-			$function = 'set_' . $key;
223
-			if ( is_callable( array( $object, $function ) ) ) {
224
-				$object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
225
-			}
226
-		}
227
-	}
228
-
229
-	/**
230
-	 * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class.
231
-	 *
232
-	 * @param GetPaid_Data $object GetPaid_Data object.
233
-	 * @since 1.0.19
234
-	 */
235
-	protected function update_post_meta( &$object ) {
236
-
237
-		$updated_props   = array();
238
-		$props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
239
-		$object_type     = $object->get_object_type();
240
-
241
-		foreach ( $props_to_update as $meta_key => $prop ) {
242
-			$value = $object->{"get_$prop"}( 'edit' );
243
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
244
-
245
-			$updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
246
-
247
-			if ( $updated ) {
248
-				$updated_props[] = $prop;
249
-			}
250
-		}
251
-
252
-		do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
253
-	}
254
-
255
-	/**
256
-	 * Update meta data in, or delete it from, the database.
257
-	 *
258
-	 * Avoids storing meta when it's either an empty string or empty array or null.
259
-	 * Other empty values such as numeric 0 should still be stored.
260
-	 * Data-stores can force meta to exist using `must_exist_meta_keys`.
261
-	 *
262
-	 * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
263
-	 *
264
-	 * @param GetPaid_Data $object The GetPaid_Data object.
265
-	 * @param string  $meta_key Meta key to update.
266
-	 * @param mixed   $meta_value Value to save.
267
-	 *
268
-	 * @since 1.0.19 Added to prevent empty meta being stored unless required.
269
-	 *
270
-	 * @return bool True if updated/deleted.
271
-	 */
272
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
275
-		} else {
276
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
277
-		}
278
-
279
-		return (bool) $updated;
280
-	}
281
-
282
-	/**
283
-	 * Return list of internal meta keys.
284
-	 *
285
-	 * @since 1.0.19
286
-	 * @return array
287
-	 */
288
-	public function get_internal_meta_keys() {
289
-		return $this->internal_meta_keys;
290
-	}
291
-
292
-	/**
293
-	 * Clear any caches.
294
-	 *
295
-	 * @param GetPaid_Data $object GetPaid_Data object.
296
-	 * @since 1.0.19
297
-	 */
298
-	protected function clear_caches( &$object ) {
299
-		clean_post_cache( $object->get_id() );
300
-	}
301
-
302
-	/**
303
-	 * Method to delete a data object from the database.
304
-	 *
305
-	 * @param GetPaid_Data $object GetPaid_Data object.
306
-	 * @param array    $args Array of args to pass to the delete method.
307
-	 *
308
-	 * @return void
309
-	 */
310
-	public function delete( &$object, $args = array() ) {
311
-		$id          = $object->get_id();
312
-		$object_type = $object->get_object_type();
313
-
314
-		if ( 'invoice' == $object_type ) {
315
-			$object_type = $object->get_type();
316
-		}
317
-
318
-		$args        = wp_parse_args(
319
-			$args,
320
-			array(
321
-				'force_delete' => false,
322
-			)
323
-		);
324
-
325
-		if ( ! $id ) {
326
-			return;
327
-		}
328
-
329
-		if ( $args['force_delete'] ) {
330
-			wp_delete_post( $id, true );
331
-			$object->set_id( 0 );
332
-			do_action( "getpaid_delete_$object_type", $id );
333
-		} else {
334
-			wp_trash_post( $id );
335
-			$object->set_status( 'trash' );
336
-			do_action( "getpaid_trash_$object_type", $id );
337
-		}
338
-	}
339
-
340
-	/**
341
-	 * Get the status to save to the post object.
342
-	 *
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  GetPaid_Data $object GetPaid_Data object.
346
-	 * @return string
347
-	 */
348
-	protected function get_post_status( $object ) {
349
-		$object_status = $object->get_status( 'edit' );
350
-		$object_type   = $object->get_object_type();
351
-
352
-		if ( ! $object_status ) {
353
-			$object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
354
-		}
355
-
356
-		return $object_status;
357
-	}
76
+                $object->get_id()
77
+            )
78
+        );
79
+
80
+        $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
+        $meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
+        return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
83
+    }
84
+
85
+    /**
86
+     * Deletes meta based on meta ID.
87
+     *
88
+     * @since  1.0.19
89
+     * @param  GetPaid_Data  $object GetPaid_Data object.
90
+     * @param  stdClass $meta (containing at least ->id).
91
+     */
92
+    public function delete_meta( &$object, $meta ) {
93
+        delete_metadata_by_mid( $this->meta_type, $meta->id );
94
+    }
95
+
96
+    /**
97
+     * Add new piece of meta.
98
+     *
99
+     * @since  1.0.19
100
+     * @param  GetPaid_Data  $object GetPaid_Data object.
101
+     * @param  stdClass $meta (containing ->key and ->value).
102
+     * @return int meta ID
103
+     */
104
+    public function add_meta( &$object, $meta ) {
105
+        return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
106
+    }
107
+
108
+    /**
109
+     * Update meta.
110
+     *
111
+     * @since  1.0.19
112
+     * @param  GetPaid_Data  $object GetPaid_Data object.
113
+     * @param  stdClass $meta (containing ->id, ->key and ->value).
114
+     */
115
+    public function update_meta( &$object, $meta ) {
116
+        update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
117
+    }
118
+
119
+    /**
120
+     * Table structure is slightly different between meta types, this function will return what we need to know.
121
+     *
122
+     * @since  1.0.19
123
+     * @return array Array elements: table, object_id_field, meta_id_field
124
+     */
125
+    protected function get_db_info() {
126
+        global $wpdb;
127
+
128
+        $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well.
129
+        $table         = $wpdb->prefix;
130
+
131
+        // If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
+        if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
133
+            $table .= 'getpaid_';
134
+        }
135
+
136
+        $table          .= $this->meta_type . 'meta';
137
+        $object_id_field = $this->meta_type . '_id';
138
+
139
+        // Figure out our field names.
140
+        if ( 'user' === $this->meta_type ) {
141
+            $meta_id_field = 'umeta_id';
142
+            $table         = $wpdb->usermeta;
143
+        }
144
+
145
+        if ( ! empty( $this->object_id_field_for_meta ) ) {
146
+            $object_id_field = $this->object_id_field_for_meta;
147
+        }
148
+
149
+        return array(
150
+            'table'           => $table,
151
+            'object_id_field' => $object_id_field,
152
+            'meta_id_field'   => $meta_id_field,
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Internal meta keys we don't want exposed as part of meta_data. This is in
158
+     * addition to all data props with _ prefix.
159
+     *
160
+     * @since 1.0.19
161
+     *
162
+     * @param string $key Prefix to be added to meta keys.
163
+     * @return string
164
+     */
165
+    protected function prefix_key( $key ) {
166
+        return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
167
+    }
168
+
169
+    /**
170
+     * Callback to remove unwanted meta data.
171
+     *
172
+     * @param object $meta Meta object to check if it should be excluded or not.
173
+     * @return bool
174
+     */
175
+    protected function exclude_internal_meta_keys( $meta ) {
176
+        return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
177
+    }
178
+
179
+    /**
180
+     * Gets a list of props and meta keys that need updated based on change state
181
+     * or if they are present in the database or not.
182
+     *
183
+     * @param  GetPaid_Data $object         The GetPaid_Data object.
184
+     * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
185
+     * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186
+     * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187
+     */
188
+    protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
189
+        $props_to_update = array();
190
+        $changed_props   = $object->get_changes();
191
+
192
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
193
+        foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
+            if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
+                $props_to_update[ $meta_key ] = $prop;
196
+            }
197
+        }
198
+
199
+        return $props_to_update;
200
+    }
201
+
202
+    /**
203
+     * Read object data.
204
+     *
205
+     * @param GetPaid_Data $object GetPaid_Data object.
206
+     * @param WP_Post   $post_object Post object.
207
+     * @since 1.0.19
208
+     */
209
+    protected function read_object_data( &$object, $post_object ) {
210
+        $id    = $object->get_id();
211
+        $props = array();
212
+
213
+        foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
+            $props[ $prop ] = get_post_meta( $id, $meta_key, true );
215
+        }
216
+
217
+        // Set object properties.
218
+        $object->set_props( $props );
219
+
220
+        // Gets extra data associated with the object if needed.
221
+        foreach ( $object->get_extra_data_keys() as $key ) {
222
+            $function = 'set_' . $key;
223
+            if ( is_callable( array( $object, $function ) ) ) {
224
+                $object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
225
+            }
226
+        }
227
+    }
228
+
229
+    /**
230
+     * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class.
231
+     *
232
+     * @param GetPaid_Data $object GetPaid_Data object.
233
+     * @since 1.0.19
234
+     */
235
+    protected function update_post_meta( &$object ) {
236
+
237
+        $updated_props   = array();
238
+        $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
239
+        $object_type     = $object->get_object_type();
240
+
241
+        foreach ( $props_to_update as $meta_key => $prop ) {
242
+            $value = $object->{"get_$prop"}( 'edit' );
243
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
244
+
245
+            $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
246
+
247
+            if ( $updated ) {
248
+                $updated_props[] = $prop;
249
+            }
250
+        }
251
+
252
+        do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
253
+    }
254
+
255
+    /**
256
+     * Update meta data in, or delete it from, the database.
257
+     *
258
+     * Avoids storing meta when it's either an empty string or empty array or null.
259
+     * Other empty values such as numeric 0 should still be stored.
260
+     * Data-stores can force meta to exist using `must_exist_meta_keys`.
261
+     *
262
+     * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
263
+     *
264
+     * @param GetPaid_Data $object The GetPaid_Data object.
265
+     * @param string  $meta_key Meta key to update.
266
+     * @param mixed   $meta_value Value to save.
267
+     *
268
+     * @since 1.0.19 Added to prevent empty meta being stored unless required.
269
+     *
270
+     * @return bool True if updated/deleted.
271
+     */
272
+    protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
+        if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
+            $updated = delete_post_meta( $object->get_id(), $meta_key );
275
+        } else {
276
+            $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
277
+        }
278
+
279
+        return (bool) $updated;
280
+    }
281
+
282
+    /**
283
+     * Return list of internal meta keys.
284
+     *
285
+     * @since 1.0.19
286
+     * @return array
287
+     */
288
+    public function get_internal_meta_keys() {
289
+        return $this->internal_meta_keys;
290
+    }
291
+
292
+    /**
293
+     * Clear any caches.
294
+     *
295
+     * @param GetPaid_Data $object GetPaid_Data object.
296
+     * @since 1.0.19
297
+     */
298
+    protected function clear_caches( &$object ) {
299
+        clean_post_cache( $object->get_id() );
300
+    }
301
+
302
+    /**
303
+     * Method to delete a data object from the database.
304
+     *
305
+     * @param GetPaid_Data $object GetPaid_Data object.
306
+     * @param array    $args Array of args to pass to the delete method.
307
+     *
308
+     * @return void
309
+     */
310
+    public function delete( &$object, $args = array() ) {
311
+        $id          = $object->get_id();
312
+        $object_type = $object->get_object_type();
313
+
314
+        if ( 'invoice' == $object_type ) {
315
+            $object_type = $object->get_type();
316
+        }
317
+
318
+        $args        = wp_parse_args(
319
+            $args,
320
+            array(
321
+                'force_delete' => false,
322
+            )
323
+        );
324
+
325
+        if ( ! $id ) {
326
+            return;
327
+        }
328
+
329
+        if ( $args['force_delete'] ) {
330
+            wp_delete_post( $id, true );
331
+            $object->set_id( 0 );
332
+            do_action( "getpaid_delete_$object_type", $id );
333
+        } else {
334
+            wp_trash_post( $id );
335
+            $object->set_status( 'trash' );
336
+            do_action( "getpaid_trash_$object_type", $id );
337
+        }
338
+    }
339
+
340
+    /**
341
+     * Get the status to save to the post object.
342
+     *
343
+     *
344
+     * @since 1.0.19
345
+     * @param  GetPaid_Data $object GetPaid_Data object.
346
+     * @return string
347
+     */
348
+    protected function get_post_status( $object ) {
349
+        $object_status = $object->get_status( 'edit' );
350
+        $object_type   = $object->get_object_type();
351
+
352
+        if ( ! $object_status ) {
353
+            $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
354
+        }
355
+
356
+        return $object_status;
357
+    }
358 358
 
359 359
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.19
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Data_Store_WP class.
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param  GetPaid_Data $object GetPaid_Data object.
65 65
 	 * @return array
66 66
 	 */
67
-	public function read_meta( &$object ) {
67
+	public function read_meta(&$object) {
68 68
 		global $wpdb;
69 69
 		$db_info       = $this->get_db_info();
70 70
 		$raw_meta_data = $wpdb->get_results(
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 			)
78 78
 		);
79 79
 
80
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
80
+		$this->internal_meta_keys = array_merge(array_map(array($this, 'prefix_key'), $object->get_data_keys()), $this->internal_meta_keys);
81
+		$meta_data                = array_filter($raw_meta_data, array($this, 'exclude_internal_meta_keys'));
82
+		return apply_filters("getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this);
83 83
 	}
84 84
 
85 85
 	/**
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
90 90
 	 * @param  stdClass $meta (containing at least ->id).
91 91
 	 */
92
-	public function delete_meta( &$object, $meta ) {
93
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
92
+	public function delete_meta(&$object, $meta) {
93
+		delete_metadata_by_mid($this->meta_type, $meta->id);
94 94
 	}
95 95
 
96 96
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @param  stdClass $meta (containing ->key and ->value).
102 102
 	 * @return int meta ID
103 103
 	 */
104
-	public function add_meta( &$object, $meta ) {
105
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
104
+	public function add_meta(&$object, $meta) {
105
+		return add_metadata($this->meta_type, $object->get_id(), $meta->key, is_string($meta->value) ? wp_slash($meta->value) : $meta->value, false);
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
113 113
 	 * @param  stdClass $meta (containing ->id, ->key and ->value).
114 114
 	 */
115
-	public function update_meta( &$object, $meta ) {
116
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
115
+	public function update_meta(&$object, $meta) {
116
+		update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key);
117 117
 	}
118 118
 
119 119
 	/**
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$table         = $wpdb->prefix;
130 130
 
131 131
 		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
132
+		if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) {
133 133
 			$table .= 'getpaid_';
134 134
 		}
135 135
 
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 		$object_id_field = $this->meta_type . '_id';
138 138
 
139 139
 		// Figure out our field names.
140
-		if ( 'user' === $this->meta_type ) {
140
+		if ('user' === $this->meta_type) {
141 141
 			$meta_id_field = 'umeta_id';
142 142
 			$table         = $wpdb->usermeta;
143 143
 		}
144 144
 
145
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
145
+		if (!empty($this->object_id_field_for_meta)) {
146 146
 			$object_id_field = $this->object_id_field_for_meta;
147 147
 		}
148 148
 
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	 * @param string $key Prefix to be added to meta keys.
163 163
 	 * @return string
164 164
 	 */
165
-	protected function prefix_key( $key ) {
166
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
165
+	protected function prefix_key($key) {
166
+		return '_' === substr($key, 0, 1) ? $key : '_' . $key;
167 167
 	}
168 168
 
169 169
 	/**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	 * @param object $meta Meta object to check if it should be excluded or not.
173 173
 	 * @return bool
174 174
 	 */
175
-	protected function exclude_internal_meta_keys( $meta ) {
176
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
175
+	protected function exclude_internal_meta_keys($meta) {
176
+		return !in_array($meta->meta_key, $this->internal_meta_keys, true) && 0 !== stripos($meta->meta_key, 'wp_');
177 177
 	}
178 178
 
179 179
 	/**
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
 	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186 186
 	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187 187
 	 */
188
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
188
+	protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') {
189 189
 		$props_to_update = array();
190 190
 		$changed_props   = $object->get_changes();
191 191
 
192 192
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
193
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
-				$props_to_update[ $meta_key ] = $prop;
193
+		foreach ($meta_key_to_props as $meta_key => $prop) {
194
+			if (array_key_exists($prop, $changed_props) || !metadata_exists($meta_type, $object->get_id(), $meta_key)) {
195
+				$props_to_update[$meta_key] = $prop;
196 196
 			}
197 197
 		}
198 198
 
@@ -206,22 +206,22 @@  discard block
 block discarded – undo
206 206
 	 * @param WP_Post   $post_object Post object.
207 207
 	 * @since 1.0.19
208 208
 	 */
209
-	protected function read_object_data( &$object, $post_object ) {
209
+	protected function read_object_data(&$object, $post_object) {
210 210
 		$id    = $object->get_id();
211 211
 		$props = array();
212 212
 
213
-		foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
-			$props[ $prop ] = get_post_meta( $id, $meta_key, true );
213
+		foreach ($this->meta_key_to_props as $meta_key => $prop) {
214
+			$props[$prop] = get_post_meta($id, $meta_key, true);
215 215
 		}
216 216
 
217 217
 		// Set object properties.
218
-		$object->set_props( $props );
218
+		$object->set_props($props);
219 219
 
220 220
 		// Gets extra data associated with the object if needed.
221
-		foreach ( $object->get_extra_data_keys() as $key ) {
221
+		foreach ($object->get_extra_data_keys() as $key) {
222 222
 			$function = 'set_' . $key;
223
-			if ( is_callable( array( $object, $function ) ) ) {
224
-				$object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
223
+			if (is_callable(array($object, $function))) {
224
+				$object->{$function}(get_post_meta($object->get_id(), $key, true));
225 225
 			}
226 226
 		}
227 227
 	}
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
 	 * @param GetPaid_Data $object GetPaid_Data object.
233 233
 	 * @since 1.0.19
234 234
 	 */
235
-	protected function update_post_meta( &$object ) {
235
+	protected function update_post_meta(&$object) {
236 236
 
237 237
 		$updated_props   = array();
238
-		$props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
238
+		$props_to_update = $this->get_props_to_update($object, $this->meta_key_to_props);
239 239
 		$object_type     = $object->get_object_type();
240 240
 
241
-		foreach ( $props_to_update as $meta_key => $prop ) {
242
-			$value = $object->{"get_$prop"}( 'edit' );
243
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
241
+		foreach ($props_to_update as $meta_key => $prop) {
242
+			$value = $object->{"get_$prop"}('edit');
243
+			$value = is_string($value) ? wp_slash($value) : $value;
244 244
 
245
-			$updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
245
+			$updated = $this->update_or_delete_post_meta($object, $meta_key, $value);
246 246
 
247
-			if ( $updated ) {
247
+			if ($updated) {
248 248
 				$updated_props[] = $prop;
249 249
 			}
250 250
 		}
251 251
 
252
-		do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
252
+		do_action("getpaid_{$object_type}_object_updated_props", $object, $updated_props);
253 253
 	}
254 254
 
255 255
 	/**
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return bool True if updated/deleted.
271 271
 	 */
272
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
272
+	protected function update_or_delete_post_meta($object, $meta_key, $meta_value) {
273
+		if (in_array($meta_value, array(array(), '', null), true) && !in_array($meta_key, $this->must_exist_meta_keys, true)) {
274
+			$updated = delete_post_meta($object->get_id(), $meta_key);
275 275
 		} else {
276
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
276
+			$updated = update_post_meta($object->get_id(), $meta_key, $meta_value);
277 277
 		}
278 278
 
279 279
 		return (bool) $updated;
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param GetPaid_Data $object GetPaid_Data object.
296 296
 	 * @since 1.0.19
297 297
 	 */
298
-	protected function clear_caches( &$object ) {
299
-		clean_post_cache( $object->get_id() );
298
+	protected function clear_caches(&$object) {
299
+		clean_post_cache($object->get_id());
300 300
 	}
301 301
 
302 302
 	/**
@@ -307,33 +307,33 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @return void
309 309
 	 */
310
-	public function delete( &$object, $args = array() ) {
310
+	public function delete(&$object, $args = array()) {
311 311
 		$id          = $object->get_id();
312 312
 		$object_type = $object->get_object_type();
313 313
 
314
-		if ( 'invoice' == $object_type ) {
314
+		if ('invoice' == $object_type) {
315 315
 			$object_type = $object->get_type();
316 316
 		}
317 317
 
318
-		$args        = wp_parse_args(
318
+		$args = wp_parse_args(
319 319
 			$args,
320 320
 			array(
321 321
 				'force_delete' => false,
322 322
 			)
323 323
 		);
324 324
 
325
-		if ( ! $id ) {
325
+		if (!$id) {
326 326
 			return;
327 327
 		}
328 328
 
329
-		if ( $args['force_delete'] ) {
330
-			wp_delete_post( $id, true );
331
-			$object->set_id( 0 );
332
-			do_action( "getpaid_delete_$object_type", $id );
329
+		if ($args['force_delete']) {
330
+			wp_delete_post($id, true);
331
+			$object->set_id(0);
332
+			do_action("getpaid_delete_$object_type", $id);
333 333
 		} else {
334
-			wp_trash_post( $id );
335
-			$object->set_status( 'trash' );
336
-			do_action( "getpaid_trash_$object_type", $id );
334
+			wp_trash_post($id);
335
+			$object->set_status('trash');
336
+			do_action("getpaid_trash_$object_type", $id);
337 337
 		}
338 338
 	}
339 339
 
@@ -345,12 +345,12 @@  discard block
 block discarded – undo
345 345
 	 * @param  GetPaid_Data $object GetPaid_Data object.
346 346
 	 * @return string
347 347
 	 */
348
-	protected function get_post_status( $object ) {
349
-		$object_status = $object->get_status( 'edit' );
348
+	protected function get_post_status($object) {
349
+		$object_status = $object->get_status('edit');
350 350
 		$object_type   = $object->get_object_type();
351 351
 
352
-		if ( ! $object_status ) {
353
-			$object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
352
+		if (!$object_status) {
353
+			$object_status = apply_filters("getpaid_default_{$object_type}_status", 'draft');
354 354
 		}
355 355
 
356 356
 		return $object_status;
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-discount-data-store.php 2 patches
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,195 +15,195 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Discount_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpi_discount_code',
26
-		'_wpi_discount_amount',
27
-		'_wpi_discount_start',
28
-		'_wpi_discount_expiration',
29
-		'_wpi_discount_type',
30
-		'_wpi_discount_uses',
31
-		'_wpi_discount_is_single_use',
32
-		'_wpi_discount_items',
33
-		'_wpi_discount_excluded_items',
34
-		'_wpi_discount_max_uses',
35
-		'_wpi_discount_is_recurring',
36
-		'_wpi_discount_min_total',
37
-		'_wpi_discount_max_total',
38
-	);
39
-
40
-	/**
41
-	 * A map of meta keys to data props.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $meta_key_to_props = array(
48
-		'_wpi_discount_code'           => 'code',
49
-		'_wpi_discount_amount'         => 'amount',
50
-		'_wpi_discount_start'          => 'start',
51
-		'_wpi_discount_expiration'     => 'expiration',
52
-		'_wpi_discount_type'           => 'type',
53
-		'_wpi_discount_uses'           => 'uses',
54
-		'_wpi_discount_is_single_use'  => 'is_single_use',
55
-		'_wpi_discount_items'          => 'items',
56
-		'_wpi_discount_excluded_items' => 'excluded_items',
57
-		'_wpi_discount_max_uses'       => 'max_uses',
58
-		'_wpi_discount_is_recurring'   => 'is_recurring',
59
-		'_wpi_discount_min_total'      => 'min_total',
60
-		'_wpi_discount_max_total'      => 'max_total',
61
-	);
62
-
63
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpi_discount_code',
26
+        '_wpi_discount_amount',
27
+        '_wpi_discount_start',
28
+        '_wpi_discount_expiration',
29
+        '_wpi_discount_type',
30
+        '_wpi_discount_uses',
31
+        '_wpi_discount_is_single_use',
32
+        '_wpi_discount_items',
33
+        '_wpi_discount_excluded_items',
34
+        '_wpi_discount_max_uses',
35
+        '_wpi_discount_is_recurring',
36
+        '_wpi_discount_min_total',
37
+        '_wpi_discount_max_total',
38
+    );
39
+
40
+    /**
41
+     * A map of meta keys to data props.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $meta_key_to_props = array(
48
+        '_wpi_discount_code'           => 'code',
49
+        '_wpi_discount_amount'         => 'amount',
50
+        '_wpi_discount_start'          => 'start',
51
+        '_wpi_discount_expiration'     => 'expiration',
52
+        '_wpi_discount_type'           => 'type',
53
+        '_wpi_discount_uses'           => 'uses',
54
+        '_wpi_discount_is_single_use'  => 'is_single_use',
55
+        '_wpi_discount_items'          => 'items',
56
+        '_wpi_discount_excluded_items' => 'excluded_items',
57
+        '_wpi_discount_max_uses'       => 'max_uses',
58
+        '_wpi_discount_is_recurring'   => 'is_recurring',
59
+        '_wpi_discount_min_total'      => 'min_total',
60
+        '_wpi_discount_max_total'      => 'max_total',
61
+    );
62
+
63
+    /*
64 64
 	|--------------------------------------------------------------------------
65 65
 	| CRUD Methods
66 66
 	|--------------------------------------------------------------------------
67 67
 	*/
68 68
 
69
-	/**
70
-	 * Method to create a new discount in the database.
71
-	 *
72
-	 * @param WPInv_Discount $discount Discount object.
73
-	 */
74
-	public function create( &$discount ) {
75
-		$discount->set_version( WPINV_VERSION );
76
-		$discount->set_date_created( current_time('mysql') );
77
-
78
-		// Create a new post.
79
-		$id = wp_insert_post(
80
-			apply_filters(
81
-				'getpaid_new_discount_data',
82
-				array(
83
-					'post_date'     => $discount->get_date_created( 'edit' ),
84
-					'post_type'     => 'wpi_discount',
85
-					'post_status'   => $this->get_post_status( $discount ),
86
-					'ping_status'   => 'closed',
87
-					'post_author'   => $discount->get_author( 'edit' ),
88
-					'post_title'    => $discount->get_name( 'edit' ),
89
-					'post_excerpt'  => $discount->get_description( 'edit' ),
90
-				)
91
-			),
92
-			true
93
-		);
94
-
95
-		if ( $id && ! is_wp_error( $id ) ) {
96
-			$discount->set_id( $id );
97
-			$this->update_post_meta( $discount );
98
-			$discount->save_meta_data();
99
-			$discount->apply_changes();
100
-			$this->clear_caches( $discount );
101
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
102
-			return true;
103
-		}
104
-
105
-		if ( is_wp_error( $id ) ) {
106
-			$discount->last_error = $id->get_error_message();
107
-		}
108
-
109
-		return false;
110
-	}
111
-
112
-	/**
113
-	 * Method to read a discount from the database.
114
-	 *
115
-	 * @param WPInv_Discount $discount Discount object.
116
-	 *
117
-	 */
118
-	public function read( &$discount ) {
119
-
120
-		$discount->set_defaults();
121
-		$discount_object = get_post( $discount->get_id() );
122
-
123
-		if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
-			$discount->last_error = __( 'Invalid discount.', 'invoicing' );
125
-			return false;
126
-		}
127
-
128
-		$discount->set_props(
129
-			array(
130
-				'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
131
-				'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
132
-				'status'        => $discount_object->post_status,
133
-				'name'          => $discount_object->post_title,
134
-				'author'        => $discount_object->post_author,
135
-				'description'   => $discount_object->post_excerpt,
136
-			)
137
-		);
138
-
139
-		$this->read_object_data( $discount, $discount_object );
140
-		$discount->read_meta_data();
141
-		$discount->set_object_read( true );
142
-		do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
143
-
144
-	}
145
-
146
-	/**
147
-	 * Method to update a discount in the database.
148
-	 *
149
-	 * @param WPInv_Discount $discount Discount object.
150
-	 */
151
-	public function update( &$discount ) {
152
-		$discount->save_meta_data();
153
-		$discount->set_version( WPINV_VERSION );
154
-
155
-		if ( null === $discount->get_date_created( 'edit' ) ) {
156
-			$discount->set_date_created(  current_time('mysql') );
157
-		}
158
-
159
-		// Grab the current status so we can compare.
160
-		$previous_status = get_post_status( $discount->get_id() );
161
-
162
-		$changes = $discount->get_changes();
163
-
164
-		// Only update the post when the post data changes.
165
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
166
-			$post_data = array(
167
-				'post_date'         => $discount->get_date_created( 'edit' ),
168
-				'post_status'       => $discount->get_status( 'edit' ),
169
-				'post_title'        => $discount->get_name( 'edit' ),
170
-				'post_author'       => $discount->get_author( 'edit' ),
171
-				'post_modified'     => $discount->get_date_modified( 'edit' ),
172
-				'post_excerpt'      => $discount->get_description( 'edit' ),
173
-			);
174
-
175
-			/**
176
-			 * When updating this object, to prevent infinite loops, use $wpdb
177
-			 * to update data, since wp_update_post spawns more calls to the
178
-			 * save_post action.
179
-			 *
180
-			 * This ensures hooks are fired by either WP itself (admin screen save),
181
-			 * or an update purely from CRUD.
182
-			 */
183
-			if ( doing_action( 'save_post' ) ) {
184
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
185
-				clean_post_cache( $discount->get_id() );
186
-			} else {
187
-				wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
188
-			}
189
-			$discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
190
-		}
191
-		$this->update_post_meta( $discount );
192
-		$discount->apply_changes();
193
-		$this->clear_caches( $discount );
194
-
195
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
-		$new_status = $discount->get_status( 'edit' );
197
-
198
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
200
-		} else {
201
-			do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
202
-		}
203
-
204
-	}
205
-
206
-	/*
69
+    /**
70
+     * Method to create a new discount in the database.
71
+     *
72
+     * @param WPInv_Discount $discount Discount object.
73
+     */
74
+    public function create( &$discount ) {
75
+        $discount->set_version( WPINV_VERSION );
76
+        $discount->set_date_created( current_time('mysql') );
77
+
78
+        // Create a new post.
79
+        $id = wp_insert_post(
80
+            apply_filters(
81
+                'getpaid_new_discount_data',
82
+                array(
83
+                    'post_date'     => $discount->get_date_created( 'edit' ),
84
+                    'post_type'     => 'wpi_discount',
85
+                    'post_status'   => $this->get_post_status( $discount ),
86
+                    'ping_status'   => 'closed',
87
+                    'post_author'   => $discount->get_author( 'edit' ),
88
+                    'post_title'    => $discount->get_name( 'edit' ),
89
+                    'post_excerpt'  => $discount->get_description( 'edit' ),
90
+                )
91
+            ),
92
+            true
93
+        );
94
+
95
+        if ( $id && ! is_wp_error( $id ) ) {
96
+            $discount->set_id( $id );
97
+            $this->update_post_meta( $discount );
98
+            $discount->save_meta_data();
99
+            $discount->apply_changes();
100
+            $this->clear_caches( $discount );
101
+            do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
102
+            return true;
103
+        }
104
+
105
+        if ( is_wp_error( $id ) ) {
106
+            $discount->last_error = $id->get_error_message();
107
+        }
108
+
109
+        return false;
110
+    }
111
+
112
+    /**
113
+     * Method to read a discount from the database.
114
+     *
115
+     * @param WPInv_Discount $discount Discount object.
116
+     *
117
+     */
118
+    public function read( &$discount ) {
119
+
120
+        $discount->set_defaults();
121
+        $discount_object = get_post( $discount->get_id() );
122
+
123
+        if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
+            $discount->last_error = __( 'Invalid discount.', 'invoicing' );
125
+            return false;
126
+        }
127
+
128
+        $discount->set_props(
129
+            array(
130
+                'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
131
+                'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
132
+                'status'        => $discount_object->post_status,
133
+                'name'          => $discount_object->post_title,
134
+                'author'        => $discount_object->post_author,
135
+                'description'   => $discount_object->post_excerpt,
136
+            )
137
+        );
138
+
139
+        $this->read_object_data( $discount, $discount_object );
140
+        $discount->read_meta_data();
141
+        $discount->set_object_read( true );
142
+        do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
143
+
144
+    }
145
+
146
+    /**
147
+     * Method to update a discount in the database.
148
+     *
149
+     * @param WPInv_Discount $discount Discount object.
150
+     */
151
+    public function update( &$discount ) {
152
+        $discount->save_meta_data();
153
+        $discount->set_version( WPINV_VERSION );
154
+
155
+        if ( null === $discount->get_date_created( 'edit' ) ) {
156
+            $discount->set_date_created(  current_time('mysql') );
157
+        }
158
+
159
+        // Grab the current status so we can compare.
160
+        $previous_status = get_post_status( $discount->get_id() );
161
+
162
+        $changes = $discount->get_changes();
163
+
164
+        // Only update the post when the post data changes.
165
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
166
+            $post_data = array(
167
+                'post_date'         => $discount->get_date_created( 'edit' ),
168
+                'post_status'       => $discount->get_status( 'edit' ),
169
+                'post_title'        => $discount->get_name( 'edit' ),
170
+                'post_author'       => $discount->get_author( 'edit' ),
171
+                'post_modified'     => $discount->get_date_modified( 'edit' ),
172
+                'post_excerpt'      => $discount->get_description( 'edit' ),
173
+            );
174
+
175
+            /**
176
+             * When updating this object, to prevent infinite loops, use $wpdb
177
+             * to update data, since wp_update_post spawns more calls to the
178
+             * save_post action.
179
+             *
180
+             * This ensures hooks are fired by either WP itself (admin screen save),
181
+             * or an update purely from CRUD.
182
+             */
183
+            if ( doing_action( 'save_post' ) ) {
184
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
185
+                clean_post_cache( $discount->get_id() );
186
+            } else {
187
+                wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
188
+            }
189
+            $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
190
+        }
191
+        $this->update_post_meta( $discount );
192
+        $discount->apply_changes();
193
+        $this->clear_caches( $discount );
194
+
195
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
+        $new_status = $discount->get_status( 'edit' );
197
+
198
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
+            do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
200
+        } else {
201
+            do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
202
+        }
203
+
204
+    }
205
+
206
+    /*
207 207
 	|--------------------------------------------------------------------------
208 208
 	| Additional Methods
209 209
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Discount_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -71,38 +71,38 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @param WPInv_Discount $discount Discount object.
73 73
 	 */
74
-	public function create( &$discount ) {
75
-		$discount->set_version( WPINV_VERSION );
76
-		$discount->set_date_created( current_time('mysql') );
74
+	public function create(&$discount) {
75
+		$discount->set_version(WPINV_VERSION);
76
+		$discount->set_date_created(current_time('mysql'));
77 77
 
78 78
 		// Create a new post.
79 79
 		$id = wp_insert_post(
80 80
 			apply_filters(
81 81
 				'getpaid_new_discount_data',
82 82
 				array(
83
-					'post_date'     => $discount->get_date_created( 'edit' ),
83
+					'post_date'     => $discount->get_date_created('edit'),
84 84
 					'post_type'     => 'wpi_discount',
85
-					'post_status'   => $this->get_post_status( $discount ),
85
+					'post_status'   => $this->get_post_status($discount),
86 86
 					'ping_status'   => 'closed',
87
-					'post_author'   => $discount->get_author( 'edit' ),
88
-					'post_title'    => $discount->get_name( 'edit' ),
89
-					'post_excerpt'  => $discount->get_description( 'edit' ),
87
+					'post_author'   => $discount->get_author('edit'),
88
+					'post_title'    => $discount->get_name('edit'),
89
+					'post_excerpt'  => $discount->get_description('edit'),
90 90
 				)
91 91
 			),
92 92
 			true
93 93
 		);
94 94
 
95
-		if ( $id && ! is_wp_error( $id ) ) {
96
-			$discount->set_id( $id );
97
-			$this->update_post_meta( $discount );
95
+		if ($id && !is_wp_error($id)) {
96
+			$discount->set_id($id);
97
+			$this->update_post_meta($discount);
98 98
 			$discount->save_meta_data();
99 99
 			$discount->apply_changes();
100
-			$this->clear_caches( $discount );
101
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
100
+			$this->clear_caches($discount);
101
+			do_action('getpaid_new_discount', $discount->get_id(), $discount);
102 102
 			return true;
103 103
 		}
104 104
 
105
-		if ( is_wp_error( $id ) ) {
105
+		if (is_wp_error($id)) {
106 106
 			$discount->last_error = $id->get_error_message();
107 107
 		}
108 108
 
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	 * @param WPInv_Discount $discount Discount object.
116 116
 	 *
117 117
 	 */
118
-	public function read( &$discount ) {
118
+	public function read(&$discount) {
119 119
 
120 120
 		$discount->set_defaults();
121
-		$discount_object = get_post( $discount->get_id() );
121
+		$discount_object = get_post($discount->get_id());
122 122
 
123
-		if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
-			$discount->last_error = __( 'Invalid discount.', 'invoicing' );
123
+		if (!$discount->get_id() || !$discount_object || $discount_object->post_type != 'wpi_discount') {
124
+			$discount->last_error = __('Invalid discount.', 'invoicing');
125 125
 			return false;
126 126
 		}
127 127
 
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 			)
137 137
 		);
138 138
 
139
-		$this->read_object_data( $discount, $discount_object );
139
+		$this->read_object_data($discount, $discount_object);
140 140
 		$discount->read_meta_data();
141
-		$discount->set_object_read( true );
142
-		do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
141
+		$discount->set_object_read(true);
142
+		do_action('getpaid_read_discount', $discount->get_id(), $discount);
143 143
 
144 144
 	}
145 145
 
@@ -148,28 +148,28 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @param WPInv_Discount $discount Discount object.
150 150
 	 */
151
-	public function update( &$discount ) {
151
+	public function update(&$discount) {
152 152
 		$discount->save_meta_data();
153
-		$discount->set_version( WPINV_VERSION );
153
+		$discount->set_version(WPINV_VERSION);
154 154
 
155
-		if ( null === $discount->get_date_created( 'edit' ) ) {
156
-			$discount->set_date_created(  current_time('mysql') );
155
+		if (null === $discount->get_date_created('edit')) {
156
+			$discount->set_date_created(current_time('mysql'));
157 157
 		}
158 158
 
159 159
 		// Grab the current status so we can compare.
160
-		$previous_status = get_post_status( $discount->get_id() );
160
+		$previous_status = get_post_status($discount->get_id());
161 161
 
162 162
 		$changes = $discount->get_changes();
163 163
 
164 164
 		// Only update the post when the post data changes.
165
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
165
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) {
166 166
 			$post_data = array(
167
-				'post_date'         => $discount->get_date_created( 'edit' ),
168
-				'post_status'       => $discount->get_status( 'edit' ),
169
-				'post_title'        => $discount->get_name( 'edit' ),
170
-				'post_author'       => $discount->get_author( 'edit' ),
171
-				'post_modified'     => $discount->get_date_modified( 'edit' ),
172
-				'post_excerpt'      => $discount->get_description( 'edit' ),
167
+				'post_date'         => $discount->get_date_created('edit'),
168
+				'post_status'       => $discount->get_status('edit'),
169
+				'post_title'        => $discount->get_name('edit'),
170
+				'post_author'       => $discount->get_author('edit'),
171
+				'post_modified'     => $discount->get_date_modified('edit'),
172
+				'post_excerpt'      => $discount->get_description('edit'),
173 173
 			);
174 174
 
175 175
 			/**
@@ -180,25 +180,25 @@  discard block
 block discarded – undo
180 180
 			 * This ensures hooks are fired by either WP itself (admin screen save),
181 181
 			 * or an update purely from CRUD.
182 182
 			 */
183
-			if ( doing_action( 'save_post' ) ) {
184
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
185
-				clean_post_cache( $discount->get_id() );
183
+			if (doing_action('save_post')) {
184
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id()));
185
+				clean_post_cache($discount->get_id());
186 186
 			} else {
187
-				wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
187
+				wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data));
188 188
 			}
189
-			$discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
189
+			$discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
190 190
 		}
191
-		$this->update_post_meta( $discount );
191
+		$this->update_post_meta($discount);
192 192
 		$discount->apply_changes();
193
-		$this->clear_caches( $discount );
193
+		$this->clear_caches($discount);
194 194
 
195 195
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
-		$new_status = $discount->get_status( 'edit' );
196
+		$new_status = $discount->get_status('edit');
197 197
 
198
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
198
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
199
+			do_action('getpaid_new_discount', $discount->get_id(), $discount);
200 200
 		} else {
201
-			do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
201
+			do_action('getpaid_update_discount', $discount->get_id(), $discount);
202 202
 		}
203 203
 
204 204
 	}
Please login to merge, or discard this patch.