[wp-trac] [WordPress Trac] #17370: Screen options and meta box settings can lose per-blog meta box positions

WordPress Trac noreply at wordpress.org
Wed Jun 8 09:19:12 UTC 2022


#17370: Screen options and meta box settings can lose per-blog meta box positions
--------------------------+---------------------------------
 Reporter:  jmdodd        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  6.1
Component:  Users         |     Version:  3.1
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  ui, administration
--------------------------+---------------------------------
Changes (by TobiasBg):

 * milestone:   => 6.1


Comment:

 I've been running into this as well, with different plugins being active
 on different sites on a network, and these user options overriding each
 other for the different sites. I therefore fully agree, that these user
 options should be per-user and per-site, instead of per-user only.

 The change should not be difficult, and it should not bring backwards
 compat issues.
 In fact, this change had been made in the past at one point already. I
 went don't the rabbit hole on this a bit, focussing on the
 `closedpostboxes_$page` setting for now:
 - Essentially, there's a "setter" `wp_ajax_closed_postboxes()` and a
 "getter" `postbox_classes()` for this option, no other code seems to be
 interacting with it.
 - Both were introduced in [6584], before WP 3.0 multisite merge (thus the
 problem didn't exist back then).
 - In [9871], this was inadvertently changed in the "getter"
 `postbox_classes()`, so that suddenly with the multisite merge in WP 3.0,
 it would be compatible to per-user per-site settings, in addition to the
 existing per-user only setting.
 - In #12439, non-saving of the settings was observed, with [13551]
 actually turning this setting into a per-user per-site setting (without
 fully noticing it, it seems).
 - This again was noticed in #13032, which resulted in [14112] making the
 setting global per-user again.
 - ("Recently", but just a technicality without functional change, the
 `update_user_option( ..., true )` was changed to `update_user_meta()` to
 save function calls, in [50981].)

 So, in summary, the "getter" `postbox_classes()` is ready to use both the
 per-user per-site setting as well as the per-user only setting (as a
 fallback), thanks to using `get_user_option()`.
 This means that changing the "setter" `wp_ajax_closed_postboxes()` to use
 a per-user per-site setting is possible, without breaking backwards
 compatibility (the existing per-user setting will be used on all sites
 where no new per-user per-site setting has been saved). There will be a
 behavioral change though, that in worst case would mean that user has to
 change/adjust metabox visibility/state on multiple sites of a network,
 instead of just once.
 The advantage however would be that different plugins on different sites
 would not run into issues with their metaboxes state changes influencing
 each other, as outlined in the ticket description.

 The necessary code change would be basically revert [50981] (partially)
 and then [14112] (for the `wp_ajax_closed_postboxes()` function), i.e.
 changing
 {{{#!php
 update_user_meta( $user->ID, "closedpostboxes_$page", $closed );
 }}}
 to
 {{{#!php
 update_user_option( $user->ID, "closedpostboxes_{$page}", $closed, false
 );
 }}}

 (and everything likewise for the `metaboxhidden_$page`, `meta-box-
 order_$page`, and `screen_layout_$page` user options.)

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


More information about the wp-trac mailing list