register_post_type is being called on 'after_setup_theme' and not 'init'
JiveDig opened this issue · 6 comments
This is breaking a lot of things in my theme(s), mostly by skewing the results of genesis_get_cpt_archive_types()
(i think). Either way, this is a bug. Doc block says it's on the init
hook here https://github.com/copyblogger/Genesis-Author-Pro/blob/master/classes/class.Genesis_Author_Pro_CPT.php#L41 but it's actually on after_setup_theme
https://github.com/copyblogger/Genesis-Author-Pro/blob/master/plugin.php#L68
When I change it to init
all is right in the world (for me) :)
Can this get patched? I can submit PR if needed.
@NicktheGeek There was an issue you opened in the G repo (1173) that is now closed without any commits. Not sure if we needed on after_setup_theme
?
@JiveDig I can't remember the exact details, it's been 3 years, but the reason it was moved has to do with i18n. Something was breaking when we tested the translation and altering the hook let it work to translate correctly.
If your PR does solve for this, then please do.
Otherwise, it might require some additional investigation and testing to get the translation and archive types to work together.
In the interim, if you do not need i18n in your themes, then you may be able to solve this with something like this in the theme.
if ( function_exists( 'gapro_autoloader' ) ) {
remove_action( 'after_setup_theme', array( 'Genesis_Author_Pro_CPT', 'init' ), 1 );
add_action( 'init' , array( 'Genesis_Author_Pro_CPT', 'init' ), 1 );
}
Ah just saw your comments. My PR only changes the hook. If another issue is i18n stuff, I would think the fix for that should be handled elsewhere since it's recommended by core to register post types on init, for exactly the reasons I'm hitting now. Any site that has multiple CPT's that register genesis-cpt-archives-settings support will likely hit issues at its current state.
I'm curious if we can (you) can come to a "next steps" decision here in the near future. I would love to see it moved to init
, but if you know it's not going to move, or at least not for x number of weeks/months I may need to move a different route. I have customers using https://maipro.io that want support for Author Pro plugin, but this late registration of the post type breaks a ton of archive/singular settings in my theme engine plugin.
Not trying to be pushy, just wondering if you had thoughts on the next steps. Thanks :)
I tested the PR at #42 with the repro steps from #8 (comment), and translations still work with the CPT setup moved to init (even without moving the translation setup to init):
So this seems safe to merge to me. cc @NicktheGeek
#42 merged.