WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 3 years ago

#38888 new enhancement

Change `init` Priority For Hook: `widgets_init`

Reported by: michael.ecklund Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.3
Component: Widgets Keywords:
Focuses: administration Cc:

Description

The action/hook init is used for Custom Post Types and Custom Taxonomies to be registered.

Most developers register Custom Post Types and Custom Taxonomies on init with the default priority of (10) -- Especially since that's how the examples are illustrated in the documentation on how to register Custom Post Types and Custom Taxonomies.

Action/hook widgets_init is fired ON action/hook init with a priority of (1).

You can see this if you look in default-filters.php for:

// Widgets
add_action( 'init', 'wp_widgets_init', 1 );

So what's the problem?

Widgets are completely unaware of Custom Post Types and Custom Taxonomies, since they're registered on init with the default priority of (1) BEFORE the Custom Post Types and Custom Taxonomies are registered for the most part on init with a default priority of (10).

How to allow Widgets to be aware of Custom Post Types and Custom Taxonomies?

Simple. Change the priority from (1) to (10).

// Widgets
add_action( 'init', 'wp_widgets_init' );

Thoughts? Would this effect anything else? Why was it initially set to (1)? Is there a reason for that?

If you want to make a push for the Theme Customizer, don't you think it would be beneficial for Widgets to be aware of Custom Post Types and Custom Taxonomies?

Change History (2)

#1 @ocean90
5 years ago

Why was it initially set to (1)? Is there a reason for that?

Hooking into init was introduced in [5336].

#2 @westonruter
5 years ago

  • Version changed from 4.6.1 to 2.3
Note: See TracTickets for help on using tickets.