LNHU-225: Custom post type and editor UI dropdown for Hero Images - #232
djanelle-mit wants to merge 7 commits into
Conversation
3903fe0 to
780bf96
Compare
matt-bernhardt
left a comment
There was a problem hiding this comment.
I'm flagging two changes (one of which I'm probably happy to let go if it's being too strict). The rest are non-blocking comments about some details that I see here and there.
Overall, I like where this gets us - being able to manage these images via the CMS instead of via PRs is a significant improvement on both of our workloads.
| * @see https://make.wordpress.org/core/2025/03/13/more-efficient-block-type-registration-in-6-8/ | ||
| * @see https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/ | ||
| */ | ||
| function register_blocks() { |
There was a problem hiding this comment.
Non-blocking comment:
I'm a little uneasy about conflating hooks to classes and hooks to functions like this, but not so much that I'm going to ask for a change now. It may never be an issue, in which case no harm done.
It wouldn't be difficult to swap this to a class method if it does turn out to be problematic.
There was a problem hiding this comment.
This is a place where Copilot did the scaffolding, and I definitely need to understand this distinction better.
Do you have an example or pseudo code for the distinction between the two options?
There was a problem hiding this comment.
There's a proof of concept for the difference at #236. This isn't something I expect to merge, but it shows what the alternative implementation would be. This function itself is pretty simple, and doesn't pollute the root PHP script terribly - so I'm happy to leave it for now. If we end up adding more complexity to this plugin, however, this might become more warranted.
| 'hero_images', | ||
| 'meta', | ||
| array( | ||
| 'get_callback' => function( $data, $field, $request, $type ) { |
There was a problem hiding this comment.
Maybe a requested change?
PHPCS is flagging the need for a space between function and the parentheses on this line. If you'd rather not deal with this now, I'm happy to leave it be - but I'm hoping to tackle a maintenance ticket for our plugins soon-ish that would pick it up at that point.
There was a problem hiding this comment.
Would the maintenance ticket for the plugins apply this across the board (vs making a tactical fix only for this instance)? I think I'll leave this as-is for now.
There was a problem hiding this comment.
The scope of the maintenance ticket is a bit nebulous - I've just been noticing that there's a small amount of technical debt like this in otherwise-clean plugins, and I've found it much easier to "hold the line" if we're always starting from a clean slate, rather than "there's a small number of things we're ignoring". It's a lot more noticeable when previously empty output now has something, than when a list of two items becomes a list of three.
| } | ||
|
|
||
| // Require the necessary classes. | ||
| require_once( plugin_dir_path( __FILE__ ) . 'src/class-heroimage.php' ); |
There was a problem hiding this comment.
Non-blocking comment:
require_once does not need parentheses (it is a statement, not a function). What you've got here is consistent with all other plugins, so I like that we're being consistent here. I'm mentioning it now so that there's background when I set up a PR to change all of these plugins at the same time as part of a maintenance ticket.
| "label": "Citation", | ||
| "name": "citation", | ||
| "type": "text", | ||
| "instructions": "The text used to credit the source of the hero image, e.g. \"Muriel Cooper personal archives\".", |
There was a problem hiding this comment.
Requested change:
Could we provide an example that uses different content for this citation field than what's used in the citation link text field? Setting this instruction to something like from the Muriel Cooper personal archives would make the distinction between the two fields a bit clearer, IMO.
| <?php if ( $hero_credit ) : ?> | ||
| <span class="hero-image-credit"> | ||
| <?php | ||
| // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- built from esc_html()/esc_url() pieces above. |
There was a problem hiding this comment.
Non-blocking comments:
- It looks like you've been using PHPCS locally, if you're selectively turning off checks like this? How has that process been so far?
- If I follow the logic of the variable names used on lines 47-57, I wonder if the final output should be
$escaped_hero_creditto reflect that the contents have already been processed via an escaping function? - I think I like the approach of relying on context-specific escaping functions while compiling the value - if we wanted to be particularly robust while still enforcing escaping at this level, we could use
wp_ksesto strip out all markup except for the link with the expected attributes here, and satisfy the requirements of this sniff.
There was a problem hiding this comment.
- I've been using CoPilot to help move things around or scaffold things, and PHPCS and the
npm run buildare always run as part of those. It's been helping my commits be more consistent, so it's easier to see when something is actually changed versus me forgetting to format something correctly. - Yes, I think being as crisp as possible with variables names makes a ton of sense. Updated.
- I'm not sure I follow what this means
There was a problem hiding this comment.
There's a proof of concept for using wp_kses at #237 - as with the other alternate, this isn't something I expect to be merged - just a demonstration for how the pattern works. We wouldn't necessarily drop the compilation step from lines 47-57, all those escaping and protection steps are likely still necessary (certainly the esc_url and esc_attr methods are doing work that wp_kses doesn't) - but it would allow us not to turn off the protection of the sniff at the rendering line, while still enforcing an allowlist of only the markup we expect to be present.
matt-bernhardt
left a comment
There was a problem hiding this comment.
I see the updated instructions values, which is the one thing I felt most strongly about. I've set up demonstrations for the two code patterns you asked about, but left them as draft because I don't expect them to merge - they're for discussion purposes only.
![]()
Developer
This work adds a plugin that introduces a new custom post type "Hero Images". This plugin also contains the homepage hero image block, which now allows the editor to select a hero image from the CPT via a dropdown in the block editor UI.
This is the first instance of our architectural decision to colocate the definitions of new data objects with all the instances of where they're rendered.
Stylesheets
string incremented.
Secrets
Documentation
Accessibility
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Stakeholder approval
Dependencies
YES | NO dependencies are updated
Code Reviewer
(not just this pull request message)