wp_scripts = $wp_scripts; } /** * @since 3.6 */ public function script_will_be_printed( $handle ) { if ( $this->query( $handle, 'queue' ) ) { return true; } if ( $this->query( $handle, 'done' ) ) { return true; } if ( $this->query( $handle, 'to_do' ) ) { return true; } return false; } /** * Based on WP_Dependency::query implementation in WordPress 4.3. * * @since 3.6 */ public function query( $handle, $list = 'registered' ) { if ( version_compare( get_bloginfo( 'version' ), '4.0', '>' ) ) { return $this->wp_scripts->query( $handle, $list ); } if ( ! in_array( $list, array( 'enqueued', 'queue' ) ) ) { return $this->wp_scripts->query( $handle, $list ); } if ( ! $this->wp_scripts->query( $handle, $list ) ) { return $this->recurse_deps( $this->wp_scripts->queue, $handle ); } return true; } /** * Recursively search the passed dependency tree for $handle. * Borrowed from WP_Dependency in WordPress 4.3. * * @since 3.6 * * @param array $queue An array of queued _WP_Dependency handle objects. * @param string $handle Name of the item. Should be unique. * @return bool Whether the handle is found after recursively searching the dependency tree. */ function recurse_deps( $queue, $handle ) { $registered = $this->wp_scripts->registered; foreach ( $queue as $queued ) { if ( ! isset( $registered[ $queued ] ) ) { continue; } if ( in_array( $handle, $registered[ $queued ]->deps ) ) { return true; } elseif ( $this->recurse_deps( $registered[ $queued ]->deps, $handle ) ) { return true; } } return false; } }