Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#14083 closed defect (bug) (fixed)

Back compat for pages and categories for the load-$pagenow hook

Reported by: simonwheatley's profile simonwheatley Owned by:
Milestone: 3.0.1 Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch commit
Focuses: Cc:

Description

In WordPress 3.0 the URLs to create a post and edit a post are now all post-new.php and post.php, with the post type being passed in a GET parameter like so: post-new.php?post_type=page…meaning load-page-new.php and load-page.php action hooks have both vanished!

The attached patch:

  1. Adds in some backwards compatibility for the old load-page-new.php, load-page.php, and load-edit-categories.php hooks.
  1. Adds some new and useful dynamically constructed hooks based on the $typenow and $taxnow variables.

Attachments (3)

typenow-taxnow-actions.diff (1.0 KB) - added by simonwheatley 13 years ago.
Amended paths within diff as per Scribu's recommendations (thanks)
alternatively - adding context to load-$pagenow hook.diff (859 bytes) - added by simonwheatley 13 years ago.
An alternative, as per JohnBillion's sugestions, which passes the type & taxonomy context as params rather than in the hook names
backwards compat.diff (837 bytes) - added by simonwheatley 13 years ago.
Patch which only covers the backwards compatability (no alteration of existing hooks, no new hooks) against the current trunk, now with added speling, corrected code comment and elseif for (very) slight performance increase

Download all attachments as: .zip

Change History (15)

#1 @simonwheatley
13 years ago

  • Keywords has-patch dev-feedback needs-testing added

#2 @simonwheatley
13 years ago

  • Cc simon@… added

#3 follow-up: @scribu
13 years ago

  • Milestone changed from Unassigned to 3.0.1

It should either go in 3.0.1 or not at all.

#4 in reply to: ↑ 3 @simonwheatley
13 years ago

Replying to scribu:

It should either go in 3.0.1 or not at all.

Agreed... for the backwards compatibility hooks, but the new hooks proposal is valid on an ongoing basis.

#5 @scribu
13 years ago

By the way, you should change the relative path in the patch (it's "Users/simon/Projects/HOI-WP/site/wp-admin/admin.php" currently).

@simonwheatley
13 years ago

Amended paths within diff as per Scribu's recommendations (thanks)

#6 in reply to: ↑ description ; follow-up: @johnbillion
13 years ago

  • Component changed from General to Administration

Replying to simonwheatley:

  1. Adds some new and useful dynamically constructed hooks based on the $typenow and $taxnow variables.

"load-edit-tags.php-type-post-tax-category" is a bit of an unweildy hook name in my opinion. I don't think the hook name is the best place to pass so much context.

Would we not be better off sticking with "load-$pagenow" and passing the context (post type and taxonomy) as a parameter?

#7 in reply to: ↑ 6 @simonwheatley
13 years ago

Replying to johnbillion:

Replying to simonwheatley:

  1. Adds some new and useful dynamically constructed hooks based on the $typenow and $taxnow variables.

"load-edit-tags.php-type-post-tax-category" is a bit of an unweildy hook name in my opinion. I don't think the hook name is the best place to pass so much context.

Would we not be better off sticking with "load-$pagenow" and passing the context (post type and taxonomy) as a parameter?

You end up with more conditionals in the hooked function in the plugin if you pass more context, and as there's potentially a lot of different context this might feel a little messy. I like the idea of keeping the hooks precisely targetted, personally, but I guess it's a matter of taste... I do agree that the hooks end up pretty long.

Attaching a diff as per your suggestion so others can comment.

S

@simonwheatley
13 years ago

An alternative, as per JohnBillion's sugestions, which passes the type & taxonomy context as params rather than in the hook names

#8 @ryan
13 years ago

The $current_screen global object contains post_type, taxonomy, and other info.

#9 @nacin
13 years ago

  • Keywords dev-feedback needs-testing removed
  • Summary changed from Specific action hooks for different content types on load of the edit screen to Back compat for pages and categories for the load-$pagenow hook
  • Type changed from enhancement to defect (bug)

It is much better to rely on the $current_screen object. And since these are globals, it is not like these are inaccessible. I suggest we add the back compat hooks, but drop the arguments.

Changing the title and making this a bug. Additional hooks or contexts can be discussed in a new ticket > 3.0.x.

#10 @nacin
13 years ago

  • Keywords commit added

Based on newest patch from simonwheatley.

@simonwheatley
13 years ago

Patch which only covers the backwards compatability (no alteration of existing hooks, no new hooks) against the current trunk, now with added speling, corrected code comment and elseif for (very) slight performance increase

#11 @ryan
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [15387]) Back compat load actions. Props simonwheatley. fixes #14083 for 3.1

#12 @ryan
13 years ago

(In [15388]) Back compat load actions. Props simonwheatley. fixes #14083 for 3.0.1

Note: See TracTickets for help on using tickets.