wp_nonce_tick

函式
wp_nonce_tick ( $action = -1 )
引數
  • (string|int) $action Optional. The nonce action. Default -1.
    Required:
    Default: -1
返回值
  • (float) Float value rounded up to the next highest integer.
定義位置
相關方法
wp_nonce_fieldwp_nonce_urlwp_nonce_ayssignup_nonce_checkwp_cache_incr
引入
2.5.0
棄用
-

wp_nonce_tick: 這個函式用來生成一個唯一的值,可以和wp_create_nonce函式結合使用,以建立一個唯一的nonce。它通常用於確保nonce在一定時間內有效。

返回建立nonce的隨時間變化的變數。

一個nonce有兩個tick的壽命。處於第二個tick的nonce可以被更新,例如通過自動儲存。

function wp_nonce_tick( $action = -1 ) {
		/**
		 * Filters the lifespan of nonces in seconds.
		 *
		 * @since 2.5.0
		 * @since 6.1.0 Added `$action` argument to allow for more targeted filters.
		 *
		 * @param int        $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day.
		 * @param string|int $action   The nonce action, or -1 if none was provided.
		 */
		$nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS, $action );

		return ceil( time() / ( $nonce_life / 2 ) );
	}
endif;

if ( ! function_exists( 'wp_verify_nonce' ) ) :
	/**
	 * Verifies that a correct security nonce was used with time limit.
	 *
	 * A nonce is valid for 24 hours (by default).
	 *
	 * @since 2.0.3
	 *
	 * @param string     $nonce  Nonce value that was used for verification, usually via a form field.
	 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
	 * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
	 *                   2 if the nonce is valid and generated between 12-24 hours ago.
	 *                   False if the nonce is invalid.
	 */

常見問題

FAQs
檢視更多 >