Passed
Push — master ( 3bc955...30a2aa )
by Brian
08:45 queued 03:07
created
includes/reports/class-getpaid-reports-helper.php 2 patches
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -12,294 +12,294 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Helper {
14 14
 
15
-	/**
16
-	 * Get report totals such as invoice totals and discount amounts.
17
-	 *
18
-	 * Data example:
19
-	 *
20
-	 * 'subtotal' => array(
21
-	 *     'type'     => 'invoice_data',
22
-	 *     'function' => 'SUM',
23
-	 *     'name'     => 'subtotal'
24
-	 * )
25
-	 *
26
-	 * @param  array $args
27
-	 * @return mixed depending on query_type
28
-	 */
29
-	public static function get_invoice_report_data( $args = array() ) {
30
-		global $wpdb;
31
-
32
-		$default_args = array(
33
-			'data'                  => array(), // The data to retrieve.
34
-			'where'                 => array(), // An array of where queries.
35
-			'query_type'            => 'get_row', // wpdb query to run.
36
-			'group_by'              => '', // What to group results by.
37
-			'order_by'              => '', // What to order by.
38
-			'limit'                 => '', // Results limit.
39
-			'filter_range'          => array(), // An array of before and after dates to limit results by.
40
-			'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
-			'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
42
-			'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43
-		);
44
-
45
-		$args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
-		$args         = wp_parse_args( $args, $default_args );
47
-
48
-		extract( $args );
49
-
50
-		if ( empty( $data ) ) {
51
-			return '';
52
-		}
53
-
54
-		$query           = array();
55
-		$query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
56
-		$query['from']   = "FROM {$wpdb->posts} AS posts";
57
-		$query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
58
-
59
-		$query['where']  = "
15
+    /**
16
+     * Get report totals such as invoice totals and discount amounts.
17
+     *
18
+     * Data example:
19
+     *
20
+     * 'subtotal' => array(
21
+     *     'type'     => 'invoice_data',
22
+     *     'function' => 'SUM',
23
+     *     'name'     => 'subtotal'
24
+     * )
25
+     *
26
+     * @param  array $args
27
+     * @return mixed depending on query_type
28
+     */
29
+    public static function get_invoice_report_data( $args = array() ) {
30
+        global $wpdb;
31
+
32
+        $default_args = array(
33
+            'data'                  => array(), // The data to retrieve.
34
+            'where'                 => array(), // An array of where queries.
35
+            'query_type'            => 'get_row', // wpdb query to run.
36
+            'group_by'              => '', // What to group results by.
37
+            'order_by'              => '', // What to order by.
38
+            'limit'                 => '', // Results limit.
39
+            'filter_range'          => array(), // An array of before and after dates to limit results by.
40
+            'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
+            'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
42
+            'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43
+        );
44
+
45
+        $args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
+        $args         = wp_parse_args( $args, $default_args );
47
+
48
+        extract( $args );
49
+
50
+        if ( empty( $data ) ) {
51
+            return '';
52
+        }
53
+
54
+        $query           = array();
55
+        $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
56
+        $query['from']   = "FROM {$wpdb->posts} AS posts";
57
+        $query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
58
+
59
+        $query['where']  = "
60 60
 			WHERE 	posts.post_type 	IN ( '" . implode( "','", $invoice_types ) . "' )
61 61
 			";
62 62
 
63
-		if ( ! empty( $invoice_status ) ) {
64
-			$query['where'] .= "
63
+        if ( ! empty( $invoice_status ) ) {
64
+            $query['where'] .= "
65 65
 				AND 	posts.post_status 	IN ( '" . implode( "','", $invoice_status ) . "' )
66 66
 			";
67
-		}
68
-
69
-		if ( ! empty( $parent_invoice_status ) ) {
70
-			if ( ! empty( $invoice_status ) ) {
71
-				$query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
72
-			} else {
73
-				$query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
74
-			}
75
-		}
76
-
77
-		if ( ! empty( $filter_range['before'] ) ) {
78
-			$query['where'] .= "
67
+        }
68
+
69
+        if ( ! empty( $parent_invoice_status ) ) {
70
+            if ( ! empty( $invoice_status ) ) {
71
+                $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
72
+            } else {
73
+                $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
74
+            }
75
+        }
76
+
77
+        if ( ! empty( $filter_range['before'] ) ) {
78
+            $query['where'] .= "
79 79
 				AND 	posts.post_date < '" . date( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "'
80 80
 			";
81
-		}
81
+        }
82 82
 
83
-		if ( ! empty( $filter_range['after'] ) ) {
84
-			$query['where'] .= "
83
+        if ( ! empty( $filter_range['after'] ) ) {
84
+            $query['where'] .= "
85 85
 				AND 	posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "'
86 86
 			";
87
-		}
87
+        }
88 88
 
89
-		if ( ! empty( $where ) ) {
89
+        if ( ! empty( $where ) ) {
90 90
 
91
-			foreach ( $where as $value ) {
91
+            foreach ( $where as $value ) {
92 92
 
93
-				if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
94
-
95
-					if ( is_array( $value['value'] ) ) {
96
-						$value['value'] = implode( "','", $value['value'] );
97
-					}
98
-
99
-					if ( ! empty( $value['value'] ) ) {
100
-						$where_value = "{$value['operator']} ('{$value['value']}')";
101
-					}
102
-				} else {
103
-					$where_value = "{$value['operator']} '{$value['value']}'";
104
-				}
105
-
106
-				if ( ! empty( $where_value ) ) {
107
-					$query['where'] .= " AND {$value['key']} {$where_value}";
108
-				}
109
-			}
110
-		}
111
-
112
-		if ( $group_by ) {
113
-			$query['group_by'] = "GROUP BY {$group_by}";
114
-		}
115
-
116
-		if ( $order_by ) {
117
-			$query['order_by'] = "ORDER BY {$order_by}";
118
-		}
119
-
120
-		if ( $limit ) {
121
-			$query['limit'] = "LIMIT {$limit}";
122
-		}
123
-
124
-		$query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
-		$query = implode( ' ', $query );
126
-
127
-		return self::execute( $query_type, $query );
128
-
129
-	}
130
-
131
-	/**
132
-	 * Prepares the data to select.
133
-	 *
134
-	 *
135
-	 * @param  array $data
136
-	 * @return array
137
-	 */
138
-	public static function prepare_invoice_data( $data ) {
139
-
140
-		$prepared = array();
141
-
142
-		foreach ( $data as $raw_key => $value ) {
143
-			$key      = sanitize_key( $raw_key );
144
-			$distinct = '';
145
-
146
-			if ( isset( $value['distinct'] ) ) {
147
-				$distinct = 'DISTINCT';
148
-			}
149
-
150
-			$get_key = self::get_invoice_table_key( $key, $value['type'] );
151
-
152
-			if ( false === $get_key ) {
153
-				// Skip to the next foreach iteration else the query will be invalid.
154
-				continue;
155
-			}
156
-
157
-			if ( ! empty( $value['function'] ) ) {
158
-				$get = "{$value['function']}({$distinct} {$get_key})";
159
-			} else {
160
-				$get = "{$distinct} {$get_key}";
161
-			}
162
-
163
-			$prepared[] = "{$get} as {$value['name']}";
164
-		}
165
-
166
-		return $prepared;
167
-
168
-	}
169
-
170
-	/**
171
-	 * Prepares the joins to use.
172
-	 *
173
-	 *
174
-	 * @param  array $data
175
-	 * @param  bool $with_parent
176
-	 * @return array
177
-	 */
178
-	public static function prepare_invoice_joins( $data, $with_parent ) {
179
-		global $wpdb;
180
-
181
-		$prepared = array();
182
-
183
-		foreach ( $data as $raw_key => $value ) {
184
-			$join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
-			$type      = isset( $value['type'] ) ? $value['type'] : false;
186
-			$key       = sanitize_key( $raw_key );
187
-
188
-			switch ( $type ) {
189
-				case 'meta':
190
-					$prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191
-					break;
192
-				case 'parent_meta':
193
-					$prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194
-					break;
195
-				case 'invoice_data':
196
-					$prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
197
-					break;
198
-				case 'invoice_item':
199
-					$prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id";
200
-					break;
201
-			}
202
-		}
203
-
204
-		if ( $with_parent ) {
205
-			$prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206
-		}
207
-
208
-		return $prepared;
209
-
210
-	}
211
-
212
-	/**
213
-	 * Retrieves the appropriate table key to use.
214
-	 *
215
-	 *
216
-	 * @param  string $key
217
-	 * @param  string $table
218
-	 * @return string|false
219
-	 */
220
-	public static function get_invoice_table_key( $key, $table ) {
221
-
222
-		$keys = array(
223
-			'meta'         => "meta_{$key}.meta_value",
224
-			'parent_meta'  => "parent_meta_{$key}.meta_value",
225
-			'post_data'    => "posts.{$key}",
226
-			'invoice_data' => "invoices.{$key}",
227
-			'invoice_item' => "invoice_items.{$key}",
228
-		);
229
-
230
-		return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
231
-
232
-	}
233
-
234
-	/**
235
-	 * Executes a query and caches the result for a minute.
236
-	 *
237
-	 *
238
-	 * @param  string $query_type
239
-	 * @param  string $query
240
-	 * @return mixed depending on query_type
241
-	 */
242
-	public static function execute( $query_type, $query ) {
243
-		global $wpdb;
244
-
245
-		$query_hash = md5( $query_type . $query );
246
-		$result     = self::get_cached_query( $query_hash );
247
-		if ( $result === false ) {
248
-			self::enable_big_selects();
249
-
250
-			$result = $wpdb->$query_type( $query );
251
-			self::set_cached_query( $query_hash, $result );
252
-		}
253
-
254
-		return $result;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Enables big mysql selects for reports, just once for this session.
260
-	 */
261
-	protected static function enable_big_selects() {
262
-		static $big_selects = false;
263
-
264
-		global $wpdb;
265
-
266
-		if ( ! $big_selects ) {
267
-			$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
268
-			$big_selects = true;
269
-		}
270
-	}
271
-
272
-	/**
273
-	 * Get the cached query result or null if it's not in the cache.
274
-	 *
275
-	 * @param string $query_hash The query hash.
276
-	 *
277
-	 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278
-	 */
279
-	protected static function get_cached_query( $query_hash ) {
280
-
281
-		return wp_cache_get(
282
-			$query_hash,
283
-			strtolower( __CLASS__ )
284
-		);
285
-
286
-	}
287
-
288
-	/**
289
-	 * Set the cached query result.
290
-	 *
291
-	 * @param string $query_hash The query hash.
292
-	 * @param mixed  $data The data to cache.
293
-	 */
294
-	protected static function set_cached_query( $query_hash, $data ) {
295
-
296
-		wp_cache_set(
297
-			$query_hash,
298
-			$data,
299
-			strtolower( __CLASS__ ),
300
-			MINUTE_IN_SECONDS
301
-		);
302
-
303
-	}
93
+                if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
94
+
95
+                    if ( is_array( $value['value'] ) ) {
96
+                        $value['value'] = implode( "','", $value['value'] );
97
+                    }
98
+
99
+                    if ( ! empty( $value['value'] ) ) {
100
+                        $where_value = "{$value['operator']} ('{$value['value']}')";
101
+                    }
102
+                } else {
103
+                    $where_value = "{$value['operator']} '{$value['value']}'";
104
+                }
105
+
106
+                if ( ! empty( $where_value ) ) {
107
+                    $query['where'] .= " AND {$value['key']} {$where_value}";
108
+                }
109
+            }
110
+        }
111
+
112
+        if ( $group_by ) {
113
+            $query['group_by'] = "GROUP BY {$group_by}";
114
+        }
115
+
116
+        if ( $order_by ) {
117
+            $query['order_by'] = "ORDER BY {$order_by}";
118
+        }
119
+
120
+        if ( $limit ) {
121
+            $query['limit'] = "LIMIT {$limit}";
122
+        }
123
+
124
+        $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
+        $query = implode( ' ', $query );
126
+
127
+        return self::execute( $query_type, $query );
128
+
129
+    }
130
+
131
+    /**
132
+     * Prepares the data to select.
133
+     *
134
+     *
135
+     * @param  array $data
136
+     * @return array
137
+     */
138
+    public static function prepare_invoice_data( $data ) {
139
+
140
+        $prepared = array();
141
+
142
+        foreach ( $data as $raw_key => $value ) {
143
+            $key      = sanitize_key( $raw_key );
144
+            $distinct = '';
145
+
146
+            if ( isset( $value['distinct'] ) ) {
147
+                $distinct = 'DISTINCT';
148
+            }
149
+
150
+            $get_key = self::get_invoice_table_key( $key, $value['type'] );
151
+
152
+            if ( false === $get_key ) {
153
+                // Skip to the next foreach iteration else the query will be invalid.
154
+                continue;
155
+            }
156
+
157
+            if ( ! empty( $value['function'] ) ) {
158
+                $get = "{$value['function']}({$distinct} {$get_key})";
159
+            } else {
160
+                $get = "{$distinct} {$get_key}";
161
+            }
162
+
163
+            $prepared[] = "{$get} as {$value['name']}";
164
+        }
165
+
166
+        return $prepared;
167
+
168
+    }
169
+
170
+    /**
171
+     * Prepares the joins to use.
172
+     *
173
+     *
174
+     * @param  array $data
175
+     * @param  bool $with_parent
176
+     * @return array
177
+     */
178
+    public static function prepare_invoice_joins( $data, $with_parent ) {
179
+        global $wpdb;
180
+
181
+        $prepared = array();
182
+
183
+        foreach ( $data as $raw_key => $value ) {
184
+            $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
+            $type      = isset( $value['type'] ) ? $value['type'] : false;
186
+            $key       = sanitize_key( $raw_key );
187
+
188
+            switch ( $type ) {
189
+                case 'meta':
190
+                    $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191
+                    break;
192
+                case 'parent_meta':
193
+                    $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194
+                    break;
195
+                case 'invoice_data':
196
+                    $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
197
+                    break;
198
+                case 'invoice_item':
199
+                    $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id";
200
+                    break;
201
+            }
202
+        }
203
+
204
+        if ( $with_parent ) {
205
+            $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206
+        }
207
+
208
+        return $prepared;
209
+
210
+    }
211
+
212
+    /**
213
+     * Retrieves the appropriate table key to use.
214
+     *
215
+     *
216
+     * @param  string $key
217
+     * @param  string $table
218
+     * @return string|false
219
+     */
220
+    public static function get_invoice_table_key( $key, $table ) {
221
+
222
+        $keys = array(
223
+            'meta'         => "meta_{$key}.meta_value",
224
+            'parent_meta'  => "parent_meta_{$key}.meta_value",
225
+            'post_data'    => "posts.{$key}",
226
+            'invoice_data' => "invoices.{$key}",
227
+            'invoice_item' => "invoice_items.{$key}",
228
+        );
229
+
230
+        return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
231
+
232
+    }
233
+
234
+    /**
235
+     * Executes a query and caches the result for a minute.
236
+     *
237
+     *
238
+     * @param  string $query_type
239
+     * @param  string $query
240
+     * @return mixed depending on query_type
241
+     */
242
+    public static function execute( $query_type, $query ) {
243
+        global $wpdb;
244
+
245
+        $query_hash = md5( $query_type . $query );
246
+        $result     = self::get_cached_query( $query_hash );
247
+        if ( $result === false ) {
248
+            self::enable_big_selects();
249
+
250
+            $result = $wpdb->$query_type( $query );
251
+            self::set_cached_query( $query_hash, $result );
252
+        }
253
+
254
+        return $result;
255
+
256
+    }
257
+
258
+    /**
259
+     * Enables big mysql selects for reports, just once for this session.
260
+     */
261
+    protected static function enable_big_selects() {
262
+        static $big_selects = false;
263
+
264
+        global $wpdb;
265
+
266
+        if ( ! $big_selects ) {
267
+            $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
268
+            $big_selects = true;
269
+        }
270
+    }
271
+
272
+    /**
273
+     * Get the cached query result or null if it's not in the cache.
274
+     *
275
+     * @param string $query_hash The query hash.
276
+     *
277
+     * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278
+     */
279
+    protected static function get_cached_query( $query_hash ) {
280
+
281
+        return wp_cache_get(
282
+            $query_hash,
283
+            strtolower( __CLASS__ )
284
+        );
285
+
286
+    }
287
+
288
+    /**
289
+     * Set the cached query result.
290
+     *
291
+     * @param string $query_hash The query hash.
292
+     * @param mixed  $data The data to cache.
293
+     */
294
+    protected static function set_cached_query( $query_hash, $data ) {
295
+
296
+        wp_cache_set(
297
+            $query_hash,
298
+            $data,
299
+            strtolower( __CLASS__ ),
300
+            MINUTE_IN_SECONDS
301
+        );
302
+
303
+    }
304 304
 
305 305
 }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Helper Class.
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param  array $args
27 27
 	 * @return mixed depending on query_type
28 28
 	 */
29
-	public static function get_invoice_report_data( $args = array() ) {
29
+	public static function get_invoice_report_data($args = array()) {
30 30
 		global $wpdb;
31 31
 
32 32
 		$default_args = array(
@@ -37,94 +37,94 @@  discard block
 block discarded – undo
37 37
 			'order_by'              => '', // What to order by.
38 38
 			'limit'                 => '', // Results limit.
39 39
 			'filter_range'          => array(), // An array of before and after dates to limit results by.
40
-			'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
-			'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
40
+			'invoice_types'         => array('wpi_invoice'), // An array of post types to retrieve.
41
+			'invoice_status'        => array('publish', 'wpi-processing', 'wpi-onhold'),
42 42
 			'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43 43
 		);
44 44
 
45
-		$args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
-		$args         = wp_parse_args( $args, $default_args );
45
+		$args         = apply_filters('getpaid_reports_get_invoice_report_data_args', $args);
46
+		$args         = wp_parse_args($args, $default_args);
47 47
 
48
-		extract( $args );
48
+		extract($args);
49 49
 
50
-		if ( empty( $data ) ) {
50
+		if (empty($data)) {
51 51
 			return '';
52 52
 		}
53 53
 
54 54
 		$query           = array();
55
-		$query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
55
+		$query['select'] = 'SELECT ' . implode(',', self::prepare_invoice_data($data));
56 56
 		$query['from']   = "FROM {$wpdb->posts} AS posts";
57
-		$query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
57
+		$query['join']   = implode(' ', self::prepare_invoice_joins($data + $where, !empty($parent_invoice_status)));
58 58
 
59 59
 		$query['where']  = "
60
-			WHERE 	posts.post_type 	IN ( '" . implode( "','", $invoice_types ) . "' )
60
+			WHERE 	posts.post_type 	IN ( '" . implode("','", $invoice_types) . "' )
61 61
 			";
62 62
 
63
-		if ( ! empty( $invoice_status ) ) {
63
+		if (!empty($invoice_status)) {
64 64
 			$query['where'] .= "
65
-				AND 	posts.post_status 	IN ( '" . implode( "','", $invoice_status ) . "' )
65
+				AND 	posts.post_status 	IN ( '" . implode("','", $invoice_status) . "' )
66 66
 			";
67 67
 		}
68 68
 
69
-		if ( ! empty( $parent_invoice_status ) ) {
70
-			if ( ! empty( $invoice_status ) ) {
71
-				$query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
69
+		if (!empty($parent_invoice_status)) {
70
+			if (!empty($invoice_status)) {
71
+				$query['where'] .= " AND ( parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) OR parent.ID IS NULL ) ";
72 72
 			} else {
73
-				$query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
73
+				$query['where'] .= " AND parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) ";
74 74
 			}
75 75
 		}
76 76
 
77
-		if ( ! empty( $filter_range['before'] ) ) {
77
+		if (!empty($filter_range['before'])) {
78 78
 			$query['where'] .= "
79
-				AND 	posts.post_date < '" . date( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "'
79
+				AND 	posts.post_date < '" . date('Y-m-d 23:59:59', strtotime($filter_range['before'])) . "'
80 80
 			";
81 81
 		}
82 82
 
83
-		if ( ! empty( $filter_range['after'] ) ) {
83
+		if (!empty($filter_range['after'])) {
84 84
 			$query['where'] .= "
85
-				AND 	posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "'
85
+				AND 	posts.post_date > '" . date('Y-m-d H:i:s', strtotime($filter_range['after'])) . "'
86 86
 			";
87 87
 		}
88 88
 
89
-		if ( ! empty( $where ) ) {
89
+		if (!empty($where)) {
90 90
 
91
-			foreach ( $where as $value ) {
91
+			foreach ($where as $value) {
92 92
 
93
-				if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
93
+				if (strtolower($value['operator']) == 'in' || strtolower($value['operator']) == 'not in') {
94 94
 
95
-					if ( is_array( $value['value'] ) ) {
96
-						$value['value'] = implode( "','", $value['value'] );
95
+					if (is_array($value['value'])) {
96
+						$value['value'] = implode("','", $value['value']);
97 97
 					}
98 98
 
99
-					if ( ! empty( $value['value'] ) ) {
99
+					if (!empty($value['value'])) {
100 100
 						$where_value = "{$value['operator']} ('{$value['value']}')";
101 101
 					}
102 102
 				} else {
103 103
 					$where_value = "{$value['operator']} '{$value['value']}'";
104 104
 				}
105 105
 
106
-				if ( ! empty( $where_value ) ) {
106
+				if (!empty($where_value)) {
107 107
 					$query['where'] .= " AND {$value['key']} {$where_value}";
108 108
 				}
109 109
 			}
110 110
 		}
111 111
 
112
-		if ( $group_by ) {
112
+		if ($group_by) {
113 113
 			$query['group_by'] = "GROUP BY {$group_by}";
114 114
 		}
115 115
 
116
-		if ( $order_by ) {
116
+		if ($order_by) {
117 117
 			$query['order_by'] = "ORDER BY {$order_by}";
118 118
 		}
119 119
 
120
-		if ( $limit ) {
120
+		if ($limit) {
121 121
 			$query['limit'] = "LIMIT {$limit}";
122 122
 		}
123 123
 
124
-		$query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
-		$query = implode( ' ', $query );
124
+		$query = apply_filters('getpaid_reports_get_invoice_report_query', $query, $data);
125
+		$query = implode(' ', $query);
126 126
 
127
-		return self::execute( $query_type, $query );
127
+		return self::execute($query_type, $query);
128 128
 
129 129
 	}
130 130
 
@@ -135,26 +135,26 @@  discard block
 block discarded – undo
135 135
 	 * @param  array $data
136 136
 	 * @return array
137 137
 	 */
138
-	public static function prepare_invoice_data( $data ) {
138
+	public static function prepare_invoice_data($data) {
139 139
 
140 140
 		$prepared = array();
141 141
 
142
-		foreach ( $data as $raw_key => $value ) {
143
-			$key      = sanitize_key( $raw_key );
142
+		foreach ($data as $raw_key => $value) {
143
+			$key      = sanitize_key($raw_key);
144 144
 			$distinct = '';
145 145
 
146
-			if ( isset( $value['distinct'] ) ) {
146
+			if (isset($value['distinct'])) {
147 147
 				$distinct = 'DISTINCT';
148 148
 			}
149 149
 
150
-			$get_key = self::get_invoice_table_key( $key, $value['type'] );
150
+			$get_key = self::get_invoice_table_key($key, $value['type']);
151 151
 
152
-			if ( false === $get_key ) {
152
+			if (false === $get_key) {
153 153
 				// Skip to the next foreach iteration else the query will be invalid.
154 154
 				continue;
155 155
 			}
156 156
 
157
-			if ( ! empty( $value['function'] ) ) {
157
+			if (!empty($value['function'])) {
158 158
 				$get = "{$value['function']}({$distinct} {$get_key})";
159 159
 			} else {
160 160
 				$get = "{$distinct} {$get_key}";
@@ -175,22 +175,22 @@  discard block
 block discarded – undo
175 175
 	 * @param  bool $with_parent
176 176
 	 * @return array
177 177
 	 */
178
-	public static function prepare_invoice_joins( $data, $with_parent ) {
178
+	public static function prepare_invoice_joins($data, $with_parent) {
179 179
 		global $wpdb;
180 180
 
181 181
 		$prepared = array();
182 182
 
183
-		foreach ( $data as $raw_key => $value ) {
184
-			$join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
-			$type      = isset( $value['type'] ) ? $value['type'] : false;
186
-			$key       = sanitize_key( $raw_key );
183
+		foreach ($data as $raw_key => $value) {
184
+			$join_type = isset($value['join_type']) ? $value['join_type'] : 'INNER';
185
+			$type      = isset($value['type']) ? $value['type'] : false;
186
+			$key       = sanitize_key($raw_key);
187 187
 
188
-			switch ( $type ) {
188
+			switch ($type) {
189 189
 				case 'meta':
190
-					$prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
190
+					$prepared["meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191 191
 					break;
192 192
 				case 'parent_meta':
193
-					$prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
193
+					$prepared["parent_meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194 194
 					break;
195 195
 				case 'invoice_data':
196 196
 					$prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			}
202 202
 		}
203 203
 
204
-		if ( $with_parent ) {
204
+		if ($with_parent) {
205 205
 			$prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206 206
 		}
207 207
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param  string $table
218 218
 	 * @return string|false
219 219
 	 */
220
-	public static function get_invoice_table_key( $key, $table ) {
220
+	public static function get_invoice_table_key($key, $table) {
221 221
 
222 222
 		$keys = array(
223 223
 			'meta'         => "meta_{$key}.meta_value",
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 			'invoice_item' => "invoice_items.{$key}",
228 228
 		);
229 229
 
230
-		return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
230
+		return isset($keys[$table]) ? $keys[$table] : false;
231 231
 
232 232
 	}
233 233
 
@@ -239,16 +239,16 @@  discard block
 block discarded – undo
239 239
 	 * @param  string $query
240 240
 	 * @return mixed depending on query_type
241 241
 	 */
242
-	public static function execute( $query_type, $query ) {
242
+	public static function execute($query_type, $query) {
243 243
 		global $wpdb;
244 244
 
245
-		$query_hash = md5( $query_type . $query );
246
-		$result     = self::get_cached_query( $query_hash );
247
-		if ( $result === false ) {
245
+		$query_hash = md5($query_type . $query);
246
+		$result     = self::get_cached_query($query_hash);
247
+		if ($result === false) {
248 248
 			self::enable_big_selects();
249 249
 
250
-			$result = $wpdb->$query_type( $query );
251
-			self::set_cached_query( $query_hash, $result );
250
+			$result = $wpdb->$query_type($query);
251
+			self::set_cached_query($query_hash, $result);
252 252
 		}
253 253
 
254 254
 		return $result;
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 
264 264
 		global $wpdb;
265 265
 
266
-		if ( ! $big_selects ) {
267
-			$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
266
+		if (!$big_selects) {
267
+			$wpdb->query('SET SESSION SQL_BIG_SELECTS=1');
268 268
 			$big_selects = true;
269 269
 		}
270 270
 	}
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278 278
 	 */
279
-	protected static function get_cached_query( $query_hash ) {
279
+	protected static function get_cached_query($query_hash) {
280 280
 
281 281
 		return wp_cache_get(
282 282
 			$query_hash,
283
-			strtolower( __CLASS__ )
283
+			strtolower(__CLASS__)
284 284
 		);
285 285
 
286 286
 	}
@@ -291,12 +291,12 @@  discard block
 block discarded – undo
291 291
 	 * @param string $query_hash The query hash.
292 292
 	 * @param mixed  $data The data to cache.
293 293
 	 */
294
-	protected static function set_cached_query( $query_hash, $data ) {
294
+	protected static function set_cached_query($query_hash, $data) {
295 295
 
296 296
 		wp_cache_set(
297 297
 			$query_hash,
298 298
 			$data,
299
-			strtolower( __CLASS__ ),
299
+			strtolower(__CLASS__),
300 300
 			MINUTE_IN_SECONDS
301 301
 		);
302 302
 
Please login to merge, or discard this patch.
templates/wpinv-invoice-print.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Fetch the invoice.
13
-if ( empty( $invoice ) ) {
14
-    $invoice = new WPInv_Invoice( $GLOBALS['post'] );
13
+if (empty($invoice)) {
14
+    $invoice = new WPInv_Invoice($GLOBALS['post']);
15 15
 }
16 16
 
17 17
 // Abort if it does not exist.
18
-if ( $invoice->get_id() == 0 ) {
18
+if ($invoice->get_id() == 0) {
19 19
     exit;
20 20
 }
21 21
 
22 22
 // Fires before printing an invoice.
23
-do_action( 'wpinv_invoice_print_before_display', $invoice );
23
+do_action('wpinv_invoice_print_before_display', $invoice);
24 24
 
25 25
 ?><!DOCTYPE html>
26 26
 
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
 
30 30
     <head>
31 31
 
32
-		<meta charset="<?php bloginfo( 'charset' ); ?>">
32
+		<meta charset="<?php bloginfo('charset'); ?>">
33 33
         <meta name="viewport" content="width=device-width, initial-scale=1.0" >
34 34
 
35 35
         <meta name="robots" content="noindex,nofollow">
36 36
 
37 37
 		<link rel="profile" href="https://gmpg.org/xfn/11">
38 38
 
39
-        <title>#<?php echo esc_html( $invoice->get_number() ); ?></title>
39
+        <title>#<?php echo esc_html($invoice->get_number()); ?></title>
40 40
 
41
-        <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?>
41
+        <?php do_action('wpinv_invoice_print_head', $invoice); ?>
42 42
 
43 43
         <style type="text/css">
44 44
 			.body{ 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
     <body class="body wpinv wpinv-print" style="font-weight: 400;">
71 71
 
72 72
         <div id="wpinv-print-inner">
73
-            <?php do_action( 'getpaid_invoice', $invoice ); ?>
74
-            <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?>
73
+            <?php do_action('getpaid_invoice', $invoice); ?>
74
+            <?php do_action('wpinv_invoice_print_body_end', $invoice); ?>
75 75
         </div>
76 76
     </body>
77 77
 
Please login to merge, or discard this patch.
vendor/ayecode/ayecode-connect-helper/ayecode-connect-helper.php 2 patches
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -1,271 +1,271 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit;
4
+    exit;
5 5
 }
6 6
 
7 7
 if ( ! class_exists( "AyeCode_Connect_Helper" ) ) {
8
-	/**
9
-	 * Allow the quick setup and connection of our AyeCode Connect plugin.
10
-	 *
11
-	 * Class AyeCode_Connect_Helper
12
-	 */
13
-	class AyeCode_Connect_Helper {
14
-
15
-		// Hold the version number
16
-		var $version = "1.0.3";
17
-
18
-		// Hold the default strings.
19
-		var $strings = array();
20
-
21
-		// Hold the default pages.
22
-		var $pages = array();
23
-
24
-		/**
25
-		 * The constructor.
26
-		 *
27
-		 * AyeCode_Connect_Helper constructor.
28
-		 *
29
-		 * @param array $strings
30
-		 * @param array $pages
31
-		 */
32
-		public function __construct( $strings = array(), $pages = array() ) {
33
-
34
-			// Only fire if not localhost and the current user has the right permissions.
35
-			if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) {
36
-
37
-
38
-				// set default strings
39
-				$default_strings = array(
40
-					'connect_title'     => __( "Thanks for choosing an AyeCode Product!" ),
41
-					'connect_external'  => __( "Please confirm you wish to connect your site?" ),
42
-					'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" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
43
-					'connect_button'    => __( "Connect Site" ),
44
-					'connecting_button' => __( "Connecting..." ),
45
-					'error_localhost'   => __( "This service will only work with a live domain, not a localhost." ),
46
-					'error'             => __( "Something went wrong, please refresh and try again." ),
47
-				);
48
-				$this->strings   = array_merge( $default_strings, $strings );
49
-
50
-
51
-				// set default pages
52
-				$default_pages = array();
53
-				$this->pages   = array_merge( $default_pages, $pages );
54
-
55
-				// maybe show connect site notice
56
-				add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) );
57
-
58
-				// add ajax action if not already added
59
-				if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) {
60
-					add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) );
61
-				}
62
-			}
63
-
64
-			// add ajax action if not already added
65
-			if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) {
66
-				add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) );
67
-			}
68
-
69
-		}
70
-
71
-		/**
72
-		 * Give a way to check we can connect via a external redirect.
73
-		 */
74
-		public function ayecode_connect_helper_installed(){
75
-			$active = array(
76
-				'gd'    =>  defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0,
77
-				'uwp'    =>  defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0,
78
-				'wpi'    =>  defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0,
79
-			);
80
-			wp_send_json_success( $active );
81
-			wp_die();
82
-		}
83
-
84
-		/**
85
-		 * Get slug from path
86
-		 *
87
-		 * @param  string $key
88
-		 *
89
-		 * @return string
90
-		 */
91
-		private function format_plugin_slug( $key ) {
92
-			$slug = explode( '/', $key );
93
-			$slug = explode( '.', end( $slug ) );
94
-
95
-			return $slug[0];
96
-		}
97
-
98
-		/**
99
-		 * Install and activate the AyeCode Connect Plugin
100
-		 */
101
-		public function ayecode_connect_install() {
102
-
103
-			// bail if localhost
104
-			if ( $this->is_localhost() ) {
105
-				wp_send_json_error( $this->strings['error_localhost'] );
106
-			}
107
-
108
-			// Explicitly clear the event.
109
-			wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() );
110
-
111
-			$success     = true;
112
-			$plugin_slug = "ayecode-connect";
113
-			if ( ! empty( $plugin_slug ) ) {
114
-				require_once( ABSPATH . 'wp-admin/includes/file.php' );
115
-				require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
116
-				require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
117
-				require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
118
-
119
-				WP_Filesystem();
120
-
121
-				$skin              = new Automatic_Upgrader_Skin;
122
-				$upgrader          = new WP_Upgrader( $skin );
123
-				$installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) );
124
-				$plugin_slug       = $plugin_slug;
125
-				$plugin            = $plugin_slug . '/' . $plugin_slug . '.php';
126
-				$installed         = false;
127
-				$activate          = false;
128
-
129
-				// See if the plugin is installed already
130
-				if ( in_array( $plugin_slug, $installed_plugins ) ) {
131
-					$installed = true;
132
-					$activate  = ! is_plugin_active( $plugin );
133
-				}
134
-
135
-				// Install this thing!
136
-				if ( ! $installed ) {
137
-
138
-					// Suppress feedback
139
-					ob_start();
140
-
141
-					try {
142
-						$plugin_information = plugins_api( 'plugin_information', array(
143
-							'slug'   => $plugin_slug,
144
-							'fields' => array(
145
-								'short_description' => false,
146
-								'sections'          => false,
147
-								'requires'          => false,
148
-								'rating'            => false,
149
-								'ratings'           => false,
150
-								'downloaded'        => false,
151
-								'last_updated'      => false,
152
-								'added'             => false,
153
-								'tags'              => false,
154
-								'homepage'          => false,
155
-								'donate_link'       => false,
156
-								'author_profile'    => false,
157
-								'author'            => false,
158
-							),
159
-						) );
160
-
161
-						if ( is_wp_error( $plugin_information ) ) {
162
-							throw new Exception( $plugin_information->get_error_message() );
163
-						}
164
-
165
-						$package  = $plugin_information->download_link;
166
-						$download = $upgrader->download_package( $package );
167
-
168
-						if ( is_wp_error( $download ) ) {
169
-							throw new Exception( $download->get_error_message() );
170
-						}
171
-
172
-						$working_dir = $upgrader->unpack_package( $download, true );
173
-
174
-						if ( is_wp_error( $working_dir ) ) {
175
-							throw new Exception( $working_dir->get_error_message() );
176
-						}
177
-
178
-						$result = $upgrader->install_package( array(
179
-							'source'                      => $working_dir,
180
-							'destination'                 => WP_PLUGIN_DIR,
181
-							'clear_destination'           => false,
182
-							'abort_if_destination_exists' => false,
183
-							'clear_working'               => true,
184
-							'hook_extra'                  => array(
185
-								'type'   => 'plugin',
186
-								'action' => 'install',
187
-							),
188
-						) );
189
-
190
-						if ( is_wp_error( $result ) ) {
191
-							throw new Exception( $result->get_error_message() );
192
-						}
193
-
194
-						$activate = true;
195
-
196
-					} catch ( Exception $e ) {
197
-						$success = false;
198
-					}
199
-
200
-					// Discard feedback
201
-					ob_end_clean();
202
-				}
203
-
204
-				wp_clean_plugins_cache();
205
-
206
-				// Activate this thing
207
-				if ( $activate ) {
208
-					try {
209
-						$result = activate_plugin( $plugin );
210
-
211
-						if ( is_wp_error( $result ) ) {
212
-							$success = false;
213
-						} else {
214
-							$success = true;
215
-						}
216
-					} catch ( Exception $e ) {
217
-						$success = false;
218
-					}
219
-				}
220
-			}
221
-
222
-			if ( $success && function_exists( 'ayecode_connect_args' ) ) {
223
-				ayecode_connect();// init
224
-				$args        = ayecode_connect_args();
225
-				$client      = new AyeCode_Connect( $args );
226
-				$redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : '';
227
-				$redirect    = $client->build_connect_url( $redirect_to );
228
-				wp_send_json_success( array( 'connect_url' => $redirect ) );
229
-			} else {
230
-				wp_send_json_error( $this->strings['error_localhost'] );
231
-			}
232
-			wp_die();
233
-		}
234
-
235
-		/**
236
-		 * Check if maybe localhost.
237
-		 *
238
-		 * @return bool
239
-		 */
240
-		public function is_localhost() {
241
-			$localhost = false;
242
-
243
-			$host              = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '';
244
-			$localhost_domains = array(
245
-				'localhost',
246
-				'localhost.localdomain',
247
-				'127.0.0.1',
248
-				'::1'
249
-			);
250
-
251
-			if ( in_array( $host, $localhost_domains ) ) {
252
-				$localhost = true;
253
-			}
254
-
255
-			return $localhost;
256
-		}
257
-
258
-		/**
259
-		 * Show notice to connect site.
260
-		 */
261
-		public function ayecode_connect_install_notice() {
262
-			if ( $this->maybe_show() ) {
263
-				$connect_title_string     = $this->strings['connect_title'];
264
-				$connect_external_string  = $this->strings['connect_external'];
265
-				$connect_string           = $this->strings['connect'];
266
-				$connect_button_string    = $this->strings['connect_button'];
267
-				$connecting_button_string = $this->strings['connecting_button'];
268
-				?>
8
+    /**
9
+     * Allow the quick setup and connection of our AyeCode Connect plugin.
10
+     *
11
+     * Class AyeCode_Connect_Helper
12
+     */
13
+    class AyeCode_Connect_Helper {
14
+
15
+        // Hold the version number
16
+        var $version = "1.0.3";
17
+
18
+        // Hold the default strings.
19
+        var $strings = array();
20
+
21
+        // Hold the default pages.
22
+        var $pages = array();
23
+
24
+        /**
25
+         * The constructor.
26
+         *
27
+         * AyeCode_Connect_Helper constructor.
28
+         *
29
+         * @param array $strings
30
+         * @param array $pages
31
+         */
32
+        public function __construct( $strings = array(), $pages = array() ) {
33
+
34
+            // Only fire if not localhost and the current user has the right permissions.
35
+            if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) {
36
+
37
+
38
+                // set default strings
39
+                $default_strings = array(
40
+                    'connect_title'     => __( "Thanks for choosing an AyeCode Product!" ),
41
+                    'connect_external'  => __( "Please confirm you wish to connect your site?" ),
42
+                    '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" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
43
+                    'connect_button'    => __( "Connect Site" ),
44
+                    'connecting_button' => __( "Connecting..." ),
45
+                    'error_localhost'   => __( "This service will only work with a live domain, not a localhost." ),
46
+                    'error'             => __( "Something went wrong, please refresh and try again." ),
47
+                );
48
+                $this->strings   = array_merge( $default_strings, $strings );
49
+
50
+
51
+                // set default pages
52
+                $default_pages = array();
53
+                $this->pages   = array_merge( $default_pages, $pages );
54
+
55
+                // maybe show connect site notice
56
+                add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) );
57
+
58
+                // add ajax action if not already added
59
+                if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) {
60
+                    add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) );
61
+                }
62
+            }
63
+
64
+            // add ajax action if not already added
65
+            if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) {
66
+                add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) );
67
+            }
68
+
69
+        }
70
+
71
+        /**
72
+         * Give a way to check we can connect via a external redirect.
73
+         */
74
+        public function ayecode_connect_helper_installed(){
75
+            $active = array(
76
+                'gd'    =>  defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0,
77
+                'uwp'    =>  defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0,
78
+                'wpi'    =>  defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0,
79
+            );
80
+            wp_send_json_success( $active );
81
+            wp_die();
82
+        }
83
+
84
+        /**
85
+         * Get slug from path
86
+         *
87
+         * @param  string $key
88
+         *
89
+         * @return string
90
+         */
91
+        private function format_plugin_slug( $key ) {
92
+            $slug = explode( '/', $key );
93
+            $slug = explode( '.', end( $slug ) );
94
+
95
+            return $slug[0];
96
+        }
97
+
98
+        /**
99
+         * Install and activate the AyeCode Connect Plugin
100
+         */
101
+        public function ayecode_connect_install() {
102
+
103
+            // bail if localhost
104
+            if ( $this->is_localhost() ) {
105
+                wp_send_json_error( $this->strings['error_localhost'] );
106
+            }
107
+
108
+            // Explicitly clear the event.
109
+            wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() );
110
+
111
+            $success     = true;
112
+            $plugin_slug = "ayecode-connect";
113
+            if ( ! empty( $plugin_slug ) ) {
114
+                require_once( ABSPATH . 'wp-admin/includes/file.php' );
115
+                require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
116
+                require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
117
+                require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
118
+
119
+                WP_Filesystem();
120
+
121
+                $skin              = new Automatic_Upgrader_Skin;
122
+                $upgrader          = new WP_Upgrader( $skin );
123
+                $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) );
124
+                $plugin_slug       = $plugin_slug;
125
+                $plugin            = $plugin_slug . '/' . $plugin_slug . '.php';
126
+                $installed         = false;
127
+                $activate          = false;
128
+
129
+                // See if the plugin is installed already
130
+                if ( in_array( $plugin_slug, $installed_plugins ) ) {
131
+                    $installed = true;
132
+                    $activate  = ! is_plugin_active( $plugin );
133
+                }
134
+
135
+                // Install this thing!
136
+                if ( ! $installed ) {
137
+
138
+                    // Suppress feedback
139
+                    ob_start();
140
+
141
+                    try {
142
+                        $plugin_information = plugins_api( 'plugin_information', array(
143
+                            'slug'   => $plugin_slug,
144
+                            'fields' => array(
145
+                                'short_description' => false,
146
+                                'sections'          => false,
147
+                                'requires'          => false,
148
+                                'rating'            => false,
149
+                                'ratings'           => false,
150
+                                'downloaded'        => false,
151
+                                'last_updated'      => false,
152
+                                'added'             => false,
153
+                                'tags'              => false,
154
+                                'homepage'          => false,
155
+                                'donate_link'       => false,
156
+                                'author_profile'    => false,
157
+                                'author'            => false,
158
+                            ),
159
+                        ) );
160
+
161
+                        if ( is_wp_error( $plugin_information ) ) {
162
+                            throw new Exception( $plugin_information->get_error_message() );
163
+                        }
164
+
165
+                        $package  = $plugin_information->download_link;
166
+                        $download = $upgrader->download_package( $package );
167
+
168
+                        if ( is_wp_error( $download ) ) {
169
+                            throw new Exception( $download->get_error_message() );
170
+                        }
171
+
172
+                        $working_dir = $upgrader->unpack_package( $download, true );
173
+
174
+                        if ( is_wp_error( $working_dir ) ) {
175
+                            throw new Exception( $working_dir->get_error_message() );
176
+                        }
177
+
178
+                        $result = $upgrader->install_package( array(
179
+                            'source'                      => $working_dir,
180
+                            'destination'                 => WP_PLUGIN_DIR,
181
+                            'clear_destination'           => false,
182
+                            'abort_if_destination_exists' => false,
183
+                            'clear_working'               => true,
184
+                            'hook_extra'                  => array(
185
+                                'type'   => 'plugin',
186
+                                'action' => 'install',
187
+                            ),
188
+                        ) );
189
+
190
+                        if ( is_wp_error( $result ) ) {
191
+                            throw new Exception( $result->get_error_message() );
192
+                        }
193
+
194
+                        $activate = true;
195
+
196
+                    } catch ( Exception $e ) {
197
+                        $success = false;
198
+                    }
199
+
200
+                    // Discard feedback
201
+                    ob_end_clean();
202
+                }
203
+
204
+                wp_clean_plugins_cache();
205
+
206
+                // Activate this thing
207
+                if ( $activate ) {
208
+                    try {
209
+                        $result = activate_plugin( $plugin );
210
+
211
+                        if ( is_wp_error( $result ) ) {
212
+                            $success = false;
213
+                        } else {
214
+                            $success = true;
215
+                        }
216
+                    } catch ( Exception $e ) {
217
+                        $success = false;
218
+                    }
219
+                }
220
+            }
221
+
222
+            if ( $success && function_exists( 'ayecode_connect_args' ) ) {
223
+                ayecode_connect();// init
224
+                $args        = ayecode_connect_args();
225
+                $client      = new AyeCode_Connect( $args );
226
+                $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : '';
227
+                $redirect    = $client->build_connect_url( $redirect_to );
228
+                wp_send_json_success( array( 'connect_url' => $redirect ) );
229
+            } else {
230
+                wp_send_json_error( $this->strings['error_localhost'] );
231
+            }
232
+            wp_die();
233
+        }
234
+
235
+        /**
236
+         * Check if maybe localhost.
237
+         *
238
+         * @return bool
239
+         */
240
+        public function is_localhost() {
241
+            $localhost = false;
242
+
243
+            $host              = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '';
244
+            $localhost_domains = array(
245
+                'localhost',
246
+                'localhost.localdomain',
247
+                '127.0.0.1',
248
+                '::1'
249
+            );
250
+
251
+            if ( in_array( $host, $localhost_domains ) ) {
252
+                $localhost = true;
253
+            }
254
+
255
+            return $localhost;
256
+        }
257
+
258
+        /**
259
+         * Show notice to connect site.
260
+         */
261
+        public function ayecode_connect_install_notice() {
262
+            if ( $this->maybe_show() ) {
263
+                $connect_title_string     = $this->strings['connect_title'];
264
+                $connect_external_string  = $this->strings['connect_external'];
265
+                $connect_string           = $this->strings['connect'];
266
+                $connect_button_string    = $this->strings['connect_button'];
267
+                $connecting_button_string = $this->strings['connecting_button'];
268
+                ?>
269 269
 				<div class="notice notice-info acch-notice">
270 270
 					<span class="acch-float-left">
271 271
 						<svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1"
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 						<h3 class="acch-title"><?php echo esc_html( $connect_title_string ); ?></h3>
305 305
 					<p>
306 306
 						<?php
307
-						echo wp_kses_post( $connect_string );
308
-						?>
307
+                        echo wp_kses_post( $connect_string );
308
+                        ?>
309 309
 					</p>
310 310
 					</span>
311 311
 
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
 				</div>
319 319
 
320 320
 				<?php
321
-				// only include the popup HTML if needed.
322
-				if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
323
-					?>
321
+                // only include the popup HTML if needed.
322
+                if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
323
+                    ?>
324 324
 					<div id="ayecode-connect-helper-external-confirm" style="display:none;">
325 325
 						<div class="noticex notice-info acch-notice" style="border: none;">
326 326
 					<span class="acch-float-left">
@@ -369,23 +369,23 @@  discard block
 block discarded – undo
369 369
 						</div>
370 370
 					</div>
371 371
 					<?php
372
-				}
373
-
374
-				// add required scripts
375
-				$this->script();
376
-			}
377
-		}
378
-
379
-		/**
380
-		 * Get the JS Script.
381
-		 */
382
-		public function script() {
383
-
384
-			// add thickbox if external request is requested
385
-			if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
386
-				add_thickbox();
387
-			}
388
-			?>
372
+                }
373
+
374
+                // add required scripts
375
+                $this->script();
376
+            }
377
+        }
378
+
379
+        /**
380
+         * Get the JS Script.
381
+         */
382
+        public function script() {
383
+
384
+            // add thickbox if external request is requested
385
+            if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
386
+                add_thickbox();
387
+            }
388
+            ?>
389 389
 			<style>
390 390
 				.acch-title {
391 391
 					margin: 0;
@@ -454,43 +454,43 @@  discard block
 block discarded – undo
454 454
 
455 455
 
456 456
 				<?php
457
-				// add thickbox if external request is requested
458
-				if(! empty( $_REQUEST['external-connect-request'] )) {
459
-				?>
457
+                // add thickbox if external request is requested
458
+                if(! empty( $_REQUEST['external-connect-request'] )) {
459
+                ?>
460 460
 				jQuery(function () {
461 461
 					setTimeout(function () {
462 462
 						tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm");
463 463
 					}, 200);
464 464
 				});
465 465
 				<?php
466
-				}
467
-				?>
466
+                }
467
+                ?>
468 468
 
469 469
 			</script>
470 470
 			<?php
471
-		}
472
-
473
-		/**
474
-		 * Decide what pages to show on.
475
-		 *
476
-		 * @return bool
477
-		 */
478
-		public function maybe_show() {
479
-			$show = false;
480
-
481
-			// check if on a page set to show
482
-			if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) {
483
-
484
-				// check if not active and connected
485
-				if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) {
486
-					$show = true;
487
-				}
471
+        }
472
+
473
+        /**
474
+         * Decide what pages to show on.
475
+         *
476
+         * @return bool
477
+         */
478
+        public function maybe_show() {
479
+            $show = false;
480
+
481
+            // check if on a page set to show
482
+            if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) {
483
+
484
+                // check if not active and connected
485
+                if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) {
486
+                    $show = true;
487
+                }
488 488
 
489
-			}
489
+            }
490 490
 
491
-			return $show;
492
-		}
491
+            return $show;
492
+        }
493 493
 
494
-	}
494
+    }
495 495
 
496 496
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit;
5 5
 }
6 6
 
7
-if ( ! class_exists( "AyeCode_Connect_Helper" ) ) {
7
+if (!class_exists("AyeCode_Connect_Helper")) {
8 8
 	/**
9 9
 	 * Allow the quick setup and connection of our AyeCode Connect plugin.
10 10
 	 *
@@ -29,41 +29,41 @@  discard block
 block discarded – undo
29 29
 		 * @param array $strings
30 30
 		 * @param array $pages
31 31
 		 */
32
-		public function __construct( $strings = array(), $pages = array() ) {
32
+		public function __construct($strings = array(), $pages = array()) {
33 33
 
34 34
 			// Only fire if not localhost and the current user has the right permissions.
35
-			if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) {
35
+			if (!$this->is_localhost() && current_user_can('manage_options')) {
36 36
 
37 37
 
38 38
 				// set default strings
39 39
 				$default_strings = array(
40
-					'connect_title'     => __( "Thanks for choosing an AyeCode Product!" ),
41
-					'connect_external'  => __( "Please confirm you wish to connect your site?" ),
42
-					'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" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
43
-					'connect_button'    => __( "Connect Site" ),
44
-					'connecting_button' => __( "Connecting..." ),
45
-					'error_localhost'   => __( "This service will only work with a live domain, not a localhost." ),
46
-					'error'             => __( "Something went wrong, please refresh and try again." ),
40
+					'connect_title'     => __("Thanks for choosing an AyeCode Product!"),
41
+					'connect_external'  => __("Please confirm you wish to connect your site?"),
42
+					'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"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
43
+					'connect_button'    => __("Connect Site"),
44
+					'connecting_button' => __("Connecting..."),
45
+					'error_localhost'   => __("This service will only work with a live domain, not a localhost."),
46
+					'error'             => __("Something went wrong, please refresh and try again."),
47 47
 				);
48
-				$this->strings   = array_merge( $default_strings, $strings );
48
+				$this->strings = array_merge($default_strings, $strings);
49 49
 
50 50
 
51 51
 				// set default pages
52 52
 				$default_pages = array();
53
-				$this->pages   = array_merge( $default_pages, $pages );
53
+				$this->pages   = array_merge($default_pages, $pages);
54 54
 
55 55
 				// maybe show connect site notice
56
-				add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) );
56
+				add_action('admin_notices', array($this, 'ayecode_connect_install_notice'));
57 57
 
58 58
 				// add ajax action if not already added
59
-				if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) {
60
-					add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) );
59
+				if (!has_action('wp_ajax_ayecode_connect_helper')) {
60
+					add_action('wp_ajax_ayecode_connect_helper', array($this, 'ayecode_connect_install'));
61 61
 				}
62 62
 			}
63 63
 
64 64
 			// add ajax action if not already added
65
-			if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) {
66
-				add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) );
65
+			if (!has_action('wp_ajax_nopriv_ayecode_connect_helper_installed')) {
66
+				add_action('wp_ajax_nopriv_ayecode_connect_helper_installed', array($this, 'ayecode_connect_helper_installed'));
67 67
 			}
68 68
 
69 69
 		}
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
 		/**
72 72
 		 * Give a way to check we can connect via a external redirect.
73 73
 		 */
74
-		public function ayecode_connect_helper_installed(){
74
+		public function ayecode_connect_helper_installed() {
75 75
 			$active = array(
76
-				'gd'    =>  defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0,
77
-				'uwp'    =>  defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0,
78
-				'wpi'    =>  defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0,
76
+				'gd'    =>  defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION, '2.0.0.79', '>') ? 1 : 0,
77
+				'uwp'    =>  defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION, '1.2.1.5', '>') ? 1 : 0,
78
+				'wpi'    =>  defined('WPINV_VERSION') && version_compare(WPINV_VERSION, '1.0.14', '>') ? 1 : 0,
79 79
 			);
80
-			wp_send_json_success( $active );
80
+			wp_send_json_success($active);
81 81
 			wp_die();
82 82
 		}
83 83
 
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 		 *
89 89
 		 * @return string
90 90
 		 */
91
-		private function format_plugin_slug( $key ) {
92
-			$slug = explode( '/', $key );
93
-			$slug = explode( '.', end( $slug ) );
91
+		private function format_plugin_slug($key) {
92
+			$slug = explode('/', $key);
93
+			$slug = explode('.', end($slug));
94 94
 
95 95
 			return $slug[0];
96 96
 		}
@@ -101,45 +101,45 @@  discard block
 block discarded – undo
101 101
 		public function ayecode_connect_install() {
102 102
 
103 103
 			// bail if localhost
104
-			if ( $this->is_localhost() ) {
105
-				wp_send_json_error( $this->strings['error_localhost'] );
104
+			if ($this->is_localhost()) {
105
+				wp_send_json_error($this->strings['error_localhost']);
106 106
 			}
107 107
 
108 108
 			// Explicitly clear the event.
109
-			wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() );
109
+			wp_clear_scheduled_hook('geodir_plugin_background_installer', func_get_args());
110 110
 
111 111
 			$success     = true;
112 112
 			$plugin_slug = "ayecode-connect";
113
-			if ( ! empty( $plugin_slug ) ) {
114
-				require_once( ABSPATH . 'wp-admin/includes/file.php' );
115
-				require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
116
-				require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
117
-				require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
113
+			if (!empty($plugin_slug)) {
114
+				require_once(ABSPATH . 'wp-admin/includes/file.php');
115
+				require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
116
+				require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
117
+				require_once(ABSPATH . 'wp-admin/includes/plugin.php');
118 118
 
119 119
 				WP_Filesystem();
120 120
 
121 121
 				$skin              = new Automatic_Upgrader_Skin;
122
-				$upgrader          = new WP_Upgrader( $skin );
123
-				$installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) );
122
+				$upgrader          = new WP_Upgrader($skin);
123
+				$installed_plugins = array_map(array($this, 'format_plugin_slug'), array_keys(get_plugins()));
124 124
 				$plugin_slug       = $plugin_slug;
125 125
 				$plugin            = $plugin_slug . '/' . $plugin_slug . '.php';
126 126
 				$installed         = false;
127 127
 				$activate          = false;
128 128
 
129 129
 				// See if the plugin is installed already
130
-				if ( in_array( $plugin_slug, $installed_plugins ) ) {
130
+				if (in_array($plugin_slug, $installed_plugins)) {
131 131
 					$installed = true;
132
-					$activate  = ! is_plugin_active( $plugin );
132
+					$activate  = !is_plugin_active($plugin);
133 133
 				}
134 134
 
135 135
 				// Install this thing!
136
-				if ( ! $installed ) {
136
+				if (!$installed) {
137 137
 
138 138
 					// Suppress feedback
139 139
 					ob_start();
140 140
 
141 141
 					try {
142
-						$plugin_information = plugins_api( 'plugin_information', array(
142
+						$plugin_information = plugins_api('plugin_information', array(
143 143
 							'slug'   => $plugin_slug,
144 144
 							'fields' => array(
145 145
 								'short_description' => false,
@@ -156,26 +156,26 @@  discard block
 block discarded – undo
156 156
 								'author_profile'    => false,
157 157
 								'author'            => false,
158 158
 							),
159
-						) );
159
+						));
160 160
 
161
-						if ( is_wp_error( $plugin_information ) ) {
162
-							throw new Exception( $plugin_information->get_error_message() );
161
+						if (is_wp_error($plugin_information)) {
162
+							throw new Exception($plugin_information->get_error_message());
163 163
 						}
164 164
 
165 165
 						$package  = $plugin_information->download_link;
166
-						$download = $upgrader->download_package( $package );
166
+						$download = $upgrader->download_package($package);
167 167
 
168
-						if ( is_wp_error( $download ) ) {
169
-							throw new Exception( $download->get_error_message() );
168
+						if (is_wp_error($download)) {
169
+							throw new Exception($download->get_error_message());
170 170
 						}
171 171
 
172
-						$working_dir = $upgrader->unpack_package( $download, true );
172
+						$working_dir = $upgrader->unpack_package($download, true);
173 173
 
174
-						if ( is_wp_error( $working_dir ) ) {
175
-							throw new Exception( $working_dir->get_error_message() );
174
+						if (is_wp_error($working_dir)) {
175
+							throw new Exception($working_dir->get_error_message());
176 176
 						}
177 177
 
178
-						$result = $upgrader->install_package( array(
178
+						$result = $upgrader->install_package(array(
179 179
 							'source'                      => $working_dir,
180 180
 							'destination'                 => WP_PLUGIN_DIR,
181 181
 							'clear_destination'           => false,
@@ -185,15 +185,15 @@  discard block
 block discarded – undo
185 185
 								'type'   => 'plugin',
186 186
 								'action' => 'install',
187 187
 							),
188
-						) );
188
+						));
189 189
 
190
-						if ( is_wp_error( $result ) ) {
191
-							throw new Exception( $result->get_error_message() );
190
+						if (is_wp_error($result)) {
191
+							throw new Exception($result->get_error_message());
192 192
 						}
193 193
 
194 194
 						$activate = true;
195 195
 
196
-					} catch ( Exception $e ) {
196
+					} catch (Exception $e) {
197 197
 						$success = false;
198 198
 					}
199 199
 
@@ -204,30 +204,30 @@  discard block
 block discarded – undo
204 204
 				wp_clean_plugins_cache();
205 205
 
206 206
 				// Activate this thing
207
-				if ( $activate ) {
207
+				if ($activate) {
208 208
 					try {
209
-						$result = activate_plugin( $plugin );
209
+						$result = activate_plugin($plugin);
210 210
 
211
-						if ( is_wp_error( $result ) ) {
211
+						if (is_wp_error($result)) {
212 212
 							$success = false;
213 213
 						} else {
214 214
 							$success = true;
215 215
 						}
216
-					} catch ( Exception $e ) {
216
+					} catch (Exception $e) {
217 217
 						$success = false;
218 218
 					}
219 219
 				}
220 220
 			}
221 221
 
222
-			if ( $success && function_exists( 'ayecode_connect_args' ) ) {
223
-				ayecode_connect();// init
222
+			if ($success && function_exists('ayecode_connect_args')) {
223
+				ayecode_connect(); // init
224 224
 				$args        = ayecode_connect_args();
225
-				$client      = new AyeCode_Connect( $args );
226
-				$redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : '';
227
-				$redirect    = $client->build_connect_url( $redirect_to );
228
-				wp_send_json_success( array( 'connect_url' => $redirect ) );
225
+				$client      = new AyeCode_Connect($args);
226
+				$redirect_to = !empty($_POST['redirect_to']) ? esc_url_raw($_POST['redirect_to']) : '';
227
+				$redirect    = $client->build_connect_url($redirect_to);
228
+				wp_send_json_success(array('connect_url' => $redirect));
229 229
 			} else {
230
-				wp_send_json_error( $this->strings['error_localhost'] );
230
+				wp_send_json_error($this->strings['error_localhost']);
231 231
 			}
232 232
 			wp_die();
233 233
 		}
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		public function is_localhost() {
241 241
 			$localhost = false;
242 242
 
243
-			$host              = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '';
243
+			$host              = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
244 244
 			$localhost_domains = array(
245 245
 				'localhost',
246 246
 				'localhost.localdomain',
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 				'::1'
249 249
 			);
250 250
 
251
-			if ( in_array( $host, $localhost_domains ) ) {
251
+			if (in_array($host, $localhost_domains)) {
252 252
 				$localhost = true;
253 253
 			}
254 254
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		 * Show notice to connect site.
260 260
 		 */
261 261
 		public function ayecode_connect_install_notice() {
262
-			if ( $this->maybe_show() ) {
262
+			if ($this->maybe_show()) {
263 263
 				$connect_title_string     = $this->strings['connect_title'];
264 264
 				$connect_external_string  = $this->strings['connect_external'];
265 265
 				$connect_string           = $this->strings['connect'];
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
 					</svg>
302 302
 					</span>
303 303
 					<span class="acch-float-left acch-text">
304
-						<h3 class="acch-title"><?php echo esc_html( $connect_title_string ); ?></h3>
304
+						<h3 class="acch-title"><?php echo esc_html($connect_title_string); ?></h3>
305 305
 					<p>
306 306
 						<?php
307
-						echo wp_kses_post( $connect_string );
307
+						echo wp_kses_post($connect_string);
308 308
 						?>
309 309
 					</p>
310 310
 					</span>
@@ -312,14 +312,14 @@  discard block
 block discarded – undo
312 312
 					<span class="acch-float-left acch-button">
313 313
 						<button onclick="ayecode_connect_helper(this);" id="gd-connect-site"
314 314
 						        class="button button-primary"
315
-						        data-connecting="<?php echo esc_attr( $connecting_button_string ); ?>"><?php echo esc_attr( $connect_button_string ) ?></button>
315
+						        data-connecting="<?php echo esc_attr($connecting_button_string); ?>"><?php echo esc_attr($connect_button_string) ?></button>
316 316
 					</span>
317 317
 
318 318
 				</div>
319 319
 
320 320
 				<?php
321 321
 				// only include the popup HTML if needed.
322
-				if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
322
+				if (!empty($_REQUEST['external-connect-request'])) {
323 323
 					?>
324 324
 					<div id="ayecode-connect-helper-external-confirm" style="display:none;">
325 325
 						<div class="noticex notice-info acch-notice" style="border: none;">
@@ -357,13 +357,13 @@  discard block
 block discarded – undo
357 357
 					</svg>
358 358
 					</span>
359 359
 					<span class="acch-float-left acch-text">
360
-						<h3 class="acch-title"><?php echo esc_attr( $connect_external_string ); ?></h3>
360
+						<h3 class="acch-title"><?php echo esc_attr($connect_external_string); ?></h3>
361 361
 					</span>
362 362
 
363 363
 					<span class="acch-float-left acch-button">
364 364
 						<button onclick="ayecode_connect_helper(this);" id="gd-connect-site"
365 365
 						        class="button button-primary"
366
-						        data-connecting="<?php echo esc_attr( $connecting_button_string ); ?>"><?php echo esc_attr( $connect_button_string ) ?></button>
366
+						        data-connecting="<?php echo esc_attr($connecting_button_string); ?>"><?php echo esc_attr($connect_button_string) ?></button>
367 367
 					</span>
368 368
 
369 369
 						</div>
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		public function script() {
383 383
 
384 384
 			// add thickbox if external request is requested
385
-			if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
385
+			if (!empty($_REQUEST['external-connect-request'])) {
386 386
 				add_thickbox();
387 387
 			}
388 388
 			?>
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 						url: ajaxurl,
435 435
 						data: {
436 436
 							action: 'ayecode_connect_helper',
437
-							security: '<?php echo esc_js( wp_create_nonce( 'ayecode-connect-helper' ) );?>',
437
+							security: '<?php echo esc_js(wp_create_nonce('ayecode-connect-helper')); ?>',
438 438
 							redirect_to: $current_url
439 439
 						},
440 440
 						beforeSend: function () {
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 
456 456
 				<?php
457 457
 				// add thickbox if external request is requested
458
-				if(! empty( $_REQUEST['external-connect-request'] )) {
458
+				if (!empty($_REQUEST['external-connect-request'])) {
459 459
 				?>
460 460
 				jQuery(function () {
461 461
 					setTimeout(function () {
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
 			$show = false;
480 480
 
481 481
 			// check if on a page set to show
482
-			if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) {
482
+			if (isset($_REQUEST['page']) && in_array($_REQUEST['page'], $this->pages)) {
483 483
 
484 484
 				// check if not active and connected
485
-				if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) {
485
+				if (!defined('AYECODE_CONNECT_VERSION') || !get_option('ayecode_connect_blog_token')) {
486 486
 					$show = true;
487 487
 				}
488 488
 
Please login to merge, or discard this patch.
templates/invoice/footer.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
     <div class="border-top pt-4 bg-white">
15 15
         <div class="container pr-0 pl-0">
16 16
 
17
-            <?php if ( $term_text = wpinv_get_terms_text() ) : ?>
17
+            <?php if ($term_text = wpinv_get_terms_text()) : ?>
18 18
                 <div class="terms-text">
19
-                    <?php echo wp_kses_post( wpautop( $term_text ) ); ?>
19
+                    <?php echo wp_kses_post(wpautop($term_text)); ?>
20 20
                 </div>
21 21
             <?php endif; ?>
22 22
 
23 23
             <div class="footer-text d-print-none">
24
-                <?php echo wp_kses_post( wpinv_get_business_footer() ); ?>
24
+                <?php echo wp_kses_post(wpinv_get_business_footer()); ?>
25 25
             </div>
26 26
 
27 27
         </div>
Please login to merge, or discard this patch.
templates/emails/wpinv-email-completed_invoice.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16
-echo wp_kses_post( $message_body );
16
+echo wp_kses_post($message_body);
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-subscription_complete.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@
 block discarded – undo
8 8
  * @var WPInv_Subscription $object
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 $invoice = $object->get_parent_payment();
14 14
 
15 15
 // Print the email header.
16
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
17 17
 
18 18
 // Generate the custom message body.
19
-echo wp_kses_post( $message_body );
19
+echo wp_kses_post($message_body);
20 20
 
21 21
 // Print the billing details.
22
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the email footer.
25
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-renewal_reminder.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,24 +8,24 @@
 block discarded – undo
8 8
  * @var WPInv_Subscription $object
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 $invoice = $object->get_parent_payment();
14 14
 
15 15
 // Print the email header.
16
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
17 17
 
18 18
 // Generate the custom message body.
19
-echo wp_kses_post( $message_body );
19
+echo wp_kses_post($message_body);
20 20
 
21 21
 // Print invoice details.
22
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print invoice items.
25
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the billing details.
28
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
29 29
 
30 30
 // Print the email footer.
31
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
31
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-processing_invoice.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16
-echo wp_kses_post( $message_body );
16
+echo wp_kses_post($message_body);
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-overdue.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16
-echo wp_kses_post( $message_body );
16
+echo wp_kses_post($message_body);
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.