Completed
Push — master ( c72cea...2f3eab )
by Stiofan
18s
created
includes/libraries/wp-session/wp-cli.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 	 * @param array $args
22 22
 	 * @param array $assoc_args
23 23
 	 */
24
-	public function count( $args, $assoc_args ) {
24
+	public function count($args, $assoc_args) {
25 25
 		$sessions = WP_Session_Utils::count_sessions();
26 26
 
27
-		\WP_CLI::line( sprintf( '%d sessions currently exist.', absint( $sessions ) ) );
27
+		\WP_CLI::line(sprintf('%d sessions currently exist.', absint($sessions)));
28 28
 	}
29 29
 
30 30
 	/**
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 	 * @param array $args
54 54
 	 * @param array $assoc_args
55 55
 	 */
56
-	public function delete( $args, $assoc_args ) {
57
-		if ( isset( $assoc_args['limit'] ) ) {
58
-			$limit = absint( $assoc_args['limit'] );
56
+	public function delete($args, $assoc_args) {
57
+		if (isset($assoc_args['limit'])) {
58
+			$limit = absint($assoc_args['limit']);
59 59
 
60
-			$count = WP_Session_Utils::delete_old_sessions( $limit );
60
+			$count = WP_Session_Utils::delete_old_sessions($limit);
61 61
 
62
-			if ( $count > 0 ) {
63
-				\WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) );
62
+			if ($count > 0) {
63
+				\WP_CLI::line(sprintf('Deleted %d sessions.', $count));
64 64
 			}
65 65
 
66 66
 			// Clear memory
@@ -69,32 +69,32 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 
71 71
 		// Determine if we're deleting all sessions or just a subset.
72
-		$all = isset( $assoc_args['all'] );
72
+		$all = isset($assoc_args['all']);
73 73
 
74 74
 		/**
75 75
 		 * Determine the size of each batch for deletion.
76 76
 		 *
77 77
 		 * @param int
78 78
 		 */
79
-		$batch = isset( $assoc_args['batch'] ) ? absint( $assoc_args['batch'] ) : apply_filters( 'wp_session_delete_batch_size', 1000 );
79
+		$batch = isset($assoc_args['batch']) ? absint($assoc_args['batch']) : apply_filters('wp_session_delete_batch_size', 1000);
80 80
 
81
-		switch ( $all ) {
81
+		switch ($all) {
82 82
 			case true:
83 83
 				$count = WP_Session_Utils::delete_all_sessions();
84 84
 
85
-				\WP_CLI::line( sprintf( 'Deleted all %d sessions.', $count ) );
85
+				\WP_CLI::line(sprintf('Deleted all %d sessions.', $count));
86 86
 				break;
87 87
 			case false:
88 88
 				do {
89
-					$count = WP_Session_Utils::delete_old_sessions( $batch );
89
+					$count = WP_Session_Utils::delete_old_sessions($batch);
90 90
 
91
-					if ( $count > 0 ) {
92
-						\WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) );
91
+					if ($count > 0) {
92
+						\WP_CLI::line(sprintf('Deleted %d sessions.', $count));
93 93
 					}
94 94
 
95 95
 					// Clear memory
96 96
 					self::free_up_memory();
97
-				} while ( $count > 0 );
97
+				} while ($count > 0);
98 98
 				break;
99 99
 		}
100 100
 	}
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @param array $args
121 121
 	 * @param array $assoc_args
122 122
 	 */
123
-	public function generate( $args, $assoc_args ) {
124
-		$count = absint( $args[0] );
125
-		$date  = isset( $assoc_args['expires'] ) ? $assoc_args['expires'] : null;
123
+	public function generate($args, $assoc_args) {
124
+		$count = absint($args[0]);
125
+		$date  = isset($assoc_args['expires']) ? $assoc_args['expires'] : null;
126 126
 
127
-		$notify = \WP_CLI\Utils\make_progress_bar( 'Generating sessions', $count );
127
+		$notify = \WP_CLI\Utils\make_progress_bar('Generating sessions', $count);
128 128
 
129
-		for ( $i = 0; $i < $count; $i ++ ) {
130
-			WP_Session_Utils::create_dummy_session( $date );
129
+		for ($i = 0; $i < $count; $i++) {
130
+			WP_Session_Utils::create_dummy_session($date);
131 131
 			$notify->tick();
132 132
 		}
133 133
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		global $wp_object_cache, $wpdb;
145 145
 		$wpdb->queries = array();
146 146
 
147
-		if ( ! is_object( $wp_object_cache ) ) {
147
+		if (!is_object($wp_object_cache)) {
148 148
 			return;
149 149
 		}
150 150
 
@@ -155,4 +155,4 @@  discard block
 block discarded – undo
155 155
 	}
156 156
 }
157 157
 
158
-\WP_CLI::add_command( 'session', 'WP_Session_Command' );
159 158
\ No newline at end of file
159
+\WP_CLI::add_command('session', 'WP_Session_Command');
160 160
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/wp-session/wp-session.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
  *
34 34
  * @param string $data
35 35
  */
36
-function wp_session_decode( $data ) {
36
+function wp_session_decode($data) {
37 37
 	$wp_session = WP_Session::get_instance();
38 38
 
39
-	return $wp_session->json_in( $data );
39
+	return $wp_session->json_in($data);
40 40
 }
41 41
 
42 42
 /**
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
  *
58 58
  * @return bool
59 59
  */
60
-function wp_session_regenerate_id( $delete_old_session = false ) {
60
+function wp_session_regenerate_id($delete_old_session = false) {
61 61
 	$wp_session = WP_Session::get_instance();
62 62
 
63
-	$wp_session->regenerate_id( $delete_old_session );
63
+	$wp_session->regenerate_id($delete_old_session);
64 64
 
65 65
 	return true;
66 66
 }
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
  */
75 75
 function wp_session_start() {
76 76
 	$wp_session = WP_Session::get_instance();
77
-	do_action( 'wp_session_start' );
77
+	do_action('wp_session_start');
78 78
 
79 79
 	return $wp_session->session_started();
80 80
 }
81
-if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) {
82
-	add_action( 'plugins_loaded', 'wp_session_start' );
81
+if (!defined('WP_CLI') || false === WP_CLI) {
82
+	add_action('plugins_loaded', 'wp_session_start');
83 83
 }
84 84
 
85 85
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 function wp_session_status() {
91 91
 	$wp_session = WP_Session::get_instance();
92 92
 
93
-	if ( $wp_session->session_started() ) {
93
+	if ($wp_session->session_started()) {
94 94
 		return PHP_SESSION_ACTIVE;
95 95
 	}
96 96
 
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 	$wp_session = WP_Session::get_instance();
114 114
 
115 115
 	$wp_session->write_data();
116
-	do_action( 'wp_session_commit' );
116
+	do_action('wp_session_commit');
117 117
 }
118
-if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) {
119
-	add_action( 'shutdown', 'wp_session_write_close' );
118
+if (!defined('WP_CLI') || false === WP_CLI) {
119
+	add_action('shutdown', 'wp_session_write_close');
120 120
 }
121 121
 
122 122
 /**
@@ -127,33 +127,33 @@  discard block
 block discarded – undo
127 127
  * of a scheduled task or cron job.
128 128
  */
129 129
 function wp_session_cleanup() {
130
-	if ( defined( 'WP_SETUP_CONFIG' ) ) {
130
+	if (defined('WP_SETUP_CONFIG')) {
131 131
 		return;
132 132
 	}
133 133
 
134
-	if ( ! defined( 'WP_INSTALLING' ) ) {
134
+	if (!defined('WP_INSTALLING')) {
135 135
 		/**
136 136
 		 * Determine the size of each batch for deletion.
137 137
 		 *
138 138
 		 * @param int
139 139
 		 */
140
-		$batch_size = apply_filters( 'wp_session_delete_batch_size', 1000 );
140
+		$batch_size = apply_filters('wp_session_delete_batch_size', 1000);
141 141
 
142 142
 		// Delete a batch of old sessions
143
-		WP_Session_Utils::delete_old_sessions( $batch_size );
143
+		WP_Session_Utils::delete_old_sessions($batch_size);
144 144
 	}
145 145
 
146 146
 	// Allow other plugins to hook in to the garbage collection process.
147
-	do_action( 'wp_session_cleanup' );
147
+	do_action('wp_session_cleanup');
148 148
 }
149
-add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' );
149
+add_action('wp_session_garbage_collection', 'wp_session_cleanup');
150 150
 
151 151
 /**
152 152
  * Register the garbage collector as a twice daily event.
153 153
  */
154 154
 function wp_session_register_garbage_collection() {
155
-	if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) {
156
-		wp_schedule_event( time(), 'hourly', 'wp_session_garbage_collection' );
155
+	if (!wp_next_scheduled('wp_session_garbage_collection')) {
156
+		wp_schedule_event(time(), 'hourly', 'wp_session_garbage_collection');
157 157
 	}
158 158
 }
159
-add_action( 'wp', 'wp_session_register_garbage_collection' );
159
+add_action('wp', 'wp_session_register_garbage_collection');
Please login to merge, or discard this patch.
includes/libraries/wp-session/class-wp-session.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return bool|WP_Session
54 54
 	 */
55 55
 	public static function get_instance() {
56
-		if ( ! self::$instance ) {
56
+		if (!self::$instance) {
57 57
 			self::$instance = new self();
58 58
 		}
59 59
 
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
 	 * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire.
70 70
 	 */
71 71
 	protected function __construct() {
72
-		if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) {
73
-			$cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] );
74
-			$cookie_crumbs = explode( '||', $cookie );
72
+		if (isset($_COOKIE[WP_SESSION_COOKIE])) {
73
+			$cookie = stripslashes($_COOKIE[WP_SESSION_COOKIE]);
74
+			$cookie_crumbs = explode('||', $cookie);
75 75
 
76
-            $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] );
77
-            $this->expires = absint( $cookie_crumbs[1] );
78
-            $this->exp_variant = absint( $cookie_crumbs[2] );
76
+            $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0]);
77
+            $this->expires = absint($cookie_crumbs[1]);
78
+            $this->exp_variant = absint($cookie_crumbs[2]);
79 79
 
80 80
 			// Update the session expiration if we're past the variant time
81
-			if ( time() > $this->exp_variant ) {
81
+			if (time() > $this->exp_variant) {
82 82
 				$this->set_expiration();
83
-				delete_option( "_wp_session_expires_{$this->session_id}" );
84
-				add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
83
+				delete_option("_wp_session_expires_{$this->session_id}");
84
+				add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no');
85 85
 			}
86 86
 		} else {
87 87
 			$this->session_id = WP_Session_Utils::generate_id();
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions.
114 114
 	 */
115 115
 	protected function set_expiration() {
116
-		$this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
117
-		$this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
116
+		$this->exp_variant = time() + (int)apply_filters('wp_session_expiration_variant', 24 * 60);
117
+		$this->expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60);
118 118
 	}
119 119
 
120 120
 	/**
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
 	* @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie()
124 124
 	*/
125 125
 	protected function set_cookie() {
126
-		if ( !defined( 'WPI_TESTING_MODE' ) ) {
126
+		if (!defined('WPI_TESTING_MODE')) {
127 127
 			try {
128 128
 				$secure = apply_filters('wp_session_cookie_secure', false);
129 129
 				$httponly = apply_filters('wp_session_cookie_httponly', false);
130
-				setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly );
131
-			} catch(Exception $e) {
132
-				error_log( 'Set Cookie Error: ' . $e->getMessage() );
130
+				setcookie(WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant, $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly);
131
+			} catch (Exception $e) {
132
+				error_log('Set Cookie Error: ' . $e->getMessage());
133 133
 			}
134 134
 		}
135 135
 	}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @return array
143 143
 	 */
144 144
 	protected function read_data() {
145
-		$this->container = get_option( "_wp_session_{$this->session_id}", array() );
145
+		$this->container = get_option("_wp_session_{$this->session_id}", array());
146 146
 
147 147
 		return $this->container;
148 148
 	}
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 	public function write_data() {
154 154
 		$option_key = "_wp_session_{$this->session_id}";
155 155
 		
156
-		if ( false === get_option( $option_key ) ) {
157
-			add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
158
-			add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
156
+		if (false === get_option($option_key)) {
157
+			add_option("_wp_session_{$this->session_id}", $this->container, '', 'no');
158
+			add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no');
159 159
 		} else {
160
-			delete_option( "_wp_session_{$this->session_id}" );
161
-			add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
160
+			delete_option("_wp_session_{$this->session_id}");
161
+			add_option("_wp_session_{$this->session_id}", $this->container, '', 'no');
162 162
 		}
163 163
 	}
164 164
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @return string
169 169
 	 */
170 170
 	public function json_out() {
171
-		return json_encode( $this->container );
171
+		return json_encode($this->container);
172 172
 	}
173 173
 
174 174
 	/**
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @return bool
180 180
 	 */
181
-	public function json_in( $data ) {
182
-		$array = json_decode( $data );
181
+	public function json_in($data) {
182
+		$array = json_decode($data);
183 183
 
184
-		if ( is_array( $array ) ) {
184
+		if (is_array($array)) {
185 185
 			$this->container = $array;
186 186
 			return true;
187 187
 		}
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 	 *
195 195
 	 * @param bool $delete_old Flag whether or not to delete the old session data from the server.
196 196
 	 */
197
-	public function regenerate_id( $delete_old = false ) {
198
-		if ( $delete_old ) {
199
-			delete_option( "_wp_session_{$this->session_id}" );
197
+	public function regenerate_id($delete_old = false) {
198
+		if ($delete_old) {
199
+			delete_option("_wp_session_{$this->session_id}");
200 200
 		}
201 201
 
202 202
 		$this->session_id = WP_Session_Utils::generate_id();
Please login to merge, or discard this patch.
includes/libraries/wp-session/class-recursive-arrayaccess.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param array $data
38 38
 	 */
39
-	protected function __construct( $data = array() ) {
40
-		foreach ( $data as $key => $value ) {
41
-			$this[ $key ] = $value;
39
+	protected function __construct($data = array()) {
40
+		foreach ($data as $key => $value) {
41
+			$this[$key] = $value;
42 42
 		}
43 43
 	}
44 44
 
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 	 * Allow deep copies of objects
47 47
 	 */
48 48
 	public function __clone() {
49
-		foreach ( $this->container as $key => $value ) {
50
-			if ( $value instanceof self ) {
51
-				$this[ $key ] = clone $value;
49
+		foreach ($this->container as $key => $value) {
50
+			if ($value instanceof self) {
51
+				$this[$key] = clone $value;
52 52
 			}
53 53
 		}
54 54
 	}
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 	 */
61 61
 	public function toArray() {
62 62
 		$data = $this->container;
63
-		foreach ( $data as $key => $value ) {
64
-			if ( $value instanceof self ) {
65
-				$data[ $key ] = $value->toArray();
63
+		foreach ($data as $key => $value) {
64
+			if ($value instanceof self) {
65
+				$data[$key] = $value->toArray();
66 66
 			}
67 67
 		}
68 68
 		return $data;
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 	 *
82 82
 	 * @return boolean true on success or false on failure.
83 83
 	 */
84
-	public function offsetExists( $offset ) {
85
-		return isset( $this->container[ $offset ]) ;
84
+	public function offsetExists($offset) {
85
+		return isset($this->container[$offset]);
86 86
 	}
87 87
 
88 88
 	/**
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @return mixed Can return all value types.
96 96
 	 */
97
-	public function offsetGet( $offset ) {
98
-		return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
97
+	public function offsetGet($offset) {
98
+		return isset($this->container[$offset]) ? $this->container[$offset] : null;
99 99
 	}
100 100
 
101 101
 	/**
@@ -108,14 +108,14 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return void
110 110
 	 */
111
-	public function offsetSet( $offset, $data ) {
112
-		if ( is_array( $data ) ) {
113
-			$data = new self( $data );
111
+	public function offsetSet($offset, $data) {
112
+		if (is_array($data)) {
113
+			$data = new self($data);
114 114
 		}
115
-		if ( $offset === null ) { // don't forget this!
115
+		if ($offset === null) { // don't forget this!
116 116
 			$this->container[] = $data;
117 117
 		} else {
118
-			$this->container[ $offset ] = $data;
118
+			$this->container[$offset] = $data;
119 119
 		}
120 120
 
121 121
 		$this->dirty = true;
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @return void
132 132
 	 */
133
-	public function offsetUnset( $offset ) {
134
-		unset( $this->container[ $offset ] );
133
+	public function offsetUnset($offset) {
134
+		unset($this->container[$offset]);
135 135
 
136 136
 		$this->dirty = true;
137 137
 	}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @return mixed
150 150
 	 */
151 151
 	public function current() {
152
-		return current( $this->container );
152
+		return current($this->container);
153 153
 	}
154 154
 
155 155
 	/**
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 * @return mixed
161 161
 	 */
162 162
 	public function key() {
163
-		return key( $this->container );
163
+		return key($this->container);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 * @return void
172 172
 	 */
173 173
 	public function next() {
174
-		next( $this->container );
174
+		next($this->container);
175 175
 	}
176 176
 
177 177
 	/**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @return void
183 183
 	 */
184 184
 	public function rewind() {
185
-		reset( $this->container );
185
+		reset($this->container);
186 186
 	}
187 187
 
188 188
 	/**
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 * @return bool
194 194
 	 */
195 195
 	public function valid() {
196
-		return $this->offsetExists( $this->key() );
196
+		return $this->offsetExists($this->key());
197 197
 	}
198 198
 
199 199
 	/*****************************************************************/
@@ -208,6 +208,6 @@  discard block
 block discarded – undo
208 208
 	 * @return int
209 209
 	 */
210 210
 	public function count() {
211
-		return count( $this->container );
211
+		return count($this->container);
212 212
 	}
213 213
 }
Please login to merge, or discard this patch.
includes/libraries/wp-session/class-wp-session-utils.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 		 *
24 24
 		 * @param string $query Database count query
25 25
 		 */
26
-		$query = apply_filters( 'wp_session_count_query', $query );
26
+		$query = apply_filters('wp_session_count_query', $query);
27 27
 
28
-		$sessions = $wpdb->get_var( $query );
28
+		$sessions = $wpdb->get_var($query);
29 29
 
30
-		return absint( $sessions );
30
+		return absint($sessions);
31 31
 	}
32 32
 
33 33
 	/**
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param null|string $date
37 37
 	 */
38
-	public static function create_dummy_session( $date = null ) {
38
+	public static function create_dummy_session($date = null) {
39 39
 		// Generate our date
40
-		if ( null !== $date ) {
41
-			$time = strtotime( $date );
40
+		if (null !== $date) {
41
+			$time = strtotime($date);
42 42
 
43
-			if ( false === $time ) {
43
+			if (false === $time) {
44 44
 				$date = null;
45 45
 			} else {
46
-				$expires = date( 'U', strtotime( $date ) );
46
+				$expires = date('U', strtotime($date));
47 47
 			}
48 48
 		}
49 49
 
50 50
 		// If null was passed, or if the string parsing failed, fall back on a default
51
-		if ( null === $date ) {
51
+		if (null === $date) {
52 52
 			/**
53 53
 			 * Filter the expiration of the session in the database
54 54
 			 *
55 55
 			 * @param int
56 56
 			 */
57
-			$expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
57
+			$expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60);
58 58
 		}
59 59
 
60 60
 		$session_id = self::generate_id();
61 61
 
62 62
 		// Store the session
63
-		add_option( "_wp_session_{$session_id}", array(), '', 'no' );
64
-		add_option( "_wp_session_expires_{$session_id}", $expires, '', 'no' );
63
+		add_option("_wp_session_{$session_id}", array(), '', 'no');
64
+		add_option("_wp_session_expires_{$session_id}", $expires, '', 'no');
65 65
 	}
66 66
 
67 67
 	/**
@@ -73,22 +73,22 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return int Sessions deleted.
75 75
 	 */
76
-	public static function delete_old_sessions( $limit = 1000 ) {
76
+	public static function delete_old_sessions($limit = 1000) {
77 77
 		global $wpdb;
78 78
 
79
-		$limit = absint( $limit );
80
-		$keys = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%' ORDER BY option_value ASC LIMIT 0, {$limit}" );
79
+		$limit = absint($limit);
80
+		$keys = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%' ORDER BY option_value ASC LIMIT 0, {$limit}");
81 81
 
82 82
 		$now = time();
83 83
 		$expired = array();
84 84
 		$count = 0;
85 85
 
86
-		foreach( $keys as $expiration ) {
86
+		foreach ($keys as $expiration) {
87 87
 			$key = $expiration->option_name;
88 88
 			$expires = $expiration->option_value;
89 89
 
90
-			if ( $now > $expires ) {
91
-				$session_id = preg_replace("/[^A-Za-z0-9_]/", '', substr( $key, 20 ) );
90
+			if ($now > $expires) {
91
+				$session_id = preg_replace("/[^A-Za-z0-9_]/", '', substr($key, 20));
92 92
 
93 93
 				$expired[] = $key;
94 94
 				$expired[] = "_wp_session_{$session_id}";
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 		}
99 99
 
100 100
 		// Delete expired sessions
101
-		if ( ! empty( $expired ) ) {
102
-		    $placeholders = array_fill( 0, count( $expired ), '%s' );
103
-		    $format = implode( ', ', $placeholders );
101
+		if (!empty($expired)) {
102
+		    $placeholders = array_fill(0, count($expired), '%s');
103
+		    $format = implode(', ', $placeholders);
104 104
 		    $query = "DELETE FROM $wpdb->options WHERE option_name IN ($format)";
105 105
 
106
-		    $prepared = $wpdb->prepare( $query, $expired );
107
-			$wpdb->query( $prepared );
106
+		    $prepared = $wpdb->prepare($query, $expired);
107
+			$wpdb->query($prepared);
108 108
 		}
109 109
 
110 110
 		return $count;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	public static function delete_all_sessions() {
121 121
 		global $wpdb;
122 122
 
123
-		$count = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_wp_session_%'" );
123
+		$count = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_wp_session_%'");
124 124
 
125
-		return (int) ( $count / 2 );
125
+		return (int)($count / 2);
126 126
 	}
127 127
 
128 128
 	/**
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @return string
132 132
 	 */
133 133
 	public static function generate_id() {
134
-		require_once( ABSPATH . 'wp-includes/class-phpass.php' );
135
-		$hash = new PasswordHash( 8, false );
134
+		require_once(ABSPATH . 'wp-includes/class-phpass.php');
135
+		$hash = new PasswordHash(8, false);
136 136
 
137
-		return md5( $hash->get_random_bytes( 32 ) );
137
+		return md5($hash->get_random_bytes(32));
138 138
 	}
139 139
 } 
140 140
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-session.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * WPInv_Session Class.
@@ -46,44 +46,44 @@  discard block
 block discarded – undo
46 46
 	public function __construct() {
47 47
 		$this->use_php_sessions = $this->use_php_sessions();
48 48
 
49
-		if ( $this->use_php_sessions ) {
50
-			if ( is_multisite() ) {
49
+		if ($this->use_php_sessions) {
50
+			if (is_multisite()) {
51 51
 				$this->prefix = '_' . get_current_blog_id();
52 52
 			}
53 53
 
54 54
 			// Use PHP SESSION (must be enabled via the WPINV_USE_PHP_SESSIONS constant)
55
-			add_action( 'init', array( $this, 'maybe_start_session' ), -2 );
55
+			add_action('init', array($this, 'maybe_start_session'), -2);
56 56
 		} else {
57 57
 			// Use WP_Session (default)
58
-			if ( !defined( 'WP_SESSION_COOKIE' ) ) {
59
-				define( 'WP_SESSION_COOKIE', 'wpinv_wp_session' );
58
+			if (!defined('WP_SESSION_COOKIE')) {
59
+				define('WP_SESSION_COOKIE', 'wpinv_wp_session');
60 60
 			}
61 61
 
62
-			if ( !class_exists( 'Recursive_ArrayAccess' ) ) {
62
+			if (!class_exists('Recursive_ArrayAccess')) {
63 63
 				require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/class-recursive-arrayaccess.php';
64 64
 			}
65 65
             
66
-			if ( !class_exists( 'WP_Session_Utils' ) ) {
66
+			if (!class_exists('WP_Session_Utils')) {
67 67
 				require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/class-wp-session-utils.php';
68 68
 			}
69 69
             
70
-			if ( defined( 'WP_CLI' ) && WP_CLI && !class_exists( 'WP_Session_Command' ) ) {
70
+			if (defined('WP_CLI') && WP_CLI && !class_exists('WP_Session_Command')) {
71 71
 				require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/wp-cli.php';
72 72
 			}
73 73
 
74
-			if ( !class_exists( 'WP_Session' ) ) {
74
+			if (!class_exists('WP_Session')) {
75 75
 				require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/class-wp-session.php';
76 76
 				require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/wp-session.php';
77 77
 			}
78 78
 
79
-			add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 );
80
-			add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 );
79
+			add_filter('wp_session_expiration_variant', array($this, 'set_expiration_variant_time'), 99999);
80
+			add_filter('wp_session_expiration', array($this, 'set_expiration_time'), 99999);
81 81
 		}
82 82
 
83
-		if ( empty( $this->session ) && ! $this->use_php_sessions ) {
84
-			add_action( 'plugins_loaded', array( $this, 'init' ), -1 );
83
+		if (empty($this->session) && !$this->use_php_sessions) {
84
+			add_action('plugins_loaded', array($this, 'init'), -1);
85 85
 		} else {
86
-			add_action( 'init', array( $this, 'init' ), -1 );
86
+			add_action('init', array($this, 'init'), -1);
87 87
 		}
88 88
 	}
89 89
 
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	 * @return void
96 96
 	 */
97 97
 	public function init() {
98
-		if ( $this->use_php_sessions ) {
99
-			$this->session = isset( $_SESSION['wpi' . $this->prefix ] ) && is_array( $_SESSION['wpi' . $this->prefix ] ) ? $_SESSION['wpi' . $this->prefix ] : array();
98
+		if ($this->use_php_sessions) {
99
+			$this->session = isset($_SESSION['wpi' . $this->prefix]) && is_array($_SESSION['wpi' . $this->prefix]) ? $_SESSION['wpi' . $this->prefix] : array();
100 100
 		} else {
101 101
 			$this->session = WP_Session::get_instance();
102 102
 		}
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
 	 * @return string Session ID
113 113
 	 */
114 114
 	public function get_id() {
115
-		if ( $this->use_php_sessions ) {
116
-			$session_id = !empty( $_SESSION ) && function_exists( 'session_id' ) ? session_id() : NULL;
115
+		if ($this->use_php_sessions) {
116
+			$session_id = !empty($_SESSION) && function_exists('session_id') ? session_id() : NULL;
117 117
 		} else {
118
-			$session_id = !empty( $this->session ) && isset( $this->session->session_id ) ? $this->session->session_id : NULL;
118
+			$session_id = !empty($this->session) && isset($this->session->session_id) ? $this->session->session_id : NULL;
119 119
 		}
120 120
 		return $session_id;
121 121
 	}
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 	 * @param string $key Session key
129 129
 	 * @return string Session variable
130 130
 	 */
131
-	public function get( $key ) {
132
-		$key = sanitize_key( $key );
133
-		return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : false;
131
+	public function get($key) {
132
+		$key = sanitize_key($key);
133
+		return isset($this->session[$key]) ? maybe_unserialize($this->session[$key]) : false;
134 134
 	}
135 135
 
136 136
 	/**
@@ -142,20 +142,20 @@  discard block
 block discarded – undo
142 142
 	 * @param integer $value Session variable
143 143
 	 * @return string Session variable
144 144
 	 */
145
-	public function set( $key, $value ) {
146
-		$key = sanitize_key( $key );
145
+	public function set($key, $value) {
146
+		$key = sanitize_key($key);
147 147
 
148
-		if ( is_array( $value ) ) {
149
-			$this->session[ $key ] = maybe_serialize( $value );
148
+		if (is_array($value)) {
149
+			$this->session[$key] = maybe_serialize($value);
150 150
 		} else {
151
-			$this->session[ $key ] = $value;
151
+			$this->session[$key] = $value;
152 152
 		}
153 153
 
154
-		if ( $this->use_php_sessions ) {
155
-			$_SESSION['wpi' . $this->prefix ] = $this->session;
154
+		if ($this->use_php_sessions) {
155
+			$_SESSION['wpi' . $this->prefix] = $this->session;
156 156
 		}
157 157
 
158
-		return $this->session[ $key ];
158
+		return $this->session[$key];
159 159
 	}
160 160
 	
161 161
 	/**
@@ -167,29 +167,29 @@  discard block
 block discarded – undo
167 167
 	 * @param integer $value Session variable.
168 168
 	 * @return string Session variable.
169 169
 	 */
170
-	public function un_set( $key ) {
171
-		if ( empty( $key ) ) {
170
+	public function un_set($key) {
171
+		if (empty($key)) {
172 172
 			return false;
173 173
 		}
174 174
 		
175
-		if ( is_array( $key ) ) {
175
+		if (is_array($key)) {
176 176
 			foreach ($key as $index) {
177
-				$index = sanitize_key( $index );
177
+				$index = sanitize_key($index);
178 178
 			
179
-				if ( $index && isset( $this->session[ $index ] ) ) {
180
-					unset( $this->session[ $index ] );
179
+				if ($index && isset($this->session[$index])) {
180
+					unset($this->session[$index]);
181 181
 				}
182 182
 			}
183 183
 		} else {
184
-			$key = sanitize_key( $key );
184
+			$key = sanitize_key($key);
185 185
 			
186
-			if ( isset( $this->session[ $key ] ) ) {
187
-				unset( $this->session[ $key ] );
186
+			if (isset($this->session[$key])) {
187
+				unset($this->session[$key]);
188 188
 			}
189 189
 		}
190 190
 
191
-		if ( $this->use_php_sessions ) {
192
-			$_SESSION['wpi' . $this->prefix ] = $this->session;
191
+		if ($this->use_php_sessions) {
192
+			$_SESSION['wpi' . $this->prefix] = $this->session;
193 193
 		}
194 194
 
195 195
 		return true;
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 	 * @param integer $value Session variable.
205 205
 	 * @return string Session variable.
206 206
 	 */
207
-	public function is_set( $key ) {
208
-		$key = sanitize_key( $key );
207
+	public function is_set($key) {
208
+		$key = sanitize_key($key);
209 209
 		
210
-		if ( empty( $key ) ) {
210
+		if (empty($key)) {
211 211
 			return false;
212 212
 		}
213 213
 
214
-		if ( isset( $this->session[ $key ] ) ) {
214
+		if (isset($this->session[$key])) {
215 215
 			return true;
216 216
 		}
217 217
 
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param int $exp Default expiration (1 hour)
227 227
 	 * @return int
228 228
 	 */
229
-	public function set_expiration_variant_time( $exp ) {
230
-		return ( 30 * 60 * 23 );
229
+	public function set_expiration_variant_time($exp) {
230
+		return (30 * 60 * 23);
231 231
 	}
232 232
 
233 233
 	/**
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
 	 * @param int $exp Default expiration (1 hour)
239 239
 	 * @return int
240 240
 	 */
241
-	public function set_expiration_time( $exp ) {
242
-		return ( 30 * 60 * 24 );
241
+	public function set_expiration_time($exp) {
242
+		return (30 * 60 * 24);
243 243
 	}
244 244
 
245 245
 	/**
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
 		$ret = false;
258 258
 
259 259
 		// If the database variable is already set, no need to run autodetection
260
-		$wpinv_use_php_sessions = (bool)get_option( 'wpinv_use_php_sessions' );
260
+		$wpinv_use_php_sessions = (bool)get_option('wpinv_use_php_sessions');
261 261
 
262
-		if (!$wpinv_use_php_sessions ) {
262
+		if (!$wpinv_use_php_sessions) {
263 263
 			// Attempt to detect if the server supports PHP sessions
264
-			if ( function_exists( 'session_start' ) && ! ini_get( 'safe_mode' ) ) {
265
-				$this->set( 'wpinv_use_php_sessions', 1 );
264
+			if (function_exists('session_start') && !ini_get('safe_mode')) {
265
+				$this->set('wpinv_use_php_sessions', 1);
266 266
 				
267
-				if ( $this->get( 'wpinv_use_php_sessions' ) ) {
267
+				if ($this->get('wpinv_use_php_sessions')) {
268 268
 					$ret = true;
269 269
 
270 270
 					// Set the database option
271
-					update_option( 'wpinv_use_php_sessions', true );
271
+					update_option('wpinv_use_php_sessions', true);
272 272
 				}
273 273
 			}
274 274
 		} else {
@@ -276,20 +276,20 @@  discard block
 block discarded – undo
276 276
 		}
277 277
 
278 278
 		// Enable or disable PHP Sessions based on the WPINV_USE_PHP_SESSIONS constant
279
-		if ( defined( 'WPINV_USE_PHP_SESSIONS' ) && WPINV_USE_PHP_SESSIONS ) {
279
+		if (defined('WPINV_USE_PHP_SESSIONS') && WPINV_USE_PHP_SESSIONS) {
280 280
 			$ret = true;
281
-		} else if ( defined( 'WPINV_USE_PHP_SESSIONS' ) && ! WPINV_USE_PHP_SESSIONS ) {
281
+		} else if (defined('WPINV_USE_PHP_SESSIONS') && !WPINV_USE_PHP_SESSIONS) {
282 282
 			$ret = false;
283 283
 		}
284 284
 
285
-		return (bool) apply_filters( 'wpinv_use_php_sessions', $ret );
285
+		return (bool)apply_filters('wpinv_use_php_sessions', $ret);
286 286
 	}
287 287
 
288 288
 	/**
289 289
 	 * Starts a new session if one hasn't started yet.
290 290
 	 */
291 291
 	public function maybe_start_session() {
292
-		if ( !session_id() && !headers_sent() ) {
292
+		if (!session_id() && !headers_sent()) {
293 293
 			session_start();
294 294
 		}
295 295
 	}
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -34,26 +34,26 @@  discard block
 block discarded – undo
34 34
     public $filter;
35 35
 
36 36
 
37
-    public function __construct( $_id = false, $_args = array() ) {
38
-        $item = WP_Post::get_instance( $_id );
39
-        return $this->setup_item( $item );
37
+    public function __construct($_id = false, $_args = array()) {
38
+        $item = WP_Post::get_instance($_id);
39
+        return $this->setup_item($item);
40 40
     }
41 41
 
42
-    private function setup_item( $item ) {
43
-        if( ! is_object( $item ) ) {
42
+    private function setup_item($item) {
43
+        if (!is_object($item)) {
44 44
             return false;
45 45
         }
46 46
 
47
-        if( ! is_a( $item, 'WP_Post' ) ) {
47
+        if (!is_a($item, 'WP_Post')) {
48 48
             return false;
49 49
         }
50 50
 
51
-        if( 'wpi_item' !== $item->post_type ) {
51
+        if ('wpi_item' !== $item->post_type) {
52 52
             return false;
53 53
         }
54 54
 
55
-        foreach ( $item as $key => $value ) {
56
-            switch ( $key ) {
55
+        foreach ($item as $key => $value) {
56
+            switch ($key) {
57 57
                 default:
58 58
                     $this->$key = $value;
59 59
                     break;
@@ -63,76 +63,76 @@  discard block
 block discarded – undo
63 63
         return true;
64 64
     }
65 65
 
66
-    public function __get( $key ) {
67
-        if ( method_exists( $this, 'get_' . $key ) ) {
68
-            return call_user_func( array( $this, 'get_' . $key ) );
66
+    public function __get($key) {
67
+        if (method_exists($this, 'get_' . $key)) {
68
+            return call_user_func(array($this, 'get_' . $key));
69 69
         } else {
70
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
70
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
71 71
         }
72 72
     }
73 73
 
74
-    public function create( $data = array(), $wp_error = false ) {
75
-        if ( $this->ID != 0 ) {
74
+    public function create($data = array(), $wp_error = false) {
75
+        if ($this->ID != 0) {
76 76
             return false;
77 77
         }
78 78
 
79 79
         $defaults = array(
80 80
             'post_type'   => 'wpi_item',
81 81
             'post_status' => 'draft',
82
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
82
+            'post_title'  => __('New Invoice Item', 'invoicing')
83 83
         );
84 84
 
85
-        $args = wp_parse_args( $data, $defaults );
85
+        $args = wp_parse_args($data, $defaults);
86 86
 
87
-        do_action( 'wpinv_item_pre_create', $args );
87
+        do_action('wpinv_item_pre_create', $args);
88 88
 
89
-        $id = wp_insert_post( $args, $wp_error );
89
+        $id = wp_insert_post($args, $wp_error);
90 90
         if ($wp_error && is_wp_error($id)) {
91 91
             return $id;
92 92
         }
93
-        if ( !$id ) {
93
+        if (!$id) {
94 94
             return false;
95 95
         }
96 96
         
97
-        $item = WP_Post::get_instance( $id );
97
+        $item = WP_Post::get_instance($id);
98 98
         
99 99
         if (!empty($item) && !empty($data['meta'])) {
100 100
             $this->ID = $item->ID;
101 101
             $this->save_metas($data['meta']);
102 102
         }
103 103
 
104
-        do_action( 'wpinv_item_create', $id, $args );
104
+        do_action('wpinv_item_create', $id, $args);
105 105
 
106
-        return $this->setup_item( $item );
106
+        return $this->setup_item($item);
107 107
     }
108 108
     
109
-    public function update( $data = array(), $wp_error = false ) {
110
-        if ( !$this->ID > 0 ) {
109
+    public function update($data = array(), $wp_error = false) {
110
+        if (!$this->ID > 0) {
111 111
             return false;
112 112
         }
113 113
         
114 114
         $data['ID'] = $this->ID;
115 115
 
116
-        do_action( 'wpinv_item_pre_update', $data );
116
+        do_action('wpinv_item_pre_update', $data);
117 117
         
118
-        $id = wp_update_post( $data, $wp_error );
118
+        $id = wp_update_post($data, $wp_error);
119 119
         if ($wp_error && is_wp_error($id)) {
120 120
             return $id;
121 121
         }
122 122
         
123
-        if ( !$id ) {
123
+        if (!$id) {
124 124
             return false;
125 125
         }
126 126
 
127
-        $item = WP_Post::get_instance( $id );
127
+        $item = WP_Post::get_instance($id);
128 128
         if (!empty($item) && !empty($data['meta'])) {
129 129
             $this->ID = $item->ID;
130 130
             $this->save_metas($data['meta']);
131 131
         }
132 132
 
133
-        do_action( 'wpinv_item_update', $id, $data );
133
+        do_action('wpinv_item_update', $id, $data);
134 134
 
135
-        return $this->setup_item( $item );
135
+        return $this->setup_item($item);
136 136
     }
137 137
 
138 138
     public function get_ID() {
@@ -140,95 +140,95 @@  discard block
 block discarded – undo
140 140
     }
141 141
 
142 142
     public function get_name() {
143
-        return get_the_title( $this->ID );
143
+        return get_the_title($this->ID);
144 144
     }
145 145
     
146 146
     public function get_summary() {
147
-        return get_the_excerpt( $this->ID );
147
+        return get_the_excerpt($this->ID);
148 148
     }
149 149
 
150 150
     public function get_price() {
151
-        if ( ! isset( $this->price ) ) {
152
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
151
+        if (!isset($this->price)) {
152
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
153 153
             
154
-            if ( $this->price ) {
155
-                $this->price = wpinv_sanitize_amount( $this->price );
154
+            if ($this->price) {
155
+                $this->price = wpinv_sanitize_amount($this->price);
156 156
             } else {
157 157
                 $this->price = 0;
158 158
             }
159 159
         }
160 160
         
161
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
161
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
162 162
     }
163 163
     
164 164
     public function get_the_price() {
165
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
165
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
166 166
         
167
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
167
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
168 168
     }
169 169
     
170 170
     public function get_vat_rule() {
171 171
         global $wpinv_euvat;
172 172
         
173
-        if( !isset( $this->vat_rule ) ) {
174
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
173
+        if (!isset($this->vat_rule)) {
174
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
175 175
 
176
-            if ( empty( $this->vat_rule ) ) {        
176
+            if (empty($this->vat_rule)) {        
177 177
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
178 178
             }
179 179
         }
180 180
         
181
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
181
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
182 182
     }
183 183
     
184 184
     public function get_vat_class() {
185
-        if( !isset( $this->vat_class ) ) {
186
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
185
+        if (!isset($this->vat_class)) {
186
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
187 187
 
188
-            if ( empty( $this->vat_class ) ) {        
188
+            if (empty($this->vat_class)) {        
189 189
                 $this->vat_class = '_standard';
190 190
             }
191 191
         }
192 192
         
193
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
193
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
194 194
     }
195 195
     
196 196
     public function get_cpt_singular_name() {
197
-        if( ! isset( $this->cpt_singular_name ) ) {
198
-            $this->cpt_singular_name = get_post_meta( $this->ID, '_wpinv_cpt_singular_name', true );
197
+        if (!isset($this->cpt_singular_name)) {
198
+            $this->cpt_singular_name = get_post_meta($this->ID, '_wpinv_cpt_singular_name', true);
199 199
         }
200 200
 
201
-        return apply_filters( 'wpinv_item_get_cpt_singular_name', $this->cpt_singular_name, $this->ID );
201
+        return apply_filters('wpinv_item_get_cpt_singular_name', $this->cpt_singular_name, $this->ID);
202 202
     }
203 203
 
204 204
     public function get_type() {
205
-        if( ! isset( $this->type ) ) {
206
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
205
+        if (!isset($this->type)) {
206
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
207 207
 
208
-            if ( empty( $this->type ) ) {
208
+            if (empty($this->type)) {
209 209
                 $this->type = 'custom';
210 210
             }
211 211
         }
212 212
 
213
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
213
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
214 214
     }
215 215
     
216 216
     public function is_recurring() {
217
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
217
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
218 218
 
219
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
219
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
220 220
 
221 221
     }
222 222
     
223
-    public function get_recurring_period( $full = false ) {
224
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
223
+    public function get_recurring_period($full = false) {
224
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
225 225
         
226
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
226
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
227 227
             $period = 'D';
228 228
         }
229 229
         
230
-        if ( $full ) {
231
-            switch( $period ) {
230
+        if ($full) {
231
+            switch ($period) {
232 232
                 case 'D':
233 233
                     $period = 'day';
234 234
                 break;
@@ -244,45 +244,45 @@  discard block
 block discarded – undo
244 244
             }
245 245
         }
246 246
 
247
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
247
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
248 248
 
249 249
     }
250 250
     
251 251
     public function get_recurring_interval() {
252
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
252
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
253 253
         
254
-        if ( !$interval > 0 ) {
254
+        if (!$interval > 0) {
255 255
             $interval = 1;
256 256
         }
257 257
 
258
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
258
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
259 259
 
260 260
     }
261 261
     
262 262
     public function get_recurring_limit() {
263
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
263
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
264 264
 
265
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
265
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
266 266
 
267 267
     }
268 268
     
269 269
     public function has_free_trial() {
270
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
271
-        $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false;
270
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
271
+        $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false;
272 272
 
273
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
273
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
274 274
 
275 275
     }
276 276
     
277
-    public function get_trial_period( $full = false ) {
278
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
277
+    public function get_trial_period($full = false) {
278
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
279 279
         
280
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
280
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
281 281
             $period = 'D';
282 282
         }
283 283
         
284
-        if ( $full ) {
285
-            switch( $period ) {
284
+        if ($full) {
285
+            switch ($period) {
286 286
                 case 'D':
287 287
                     $period = 'day';
288 288
                 break;
@@ -298,47 +298,47 @@  discard block
 block discarded – undo
298 298
             }
299 299
         }
300 300
 
301
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
301
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
302 302
 
303 303
     }
304 304
     
305 305
     public function get_trial_interval() {
306
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
306
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
307 307
         
308
-        if ( !$interval > 0 ) {
308
+        if (!$interval > 0) {
309 309
             $interval = 1;
310 310
         }
311 311
 
312
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
312
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
313 313
 
314 314
     }
315 315
 
316 316
     public function is_free() {
317 317
         $is_free = false;
318 318
         
319
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
319
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
320 320
 
321
-        if ( (float)$price == 0 ) {
321
+        if ((float)$price == 0) {
322 322
             $is_free = true;
323 323
         }
324 324
 
325
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
325
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
326 326
 
327 327
     }
328 328
     
329 329
     public function is_package() {
330 330
         $is_package = $this->get_type() == 'package' ? true : false;
331 331
 
332
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
332
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
333 333
 
334 334
     }
335 335
     
336
-    public function save_metas( $metas = array() ) {
337
-        if ( empty( $metas ) ) {
336
+    public function save_metas($metas = array()) {
337
+        if (empty($metas)) {
338 338
             return false;
339 339
         }
340 340
         
341
-        foreach ( $metas as $meta_key => $meta_value ) {
341
+        foreach ($metas as $meta_key => $meta_value) {
342 342
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
343 343
             
344 344
             $this->update_meta($meta_key, $meta_value);
@@ -347,66 +347,66 @@  discard block
 block discarded – undo
347 347
         return true;
348 348
     }
349 349
 
350
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
351
-        if ( empty( $meta_key ) ) {
350
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
351
+        if (empty($meta_key)) {
352 352
             return false;
353 353
         }
354 354
         
355
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
355
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
356 356
 
357
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
357
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
358 358
     }
359 359
     
360
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
360
+    public function get_fees($type = 'fee', $item_id = 0) {
361 361
         global $wpi_session;
362 362
         
363
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
363
+        $fees = $wpi_session->get('wpi_cart_fees');
364 364
 
365
-        if ( ! wpinv_get_cart_contents() ) {
365
+        if (!wpinv_get_cart_contents()) {
366 366
             // We can only get item type fees when the cart is empty
367 367
             $type = 'custom';
368 368
         }
369 369
 
370
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
371
-            foreach( $fees as $key => $fee ) {
372
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
373
-                    unset( $fees[ $key ] );
370
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
371
+            foreach ($fees as $key => $fee) {
372
+                if (!empty($fee['type']) && $type != $fee['type']) {
373
+                    unset($fees[$key]);
374 374
                 }
375 375
             }
376 376
         }
377 377
 
378
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
378
+        if (!empty($fees) && !empty($item_id)) {
379 379
             // Remove fees that don't belong to the specified Item
380
-            foreach ( $fees as $key => $fee ) {
381
-                if ( (int) $item_id !== (int)$fee['item_id'] ) {
382
-                    unset( $fees[ $key ] );
380
+            foreach ($fees as $key => $fee) {
381
+                if ((int)$item_id !== (int)$fee['item_id']) {
382
+                    unset($fees[$key]);
383 383
                 }
384 384
             }
385 385
         }
386 386
 
387
-        if ( ! empty( $fees ) ) {
387
+        if (!empty($fees)) {
388 388
             // Remove fees that belong to a specific item but are not in the cart
389
-            foreach( $fees as $key => $fee ) {
390
-                if( empty( $fee['item_id'] ) ) {
389
+            foreach ($fees as $key => $fee) {
390
+                if (empty($fee['item_id'])) {
391 391
                     continue;
392 392
                 }
393 393
 
394
-                if ( !wpinv_item_in_cart( $fee['item_id'] ) ) {
395
-                    unset( $fees[ $key ] );
394
+                if (!wpinv_item_in_cart($fee['item_id'])) {
395
+                    unset($fees[$key]);
396 396
                 }
397 397
             }
398 398
         }
399 399
 
400
-        return ! empty( $fees ) ? $fees : array();
400
+        return !empty($fees) ? $fees : array();
401 401
     }
402 402
     
403 403
     public function can_purchase() {
404 404
         $can_purchase = true;
405 405
 
406
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
406
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
407 407
             $can_purchase = false;
408 408
         }
409 409
 
410
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
410
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
411 411
     }
412 412
 }
Please login to merge, or discard this patch.
includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	public function __construct($login, $transkey, $test = self::USE_PRODUCTION_SERVER)
52 52
 	{
53
-		$login    = trim($login);
53
+		$login = trim($login);
54 54
         $transkey = trim($transkey);
55 55
         if (empty($login) || empty($transkey))
56 56
         {
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
         $this->login    = trim($login);
61 61
         $this->transkey = trim($transkey);
62
-        $test           = (bool) $test;
62
+        $test           = (bool)$test;
63 63
 
64 64
         $subdomain = ($test) ? 'apitest' : 'api';
65 65
         $this->url = 'https://' . $subdomain . '.authorize.net/xml/v1/request.api';
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
     private function removeResponseXMLNS($input)
74 74
     {
75 75
         // why remove them one at a time? all three aren't consistantly used in the response
76
-        $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"','',$input);
77
-        $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','',$input);
78
-        return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"','',$input);
76
+        $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $input);
77
+        $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', '', $input);
78
+        return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"', '', $input);
79 79
     }
80 80
 
81 81
 	public function __toString()
82 82
 	{
83
-	    $output  = '';
83
+	    $output = '';
84 84
         $output .= '<table summary="Authorize.Net Results" id="authnet">' . "\n";
85 85
         $output .= '<tr>' . "\n\t\t" . '<th colspan="2"><b>Class Parameters</b></th>' . "\n" . '</tr>' . "\n";
86 86
         $output .= '<tr>' . "\n\t\t" . '<td><b>API Login ID</b></td><td>' . $this->login . '</td>' . "\n" . '</tr>' . "\n";
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
             {
160 160
                 if (is_array($value))
161 161
                 {
162
-                    if(is_numeric($key))
162
+                    if (is_numeric($key))
163 163
                     {
164
-                        if($first === true)
164
+                        if ($first === true)
165 165
                         {
166 166
                             $xmlx  = $xml;
167 167
                             $first = false;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     	curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
201 201
     	curl_setopt($this->ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ssl/cert.pem');
202 202
 
203
-        if(($this->response = curl_exec($this->ch)) !== false)
203
+        if (($this->response = curl_exec($this->ch)) !== false)
204 204
         {
205 205
             $this->response_xml = @new SimpleXMLElement($this->response);
206 206
 
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetAIM.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
      * A list of all fields in the AIM API.
78 78
      * Used to warn user if they try to set a field not offered in the API.
79 79
      */
80
-    private $_all_aim_fields = array("address","allow_partial_auth","amount",
81
-        "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name",
82
-        "bank_acct_num","bank_acct_type","bank_check_number","bank_name",
83
-        "card_code","card_num","cardholder_authentication_value","city","company",
84
-        "country","cust_id","customer_ip","delim_char","delim_data","description",
85
-        "duplicate_window","duty","echeck_type","email","email_customer",
86
-        "encap_char","exp_date","fax","first_name","footer_email_receipt",
87
-        "freight","header_email_receipt","invoice_num","last_name","line_item",
88
-        "login","method","phone","po_num","recurring_billing","relay_response",
89
-        "ship_to_address","ship_to_city","ship_to_company","ship_to_country",
90
-        "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip",
91
-        "split_tender_id","state","tax","tax_exempt","test_request","tran_key",
92
-        "trans_id","type","version","zip"
80
+    private $_all_aim_fields = array("address", "allow_partial_auth", "amount",
81
+        "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name",
82
+        "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name",
83
+        "card_code", "card_num", "cardholder_authentication_value", "city", "company",
84
+        "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description",
85
+        "duplicate_window", "duty", "echeck_type", "email", "email_customer",
86
+        "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt",
87
+        "freight", "header_email_receipt", "invoice_num", "last_name", "line_item",
88
+        "login", "method", "phone", "po_num", "recurring_billing", "relay_response",
89
+        "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country",
90
+        "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip",
91
+        "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key",
92
+        "trans_id", "type", "version", "zip"
93 93
         );
94 94
     
95 95
     /**
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
             // Split Array
404 404
             $this->response = $response;
405 405
             if ($encap_char) {
406
-                $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
406
+                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
407 407
             } else {
408 408
                 $this->_response_array = explode($delimiter, $response);
409 409
             }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
             $this->duty                 = $this->_response_array[33];
458 458
             $this->freight              = $this->_response_array[34];
459 459
             $this->tax_exempt           = $this->_response_array[35];
460
-            $this->purchase_order_number= $this->_response_array[36];
460
+            $this->purchase_order_number = $this->_response_array[36];
461 461
             $this->md5_hash             = $this->_response_array[37];
462 462
             $this->card_code_response   = $this->_response_array[38];
463 463
             $this->cavv_response        = $this->_response_array[39];
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
             
485 485
             if ($this->error) {
486 486
                 $this->error_message = "AuthorizeNet Error:
487
-                Response Code: ".$this->response_code."
488
-                Response Subcode: ".$this->response_subcode."
489
-                Response Reason Code: ".$this->response_reason_code."
490
-                Response Reason Text: ".$this->response_reason_text."
487
+                Response Code: ".$this->response_code . "
488
+                Response Subcode: ".$this->response_subcode . "
489
+                Response Reason Code: ".$this->response_reason_code . "
490
+                Response Reason Text: ".$this->response_reason_text . "
491 491
                 ";
492 492
             }
493 493
         } else {
Please login to merge, or discard this patch.