Jump to content

Cre8asiteforums

Web Site Design, Usability, SEO & Marketing Discussion and Support

Sign in to follow this  
fisicx

Wordpress Plugins

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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......

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×