/** * @param string $handle * @return bool */ public function do_item($handle) { if (!parent::do_item($handle)) { return false; } $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]; } if ($this->do_concat) { if ($this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt'])) { $this->concat .= "{$handle},"; $this->concat_version .= "{$handle}{$ver}"; $this->print_code .= $this->print_inline_style($handle, false); return true; } } if (isset($obj->args)) { $media = esc_attr($obj->args); } else { $media = 'all'; } $href = $this->_css_href($obj->src, $ver, $handle); if (empty($href)) { // Turns out there is nothing to print. return true; } $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; $title = isset($obj->extra['title']) ? "title='" . esc_attr($obj->extra['title']) . "'" : ''; /** * Filter the HTML link tag of an enqueued style. * * @since 0.0.1 * @since 0.0.1 * * @param string $html The link tag for the enqueued style. * @param string $handle The style's registered handle. * @param string $href The stylesheet's source URL. */ $tag = apply_filters('style_loader_tag', "<link rel='{$rel}' id='{$handle}-css' {$title} href='{$href}' type='text/css' media='{$media}' />\n", $handle, $href); if ('rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl']) { if (is_bool($obj->extra['rtl']) || 'replace' === $obj->extra['rtl']) { $suffix = isset($obj->extra['suffix']) ? $obj->extra['suffix'] : ''; $rtl_href = str_replace("{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href($obj->src, $ver, "{$handle}-rtl")); } else { $rtl_href = $this->_css_href($obj->extra['rtl'], $ver, "{$handle}-rtl"); } /** This filter is documented in hq-includes/class.hq-styles.php */ $rtl_tag = apply_filters('style_loader_tag', "<link rel='{$rel}' id='{$handle}-rtl-css' {$title} href='{$rtl_href}' type='text/css' media='{$media}' />\n", $handle, $rtl_href); if ($obj->extra['rtl'] === 'replace') { $tag = $rtl_tag; } else { $tag .= $rtl_tag; } } $conditional_pre = $conditional_post = ''; if (isset($obj->extra['conditional']) && $obj->extra['conditional']) { $conditional_pre = "<!--[if {$obj->extra['conditional']}]>\n"; $conditional_post = "<![endif]-->\n"; } if ($this->do_concat) { $this->print_html .= $conditional_pre; $this->print_html .= $tag; if ($inline_style = $this->print_inline_style($handle, false)) { $this->print_html .= sprintf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $inline_style); } $this->print_html .= $conditional_post; } else { echo $conditional_pre; echo $tag; $this->print_inline_style($handle); echo $conditional_post; } return true; }
/** * @param string $handle Name of the item. Should be unique. * @param int|bool $group * @return bool True on success, false if not set. */ 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"; } if ($this->do_concat) { /** * Filter the script loader source. * * @since 0.0.1 * * @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) && !$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; } 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 hq-includes/class.hq-scripts.php */ $src = esc_url(apply_filters('script_loader_src', $src, $handle)); if (!$src) { return true; } $tag = "{$cond_before}<script type='text/javascript' src='{$src}'></script>\n{$cond_after}"; /** * Filter the HTML script tag of an enqueued script. * * @since 0.0.1 * * @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; }