wp/wp-includes/class.wp-scripts.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * BackPress Scripts enqueue.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * These classes were refactored from the WordPress WP_Scripts and WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * script enqueue API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @package BackPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 * @since r16
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * BackPress Scripts enqueue class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @package BackPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @uses WP_Dependencies
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @since r16
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
class WP_Scripts extends WP_Dependencies {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
	public $base_url; // Full URL with trailing slash
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	public $content_url;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
	public $default_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
	public $in_footer = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	public $concat = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
	public $concat_version = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	public $do_concat = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	public $print_html = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	public $print_code = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	public $ext_handles = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	public $ext_version = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	public $default_dirs;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	public function __construct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		add_action( 'init', array( $this, 'init' ), 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	public function init() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
		 * Fires when the WP_Scripts instance is initialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
		 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
		 * @param WP_Scripts &$this WP_Scripts instance, passed by reference.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		do_action_ref_array( 'wp_default_scripts', array(&$this) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
	 * Prints scripts.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	 * Prints the scripts passed to it or the print queue. Also prints all necessary dependencies.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
	 * @param mixed $handles Optional. Scripts to be printed. (void) prints queue, (string) prints
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	 *                       that script, (array of strings) prints those scripts. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
	 * @param int   $group   Optional. If scripts were queued in groups prints this group number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
	 *                       Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
	 * @return array Scripts that have been printed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
	public function print_scripts( $handles = false, $group = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		return $this->do_items( $handles, $group );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	// Deprecated since 3.3, see print_extra_script()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	public function print_scripts_l10n( $handle, $echo = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		_deprecated_function( __FUNCTION__, '3.3', 'print_extra_script()' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		return $this->print_extra_script( $handle, $echo );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
	public function print_extra_script( $handle, $echo = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		if ( !$output = $this->get_data( $handle, 'data' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		if ( !$echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
		echo "/* <![CDATA[ */\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		echo "$output\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		echo "/* ]]> */\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		echo "</script>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
	public function do_item( $handle, $group = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		if ( !parent::do_item($handle) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		if ( 0 === $group && $this->groups[$handle] > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			$this->in_footer[] = $handle;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		if ( false === $group && in_array($handle, $this->in_footer, true) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
			$this->in_footer = array_diff( $this->in_footer, (array) $handle );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		$obj = $this->registered[$handle];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
		if ( null === $obj->ver ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
			$ver = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
			$ver = $obj->ver ? $obj->ver : $this->default_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		if ( isset($this->args[$handle]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			$ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
		$src = $obj->src;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		$cond_before = $cond_after = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
		$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
		if ( $conditional ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
			$cond_before = "<!--[if {$conditional}]>\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
			$cond_after = "<![endif]-->\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		if ( $this->do_concat ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
			 * Filter the script loader source.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
			 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
			 * @param string $src    Script loader source path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
			 * @param string $handle Script handle.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
			$srce = apply_filters( 'script_loader_src', $src, $handle );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
			if ( $this->in_default_dir( $srce ) && ! $conditional ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
				$this->print_code .= $this->print_extra_script( $handle, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
				$this->concat .= "$handle,";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
				$this->concat_version .= "$handle$ver";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
				$this->ext_handles .= "$handle,";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
				$this->ext_version .= "$handle$ver";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
		$has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		if ( $has_conditional_data ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
			echo $cond_before;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		$this->print_extra_script( $handle );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
		if ( $has_conditional_data ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
			echo $cond_after;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
		if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
			$src = $this->base_url . $src;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
		if ( ! empty( $ver ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
			$src = add_query_arg( 'ver', $ver, $src );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
		/** This filter is documented in wp-includes/class.wp-scripts.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
		if ( ! $src )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
		$tag = "{$cond_before}<script type='text/javascript' src='$src'></script>\n{$cond_after}";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
		/** 
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
		 * Filter the HTML script tag of an enqueued script.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
		 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
		 * @param string $tag    The `<script>` tag for the enqueued script.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
		 * @param string $handle The script's registered handle.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
		 * @param string $src    The script's source URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
		$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
		if ( $this->do_concat ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
			$this->print_html .= $tag;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
			echo $tag;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	 * Localizes a script
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	 * Localizes only if the script has already been added
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
	public function localize( $handle, $object_name, $l10n ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
		if ( $handle === 'jquery' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			$handle = 'jquery-core';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
			$after = $l10n['l10n_print_after'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			unset($l10n['l10n_print_after']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
		foreach ( (array) $l10n as $key => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
			if ( !is_scalar($value) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			$l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
		$script = "var $object_name = " . wp_json_encode( $l10n ) . ';';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		if ( !empty($after) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
			$script .= "\n$after;";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		$data = $this->get_data( $handle, 'data' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
		if ( !empty( $data ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
			$script = "$data\n$script";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		return $this->add_data( $handle, 'data', $script );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
	public function set_group( $handle, $recursion, $group = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		if ( $this->registered[$handle]->args === 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			$grp = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
			$grp = (int) $this->get_data( $handle, 'group' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
		if ( false !== $group && $grp > $group )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			$grp = $group;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		return parent::set_group( $handle, $recursion, $grp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
	public function all_deps( $handles, $recursion = false, $group = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		$r = parent::all_deps( $handles, $recursion );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
		if ( ! $recursion ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
			 * Filter the list of script dependencies left to print.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
			 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
			 * @param array $to_do An array of script dependencies.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
			$this->to_do = apply_filters( 'print_scripts_array', $this->to_do );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
	public function do_head_items() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
		$this->do_items(false, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		return $this->done;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
	public function do_footer_items() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		$this->do_items(false, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		return $this->done;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
	public function in_default_dir( $src ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
		if ( ! $this->default_dirs ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
			return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
		if ( 0 === strpos( $src, '/' . WPINC . '/js/l10n' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		foreach ( (array) $this->default_dirs as $test ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
			if ( 0 === strpos( $src, $test ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
				return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
	public function reset() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
		$this->do_concat = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		$this->print_code = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		$this->concat = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		$this->concat_version = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		$this->print_html = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		$this->ext_version = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
		$this->ext_handles = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
}