Ticket #11520: get_data.11520.diff
File get_data.11520.diff, 5.9 KB (added by , 13 years ago) |
---|
-
wp-includes/class.wp-styles.php
46 46 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 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; 57 56 } … … 97 96 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 ) 117 121 return $output; … … 151 155 } 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); 157 161 return $this->done; -
wp-includes/class.wp-dependencies.php
134 134 /** 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]) )144 function add_data( $handle, $key, $value ) { 145 if ( !isset( $this->registered[$handle] ) ) 146 146 return false; 147 return $this->registered[$handle]->add_data( $data_name, $data ); 147 148 return $this->registered[$handle]->add_data( $key, $value ); 148 149 } 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]; 170 } 171 150 172 function remove( $handles ) { 151 173 foreach ( (array) $handles as $handle ) 152 174 unset($this->registered[$handle]); -
wp-includes/class.wp-scripts.php
54 54 } 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 65 61 if ( is_array($data) && isset($data['l10n_print_after']) ) { … … 68 64 } 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 } 74 75 } … … 142 143 * 143 144 * Localizes only if script has already been added 144 145 * 145 * @since146 146 * @deprecated WP 3.3 147 147 */ 148 148 function localize( $handle, $object_name, $l10n ) { … … 157 157 * 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) )163 function add_script_data( $handle, $name, $args ) { 164 if ( !$name || !is_array( $args ) ) 165 165 return false; 166 166 167 if ( !empty( $this->registered[$handle]->extra['data'][$name] ) ) 168 $data = array_merge( $data, (array) $this->registered[$handle]->extra['data'][$name] ); 167 $data = $this->get_data( $handle, 'data' ); 169 168 170 return $this->add_data( $handle, 'data', array( $name => $data ) ); 169 if ( !empty( $data[$name] ) ) 170 $args = array_merge( $args, $data[$name] ); 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; 177 180