@@ -1,61 +1,61 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_print_errors() { |
8 | 8 | $errors = wpinv_get_errors(); |
9 | 9 | |
10 | - if ( $errors ) { |
|
11 | - $classes = apply_filters( 'wpinv_error_class', array( |
|
10 | + if ($errors) { |
|
11 | + $classes = apply_filters('wpinv_error_class', array( |
|
12 | 12 | 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-error' |
13 | - ) ); |
|
14 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
13 | + )); |
|
14 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
15 | 15 | // Loop error codes and display errors |
16 | - foreach ( $errors as $error_id => $error ) { |
|
17 | - echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>'; |
|
16 | + foreach ($errors as $error_id => $error) { |
|
17 | + echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __('Error', 'invoicing') . '</strong>: ' . $error . '</p>'; |
|
18 | 18 | } |
19 | 19 | echo '</div>'; |
20 | 20 | wpinv_clear_errors(); |
21 | 21 | } |
22 | 22 | } |
23 | -add_action( 'wpinv_purchase_form_before_submit', 'wpinv_print_errors' ); |
|
24 | -add_action( 'wpinv_ajax_checkout_errors', 'wpinv_print_errors' ); |
|
23 | +add_action('wpinv_purchase_form_before_submit', 'wpinv_print_errors'); |
|
24 | +add_action('wpinv_ajax_checkout_errors', 'wpinv_print_errors'); |
|
25 | 25 | |
26 | 26 | function wpinv_get_errors() { |
27 | 27 | global $wpi_session; |
28 | 28 | |
29 | - return $wpi_session->get( 'wpinv_errors' ); |
|
29 | + return $wpi_session->get('wpinv_errors'); |
|
30 | 30 | } |
31 | 31 | |
32 | -function wpinv_set_error( $error_id, $error_message ) { |
|
32 | +function wpinv_set_error($error_id, $error_message) { |
|
33 | 33 | global $wpi_session; |
34 | 34 | |
35 | 35 | $errors = wpinv_get_errors(); |
36 | 36 | |
37 | - if ( ! $errors ) { |
|
37 | + if (!$errors) { |
|
38 | 38 | $errors = array(); |
39 | 39 | } |
40 | 40 | |
41 | - $errors[ $error_id ] = $error_message; |
|
42 | - $wpi_session->set( 'wpinv_errors', $errors ); |
|
41 | + $errors[$error_id] = $error_message; |
|
42 | + $wpi_session->set('wpinv_errors', $errors); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function wpinv_clear_errors() { |
46 | 46 | global $wpi_session; |
47 | 47 | |
48 | - $wpi_session->set( 'wpinv_errors', null ); |
|
48 | + $wpi_session->set('wpinv_errors', null); |
|
49 | 49 | } |
50 | 50 | |
51 | -function wpinv_unset_error( $error_id ) { |
|
51 | +function wpinv_unset_error($error_id) { |
|
52 | 52 | global $wpi_session; |
53 | 53 | |
54 | 54 | $errors = wpinv_get_errors(); |
55 | 55 | |
56 | - if ( $errors ) { |
|
57 | - unset( $errors[ $error_id ] ); |
|
58 | - $wpi_session->set( 'wpinv_errors', $errors ); |
|
56 | + if ($errors) { |
|
57 | + unset($errors[$error_id]); |
|
58 | + $wpi_session->set('wpinv_errors', $errors); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | die(); |
64 | 64 | } |
65 | 65 | |
66 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
67 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
68 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
69 | - wp_die( $message, $title, array( 'response' => $status )); |
|
66 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
67 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
68 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
69 | + wp_die($message, $title, array('response' => $status)); |
|
70 | 70 | } |
@@ -130,7 +130,6 @@ |
||
130 | 130 | private function mostSpecificSubdivision() |
131 | 131 | { |
132 | 132 | return empty($this->subdivisions) ? |
133 | - new \GeoIp2\Record\Subdivision(array(), $this->locales) : |
|
134 | - end($this->subdivisions); |
|
133 | + new \GeoIp2\Record\Subdivision(array(), $this->locales) : end($this->subdivisions); |
|
135 | 134 | } |
136 | 135 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | // This is for backwards compatibility. Do not remove except for a |
77 | 77 | // major version bump. |
78 | 78 | if (is_string($options)) { |
79 | - $options = array( 'host' => $options ); |
|
79 | + $options = array('host' => $options); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | if (!isset($options['host'])) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if ($nodesWithStyleAttributes !== false) { |
239 | 239 | /** @var $nodeWithStyleAttribute DOMNode */ |
240 | 240 | foreach ($nodesWithStyleAttributes as $node) { |
241 | - $normalizedOriginalStyle = preg_replace_callback( '/[A-z\\-]+(?=\\:)/S', array( $this, 'strtolower' ), $node->getAttribute('style') ); |
|
241 | + $normalizedOriginalStyle = preg_replace_callback('/[A-z\\-]+(?=\\:)/S', array($this, 'strtolower'), $node->getAttribute('style')); |
|
242 | 242 | |
243 | 243 | // in order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles |
244 | 244 | $nodePath = $node->getNodePath(); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // now sort the selectors by precedence |
292 | - usort($allSelectors, array($this,'sortBySelectorPrecedence')); |
|
292 | + usort($allSelectors, array($this, 'sortBySelectorPrecedence')); |
|
293 | 293 | |
294 | 294 | $this->caches[self::CACHE_KEY_CSS][$cssKey] = $allSelectors; |
295 | 295 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | if ($nodesWithStyleDisplayNone->length > 0) { |
330 | 330 | /** @var $node \DOMNode */ |
331 | 331 | foreach ($nodesWithStyleDisplayNone as $node) { |
332 | - if ($node->parentNode && is_callable(array($node->parentNode,'removeChild'))) { |
|
332 | + if ($node->parentNode && is_callable(array($node->parentNode, 'removeChild'))) { |
|
333 | 333 | $node->parentNode->removeChild($node); |
334 | 334 | } |
335 | 335 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | $this->copyCssWithMediaToStyleNode($cssParts, $xmlDocument); |
339 | 339 | |
340 | 340 | if ($this->preserveEncoding) { |
341 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
342 | - return mb_convert_encoding( $xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES' ); |
|
341 | + if (function_exists('mb_convert_encoding')) { |
|
342 | + return mb_convert_encoding($xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES'); |
|
343 | 343 | } else { |
344 | - return htmlspecialchars_decode( utf8_encode( html_entity_decode( $xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING ) ) ); |
|
344 | + return htmlspecialchars_decode(utf8_encode(html_entity_decode($xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING))); |
|
345 | 345 | } |
346 | 346 | } else { |
347 | 347 | return $xmlDocument->saveHTML(); |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @return array |
463 | 463 | */ |
464 | 464 | private function splitCssAndMediaQuery($css) { |
465 | - $css = preg_replace_callback( '#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array( $this, '_media_concat' ), $css ); |
|
465 | + $css = preg_replace_callback('#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array($this, '_media_concat'), $css); |
|
466 | 466 | |
467 | 467 | // filter the CSS |
468 | 468 | $search = array( |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | return array('css' => $css, 'media' => self::$_media); |
487 | 487 | } |
488 | 488 | |
489 | - private function _media_concat( $matches ) { |
|
489 | + private function _media_concat($matches) { |
|
490 | 490 | self::$_media .= $matches[0]; |
491 | 491 | } |
492 | 492 | |
@@ -524,10 +524,10 @@ discard block |
||
524 | 524 | $bodyWithoutUnprocessableTags = $this->html; |
525 | 525 | } |
526 | 526 | |
527 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
528 | - return mb_convert_encoding( $bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING ); |
|
527 | + if (function_exists('mb_convert_encoding')) { |
|
528 | + return mb_convert_encoding($bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING); |
|
529 | 529 | } else { |
530 | - return htmlspecialchars_decode( utf8_decode( htmlentities( $bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false ) ) ); |
|
530 | + return htmlspecialchars_decode(utf8_decode(htmlentities($bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false))); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | $precedence = 0; |
563 | 563 | $value = 100; |
564 | 564 | // ids: worth 100, classes: worth 10, elements: worth 1 |
565 | - $search = array('\\#','\\.',''); |
|
565 | + $search = array('\\#', '\\.', ''); |
|
566 | 566 | |
567 | 567 | foreach ($search as $s) { |
568 | 568 | if (trim($selector == '')) { |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | */ |
591 | 591 | private function translateCssToXpath($paramCssSelector) { |
592 | 592 | $cssSelector = ' ' . $paramCssSelector . ' '; |
593 | - $cssSelector = preg_replace_callback( '/\s+\w+\s+/', array( $this, 'strtolower' ), $cssSelector ); |
|
593 | + $cssSelector = preg_replace_callback('/\s+\w+\s+/', array($this, 'strtolower'), $cssSelector); |
|
594 | 594 | $cssSelector = trim($cssSelector); |
595 | 595 | $xpathKey = md5($cssSelector); |
596 | 596 | if (!isset($this->caches[self::CACHE_KEY_XPATH][$xpathKey])) { |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | * @return array |
714 | 714 | */ |
715 | 715 | private function parseNth(array $match) { |
716 | - if (in_array(strtolower($match[2]), array('even','odd'))) { |
|
716 | + if (in_array(strtolower($match[2]), array('even', 'odd'))) { |
|
717 | 717 | $index = strtolower($match[2]) == 'even' ? 0 : 1; |
718 | 718 | return array(self::MULTIPLIER => 2, self::INDEX => $index); |
719 | 719 | } elseif (stripos($match[2], 'n') === false) { |
@@ -21,10 +21,10 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -33,10 +33,10 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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'); |
@@ -53,7 +53,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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(); |
@@ -36,9 +36,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -23,11 +23,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |