update_option from a custom admin page

WPPizza – A Restaurant Plugin for WordPress Support General Support update_option from a custom admin page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #21621
    cubic
    Participant

      Hi,

      I’m trying to update order_email_to from a custom admin page. But no way.
      I created a new plugin to add an admin page with add_menu_page

      
      function test_plugin_setup_menu(){
      add_menu_page( 'Email', 'Email', 'contributor', 'test-plugin', 'test_init' );
      }
      add_action('admin_menu', 'test_plugin_setup_menu');
      function test_init(){
      save_my_email();
      }
      function save_my_email(){
      $options=get_option('wppizza');
      echo 'MY EMAIL  '.$options['order']['order_email_to'][0];
      $options['order']['order_email_to'][0]='[email protected]';
      $go=update_option('wppizza', $options);
      if($go==false){
      echo 'false';
      }else{
      echo 'yes';
      }
      }
      //If I do save_my_email() outside test_init(), it's ok.
      //save_my_email()
      

      But the result is always FALSE, the option isn’t saved. Impossible to solved this problem.
      Why … What’s wrong ?
      Thanks
      Nicolas

      #21624
      Olly
      Admin & Mod

        ignoring the fact that i don’t understand why you would actually need this if there is a perfectly good admin page that lets you set the email address

        $go will only return true if the option was actually updated (that is CHANGED)
        if you keep setting the same email address, it will only ever be true the first time you set it

        #21625
        Olly
        Admin & Mod

          generally speaking though, debugging your scripts is somewhat outside plugin support….
          for this sort of thing, i would suggest something like
          http://wordpress.stackexchange.com/

          (or of course https://developer.wordpress.org/reference/)

          #21626
          cubic
          Participant

            Ok I understand.
            Thank you

          Viewing 4 posts - 1 through 4 (of 4 total)
          • The topic ‘update_option from a custom admin page’ is closed to new replies.