Skip to content

Commit ed233eb

Browse files
authored
Forms: Add jwt filter (#45731)
* Forms: Add forms jwt filter Introduces filter to allow customization of the secret used for signing contact form JWT tokens. Falls back to the default secret if the filter does not return a value. * changelog * Update the copy and check that we are returning a string from the filter. * fix to be plural
1 parent 40664d4 commit ed233eb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Forms: add a new jwt filter

projects/packages/forms/src/contact-form/class-contact-form.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,19 @@ public static function compute_id( $attributes, $post = null, $page_number = 1 )
389389
* @return string The secret from the Tokens class, or a default secret if not available.
390390
*/
391391
private static function get_secret() {
392+
393+
/**
394+
* Filter the secret used for signing contact form JWT tokens.
395+
*
396+
* @param string $secret Passes a empty string by default so that we can fall back to other methods if the filter is not used.
397+
*
398+
* @return string The secret used for signing contact form JWT tokens.
399+
*/
400+
$secret = apply_filters( 'jetpack_forms_secret_jwt', '' );
401+
if ( is_string( $secret ) && ! empty( $secret ) ) {
402+
return $secret;
403+
}
404+
392405
$token = ( new Tokens() )->get_access_token();
393406
$default_secret = hash_hmac( 'md5', get_option( 'admin_email' ), JETPACK__VERSION );
394407

0 commit comments

Comments
 (0)