Support

Account

Home Forums Feature Requests Button to Reset to Default Values Reply To: Button to Reset to Default Values

  • This function needs to be put into the JavaScript file that you’re enqueuing

    
    function my_options_reset_defaults() {
      if (!confirm('Are you sure you want to reset the default options?\nThis operation cannot be undone.')) {
        return;
      }
      jQuery.post(
        // the object name needs to be the same
        // as the object name used when
        // localizing the script
        my_options_object._ajax_url, {
          // the action needs to be the same
          // as the wp_ajax_ action you set up
          'action': 'my_options_reset',
          'nonce': my_options_object._nonce
        },
        function (data) {
          // does not matter what's returned
          // reloads the options page to show defaults
          location.reload();
        }
      );
    }