Make WordPress Core

Opened 18 years ago

Closed 18 years ago

#6197 closed enhancement (fixed)

Add function for checking whether a script has already been added

Reported by: Denis-de-Bernardy Owned by: westi
Priority: lowest Milestone: 2.8
Component: General Version: 2.5
Severity: trivial Keywords: has-patch commit
Cc: Focuses:

Description

a wp_is_enqueued_script($handle) function could be useful... something like:

function wp_is_enqueued_script($handle)
{
  global $wp_scripts;
  if ( !is_object($wp_scripts) )
    return false;
  else
    return in_array($handle, (array) $wp_scripts->queue);
}

Attachments (1)

6197.r10258.diff (2.3 KB ) - added by jacobsantos 18 years ago.
Adds new functions based off of r10258

Download all attachments as: .zip

Change History (11)

#1 @mdawaffe
18 years ago

The wp_scripts already has a method to determine if a script, exists, has been queued, or has been printed.

global $wp_scripts;
return $wp_scripts->query( $handle, 'queue' ); // 'scripts', 'queue', or 'printed'

There's no procedural wrapper for it though.

#2 @Denis-de-Bernardy
18 years ago

  • Priority normallowest

works for me... :)

#3 @westi
18 years ago

  • Keywords needs-patch added
  • Milestone 2.52.6
  • Owner changed from anonymous to westi
  • Status newassigned

Good idea - moving to 2.6 as we are in feature freeze and you can access the info easily if not via a wrapper function.

@jacobsantos
18 years ago

Adds new functions based off of r10258

#4 @jacobsantos
18 years ago

  • Keywords has-patch tested added; needs-patch removed
  • Milestone 2.92.8

Moving to 2.8 since it has a patch.

#5 @jacobsantos
18 years ago

  • Keywords commit needs-testing added; tested removed

#6 @jacobsantos
18 years ago

  • Keywords needs-testing removed

Shouldn't need testing since it is based on part off of the query in WP_Dependencies, so if there is a bug, then it is within WP_Dependencies::query().

#7 @jacobsantos
18 years ago

  • Cc jacobsantos added

#8 @jacobsantos
18 years ago

Yeah, is there a reason this hasn't been committed yet? I'll be willing to make the changes to get this committed.

#9 @jacobsantos
18 years ago

  • Summary extra scripts function suggestionAdd function for checking whether a script has already been added

#10 @westi
18 years ago

  • Resolutionfixed
  • Status assignedclosed

(In [10572]) Expose the ability to find out if styles, scripts have already been queued. Fixes #6197 props jacobsantos

Note: See TracTickets for help on using tickets.