- Timestamp:
- 10/28/2026 09:22:17 PM (7 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
joinotify/trunk/admin/src/Admin/Settings/Repository.php
r3669756 r3771693 5 5 use MeuMouse\Joinotify\Admin\Default_Options; 6 6 use MeuMouse\Joinotify\Core\Helpers; 7 use MeuMouse\Joinotify\Core\Token_Vault; 7 8 8 9 defined('ABSPATH') || exit; … … 26 27 * Persist a settings payload and return the sanitized result. 27 28 * 29 * The returned array is what was stored, so the API key in it is sealed — 30 * pass it through Registry::get_settings_for_client() before it reaches the 31 * browser, as every caller does. 32 * 33 * @version 2.6.0 28 34 * @param array<string,mixed> $incoming 29 35 * @return array<string,mixed> … … 63 69 64 70 $sanitized = self::preserve_write_only( $sanitized, $current, Registry::get_write_only_keys() ); 71 $sanitized = self::seal_api_key( $sanitized, $current ); 72 73 // The `_is_set`/`_locked` flags are derived for the browser on every read 74 // (Registry::get_settings_for_client) and come back with the whole form; 75 // they describe the key, they are not settings of their own. 76 foreach ( Registry::get_write_only_keys() as $write_only_key ) { 77 unset( $sanitized[ $write_only_key . '_is_set' ], $sanitized[ $write_only_key . '_locked' ] ); 78 } 65 79 66 80 update_option( 'joinotify_settings', $sanitized ); … … 118 132 119 133 /** 134 * Keep the Joinotify API key sealed in the stored settings. 135 * 136 * A save usually hands back the sealed value it read (preserved above, or 137 * merged in by the wizard and the import), which is kept as it is. A key in 138 * the clear — the API key control puts the one it just connected with into 139 * the form — is sealed, unless it is the key already stored, in which case 140 * the stored value is kept instead of being sealed again with a new nonce. 141 * 142 * @since 2.6.0 143 * @param array<string,mixed> $sanitized Values about to be stored. 144 * @param array<string,mixed> $current Values currently stored. 145 * @return array<string,mixed> 146 */ 147 public static function seal_api_key( $sanitized, $current ) { 148 $key = 'whatsapp_cloud_api_token'; 149 150 if ( ! isset( $sanitized[ $key ] ) || ! is_scalar( $sanitized[ $key ] ) ) { 151 return $sanitized; 152 } 153 154 $incoming = trim( (string) $sanitized[ $key ] ); 155 $stored = isset( $current[ $key ] ) && is_scalar( $current[ $key ] ) ? trim( (string) $current[ $key ] ) : ''; 156 157 if ( '' === $incoming || Token_Vault::is_encrypted( $incoming ) ) { 158 return $sanitized; 159 } 160 161 if ( Token_Vault::is_encrypted( $stored ) && Token_Vault::decrypt( $stored ) === $incoming ) { 162 $sanitized[ $key ] = $stored; 163 164 return $sanitized; 165 } 166 167 $sanitized[ $key ] = Token_Vault::encrypt( $incoming ); 168 169 return $sanitized; 170 } 171 172 173 /** 120 174 * Reset Joinotify settings to a pristine state. 121 175 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)