1472 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 6 years
  • Has sold $250,000+ on Envato Market
+5 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
  • Sells items exclusively on Envato Market
  • 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

1472 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 6 years
  • Has sold $250,000+ on Envato Market
+5 more
fuelthemes says

Thanks Orkun, got it working!

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

anteksiler aaattttt gmail.com

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by