Changeset 18480
- Timestamp:
- 07/28/2011 06:24:00 PM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class.wp-dependencies.php
r18446 r18480 135 135 * Adds extra data 136 136 * 137 * Adds data only if script has already been added 137 * Adds data only if script has already been added. 138 138 * 139 139 * @param string $handle Script name 140 * @param string $ data_name Name of object in which to store extra data141 * @param array $data Array of extra data140 * @param string $key 141 * @param mixed $value 142 142 * @return bool success 143 143 */ 144 function add_data( $handle, $data_name, $data ) { 145 if ( !isset($this->registered[$handle]) ) 146 return false; 147 return $this->registered[$handle]->add_data( $data_name, $data ); 144 function add_data( $handle, $key, $value ) { 145 if ( !isset( $this->registered[$handle] ) ) 146 return false; 147 148 return $this->registered[$handle]->add_data( $key, $value ); 149 } 150 151 /** 152 * Get extra data 153 * 154 * Gets data associated with a certain handle. 155 * 156 * @since WP 3.3 157 * 158 * @param string $handle Script name 159 * @param string $key 160 * @return mixed 161 */ 162 function get_data( $handle, $key ) { 163 if ( !isset( $this->registered[$handle] ) ) 164 return false; 165 166 if ( !isset( $this->registered[$handle]->extra[$key] ) ) 167 return false; 168 169 return $this->registered[$handle]->extra[$key]; 148 170 } 149 171 -
trunk/wp-includes/class.wp-scripts.php
r18464 r18480 55 55 56 56 function print_script_data( $handle, $echo = true, $_l10n = false ) { 57 if ( empty($this->registered[$handle]->extra['data']) )58 return false;59 60 57 if ( $_l10n ) { 61 $name = $this->registered[$handle]->extra['l10n'][0]; 62 $data = $this->registered[$handle]->extra['l10n'][1]; 58 list( $name, $data ) = $this->get_data( $handle, 'l10n' ); 63 59 $after = ''; 64 60 … … 69 65 $output = "var $name = " . json_encode($data) . "; $after\n"; 70 66 } else { 71 foreach ( (array) $this->registered[$handle]->extra['data'] as $name => $data ) { 67 $data = $this->get_data( $handle, 'data' ); 68 69 if ( empty( $data ) ) 70 return false; 71 72 foreach ( (array) $data as $name => $data ) { 72 73 $output = "var $name = " . json_encode($data) . ";\n"; 73 74 } … … 143 144 * Localizes only if script has already been added 144 145 * 145 * @since146 146 * @deprecated WP 3.3 147 147 */ … … 158 158 * @param string $handle Script name 159 159 * @param string $name Name of JS object to hold the data 160 * @param array $ data Associative array of JS name => value160 * @param array $args Associative array of JS object attributes 161 161 * @return bool Successful or not 162 162 */ 163 function add_script_data( $handle, $name, $data ) { 164 if ( !$name || !is_array($data) ) 165 return false; 166 167 if ( !empty( $this->registered[$handle]->extra['data'][$name] ) ) 168 $data = array_merge( $data, (array) $this->registered[$handle]->extra['data'][$name] ); 169 170 return $this->add_data( $handle, 'data', array( $name => $data ) ); 163 function add_script_data( $handle, $name, $args ) { 164 if ( !$name || !is_array( $args ) ) 165 return false; 166 167 $data = $this->get_data( $handle, 'data' ); 168 169 if ( !empty( $data[$name] ) ) 170 $args = array_merge( $data[$name], $args ); 171 172 return $this->add_data( $handle, 'data', array( $name => $args ) ); 171 173 } 172 174 173 175 function set_group( $handle, $recursion, $group = false ) { 174 $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0; 176 $grp = (int) $this->get_data( $handle, 'group' ); 177 175 178 if ( false !== $group && $grp > $group ) 176 179 $grp = $group; -
trunk/wp-includes/class.wp-styles.php
r18464 r18480 47 47 48 48 if ( $this->do_concat ) { 49 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) 49 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { 50 50 $this->concat .= "$handle,"; 51 51 $this->concat_version .= "$handle$ver"; 52 52 53 if ( !empty($this->registered[$handle]->extra['data']) ) 54 $this->print_code .= $this->registered[$handle]->extra['data']; 53 $this->print_code .= $this->get_data( $handle, 'after' ); 55 54 56 55 return true; … … 98 97 } 99 98 100 function add_inline_style( $handle, $ data) {101 if ( !$ data)99 function add_inline_style( $handle, $code ) { 100 if ( !$code ) 102 101 return false; 103 102 104 if ( !empty( $this->registered[$handle]->extra['data'] ) ) 105 $data .= "\n" . $this->registered[$handle]->extra['data']; 103 $after = $this->get_data( $handle, 'after' ); 104 if ( !$after ) 105 $after = array(); 106 106 107 return $this->add_data( $handle, 'data', $data ); 107 $after[] = $code; 108 109 return $this->add_data( $handle, 'after', $after ); 108 110 } 109 111 110 112 function print_inline_style( $handle, $echo = true ) { 111 if ( empty($this->registered[$handle]->extra['data']) ) 113 $output = $this->get_data( $handle, 'after' ); 114 115 if ( empty( $output ) ) 112 116 return false; 113 117 114 $output = $this->registered[$handle]->extra['data'];118 $output = implode( "\n", $output ); 115 119 116 120 if ( !$echo ) … … 152 156 return false; 153 157 } 154 158 155 159 function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer. 156 160 $this->do_items(false, 1); -
trunk/wp-includes/functions.wp-scripts.php
r18464 r18480 67 67 * } 68 68 * The $name is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/ 69 * The $data array is JSON encoded. If called more than once for the same $handle ,with the same $name,69 * The $data array is JSON encoded. If called more than once for the same $handle with the same $name, 70 70 * the object would contain all values. In that case if two or more keys are the same, 71 * the first value is kept and subsequent values are ignored.71 * the last value overwrites the previous. 72 72 * 73 73 * @since 3.3 -
trunk/wp-includes/functions.wp-styles.php
r18464 r18480 38 38 * 39 39 * Works only if the stylesheet has already been added. 40 * Accepts a string $data containing the CSS. 40 * Accepts a string $data containing the CSS. If two or more CSS code blocks are 41 * added to the same stylesheet $handle, they will be printed in the order 42 * they were added, i.e. the latter added styles can redeclare the previous. 41 43 * 42 44 * @since 3.3
Note: See TracChangeset
for help on using the changeset viewer.