stylesplugin / styles-font-menu

Display an up-to-date menu of Google Fonts with image previews. Include it in your own plugins and themes, or install as a plugin.
15 stars 8 forks source link

styles_font_menu not saving #12

Closed joepierce closed 10 years ago

joepierce commented 10 years ago

getting much closer to a solution:

The text fields are saving data now but the "styles_font_menu" font dropdown still doesn't. The issue is apparently in the "function button1text_setting()" function. What would be the best way to write this function?


function build_options_page() { ?>
<div id="theme-options-wrap">
<form method="post" action="options.php" enctype="multipart/form-data">
<?php settings_fields('theme_options'); ?>
<?php do_settings_sections(__FILE__); ?>
<p>
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</p>
</form>
</div>

<?php } add_action('admin_init', 'register_and_build_fields');

function register_and_build_fields() {

register_setting('theme_options', 'theme_options', 'validate_setting');
add_settings_section('homepage_settings', 'Homepage Settings', 'section_homepage', __FILE__);
function section_homepage() {}

add_settings_field('button1text', 'Text Font', 'button1text_setting', __FILE__, 'homepage_settings');
add_settings_field('button1link', 'text field 1', 'button1link_setting', __FILE__, 'homepage_settings');
add_settings_field('button2text', 'text field 2', 'button2text_setting', __FILE__, 'homepage_settings');
}

function validate_setting($theme_options) { return $theme_options; }

function button1text_setting() { 
$options = get_option('theme_options');
$attributes = array(
'name' => 'button1text_setting',
'id' => 'button1text_setting'    );
do_action( 'styles_font_menu', $attributes);
}

function button1link_setting() { $options = get_option('theme_options'); echo "<input name='theme_options[button1link_setting]' type='text' value='{$options['button1link_setting']}' />"; }

function button2text_setting() { $options = get_option('theme_options'); echo "<input name='theme_options[button2text_setting]' type='text' value='{$options['button2text_setting']}' />"; }

add_action('admin_menu', 'theme_options_page');

function theme_options_page() { add_options_page('Theme Settings', 'Theme Settings', 'administrator', __FILE__, 'build_options_page');}

(you can see that the text fields are saving but the font doesn't) This code puts out:

output

pdclark commented 10 years ago

Ah, found it! Closing as a duplicate of #11. Per my notes in that thread, looks like you are setting name, but it should be theme_options[button1text_setting], not button1text_setting. Still likely cleaner to use the options framework example in the other thread.

joepierce commented 10 years ago

so what is the final snip?

On 7/3/14 3:28 PM, Paul Clark wrote:

Ah, found it! Closing as a duplicate of #11 https://github.com/stylesplugin/styles-font-menu/issues/11. Per my notes in that thread, looks like you are setting name, but it should be |theme_options[button1text_setting]|, not |button1text_setting|. Still likely cleaner to use the options framework example in the other thread.

— Reply to this email directly or view it on GitHub https://github.com/stylesplugin/styles-font-menu/issues/12#issuecomment-47986896.

joepierce commented 10 years ago

I'm sorry, I'm still not clear on what I should use as a best-case-usage-scenario.

please and thank you.

On 7/3/14 3:28 PM, Joe Pierce wrote:

so what is the final snip?

On 7/3/14 3:28 PM, Paul Clark wrote:

Ah, found it! Closing as a duplicate of #11 https://github.com/stylesplugin/styles-font-menu/issues/11. Per my notes in that thread, looks like you are setting name, but it should be |theme_options[button1text_setting]|, not |button1text_setting|. Still likely cleaner to use the options framework example in the other thread.

— Reply to this email directly or view it on GitHub https://github.com/stylesplugin/styles-font-menu/issues/12#issuecomment-47986896.