php - WordPress doesn't save my custom setting in permalink section -
i have created many custom settings in wordpress using settings api, reason having trouble 1 in particular.
i want include custom url shortener using wordpress's shortlink feature, added custom setting store url shortener's domain name. allows customizable.
function urb_admin_init_shortlink_domain() { $option_group = 'permalink'; $option_name = 'shortlink_domain'; $sanitize_callback = null; register_setting( $option_group, $option_name, $sanitize_callback ); $id = 'shortlink_domain'; $title = 'shortlink domain'; $callback = 'urb_shortlink_domain'; $page = 'permalink'; $section = 'optional'; $args = null; 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" />'; } add_action( 'admin_init', 'urb_admin_init_shortlink_domain' );
for reason, doesn't save value. get_option('shortlink_domain')
function returns false
.
wordpress permalink settings provide settings sections , fields doesn't save values custom fields same others page media, reading etc.
i think need way save custom fields values on permalink page.
below sample code of save setting on permalink page.
add_action( 'admin_init', 'save_your_permalink_settings' ); function save_your_permalink_settings(){ if( isset($_post['permalink_structure']) && isset( $_post['shortlink_domain'] ) ){ $short_domain = wp_unslash( $_post['shortlink_domain'] ); update_option( 'shortlink_domain', $short_domain ); } }
Comments
Post a Comment