I'm putting together a Theme Options page, where the user(s) I'm building this for would like to be able to edit a few settings directly from this page, including of which - the Site Title and Tagline.
With some fantastic help from brasofilo, I have the following...
/inc/options-framework.php:
/**
* Validate Options.
*
* This runs after the submit/reset button has been clicked and
* validates the inputs.
*/
function optionsframework_validate( $input ) {
/* code */
$clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option );
/* code */
options.php:
$options[] = array(
'name' => __('Input Text Mini', 'options_framework_theme'),
'desc' => __('A mini text input field.', 'options_framework_theme'),
'id' => 'blogname',
'std' => 'Default',
'class' => 'mini',
'type' => 'text');
$options[] = array(
'name' => __('Input Text', 'options_framework_theme'),
'desc' => __('A text input field.', 'options_framework_theme'),
'id' => 'blogdescription',
'std' => 'Default Value',
'type' => 'text');
functions.php:
add_filter( 'of_sanitize_text', 'wpse_77233_framework_to_settings', 10, 2 );
function wpse_77233_framework_to_settings( $input, $option )
{
if( 'blogname' == $option['id'] )
update_option( 'blogname', sanitize_text_field( $input ) );
if( 'blogdescription' == $option['id'] )
update_option( 'blogdescription', sanitize_text_field( $input ) );
return $input;
}
If the user(s) add in their own blogname/Site Title and blogdescription/Tagline within the Theme Options page and then click the Save button, it will output the information to the front-end of the site accordingly, and update the information within each of the text-fields within the WP API Settings > General menu.
Theme Options:
Settings > General:
However, if the user(s) make any changes the other way around (within the WP API Settings > General menu), the information is output to the front-end of the site, but wont update the fields within the options-framework/Theme Options page.
As I'm fairly new to PHP and how this all works, I was wondering how would I be able to make this work the other way too?
wp_options
table and see if you are getting two entries for the blog name and description, under different keys.get_option('blogname')
wherever you need it? The whole concept of duplicating that data is wrong IMHOget_option('blogname')
will just retrieve the blogname from the Settings > General page. The user(s) I'm building this for would like to be able to edit a few settings directly from this page, including of which, the Site Title and Tagline.update_option_blogname
andupdate_option_blogdescription
, but you'll have to learn how to manipulate your{$option_name}
as @Milo points out...