Make WordPress Core

Opened 18 years ago

Closed 17 years ago

#6197 closed enhancement (fixed)

Add function for checking whether a script has already been added

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

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 17 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 changed from normal to lowest

works for me... :)

#3 @westi
18 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.5 to 2.6
  • Owner changed from anonymous to westi
  • Status changed from new to assigned

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
17 years ago

Adds new functions based off of r10258

#4 @jacobsantos
17 years ago

  • Keywords has-patch tested added; needs-patch removed
  • Milestone changed from 2.9 to 2.8

Moving to 2.8 since it has a patch.

#5 @jacobsantos
17 years ago

  • Keywords commit needs-testing added; tested removed

#6 @jacobsantos
17 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
17 years ago

  • Cc jacobsantos added

#8 @jacobsantos
17 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
17 years ago

  • Summary changed from extra scripts function suggestion to Add function for checking whether a script has already been added

#10 @westi
17 years ago

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

(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.