• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WP_Scripts::do_item() – Processes a script dependency.

You appear to be a bot. Output may be restricted

Description

Processes a script dependency.

Usage

$bool = WP_Scripts::do_item( $handle, $group );

Parameters

$handle
( string ) required – The script's registered handle.
$group
( int|false ) optional – Optional. Group level: level (int), no groups (false). Default false.

Returns

bool True on success, false on failure.

Source

File name: wordpress/wp-includes/class.wp-scripts.php
Lines:

1 to 100 of 149
  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 . '&' . $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->WP_Scripts::print_inline_script( $handle, 'before', false );
    $after_handle  = $this->WP_Scripts::print_inline_script( $handle, 'after', false );

    if ( $before_handle ) {
      $before_handle = sprintf( "<script%s id='%s-js-before'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $before_handle );
    }

    if ( $after_handle ) {
      $after_handle = sprintf( "<script%s id='%s-js-after'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $after_handle );
    }

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

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

    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->WP_Scripts::in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations ) ) {
        $this->do_concat = false;

        // Have to print the so-far concatenated scripts right away to maintain the right order.
        _print_scripts();
        $this->WP_Scripts::reset();
      } elseif ( $this->WP_Scripts::in_default_dir( $srce ) && ! $conditional ) {
        $this->print_code     .= $this->WP_Scripts::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->WP_Scripts::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 ) {
 
[1] [2] Next »

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 1st September 2020

Primary Sidebar

Information

Function name: WP_Scripts::do_item
Class ref: WP_Scripts
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/class.wp-scripts.php
File ref: wp-includes/class.wp-scripts.php
Deprecated?: No
API Letters: D,I,S,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites