[wp-trac] [WordPress Trac] #60575: Refactor: `data_wp_context` function does not follow WP standards.

WordPress Trac noreply at wordpress.org
Tue Feb 20 23:13:23 UTC 2024


#60575: Refactor: `data_wp_context` function does not follow WP standards.
--------------------------------------+---------------------
 Reporter:  cbravobernal              |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  6.5
Component:  Editor                    |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  needs-patch dev-feedback  |     Focuses:
--------------------------------------+---------------------

Comment (by westonruter):

 If we wanted to follow the existing pattern of WordPress
 [https://codex.wordpress.org/Template_Tags template tags] (which we
 probably shouldn't!), like `the_title_attribute()`, then it could be
 `the_data_wp_context_attribute()`. Consider also `body_class()` versus
 `get_body_class()`.

 Since most template tags have a `the_` version that prints and a `get_`
 version that... gets, perhaps there should be two:

 * `wp_interactivity_get_context_attr()`
 * `wp_interactivity_the_context_attr()` or better just
 `wp_interactivity_context_attr()` without `the_`

 Having a function that prints would avoid PHPCS complaints about printing
 unescaped output, although that would also be solved by adding it to
 [https://github.com/WordPress/WordPress-Coding-
 Standards/blob/f985e0aaf45e964d14a73e698b70a9c759c491f0/WordPress/Helpers/EscapingFunctionsTrait.php#L110-L171
 EscapingFunctionsTrait::$autoEscapedFunctions].

 Compare:

 {{{#!php
 <div <?php echo wp_interactivity_get_context_attr( $context, $namespace );
 ?>>
 }}}

 {{{#!php
 <div <?php wp_interactivity_context_attr( $context, $namespace ); ?>>
 }}}

 The second is briefer.

 Nevertheless, perhaps prior art here is `get_block_wrapper_attributes()`
 which notably does not have a prefix and it doesn't have a
 `the_block_wrapper_attributes()` variant. I guess it depends on how often
 the function would be needing to return a value versus print the value.

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


More information about the wp-trac mailing list