Jump to content

Cre8asiteforums Internet Marketing
and Conversion Web Design


Photo

Wordpress Plugins


  • Please log in to reply
2 replies to this topic

#1 fisicx

fisicx

    Sonic Boom Member

  • Hall Of Fame
  • 1886 posts

Posted 23 February 2012 - 06:48 AM

Mr Thicko here.

The plugin options page loads and I can edit but when I save the settings the default settings return.

Obviously something wonky. I've nicked much of the code form the 'plugin options stater kit' plugin (that's what it's there for).

This is how I set up the defaults:
function cbf_add_defaults() {
$tmp = get_option('cbf_options');
$arr = array("txt_1" => "Your Name");
add_option('cbf_options', $arr);
}

This is how I register the options:
function cbf_init(){
register_setting( 'cbf_plugin_options', 'cbf_options[txt_1]', 'cbf_validate_options' );
}

This is the options form:
<form method="post" action="options.php">
<?php settings_fields('cbf_plugin_options'); ?>
<?php $options = get_option('cbf_options'); ?>
<p>Enter the label: <input type="text" size="60" name="cbf_options[txt_1]" value="<?php echo $options['txt_1']; ?>" /></p>
<p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
</form>

All seems to be in place according to the codex and umpteen tutorials and articles. It's just not saving. I edit the label, hit submit and the default returns. When I actually use the plugin the label doesn't show:

<?php echo get_option('cbf_options(txt_1)'); ?>

Is empty no matter how I format the get_options

Help?

#2 mregan

mregan

    Gravity Master Member

  • Members
  • 128 posts

Posted 23 February 2012 - 09:12 PM

Sounds like you don't have write permissions for that file or in that directory.

#3 fisicx

fisicx

    Sonic Boom Member

  • Hall Of Fame
  • 1886 posts

Posted 24 February 2012 - 09:51 AM

Managed to resolve the problem by removing the arrays! (a part of PHP I just don't understand).

Sledge hammer to crack a nut I know but since there are only 4 options to define I was easier to create each one seperately.

I have another problem however and that concerns shortcodes.

It makes no difference where I put the shortcode in the post, the function output allways goes to the top.

According to the various forums it has to do with using echo in the function but I don't understand how to fix it.

add_shortcode('callback', 'cbf_form');

works fine.

But the even when [callback] is at the bototm of a post the form called by cbf_form always appears at the top of the post.

stupidphpwhyisitsoawkward......



RSS Feed

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users