Opened 6 weeks ago
Last modified 5 weeks ago
#62763 new defect (bug)
get_calendar(): IDs may be duplicated
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
I discovered this while looking into the following Gutenberg issue: https://github.com/WordPress/gutenberg/issues/68451
The get_calendar()
function applies the following two IDs to the generated HTML:
- table element:
wp-calendar
- Today's date cell:
today
These IDs cannot be changed, so the IDs will be duplicated if multiple calendars are output.
Using the wp_unique_id()
function will help us avoid duplicate IDs, but there are themes or plugins that rely on existing IDs, so we may need to use a different approach.
Change History (4)
#2
@
5 weeks ago
Hi @vineet2003, I guess this is a straightforward approach, But it may have some implications.
For example, We need to find an approach that plugin/theme developers does not need to do extra thing like to add the filter, if ultimately they need to, then we can just use wp_unique_id without any additional filters, and ask plugin/theme developer to change their code to use the generated ID may be in JS. So we would not introduce any extra filter to the core codebase.
So, we need to find an approach that plugin/theme developer would not need to change/add something to their codebase, and we can achieve the desired results or, if ultimately they need to change, then we should use directly wp_unique_id() and ask them to use new ID.
#3
@
5 weeks ago
Also, @wildworks, If plugin or theme developer have used the IDs
to add some of their logic, then probably they would not have use calendar ID to add some logic, instead they may have use classes for the logic.
We just need to check if calendar is use single time on page and if they have used the ID for some internal logic.
#4
@
5 weeks ago
Hi @hbhalodia,
Thanks for your input! I understand the desire to keep things simple and avoid adding extra filters. However, I believe adding filters to customize the calendar IDs (as I suggested) would provide more flexibility in the long run. Some developers might rely on the default wp-calendar and today IDs for their JavaScript or CSS, and changing them without a way to customize could break their existing functionality.
Using wp_unique_id() directly is a great solution for preventing duplicates, but I think offering the option to customize the IDs via filters would give developers the control they need while avoiding potential conflicts.
Let me know your thoughts on striking a balance between simplicity and flexibility!
Thanks
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 ?