| @@ -2,12 +2,12 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Responsible for managing user sessions. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable Session |
| 6 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 6 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 7 | 7 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 8 | 8 | * @since 1.0.0 |
| 9 | - * @version 1.6.49 | |
| 9 | + * @version 1.8.9.1 | |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -61,9 +61,9 @@ | ||
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if ( ! defined( 'WP_SESSION_COOKIE' ) ) { |
| 65 | - define( 'WP_SESSION_COOKIE', 'charitable_session' ); | |
| 65 | + define( 'WP_SESSION_COOKIE', 'charitable_session' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- This is a bundled library constant. Changing it would break existing functionality. | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ( ! class_exists( 'Recursive_ArrayAccess' ) ) { |
| 69 | 69 | require_once( charitable()->get_path( 'includes' ) . 'libraries/wp-session/class-recursive-arrayaccess.php' ); |
| @@ -114,21 +114,17 @@ | ||
| 114 | 114 | * |
| 115 | 115 | * @return void |
| 116 | 116 | */ |
| 117 | 117 | public function enqueue_scripts() { |
| 118 | - if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) { | |
| 119 | - $suffix = ''; | |
| 120 | - $version = ''; | |
| 121 | - } else { | |
| 122 | - $suffix = '.min'; | |
| 123 | - $version = charitable()->get_version(); | |
| 124 | - } | |
| 125 | 118 | |
| 119 | + $min = charitable_get_min_suffix(); | |
| 120 | + $version = charitable()->get_version(); | |
| 121 | + | |
| 126 | 122 | $assets_dir = charitable()->get_path( 'assets', false ); |
| 127 | 123 | |
| 128 | 124 | wp_register_script( |
| 129 | 125 | 'js-cookie', |
| 130 | - $assets_dir . 'js/libraries/js-cookie' . $suffix . '.js', | |
| 126 | + $assets_dir . 'js/libraries/js-cookie' . $min . '.js', | |
| 131 | 127 | array(), |
| 132 | 128 | '2.1.4', |
| 133 | 129 | false |
| 134 | 130 | ); |
| @@ -134,9 +130,9 @@ | ||
| 134 | 130 | ); |
| 135 | 131 | |
| 136 | 132 | wp_enqueue_script( |
| 137 | 133 | 'charitable-sessions', |
| 138 | - $assets_dir . 'js/charitable-session' . $suffix . '.js', | |
| 134 | + $assets_dir . 'js/charitable-session' . $min . '.js', | |
| 139 | 135 | array( 'js-cookie' ), |
| 140 | 136 | $version, |
| 141 | 137 | false |
| 142 | 138 | ); |
| @@ -149,9 +145,9 @@ | ||
| 149 | 145 | 'id' => $this->get_session_id(), |
| 150 | 146 | 'cookie_name' => WP_SESSION_COOKIE, |
| 151 | 147 | 'expiration' => $this->set_session_length(), |
| 152 | 148 | 'expiration_variant' => $this->set_session_expiration_variant_length(), |
| 153 | - 'secure' => (bool) apply_filters( 'wp_session_cookie_secure', false ), | |
| 149 | + 'secure' => (bool) apply_filters( 'wp_session_cookie_secure', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- This is a bundled library hook. Changing it would break existing functionality. | |
| 154 | 150 | 'cookie_path' => COOKIEPATH, |
| 155 | 151 | 'cookie_domain' => COOKIE_DOMAIN, |
| 156 | 152 | 'generated_id' => WP_Session_Utils::generate_id(), |
| 157 | 153 | 'disable_cookie' => $this->disable_cookie, |
| @@ -284,8 +280,19 @@ | ||
| 284 | 280 | */ |
| 285 | 281 | public function add_donation( $campaign_id, $amount, $period = 'once' ) { |
| 286 | 282 | $donations = $this->get( 'donations' ); |
| 287 | 283 | |
| 284 | + /* | |
| 285 | + * get() returns false when the key is not in the session, which is the normal state for the | |
| 286 | + * first donation of a fresh session. Assigning $donations[ $campaign_id ] to that false | |
| 287 | + * relied on PHP silently converting it to an array - deprecated in PHP 8.1 and a fatal | |
| 288 | + * TypeError in PHP 9, on the donation path. add_donation_key() below already guards exactly | |
| 289 | + * this way; this method was simply missing it. | |
| 290 | + */ | |
| 291 | + if ( ! is_array( $donations ) ) { | |
| 292 | + $donations = array(); | |
| 293 | + } | |
| 294 | + | |
| 288 | 295 | $campaign_donation = isset( $donations[ $campaign_id ] ) ? $donations[ $campaign_id ] : array(); |
| 289 | 296 | $campaign_donation['amount'] = floatval( charitable_get_currency_helper()->cast_to_decimal_format( $amount ) ); |
| 290 | 297 | $campaign_donation['donation_period'] = $period; |
| 291 | 298 | |
| @@ -403,9 +410,13 @@ | ||
| 403 | 410 | * |
| 404 | 411 | * @return string Session ID |
| 405 | 412 | */ |
| 406 | 413 | public function get_session_id() { |
| 407 | - return $this->session->session_id; | |
| 414 | + if ( isset( $this->session->session_id ) ) { | |
| 415 | + return $this->session->session_id; | |
| 416 | + } else { | |
| 417 | + return false; | |
| 418 | + } | |
| 408 | 419 | } |
| 409 | 420 | |
| 410 | 421 | /** |
| 411 | 422 | * Determines if we should start sessions |
| @@ -418,9 +429,9 @@ | ||
| 418 | 429 | $start_session = true; |
| 419 | 430 | |
| 420 | 431 | if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { |
| 421 | 432 | $blocklist = $this->get_blocklist(); |
| 422 | - $uri = ltrim( $_SERVER['REQUEST_URI'], '/' ); | |
| 433 | + $uri = ltrim( $_SERVER['REQUEST_URI'], '/' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 423 | 434 | $uri = untrailingslashit( $uri ); |
| 424 | 435 | |
| 425 | 436 | if ( in_array( $uri, $blocklist ) ) { |
| 426 | 437 | $start_session = false; |