Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#18016 closed defect (bug) (invalid)

Running wp_ actions on backend

Reported by: thomask's profile thomask Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: General Keywords:
Focuses: Cc:

Description

I'm not sure if this is a bug, feature or just unclear documentation, but IMO it is something what was not planned at the begining: if you look in the Codex about the actions (http://codex.wordpress.org/Plugin_API/Action_Reference), there are many actions which are under "Actions Run During a Typical Request", but are not under "Actions Run During an Admin Page Request" - there are similar functions with admin_prefix. E.g. wp_head, wp_enqueue_scripts etc.
From this Codex i would guess that those action do NOT run under Admin page request, but it is not true - they are started.
Under that "Actions Run During an Admin Page Request" there is also wp* action, what could mean, that any wp* action runs as well, so it may be intentional, but from that fact that they are explicitly listed on first list and not on the second, i guess that it is wrong.
A also think that it is wrong by design - probably there are minimum to zero actions, which you need to do both at admin AND frontend simultaneously - so now many plugins wrongly run scripts or include something in header of backend unnecessarily, what slows down backend, few of them noticed this problem so they they use !is_admin()

So solution could be
a) do not run all wp* actions on backend (but it may destroy some admin related plugins whoose authors do not notice the admin_ prefixed alternatives)
b) or clarify the Codex and maybe create something like frontend_ prefixed actions, for those who want to address just the frontend

P.S.: this "bug" is for all versions, not just 3.2

Change History (5)

#1 @nacin
14 years ago

Neither wp_head or wp_print_scripts are run in the admin.

I actually can't think of a common wp_ hook that is. Most are admin_*.

#2 @thomask
14 years ago

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

I'm sorry, i have tested it before i post it and it worked but not now, don't know what i was doing. I'm probably too tired, it is 3am here :-(

#3 @thomask
14 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Upss, back again - wp_head definitely run in the admin. This is my code (downgrading the jquery version) - should be just on frontend but is on backend as well

function mc_old_jquery($version) {
  wp_deregister_script('jquery'); 
  wp_register_script('jquery',
  'http://ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery.min.js',
  false, $version);
}
add_action( 'wp_head', mc_old_jquery( '1.4.4' ) ); 

#4 @kawauso
14 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

You're meant to pass a function callback to add_action, i.e. add_action( 'wp_head', 'mc_old_jquery' ). Your code is actually executing mc_old_jquery() when the action is added and attempting to add its non-existant return value as the callback.

#5 @kawauso
14 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.