Ticket #25333: 25333.diff
| File 25333.diff, 6.6 KB (added by , 13 years ago) |
|---|
-
src/wp-includes/theme.php
1261 1261 */ 1262 1262 function add_theme_support( $feature ) { 1263 1263 global $_wp_theme_features; 1264 static $_back_compat = array(); 1264 1265 1265 1266 if ( func_num_args() == 1 ) 1266 1267 $args = true; … … 1323 1324 if ( $jit ) 1324 1325 $args[0] = wp_parse_args( $args[0], $defaults ); 1325 1326 1326 // If a constant was defined, use that value. Otherwise, define the constant to ensure 1327 // the constant is always accurate (and is not defined later, overriding our value). 1327 // Make sure the code below runs only once, otherwise the defined constants will keep 1328 // overriding the $args, regardless of whether they've been removed with remove_theme_support(). 1329 1330 if ( ! isset( $_back_compat[ $feature ] ) ) { 1331 $_back_compat[ $feature ] = array(); 1332 } 1333 1334 $_back_compat[ $feature ] = array_merge( $_back_compat[ $feature ], array_map( '__return_true', $args[0] ) ); 1335 1336 // If a constant was defined, use that value, but only use it once. 1328 1337 // As stated above, the first value wins. 1329 // Once we get to wp_loaded (just-in-time), define any constants we haven't already.1330 // Constants are lame. Don't reference them. This is just for backwards compatibility.1331 1338 1332 if ( defined( 'NO_HEADER_TEXT' ) )1339 if ( defined( 'NO_HEADER_TEXT' ) && ! isset( $_back_compat[ $feature ]['header-text'] ) ) { 1333 1340 $args[0]['header-text'] = ! NO_HEADER_TEXT; 1334 elseif ( isset( $args[0]['header-text'] ) )1335 define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) );1341 $_back_compat[ $feature ]['header-text'] = true; 1342 } 1336 1343 1337 if ( defined( 'HEADER_IMAGE_WIDTH' ) )1344 if ( defined( 'HEADER_IMAGE_WIDTH' ) && ! isset( $_back_compat[ $feature ]['width'] ) ) { 1338 1345 $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; 1339 elseif ( isset( $args[0]['width'] ) )1340 define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] );1346 $_back_compat[ $feature ]['width'] = true; 1347 } 1341 1348 1342 if ( defined( 'HEADER_IMAGE_HEIGHT' ) )1349 if ( defined( 'HEADER_IMAGE_HEIGHT' ) && ! isset( $_back_compat[ $feature ]['height'] ) ) { 1343 1350 $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; 1344 elseif ( isset( $args[0]['height'] ) )1345 define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] );1351 $_back_compat[ $feature ]['height'] = true; 1352 } 1346 1353 1347 if ( defined( 'HEADER_TEXTCOLOR' ) )1354 if ( defined( 'HEADER_TEXTCOLOR' ) && ! isset( $_back_compat[ $feature ]['default-text-color'] ) ) { 1348 1355 $args[0]['default-text-color'] = HEADER_TEXTCOLOR; 1349 elseif ( isset( $args[0]['default-text-color'] ) )1350 define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] );1356 $_back_compat[ $feature ]['default-text-color'] = true; 1357 } 1351 1358 1352 if ( defined( 'HEADER_IMAGE' ) )1359 if ( defined( 'HEADER_IMAGE' ) && ! isset( $_back_compat[ $feature ]['default-image'] ) ) { 1353 1360 $args[0]['default-image'] = HEADER_IMAGE; 1354 elseif ( isset( $args[0]['default-image'] ) )1355 define( 'HEADER_IMAGE', $args[0]['default-image'] );1361 $_back_compat[ $feature ]['default-image'] = true; 1362 } 1356 1363 1357 1364 if ( $jit && ! empty( $args[0]['default-image'] ) ) 1358 1365 $args[0]['random-default'] = false; … … 1366 1373 $args[0]['flex-height'] = true; 1367 1374 } 1368 1375 1376 // Once we get to wp_loaded (just-in-time), define any constants we haven't already. 1377 // Constants are lame. Don't reference them. This is just for backwards compatibility. 1378 if ( $jit ) { 1379 if ( ! defined( 'NO_HEADER_TEXT' ) ) { 1380 define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); 1381 } 1382 1383 if ( ! defined( 'HEADER_IMAGE_WIDTH' ) ) { 1384 define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); 1385 } 1386 1387 if ( ! defined( 'HEADER_IMAGE_HEIGHT' ) ) { 1388 define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); 1389 } 1390 1391 if ( ! defined( 'HEADER_TEXTCOLOR' ) ) { 1392 define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); 1393 } 1394 1395 if ( ! defined( 'HEADER_IMAGE' ) ) { 1396 define( 'HEADER_IMAGE', $args[0]['default-image'] ); 1397 } 1398 } 1399 1369 1400 break; 1370 1401 1371 1402 case 'custom-background' : -
tests/phpunit/tests/theme/support.php
156 156 remove_theme_support( 'foobar' ); 157 157 $this->assertFalse( current_theme_supports( 'foobar', 'bar' ) ); 158 158 } 159 160 /** 161 * @ticket 25333 162 */ 163 function test_remove_theme_support() { 164 165 // At this point, the default theme has (probably) already registered custom header support. 166 $original_width = get_theme_support( 'custom-header', 'width' ); 167 $original_image = get_theme_support( 'custom-header', 'default-image' ); 168 169 $this->assertTrue( defined( 'HEADER_IMAGE_WIDTH' ) ); 170 $this->assertTrue( defined( 'HEADER_IMAGE' ) ); 171 $this->assertEquals( HEADER_IMAGE_WIDTH, $original_width ); 172 $this->assertEquals( HEADER_IMAGE, $original_image ); 173 174 remove_theme_support( 'custom-header' ); 175 $this->assertFalse( current_theme_supports( 'custom-header' ) ); 176 177 // First registered value wins, because child themes are loaded earlier. 178 add_theme_support( 'custom-header', array( 'default-image' => 'foo' ) ); 179 $this->assertEquals( 'foo', get_theme_support( 'custom-header', 'default-image' ) ); 180 181 // This should not override the above. 182 add_theme_support( 'custom-header', array( 'default-image' => 'bar' ) ); 183 $this->assertEquals( 'foo', get_theme_support( 'custom-header', 'default-image' ) ); 184 185 // This, however, should override whatever has been set. 186 remove_theme_support( 'custom-header' ); 187 add_theme_support( 'custom-header', array( 'default-image' => 'baz' ) ); 188 $this->assertEquals( 'baz', get_theme_support( 'custom-header', 'default-image' ) ); 189 190 // Second call to add_theme_support should merge the arguments with the first. 191 remove_theme_support( 'custom-header' ); 192 add_theme_support( 'custom-header', array( 'width' => 123 ) ); 193 add_theme_support( 'custom-header', array( 'height' => 456 ) ); 194 $this->assertEquals( 123, get_theme_support( 'custom-header', 'width' ) ); 195 $this->assertEquals( 456, get_theme_support( 'custom-header', 'height' ) ); 196 197 // Second call to add_theme_support should not override arguments set in the first. 198 remove_theme_support( 'custom-header' ); 199 add_theme_support( 'custom-header', array( 'width' => 123 ) ); 200 add_theme_support( 'custom-header', array( 'width' => 789, 'height' => 456 ) ); 201 $this->assertEquals( 123, get_theme_support( 'custom-header', 'width' ) ); 202 $this->assertEquals( 456, get_theme_support( 'custom-header', 'height' ) ); 203 } 159 204 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)