[wp-trac] [WordPress Trac] #62763: get_calendar(): IDs may be duplicated
WordPress Trac
noreply at wordpress.org
Fri Jan 3 07:22:14 UTC 2025
#62763: get_calendar(): IDs may be duplicated
--------------------------+------------------------------
Reporter: wildworks | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by vineet2003):
We want to make the IDs used in the get_calendar() function unique to
avoid duplicates when multiple calendars are shown on the same page. We'll
also allow developers to customize these IDs if needed.
Can we do something like this ?
{{{
// The get_calendar() function generates a calendar in HTML with specific
IDs for the table and today's date cell.
// However, if multiple calendars are displayed on the same page, these
IDs could be duplicated, causing issues.
// To prevent this, we use the wp_unique_id() function to create unique
IDs for each calendar element.
// Additionally, we provide filters that allow developers to customize
these IDs if needed.
// Generate unique IDs for the calendar elements
$calendar_table_id = apply_filters('get_calendar_table_id', 'wp-calendar-'
. wp_unique_id());
$today_cell_id = apply_filters('get_calendar_today_id', 'today-' .
wp_unique_id());
// Example of how these IDs might be used in the HTML
$calendar_html = '<table id="' . esc_attr($calendar_table_id) . '">';
$calendar_html .= '<tr><td id="' . esc_attr($today_cell_id) .
'">Today</td></tr>';
$calendar_html .= '</table>';
return $calendar_html;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62763#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list