Ticket #20249: 20249.diff
File 20249.diff, 18.9 KB (added by , 13 years ago) |
---|
-
wp-includes/theme.php
897 897 * Retrieve text color for custom header. 898 898 * 899 899 * @since 2.1.0 900 * @uses HEADER_TEXTCOLOR901 900 * 902 901 * @return string 903 902 */ 904 903 function get_header_textcolor() { 905 $default = defined('HEADER_TEXTCOLOR') ? HEADER_TEXTCOLOR : ''; 906 907 return get_theme_mod('header_textcolor', $default); 904 return get_theme_mod('header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); 908 905 } 909 906 910 907 /** … … 920 917 * Retrieve header image for custom header. 921 918 * 922 919 * @since 2.1.0 923 * @uses HEADER_IMAGE924 920 * 925 921 * @return string 926 922 */ 927 923 function get_header_image() { 928 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 929 $url = get_theme_mod( 'header_image', $default ); 924 $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); 930 925 931 926 if ( 'remove-header' == $url ) 932 927 return false; … … 966 961 if ( 'random-default-image' == $header_image_mod ) { 967 962 $headers = $_wp_default_headers; 968 963 } else { 969 $is_random = get_theme_support( 'custom-header' ); 970 if ( isset( $is_random[ 0 ] ) && !empty( $is_random[ 0 ][ 'random-default' ] ) ) 964 if ( current_theme_supports( 'custom-header', 'random-default' ) ) 971 965 $headers = $_wp_default_headers; 972 966 } 973 967 } … … 1006 1000 * is chosen, and theme turns on random headers with add_theme_support(). 1007 1001 * 1008 1002 * @since 3.2.0 1009 * @uses HEADER_IMAGE1010 1003 * 1011 1004 * @param string $type The random pool to use. any|default|uploaded 1012 1005 * @return boolean 1013 1006 */ 1014 1007 function is_random_header_image( $type = 'any' ) { 1015 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 1016 $header_image_mod = get_theme_mod( 'header_image', $default ); 1008 $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); 1017 1009 1018 1010 if ( 'any' == $type ) { 1019 1011 if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) … … 1075 1067 * 1076 1068 * @return object 1077 1069 */ 1078 function get_cu rrent_header_data() {1070 function get_custom_header() { 1079 1071 $data = is_random_header_image()? _get_random_header_data() : get_theme_mod( 'header_image_data' ); 1080 1072 $default = array( 1081 1073 'url' => '', 1082 1074 'thumbnail_url' => '', 1083 'width' => '',1084 'height' => '',1075 'width' => get_theme_suppport( 'custom-header', 'width' ), 1076 'height' => get_theme_suppport( 'custom-header', 'height' ), 1085 1077 ); 1086 1078 return (object) wp_parse_args( $data, $default ); 1087 1079 } 1088 1080 1089 1081 /** 1090 * Get the header image width.1091 *1092 * @since 3.4.01093 *1094 * @return int1095 */1096 function get_header_image_width() {1097 return empty( get_current_header_data()->width )? HEADER_IMAGE_WIDTH : get_current_header_data()->width;1098 }1099 1100 /**1101 * Get the header image height.1102 *1103 * @since 3.4.01104 *1105 * @return int1106 */1107 function get_header_image_height() {1108 return empty( get_current_header_data()->height )? HEADER_IMAGE_HEIGHT : get_current_header_data()->height;1109 }1110 1111 /**1112 1082 * Add callbacks for image header display. 1113 1083 * 1114 * The parameter $header_callback callback will be required to display the1115 * content for the 'wp_head' action. The parameter $admin_header_callback1116 * callback will be added to Custom_Image_Header class and that will be added1117 * to the 'admin_menu' action.1118 *1119 1084 * @since 2.1.0 1120 * @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display. 1085 * @deprecated 3.4.0 1086 * @deprecated Use add_theme_support('custom-header', $args) 1087 * @see add_theme_support() 1121 1088 * 1122 1089 * @param callback $header_callback Call on 'wp_head' action. 1123 1090 * @param callback $admin_header_callback Call on custom header administration screen. 1124 1091 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional. 1125 1092 */ 1126 1093 function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '' ) { 1127 if ( ! empty( $header_callback ) ) 1128 add_action('wp_head', $header_callback); 1129 1130 $support = array( 'callback' => $header_callback ); 1131 $theme_support = get_theme_support( 'custom-header' ); 1132 if ( ! empty( $theme_support ) && is_array( $theme_support[ 0 ] ) ) 1133 $support = array_merge( $theme_support[ 0 ], $support ); 1134 add_theme_support( 'custom-header', $support ); 1135 add_theme_support( 'custom-header-uploads' ); 1136 1137 if ( ! is_admin() ) 1138 return; 1139 1140 global $custom_image_header; 1141 1142 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 1143 $custom_image_header = new Custom_Image_Header( $admin_header_callback, $admin_image_div_callback ); 1144 add_action( 'admin_menu', array( &$custom_image_header, 'init' ) ); 1094 _deprecated_function( __FUNCTION__, '3.4', 'add_theme_support(\'custom-header\', $args)' ); 1095 return add_theme_support( 'custom-header', array( 1096 'callback' => $header_callback, 1097 'admin-header-callback' => $admin_header_callback, 1098 'admin-image-div-callback' => $admin_image_div_callback, 1099 ) ); 1145 1100 } 1146 1101 1147 1102 /** 1148 1103 * Remove image header support. 1149 1104 * 1150 1105 * @since 3.1.0 1151 * @see add_custom_image_header() 1106 * @deprecated 3.4.0 1107 * @deprecated Use remove_theme_support('custom-header') 1108 * @see remove_theme_support() 1152 1109 * 1153 1110 * @return bool Whether support was removed. 1154 1111 */ 1155 1112 function remove_custom_image_header() { 1156 if ( ! current_theme_supports( 'custom-header' ) ) 1157 return false; 1158 1159 $callback = get_theme_support( 'custom-header' ); 1160 remove_action( 'wp_head', $callback[0]['callback'] ); 1161 _remove_theme_support( 'custom-header' ); 1162 remove_theme_support( 'custom-header-uploads' ); 1163 1164 if ( is_admin() ) { 1165 remove_action( 'admin_menu', array( &$GLOBALS['custom_image_header'], 'init' ) ); 1166 unset( $GLOBALS['custom_image_header'] ); 1167 } 1168 1169 return true; 1113 _deprecated_function( __FUNCTION__, '3.4', 'remove_theme_support(\'custom-header\')' ); 1114 return remove_theme_support( 'custom-header' ); 1170 1115 } 1171 1116 1172 1117 /** … … 1214 1159 * @return string 1215 1160 */ 1216 1161 function get_background_image() { 1217 $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : ''; 1218 1219 return get_theme_mod('background_image', $default); 1162 return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) ); 1220 1163 } 1221 1164 1222 1165 /** … … 1232 1175 * Retrieve value for custom background color. 1233 1176 * 1234 1177 * @since 3.0.0 1235 * @uses BACKGROUND_COLOR1236 1178 * 1237 1179 * @return string 1238 1180 */ 1239 1181 function get_background_color() { 1240 $default = defined('BACKGROUND_COLOR') ? BACKGROUND_COLOR : ''; 1241 1242 return get_theme_mod('background_color', $default); 1182 return get_theme_mod('background_color', get_theme_support( 'custom-background', 'default-color' ) ); 1243 1183 } 1244 1184 1245 1185 /** … … 1267 1207 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional. 1268 1208 */ 1269 1209 function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) { 1270 if ( isset( $GLOBALS['custom_background'] ) ) 1271 return; 1272 1273 if ( empty( $header_callback ) ) 1274 $header_callback = '_custom_background_cb'; 1275 1276 add_action( 'wp_head', $header_callback ); 1277 1278 add_theme_support( 'custom-background', array( 'callback' => $header_callback ) ); 1279 1280 if ( ! is_admin() ) 1281 return; 1282 require_once( ABSPATH . 'wp-admin/custom-background.php' ); 1283 $GLOBALS['custom_background'] = new Custom_Background( $admin_header_callback, $admin_image_div_callback ); 1284 add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) ); 1210 return add_theme_support( 'custom-background', array( 1211 'callback' => $header_callback, 1212 'admin-header-callback' => $admin_header_callback, 1213 'admin-image-div-callback' => $admin_image_div_callback, 1214 ) ); 1285 1215 } 1286 1216 1287 1217 /** … … 1293 1223 * @return bool Whether support was removed. 1294 1224 */ 1295 1225 function remove_custom_background() { 1296 if ( ! current_theme_supports( 'custom-background' ) ) 1297 return false; 1298 1299 $callback = get_theme_support( 'custom-background' ); 1300 remove_action( 'wp_head', $callback[0]['callback'] ); 1301 _remove_theme_support( 'custom-background' ); 1302 1303 if ( is_admin() ) { 1304 remove_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) ); 1305 unset( $GLOBALS['custom_background'] ); 1306 } 1307 1308 return true; 1226 _deprecated_function( __FUNCTION__, '3.4', 'remove_theme_support(\'custom-background\')' ); 1227 return remove_theme_support( 'custom-background' ); 1309 1228 } 1310 1229 1311 1230 /** … … 1418 1337 global $_wp_theme_features; 1419 1338 1420 1339 if ( func_num_args() == 1 ) 1421 $ _wp_theme_features[$feature]= true;1340 $args = true; 1422 1341 else 1423 $ _wp_theme_features[$feature]= array_slice( func_get_args(), 1 );1342 $args = array_slice( func_get_args(), 1 ); 1424 1343 1425 if ( $feature == 'post-formats' && is_array( $_wp_theme_features[$feature][0] ) ) 1426 $_wp_theme_features[$feature][0] = array_intersect( $_wp_theme_features[$feature][0], array_keys( get_post_format_slugs() ) ); 1344 switch ( $feature ) { 1345 case 'post-formats' : 1346 if ( is_array( $args[0] ) ) 1347 $args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) ); 1348 break; 1349 1350 case 'custom-header-uploads' : 1351 return add_theme_support( 'custom-header', array( 'uploads' => true ) ); 1352 break; 1353 1354 case 'custom-header' : 1355 $defaults = array( 1356 'default-image' => '', 1357 'random-default' => false, 1358 'width' => 0, 1359 'height' => 0, 1360 'suggested-width' => 0, 1361 'suggested-height' => 0, 1362 'flex-height' => false, 1363 'flex-width' => false, 1364 'default-text-color' => '', 1365 'header-text' => true, 1366 'uploads' => true, 1367 'callback' => '', 1368 'admin-header-callback' => '', 1369 'admin-image-div-callback' => '', 1370 ); 1371 1372 // Merge in data from previous add_theme_support() calls. 1373 if ( isset( $_wp_theme_features['custom-header'] ) ) 1374 $defaults = wp_parse_args( $_wp_theme_features['custom-header'][0], $defaults ); 1375 1376 $_args = $args[0]; 1377 $args[0] = wp_parse_args( $args[0], $defaults ); 1378 unset( $args[0]['__jit'] ); 1379 1380 if ( defined( 'NO_HEADER_TEXT' ) ) 1381 $args[0]['header-text'] = ! NO_HEADER_TEXT; 1382 elseif ( ! empty( $args[0]['header-text'] ) || isset( $_args['__jit'] ) ) 1383 define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); 1384 1385 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) 1386 $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; 1387 elseif ( ! empty( $args[0]['width'] ) || isset( $_args['__jit'] ) ) 1388 define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); 1389 1390 if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) 1391 $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; 1392 elseif ( ! empty( $args[0]['height'] ) || isset( $_args['__jit'] ) ) 1393 define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); 1394 1395 if ( defined( 'HEADER_TEXTCOLOR' ) ) 1396 $args[0]['default-text-color'] = HEADER_TEXTCOLOR; 1397 elseif ( $args[0]['default-text-color'] || isset( $_args['__jit'] ) ) 1398 define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); 1399 1400 if ( defined( 'HEADER_IMAGE' ) ) 1401 $args[0]['default-image'] = HEADER_IMAGE; 1402 1403 if ( ! empty( $args[0]['default-image'] ) ) 1404 $args[0]['random-default'] = false; 1405 1406 if ( ! defined( 'HEADER_IMAGE' ) 1407 && ( isset( $_args['default-image'] ) || isset( $_args['random-default'] ) || isset( $_args['__jit'] ) ) ) 1408 define( 'HEADER_IMAGE', $args[0]['default-image'] ); 1409 1410 if ( ! empty( $args[0]['width'] ) ) 1411 $args[0]['flex-width'] = $args[0]['suggested-width'] = $args[0]['max-width'] = false; 1412 1413 if ( ! empty( $args[0]['height'] ) ) 1414 $args[0]['flex-height'] = $args[0]['suggested-height'] = false; 1415 1416 break; 1417 1418 case 'custom-background' : 1419 $defaults = array( 1420 'default-image' => '', 1421 'default-color' => '', 1422 'callback' => '', 1423 'admin-header-callback' => '', 1424 'admin-image-div-callback' => '', 1425 ); 1426 if ( isset( $_wp_theme_features['custom-background'] ) ) 1427 $defaults = wp_parse_args( $_wp_theme_features['custom-background'][0], $defaults ); 1428 1429 $_args = $args[0]; 1430 $args[0] = wp_parse_args( $args[0], $defaults ); 1431 1432 if ( defined( 'BACKGROUND_COLOR' ) ) 1433 $args[0]['default-color'] = BACKGROUND_COLOR; 1434 elseif ( $args[0]['default-color'] || isset( $_args['__jit'] ) ) 1435 define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); 1436 1437 if ( defined( 'BACKGROUND_IMAGE' ) ) 1438 $args[0]['default-image'] = BACKGROUND_HEADER; 1439 elseif ( $args[0]['default-image'] || isset( $_args['__jit'] ) ) 1440 define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); 1441 1442 if ( empty( $args[0]['callback'] ) ) 1443 $args[0]['callback'] = '_custom_background_cb'; 1444 1445 break; 1446 } 1447 1448 $_wp_theme_features[ $feature ] = $args; 1427 1449 } 1428 1450 1429 1451 /** 1452 * Registers the internal custom header and background routines. 1453 * 1454 * @since 3.4.0 1455 * @access private 1456 */ 1457 function _custom_header_background_just_in_time() { 1458 global $custom_image_header, $custom_background; 1459 1460 if ( current_theme_supports( 'custom-header' ) ) { 1461 // In case any constants were defined after an add_custom_image_header() call, re-run. 1462 add_theme_support( 'custom-header', array( '__jit' => true ) ); 1463 1464 $args = get_theme_support( 'custom-header' ); 1465 if ( $args[0]['callback'] ) 1466 add_action( 'wp_head', $args[0]['callback'] ); 1467 1468 if ( is_admin() ) { 1469 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 1470 $custom_image_header = new Custom_Image_Header( $args[0]['admin-header-callback'], $args[0]['admin-image-div-callback'] ); 1471 } 1472 } 1473 1474 if ( current_theme_supports( 'custom-background' ) ) { 1475 // In case any constants were defined after an add_custom_background() call, re-run. 1476 add_theme_support( 'custom-background', array( '__jit' => true ) ); 1477 1478 $args = get_theme_support( 'custom-background' ); 1479 add_action( 'wp_head', $args[0]['callback'] ); 1480 1481 if ( is_admin() ) { 1482 require_once( ABSPATH . 'wp-admin/custom-background.php' ); 1483 $custom_background = new Custom_Background( $args[0]['admin-header-callback'], $args[0]['admin-image-div-callback'] ); 1484 } 1485 } 1486 } 1487 add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); 1488 1489 /** 1430 1490 * Gets the theme support arguments passed when registering that support 1431 1491 * 1432 1492 * @since 3.1 … … 1435 1495 */ 1436 1496 function get_theme_support( $feature ) { 1437 1497 global $_wp_theme_features; 1438 if ( ! isset( $_wp_theme_features[$feature] ) )1498 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 1439 1499 return false; 1440 else 1441 return $_wp_theme_features[$feature]; 1500 1501 if ( func_num_args() <= 1 ) 1502 return $_wp_theme_features[ $feature ]; 1503 1504 $args = array_slice( func_get_args(), 1 ); 1505 switch ( $feature ) { 1506 case 'custom-header' : 1507 case 'custom-background' : 1508 if ( isset( $_wp_theme_features[ $feature ][ $args[0] ] ) ) 1509 return $_wp_theme_features[ $feature ][ $args[0] ]; 1510 return false; 1511 break; 1512 default : 1513 return $_wp_theme_features[ $feature ]; 1514 break; 1515 } 1442 1516 } 1443 1517 1444 1518 /** … … 1454 1528 */ 1455 1529 function remove_theme_support( $feature ) { 1456 1530 // Blacklist: for internal registrations not used directly by themes. 1457 if ( in_array( $feature, array( ' custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) )1531 if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) 1458 1532 return false; 1533 1459 1534 return _remove_theme_support( $feature ); 1460 1535 } 1461 1536 … … 1468 1543 function _remove_theme_support( $feature ) { 1469 1544 global $_wp_theme_features; 1470 1545 1471 if ( ! isset( $_wp_theme_features[$feature] ) ) 1546 switch ( $feature ) { 1547 case 'custom-header-uploads' : 1548 if ( ! isset( $_wp_theme_features['custom-header'] ) ) 1549 return false; 1550 add_theme_support( 'custom-header', array( 'uploads' => false ) ); 1551 return; // Do not continue - custom-header-uploads no longer exists. 1552 } 1553 1554 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 1472 1555 return false; 1473 unset( $_wp_theme_features[$feature] ); 1556 1557 switch ( $feature ) { 1558 case 'custom-header' : 1559 $support = get_theme_support( 'custom-header' ); 1560 if ( $support[0]['callback'] ) 1561 remove_action( 'wp_head', $support[0]['callback'] ); 1562 unset( $GLOBALS['custom_image_header'] ); 1563 break; 1564 1565 case 'custom-header' : 1566 $support = get_theme_support( 'custom-background' ); 1567 remove_action( 'wp_head', $support[0]['callback'] ); 1568 unset( $GLOBALS['custom_background'] ); 1569 break; 1570 } 1571 1572 unset( $_wp_theme_features[ $feature ] ); 1474 1573 return true; 1475 1574 } 1476 1575 … … 1484 1583 function current_theme_supports( $feature ) { 1485 1584 global $_wp_theme_features; 1486 1585 1586 if ( 'custom-header-uploads' == $feature ) 1587 return current_theme_supports( 'custom-header', 'uploads' ); 1588 1487 1589 if ( !isset( $_wp_theme_features[$feature] ) ) 1488 1590 return false; 1489 1591 -
wp-admin/custom-header.php
71 71 function __construct($admin_header_callback, $admin_image_div_callback = '') { 72 72 $this->admin_header_callback = $admin_header_callback; 73 73 $this->admin_image_div_callback = $admin_image_div_callback; 74 75 add_action( 'admin_menu', array( $this, 'init' ) ); 74 76 } 75 77 76 78 /** 79 * Destructor - Remove admin menu hook when theme support is removed. 80 */ 81 function __destruct() { 82 remove_action( 'admin_menu', array( $this, 'init' ) ); 83 } 84 85 /** 77 86 * Set up the hooks for the Custom Header admin page. 78 87 * 79 88 * @since 2.1.0 … … 531 540 532 541 <tr valign="top"> 533 542 <th scope="row"><?php _e( 'Preview' ); ?></th> 534 <td 543 <td> 535 544 <?php if ( $this->admin_image_div_callback ) { 536 545 call_user_func( $this->admin_image_div_callback ); 537 546 } else { … … 791 800 * @since 2.1.0 792 801 */ 793 802 function step_3() { 794 check_admin_referer('custom-header-crop-image'); 795 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 803 check_admin_referer( 'custom-header-crop-image' ); 804 805 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) 796 806 wp_die( __( 'Cheatin’ uh?' ) ); 797 807 798 808 if ( $_POST['oitar'] > 1 ) { … … 894 904 if ( ! current_user_can('edit_theme_options') ) 895 905 wp_die(__('You do not have permission to customize headers.')); 896 906 $step = $this->step(); 897 if ( 1 == $step )907 if ( 1 == $step || ! $_POST ) 898 908 $this->step_1(); 899 909 elseif ( 2 == $step ) 900 910 $this->step_2(); -
wp-admin/custom-background.php
53 53 function __construct($admin_header_callback = '', $admin_image_div_callback = '') { 54 54 $this->admin_header_callback = $admin_header_callback; 55 55 $this->admin_image_div_callback = $admin_image_div_callback; 56 57 add_action( 'admin_menu', array( $this, 'init' ) ); 56 58 } 57 59 58 60 /** 61 * Destructor - Remove admin menu hook when theme support is removed. 62 */ 63 function __destruct() { 64 remove_action( 'admin_menu', array( $this, 'init' ) ); 65 } 66 67 /** 59 68 * Set up the hooks for the Custom Background admin page. 60 69 * 61 70 * @since 3.0.0 … … 226 235 </tr> 227 236 <?php endif; ?> 228 237 229 <?php if ( defined( 'BACKGROUND_IMAGE' ) ) : // Show only if a default background image exists?>238 <?php if ( get_theme_support( 'custom-background', 'default-image' ) ) : ?> 230 239 <tr valign="top"> 231 240 <th scope="row"><?php _e('Restore Original Image'); ?></th> 232 241 <td>