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 using the Options Framework Theme to put together an options 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.

Concept:

enter image description here

Options.php:

$options[] = array(
    'name' => __('Site Title', 'options_framework_theme'),
    'desc' => __('The name of your site.', 'options_framework_theme'),
    'id' => 'title',
    'std' => 'PHP CODE FOR SITE TITLE HERE ...',
    'class' => 'medium',
    'type' => 'text');

Is there a way to do this (add their own Site Title and Taglines) within a text-field for example, click the Save Options button to output it to the front-end of the site and display an updated version in the WP API Settings > General Settings sub-menu page?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The framework offers a filter for validating input values inside the optionsframework_validate function.
Just for reference, here's the relevant part from the file wp-content/themes/your-theme/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 */

So, considering that we have the following options in the file wp-content/themes/your-theme/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');

And in wp-content/themes/your-theme/functions.php, we filter the text input type (of_sanitize_ + text) and if it matches our defined ids (blogname and blogdescription, just like in General Settings), it will update the site options that have the same id.

Please note, that this doesn't work the other way around: changes made in Settings -> General won't be reflected inside the theme options page...

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;
}
share|improve this answer
1  
@user1752759, I've updated the Answer with more details about each block of code. Hope it helps! –  brasofilo Dec 26 '12 at 5:46
    
Beautiful @brasofilo, just what I was after! Is it also possible to allow this to work the other way too (Settings > General to the Theme Options page)? –  user1752759 Dec 26 '12 at 23:24
    
Possible, it is. I've done it before but cannot find where the code is... Anyway, that's a new, different Question. And a research here at WPSE may bring an answer ;) –  brasofilo Dec 27 '12 at 10:35
    
Thanks for everything @brasofilo, I'll research and open up a new question for this if needed. All the best. –  user1752759 Dec 27 '12 at 10:37
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.