WordPress Settings API unable to save settings

The <input> generated by your client_id_field() function is using the wrong name which is pardot_client_id, and by “wrong”, I mean there’s no database option registered with that name and the one you’ve registered is named pardot_settings.

  • The database option is the second parameter for register_setting().

  • And it should be used in the name attribute of form fields like <input> and <select>, e.g. <input name="DATABASE OPTION NAME">.

So looking at your class, you should have used <input type="text" size="30" id="pardot_client_id" name="{$html_name}" value="{$client_id}" /> there.

And then get the saved option like so:

// Get all settings in the option array.
$options = (array) get_option( self::$option_group );

// Get the pardot_client_id setting.
$client_id = $options['pardot_client_id'] ?? '';

tech