[wp-trac] [WordPress Trac] #36579: global $wp_rewrite not set when create_initial_post_types() first run

WordPress Trac noreply at wordpress.org
Tue Apr 19 09:33:48 UTC 2016


#36579: global $wp_rewrite not set when create_initial_post_types() first run
-------------------------------+------------------------------
 Reporter:  bobbingwide        |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  4.4
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by dd32):

 > I could wait for 'plugins_loaded' but it's probably safer to wait for
 'setup_theme', since $wp_rewrite should have been initialised by then.

 * You should run `add_action()`/`add_filter()` on `plugins_loaded` or
 later
 * Adding the action on `plugins_loaded` is fine, as the
 `register_post_type_args` filter won't fire again until either a) A plugin
 registers a post type, or b) `init` when `create_initial_post_types()` is
 run again.
 * You shouldn't run code which expects WordPress to be initialised (such
 as `$wp_rewrite`) until `init` or later

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36579#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list