Make WordPress Core

Opened 2 months ago

Closed 7 weeks ago

#65497 closed enhancement (wontfix)

Replace unnecessary PHP comment with HTML comment in wp-admin/customize.php

Reported by: harishtewari Owned by:
Priority: normal Milestone:
Component: Customize Version: 4.9
Severity: normal Keywords: has-patch reporter-feedback close
Cc: Focuses:

Description (last modified by sabernhardt)

In src/wp-admin/customize.php (around line 227 and 266), there is a PHP opening tag used solely for an inline comment:

<ul class="customize-pane-parent"><?php // Panels and sections are managed here via JavaScript ?></ul>

Since no PHP code is being executed, the PHP tag is unnecessary. This can be replaced with an HTML comment to improve code readability and maintainability.
WordPress coding standards generally prefer avoiding unnecessary PHP tags when no PHP code is being executed

Change History (7)

This ticket was mentioned in PR #12241 on WordPress/wordpress-develop by @harishtewari.


2 months ago
#1

https://core.trac.wordpress.org/ticket/65497

In src/wp-admin/customize.php (around line 227 and 266), there is a PHP opening tag used solely for an inline comment:

<ul class="customize-pane-parent"><?php Panels and sections are managed here via JavaScript ?></ul>

Since no PHP code is being executed, the PHP tag is unnecessary. This can be replaced with an HTML comment to improve code readability and maintainability.

WordPress coding standards generally prefer avoiding unnecessary PHP tags when no PHP code is being executed

Trac ticket:

## Use of AI Tools

#2 @sabernhardt
2 months ago

  • Component GeneralCustomize
  • Description modified (diff)
  • Summary Unnecessary PHP comment with HTML comment in wp-admin/customize.phpReplace unnecessary PHP comment with HTML comment in wp-admin/customize.php
  • Type defect (bug)enhancement
  • Version 7.04.9

These comments were committed in r30102 and r41626.

#3 follow-up: @dmsnell
2 months ago

@harishtewari thanks for the proposal. it’s worth pointing out that this change modifies the rendered page and leaves what was previously a private comment in the public view.

did you find that the PHP tag was problematic in some way, or dig up that the comments were supposed to be part of the rendered page?

#4 @dmsnell
2 months ago

  • Keywords reporter-feedback added

#5 in reply to: ↑ 3 @khokansardar
2 months ago

Replying to dmsnell:

@harishtewari thanks for the proposal. it’s worth pointing out that this change modifies the rendered page and leaves what was previously a private comment in the public view.

did you find that the PHP tag was problematic in some way, or dig up that the comments were supposed to be part of the rendered page?

+1 to this concern. To add some context that may help close the loop here:

The <?php // ... ?> tags aren't dead code — they're doing exactly what they should. A PHP comment is stripped on the server and never sent to the browser, whereas an HTML comment is emitted into the page output. So this change doesn't remove an "unnecessary" tag; it converts two private, developer-facing notes into public markup on every Customizer load. That's a behavior change, not a cleanup.

There's also a functional angle. Both <ul> elements (customize-pane-parent and customize-outer-pane-parent) are populated by JS via api.Section / api.Panel, and the second comment was committed in r41626 specifically with the note *"to avoid any
side-effect in api.Section."* An HTML comment is a real DOM node (childNodes/firstChild), so swapping it in reintroduces exactly the kind of side-effect that line was written to prevent. The empty-by-design output is intentional.

WordPress Coding Standards also don't call for removing inline PHP comment tags in templates — <?php // ... ?> as a server-only annotation inside markup is a long-standing, accepted idiom in core.

Given that the comments were added deliberately (r30102 and r41626) and the PHP tag isn't causing any problem, I'd suggest closing this as wontfix. And I don't think there's a change worth making here, but I'll leave the final call to the committers. Thanks for the proposal though, @harishtewari — it's a reasonable thing to question at first glance.

#6 @sabernhardt
8 weeks ago

  • Keywords close added

#7 @westonruter
7 weeks ago

  • Milestone Awaiting Review
  • Resolutionwontfix
  • Status newclosed
Note: See TracTickets for help on using tickets.