1642 posts
  • Elite Author
  • Featured Author
  • 6 Years of Membership
  • Author Level 10
+8 more
fuelthemes
says

Hi everyone,

I am having trouble saving settings using ajax in my theme options page.

I am submitting the data using jQuery post with “action : theme_save_ajax” to Wordpress “ajaxurl” address.

then in the backend, I have added the following hook:

add_action(‘wp_ajax_theme_save_ajax, ‘theme_save’);

and the following function:

function theme_save() {

        $this->options["name"] = $_POST["name"];

        update_option('my_theme', $this->options);

        die();
    }

but I can’t even trigger the theme_save() function.

Using firebug, I can see that the jquery post is successful, returning “0”, not “-1”.

2 posts
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
  • Exclusive Author
+5 more
orqun
says

Hi Ant,

If the “theme_save” function is a sub-function of a class, it has to be called within the class when adding to “wp_ajax_” hook.

Ex: add_action( ‘wp_ajax_theme_save_ajax’, array(&$yourClass, ‘theme_save’) );

http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback

Regards, Orkun

1642 posts
  • Elite Author
  • Featured Author
  • 6 Years of Membership
  • Author Level 10
+8 more
fuelthemes
says

Thanks Orkun, got it working!

You can add me on google chat if you are using:

anteksiler aaattttt gmail.com

by
by
by
by
by
by