<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[18480] trunk/wp-includes: Introduce WP_Dependencies::get_data() method, change scripts and styles priority to follow the "natural" order in HTML, i.e.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/18480">18480</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2011-07-28 18:24:00 +0000 (Thu, 28 Jul 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce WP_Dependencies::get_data() method, change scripts and styles priority to follow the "natural" order in HTML, i.e. the last one wins, props scribu, see <a href="http://core.trac.wordpress.org/ticket/11520">#11520</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclasswpdependenciesphp">trunk/wp-includes/class.wp-dependencies.php</a></li>
<li><a href="#trunkwpincludesclasswpscriptsphp">trunk/wp-includes/class.wp-scripts.php</a></li>
<li><a href="#trunkwpincludesclasswpstylesphp">trunk/wp-includes/class.wp-styles.php</a></li>
<li><a href="#trunkwpincludesfunctionswpscriptsphp">trunk/wp-includes/functions.wp-scripts.php</a></li>
<li><a href="#trunkwpincludesfunctionswpstylesphp">trunk/wp-includes/functions.wp-styles.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclasswpdependenciesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class.wp-dependencies.php (18479 => 18480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class.wp-dependencies.php        2011-07-28 17:35:37 UTC (rev 18479)
+++ trunk/wp-includes/class.wp-dependencies.php        2011-07-28 18:24:00 UTC (rev 18480)
</span><span class="lines">@@ -134,19 +134,41 @@
</span><span class="cx">         /**
</span><span class="cx">          * Adds extra data
</span><span class="cx">          *
</span><del>-         * Adds data only if script has already been added
</del><ins>+         * Adds data only if script has already been added.
</ins><span class="cx">          *
</span><span class="cx">          * @param string $handle Script name
</span><del>-         * @param string $data_name Name of object in which to store extra data
-         * @param array $data Array of extra data
</del><ins>+         * @param string $key
+         * @param mixed $value
</ins><span class="cx">          * @return bool success
</span><span class="cx">          */
</span><del>-        function add_data( $handle, $data_name, $data ) {
-                if ( !isset($this->registered[$handle]) )
</del><ins>+        function add_data( $handle, $key, $value ) {
+                if ( !isset( $this->registered[$handle] ) )
</ins><span class="cx">                         return false;
</span><del>-                return $this->registered[$handle]->add_data( $data_name, $data );
</del><ins>+
+                return $this->registered[$handle]->add_data( $key, $value );
</ins><span class="cx">         }
</span><span class="cx">
</span><ins>+        /**
+         * Get extra data
+         *
+         * Gets data associated with a certain handle.
+         *
+         * @since WP 3.3
+         *
+         * @param string $handle Script name
+         * @param string $key
+         * @return mixed
+         */
+        function get_data( $handle, $key ) {
+                if ( !isset( $this->registered[$handle] ) )
+                        return false;
+
+                if ( !isset( $this->registered[$handle]->extra[$key] ) )
+                        return false;
+
+                return $this->registered[$handle]->extra[$key];
+        }
+
</ins><span class="cx">         function remove( $handles ) {
</span><span class="cx">                 foreach ( (array) $handles as $handle )
</span><span class="cx">                         unset($this->registered[$handle]);
</span></span></pre></div>
<a id="trunkwpincludesclasswpscriptsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class.wp-scripts.php (18479 => 18480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class.wp-scripts.php        2011-07-28 17:35:37 UTC (rev 18479)
+++ trunk/wp-includes/class.wp-scripts.php        2011-07-28 18:24:00 UTC (rev 18480)
</span><span class="lines">@@ -54,12 +54,8 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function print_script_data( $handle, $echo = true, $_l10n = false ) {
</span><del>-                if ( empty($this->registered[$handle]->extra['data']) )
-                        return false;
-
</del><span class="cx">                 if ( $_l10n ) {
</span><del>-                        $name = $this->registered[$handle]->extra['l10n'][0];
-                        $data = $this->registered[$handle]->extra['l10n'][1];
</del><ins>+                        list( $name, $data ) = $this->get_data( $handle, 'l10n' );
</ins><span class="cx">                         $after = '';
</span><span class="cx">
</span><span class="cx">                         if ( is_array($data) && isset($data['l10n_print_after']) ) {
</span><span class="lines">@@ -68,7 +64,12 @@
</span><span class="cx">                         }
</span><span class="cx">                         $output = "var $name = " . json_encode($data) . "; $after\n";
</span><span class="cx">                 } else {
</span><del>-                        foreach ( (array) $this->registered[$handle]->extra['data'] as $name => $data ) {
</del><ins>+                        $data = $this->get_data( $handle, 'data' );
+
+                        if ( empty( $data ) )
+                                return false;
+
+                        foreach ( (array) $data as $name => $data ) {
</ins><span class="cx">                                 $output = "var $name = " . json_encode($data) . ";\n";
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -142,7 +143,6 @@
</span><span class="cx">          *
</span><span class="cx">          * Localizes only if script has already been added
</span><span class="cx">          *
</span><del>-         * @since
</del><span class="cx">          * @deprecated WP 3.3
</span><span class="cx">          */
</span><span class="cx">         function localize( $handle, $object_name, $l10n ) {
</span><span class="lines">@@ -157,21 +157,24 @@
</span><span class="cx">          *
</span><span class="cx">          * @param string $handle Script name
</span><span class="cx">          * @param string $name Name of JS object to hold the data
</span><del>-         * @param array $data Associative array of JS name => value
</del><ins>+         * @param array $args Associative array of JS object attributes
</ins><span class="cx">          * @return bool Successful or not
</span><span class="cx">          */
</span><del>-        function add_script_data( $handle, $name, $data ) {
-                if ( !$name || !is_array($data) )
</del><ins>+        function add_script_data( $handle, $name, $args ) {
+                if ( !$name || !is_array( $args ) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                if ( !empty( $this->registered[$handle]->extra['data'][$name] ) )
-                        $data = array_merge( $data, (array) $this->registered[$handle]->extra['data'][$name] );
</del><ins>+                $data = $this->get_data( $handle, 'data' );
</ins><span class="cx">
</span><del>-                return $this->add_data( $handle, 'data', array( $name => $data ) );
</del><ins>+                if ( !empty( $data[$name] ) )
+                        $args = array_merge( $data[$name], $args );
+
+                return $this->add_data( $handle, 'data', array( $name => $args ) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function set_group( $handle, $recursion, $group = false ) {
</span><del>-                $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0;
</del><ins>+                $grp = (int) $this->get_data( $handle, 'group' );
+
</ins><span class="cx">                 if ( false !== $group && $grp > $group )
</span><span class="cx">                         $grp = $group;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesclasswpstylesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class.wp-styles.php (18479 => 18480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class.wp-styles.php        2011-07-28 17:35:37 UTC (rev 18479)
+++ trunk/wp-includes/class.wp-styles.php        2011-07-28 18:24:00 UTC (rev 18480)
</span><span class="lines">@@ -46,12 +46,11 @@
</span><span class="cx">                         $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
</span><span class="cx">
</span><span class="cx">                 if ( $this->do_concat ) {
</span><del>-                        if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional'])        && !isset($obj->extra['alt']) ) {
</del><ins>+                        if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
</ins><span class="cx">                                 $this->concat .= "$handle,";
</span><span class="cx">                                 $this->concat_version .= "$handle$ver";
</span><span class="cx">
</span><del>-                                if ( !empty($this->registered[$handle]->extra['data']) )
-                                        $this->print_code .= $this->registered[$handle]->extra['data'];
</del><ins>+                                $this->print_code .= $this->get_data( $handle, 'after' );
</ins><span class="cx">
</span><span class="cx">                                 return true;
</span><span class="cx">                         }
</span><span class="lines">@@ -97,21 +96,26 @@
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function add_inline_style( $handle, $data ) {
-                if ( !$data )
</del><ins>+        function add_inline_style( $handle, $code ) {
+                if ( !$code )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                if ( !empty( $this->registered[$handle]->extra['data'] ) )
-                        $data .= "\n" . $this->registered[$handle]->extra['data'];
</del><ins>+                $after = $this->get_data( $handle, 'after' );
+                if ( !$after )
+                        $after = array();
</ins><span class="cx">
</span><del>-                return $this->add_data( $handle, 'data', $data );
</del><ins>+                $after[] = $code;
+
+                return $this->add_data( $handle, 'after', $after );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function print_inline_style( $handle, $echo = true ) {
</span><del>-                if ( empty($this->registered[$handle]->extra['data']) )
</del><ins>+                $output = $this->get_data( $handle, 'after' );
+
+                if ( empty( $output ) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                $output = $this->registered[$handle]->extra['data'];
</del><ins>+                $output = implode( "\n", $output );
</ins><span class="cx">
</span><span class="cx">                 if ( !$echo )
</span><span class="cx">                         return $output;
</span><span class="lines">@@ -151,7 +155,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
</span><span class="cx">                 $this->do_items(false, 1);
</span><span class="cx">                 return $this->done;
</span></span></pre></div>
<a id="trunkwpincludesfunctionswpscriptsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.wp-scripts.php (18479 => 18480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.wp-scripts.php        2011-07-28 17:35:37 UTC (rev 18479)
+++ trunk/wp-includes/functions.wp-scripts.php        2011-07-28 18:24:00 UTC (rev 18480)
</span><span class="lines">@@ -66,9 +66,9 @@
</span><span class="cx"> * ...
</span><span class="cx"> * }
</span><span class="cx"> * The $name is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/
</span><del>- * The $data array is JSON encoded. If called more than once for the same $handle, with the same $name,
</del><ins>+ * The $data array is JSON encoded. If called more than once for the same $handle with the same $name,
</ins><span class="cx"> * the object would contain all values. In that case if two or more keys are the same,
</span><del>- * the first value is kept and subsequent values are ignored.
</del><ins>+ * the last value overwrites the previous.
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.3
</span><span class="cx"> * @see WP_Scripts::add_script_data()
</span></span></pre></div>
<a id="trunkwpincludesfunctionswpstylesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.wp-styles.php (18479 => 18480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.wp-styles.php        2011-07-28 17:35:37 UTC (rev 18479)
+++ trunk/wp-includes/functions.wp-styles.php        2011-07-28 18:24:00 UTC (rev 18480)
</span><span class="lines">@@ -37,7 +37,9 @@
</span><span class="cx"> * Adds extra CSS.
</span><span class="cx"> *
</span><span class="cx"> * Works only if the stylesheet has already been added.
</span><del>- * Accepts a string $data containing the CSS.
</del><ins>+ * Accepts a string $data containing the CSS. If two or more CSS code blocks are
+ * added to the same stylesheet $handle, they will be printed in the order
+ * they were added, i.e. the latter added styles can redeclare the previous.
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.3
</span><span class="cx"> * @see WP_Scripts::add_inline_style()
</span></span></pre>
</div>
</div>
</body>
</html>