1336 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has been part of the Envato Community for over 5 years
  • Has sold $250,000+ on Envato Market
+6 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
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+4 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

1336 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has been part of the Envato Community for over 5 years
  • Has sold $250,000+ on Envato Market
+6 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