Ticket #20249: 20249.2.diff
File 20249.2.diff, 35.7 KB (added by , 13 years ago) |
---|
-
wp-includes/class-wp-customize.php
479 479 'section' => 'header', 480 480 'sanitize_callback' => 'sanitize_hexcolor', 481 481 'control' => 'color', 482 'default' => defined( 'HEADER_TEXTCOLOR' ) ? HEADER_TEXTCOLOR : ''482 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 483 483 ) ); 484 484 485 485 /* … … 505 505 'control' => 'checkbox', 506 506 // @todo 507 507 // not the default, it's the value. 508 // value is saved in get_theme_support( 'custom-header' )[0][ 'random-default' ]508 // value is saved in get_theme_support( 'custom-header', 'random-default' ) 509 509 'default' => 'random-default-image' 510 510 ) ); 511 511 … … 522 522 'label' => 'Background Color', 523 523 'section' => 'background', 524 524 'control' => 'color', 525 'default' => defined( 'BACKGROUND_COLOR' ) ? BACKGROUND_COLOR : '',525 'default' => get_theme_support( 'custom-background', 'default-color' ), 526 526 'sanitize_callback' => 'sanitize_hexcolor', 527 527 ) ); 528 528 -
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 # _deprecated_function( __FUNCTION__, '3.4', 'add_theme_support(\'custom-background\', $args)' ); 1211 return add_theme_support( 'custom-background', array( 1212 'callback' => $header_callback, 1213 'admin-header-callback' => $admin_header_callback, 1214 'admin-image-div-callback' => $admin_image_div_callback, 1215 ) ); 1285 1216 } 1286 1217 1287 1218 /** … … 1293 1224 * @return bool Whether support was removed. 1294 1225 */ 1295 1226 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; 1227 # _deprecated_function( __FUNCTION__, '3.4', 'remove_theme_support(\'custom-background\')' ); 1228 return remove_theme_support( 'custom-background' ); 1309 1229 } 1310 1230 1311 1231 /** 1312 1232 * Default custom background callback. 1313 1233 * 1314 1234 * @since 3.0.0 1315 * @see add_custom_background()1316 1235 * @access protected 1317 1236 */ 1318 1237 function _custom_background_cb() { … … 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 a constant was defined, use that value. Otherwise, define the constant. 1381 // For values based on constants, the first value wins. (A child theme is set up first.) 1382 // Once we get to wp_loaded (just-in-time), define any constants we haven't already. 1383 // Constants are lame. Don't reference them. This is just for backwards compatibility. 1384 1385 if ( defined( 'NO_HEADER_TEXT' ) ) 1386 $args[0]['header-text'] = ! NO_HEADER_TEXT; 1387 elseif ( ! empty( $args[0]['header-text'] ) || isset( $_args['__jit'] ) ) 1388 define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); 1389 1390 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) 1391 $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; 1392 elseif ( ! empty( $args[0]['width'] ) || isset( $_args['__jit'] ) ) 1393 define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); 1394 1395 if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) 1396 $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; 1397 elseif ( ! empty( $args[0]['height'] ) || isset( $_args['__jit'] ) ) 1398 define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); 1399 1400 if ( defined( 'HEADER_TEXTCOLOR' ) ) 1401 $args[0]['default-text-color'] = HEADER_TEXTCOLOR; 1402 elseif ( $args[0]['default-text-color'] || isset( $_args['__jit'] ) ) 1403 define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); 1404 1405 if ( defined( 'HEADER_IMAGE' ) ) 1406 $args[0]['default-image'] = HEADER_IMAGE; 1407 1408 if ( ! empty( $args[0]['default-image'] ) ) 1409 $args[0]['random-default'] = false; 1410 1411 if ( ! defined( 'HEADER_IMAGE' ) 1412 && ( isset( $_args['default-image'] ) || isset( $_args['random-default'] ) || isset( $_args['__jit'] ) ) ) 1413 define( 'HEADER_IMAGE', $args[0]['default-image'] ); 1414 1415 if ( ! empty( $args[0]['width'] ) ) 1416 $args[0]['flex-width'] = $args[0]['suggested-width'] = $args[0]['max-width'] = false; 1417 1418 if ( ! empty( $args[0]['height'] ) ) 1419 $args[0]['flex-height'] = $args[0]['suggested-height'] = false; 1420 1421 break; 1422 1423 case 'custom-background' : 1424 $defaults = array( 1425 'default-image' => '', 1426 'default-color' => '', 1427 'callback' => '', 1428 'admin-header-callback' => '', 1429 'admin-image-div-callback' => '', 1430 ); 1431 if ( isset( $_wp_theme_features['custom-background'] ) ) 1432 $defaults = wp_parse_args( $_wp_theme_features['custom-background'][0], $defaults ); 1433 1434 $_args = $args[0]; 1435 $args[0] = wp_parse_args( $args[0], $defaults ); 1436 1437 if ( defined( 'BACKGROUND_COLOR' ) ) 1438 $args[0]['default-color'] = BACKGROUND_COLOR; 1439 elseif ( $args[0]['default-color'] || isset( $_args['__jit'] ) ) 1440 define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); 1441 1442 if ( defined( 'BACKGROUND_IMAGE' ) ) 1443 $args[0]['default-image'] = BACKGROUND_HEADER; 1444 elseif ( $args[0]['default-image'] || isset( $_args['__jit'] ) ) 1445 define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); 1446 1447 if ( empty( $args[0]['callback'] ) ) 1448 $args[0]['callback'] = '_custom_background_cb'; 1449 1450 break; 1451 } 1452 1453 $_wp_theme_features[ $feature ] = $args; 1427 1454 } 1428 1455 1429 1456 /** 1457 * Registers the internal custom header and background routines. 1458 * 1459 * @since 3.4.0 1460 * @access private 1461 */ 1462 function _custom_header_background_just_in_time() { 1463 global $custom_image_header, $custom_background; 1464 1465 if ( current_theme_supports( 'custom-header' ) ) { 1466 // In case any constants were defined after an add_custom_image_header() call, re-run. 1467 add_theme_support( 'custom-header', array( '__jit' => true ) ); 1468 1469 $args = get_theme_support( 'custom-header' ); 1470 if ( $args[0]['callback'] ) 1471 add_action( 'wp_head', $args[0]['callback'] ); 1472 1473 if ( is_admin() ) { 1474 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 1475 $custom_image_header = new Custom_Image_Header( $args[0]['admin-header-callback'], $args[0]['admin-image-div-callback'] ); 1476 } 1477 } 1478 1479 if ( current_theme_supports( 'custom-background' ) ) { 1480 // In case any constants were defined after an add_custom_background() call, re-run. 1481 add_theme_support( 'custom-background', array( '__jit' => true ) ); 1482 1483 $args = get_theme_support( 'custom-background' ); 1484 add_action( 'wp_head', $args[0]['callback'] ); 1485 1486 if ( is_admin() ) { 1487 require_once( ABSPATH . 'wp-admin/custom-background.php' ); 1488 $custom_background = new Custom_Background( $args[0]['admin-header-callback'], $args[0]['admin-image-div-callback'] ); 1489 } 1490 } 1491 } 1492 add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); 1493 1494 /** 1430 1495 * Gets the theme support arguments passed when registering that support 1431 1496 * 1432 1497 * @since 3.1 … … 1435 1500 */ 1436 1501 function get_theme_support( $feature ) { 1437 1502 global $_wp_theme_features; 1438 if ( ! isset( $_wp_theme_features[$feature] ) )1503 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 1439 1504 return false; 1440 else 1441 return $_wp_theme_features[$feature]; 1505 1506 if ( func_num_args() <= 1 ) 1507 return $_wp_theme_features[ $feature ]; 1508 1509 $args = array_slice( func_get_args(), 1 ); 1510 switch ( $feature ) { 1511 case 'custom-header' : 1512 case 'custom-background' : 1513 if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) 1514 return $_wp_theme_features[ $feature ][0][ $args[0] ]; 1515 return false; 1516 break; 1517 default : 1518 return $_wp_theme_features[ $feature ]; 1519 break; 1520 } 1442 1521 } 1443 1522 1444 1523 /** … … 1454 1533 */ 1455 1534 function remove_theme_support( $feature ) { 1456 1535 // Blacklist: for internal registrations not used directly by themes. 1457 if ( in_array( $feature, array( ' custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) )1536 if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) 1458 1537 return false; 1538 1459 1539 return _remove_theme_support( $feature ); 1460 1540 } 1461 1541 … … 1468 1548 function _remove_theme_support( $feature ) { 1469 1549 global $_wp_theme_features; 1470 1550 1471 if ( ! isset( $_wp_theme_features[$feature] ) ) 1551 switch ( $feature ) { 1552 case 'custom-header-uploads' : 1553 if ( ! isset( $_wp_theme_features['custom-header'] ) ) 1554 return false; 1555 add_theme_support( 'custom-header', array( 'uploads' => false ) ); 1556 return; // Do not continue - custom-header-uploads no longer exists. 1557 } 1558 1559 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 1472 1560 return false; 1473 unset( $_wp_theme_features[$feature] ); 1561 1562 switch ( $feature ) { 1563 case 'custom-header' : 1564 $support = get_theme_support( 'custom-header' ); 1565 if ( $support[0]['callback'] ) 1566 remove_action( 'wp_head', $support[0]['callback'] ); 1567 unset( $GLOBALS['custom_image_header'] ); 1568 break; 1569 1570 case 'custom-header' : 1571 $support = get_theme_support( 'custom-background' ); 1572 remove_action( 'wp_head', $support[0]['callback'] ); 1573 unset( $GLOBALS['custom_background'] ); 1574 break; 1575 } 1576 1577 unset( $_wp_theme_features[ $feature ] ); 1474 1578 return true; 1475 1579 } 1476 1580 … … 1484 1588 function current_theme_supports( $feature ) { 1485 1589 global $_wp_theme_features; 1486 1590 1591 if ( 'custom-header-uploads' == $feature ) 1592 return current_theme_supports( 'custom-header', 'uploads' ); 1593 1487 1594 if ( !isset( $_wp_theme_features[$feature] ) ) 1488 1595 return false; 1489 1596 -
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 … … 140 149 function js_includes() { 141 150 $step = $this->step(); 142 151 143 if ( ( 1 == $step || 3 == $step ) && $this->header_text() )152 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 144 153 wp_enqueue_script('farbtastic'); 145 154 elseif ( 2 == $step ) 146 155 wp_enqueue_script('imgareaselect'); … … 154 163 function css_includes() { 155 164 $step = $this->step(); 156 165 157 if ( ( 1 == $step || 3 == $step ) && $this->header_text() )166 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 158 167 wp_enqueue_style('farbtastic'); 159 168 elseif ( 2 == $step ) 160 169 wp_enqueue_style('imgareaselect'); 161 170 } 162 171 163 172 /** 164 * Check if header text is allowed165 *166 * @since 3.0.0167 */168 function header_text() {169 if ( defined( 'NO_HEADER_TEXT' ) && NO_HEADER_TEXT )170 return false;171 172 return true;173 }174 175 /**176 173 * Execute custom header modification. 177 174 * 178 175 * @since 2.6.0 … … 189 186 if ( isset( $_POST['resetheader'] ) ) { 190 187 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 191 188 $this->process_default_headers(); 192 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';189 $default = get_theme_support( 'custom-header', 'default-image' ); 193 190 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 194 191 foreach ( $this->default_headers as $header => $details ) { 195 192 if ( $details['url'] == $default ) { … … 199 196 } 200 197 set_theme_mod( 'header_image', $default ); 201 198 if ( empty( $default_data['width'] ) ) 202 $default_data['width'] = HEADER_IMAGE_WIDTH;199 $default_data['width'] = get_theme_support( 'custom-header', 'width' ); 203 200 if ( empty( $default_data['height'] ) ) 204 $default_data['height'] = HEADER_IMAGE_HEIGHT;201 $default_data['height'] = get_theme_support( 'custom-header', 'height' ); 205 202 set_theme_mod( 'header_image_data', (object) $default_data ); 206 203 return; 207 204 } … … 245 242 } elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) { 246 243 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 247 244 if ( empty( $this->default_headers[$_POST['default-header']]['width'] ) ) 248 $this->default_headers[$_POST['default-header']]['width'] = HEADER_IMAGE_WIDTH;245 $this->default_headers[$_POST['default-header']]['width'] = get_theme_support( 'custom-header', 'width' ); 249 246 if ( empty( $this->default_headers[$_POST['default-header']]['height'] ) ) 250 $this->default_headers[$_POST['default-header']]['height'] = HEADER_IMAGE_HEIGHT;247 $this->default_headers[$_POST['default-header']]['height'] = get_theme_support( 'custom-header', 'height' ); 251 248 set_theme_mod( 'header_image_data', (object) $this->default_headers[$_POST['default-header']] ); 252 249 } 253 250 } … … 325 322 */ 326 323 function js() { 327 324 $step = $this->step(); 328 if ( ( 1 == $step || 3 == $step ) && $this->header_text() )325 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 329 326 $this->js_1(); 330 327 elseif ( 2 == $step ) 331 328 $this->js_2(); … … 341 338 /* <![CDATA[ */ 342 339 var text_objects = ['#name', '#desc', '#text-color-row']; 343 340 var farbtastic; 344 var default_color = '#<?php echo HEADER_TEXTCOLOR; ?>';341 var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>'; 345 342 var old_color = null; 346 343 347 344 function pickColor(color) { … … 411 408 }); 412 409 413 410 farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); }); 414 <?php if ( $color = get_ theme_mod('header_textcolor', HEADER_TEXTCOLOR) ) { ?>411 <?php if ( $color = get_header_textcolor() ) { ?> 415 412 pickColor('#<?php echo $color; ?>'); 416 413 <?php } ?> 417 414 418 <?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) { ?>415 <?php if ( 'blank' == $color || '' == $color || ! current_theme_supports( 'custom-header', 'header-text' ) ) { ?> 419 416 toggle_text(); 420 417 <?php } ?> 421 418 }); … … 441 438 442 439 jQuery(document).ready(function() { 443 440 <?php 444 $xinit = HEADER_IMAGE_WIDTH; 445 $yinit = HEADER_IMAGE_HEIGHT; 446 $header_support = get_theme_support( 'custom-header' ); 447 if ( !empty( $header_support[ 0 ][ 'suggested-width' ] ) ) 448 $xinit = $header_support[ 0 ][ 'suggested-width' ]; 449 if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) ) 450 $yinit = $header_support[ 0 ][ 'suggested-height' ]; 441 if ( ! $xinit = get_theme_support( 'custom-header', 'suggested-width' ) ) 442 $xinit = get_theme_support( 'custom-header', 'width' ); 443 if ( ! $yinit = get_theme_support( 'custom-header', 'suggested-height' ) ) 444 $yinit = get_theme_support( 'custom-header', 'height' ); 451 445 ?> 452 446 var xinit = <?php echo absint( $xinit ); ?>; 453 447 var yinit = <?php echo absint( $yinit ); ?>; … … 481 475 } 482 476 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { 483 477 ?> 484 maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,478 maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>, 485 479 <?php 486 480 } 487 481 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { 488 482 ?> 489 maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,483 maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>, 490 484 <?php 491 485 } 492 486 ?> … … 531 525 532 526 <tr valign="top"> 533 527 <th scope="row"><?php _e( 'Preview' ); ?></th> 534 <td 528 <td> 535 529 <?php if ( $this->admin_image_div_callback ) { 536 530 call_user_func( $this->admin_image_div_callback ); 537 531 } else { 538 532 ?> 539 <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_ header_image_width(); ?>px;height:<?php echo get_header_image_height(); ?>px;">533 <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_custom_header()->width; ?>px;height:<?php echo get_custom_header()->height; ?>px;"> 540 534 <?php 541 if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) 535 $color = get_header_textcolor(); 536 if ( 'blank' == $color || '' == $color || ! current_theme_supports( 'custom-header', 'header-text' ) ) 542 537 $style = ' style="display:none;"'; 543 538 else 544 $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ). ';"';539 $style = ' style="color:#' . $color . ';"'; 545 540 ?> 546 541 <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1> 547 542 <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> … … 556 551 <p><?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br /> 557 552 <?php 558 553 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) { 559 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);554 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) ); 560 555 } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { 561 556 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) 562 printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ) . '<br />', HEADER_IMAGE_WIDTH);557 printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ) . '<br />', get_theme_support( 'custom-header', 'width' ) ); 563 558 } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { 564 559 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) 565 printf( __( 'Images should be at least <strong>%1$d pixels</strong> tall.' ) . '<br />', HEADER_IMAGE_HEIGHT);560 printf( __( 'Images should be at least <strong>%1$d pixels</strong> tall.' ) . '<br />', get_theme_support( 'custom-header', 'height' ) ); 566 561 } 567 562 if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) { 568 $header_support = get_theme_support( 'custom-header' ); 569 if ( !empty( $header_support[ 0 ][ 'suggested-width' ] ) ) 570 printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . '<br />', absint( $header_support[ 0 ][ 'suggested-width' ] ) ); 571 if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) ) 572 printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . '<br />', absint( $header_support[ 0 ][ 'suggested-height' ] ) ); 563 if ( current_theme_supports( 'custom-header', 'suggested-width' ) ) 564 printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . '<br />', get_theme_support( 'custom-header', 'suggested-width' ) ); 565 if ( current_theme_supports( 'custom-header', 'suggested-height' ) ) 566 printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . '<br />', get_theme_support( 'custom-header', 'suggested-height' ) ); 573 567 } 574 568 ?></p> 575 569 <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>"> … … 626 620 </tr> 627 621 <?php endif; 628 622 629 if ( defined( 'HEADER_IMAGE' ) && '' != HEADER_IMAGE) : ?>623 if ( current_theme_supports( 'custom-header', 'default-image' ) ) : ?> 630 624 <tr valign="top"> 631 625 <th scope="row"><?php _e( 'Reset Image' ); ?></th> 632 626 <td> … … 637 631 <?php endif; ?> 638 632 </tbody> 639 633 </table> 640 <?php if ( $this->header_text() ) : ?>634 <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?> 641 635 <table class="form-table"> 642 636 <tbody> 643 637 <tr valign="top" class="hide-if-no-js"> 644 638 <th scope="row"><?php _e( 'Display Text' ); ?></th> 645 639 <td> 646 640 <p> 647 <?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?> 648 <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? true : false ); ?> /> <?php _e( 'No' ); ?></label> 649 <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?> /> <?php _e( 'Yes' ); ?></label> 641 <?php 642 $show_text = get_header_textcolor(); 643 if ( 'blank' == $show_text ) 644 $show_text = false; 645 else 646 $show_text = (bool) $show_text; 647 ?> 648 <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ! $show_text ); ?> /> <?php _e( 'No' ); ?></label> 649 <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( $show_text ); ?> /> <?php _e( 'Yes' ); ?></label> 650 650 </p> 651 651 </td> 652 652 </tr> … … 655 655 <th scope="row"><?php _e( 'Text Color' ); ?></th> 656 656 <td> 657 657 <p> 658 <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_ theme_mod( 'header_textcolor', HEADER_TEXTCOLOR) ); ?>" />658 <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_header_textcolor() ); ?>" /> 659 659 <span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span> 660 660 <input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" /> 661 661 </p> … … 663 663 </td> 664 664 </tr> 665 665 666 <?php if ( defined('HEADER_TEXTCOLOR') && get_theme_mod('header_textcolor') ) { ?>666 <?php if ( current_theme_supports( 'custom-header', 'default-text-color' ) && get_theme_mod( 'header_textcolor' ) ) { ?> 667 667 <tr valign="top"> 668 668 <th scope="row"><?php _e('Reset Text Color'); ?></th> 669 669 <td> … … 722 722 723 723 list($width, $height, $type, $attr) = getimagesize( $file ); 724 724 725 $header_support = get_theme_support( 'custom-header' );726 725 $max_width = 0; 727 726 // For flex, limit size of image displayed to 1500px unless theme says otherwise 728 727 if ( current_theme_supports( 'custom-header', 'flex-width' ) ) 729 728 $max_width = 1500; 730 729 731 if ( !empty( $header_support[ 0 ][ 'max-width' ] ) ) 732 $max_width = max( $max_width, absint( $header_support[ 0 ][ 'max-width' ] ) ); 730 if ( current_theme_supports( 'custom-header', 'max-width' ) ) 731 $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); 732 $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); 733 733 734 if ( defined( 'HEADER_IMAGE_WIDTH' ) )735 $max_width = max( $max_width, HEADER_IMAGE_WIDTH );736 734 // If flexible height isn't supported and the image is the exact right size 737 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) && $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 735 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) 736 && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) ) 737 { 738 738 // Add the meta-data 739 739 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 740 740 update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); … … 791 791 * @since 2.1.0 792 792 */ 793 793 function step_3() { 794 check_admin_referer('custom-header-crop-image'); 795 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 794 check_admin_referer( 'custom-header-crop-image' ); 795 796 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) 796 797 wp_die( __( 'Cheatin’ uh?' ) ); 797 798 798 799 if ( $_POST['oitar'] > 1 ) { … … 805 806 $attachment_id = absint( $_POST['attachment_id'] ); 806 807 $original = get_attached_file($attachment_id); 807 808 808 $header_support = get_theme_support( 'custom-header' ); 809 809 810 $max_width = 0; 810 811 // For flex, limit size of image displayed to 1500px unless theme says otherwise 811 812 if ( current_theme_supports( 'custom-header', 'flex-width' ) ) 812 813 $max_width = 1500; 813 814 814 if ( !empty( $header_support[ 0 ][ 'max-width' ] ) ) 815 $max_width = max( $max_width, absint( $header_support[ 0 ][ 'max-width' ] ) ); 815 if ( current_theme_supports( 'custom-header', 'max-width' ) ) 816 $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); 817 $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); 816 818 817 if ( defined( 'HEADER_IMAGE_WIDTH' ) )818 $max_width = max( $max_width, HEADER_IMAGE_WIDTH );819 820 819 if ( ( current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) || $_POST['width'] > $max_width ) 821 820 $dst_height = absint( $_POST['height'] * ( $max_width / $_POST['width'] ) ); 822 821 elseif ( current_theme_supports( 'custom-header', 'flex-height' ) && current_theme_supports( 'custom-header', 'flex-width' ) ) 823 822 $dst_height = absint( $_POST['height'] ); 824 823 else 825 $dst_height = HEADER_IMAGE_HEIGHT;824 $dst_height = get_theme_support( 'custom-header', 'height' ); 826 825 827 826 if ( ( current_theme_supports( 'custom-header', 'flex-width' ) && ! current_theme_supports( 'custom-header', 'flex-height' ) ) || $_POST['width'] > $max_width ) 828 827 $dst_width = absint( $_POST['width'] * ( $max_width / $_POST['width'] ) ); 829 828 elseif ( current_theme_supports( 'custom-header', 'flex-width' ) && current_theme_supports( 'custom-header', 'flex-height' ) ) 830 829 $dst_width = absint( $_POST['width'] ); 831 830 else 832 $dst_width = HEADER_IMAGE_WIDTH;831 $dst_width = get_theme_support( 'custom-header', 'width' ); 833 832 834 833 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height ); 835 834 if ( is_wp_error( $cropped ) ) … … 894 893 if ( ! current_user_can('edit_theme_options') ) 895 894 wp_die(__('You do not have permission to customize headers.')); 896 895 $step = $this->step(); 897 if ( 1 == $step )896 if ( 1 == $step || ! $_POST ) 898 897 $this->step_1(); 899 898 elseif ( 2 == $step ) 900 899 $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>