I’m trying to add a Shortlink Domain setting to the Optional section of WordPress’s Permalinks Settings page. For some reason, the value is not saving to the database. I’m sure I’m missing something simple, but I’m having a hard time figuring it out.
function urb_admin_init_shortlink_domain()
{
$option_group = 'optional'; // not sure what to put here
$option_name = 'shortlink_domain';
$sanitiaze_callback = ''; // for validation
register_setting( $option_group, $option_name, $sanitize_callback );
$id = 'shortlink_domain';
$title = 'Shortlink Domain';
$callback = 'urb_shortlink_domain';
$page = 'permalink';
$section = 'optional';
$args = '';
add_settings_field( $id, $title, $callback, $page, $section, $args );
}
function urb_shortlink_domain()
{
$option = 'shortlink_domain';
echo '<input type="text" name="' . $option . '" id="' . $option . '" value="' . get_option( $option ) . '" class="regular-text ltr" />';
}
function urb_get_shortlink( $shortlink, $id = 0, $context = null, $allow_slugs = null )
{
global $post;
return get_option('shortlink_domain') . $post->ID;
}
I’m not sure what to put for $option_group
in urb_admin_init_shortlink_domain()
. I tried permalink
, optional
, default
, urb_shortlink_domain
.
I tried reordering all of the functions and made sure to visit the Permalinks page each time.