WordPress at a glance
function is not described

WP_Scripts::do_item() WP 2.6.0

Processes a script dependency.

This is a method of the class: WP_Scripts

Return

true/false. True on success, false on failure.

Usage

$WP_Scripts = new WP_Scripts();
$var = $WP_Scripts->do_item( $handle, $group );
$handle(string) (required)
The script's registered handle.
$group(int/false)
Group level: level (int), no groups (false).
Default: false

Notes

  • See: WP_Dependencies::do_item()

Changelog

Since 2.6.0 Introduced.
Since 2.8.0 Added the $group parameter.

Code of WP Scripts::do item: wp-includes/class.wp-scripts.php WP 5.4.2

<?php
public function do_item( $handle, $group = false ) {
	if ( ! parent::do_item( $handle ) ) {
		return false;
	}

	if ( 0 === $group && $this->groups[ $handle ] > 0 ) {
		$this->in_footer[] = $handle;
		return false;
	}

	if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {
		$this->in_footer = array_diff( $this->in_footer, (array) $handle );
	}

	$obj = $this->registered[ $handle ];

	if ( null === $obj->ver ) {
		$ver = '';
	} else {
		$ver = $obj->ver ? $obj->ver : $this->default_version;
	}

	if ( isset( $this->args[ $handle ] ) ) {
		$ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
	}

	$src         = $obj->src;
	$cond_before = '';
	$cond_after  = '';
	$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';

	if ( $conditional ) {
		$cond_before = "<!--[if {$conditional}]>\n";
		$cond_after  = "<![endif]-->\n";
	}

	$before_handle = $this->print_inline_script( $handle, 'before', false );
	$after_handle  = $this->print_inline_script( $handle, 'after', false );

	if ( $before_handle ) {
		$before_handle = sprintf( "<script%s>\n%s\n</script>\n", $this->type_attr, $before_handle );
	}

	if ( $after_handle ) {
		$after_handle = sprintf( "<script%s>\n%s\n</script>\n", $this->type_attr, $after_handle );
	}

	if ( $before_handle || $after_handle ) {
		$inline_script_tag = $cond_before . $before_handle . $after_handle . $cond_after;
	} else {
		$inline_script_tag = '';
	}

	if ( $this->do_concat ) {
		/**
		 * Filters the script loader source.
		 *
		 * @since 2.2.0
		 *
		 * @param string $src    Script loader source path.
		 * @param string $handle Script handle.
		 */
		$srce = apply_filters( 'script_loader_src', $src, $handle );

		if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle ) ) {
			$this->do_concat = false;

			// Have to print the so-far concatenated scripts right away to maintain the right order.
			_print_scripts();
			$this->reset();
		} elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
			$this->print_code     .= $this->print_extra_script( $handle, false );
			$this->concat         .= "$handle,";
			$this->concat_version .= "$handle$ver";
			return true;
		} else {
			$this->ext_handles .= "$handle,";
			$this->ext_version .= "$handle$ver";
		}
	}

	$has_conditional_data = $conditional && $this->get_data( $handle, 'data' );

	if ( $has_conditional_data ) {
		echo $cond_before;
	}

	$this->print_extra_script( $handle );

	if ( $has_conditional_data ) {
		echo $cond_after;
	}

	// A single item may alias a set of items, by having dependencies, but no source.
	if ( ! $src ) {
		if ( $inline_script_tag ) {
			if ( $this->do_concat ) {
				$this->print_html .= $inline_script_tag;
			} else {
				echo $inline_script_tag;
			}
		}

		return true;
	}

	$translations = $this->print_translations( $handle, false );
	if ( $translations ) {
		$translations = sprintf( "<script%s>\n%s\n</script>\n", $this->type_attr, $translations );
	}

	if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
		$src = $this->base_url . $src;
	}

	if ( ! empty( $ver ) ) {
		$src = add_query_arg( 'ver', $ver, $src );
	}

	/** This filter is documented in wp-includes/class.wp-scripts.php */
	$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );

	if ( ! $src ) {
		return true;
	}

	$tag  = $translations . $cond_before . $before_handle;
	$tag .= sprintf( "<script%s src='%s'></script>\n", $this->type_attr, $src );
	$tag .= $after_handle . $cond_after;

	/**
	 * Filters the HTML script tag of an enqueued script.
	 *
	 * @since 4.1.0
	 *
	 * @param string $tag    The `<script>` tag for the enqueued script.
	 * @param string $handle The script's registered handle.
	 * @param string $src    The script's source URL.
	 */
	$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );

	if ( $this->do_concat ) {
		$this->print_html .= $tag;
	} else {
		echo $tag;
	}

	return true;
}