Opened 7 years ago
Closed 2 years ago
#42834 closed defect (bug) (fixed)
Doc mismatch between developer. and codex., codex appears to be more correct
Reported by: | kluny | Owned by: | |
---|---|---|---|
Milestone: | WordPress.org | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | |
Focuses: | docs | Cc: |
Description (last modified by )
I’m looking at some code that uses the switch_theme
hook. The docs are quite different between the current docs and the old codex.
Specifically, the old version specified that switch_theme
is best used for things that should happen when a theme is *deactivated*, and actions related to the new theme should be on after_switch_theme
. The new docs don’t make the distinction, but the code hasn’t changed since like 4.5. I'm wonder whether developer.wordpress.org has the most correct info?
Change History (5)
#2
@
7 years ago
Also codex seems to be no longer maintained. All the relevant information should be found on developers page :)
Although, someone should update the wpdb
developers page to be like the one for WP_Query()
.
#4
@
4 years ago
- Focuses docs added
The codex automatically redirects to the developers page now, where it has details under More information.
Is there more to add to the section?
#5
@
2 years ago
- Description modified (diff)
- Milestone changed from Awaiting Review to WordPress.org
- Resolution set to fixed
- Status changed from new to closed
The current "More Information" section seems to have what is mentioned in this ticket's description, so I'll close as fixed.
switch_theme
is triggered when the blog’s theme is changed. Specifically, it fires after the theme has been switched but before the next request. Theme developers should use this hook to do things when their theme is deactivated.
Theme functions attached to this hook are only triggered in the theme being deactivated. To do things when your theme is activated, use after_switch_theme.
Functions attached to this action hook receive one parameter: a string with the name of the new theme being activated.
If there is something else to add, feel free to reopen.
Hi @kluny,
The descriptions on https://developer.wordpress.org/ is automatically parsed from the inline docs in the code, which in this case can be found at https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/theme.php#L741. We could improve the online documentation by adding an additional description to the inline docs for this hook, in order to make the use more clear.
Alternately, user contributed notes can be added at the end of each documentation page. In this case, it looks like there is a user supplied example, which states "This hook is useful while deactivating a theme." While close, I don't think that clearly communicates "why" it's useful while deactivating a theme, so additional details would be helpful.