[wp-trac] [WordPress Trac] #15344: global variables get cleared

WordPress Trac wp-trac at lists.automattic.com
Mon Nov 8 17:30:31 UTC 2010


#15344: global variables get cleared
--------------------------+-------------------------------------------------
 Reporter:  OS1           |       Owner:                   
     Type:  defect (bug)  |      Status:  new              
 Priority:  normal        |   Milestone:  Awaiting Review  
Component:  General       |     Version:  3.0.1            
 Severity:  normal        |    Keywords:  reporter-feedback
--------------------------+-------------------------------------------------

Comment(by OS1):

 $shopMessages = null;
 function displayShopMessages($page_content)
 {
   global $shopMessages;

   $messages = "";
   if ((null != $shopMessages) && (gettype($shopMessages) === "array"))
   {
     for ($mI = 0; $mI < count($shopMessages); $mI++)
     {
       $messages .= $shopMessages[$mI]."<br>";
     }
     $messages .= "<br><br>";
   }
   unset($shopMessages);
   $shopMessages = null;

   $pageC = $messages.$page_content;
   return $pageC;
 }

 add_filter('the_content', 'displayShopMessages');

 function checkHeaderParameters()
 {
   global $current_user, $error, $shopMessages;
   if ($_GET["logout"])
   {
     wp_logout();
     wp_set_current_user(0);
   }
   else if ($_POST["wp-submit"] === "Log In")
   {
     $newUser = wp_signon(array('user_login' => $_POST['log'],
 'user_password' => $_POST['pwd'], 'remember' => true));
     if (is_callable(array($newUser, "get_error_code")) &&
 $newUser->get_error_codes())
     {
       if (null == $shopMessages)
       {
         $shopMessages = array();
       }
       $shopMessages[] = "Sorry, log in failed, the following issues were
 reported:<br>";
       foreach($newUser->errors as $error)
       {
         foreach($error as $errMsg)
         {
           $shopMessages[] = $error;
         }
       }
       $newUser = null;
     }
     wp_redirect("/login/");
     exit();
 //    wp_login($_POST['log'], $_POST['pwd']);
 /*    $newUser = wp_signon(array('user_login' => $_POST['log'],
 'user_password' => $_POST['pwd'], 'remember' => true));
     if (!$error)
     {
       $current_user = $newUser;
       wp_set_auth_cookie($newUser->id);
     }
     else
     {
       if (null == $shopMessages)
       {
         $shopMessages = array();
       }
       $shopMessages[] = $error;
     } */
   }
   else if ($_POST["wp-submit"] === "Register")
   {
     require_once("logInOut.php");
     $reqAuthU = new AuthUser();
     $dataOk = $reqAuthU->checkNewUser($_POST['user_login'],
 $_POST['user_email'], $_POST['pwd']);
     if ($dataOk)
     {
       $userId = wp_create_user($_POST['user_login'], $_POST['pwd'],
 $_POST['user_email']);
       if (!$userId)
       {
         if (null == $shopMessages)
         {
           $shopMessages = array();
         }
         $shopMessages[] = "Registration failed";
       }
       else
       {
         $newUser = wp_signon(array('user_login' => $_POST['user_login'],
 'user_password' => $_POST['pwd'], 'remember' => true));
         if (is_callable(array($newUser, "get_error_code")) &&
 $newUser->get_error_codes())
         {
           if (null == $shopMessages)
           {
             $shopMessages = array();
           }
           $shopMessages[] = "Sorry, user registration failed, the
 following issues were reported:";
           foreach($newUser->errors as $error)
           {
             foreach($error as $errMsg)
             {
               $shopMessages[] = $errMsg;
             }
           }
           $newUser = null;
         }
         else
         {
           if (null == $shopMessages)
           {
             $shopMessages = array();
           }
           $shopMessages[] = "Thankyou for registering with us.";
           wp_login($_POST['log'], $_POST['pwd']);
           $current_user = $newUser;
           wp_set_auth_cookie($newUser->id);
           wp_redirect("/my-account/?task=dets");
           exit();
         }
       }
     }
   }
 }
 add_filter('init', 'checkHeaderParameters');

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15344#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list