Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

enter image description here

Settings > General:

enter image description here

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?

share|improve this question
    
That doesn't really make sense. I suspect that Options Framework is saving and retrieving a different key/value than the one WordPress is using, and you have only half interrupted it. Check the wp_options table and see if you are getting two entries for the blog name and description, under different keys. –  s_ha_dum Dec 28 '12 at 14:54
    
You will need to look at the database using the MySQL CLI or something like PhpMyAdmin ( I think Plesk and cPanel both incorporate that but I am not sure. It has been awhile since I used either. ) –  s_ha_dum Dec 28 '12 at 15:00
    
What reson do you have to do that at all? why can't you just use get_option('blogname') wherever you need it? The whole concept of duplicating that data is wrong IMHO –  Mark Kaplun Dec 28 '12 at 16:09
    
Using get_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. –  user1752759 Dec 28 '12 at 16:19
1  
It is good practice to attribute where did your code come from. Having answered the previous Question and knowing the context: why do you need this in the first place? Ain't the Theme options the place to modify the Site name and Tagline? Or are you granting administrative access (settings page) to the client as well? That being said, what you want is possible using the hooks update_option_blogname and update_option_blogdescription, but you'll have to learn how to manipulate your {$option_name} as @Milo points out... –  brasofilo Dec 28 '12 at 16:27
show 1 more comment

1 Answer

I presume your options are being saved in an array under a single key and not actually within the native options WP uses. You can add an action to update_option_{$option_name} to update the options famework entry when an option is updated outside your own options panel. You'll have to figure out what key your own options are being saved under.

share|improve this answer
    
This sounds promising...but as I'm relatively new to all of this, I'm unsure of how to implement your suggestion @Milo. Could you possibly check the framework or point me in the right direction for the relevant code? –  user1752759 Dec 28 '12 at 15:55
1  
In your options framework setup, look for the name of the key that your options are saved under, there's probably a default value if you haven't set one explicitly. Look in WP docs under add_action and the actions reference page for info on hooking a function to the update of the native WP options. Sorry I'm on a slow mobile connection right now, I can give you more info when I'm in office. –  Milo Dec 28 '12 at 16:22
    
Thanks for the quick responses @Milo, there are a few references to the add_action and one for update_option - update_option( 'optionsframework', $optionsframework_settings ) in the framework so I'll look into this and hopefully implement your suggestion correctly to make this work. Thank you for all the help. –  user1752759 Dec 29 '12 at 2:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.