Skip to content

Commit 0c248dc

Browse files
committed
General: Pass $action to nonce_life filter.
This changeset contextualizes the usage of `nonce_life` filter by passing the `$action` parameter. It allows to alterate the default lifespan of nonces on a case by case basis. Props giuseppemazzapica, dwainm, DrewAPicture, jorbin, audrasjb, SergeyBiryukov, costdev, antonvlasenko. Fixes #35188. git-svn-id: https://develop.svn.wordpress.org/trunk@54218 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8127aae commit 0c248dc

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/wp-includes/pluggable.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,18 +2245,22 @@ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' )
22452245
* updated, e.g. by autosave.
22462246
*
22472247
* @since 2.5.0
2248+
* @since 6.1.0 Added `action` argument.
22482249
*
2250+
* @param string|int $action Optional. The current nonce action. Default -1.
22492251
* @return float Float value rounded up to the next highest integer.
22502252
*/
2251-
function wp_nonce_tick() {
2253+
function wp_nonce_tick( $action = -1 ) {
22522254
/**
22532255
* Filters the lifespan of nonces in seconds.
22542256
*
22552257
* @since 2.5.0
2258+
* @since 6.1.0 Added `action` argument to allow for more targeted filters.
22562259
*
2257-
* @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day.
2260+
* @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day.
2261+
* @param string|int $action The current nonce action.
22582262
*/
2259-
$nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS );
2263+
$nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS, $action );
22602264

22612265
return ceil( time() / ( $nonce_life / 2 ) );
22622266
}
@@ -2297,7 +2301,7 @@ function wp_verify_nonce( $nonce, $action = -1 ) {
22972301
}
22982302

22992303
$token = wp_get_session_token();
2300-
$i = wp_nonce_tick();
2304+
$i = wp_nonce_tick( $action );
23012305

23022306
// Nonce generated 0-12 hours ago.
23032307
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
@@ -2347,8 +2351,8 @@ function wp_create_nonce( $action = -1 ) {
23472351
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
23482352
}
23492353

2350-
$token = wp_get_session_token();
2351-
$i = wp_nonce_tick();
2354+
$token = wp_get_session_token( $action );
2355+
$i = wp_nonce_tick( $action );
23522356

23532357
return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
23542358
}

tests/phpunit/tests/pluggable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function get_pluggable_function_signatures() {
201201
'deprecated' => null,
202202
'notify' => '',
203203
),
204-
'wp_nonce_tick' => array(),
204+
'wp_nonce_tick' => array( 'action' => -1 ),
205205
'wp_verify_nonce' => array(
206206
'nonce',
207207
'action' => -1,

0 commit comments

Comments
 (0)