[wp-trac] [WordPress Trac] #38098: Use common naming for context switching functions / classes

WordPress Trac noreply at wordpress.org
Mon Sep 19 21:28:08 UTC 2016


#38098: Use common naming for context switching functions / classes
--------------------------+------------------------------
 Reporter:  swissspidy    |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by jdgrimes):

 It sounds like maybe we need each stack to be a stack of stacks, to keep
 track of the state of the state. :-)

 As far as context vs state, I think that context might make more sense
 here. When I hear state, I think of a snapshot of the entire state of the
 application being saved. More like switching to the previous site state
 will roll back the database to that point or something. Context indicates
 to me what is the current "stuff": site, user, etc.

 I'd definitely favor introducing an interface. As far as the
 method/function naming, I think that the term "switch" makes sense, but
 "restore" could be replaced with something better. "Restore" was fine when
 `switch_to_blog()` was always used just once and paired with
 `restore_current_blog()`, but now we are talking about switching through
 several states, and maybe switching back, and maybe not. So
 `restore_current_blog()` is no longer only used to switch back to the
 "current" blog, and "restore" without "current" doesn't make as much sense
 to me. `switch_back`, `unswitch`, `previous`, or `pop` would be probably
 be better/more familiar, though obviously not all of those pair with
 `switch` very well. I'd say `restore` would really make more sense if it
 was taking us back to the original state. I realize that that would break
 with current naming conventions, though.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38098#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list