| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * @since 2.9 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Cookie { |
| 12 | 12 | /** |
| 13 | - * Parses the cookie parameters | |
| 13 | + * Parses the cookie parameters. | |
| 14 | 14 | * |
| 15 | 15 | * @since 2.9 |
| 16 | 16 | * |
| 17 | 17 | * @param array $args {@see PLL_Cookie::set()} |
| @@ -18,27 +18,51 @@ | ||
| 18 | 18 | * @return array |
| 19 | 19 | */ |
| 20 | 20 | protected static function parse_args( $args ) { |
| 21 | 21 | /** |
| 22 | - * Filter the Polylang cookie duration | |
| 23 | - * /!\ this filter may be fired *before* the theme is loaded | |
| 22 | + * Filters the Polylang cookie duration. | |
| 24 | 23 | * |
| 24 | + * If a cookie duration of 0 is specified, a session cookie will be set. | |
| 25 | + * If a negative cookie duration is specified, the cookie is removed. | |
| 26 | + * /!\ This filter may be fired *before* the theme is loaded. | |
| 27 | + * | |
| 25 | 28 | * @since 1.8 |
| 26 | 29 | * |
| 27 | - * @param int $duration cookie duration in seconds | |
| 30 | + * @param int $duration Cookie duration in seconds. | |
| 28 | 31 | */ |
| 29 | - $expiration = apply_filters( 'pll_cookie_expiration', YEAR_IN_SECONDS ); | |
| 32 | + $expiration = (int) apply_filters( 'pll_cookie_expiration', YEAR_IN_SECONDS ); | |
| 30 | 33 | |
| 31 | 34 | $defaults = array( |
| 32 | - 'expires' => time() + $expiration, | |
| 35 | + 'expires' => 0 !== $expiration ? time() + $expiration : 0, | |
| 33 | 36 | 'path' => COOKIEPATH, |
| 34 | - 'domain' => COOKIE_DOMAIN, // Cookie domain must be set to false for localhost ( default value for COOKIE_DOMAIN ) thanks to Stephen Harris. | |
| 37 | + 'domain' => COOKIE_DOMAIN, // Cookie domain must be set to false for localhost (default value for `COOKIE_DOMAIN`) thanks to Stephen Harris. | |
| 35 | 38 | 'secure' => is_ssl(), |
| 36 | 39 | 'httponly' => false, |
| 37 | 40 | 'samesite' => 'Lax', |
| 38 | 41 | ); |
| 39 | 42 | |
| 40 | - return wp_parse_args( $args, $defaults ); | |
| 43 | + $args = wp_parse_args( $args, $defaults ); | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Filters the Polylang cookie arguments. | |
| 47 | + * /!\ This filter may be fired *before* the theme is loaded. | |
| 48 | + * | |
| 49 | + * @since 3.6 | |
| 50 | + * | |
| 51 | + * @param array $args { | |
| 52 | + * Optional. Array of arguments for setting the cookie. | |
| 53 | + * | |
| 54 | + * @type int $expires Cookie duration. | |
| 55 | + * If a cookie duration of 0 is specified, a session cookie will be set. | |
| 56 | + * If a negative cookie duration is specified, the cookie is removed. | |
| 57 | + * @type string $path Cookie path. | |
| 58 | + * @type string $domain Cookie domain. Must be set to false for localhost (default value for `COOKIE_DOMAIN`). | |
| 59 | + * @type bool $secure Should the cookie be sent only over https? | |
| 60 | + * @type bool $httponly Should the cookie be accessed only over http protocol?. | |
| 61 | + * @type string $samesite Either 'Strict', 'Lax' or 'None'. | |
| 62 | + * } | |
| 63 | + */ | |
| 64 | + return (array) apply_filters( 'pll_cookie_args', $args ); | |
| 41 | 65 | } |
| 42 | 66 | |
| 43 | 67 | /** |
| 44 | 68 | * Sets the cookie. |
| @@ -54,8 +78,9 @@ | ||
| 54 | 78 | * @type bool $secure Should the cookie be sent only over https? |
| 55 | 79 | * @type bool $httponly Should the cookie accessed only over http protocol? Defaults to false. |
| 56 | 80 | * @type string $samesite Either 'Strict', 'Lax' or 'None', defaults to 'Lax'. |
| 57 | 81 | * } |
| 82 | + * @return void | |
| 58 | 83 | */ |
| 59 | 84 | public static function set( $lang, $args = array() ) { |
| 60 | 85 | $args = self::parse_args( $args ); |
| 61 | 86 | |