Passed
Push — master ( 7ebec5...2857a5 )
by Brian
12:31
created
includes/class-wpinv-db.php 1 patch
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -7,237 +7,237 @@
 block discarded – undo
7 7
 
8 8
 abstract class Wpinv_DB {
9 9
 
10
-	/**
11
-	 * The name of our database table
12
-	 *
13
-	 * @access  public
14
-	 * @since   1.0.0
15
-	 */
16
-	public $table_name;
17
-
18
-	/**
19
-	 * The version of our database table
20
-	 *
21
-	 * @access  public
22
-	 * @since   1.0.0
23
-	 */
24
-	public $version;
25
-
26
-	/**
27
-	 * The name of the primary column
28
-	 *
29
-	 * @access  public
30
-	 * @since   1.0.0
31
-	 */
32
-	public $primary_key;
33
-
34
-	/**
35
-	 * Get things started
36
-	 *
37
-	 * @access  public
38
-	 * @since   1.0.0
39
-	 */
40
-	public function __construct() {}
41
-
42
-	/**
43
-	 * Whitelist of columns
44
-	 *
45
-	 * @access  public
46
-	 * @since   1.0.0
47
-	 * @return  array
48
-	 */
49
-	public function get_columns() {
50
-		return array();
51
-	}
52
-
53
-	/**
54
-	 * Default column values
55
-	 *
56
-	 * @access  public
57
-	 * @since   1.0.0
58
-	 * @return  array
59
-	 */
60
-	public function get_column_defaults() {
61
-		return array();
62
-	}
63
-
64
-	/**
65
-	 * Retrieve a row by the primary key
66
-	 *
67
-	 * @access  public
68
-	 * @since   1.0.0
69
-	 * @return  object
70
-	 */
71
-	public function get( $row_id ) {
72
-		global $wpdb;
73
-		return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
74
-	}
75
-
76
-	/**
77
-	 * Retrieve a row by a specific column / value
78
-	 *
79
-	 * @access  public
80
-	 * @since   1.0.0
81
-	 * @return  object
82
-	 */
83
-	public function get_by( $column, $row_id ) {
84
-		global $wpdb;
85
-		$column = esc_sql( $column );
86
-		return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );
87
-	}
88
-
89
-	/**
90
-	 * Retrieve a specific column's value by the primary key
91
-	 *
92
-	 * @access  public
93
-	 * @since   1.0.0
94
-	 * @return  string
95
-	 */
96
-	public function get_column( $column, $row_id ) {
97
-		global $wpdb;
98
-		$column = esc_sql( $column );
99
-		return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
100
-	}
101
-
102
-	/**
103
-	 * Retrieve a specific column's value by the the specified column / value
104
-	 *
105
-	 * @access  public
106
-	 * @since   1.0.0
107
-	 * @return  string
108
-	 */
109
-	public function get_column_by( $column, $column_where, $column_value ) {
110
-		global $wpdb;
111
-		$column_where = esc_sql( $column_where );
112
-		$column       = esc_sql( $column );
113
-		return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );
114
-	}
115
-
116
-	/**
117
-	 * Insert a new row
118
-	 *
119
-	 * @access  public
120
-	 * @since   1.0.0
121
-	 * @return  int
122
-	 */
123
-	public function insert( $data, $type = '' ) {
124
-		global $wpdb;
125
-
126
-		// Set default values
127
-		$data = wp_parse_args( $data, $this->get_column_defaults() );
128
-
129
-		do_action( 'wpinv_pre_insert_' . $type, $data );
130
-
131
-		// Initialise column format array
132
-		$column_formats = $this->get_columns();
133
-
134
-		// Force fields to lower case
135
-		$data = array_change_key_case( $data );
136
-
137
-		// White list columns
138
-		$data = array_intersect_key( $data, $column_formats );
139
-
140
-		// Reorder $column_formats to match the order of columns given in $data
141
-		$data_keys = array_keys( $data );
142
-		$column_formats = array_merge( array_flip( $data_keys ), $column_formats );
143
-
144
-		$wpdb->insert( $this->table_name, $data, $column_formats );
145
-		$wpdb_insert_id = $wpdb->insert_id;
146
-
147
-		do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data );
148
-
149
-		return $wpdb_insert_id;
150
-	}
151
-
152
-	/**
153
-	 * Update a row
154
-	 *
155
-	 * @access  public
156
-	 * @since   1.0.0
157
-	 * @return  bool
158
-	 */
159
-	public function update( $row_id, $data = array(), $where = '' ) {
160
-
161
-		global $wpdb;
162
-
163
-		// Row ID must be positive integer
164
-		$row_id = absint( $row_id );
165
-
166
-		if ( empty( $row_id ) ) {
167
-			return false;
168
-		}
169
-
170
-		if ( empty( $where ) ) {
171
-			$where = $this->primary_key;
172
-		}
173
-
174
-		// Initialise column format array
175
-		$column_formats = $this->get_columns();
176
-
177
-		// Force fields to lower case
178
-		$data = array_change_key_case( $data );
179
-
180
-		// White list columns
181
-		$data = array_intersect_key( $data, $column_formats );
182
-
183
-		// Reorder $column_formats to match the order of columns given in $data
184
-		$data_keys = array_keys( $data );
185
-		$column_formats = array_merge( array_flip( $data_keys ), $column_formats );
186
-
187
-		if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) {
188
-			return false;
189
-		}
190
-
191
-		return true;
192
-	}
193
-
194
-	/**
195
-	 * Delete a row identified by the primary key
196
-	 *
197
-	 * @access  public
198
-	 * @since   1.0.0
199
-	 * @return  bool
200
-	 */
201
-	public function delete( $row_id = 0 ) {
202
-
203
-		global $wpdb;
204
-
205
-		// Row ID must be positive integer
206
-		$row_id = absint( $row_id );
207
-
208
-		if ( empty( $row_id ) ) {
209
-			return false;
210
-		}
211
-
212
-		if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) {
213
-			return false;
214
-		}
215
-
216
-		return true;
217
-	}
218
-
219
-	/**
220
-	 * Check if the given table exists
221
-	 *
222
-	 * @since  2.4
223
-	 * @param  string $table The table name
224
-	 * @return bool          If the table name exists
225
-	 */
226
-	public function table_exists( $table ) {
227
-		global $wpdb;
228
-		$table = sanitize_text_field( $table );
229
-
230
-		return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
231
-	}
232
-
233
-	/**
234
-	 * Check if the table was ever installed
235
-	 *
236
-	 * @since  2.4
237
-	 * @return bool Returns if the customers table was installed and upgrade routine run
238
-	 */
239
-	public function installed() {
240
-		return $this->table_exists( $this->table_name );
241
-	}
10
+    /**
11
+     * The name of our database table
12
+     *
13
+     * @access  public
14
+     * @since   1.0.0
15
+     */
16
+    public $table_name;
17
+
18
+    /**
19
+     * The version of our database table
20
+     *
21
+     * @access  public
22
+     * @since   1.0.0
23
+     */
24
+    public $version;
25
+
26
+    /**
27
+     * The name of the primary column
28
+     *
29
+     * @access  public
30
+     * @since   1.0.0
31
+     */
32
+    public $primary_key;
33
+
34
+    /**
35
+     * Get things started
36
+     *
37
+     * @access  public
38
+     * @since   1.0.0
39
+     */
40
+    public function __construct() {}
41
+
42
+    /**
43
+     * Whitelist of columns
44
+     *
45
+     * @access  public
46
+     * @since   1.0.0
47
+     * @return  array
48
+     */
49
+    public function get_columns() {
50
+        return array();
51
+    }
52
+
53
+    /**
54
+     * Default column values
55
+     *
56
+     * @access  public
57
+     * @since   1.0.0
58
+     * @return  array
59
+     */
60
+    public function get_column_defaults() {
61
+        return array();
62
+    }
63
+
64
+    /**
65
+     * Retrieve a row by the primary key
66
+     *
67
+     * @access  public
68
+     * @since   1.0.0
69
+     * @return  object
70
+     */
71
+    public function get( $row_id ) {
72
+        global $wpdb;
73
+        return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
74
+    }
75
+
76
+    /**
77
+     * Retrieve a row by a specific column / value
78
+     *
79
+     * @access  public
80
+     * @since   1.0.0
81
+     * @return  object
82
+     */
83
+    public function get_by( $column, $row_id ) {
84
+        global $wpdb;
85
+        $column = esc_sql( $column );
86
+        return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );
87
+    }
88
+
89
+    /**
90
+     * Retrieve a specific column's value by the primary key
91
+     *
92
+     * @access  public
93
+     * @since   1.0.0
94
+     * @return  string
95
+     */
96
+    public function get_column( $column, $row_id ) {
97
+        global $wpdb;
98
+        $column = esc_sql( $column );
99
+        return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
100
+    }
101
+
102
+    /**
103
+     * Retrieve a specific column's value by the the specified column / value
104
+     *
105
+     * @access  public
106
+     * @since   1.0.0
107
+     * @return  string
108
+     */
109
+    public function get_column_by( $column, $column_where, $column_value ) {
110
+        global $wpdb;
111
+        $column_where = esc_sql( $column_where );
112
+        $column       = esc_sql( $column );
113
+        return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );
114
+    }
115
+
116
+    /**
117
+     * Insert a new row
118
+     *
119
+     * @access  public
120
+     * @since   1.0.0
121
+     * @return  int
122
+     */
123
+    public function insert( $data, $type = '' ) {
124
+        global $wpdb;
125
+
126
+        // Set default values
127
+        $data = wp_parse_args( $data, $this->get_column_defaults() );
128
+
129
+        do_action( 'wpinv_pre_insert_' . $type, $data );
130
+
131
+        // Initialise column format array
132
+        $column_formats = $this->get_columns();
133
+
134
+        // Force fields to lower case
135
+        $data = array_change_key_case( $data );
136
+
137
+        // White list columns
138
+        $data = array_intersect_key( $data, $column_formats );
139
+
140
+        // Reorder $column_formats to match the order of columns given in $data
141
+        $data_keys = array_keys( $data );
142
+        $column_formats = array_merge( array_flip( $data_keys ), $column_formats );
143
+
144
+        $wpdb->insert( $this->table_name, $data, $column_formats );
145
+        $wpdb_insert_id = $wpdb->insert_id;
146
+
147
+        do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data );
148
+
149
+        return $wpdb_insert_id;
150
+    }
151
+
152
+    /**
153
+     * Update a row
154
+     *
155
+     * @access  public
156
+     * @since   1.0.0
157
+     * @return  bool
158
+     */
159
+    public function update( $row_id, $data = array(), $where = '' ) {
160
+
161
+        global $wpdb;
162
+
163
+        // Row ID must be positive integer
164
+        $row_id = absint( $row_id );
165
+
166
+        if ( empty( $row_id ) ) {
167
+            return false;
168
+        }
169
+
170
+        if ( empty( $where ) ) {
171
+            $where = $this->primary_key;
172
+        }
173
+
174
+        // Initialise column format array
175
+        $column_formats = $this->get_columns();
176
+
177
+        // Force fields to lower case
178
+        $data = array_change_key_case( $data );
179
+
180
+        // White list columns
181
+        $data = array_intersect_key( $data, $column_formats );
182
+
183
+        // Reorder $column_formats to match the order of columns given in $data
184
+        $data_keys = array_keys( $data );
185
+        $column_formats = array_merge( array_flip( $data_keys ), $column_formats );
186
+
187
+        if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) {
188
+            return false;
189
+        }
190
+
191
+        return true;
192
+    }
193
+
194
+    /**
195
+     * Delete a row identified by the primary key
196
+     *
197
+     * @access  public
198
+     * @since   1.0.0
199
+     * @return  bool
200
+     */
201
+    public function delete( $row_id = 0 ) {
202
+
203
+        global $wpdb;
204
+
205
+        // Row ID must be positive integer
206
+        $row_id = absint( $row_id );
207
+
208
+        if ( empty( $row_id ) ) {
209
+            return false;
210
+        }
211
+
212
+        if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) {
213
+            return false;
214
+        }
215
+
216
+        return true;
217
+    }
218
+
219
+    /**
220
+     * Check if the given table exists
221
+     *
222
+     * @since  2.4
223
+     * @param  string $table The table name
224
+     * @return bool          If the table name exists
225
+     */
226
+    public function table_exists( $table ) {
227
+        global $wpdb;
228
+        $table = sanitize_text_field( $table );
229
+
230
+        return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
231
+    }
232
+
233
+    /**
234
+     * Check if the table was ever installed
235
+     *
236
+     * @since  2.4
237
+     * @return bool Returns if the customers table was installed and upgrade routine run
238
+     */
239
+    public function installed() {
240
+        return $this->table_exists( $this->table_name );
241
+    }
242 242
 
243 243
 }
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -12,144 +12,144 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
-
33
-	}
34
-
35
-	/**
36
-	 * Schedules a cron to run every day at 7 a.m
37
-	 *
38
-	 */
39
-	public function maybe_create_scheduled_event() {
40
-
41
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
-		}
45
-
46
-	}
47
-
48
-	/**
49
-	 * Clears deprecated events.
50
-	 *
51
-	 */
52
-	public function maybe_clear_deprecated_events() {
53
-
54
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
-			update_option( 'wpinv_cleared_old_events', 1 );
58
-		}
59
-
60
-	}
61
-
62
-	/**
63
-	 * Fires the old hook for backwards compatibility.
64
-	 *
65
-	 */
66
-	public function backwards_compat() {
67
-		do_action( 'wpinv_register_schedule_event_daily' );
68
-	}
69
-
70
-	/**
71
-	 * Checks for subscriptions that are scheduled to renew.
72
-	 *
73
-	 */
74
-	public function check_renewing_subscriptions() {
75
-
76
-		// Fetch subscriptions that expire today.
77
-		$args  = array(
78
-			'number'             => -1,
79
-			'count_total'        => false,
80
-			'status'             => 'trialling active',
81
-			'date_expires_query' => array(
82
-				array(
83
-					'year'    => date( 'Y', current_time( 'timestamp' ) ),
84
-					'month'   => date( 'n', current_time( 'timestamp' ) ),
85
-					'day'     => date( 'j', current_time( 'timestamp' ) ),
86
-					'compare' => '=',
87
-				),
88
-			),
89
-		);
90
-
91
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
92
-
93
-		foreach ( $subscriptions->get_results() as $subscription ) {
94
-
95
-			/** @var WPInv_Subscription $subscription */
96
-			if ( $subscription->is_last_renewal() ) {
97
-				$subscription->complete();
98
-			} else {
99
-				do_action( 'getpaid_should_renew_subscription', $subscription );
100
-			}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
+
33
+    }
34
+
35
+    /**
36
+     * Schedules a cron to run every day at 7 a.m
37
+     *
38
+     */
39
+    public function maybe_create_scheduled_event() {
40
+
41
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
+        }
45
+
46
+    }
47
+
48
+    /**
49
+     * Clears deprecated events.
50
+     *
51
+     */
52
+    public function maybe_clear_deprecated_events() {
53
+
54
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
+            update_option( 'wpinv_cleared_old_events', 1 );
58
+        }
59
+
60
+    }
61
+
62
+    /**
63
+     * Fires the old hook for backwards compatibility.
64
+     *
65
+     */
66
+    public function backwards_compat() {
67
+        do_action( 'wpinv_register_schedule_event_daily' );
68
+    }
69
+
70
+    /**
71
+     * Checks for subscriptions that are scheduled to renew.
72
+     *
73
+     */
74
+    public function check_renewing_subscriptions() {
75
+
76
+        // Fetch subscriptions that expire today.
77
+        $args  = array(
78
+            'number'             => -1,
79
+            'count_total'        => false,
80
+            'status'             => 'trialling active',
81
+            'date_expires_query' => array(
82
+                array(
83
+                    'year'    => date( 'Y', current_time( 'timestamp' ) ),
84
+                    'month'   => date( 'n', current_time( 'timestamp' ) ),
85
+                    'day'     => date( 'j', current_time( 'timestamp' ) ),
86
+                    'compare' => '=',
87
+                ),
88
+            ),
89
+        );
90
+
91
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
92
+
93
+        foreach ( $subscriptions->get_results() as $subscription ) {
94
+
95
+            /** @var WPInv_Subscription $subscription */
96
+            if ( $subscription->is_last_renewal() ) {
97
+                $subscription->complete();
98
+            } else {
99
+                do_action( 'getpaid_should_renew_subscription', $subscription );
100
+            }
101 101
 }
102 102
 
103
-	}
104
-
105
-	/**
106
-	 * Expires expired subscriptions.
107
-	 *
108
-	 */
109
-	public function maybe_expire_subscriptions() {
110
-
111
-		// Fetch expired subscriptions (skips those that expire today).
112
-		$args  = array(
113
-			'number'             => -1,
114
-			'count_total'        => false,
115
-			'status'             => 'trialling active failing cancelled',
116
-			'date_expires_query' => array(
117
-				'before'    => 'yesterday',
118
-				'inclusive' => false,
119
-			),
120
-		);
121
-
122
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
123
-
124
-		foreach ( $subscriptions->get_results() as $subscription ) {
125
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
126
-				$subscription->set_status( 'expired' );
127
-				$subscription->save();
128
-			}
129
-		}
130
-
131
-	}
132
-
133
-	/**
134
-	 * Logs cron runs.
135
-	 *
136
-	 */
137
-	public function log_cron_run() {
138
-		wpinv_error_log( 'GetPaid Daily Cron', false );
139
-	}
140
-
141
-	/**
142
-	 * Updates GeoIP databases.
143
-	 *
144
-	 */
145
-	public function maybe_update_geoip_databases() {
146
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
147
-
148
-		if ( false === $updated ) {
149
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
150
-			do_action( 'getpaid_update_geoip_databases' );
151
-		}
152
-
153
-	}
103
+    }
104
+
105
+    /**
106
+     * Expires expired subscriptions.
107
+     *
108
+     */
109
+    public function maybe_expire_subscriptions() {
110
+
111
+        // Fetch expired subscriptions (skips those that expire today).
112
+        $args  = array(
113
+            'number'             => -1,
114
+            'count_total'        => false,
115
+            'status'             => 'trialling active failing cancelled',
116
+            'date_expires_query' => array(
117
+                'before'    => 'yesterday',
118
+                'inclusive' => false,
119
+            ),
120
+        );
121
+
122
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
123
+
124
+        foreach ( $subscriptions->get_results() as $subscription ) {
125
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
126
+                $subscription->set_status( 'expired' );
127
+                $subscription->save();
128
+            }
129
+        }
130
+
131
+    }
132
+
133
+    /**
134
+     * Logs cron runs.
135
+     *
136
+     */
137
+    public function log_cron_run() {
138
+        wpinv_error_log( 'GetPaid Daily Cron', false );
139
+    }
140
+
141
+    /**
142
+     * Updates GeoIP databases.
143
+     *
144
+     */
145
+    public function maybe_update_geoip_databases() {
146
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
147
+
148
+        if ( false === $updated ) {
149
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
150
+            do_action( 'getpaid_update_geoip_databases' );
151
+        }
152
+
153
+    }
154 154
 
155 155
 }
Please login to merge, or discard this patch.
includes/class-wpinv-session-handler.php 1 patch
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -12,125 +12,125 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class WPInv_Session_Handler extends WPInv_Session {
14 14
 
15
-	/**
16
-	 * Cookie name used for the session.
17
-	 *
18
-	 * @var string cookie name
19
-	 */
20
-	protected $_cookie;
21
-
22
-	/**
23
-	 * Stores session expiry.
24
-	 *
25
-	 * @var int session due to expire timestamp
26
-	 */
27
-	protected $_session_expiring;
28
-
29
-	/**
30
-	 * Stores session due to expire timestamp.
31
-	 *
32
-	 * @var string session expiration timestamp
33
-	 */
34
-	protected $_session_expiration;
35
-
36
-	/**
37
-	 * True when the cookie exists.
38
-	 *
39
-	 * @var bool Based on whether a cookie exists.
40
-	 */
41
-	protected $_has_cookie = false;
42
-
43
-	/**
44
-	 * Table name for session data.
45
-	 *
46
-	 * @var string Custom session table name
47
-	 */
48
-	protected $_table;
49
-
50
-	/**
51
-	 * Constructor for the session class.
52
-	 */
53
-	public function __construct() {
54
-
55
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
15
+    /**
16
+     * Cookie name used for the session.
17
+     *
18
+     * @var string cookie name
19
+     */
20
+    protected $_cookie;
21
+
22
+    /**
23
+     * Stores session expiry.
24
+     *
25
+     * @var int session due to expire timestamp
26
+     */
27
+    protected $_session_expiring;
28
+
29
+    /**
30
+     * Stores session due to expire timestamp.
31
+     *
32
+     * @var string session expiration timestamp
33
+     */
34
+    protected $_session_expiration;
35
+
36
+    /**
37
+     * True when the cookie exists.
38
+     *
39
+     * @var bool Based on whether a cookie exists.
40
+     */
41
+    protected $_has_cookie = false;
42
+
43
+    /**
44
+     * Table name for session data.
45
+     *
46
+     * @var string Custom session table name
47
+     */
48
+    protected $_table;
49
+
50
+    /**
51
+     * Constructor for the session class.
52
+     */
53
+    public function __construct() {
54
+
55
+        $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
56 56
         add_action( 'init', array( $this, 'init' ), -1 );
57
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
60
-
61
-	}
62
-
63
-	/**
64
-	 * Init hooks and session data.
65
-	 *
66
-	 * @since 3.3.0
67
-	 */
68
-	public function init() {
69
-		$this->init_session_cookie();
70
-
71
-		if ( ! is_user_logged_in() ) {
72
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
73
-		}
74
-	}
75
-
76
-	/**
77
-	 * Setup cookie and customer ID.
78
-	 *
79
-	 * @since 3.6.0
80
-	 */
81
-	public function init_session_cookie() {
82
-		$cookie = $this->get_session_cookie();
83
-
84
-		if ( $cookie ) {
85
-			$this->_customer_id        = $cookie[0];
86
-			$this->_session_expiration = $cookie[1];
87
-			$this->_session_expiring   = $cookie[2];
88
-			$this->_has_cookie         = true;
89
-			$this->_data               = $this->get_session_data();
90
-
91
-			// If the user logs in, update session.
92
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
93
-				$this->_customer_id = get_current_user_id();
94
-				$this->_dirty       = true;
95
-				$this->save_data();
96
-				$this->set_customer_session_cookie( true );
97
-			}
98
-
99
-			// Update session if its close to expiring.
100
-			if ( time() > $this->_session_expiring ) {
101
-				$this->set_session_expiration();
102
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
103
-			}
104
-		} else {
105
-			$this->set_session_expiration();
106
-			$this->_customer_id = $this->generate_customer_id();
107
-			$this->_data        = $this->get_session_data();
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * Sets the session cookie on-demand (usually after adding an item to the cart).
113
-	 *
114
-	 * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
115
-	 *
116
-	 * Warning: Cookies will only be set if this is called before the headers are sent.
117
-	 *
118
-	 * @param bool $set Should the session cookie be set.
119
-	 */
120
-	public function set_customer_session_cookie( $set ) {
121
-		if ( $set ) {
122
-			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
123
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
124
-			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
125
-			$this->_has_cookie = true;
126
-
127
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
128
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
-			}
130
-		}
131
-	}
132
-
133
-	public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
57
+        add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
+        add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
+        add_action( 'shutdown', array( $this, 'save_data' ), 20 );
60
+
61
+    }
62
+
63
+    /**
64
+     * Init hooks and session data.
65
+     *
66
+     * @since 3.3.0
67
+     */
68
+    public function init() {
69
+        $this->init_session_cookie();
70
+
71
+        if ( ! is_user_logged_in() ) {
72
+            add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
73
+        }
74
+    }
75
+
76
+    /**
77
+     * Setup cookie and customer ID.
78
+     *
79
+     * @since 3.6.0
80
+     */
81
+    public function init_session_cookie() {
82
+        $cookie = $this->get_session_cookie();
83
+
84
+        if ( $cookie ) {
85
+            $this->_customer_id        = $cookie[0];
86
+            $this->_session_expiration = $cookie[1];
87
+            $this->_session_expiring   = $cookie[2];
88
+            $this->_has_cookie         = true;
89
+            $this->_data               = $this->get_session_data();
90
+
91
+            // If the user logs in, update session.
92
+            if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
93
+                $this->_customer_id = get_current_user_id();
94
+                $this->_dirty       = true;
95
+                $this->save_data();
96
+                $this->set_customer_session_cookie( true );
97
+            }
98
+
99
+            // Update session if its close to expiring.
100
+            if ( time() > $this->_session_expiring ) {
101
+                $this->set_session_expiration();
102
+                $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
103
+            }
104
+        } else {
105
+            $this->set_session_expiration();
106
+            $this->_customer_id = $this->generate_customer_id();
107
+            $this->_data        = $this->get_session_data();
108
+        }
109
+    }
110
+
111
+    /**
112
+     * Sets the session cookie on-demand (usually after adding an item to the cart).
113
+     *
114
+     * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
115
+     *
116
+     * Warning: Cookies will only be set if this is called before the headers are sent.
117
+     *
118
+     * @param bool $set Should the session cookie be set.
119
+     */
120
+    public function set_customer_session_cookie( $set ) {
121
+        if ( $set ) {
122
+            $to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
123
+            $cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
124
+            $cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
125
+            $this->_has_cookie = true;
126
+
127
+            if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
128
+                $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
+            }
130
+        }
131
+    }
132
+
133
+    public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
134 134
         if ( ! headers_sent() ) {
135 135
             setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
136 136
         } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@@ -139,86 +139,86 @@  discard block
 block discarded – undo
139 139
         }
140 140
     }
141 141
 
142
-	/**
143
-	 * Should the session cookie be secure?
144
-	 *
145
-	 * @since 3.6.0
146
-	 * @return bool
147
-	 */
148
-	protected function use_secure_cookie() {
142
+    /**
143
+     * Should the session cookie be secure?
144
+     *
145
+     * @since 3.6.0
146
+     * @return bool
147
+     */
148
+    protected function use_secure_cookie() {
149 149
         $is_https = false !== strstr( get_option( 'home' ), 'https:' );
150
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
-	}
152
-
153
-	/**
154
-	 * Return true if the current user has an active session, i.e. a cookie to retrieve values.
155
-	 *
156
-	 * @return bool
157
-	 */
158
-	public function has_session() {
159
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
160
-	}
161
-
162
-	/**
163
-	 * Set session expiration.
164
-	 */
165
-	public function set_session_expiration() {
166
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
167
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
-	}
169
-
170
-	/**
171
-	 * Generates session ids.
172
-	 *
173
-	 * @return string
174
-	 */
175
-	public function generate_customer_id() {
176
-		require_once ABSPATH . 'wp-includes/class-phpass.php';
177
-		$hasher      = new PasswordHash( 8, false );
178
-		return md5( $hasher->get_random_bytes( 32 ) );
179
-	}
180
-
181
-	/**
182
-	 * Get the session cookie, if set. Otherwise return false.
183
-	 *
184
-	 * Session cookies without a customer ID are invalid.
185
-	 *
186
-	 * @return bool|array
187
-	 */
188
-	public function get_session_cookie() {
189
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
190
-
191
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
192
-			return false;
193
-		}
194
-
195
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
196
-
197
-		if ( empty( $customer_id ) ) {
198
-			return false;
199
-		}
200
-
201
-		// Validate hash.
202
-		$to_hash = $customer_id . '|' . $session_expiration;
203
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
204
-
205
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
206
-			return false;
207
-		}
208
-
209
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
210
-	}
211
-
212
-	/**
213
-	 * Get session data.
214
-	 *
215
-	 * @return array
216
-	 */
217
-	public function get_session_data() {
218
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
219
-	}
220
-
221
-	public function generate_key( $customer_id ) {
150
+        return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
+    }
152
+
153
+    /**
154
+     * Return true if the current user has an active session, i.e. a cookie to retrieve values.
155
+     *
156
+     * @return bool
157
+     */
158
+    public function has_session() {
159
+        return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
160
+    }
161
+
162
+    /**
163
+     * Set session expiration.
164
+     */
165
+    public function set_session_expiration() {
166
+        $this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
167
+        $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
+    }
169
+
170
+    /**
171
+     * Generates session ids.
172
+     *
173
+     * @return string
174
+     */
175
+    public function generate_customer_id() {
176
+        require_once ABSPATH . 'wp-includes/class-phpass.php';
177
+        $hasher      = new PasswordHash( 8, false );
178
+        return md5( $hasher->get_random_bytes( 32 ) );
179
+    }
180
+
181
+    /**
182
+     * Get the session cookie, if set. Otherwise return false.
183
+     *
184
+     * Session cookies without a customer ID are invalid.
185
+     *
186
+     * @return bool|array
187
+     */
188
+    public function get_session_cookie() {
189
+        $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
190
+
191
+        if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
192
+            return false;
193
+        }
194
+
195
+        list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
196
+
197
+        if ( empty( $customer_id ) ) {
198
+            return false;
199
+        }
200
+
201
+        // Validate hash.
202
+        $to_hash = $customer_id . '|' . $session_expiration;
203
+        $hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
204
+
205
+        if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
206
+            return false;
207
+        }
208
+
209
+        return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
210
+    }
211
+
212
+    /**
213
+     * Get session data.
214
+     *
215
+     * @return array
216
+     */
217
+    public function get_session_data() {
218
+        return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
219
+    }
220
+
221
+    public function generate_key( $customer_id ) {
222 222
         if ( ! $customer_id ) {
223 223
             return;
224 224
         }
@@ -226,68 +226,68 @@  discard block
 block discarded – undo
226 226
         return 'wpi_trans_' . $customer_id;
227 227
     }
228 228
 
229
-	/**
230
-	 * Save data.
231
-	 */
232
-	public function save_data() {
233
-		// Dirty if something changed - prevents saving nothing new.
234
-		if ( $this->_dirty && $this->has_session() ) {
229
+    /**
230
+     * Save data.
231
+     */
232
+    public function save_data() {
233
+        // Dirty if something changed - prevents saving nothing new.
234
+        if ( $this->_dirty && $this->has_session() ) {
235 235
 
236 236
             set_transient( $this->generate_key( $this->_customer_id ), $this->_data, $this->_session_expiration );
237 237
 
238
-			$this->_dirty = false;
239
-		}
240
-	}
241
-
242
-	/**
243
-	 * Destroy all session data.
244
-	 */
245
-	public function destroy_session() {
246
-		$this->delete_session( $this->_customer_id );
247
-		$this->forget_session();
248
-	}
249
-
250
-	/**
251
-	 * Forget all session data without destroying it.
252
-	 */
253
-	public function forget_session() {
254
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
255
-
256
-		wpinv_empty_cart();
257
-
258
-		$this->_data        = array();
259
-		$this->_dirty       = false;
260
-		$this->_customer_id = $this->generate_customer_id();
261
-	}
262
-
263
-	/**
264
-	 * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
265
-	 *
266
-	 * @param int $uid User ID.
267
-	 * @return string
268
-	 */
269
-	public function nonce_user_logged_out( $uid ) {
270
-
271
-		// Check if one of our nonces.
272
-		if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) {
273
-			return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
274
-		}
275
-
276
-		return $uid;
277
-	}
278
-
279
-	/**
280
-	 * Returns the session.
281
-	 *
282
-	 * @param string $customer_id Customer ID.
283
-	 * @param mixed  $default Default session value.
284
-	 * @return string|array
285
-	 */
286
-	public function get_session( $customer_id, $default = false ) {
287
-
288
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
289
-			return array();
290
-		}
238
+            $this->_dirty = false;
239
+        }
240
+    }
241
+
242
+    /**
243
+     * Destroy all session data.
244
+     */
245
+    public function destroy_session() {
246
+        $this->delete_session( $this->_customer_id );
247
+        $this->forget_session();
248
+    }
249
+
250
+    /**
251
+     * Forget all session data without destroying it.
252
+     */
253
+    public function forget_session() {
254
+        $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
255
+
256
+        wpinv_empty_cart();
257
+
258
+        $this->_data        = array();
259
+        $this->_dirty       = false;
260
+        $this->_customer_id = $this->generate_customer_id();
261
+    }
262
+
263
+    /**
264
+     * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
265
+     *
266
+     * @param int $uid User ID.
267
+     * @return string
268
+     */
269
+    public function nonce_user_logged_out( $uid ) {
270
+
271
+        // Check if one of our nonces.
272
+        if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) {
273
+            return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
274
+        }
275
+
276
+        return $uid;
277
+    }
278
+
279
+    /**
280
+     * Returns the session.
281
+     *
282
+     * @param string $customer_id Customer ID.
283
+     * @param mixed  $default Default session value.
284
+     * @return string|array
285
+     */
286
+    public function get_session( $customer_id, $default = false ) {
287
+
288
+        if ( defined( 'WP_SETUP_CONFIG' ) ) {
289
+            return array();
290
+        }
291 291
 
292 292
         $key = $this->generate_key( $customer_id );
293 293
         $value = get_transient( $key );
@@ -296,30 +296,30 @@  discard block
 block discarded – undo
296 296
             $value = $default;
297 297
         }
298 298
 
299
-		return maybe_unserialize( $value );
300
-	}
299
+        return maybe_unserialize( $value );
300
+    }
301 301
 
302
-	/**
303
-	 * Delete the session from the cache and database.
304
-	 *
305
-	 * @param int $customer_id Customer ID.
306
-	 */
307
-	public function delete_session( $customer_id ) {
302
+    /**
303
+     * Delete the session from the cache and database.
304
+     *
305
+     * @param int $customer_id Customer ID.
306
+     */
307
+    public function delete_session( $customer_id ) {
308 308
 
309 309
         $key = $this->generate_key( $customer_id );
310 310
 
311
-		delete_transient( $key );
312
-	}
311
+        delete_transient( $key );
312
+    }
313 313
 
314
-	/**
315
-	 * Update the session expiry timestamp.
316
-	 *
317
-	 * @param string $customer_id Customer ID.
318
-	 * @param int    $timestamp Timestamp to expire the cookie.
319
-	 */
320
-	public function update_session_timestamp( $customer_id, $timestamp ) {
314
+    /**
315
+     * Update the session expiry timestamp.
316
+     *
317
+     * @param string $customer_id Customer ID.
318
+     * @param int    $timestamp Timestamp to expire the cookie.
319
+     */
320
+    public function update_session_timestamp( $customer_id, $timestamp ) {
321 321
 
322 322
         set_transient( $this->generate_key( $customer_id ), maybe_serialize( $this->_data ), $timestamp );
323 323
 
324
-	}
324
+    }
325 325
 }
Please login to merge, or discard this patch.
includes/invoice-functions.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69 69
 function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
70
+    return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
71 71
 }
72 72
 
73 73
 /**
@@ -556,37 +556,37 @@  discard block
 block discarded – undo
556 556
     $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
557 557
     $columns = array(
558 558
 
559
-		'invoice-number'  => array(
560
-			'title' => $label,
561
-			'class' => 'text-left',
562
-		),
559
+        'invoice-number'  => array(
560
+            'title' => $label,
561
+            'class' => 'text-left',
562
+        ),
563 563
 
564
-		'created-date'    => array(
565
-			'title' => __( 'Created Date', 'invoicing' ),
566
-			'class' => 'text-left',
567
-		),
564
+        'created-date'    => array(
565
+            'title' => __( 'Created Date', 'invoicing' ),
566
+            'class' => 'text-left',
567
+        ),
568 568
 
569
-		'payment-date'    => array(
570
-			'title' => __( 'Payment Date', 'invoicing' ),
571
-			'class' => 'text-left',
572
-		),
569
+        'payment-date'    => array(
570
+            'title' => __( 'Payment Date', 'invoicing' ),
571
+            'class' => 'text-left',
572
+        ),
573 573
 
574
-		'invoice-status'  => array(
575
-			'title' => __( 'Status', 'invoicing' ),
576
-			'class' => 'text-center',
577
-		),
574
+        'invoice-status'  => array(
575
+            'title' => __( 'Status', 'invoicing' ),
576
+            'class' => 'text-center',
577
+        ),
578 578
 
579
-		'invoice-total'   => array(
580
-			'title' => __( 'Total', 'invoicing' ),
581
-			'class' => 'text-right',
582
-		),
579
+        'invoice-total'   => array(
580
+            'title' => __( 'Total', 'invoicing' ),
581
+            'class' => 'text-right',
582
+        ),
583 583
 
584
-		'invoice-actions' => array(
585
-			'title' => ' ',
586
-			'class' => 'text-center',
587
-		),
584
+        'invoice-actions' => array(
585
+            'title' => ' ',
586
+            'class' => 'text-center',
587
+        ),
588 588
 
589
-	);
589
+    );
590 590
 
591 591
     return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
592 592
 }
@@ -1274,22 +1274,22 @@  discard block
 block discarded – undo
1274 1274
  */
1275 1275
 function getpaid_get_invoice_status_classes() {
1276 1276
 
1277
-	return apply_filters(
1278
-		'getpaid_get_invoice_status_classes',
1279
-		array(
1277
+    return apply_filters(
1278
+        'getpaid_get_invoice_status_classes',
1279
+        array(
1280 1280
             'wpi-quote-declined' => 'badge-danger',
1281 1281
             'wpi-failed'         => 'badge-danger',
1282
-			'wpi-processing'     => 'badge-info',
1283
-			'wpi-onhold'         => 'badge-warning',
1284
-			'wpi-quote-accepted' => 'badge-success',
1285
-			'publish'            => 'badge-success',
1286
-			'wpi-renewal'        => 'badge-primary',
1282
+            'wpi-processing'     => 'badge-info',
1283
+            'wpi-onhold'         => 'badge-warning',
1284
+            'wpi-quote-accepted' => 'badge-success',
1285
+            'publish'            => 'badge-success',
1286
+            'wpi-renewal'        => 'badge-primary',
1287 1287
             'wpi-cancelled'      => 'badge-secondary',
1288 1288
             'wpi-pending'        => 'badge-dark',
1289 1289
             'wpi-quote-pending'  => 'badge-dark',
1290 1290
             'wpi-refunded'       => 'badge-secondary',
1291
-		)
1292
-	);
1291
+        )
1292
+    );
1293 1293
 
1294 1294
 }
1295 1295
 
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
 function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1304 1304
 
1305 1305
     $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1306
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1306
+    $rates   = getpaid_filter_item_tax_rates( $item, $rates );
1307 1307
     $rates   = wp_list_pluck( $rates, 'rate' );
1308 1308
 
1309 1309
     return array_sum( $rates );
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -31,16 +31,16 @@  discard block
 block discarded – undo
31 31
 }
32 32
 
33 33
 function wpinv_can_checkout() {
34
-	$can_checkout = true; // Always true for now
34
+    $can_checkout = true; // Always true for now
35 35
 
36
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
36
+    return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
37 37
 }
38 38
 
39 39
 function wpinv_get_success_page_uri() {
40
-	$page_id = wpinv_get_option( 'success_page', 0 );
41
-	$page_id = absint( $page_id );
40
+    $page_id = wpinv_get_option( 'success_page', 0 );
41
+    $page_id = absint( $page_id );
42 42
 
43
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
43
+    return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
44 44
 }
45 45
 
46 46
 /**
@@ -51,22 +51,22 @@  discard block
 block discarded – undo
51 51
  */
52 52
 function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) {
53 53
     $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) );
54
-	$page_id   = wpinv_get_option( "{$post_type}_history_page", 0 );
55
-	$page_id   = absint( $page_id );
56
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type );
54
+    $page_id   = wpinv_get_option( "{$post_type}_history_page", 0 );
55
+    $page_id   = absint( $page_id );
56
+    return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type );
57 57
 }
58 58
 
59 59
 function wpinv_is_success_page() {
60
-	$is_success_page = wpinv_get_option( 'success_page', false );
61
-	$is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false;
60
+    $is_success_page = wpinv_get_option( 'success_page', false );
61
+    $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false;
62 62
 
63
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
63
+    return apply_filters( 'wpinv_is_success_page', $is_success_page );
64 64
 }
65 65
 
66 66
 function wpinv_is_invoice_history_page() {
67
-	$ret = wpinv_get_option( 'invoice_history_page', false );
68
-	$ret = $ret ? is_page( $ret ) : false;
69
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
67
+    $ret = wpinv_get_option( 'invoice_history_page', false );
68
+    $ret = $ret ? is_page( $ret ) : false;
69
+    return apply_filters( 'wpinv_is_invoice_history_page', $ret );
70 70
 }
71 71
 
72 72
 function wpinv_is_subscriptions_history_page() {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 }
93 93
 
94 94
 function wpinv_send_to_failed_page( $args = null ) {
95
-	$redirect = wpinv_get_failed_transaction_uri();
95
+    $redirect = wpinv_get_failed_transaction_uri();
96 96
 
97 97
     if ( ! empty( $args ) ) {
98 98
         // Check for backward compatibility
@@ -113,58 +113,58 @@  discard block
 block discarded – undo
113 113
 }
114 114
 
115 115
 function wpinv_get_checkout_uri( $args = array() ) {
116
-	$uri = wpinv_get_option( 'checkout_page', false );
117
-	$uri = isset( $uri ) ? get_permalink( $uri ) : null;
116
+    $uri = wpinv_get_option( 'checkout_page', false );
117
+    $uri = isset( $uri ) ? get_permalink( $uri ) : null;
118 118
 
119
-	if ( ! empty( $args ) ) {
120
-		// Check for backward compatibility
121
-		if ( is_string( $args ) ) {
122
-			$args = str_replace( '?', '', $args );
119
+    if ( ! empty( $args ) ) {
120
+        // Check for backward compatibility
121
+        if ( is_string( $args ) ) {
122
+            $args = str_replace( '?', '', $args );
123 123
         }
124 124
 
125
-		$args = wp_parse_args( $args );
125
+        $args = wp_parse_args( $args );
126 126
 
127
-		$uri = add_query_arg( $args, $uri );
128
-	}
127
+        $uri = add_query_arg( $args, $uri );
128
+    }
129 129
 
130
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
130
+    $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
131 131
 
132
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
132
+    $ajax_url = admin_url( 'admin-ajax.php', $scheme );
133 133
 
134
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
135
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
136
-	}
134
+    if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
135
+        $uri = preg_replace( '/^http:/', 'https:', $uri );
136
+    }
137 137
 
138
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
138
+    return apply_filters( 'wpinv_get_checkout_uri', $uri );
139 139
 }
140 140
 
141 141
 function wpinv_get_success_page_url( $query_string = null ) {
142
-	$success_page = wpinv_get_option( 'success_page', 0 );
143
-	$success_page = get_permalink( $success_page );
142
+    $success_page = wpinv_get_option( 'success_page', 0 );
143
+    $success_page = get_permalink( $success_page );
144 144
 
145
-	if ( $query_string ) {
146
-		$success_page .= $query_string;
145
+    if ( $query_string ) {
146
+        $success_page .= $query_string;
147 147
     }
148 148
 
149
-	return apply_filters( 'wpinv_success_page_url', $success_page );
149
+    return apply_filters( 'wpinv_success_page_url', $success_page );
150 150
 }
151 151
 
152 152
 function wpinv_get_failed_transaction_uri( $extras = false ) {
153
-	$uri = wpinv_get_option( 'failure_page', '' );
154
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
153
+    $uri = wpinv_get_option( 'failure_page', '' );
154
+    $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
155 155
 
156
-	if ( $extras ) {
157
-		$uri .= $extras;
156
+    if ( $extras ) {
157
+        $uri .= $extras;
158 158
     }
159 159
 
160
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
160
+    return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
161 161
 }
162 162
 
163 163
 function wpinv_is_failed_transaction_page() {
164
-	$ret = wpinv_get_option( 'failure_page', false );
165
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
164
+    $ret = wpinv_get_option( 'failure_page', false );
165
+    $ret = isset( $ret ) ? is_page( $ret ) : false;
166 166
 
167
-	return apply_filters( 'wpinv_is_failure_page', $ret );
167
+    return apply_filters( 'wpinv_is_failure_page', $ret );
168 168
 }
169 169
 
170 170
 function wpinv_transaction_query( $type = 'start' ) {
@@ -244,36 +244,36 @@  discard block
 block discarded – undo
244 244
     $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
245 245
 
246 246
     if ( $require_billing_details ) {
247
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
248
-			$required_fields['first_name'] = array(
249
-				'error_id'      => 'invalid_first_name',
250
-				'error_message' => __( 'Please enter your first name', 'invoicing' ),
251
-			);
252
-		}
253
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
254
-			$required_fields['address'] = array(
255
-				'error_id'      => 'invalid_address',
256
-				'error_message' => __( 'Please enter your address', 'invoicing' ),
257
-			);
258
-		}
259
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
260
-			$required_fields['city'] = array(
261
-				'error_id'      => 'invalid_city',
262
-				'error_message' => __( 'Please enter your billing city', 'invoicing' ),
263
-			);
264
-		}
265
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
266
-			$required_fields['state'] = array(
267
-				'error_id'      => 'invalid_state',
268
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' ),
269
-			);
270
-		}
271
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
272
-			$required_fields['country'] = array(
273
-				'error_id'      => 'invalid_country',
274
-				'error_message' => __( 'Please select your billing country', 'invoicing' ),
275
-			);
276
-		}
247
+        if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
248
+            $required_fields['first_name'] = array(
249
+                'error_id'      => 'invalid_first_name',
250
+                'error_message' => __( 'Please enter your first name', 'invoicing' ),
251
+            );
252
+        }
253
+        if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
254
+            $required_fields['address'] = array(
255
+                'error_id'      => 'invalid_address',
256
+                'error_message' => __( 'Please enter your address', 'invoicing' ),
257
+            );
258
+        }
259
+        if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
260
+            $required_fields['city'] = array(
261
+                'error_id'      => 'invalid_city',
262
+                'error_message' => __( 'Please enter your billing city', 'invoicing' ),
263
+            );
264
+        }
265
+        if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
266
+            $required_fields['state'] = array(
267
+                'error_id'      => 'invalid_state',
268
+                'error_message' => __( 'Please enter billing state / province', 'invoicing' ),
269
+            );
270
+        }
271
+        if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
272
+            $required_fields['country'] = array(
273
+                'error_id'      => 'invalid_country',
274
+                'error_message' => __( 'Please select your billing country', 'invoicing' ),
275
+            );
276
+        }
277 277
     }
278 278
 
279 279
     return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -160,50 +160,50 @@
 block discarded – undo
160 160
  */
161 161
 function getpaid_calculate_invoice_discount( $invoice, $discount ) {
162 162
 
163
-	$initial_discount   = 0;
164
-	$recurring_discount = 0;
163
+    $initial_discount   = 0;
164
+    $recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+    foreach ( $invoice->get_items() as $item ) {
167 167
 
168
-		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
-			continue;
171
-		}
168
+        // Abort if it is not valid for this item.
169
+        if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
+            continue;
171
+        }
172 172
 
173
-		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
-		$recurring_item_discount = 0;
173
+        // Calculate the initial amount...
174
+        $item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
+        $recurring_item_discount = 0;
176 176
 
177
-		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
-		}
177
+        // ... and maybe the recurring amount.
178
+        if ( $item->is_recurring() && $discount->is_recurring() ) {
179
+            $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
+        }
181 181
 
182
-		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
182
+        // Discount should not exceed discounted amount.
183
+        if ( ! $discount->is_type( 'percent' ) ) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
-				$item_discount = $discount->get_amount() - $initial_discount;
187
-			}
185
+            if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
+                $item_discount = $discount->get_amount() - $initial_discount;
187
+            }
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
-				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
-			}
189
+            if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
+                $recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
+            }
192 192
 }
193 193
 
194
-		$initial_discount             += $item_discount;
195
-		$recurring_discount           += $recurring_item_discount;
196
-		$item->item_discount           = $item_discount;
197
-		$item->recurring_item_discount = $recurring_item_discount;
194
+        $initial_discount             += $item_discount;
195
+        $recurring_discount           += $recurring_item_discount;
196
+        $item->item_discount           = $item_discount;
197
+        $item->recurring_item_discount = $recurring_item_discount;
198 198
 
199
-	}
199
+    }
200 200
 
201
-	return array(
202
-		'name'               => 'discount_code',
203
-		'discount_code'      => $discount->get_code(),
204
-		'initial_discount'   => $initial_discount,
205
-		'recurring_discount' => $recurring_discount,
206
-	);
201
+    return array(
202
+        'name'               => 'discount_code',
203
+        'discount_code'      => $discount->get_code(),
204
+        'initial_discount'   => $initial_discount,
205
+        'recurring_discount' => $recurring_discount,
206
+    );
207 207
 
208 208
 }
209 209
 
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
     $css = getpaid_get_email_css();
110 110
 
111 111
     // include css inliner
112
-	if ( ! class_exists( 'Emogrifier' ) ) {
113
-		include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
112
+    if ( ! class_exists( 'Emogrifier' ) ) {
113
+        include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
114 114
     }
115 115
 
116 116
     // Inline the css.
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     $message = wpinv_email_style_body( $message );
190 190
     $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
191 191
 
192
-	return $mailer->send(
192
+    return $mailer->send(
193 193
         $to,
194 194
         $subject,
195 195
         $message,
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -12,207 +12,207 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
-
28
-		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
-
31
-		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
33
-	}
34
-
35
-	/**
36
-	 * Filters invoice notes query to only include our notes.
37
-	 *
38
-	 * @param WP_Comment_Query $query
39
-	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
-
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
-			$query->query_vars['type'] = 'wpinv_note';
45
-		} else {
46
-
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
48
-				$query->query_vars['type__not_in'] = array();
49
-			}
50
-
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
-		}
54
-
55
-		return $query;
56
-	}
57
-
58
-	/**
59
-	 * Exclude notes from the comments feed.
60
-	 */
61
-	function wpinv_comment_feed_where( $where ) {
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
-	}
64
-
65
-	/**
66
-	 * Delete comments count cache whenever there is
67
-	 * new comment or the status of a comment changes. Cache
68
-	 * will be regenerated next time WPInv_Notes::wp_count_comments()
69
-	 * is called.
70
-	 */
71
-	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
73
-	}
74
-
75
-	/**
76
-	 * Remove invoice notes from wp_count_comments().
77
-	 *
78
-	 * @since  2.2
79
-	 * @param  object $stats   Comment stats.
80
-	 * @param  int    $post_id Post ID.
81
-	 * @return object
82
-	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
84
-		global $wpdb;
85
-
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
88
-
89
-			if ( ! $stats ) {
90
-				$stats = array(
91
-					'total_comments' => 0,
92
-					'all'            => 0,
93
-				);
94
-
95
-				$count = $wpdb->get_results(
96
-					"
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Delete comments count cache whenever there is a new comment or a comment status changes.
25
+        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
+        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
+
28
+        // Count comments.
29
+        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
+
31
+        // Fires after notes are loaded.
32
+        do_action( 'wpinv_notes_init', $this );
33
+    }
34
+
35
+    /**
36
+     * Filters invoice notes query to only include our notes.
37
+     *
38
+     * @param WP_Comment_Query $query
39
+     */
40
+    public function set_invoice_note_type( $query ) {
41
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
+
43
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
+            $query->query_vars['type'] = 'wpinv_note';
45
+        } else {
46
+
47
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
48
+                $query->query_vars['type__not_in'] = array();
49
+            }
50
+
51
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
+        }
54
+
55
+        return $query;
56
+    }
57
+
58
+    /**
59
+     * Exclude notes from the comments feed.
60
+     */
61
+    function wpinv_comment_feed_where( $where ) {
62
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
+    }
64
+
65
+    /**
66
+     * Delete comments count cache whenever there is
67
+     * new comment or the status of a comment changes. Cache
68
+     * will be regenerated next time WPInv_Notes::wp_count_comments()
69
+     * is called.
70
+     */
71
+    public function delete_comments_count_cache() {
72
+        delete_transient( 'getpaid_count_comments' );
73
+    }
74
+
75
+    /**
76
+     * Remove invoice notes from wp_count_comments().
77
+     *
78
+     * @since  2.2
79
+     * @param  object $stats   Comment stats.
80
+     * @param  int    $post_id Post ID.
81
+     * @return object
82
+     */
83
+    public function wp_count_comments( $stats, $post_id ) {
84
+        global $wpdb;
85
+
86
+        if ( empty( $post_id ) ) {
87
+            $stats = get_transient( 'getpaid_count_comments' );
88
+
89
+            if ( ! $stats ) {
90
+                $stats = array(
91
+                    'total_comments' => 0,
92
+                    'all'            => 0,
93
+                );
94
+
95
+                $count = $wpdb->get_results(
96
+                    "
97 97
 					SELECT comment_approved, COUNT(*) AS num_comments
98 98
 					FROM {$wpdb->comments}
99 99
 					WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note')
100 100
 					GROUP BY comment_approved
101 101
 					",
102
-					ARRAY_A
103
-				);
104
-
105
-				$approved = array(
106
-					'0'            => 'moderated',
107
-					'1'            => 'approved',
108
-					'spam'         => 'spam',
109
-					'trash'        => 'trash',
110
-					'post-trashed' => 'post-trashed',
111
-				);
112
-
113
-				foreach ( (array) $count as $row ) {
114
-					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
-						$stats['all']            += $row['num_comments'];
117
-						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
-						$stats['total_comments'] += $row['num_comments'];
120
-					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
-					}
124
-				}
125
-
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
129
-					}
130
-				}
131
-
132
-				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
134
-			}
102
+                    ARRAY_A
103
+                );
104
+
105
+                $approved = array(
106
+                    '0'            => 'moderated',
107
+                    '1'            => 'approved',
108
+                    'spam'         => 'spam',
109
+                    'trash'        => 'trash',
110
+                    'post-trashed' => 'post-trashed',
111
+                );
112
+
113
+                foreach ( (array) $count as $row ) {
114
+                    // Don't count post-trashed toward totals.
115
+                    if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
+                        $stats['all']            += $row['num_comments'];
117
+                        $stats['total_comments'] += $row['num_comments'];
118
+                    } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
+                        $stats['total_comments'] += $row['num_comments'];
120
+                    }
121
+                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
+                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
+                    }
124
+                }
125
+
126
+                foreach ( $approved as $key ) {
127
+                    if ( empty( $stats[ $key ] ) ) {
128
+                        $stats[ $key ] = 0;
129
+                    }
130
+                }
131
+
132
+                $stats = (object) $stats;
133
+                set_transient( 'getpaid_count_comments', $stats );
134
+            }
135 135
 }
136 136
 
137
-		return $stats;
138
-	}
139
-
140
-	/**
141
-	 * Returns an array of invoice notes.
142
-	 *
143
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
144
-	 * @param string $type Optional. Pass in customer to only return customer notes.
145
-	 * @return WP_Comment[]
146
-	 */
147
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
-
149
-		// Default comment args.
150
-		$args = array(
151
-			'post_id' => $invoice_id,
152
-			'orderby' => 'comment_ID',
153
-			'order'   => 'ASC',
154
-		);
155
-
156
-		// Maybe only show customer comments.
157
-		if ( $type == 'customer' ) {
158
-			$args['meta_key']   = '_wpi_customer_note';
159
-			$args['meta_value'] = 1;
160
-		}
161
-
162
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
-
164
-		return get_comments( $args );
165
-	}
166
-
167
-	/**
168
-	 * Saves an invoice comment.
169
-	 *
170
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
171
-	 * @param string $note The note content.
172
-	 * @param string $note_author The name of the author of the note.
173
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174
-	 * @return int|false The new note's ID on success, false on failure.
175
-	 */
176
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
177
-
178
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
-
180
-		/**
181
-		 * Insert the comment.
182
-		 */
183
-		$note_id = wp_insert_comment(
184
-			wp_filter_comment(
185
-				array(
186
-					'comment_post_ID'      => $invoice->get_id(),
187
-					'comment_content'      => $note,
188
-					'comment_agent'        => 'Invoicing',
189
-					'user_id'              => get_current_user_id(),
190
-					'comment_author'       => $note_author,
191
-					'comment_author_IP'    => wpinv_get_ip(),
192
-					'comment_author_email' => $author_email,
193
-					'comment_author_url'   => $invoice->get_view_url(),
194
-					'comment_type'         => 'wpinv_note',
195
-				)
196
-			)
197
-		);
198
-
199
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
-
201
-		// Are we notifying the customer?
202
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
203
-			return $note_id;
204
-		}
205
-
206
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
207
-		do_action(
137
+        return $stats;
138
+    }
139
+
140
+    /**
141
+     * Returns an array of invoice notes.
142
+     *
143
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
144
+     * @param string $type Optional. Pass in customer to only return customer notes.
145
+     * @return WP_Comment[]
146
+     */
147
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
+
149
+        // Default comment args.
150
+        $args = array(
151
+            'post_id' => $invoice_id,
152
+            'orderby' => 'comment_ID',
153
+            'order'   => 'ASC',
154
+        );
155
+
156
+        // Maybe only show customer comments.
157
+        if ( $type == 'customer' ) {
158
+            $args['meta_key']   = '_wpi_customer_note';
159
+            $args['meta_value'] = 1;
160
+        }
161
+
162
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
+
164
+        return get_comments( $args );
165
+    }
166
+
167
+    /**
168
+     * Saves an invoice comment.
169
+     *
170
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
171
+     * @param string $note The note content.
172
+     * @param string $note_author The name of the author of the note.
173
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174
+     * @return int|false The new note's ID on success, false on failure.
175
+     */
176
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
177
+
178
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
+
180
+        /**
181
+         * Insert the comment.
182
+         */
183
+        $note_id = wp_insert_comment(
184
+            wp_filter_comment(
185
+                array(
186
+                    'comment_post_ID'      => $invoice->get_id(),
187
+                    'comment_content'      => $note,
188
+                    'comment_agent'        => 'Invoicing',
189
+                    'user_id'              => get_current_user_id(),
190
+                    'comment_author'       => $note_author,
191
+                    'comment_author_IP'    => wpinv_get_ip(),
192
+                    'comment_author_email' => $author_email,
193
+                    'comment_author_url'   => $invoice->get_view_url(),
194
+                    'comment_type'         => 'wpinv_note',
195
+                )
196
+            )
197
+        );
198
+
199
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
+
201
+        // Are we notifying the customer?
202
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
203
+            return $note_id;
204
+        }
205
+
206
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
207
+        do_action(
208 208
             'wpinv_new_customer_note',
209 209
             array(
210
-				'invoice_id' => $invoice->get_id(),
211
-				'user_note'  => $note,
210
+                'invoice_id' => $invoice->get_id(),
211
+                'user_note'  => $note,
212 212
             )
213 213
         );
214
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
215
-		return $note_id;
216
-	}
214
+        do_action( 'getpaid_new_customer_note', $invoice, $note );
215
+        return $note_id;
216
+    }
217 217
 
218 218
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-legacy-gateway.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@  discard block
 block discarded – undo
15 15
 abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway {
16 16
 
17 17
     /**
18
-	 * Class constructor.
19
-	 */
20
-	public function __construct() {
18
+     * Class constructor.
19
+     */
20
+    public function __construct() {
21 21
         parent::__construct();
22 22
     }
23 23
 
24 24
     /**
25
-	 * Returns the API URL.
26
-	 *
27
-	 *
28
-	 * @param WPInv_Invoice $invoice Invoice.
29
-	 * @return string
30
-	 */
31
-	public function get_api_url( $invoice ) {
25
+     * Returns the API URL.
26
+     *
27
+     *
28
+     * @param WPInv_Invoice $invoice Invoice.
29
+     * @return string
30
+     */
31
+    public function get_api_url( $invoice ) {
32 32
         return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
36
-	 * Communicates with authorize.net
37
-	 *
38
-	 *
39
-	 * @param array $post Data to post.
36
+     * Communicates with authorize.net
37
+     *
38
+     *
39
+     * @param array $post Data to post.
40 40
      * @param WPInv_Invoice $invoice Invoice.
41
-	 * @return stdClass|WP_Error
42
-	 */
41
+     * @return stdClass|WP_Error
42
+     */
43 43
     public function post( $post, $invoice ) {
44 44
 
45 45
         $url      = $this->get_api_url( $invoice );
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
     /**
92
-	 * Returns the API authentication params.
93
-	 *
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function get_auth_params() {
92
+     * Returns the API authentication params.
93
+     *
94
+     *
95
+     * @return array
96
+     */
97
+    public function get_auth_params() {
98 98
 
99 99
         return array(
100 100
             'name'           => $this->get_option( 'login_id' ),
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
     }
105 105
 
106 106
     /**
107
-	 * Cancels a subscription remotely
108
-	 *
109
-	 *
110
-	 * @param WPInv_Subscription $subscription Subscription.
107
+     * Cancels a subscription remotely
108
+     *
109
+     *
110
+     * @param WPInv_Subscription $subscription Subscription.
111 111
      * @param WPInv_Invoice $invoice Invoice.
112
-	 */
113
-	public function cancel_subscription( $subscription, $invoice ) {
112
+     */
113
+    public function cancel_subscription( $subscription, $invoice ) {
114 114
 
115 115
         // Backwards compatibility. New version do not use authorize.net subscriptions.
116 116
         $this->post(
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     /**
129
-	 * Processes ipns.
130
-	 *
131
-	 * @return void
132
-	 */
133
-	public function verify_ipn() {
129
+     * Processes ipns.
130
+     *
131
+     * @return void
132
+     */
133
+    public function verify_ipn() {
134 134
 
135 135
         $this->maybe_process_old_ipn();
136 136
 
137 137
         // Validate the IPN.
138 138
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
139
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
139
+            wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
140 140
         }
141 141
 
142 142
         // Event type.
@@ -175,24 +175,24 @@  discard block
 block discarded – undo
175 175
     }
176 176
 
177 177
     /**
178
-	 * Validates IPN invoices.
179
-	 *
178
+     * Validates IPN invoices.
179
+     *
180 180
      * @param WPInv_Invoice $invoice
181 181
      * @param object $payload
182
-	 * @return void
183
-	 */
184
-	public function validate_ipn_invoice( $invoice, $payload ) {
182
+     * @return void
183
+     */
184
+    public function validate_ipn_invoice( $invoice, $payload ) {
185 185
         if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
186 186
             exit;
187 187
         }
188 188
     }
189 189
 
190 190
     /**
191
-	 * Process subscriptio IPNS.
192
-	 *
193
-	 * @return void
194
-	 */
195
-	public function maybe_process_old_ipn() {
191
+     * Process subscriptio IPNS.
192
+     *
193
+     * @return void
194
+     */
195
+    public function maybe_process_old_ipn() {
196 196
 
197 197
         $data = wp_kses_post_deep( wp_unslash( $_POST ) );
198 198
 
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
     }
235 235
 
236 236
     /**
237
-	 * Validates the old IPN signature.
237
+     * Validates the old IPN signature.
238 238
      *
239 239
      * @param array $posted
240
-	 */
241
-	public function validate_old_ipn_signature( $posted ) {
240
+     */
241
+    public function validate_old_ipn_signature( $posted ) {
242 242
 
243 243
         $signature = $this->get_option( 'signature_key' );
244 244
         if ( ! empty( $signature ) ) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
     }
257 257
 
258 258
     /**
259
-	 * Check Authorize.NET IPN validity.
260
-	 */
261
-	public function validate_ipn() {
259
+     * Check Authorize.NET IPN validity.
260
+     */
261
+    public function validate_ipn() {
262 262
 
263 263
         wpinv_error_log( 'Validating Authorize.NET IPN response' );
264 264
 
Please login to merge, or discard this patch.