Ticket #17242: death-to-constants-and-lame-functions.diff
File death-to-constants-and-lame-functions.diff, 16.2 KB (added by , 9 years ago) |
---|
-
wp-includes/theme.php
1111 1111 /** 1112 1112 * Add callbacks for image header display. 1113 1113 * 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 1114 * @since 2.1.0 1120 * @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display.1121 1115 * 1122 1116 * @param callback $header_callback Call on 'wp_head' action. 1123 1117 * @param callback $admin_header_callback Call on custom header administration screen. 1124 1118 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional. 1125 1119 */ 1126 1120 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' ) ); 1121 _deprecated_function( __FUNCTION__, '3.4', 'add_theme_support(\'custom-header\', $args)' ); 1122 return add_theme_support( 'custom-header', array( 1123 'callback' => $header_callback, 1124 'admin-header-callback' => $admin_header_callback, 1125 'admin-image-div-callback' => $admin_image_div_callback, 1126 ) ); 1145 1127 } 1146 1128 1147 1129 /** … … 1153 1135 * @return bool Whether support was removed. 1154 1136 */ 1155 1137 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; 1138 _deprecated_function( __FUNCTION__, '3.4', 'remove_theme_support(\'custom-header\')' ); 1139 return remove_theme_support( 'custom-header' ); 1170 1140 } 1171 1141 1172 1142 /** … … 1267 1237 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional. 1268 1238 */ 1269 1239 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' ) ); 1240 return add_theme_support( 'custom-background', array( 1241 'callback' => $header_callback, 1242 'admin-header-callback' => $admin_header_callback, 1243 'admin-image-div-callback' => $admin_image_div_callback, 1244 ) ); 1285 1245 } 1286 1246 1287 1247 /** … … 1293 1253 * @return bool Whether support was removed. 1294 1254 */ 1295 1255 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; 1256 _deprecated_function( __FUNCTION__, '3.4', 'remove_theme_support(\'custom-background\')' ); 1257 return remove_theme_support( 'custom-background' ); 1309 1258 } 1310 1259 1311 1260 /** … … 1418 1367 global $_wp_theme_features; 1419 1368 1420 1369 if ( func_num_args() == 1 ) 1421 $ _wp_theme_features[$feature]= true;1370 $args = true; 1422 1371 else 1423 $ _wp_theme_features[$feature]= array_slice( func_get_args(), 1 );1372 $args = array_slice( func_get_args(), 1 ); 1424 1373 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() ) ); 1374 switch ( $feature ) { 1375 case 'post-formats' : 1376 if ( is_array( $args[0] ) ) 1377 $args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) ); 1378 break; 1379 1380 case 'custom-header-uploads' : 1381 return add_theme_support( 'custom-header', array( 'uploads' => true ) ); 1382 break; 1383 1384 case 'custom-header' : 1385 $defaults = array( 1386 'default-image' => '', 1387 'random-default' => false, 1388 'width' => 0, 1389 'height' => 0, 1390 'suggested-width' => 0, 1391 'suggested-height' => 0, 1392 'flex-height' => false, 1393 'flex-width' => false, 1394 'default-text-color' => '', 1395 'header-text' => true, 1396 'uploads' => true, 1397 'callback' => '', 1398 'admin-header-callback' => '', 1399 'admin-image-div-callback' => '', 1400 ); 1401 1402 // Merge in data from previous add_theme_support() calls. 1403 if ( isset( $_wp_theme_features['custom-header'] ) ) 1404 $defaults = wp_parse_args( $_wp_theme_features['custom-header'][0], $defaults ); 1405 1406 $_args = $args[0]; 1407 $args[0] = wp_parse_args( $args[0], $defaults ); 1408 unset( $args[0]['__jit'] ); 1409 1410 if ( defined( 'NO_HEADER_TEXT' ) ) 1411 $args[0]['header-text'] = ! NO_HEADER_TEXT; 1412 elseif ( ! empty( $args[0]['header-text'] ) || isset( $_args['__jit'] ) ) 1413 define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); 1414 1415 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) 1416 $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; 1417 elseif ( ! empty( $args[0]['width'] ) || isset( $_args['__jit'] ) ) 1418 define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); 1419 1420 if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) 1421 $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; 1422 elseif ( ! empty( $args[0]['height'] ) || isset( $_args['__jit'] ) ) 1423 define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); 1424 1425 if ( defined( 'HEADER_TEXTCOLOR' ) ) 1426 $args[0]['default-text-color'] = HEADER_TEXTCOLOR; 1427 elseif ( $args[0]['default-text-color'] || isset( $_args['__jit'] ) ) 1428 define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); 1429 1430 if ( defined( 'HEADER_IMAGE' ) ) 1431 $args[0]['default-image'] = HEADER_IMAGE; 1432 1433 if ( ! empty( $args[0]['default-image'] ) ) 1434 $args[0]['random-default'] = false; 1435 1436 if ( ! defined( 'HEADER_IMAGE' ) && ( isset( $_args['default-image'] ) || isset( $_args['random-default'] ) ) ) 1437 define( 'HEADER_IMAGE', $args[0]['default-image'] ); 1438 1439 if ( ! empty( $args[0]['width'] ) ) 1440 $args[0]['flex-width'] = $args[0]['suggested-width'] = $args[0]['max-width'] = false; 1441 1442 if ( ! empty( $args[0]['height'] ) ) 1443 $args[0]['flex-height'] = $args[0]['suggested-height'] = false; 1444 1445 if ( $args[0]['callback'] ) 1446 add_action( 'wp_head', $args[0]['callback'] ); 1447 1448 break; 1449 1450 case 'custom-background' : 1451 $defaults = array( 1452 'callback' => '', 1453 'admin-header-callback' => '', 1454 'admin-image-div-callback' => '', 1455 ); 1456 if ( isset( $_wp_theme_features['custom-background'] ) ) 1457 $defaults = wp_parse_args( $_wp_theme_features['custom-background'][0], $defaults ); 1458 1459 $_args = $args; 1460 $args[0] = wp_parse_args( $args[0], $defaults ); 1461 if ( empty( $args[0]['callback'] ) ) 1462 $args[0]['callback'] = '_custom_background_cb'; 1463 1464 add_action( 'wp_head', $args[0]['callback'] ); 1465 1466 break; 1467 } 1468 1469 $_wp_theme_features[ $feature ] = $args; 1427 1470 } 1428 1471 1472 add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); 1473 1474 function _custom_header_background_just_in_time() { 1475 global $custom_image_header, $custom_background; 1476 1477 if ( current_theme_supports( 'custom-header' ) ) { 1478 // In case any constants were defined after an add_custom_image_header() call, re-run. 1479 add_theme_support( 'custom-header', array( '__jit' => true ) ); 1480 1481 if ( is_admin() ) { 1482 $args = get_theme_support( 'custom-header' ); 1483 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 1484 $custom_image_header = new Custom_Image_Header( $args[0]['admin-header-callback'], $args[0]['admin-image-div-callback'] ); 1485 } 1486 } 1487 1488 if ( is_admin() && current_theme_supports( 'custom-background' ) ) { 1489 $args = get_theme_support( 'custom-header' ); 1490 require_once( ABSPATH . 'wp-admin/custom-background.php' ); 1491 $custom_background = new Custom_Background( $args[0]['admin-header-callback'], $args[0]['admin-image-div-callback'] ); 1492 } 1493 } 1494 1429 1495 /** 1430 1496 * Gets the theme support arguments passed when registering that support 1431 1497 * … … 1454 1520 */ 1455 1521 function remove_theme_support( $feature ) { 1456 1522 // Blacklist: for internal registrations not used directly by themes. 1457 if ( in_array( $feature, array( 'custom-background', ' custom-header', 'editor-style', 'widgets', 'menus' ) ) )1523 if ( in_array( $feature, array( 'custom-background', 'editor-style', 'widgets', 'menus' ) ) ) 1458 1524 return false; 1525 1459 1526 return _remove_theme_support( $feature ); 1460 1527 } 1461 1528 … … 1468 1535 function _remove_theme_support( $feature ) { 1469 1536 global $_wp_theme_features; 1470 1537 1471 if ( ! isset( $_wp_theme_features[$feature] ) ) 1538 switch ( $feature ) { 1539 case 'custom-header-uploads' : 1540 if ( ! isset( $_wp_theme_features['custom-header'] ) ) 1541 return false; 1542 add_theme_support( 'custom-header', array( 'uploads' => false ) ); 1543 return; // Do not continue - custom-header-uploads no longer exists. 1544 } 1545 1546 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 1472 1547 return false; 1473 unset( $_wp_theme_features[$feature] ); 1548 1549 switch ( $feature ) { 1550 case 'custom-header' : 1551 $support = get_theme_support( 'custom-header' ); 1552 if ( $support[0]['callback'] ) 1553 remove_action( 'wp_head', $support[0]['callback'] ); 1554 unset( $GLOBALS['custom_image_header'] ); 1555 break; 1556 1557 case 'custom-header' : 1558 $support = get_theme_support( 'custom-background' ); 1559 remove_action( 'wp_head', $support[0]['callback'] ); 1560 unset( $GLOBALS['custom_background'] ); 1561 break; 1562 } 1563 1564 unset( $_wp_theme_features[ $feature ] ); 1474 1565 return true; 1475 1566 } 1476 1567 … … 1484 1575 function current_theme_supports( $feature ) { 1485 1576 global $_wp_theme_features; 1486 1577 1578 if ( 'custom-header-uploads' == $feature ) 1579 return current_theme_supports( 'custom-header', 'uploads' ); 1580 1487 1581 if ( !isset( $_wp_theme_features[$feature] ) ) 1488 1582 return false; 1489 1583 -
wp-content/themes/twentyten/functions.php
103 103 // This theme allows users to set a custom background 104 104 add_custom_background(); 105 105 106 // Your changeable header business starts here 107 if ( ! defined( 'HEADER_TEXTCOLOR' ) ) 108 define( 'HEADER_TEXTCOLOR', '' ); 106 add_theme_support( 'custom-header', array( 107 'width' => 940, 108 'height' => 198, 109 'admin-header-callback' => 'twentyten_admin_header_style', 110 'header-text' => false, 111 'default-image' => '%s/images/headers/path.jpg', 112 ) ); 109 113 110 // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.111 if ( ! defined( 'HEADER_IMAGE' ) )112 define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );113 114 // The height and width of your custom header. You can hook into the theme's own filters to change these values.115 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.116 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );117 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );118 119 114 // We'll be using post thumbnails for custom header images on posts and pages. 120 115 // We want them to be 940 pixels wide by 198 pixels tall. 121 116 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 122 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );117 set_post_thumbnail_size( 940, 198, true ); 123 118 124 // Don't support text inside the header image.125 if ( ! defined( 'NO_HEADER_TEXT' ) )126 define( 'NO_HEADER_TEXT', true );127 128 // Add a way for the custom header to be styled in the admin panel that controls129 // custom headers. See twentyten_admin_header_style(), below.130 add_custom_image_header( '', 'twentyten_admin_header_style' );131 132 119 // ... and thus ends the changeable header business. 133 120 134 121 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. -
wp-content/themes/twentytwelve/functions.php
76 76 'flex-width' => true, 77 77 'max-width' => apply_filters( 'twentytwelve_header_image_max_width', 2000 ), 78 78 'suggested-width' => apply_filters( 'twentytwelve_header_image_width', 960 ), 79 'callback' => 'twentytwelve_header_style', 80 'admin-header-callback' => 'twentytwelve_admin_header_style', 81 'admin-image-div-callback' => 'twentytwelve_admin_header_image', 79 82 ); 80 83 add_theme_support( 'custom-header', $header_args ); 81 add_custom_image_header( 'twentytwelve_header_style', 'twentytwelve_admin_header_style', 'twentytwelve_admin_header_image' );82 84 83 85 // The default header text color 84 86 define( 'HEADER_TEXTCOLOR', '444' ); -
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 … … 533 542 534 543 <tr valign="top"> 535 544 <th scope="row"><?php _e( 'Preview' ); ?></th> 536 <td 545 <td> 537 546 <?php if ( $this->admin_image_div_callback ) { 538 547 call_user_func( $this->admin_image_div_callback ); 539 548 } else { … … 800 809 * @since 2.1.0 801 810 */ 802 811 function step_3() { 803 check_admin_referer('custom-header-crop-image'); 804 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 812 check_admin_referer( 'custom-header-crop-image' ); 813 814 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) 805 815 wp_die( __( 'Cheatin’ uh?' ) ); 806 816 807 817 if ( $_POST['oitar'] > 1 ) { … … 903 913 if ( ! current_user_can('edit_theme_options') ) 904 914 wp_die(__('You do not have permission to customize headers.')); 905 915 $step = $this->step(); 906 if ( 1 == $step )916 if ( 1 == $step || ! $_POST ) 907 917 $this->step_1(); 908 918 elseif ( 2 == $step ) 909 919 $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