[wp-trac] [WordPress Trac] #20770: Introduce AJAX response message

WordPress Trac wp-trac at lists.automattic.com
Wed May 30 00:30:57 UTC 2012


#20770: Introduce AJAX response message
-------------------------------------------------+-------------------------
 Reporter:  alexvorn2                            |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Widgets                              |  Review
 Severity:  minor                                |     Version:
 Keywords:  2nd-opinion has-patch ui-feedback    |  Resolution:
  ux-feedback                                    |
-------------------------------------------------+-------------------------

Comment (by kurtpayne):

 Replying to [comment:3 helenyhou]:
 > I like this, but I think it's weird that it replaces the controls
 entirely - no way to go back and save the changes if you log in in another
 window. Maybe worth just inserting before the controls instead.

 Agreed.  [[attachment:20770.1.patch]] integrates your padding / CSS
 changes with this.  A new div is added for a "You are logged out."
 message.  The message is removed if a user logs back in.  If the user
 repeatedly clicks "Save" then the message flashes (a la
 `fadeOut(50).fadeIn(500)`).  Feel free to adjust the UX accordingly.

 Replying to [comment:4 alexvorn2]:
 > why if ( "0" === r ) but not ( "-1" === r ) ?

 The widget ajax (if successful) returns HTML code.  A successful save on
 the meta widget, for example, may return this:

 {{{
 <p><label for="widget-meta-2-title">Title:</label> <input class="widefat"
 id="widget-meta-2-title" name="widget-meta[2][title]" type="text"
 value="title goes here" /></p>
 }}}

 If the ajax fails, it returns 0 (which javascript treats as a string in
 this instance).

 Why does it return 0 and not -1?  If you're logged in, admin-ajax.php will
 call `do_action('wp_ajax_' . $_REQUEST['action']);` otherwise, it calls
 `do_action('wp_ajax_nopriv_' . $_REQUEST['action']);`.

 You might read the code and think it would call `wp_ajax_save_widget()`
 and fail on `check_ajax_referer()` and call `wp_die(-1)` and the
 javascript should check for -1.  However, in this instance, if you're not
 logged in, !WordPress will never call `wp_ajax_save_widget()`, it will
 simply fall all through way through admin-ajax.php and hit the last line:
 `die(0);`

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


More information about the wp-trac mailing list