Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this fucntion which is called via Ajax to delete an option based on the name passed in.

function uncheck_package(){
    if(isset($_POST['element_value'])){
        $element = $_POST['element_value'];
    }

    echo json_encode($element);

    if(isset($element)){
        $option = get_option('aisis_options');
        if(isset($option[$element])){
            unset($option[$element]);
            update_option('aisis_options', $option);
            print_r($option);
        }
    }
}

add_action( 'wp_ajax_nopriv_uncheck_package', 'uncheck_package' );  
add_action( 'wp_ajax_uncheck_package', 'uncheck_package' );  

the jquery calling this:

(function($){   
    $(document).ready(function(){
        $('a').click(function(e){
          var el = $(this).prev('input[type="checkbox"]');
          if(el.is(':checked')){
               el.prop('checked',false);   
          }
          $.ajax({
              url  : 'http://localhost/wordpress/wp-admin/admin-ajax.php',
              type : 'POST',
              data : { 
                  action : 'uncheck_package',
                  element_value : el.val()
              },      
              success: function(result){
                console.log(result);
              },
              error: function(jqXHR, textStatus, errorThrown ){
                console.log(jqXHR, textStatus, errorThrown);
              } 
          })
          e.preventDefault();
        });
    }); 
 })(jQuery);

Now What I did so you can see the out put, is created a gist which has the out put of this function being called three consecutive times to delete three different options.

What you will notice is that, the name above the option array that's printed out is no where in that option array, BUT in every other array that option name exists.

So if package_Aisis-Related-Posts-Package-master is deleted in the first call, which it is - its no longer deleted when the function is called again, or a the third time.

The question is, why.

share|improve this question
    
what resultat you getting from the update_option('aisis_options', $option); call, is it returning false? before the print_r, do another $option = get_option('aisis_options'); to relly see whats saved, insted of listing what you want to save –  Puggan Se Aug 13 '13 at 21:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.