Changeset 42343 for trunk/src/wp-includes/class-wp-customize-manager.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-manager.php
r42171 r42343 284 284 285 285 $this->original_stylesheet = get_stylesheet(); 286 $this->theme = wp_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null );287 $this->messenger_channel = $args['messenger_channel'];288 $this->_changeset_uuid = $args['changeset_uuid'];286 $this->theme = wp_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null ); 287 $this->messenger_channel = $args['messenger_channel']; 288 $this->_changeset_uuid = $args['changeset_uuid']; 289 289 290 290 foreach ( array( 'settings_previewed', 'autosaved', 'branching' ) as $key ) { … … 366 366 367 367 add_action( 'setup_theme', array( $this, 'setup_theme' ) ); 368 add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );368 add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); 369 369 370 370 // Do not spawn cron (especially the alternate cron) while running the Customizer. … … 376 376 remove_action( 'admin_init', '_maybe_update_themes' ); 377 377 378 add_action( 'wp_ajax_customize_save', array( $this, 'save' ) );379 add_action( 'wp_ajax_customize_trash', array( $this, 'handle_changeset_trash_request' ) );380 add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );381 add_action( 'wp_ajax_customize_load_themes', array( $this, 'handle_load_themes_request' ) );382 add_filter( 'heartbeat_settings', array( $this, 'add_customize_screen_to_heartbeat_settings' ) );383 add_filter( 'heartbeat_received', array( $this, 'check_changeset_lock_with_heartbeat' ), 10, 3 );384 add_action( 'wp_ajax_customize_override_changeset_lock', array( $this, 'handle_override_changeset_lock_request' ) );378 add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); 379 add_action( 'wp_ajax_customize_trash', array( $this, 'handle_changeset_trash_request' ) ); 380 add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); 381 add_action( 'wp_ajax_customize_load_themes', array( $this, 'handle_load_themes_request' ) ); 382 add_filter( 'heartbeat_settings', array( $this, 'add_customize_screen_to_heartbeat_settings' ) ); 383 add_filter( 'heartbeat_received', array( $this, 'check_changeset_lock_with_heartbeat' ), 10, 3 ); 384 add_action( 'wp_ajax_customize_override_changeset_lock', array( $this, 'handle_override_changeset_lock_request' ) ); 385 385 add_action( 'wp_ajax_customize_dismiss_autosave_or_lock', array( $this, 'handle_dismiss_autosave_or_lock_request' ) ); 386 386 387 add_action( 'customize_register', array( $this, 'register_controls' ) );388 add_action( 'customize_register', array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first389 add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) );387 add_action( 'customize_register', array( $this, 'register_controls' ) ); 388 add_action( 'customize_register', array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first 389 add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) ); 390 390 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) ); 391 391 … … 459 459 'messengerArgs' => array( 460 460 'channel' => $this->messenger_channel, 461 'url' => wp_customize_url(),461 'url' => wp_customize_url(), 462 462 ), 463 'error' => $ajax_message,463 'error' => $ajax_message, 464 464 ); 465 465 ?> … … 468 468 var preview = new api.Messenger( settings.messengerArgs ); 469 469 preview.send( 'iframe-loading-error', settings.error ); 470 } )( wp.customize, <?php echo wp_json_encode( $settings ) ?> );470 } )( wp.customize, <?php echo wp_json_encode( $settings ); ?> ); 471 471 </script> 472 472 <?php … … 614 614 615 615 if ( ! $this->branching() && $this->is_theme_active() ) { 616 $unpublished_changeset_posts = $this->get_changeset_posts( array( 617 'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ), 618 'exclude_restore_dismissed' => false, 619 'author' => 'any', 620 'posts_per_page' => 1, 621 'order' => 'DESC', 622 'orderby' => 'date', 623 ) ); 624 $unpublished_changeset_post = array_shift( $unpublished_changeset_posts ); 616 $unpublished_changeset_posts = $this->get_changeset_posts( 617 array( 618 'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ), 619 'exclude_restore_dismissed' => false, 620 'author' => 'any', 621 'posts_per_page' => 1, 622 'order' => 'DESC', 623 'orderby' => 'date', 624 ) 625 ); 626 $unpublished_changeset_post = array_shift( $unpublished_changeset_posts ); 625 627 if ( ! empty( $unpublished_changeset_post ) && wp_is_uuid( $unpublished_changeset_post->post_name ) ) { 626 628 $changeset_uuid = $unpublished_changeset_post->post_name; … … 963 965 */ 964 966 public function find_changeset_post_id( $uuid ) { 965 $cache_group = 'customize_changeset_post';967 $cache_group = 'customize_changeset_post'; 966 968 $changeset_post_id = wp_cache_get( $uuid, $cache_group ); 967 969 if ( $changeset_post_id && 'customize_changeset' === get_post_type( $changeset_post_id ) ) { … … 969 971 } 970 972 971 $changeset_post_query = new WP_Query( array( 972 'post_type' => 'customize_changeset', 973 'post_status' => get_post_stati(), 974 'name' => $uuid, 975 'posts_per_page' => 1, 976 'no_found_rows' => true, 977 'cache_results' => true, 978 'update_post_meta_cache' => false, 979 'update_post_term_cache' => false, 980 'lazy_load_term_meta' => false, 981 ) ); 973 $changeset_post_query = new WP_Query( 974 array( 975 'post_type' => 'customize_changeset', 976 'post_status' => get_post_stati(), 977 'name' => $uuid, 978 'posts_per_page' => 1, 979 'no_found_rows' => true, 980 'cache_results' => true, 981 'update_post_meta_cache' => false, 982 'update_post_term_cache' => false, 983 'lazy_load_term_meta' => false, 984 ) 985 ); 982 986 if ( ! empty( $changeset_post_query->posts ) ) { 983 987 // Note: 'fields'=>'ids' is not being used in order to cache the post object as it will be needed. … … 1008 1012 $default_args = array( 1009 1013 'exclude_restore_dismissed' => true, 1010 'posts_per_page' => -1,1011 'post_type' => 'customize_changeset',1012 'post_status' => 'auto-draft',1013 'order' => 'DESC',1014 'orderby' => 'date',1015 'no_found_rows' => true,1016 'cache_results' => true,1017 'update_post_meta_cache' => false,1018 'update_post_term_cache' => false,1019 'lazy_load_term_meta' => false,1014 'posts_per_page' => -1, 1015 'post_type' => 'customize_changeset', 1016 'post_status' => 'auto-draft', 1017 'order' => 'DESC', 1018 'orderby' => 'date', 1019 'no_found_rows' => true, 1020 'cache_results' => true, 1021 'update_post_meta_cache' => false, 1022 'update_post_term_cache' => false, 1023 'lazy_load_term_meta' => false, 1020 1024 ); 1021 1025 if ( get_current_user_id() ) { … … 1028 1032 $args['meta_query'] = array( 1029 1033 array( 1030 'key' => '_customize_restore_dismissed',1034 'key' => '_customize_restore_dismissed', 1031 1035 'compare' => 'NOT EXISTS', 1032 1036 ), … … 1044 1048 */ 1045 1049 protected function dismiss_user_auto_draft_changesets() { 1046 $changeset_autodraft_posts = $this->get_changeset_posts( array( 1047 'post_status' => 'auto-draft', 1048 'exclude_restore_dismissed' => true, 1049 'posts_per_page' => -1, 1050 ) ); 1051 $dismissed = 0; 1050 $changeset_autodraft_posts = $this->get_changeset_posts( 1051 array( 1052 'post_status' => 'auto-draft', 1053 'exclude_restore_dismissed' => true, 1054 'posts_per_page' => -1, 1055 ) 1056 ); 1057 $dismissed = 0; 1052 1058 foreach ( $changeset_autodraft_posts as $autosave_autodraft_post ) { 1053 1059 if ( $autosave_autodraft_post->ID === $this->changeset_post_id() ) { … … 1194 1200 1195 1201 $sidebars_widgets = isset( $starter_content['widgets'] ) && ! empty( $this->widgets ) ? $starter_content['widgets'] : array(); 1196 $attachments = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array();1197 $posts = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array();1198 $options = isset( $starter_content['options'] ) ? $starter_content['options'] : array();1199 $nav_menus = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array();1200 $theme_mods = isset( $starter_content['theme_mods'] ) ? $starter_content['theme_mods'] : array();1202 $attachments = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array(); 1203 $posts = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array(); 1204 $options = isset( $starter_content['options'] ) ? $starter_content['options'] : array(); 1205 $nav_menus = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array(); 1206 $theme_mods = isset( $starter_content['theme_mods'] ) ? $starter_content['theme_mods'] : array(); 1201 1207 1202 1208 // Widgets. … … 1218 1224 $widget_numbers = array_keys( $settings ); 1219 1225 if ( count( $widget_numbers ) > 0 ) { 1220 $widget_numbers[] = 1;1226 $widget_numbers[] = 1; 1221 1227 $max_widget_numbers[ $id_base ] = call_user_func_array( 'max', $widget_numbers ); 1222 1228 } else { … … 1226 1232 $max_widget_numbers[ $id_base ] += 1; 1227 1233 1228 $widget_id = sprintf( '%s-%d', $id_base, $max_widget_numbers[ $id_base ] );1234 $widget_id = sprintf( '%s-%d', $id_base, $max_widget_numbers[ $id_base ] ); 1229 1235 $setting_id = sprintf( 'widget_%s[%d]', $id_base, $max_widget_numbers[ $id_base ] ); 1230 1236 … … 1251 1257 // Make an index of all the posts needed and what their slugs are. 1252 1258 $needed_posts = array(); 1253 $attachments = $this->prepare_starter_content_attachments( $attachments );1259 $attachments = $this->prepare_starter_content_attachments( $attachments ); 1254 1260 foreach ( $attachments as $attachment ) { 1255 $key = 'attachment:' . $attachment['post_name'];1261 $key = 'attachment:' . $attachment['post_name']; 1256 1262 $needed_posts[ $key ] = true; 1257 1263 } … … 1283 1289 $existing_starter_content_posts = array(); 1284 1290 if ( ! empty( $starter_content_auto_draft_post_ids ) ) { 1285 $existing_posts_query = new WP_Query( array( 1286 'post__in' => $starter_content_auto_draft_post_ids, 1287 'post_status' => 'auto-draft', 1288 'post_type' => $post_types, 1289 'posts_per_page' => -1, 1290 ) ); 1291 $existing_posts_query = new WP_Query( 1292 array( 1293 'post__in' => $starter_content_auto_draft_post_ids, 1294 'post_status' => 'auto-draft', 1295 'post_type' => $post_types, 1296 'posts_per_page' => -1, 1297 ) 1298 ); 1291 1299 foreach ( $existing_posts_query->posts as $existing_post ) { 1292 1300 $post_name = $existing_post->post_name; … … 1300 1308 // Re-use non-auto-draft posts. 1301 1309 if ( ! empty( $all_post_slugs ) ) { 1302 $existing_posts_query = new WP_Query( array( 1303 'post_name__in' => $all_post_slugs, 1304 'post_status' => array_diff( get_post_stati(), array( 'auto-draft' ) ), 1305 'post_type' => 'any', 1306 'posts_per_page' => -1, 1307 ) ); 1310 $existing_posts_query = new WP_Query( 1311 array( 1312 'post_name__in' => $all_post_slugs, 1313 'post_status' => array_diff( get_post_stati(), array( 'auto-draft' ) ), 1314 'post_type' => 'any', 1315 'posts_per_page' => -1, 1316 ) 1317 ); 1308 1318 foreach ( $existing_posts_query->posts as $existing_post ) { 1309 1319 $key = $existing_post->post_type . ':' . $existing_post->post_name; … … 1320 1330 1321 1331 foreach ( $attachments as $symbol => $attachment ) { 1322 $file_array = array(1332 $file_array = array( 1323 1333 'name' => $attachment['file_name'], 1324 1334 ); 1325 $file_path = $attachment['file_path'];1335 $file_path = $attachment['file_path']; 1326 1336 $attachment_id = null; 1327 1337 $attached_file = null; 1328 1338 if ( isset( $existing_starter_content_posts[ 'attachment:' . $attachment['post_name'] ] ) ) { 1329 1339 $attachment_post = $existing_starter_content_posts[ 'attachment:' . $attachment['post_name'] ]; 1330 $attachment_id = $attachment_post->ID;1331 $attached_file = get_attached_file( $attachment_id );1340 $attachment_id = $attachment_post->ID; 1341 $attached_file = get_attached_file( $attachment_id ); 1332 1342 if ( empty( $attached_file ) || ! file_exists( $attached_file ) ) { 1333 1343 $attachment_id = null; … … 1430 1440 1431 1441 // Nav menus. 1432 $placeholder_id = -1;1442 $placeholder_id = -1; 1433 1443 $reused_nav_menu_setting_ids = array(); 1434 1444 foreach ( $nav_menus as $nav_menu_location => $nav_menu ) { 1435 1445 1436 $nav_menu_term_id = null;1446 $nav_menu_term_id = null; 1437 1447 $nav_menu_setting_id = null; 1438 $matches = array();1448 $matches = array(); 1439 1449 1440 1450 // Look for an existing placeholder menu with starter content to re-use. … … 1448 1458 ); 1449 1459 if ( $can_reuse ) { 1450 $nav_menu_term_id = intval( $matches['nav_menu_id'] );1451 $nav_menu_setting_id = $setting_id;1460 $nav_menu_term_id = intval( $matches['nav_menu_id'] ); 1461 $nav_menu_setting_id = $setting_id; 1452 1462 $reused_nav_menu_setting_ids[] = $setting_id; 1453 1463 break; … … 1459 1469 $placeholder_id--; 1460 1470 } 1461 $nav_menu_term_id = $placeholder_id;1471 $nav_menu_term_id = $placeholder_id; 1462 1472 $nav_menu_setting_id = sprintf( 'nav_menu[%d]', $placeholder_id ); 1463 1473 } 1464 1474 1465 $this->set_post_value( $nav_menu_setting_id, array( 1466 'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location, 1467 ) ); 1475 $this->set_post_value( 1476 $nav_menu_setting_id, array( 1477 'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location, 1478 ) 1479 ); 1468 1480 $this->pending_starter_content_settings_ids[] = $nav_menu_setting_id; 1469 1481 … … 1481 1493 $nav_menu_item['object_id'] = $posts[ $matches['symbol'] ]['ID']; 1482 1494 if ( empty( $nav_menu_item['title'] ) ) { 1483 $original_object = get_post( $nav_menu_item['object_id'] );1495 $original_object = get_post( $nav_menu_item['object_id'] ); 1484 1496 $nav_menu_item['title'] = $original_object->post_title; 1485 1497 } … … 1536 1548 // Handle header image as special case since setting has a legacy format. 1537 1549 if ( 'header_image' === $name ) { 1538 $name = 'header_image_data';1550 $name = 'header_image_data'; 1539 1551 $metadata = wp_get_attachment_metadata( $value ); 1540 1552 if ( empty( $metadata ) ) { … … 1543 1555 $value = array( 1544 1556 'attachment_id' => $value, 1545 'url' => wp_get_attachment_url( $value ),1546 'height' => $metadata['height'],1547 'width' => $metadata['width'],1557 'url' => wp_get_attachment_url( $value ), 1558 'height' => $metadata['height'], 1559 'width' => $metadata['width'], 1548 1560 ); 1549 1561 } elseif ( 'background_image' === $name ) { … … 1621 1633 } 1622 1634 1623 $attachment['file_name'] = $file_name;1624 $attachment['file_path'] = $file_path;1635 $attachment['file_name'] = $file_name; 1636 $attachment['file_path'] = $file_path; 1625 1637 $prepared_attachments[ $symbol ] = $attachment; 1626 1638 } … … 1639 1651 } 1640 1652 1641 $this->save_changeset_post( array( 1642 'data' => array_fill_keys( $this->pending_starter_content_settings_ids, array( 'starter_content' => true ) ), 1643 'starter_content' => true, 1644 ) ); 1653 $this->save_changeset_post( 1654 array( 1655 'data' => array_fill_keys( $this->pending_starter_content_settings_ids, array( 'starter_content' => true ) ), 1656 'starter_content' => true, 1657 ) 1658 ); 1645 1659 $this->saved_starter_content_changeset = true; 1646 1660 … … 1689 1703 if ( ! $this->is_theme_active() ) { 1690 1704 $stashed_theme_mods = get_option( 'customize_stashed_theme_mods' ); 1691 $stylesheet = $this->get_stylesheet();1705 $stylesheet = $this->get_stylesheet(); 1692 1706 if ( isset( $stashed_theme_mods[ $stylesheet ] ) ) { 1693 1707 $values = array_merge( $values, wp_list_pluck( $stashed_theme_mods[ $stylesheet ], 'value' ) ); … … 1877 1891 */ 1878 1892 public function filter_iframe_security_headers( $headers ) { 1879 $customize_url = admin_url( 'customize.php' );1880 $headers['X-Frame-Options'] = 'ALLOW-FROM ' . $customize_url;1893 $customize_url = admin_url( 'customize.php' ); 1894 $headers['X-Frame-Options'] = 'ALLOW-FROM ' . $customize_url; 1881 1895 $headers['Content-Security-Policy'] = 'frame-ancestors ' . preg_replace( '#^(\w+://[^/]+).+?$#', '$1', $customize_url ); 1882 1896 return $headers; … … 1895 1909 public function add_state_query_params( $url ) { 1896 1910 $parsed_original_url = wp_parse_url( $url ); 1897 $is_allowed = false;1911 $is_allowed = false; 1898 1912 foreach ( $this->get_allowed_urls() as $allowed_url ) { 1899 1913 $parsed_allowed_url = wp_parse_url( $allowed_url ); 1900 $is_allowed = (1914 $is_allowed = ( 1901 1915 $parsed_allowed_url['scheme'] === $parsed_original_url['scheme'] 1902 1916 && … … 1963 1977 */ 1964 1978 public function customize_preview_loading_style() { 1965 ?><style> 1979 ?> 1980 <style> 1966 1981 body.wp-customizer-unloading { 1967 1982 opacity: 0.25; … … 1981 1996 cursor: not-allowed !important; 1982 1997 } 1983 </style><?php 1998 </style> 1999 <?php 1984 2000 } 1985 2001 … … 2027 2043 */ 2028 2044 public function customize_preview_settings() { 2029 $post_values = $this->unsanitized_post_values( array( 'exclude_changeset' => true ) );2030 $setting_validities = $this->validate_setting_values( $post_values );2045 $post_values = $this->unsanitized_post_values( array( 'exclude_changeset' => true ) ); 2046 $setting_validities = $this->validate_setting_values( $post_values ); 2031 2047 $exported_setting_validities = array_map( array( $this, 'prepare_setting_validity_for_js' ), $setting_validities ); 2032 2048 2033 2049 // Note that the REQUEST_URI is not passed into home_url() since this breaks subdirectory installations. 2034 $self_url = empty( $_SERVER['REQUEST_URI'] ) ? home_url( '/' ) : esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) );2050 $self_url = empty( $_SERVER['REQUEST_URI'] ) ? home_url( '/' ) : esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ); 2035 2051 $state_query_params = array( 2036 2052 'customize_theme', … … 2038 2054 'customize_messenger_channel', 2039 2055 ); 2040 $self_url = remove_query_arg( $state_query_params, $self_url );2041 2042 $allowed_urls = $this->get_allowed_urls();2056 $self_url = remove_query_arg( $state_query_params, $self_url ); 2057 2058 $allowed_urls = $this->get_allowed_urls(); 2043 2059 $allowed_hosts = array(); 2044 2060 foreach ( $allowed_urls as $allowed_url ) { … … 2055 2071 2056 2072 $switched_locale = switch_to_locale( get_user_locale() ); 2057 $l10n = array(2058 'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),2073 $l10n = array( 2074 'shiftClickToEdit' => __( 'Shift-click to edit this element.' ), 2059 2075 'linkUnpreviewable' => __( 'This link is not live-previewable.' ), 2060 2076 'formUnpreviewable' => __( 'This form is not live-previewable.' ), … … 2065 2081 2066 2082 $settings = array( 2067 'changeset' => array(2068 'uuid' => $this->changeset_uuid(),2083 'changeset' => array( 2084 'uuid' => $this->changeset_uuid(), 2069 2085 'autosaved' => $this->autosaved(), 2070 2086 ), 2071 'timeouts' => array(2087 'timeouts' => array( 2072 2088 'selectiveRefresh' => 250, 2073 'keepAliveSend' => 1000,2089 'keepAliveSend' => 1000, 2074 2090 ), 2075 'theme' => array(2091 'theme' => array( 2076 2092 'stylesheet' => $this->get_stylesheet(), 2077 2093 'active' => $this->is_theme_active(), 2078 2094 ), 2079 'url' => array(2080 'self' => $self_url,2081 'allowed' => array_map( 'esc_url_raw', $this->get_allowed_urls() ),2082 'allowedHosts' => array_unique( $allowed_hosts ),2095 'url' => array( 2096 'self' => $self_url, 2097 'allowed' => array_map( 'esc_url_raw', $this->get_allowed_urls() ), 2098 'allowedHosts' => array_unique( $allowed_hosts ), 2083 2099 'isCrossDomain' => $this->is_cross_domain(), 2084 2100 ), 2085 'channel' => $this->messenger_channel,2086 'activePanels' => array(),2087 'activeSections' => array(),2088 'activeControls' => array(),2101 'channel' => $this->messenger_channel, 2102 'activePanels' => array(), 2103 'activeSections' => array(), 2104 'activeControls' => array(), 2089 2105 'settingValidities' => $exported_setting_validities, 2090 'nonce' => current_user_can( 'customize' ) ? $this->get_nonces() : array(),2091 'l10n' => $l10n,2092 '_dirty' => array_keys( $post_values ),2106 'nonce' => current_user_can( 'customize' ) ? $this->get_nonces() : array(), 2107 'l10n' => $l10n, 2108 '_dirty' => array_keys( $post_values ), 2093 2109 ); 2094 2110 … … 2229 2245 */ 2230 2246 public function current_theme( $current_theme ) { 2231 return $this->theme()->display( 'Name');2247 return $this->theme()->display( 'Name' ); 2232 2248 } 2233 2249 … … 2255 2271 */ 2256 2272 public function validate_setting_values( $setting_values, $options = array() ) { 2257 $options = wp_parse_args( $options, array( 2258 'validate_capability' => false, 2259 'validate_existence' => false, 2260 ) ); 2273 $options = wp_parse_args( 2274 $options, array( 2275 'validate_capability' => false, 2276 'validate_existence' => false, 2277 ) 2278 ); 2261 2279 2262 2280 $validities = array(); … … 2319 2337 $notification[ $error_code ] = array( 2320 2338 'message' => join( ' ', $error_messages ), 2321 'data' => $validity->get_error_data( $error_code ),2339 'data' => $validity->get_error_data( $error_code ), 2322 2340 ); 2323 2341 } … … 2349 2367 2350 2368 $changeset_post_id = $this->changeset_post_id(); 2351 $is_new_changeset = empty( $changeset_post_id );2369 $is_new_changeset = empty( $changeset_post_id ); 2352 2370 if ( $is_new_changeset ) { 2353 2371 if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->create_posts ) ) { … … 2376 2394 2377 2395 // Validate changeset status param. 2378 $is_publish = null;2396 $is_publish = null; 2379 2397 $changeset_status = null; 2380 2398 if ( isset( $_POST['customize_changeset_status'] ) ) { … … 2399 2417 $changeset_date = wp_unslash( $_POST['customize_changeset_date'] ); 2400 2418 if ( preg_match( '/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $changeset_date ) ) { 2401 $mm = substr( $changeset_date, 5, 2 );2402 $jj = substr( $changeset_date, 8, 2 );2403 $aa = substr( $changeset_date, 0, 4 );2419 $mm = substr( $changeset_date, 5, 2 ); 2420 $jj = substr( $changeset_date, 8, 2 ); 2421 $aa = substr( $changeset_date, 0, 4 ); 2404 2422 $valid_date = wp_checkdate( $mm, $jj, $aa, $changeset_date ); 2405 2423 if ( ! $valid_date ) { … … 2417 2435 2418 2436 $lock_user_id = null; 2419 $autosave = ! empty( $_POST['customize_changeset_autosave'] );2437 $autosave = ! empty( $_POST['customize_changeset_autosave'] ); 2420 2438 if ( ! $is_new_changeset ) { 2421 2439 $lock_user_id = wp_check_post_lock( $this->changeset_post_id() ); … … 2424 2442 // Force request to autosave when changeset is locked. 2425 2443 if ( $lock_user_id && ! $autosave ) { 2426 $autosave = true;2427 $changeset_status = null;2444 $autosave = true; 2445 $changeset_status = null; 2428 2446 $changeset_date_gmt = null; 2429 2447 } … … 2434 2452 2435 2453 $autosaved = false; 2436 $r = $this->save_changeset_post( array( 2437 'status' => $changeset_status, 2438 'title' => $changeset_title, 2439 'date_gmt' => $changeset_date_gmt, 2440 'data' => $input_changeset_data, 2441 'autosave' => $autosave, 2442 ) ); 2454 $r = $this->save_changeset_post( 2455 array( 2456 'status' => $changeset_status, 2457 'title' => $changeset_title, 2458 'date_gmt' => $changeset_date_gmt, 2459 'data' => $input_changeset_data, 2460 'autosave' => $autosave, 2461 ) 2462 ); 2443 2463 if ( $autosave && ! is_wp_error( $r ) ) { 2444 2464 $autosaved = true; … … 2459 2479 $response = array( 2460 2480 'message' => $r->get_error_message(), 2461 'code' => $r->get_error_code(),2481 'code' => $r->get_error_code(), 2462 2482 ); 2463 2483 if ( is_array( $r->get_error_data() ) ) { … … 2467 2487 } 2468 2488 } else { 2469 $response = $r;2489 $response = $r; 2470 2490 $changeset_post = get_post( $this->changeset_post_id() ); 2471 2491 … … 2545 2565 $args = array_merge( 2546 2566 array( 2547 'status' => null,2548 'title' => null,2549 'data' => array(),2550 'date_gmt' => null,2551 'user_id' => get_current_user_id(),2567 'status' => null, 2568 'title' => null, 2569 'data' => array(), 2570 'date_gmt' => null, 2571 'user_id' => get_current_user_id(), 2552 2572 'starter_content' => false, 2553 'autosave' => false,2573 'autosave' => false, 2554 2574 ), 2555 2575 $args 2556 2576 ); 2557 2577 2558 $changeset_post_id = $this->changeset_post_id();2578 $changeset_post_id = $this->changeset_post_id(); 2559 2579 $existing_changeset_data = array(); 2560 2580 if ( $changeset_post_id ) { … … 2622 2642 // The request was made via wp.customize.previewer.save(). 2623 2643 $update_transactionally = (bool) $args['status']; 2624 $allow_revision = (bool) $args['status'];2644 $allow_revision = (bool) $args['status']; 2625 2645 2626 2646 // Amend post values with any supplied data. … … 2632 2652 2633 2653 // Note that in addition to post data, this will include any stashed theme mods. 2634 $post_values = $this->unsanitized_post_values( array( 2635 'exclude_changeset' => true, 2636 'exclude_post_data' => false, 2637 ) ); 2654 $post_values = $this->unsanitized_post_values( 2655 array( 2656 'exclude_changeset' => true, 2657 'exclude_post_data' => false, 2658 ) 2659 ); 2638 2660 $this->add_dynamic_settings( array_keys( $post_values ) ); // Ensure settings get created even if they lack an input value. 2639 2661 … … 2682 2704 2683 2705 // Validate settings. 2684 $validated_values = array_merge(2706 $validated_values = array_merge( 2685 2707 array_fill_keys( array_keys( $args['data'] ), null ), // Make sure existence/capability checks are done on value-less setting updates. 2686 2708 $post_values 2687 2709 ); 2688 $setting_validities = $this->validate_setting_values( $validated_values, array( 2689 'validate_capability' => true, 2690 'validate_existence' => true, 2691 ) ); 2710 $setting_validities = $this->validate_setting_values( 2711 $validated_values, array( 2712 'validate_capability' => true, 2713 'validate_existence' => true, 2714 ) 2715 ); 2692 2716 $invalid_setting_count = count( array_filter( $setting_validities, 'is_wp_error' ) ); 2693 2717 … … 2700 2724 'setting_validities' => $setting_validities, 2701 2725 /* translators: %s: number of invalid settings */ 2702 'message' => sprintf( _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', $invalid_setting_count ), number_format_i18n( $invalid_setting_count ) ),2726 'message' => sprintf( _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', $invalid_setting_count ), number_format_i18n( $invalid_setting_count ) ), 2703 2727 ); 2704 2728 return new WP_Error( 'transaction_fail', '', $response ); … … 2707 2731 // Obtain/merge data for changeset. 2708 2732 $original_changeset_data = $this->get_changeset_post_data( $changeset_post_id ); 2709 $data = $original_changeset_data;2733 $data = $original_changeset_data; 2710 2734 if ( is_wp_error( $data ) ) { 2711 2735 $data = array(); … … 2758 2782 $merged_setting_params, 2759 2783 array( 2760 'type' => $setting->type,2761 'user_id' => $args['user_id'],2784 'type' => $setting->type, 2785 'user_id' => $args['user_id'], 2762 2786 'date_modified_gmt' => current_time( 'mysql', true ), 2763 2787 ) … … 2772 2796 2773 2797 $filter_context = array( 2774 'uuid' => $this->changeset_uuid(),2775 'title' => $args['title'],2776 'status' => $args['status'],2777 'date_gmt' => $args['date_gmt'],2778 'post_id' => $changeset_post_id,2798 'uuid' => $this->changeset_uuid(), 2799 'title' => $args['title'], 2800 'status' => $args['status'], 2801 'date_gmt' => $args['date_gmt'], 2802 'post_id' => $changeset_post_id, 2779 2803 'previous_data' => is_wp_error( $original_changeset_data ) ? array() : $original_changeset_data, 2780 'manager' => $this,2804 'manager' => $this, 2781 2805 ); 2782 2806 … … 2818 2842 } 2819 2843 $json_options |= JSON_PRETTY_PRINT; // Also introduced in PHP 5.4, but WP defines constant for back compat. See WP Trac #30139. 2820 $post_array = array(2844 $post_array = array( 2821 2845 'post_content' => wp_json_encode( $data, $json_options ), 2822 2846 ); … … 2827 2851 $post_array['ID'] = $changeset_post_id; 2828 2852 } else { 2829 $post_array['post_type'] = 'customize_changeset';2830 $post_array['post_name'] = $this->changeset_uuid();2853 $post_array['post_type'] = 'customize_changeset'; 2854 $post_array['post_name'] = $this->changeset_uuid(); 2831 2855 $post_array['post_status'] = 'auto-draft'; 2832 2856 } … … 2838 2862 if ( 'publish' === $args['status'] ) { 2839 2863 $post_array['post_date_gmt'] = '0000-00-00 00:00:00'; 2840 $post_array['post_date'] = '0000-00-00 00:00:00';2864 $post_array['post_date'] = '0000-00-00 00:00:00'; 2841 2865 } elseif ( $args['date_gmt'] ) { 2842 2866 $post_array['post_date_gmt'] = $args['date_gmt']; 2843 $post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] );2867 $post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] ); 2844 2868 } elseif ( $changeset_post_id && 'auto-draft' === get_post_status( $changeset_post_id ) ) { 2845 2869 /* … … 2848 2872 * wp_delete_auto_drafts(). 2849 2873 */ 2850 $post_array['post_date'] = current_time( 'mysql' );2874 $post_array['post_date'] = current_time( 'mysql' ); 2851 2875 $post_array['post_date_gmt'] = ''; 2852 2876 } … … 2866 2890 // See _wp_translate_postdata() for why this is required as it will use the edit_post meta capability. 2867 2891 add_filter( 'map_meta_cap', array( $this, 'grant_edit_post_capability_for_changeset' ), 10, 4 ); 2868 $post_array['post_ID'] = $post_array['ID'];2892 $post_array['post_ID'] = $post_array['ID']; 2869 2893 $post_array['post_type'] = 'customize_changeset'; 2870 $r = wp_create_post_autosave( wp_slash( $post_array ) );2894 $r = wp_create_post_autosave( wp_slash( $post_array ) ); 2871 2895 remove_filter( 'map_meta_cap', array( $this, 'grant_edit_post_capability_for_changeset' ), 10 ); 2872 2896 } else { 2873 2897 $post_array['edit_date'] = true; // Prevent date clearing. 2874 $r = wp_update_post( wp_slash( $post_array ), true );2898 $r = wp_update_post( wp_slash( $post_array ), true ); 2875 2899 2876 2900 // Delete autosave revision when the changeset is updated. … … 2993 3017 2994 3018 if ( ! check_ajax_referer( 'trash_customize_changeset', 'nonce', false ) ) { 2995 wp_send_json_error( array( 2996 'code' => 'invalid_nonce', 2997 'message' => __( 'There was an authentication problem. Please reload and try again.' ), 2998 ) ); 3019 wp_send_json_error( 3020 array( 3021 'code' => 'invalid_nonce', 3022 'message' => __( 'There was an authentication problem. Please reload and try again.' ), 3023 ) 3024 ); 2999 3025 } 3000 3026 … … 3002 3028 3003 3029 if ( ! $changeset_post_id ) { 3004 wp_send_json_error( array( 3005 'message' => __( 'No changes saved yet, so there is nothing to trash.' ), 3006 'code' => 'non_existent_changeset', 3007 ) ); 3030 wp_send_json_error( 3031 array( 3032 'message' => __( 'No changes saved yet, so there is nothing to trash.' ), 3033 'code' => 'non_existent_changeset', 3034 ) 3035 ); 3008 3036 return; 3009 3037 } 3010 3038 3011 3039 if ( $changeset_post_id && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->delete_post, $changeset_post_id ) ) { 3012 wp_send_json_error( array( 3013 'code' => 'changeset_trash_unauthorized', 3014 'message' => __( 'Unable to trash changes.' ), 3015 ) ); 3040 wp_send_json_error( 3041 array( 3042 'code' => 'changeset_trash_unauthorized', 3043 'message' => __( 'Unable to trash changes.' ), 3044 ) 3045 ); 3016 3046 } 3017 3047 3018 3048 if ( 'trash' === get_post_status( $changeset_post_id ) ) { 3019 wp_send_json_error( array( 3020 'message' => __( 'Changes have already been trashed.' ), 3021 'code' => 'changeset_already_trashed', 3022 ) ); 3049 wp_send_json_error( 3050 array( 3051 'message' => __( 'Changes have already been trashed.' ), 3052 'code' => 'changeset_already_trashed', 3053 ) 3054 ); 3023 3055 return; 3024 3056 } … … 3026 3058 $r = $this->trash_changeset_post( $changeset_post_id ); 3027 3059 if ( ! ( $r instanceof WP_Post ) ) { 3028 wp_send_json_error( array( 3029 'code' => 'changeset_trash_failure', 3030 'message' => __( 'Unable to trash changes.' ), 3031 ) ); 3032 } 3033 3034 wp_send_json_success( array( 3035 'message' => __( 'Changes trashed successfully.' ), 3036 ) ); 3060 wp_send_json_error( 3061 array( 3062 'code' => 'changeset_trash_failure', 3063 'message' => __( 'Unable to trash changes.' ), 3064 ) 3065 ); 3066 } 3067 3068 wp_send_json_success( 3069 array( 3070 'message' => __( 'Changes trashed successfully.' ), 3071 ) 3072 ); 3037 3073 } 3038 3074 … … 3061 3097 if ( 'edit_post' === $cap && ! empty( $args[0] ) && 'customize_changeset' === get_post_type( $args[0] ) ) { 3062 3098 $post_type_obj = get_post_type_object( 'customize_changeset' ); 3063 $caps = map_meta_cap( $post_type_obj->cap->$cap, $user_id );3099 $caps = map_meta_cap( $post_type_obj->cap->$cap, $user_id ); 3064 3100 } 3065 3101 return $caps; … … 3106 3142 3107 3143 if ( $lock && ! empty( $lock[1] ) ) { 3108 $user_id = intval( $lock[1] );3144 $user_id = intval( $lock[1] ); 3109 3145 $current_user_id = get_current_user_id(); 3110 3146 if ( $user_id === $current_user_id ) { … … 3147 3183 } 3148 3184 return array( 3149 'id' => $lock_user->ID,3150 'name' => $lock_user->display_name,3185 'id' => $lock_user->ID, 3186 'name' => $lock_user->display_name, 3151 3187 'avatar' => get_avatar_url( $lock_user->ID, array( 'size' => 128 ) ), 3152 3188 ); … … 3190 3226 3191 3227 if ( ! check_ajax_referer( 'customize_override_changeset_lock', 'nonce', false ) ) { 3192 wp_send_json_error( array( 3193 'code' => 'invalid_nonce', 3194 'message' => __( 'Security check failed.' ), 3195 ) ); 3228 wp_send_json_error( 3229 array( 3230 'code' => 'invalid_nonce', 3231 'message' => __( 'Security check failed.' ), 3232 ) 3233 ); 3196 3234 } 3197 3235 … … 3199 3237 3200 3238 if ( empty( $changeset_post_id ) ) { 3201 wp_send_json_error( array( 3202 'code' => 'no_changeset_found_to_take_over', 3203 'message' => __( 'No changeset found to take over' ), 3204 ) ); 3239 wp_send_json_error( 3240 array( 3241 'code' => 'no_changeset_found_to_take_over', 3242 'message' => __( 'No changeset found to take over' ), 3243 ) 3244 ); 3205 3245 } 3206 3246 3207 3247 if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $changeset_post_id ) ) { 3208 wp_send_json_error( array( 3209 'code' => 'cannot_remove_changeset_lock', 3210 'message' => __( 'Sorry, you are not allowed to take over.' ), 3211 ) ); 3248 wp_send_json_error( 3249 array( 3250 'code' => 'cannot_remove_changeset_lock', 3251 'message' => __( 'Sorry, you are not allowed to take over.' ), 3252 ) 3253 ); 3212 3254 } 3213 3255 … … 3289 3331 3290 3332 // Parse changeset data to identify theme mod settings and user IDs associated with settings to be saved. 3291 $setting_user_ids = array();3333 $setting_user_ids = array(); 3292 3334 $theme_mod_settings = array(); 3293 $namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/';3294 $matches = array();3335 $namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/'; 3336 $matches = array(); 3295 3337 foreach ( $this->_changeset_data as $raw_setting_id => $setting_params ) { 3296 $actual_setting_id = null;3338 $actual_setting_id = null; 3297 3339 $is_theme_mod_setting = ( 3298 3340 isset( $setting_params['value'] ) … … 3323 3365 } 3324 3366 3325 $changeset_setting_values = $this->unsanitized_post_values( array( 3326 'exclude_post_data' => true, 3327 'exclude_changeset' => false, 3328 ) ); 3329 $changeset_setting_ids = array_keys( $changeset_setting_values ); 3367 $changeset_setting_values = $this->unsanitized_post_values( 3368 array( 3369 'exclude_post_data' => true, 3370 'exclude_changeset' => false, 3371 ) 3372 ); 3373 $changeset_setting_ids = array_keys( $changeset_setting_values ); 3330 3374 $this->add_dynamic_settings( $changeset_setting_ids ); 3331 3375 … … 3351 3395 if ( $setting && ! isset( $setting_user_ids[ $setting_id ] ) ) { 3352 3396 $original_setting_capabilities[ $setting->id ] = $setting->capability; 3353 $setting->capability = 'exist';3397 $setting->capability = 'exist'; 3354 3398 } 3355 3399 } … … 3418 3462 array( 3419 3463 'post_status' => 'auto-draft', 3420 'post_type' => 'customize_changeset',3421 'post_name' => wp_generate_uuid4(),3464 'post_type' => 'customize_changeset', 3465 'post_name' => wp_generate_uuid4(), 3422 3466 'post_parent' => 0, 3423 3467 ), … … 3463 3507 3464 3508 $autoload = false; 3465 $result = update_option( 'customize_stashed_theme_mods', $stashed_theme_mod_settings, $autoload );3509 $result = update_option( 'customize_stashed_theme_mods', $stashed_theme_mod_settings, $autoload ); 3466 3510 if ( ! $result ) { 3467 3511 return false; … … 3498 3542 3499 3543 $changeset_post_id = $this->changeset_post_id(); 3500 $dismiss_lock = ! empty( $_POST['dismiss_lock'] );3501 $dismiss_autosave = ! empty( $_POST['dismiss_autosave'] );3544 $dismiss_lock = ! empty( $_POST['dismiss_lock'] ); 3545 $dismiss_autosave = ! empty( $_POST['dismiss_autosave'] ); 3502 3546 3503 3547 if ( $dismiss_lock ) { … … 3564 3608 * Using 'refresh' makes the change visible by reloading the whole preview. 3565 3609 * Using 'postMessage' allows a custom JavaScript to handle live changes. 3566 * @link https://developer.wordpress.org/themes/customize-api3610 * @link https://developer.wordpress.org/themes/customize-api 3567 3611 * Default is 'refresh' 3568 3612 * @type callable $validate_callback Server-side validation callback for the setting's value. … … 3615 3659 } 3616 3660 3617 $setting_args = false;3661 $setting_args = false; 3618 3662 $setting_class = 'WP_Customize_Setting'; 3619 3663 … … 3735 3779 if ( in_array( $id, $this->components, true ) ) { 3736 3780 /* translators: 1: panel id, 2: link to 'customize_loaded_components' filter reference */ 3737 $message = sprintf( __( 'Removing %1$s manually will cause PHP warnings. Use the %2$s filter instead.' ), 3781 $message = sprintf( 3782 __( 'Removing %1$s manually will cause PHP warnings. Use the %2$s filter instead.' ), 3738 3783 $id, 3739 3784 '<a href="' . esc_url( 'https://developer.wordpress.org/reference/hooks/customize_loaded_components/' ) . '"><code>customize_loaded_components</code></a>' … … 3814 3859 */ 3815 3860 public function get_section( $id ) { 3816 if ( isset( $this->sections[ $id ] ) ) 3861 if ( isset( $this->sections[ $id ] ) ) { 3817 3862 return $this->sections[ $id ]; 3863 } 3818 3864 } 3819 3865 … … 3905 3951 */ 3906 3952 public function get_control( $id ) { 3907 if ( isset( $this->controls[ $id ] ) ) 3953 if ( isset( $this->controls[ $id ] ) ) { 3908 3954 return $this->controls[ $id ]; 3955 } 3909 3956 } 3910 3957 … … 3941 3988 public function render_control_templates() { 3942 3989 foreach ( $this->registered_control_types as $control_type ) { 3943 $control = new $control_type( $this, 'temp', array( 3944 'settings' => array(), 3945 ) ); 3990 $control = new $control_type( 3991 $this, 'temp', array( 3992 'settings' => array(), 3993 ) 3994 ); 3946 3995 $control->print_template(); 3947 3996 } … … 4217 4266 public function prepare_controls() { 4218 4267 4219 $controls = array(); 4220 $this->controls = wp_list_sort( $this->controls, array( 4221 'priority' => 'ASC', 4222 'instance_number' => 'ASC', 4223 ), 'ASC', true ); 4268 $controls = array(); 4269 $this->controls = wp_list_sort( 4270 $this->controls, array( 4271 'priority' => 'ASC', 4272 'instance_number' => 'ASC', 4273 ), 'ASC', true 4274 ); 4224 4275 4225 4276 foreach ( $this->controls as $id => $control ) { … … 4229 4280 4230 4281 $this->sections[ $control->section ]->controls[] = $control; 4231 $controls[ $id ] = $control;4282 $controls[ $id ] = $control; 4232 4283 } 4233 4284 $this->controls = $controls; 4234 4285 4235 4286 // Prepare sections. 4236 $this->sections = wp_list_sort( $this->sections, array( 4237 'priority' => 'ASC', 4238 'instance_number' => 'ASC', 4239 ), 'ASC', true ); 4240 $sections = array(); 4287 $this->sections = wp_list_sort( 4288 $this->sections, array( 4289 'priority' => 'ASC', 4290 'instance_number' => 'ASC', 4291 ), 'ASC', true 4292 ); 4293 $sections = array(); 4241 4294 4242 4295 foreach ( $this->sections as $section ) { … … 4245 4298 } 4246 4299 4247 4248 $section->controls = wp_list_sort( $section->controls, array( 4249 'priority' => 'ASC', 4250 'instance_number' => 'ASC', 4251 ) ); 4300 $section->controls = wp_list_sort( 4301 $section->controls, array( 4302 'priority' => 'ASC', 4303 'instance_number' => 'ASC', 4304 ) 4305 ); 4252 4306 4253 4307 if ( ! $section->panel ) { … … 4264 4318 4265 4319 // Prepare panels. 4266 $this->panels = wp_list_sort( $this->panels, array( 4267 'priority' => 'ASC', 4268 'instance_number' => 'ASC', 4269 ), 'ASC', true ); 4270 $panels = array(); 4320 $this->panels = wp_list_sort( 4321 $this->panels, array( 4322 'priority' => 'ASC', 4323 'instance_number' => 'ASC', 4324 ), 'ASC', true 4325 ); 4326 $panels = array(); 4271 4327 4272 4328 foreach ( $this->panels as $panel ) { … … 4275 4331 } 4276 4332 4277 $panel->sections = wp_list_sort( $panel->sections, array( 4333 $panel->sections = wp_list_sort( 4334 $panel->sections, array( 4335 'priority' => 'ASC', 4336 'instance_number' => 'ASC', 4337 ), 'ASC', true 4338 ); 4339 $panels[ $panel->id ] = $panel; 4340 } 4341 $this->panels = $panels; 4342 4343 // Sort panels and top-level sections together. 4344 $this->containers = array_merge( $this->panels, $this->sections ); 4345 $this->containers = wp_list_sort( 4346 $this->containers, array( 4278 4347 'priority' => 'ASC', 4279 4348 'instance_number' => 'ASC', 4280 ), 'ASC', true ); 4281 $panels[ $panel->id ] = $panel; 4282 } 4283 $this->panels = $panels; 4284 4285 // Sort panels and top-level sections together. 4286 $this->containers = array_merge( $this->panels, $this->sections ); 4287 $this->containers = wp_list_sort( $this->containers, array( 4288 'priority' => 'ASC', 4289 'instance_number' => 'ASC', 4290 ), 'ASC', true ); 4349 ), 'ASC', true 4350 ); 4291 4351 } 4292 4352 … … 4303 4363 if ( ! is_multisite() && ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) || current_user_can( 'delete_themes' ) ) ) { 4304 4364 wp_enqueue_script( 'updates' ); 4305 wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( 4306 'totals' => wp_get_update_data(), 4307 ) ); 4365 wp_localize_script( 4366 'updates', '_wpUpdatesItemCounts', array( 4367 'totals' => wp_get_update_data(), 4368 ) 4369 ); 4308 4370 } 4309 4371 } … … 4349 4411 */ 4350 4412 public function set_preview_url( $preview_url ) { 4351 $preview_url = esc_url_raw( $preview_url );4413 $preview_url = esc_url_raw( $preview_url ); 4352 4414 $this->preview_url = wp_validate_redirect( $preview_url, home_url( '/' ) ); 4353 4415 } … … 4378 4440 public function is_cross_domain() { 4379 4441 $admin_origin = wp_parse_url( admin_url() ); 4380 $home_origin = wp_parse_url( home_url() );4442 $home_origin = wp_parse_url( home_url() ); 4381 4443 $cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) ); 4382 4444 return $cross_domain; … … 4437 4499 */ 4438 4500 public function set_return_url( $return_url ) { 4439 $return_url = esc_url_raw( $return_url );4440 $return_url = remove_query_arg( wp_removable_query_args(), $return_url );4441 $return_url = wp_validate_redirect( $return_url );4501 $return_url = esc_url_raw( $return_url ); 4502 $return_url = remove_query_arg( wp_removable_query_args(), $return_url ); 4503 $return_url = wp_validate_redirect( $return_url ); 4442 4504 $this->return_url = $return_url; 4443 4505 } … … 4451 4513 */ 4452 4514 public function get_return_url() { 4453 $referer = wp_get_referer();4515 $referer = wp_get_referer(); 4454 4516 $excluded_referer_basenames = array( 'customize.php', 'wp-login.php' ); 4455 4517 4456 4518 if ( $this->return_url ) { 4457 4519 $return_url = $this->return_url; 4458 } else if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {4520 } elseif ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) { 4459 4521 $return_url = $referer; 4460 } else if ( $this->preview_url ) {4522 } elseif ( $this->preview_url ) { 4461 4523 $return_url = $this->preview_url; 4462 4524 } else { … … 4509 4571 public function get_nonces() { 4510 4572 $nonces = array( 4511 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),4512 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ),4513 'switch_themes' => wp_create_nonce( 'switch_themes' ),4573 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 4574 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 4575 'switch_themes' => wp_create_nonce( 'switch_themes' ), 4514 4576 'dismiss_autosave_or_lock' => wp_create_nonce( 'customize_dismiss_autosave_or_lock' ), 4515 'override_lock' => wp_create_nonce( 'customize_override_changeset_lock' ),4516 'trash' => wp_create_nonce( 'trash_customize_changeset' ),4577 'override_lock' => wp_create_nonce( 'customize_override_changeset_lock' ), 4578 'trash' => wp_create_nonce( 'trash_customize_changeset' ), 4517 4579 ); 4518 4580 … … 4538 4600 public function customize_pane_settings() { 4539 4601 4540 $login_url = add_query_arg( array( 4541 'interim-login' => 1, 4542 'customize-login' => 1, 4543 ), wp_login_url() ); 4602 $login_url = add_query_arg( 4603 array( 4604 'interim-login' => 1, 4605 'customize-login' => 1, 4606 ), wp_login_url() 4607 ); 4544 4608 4545 4609 // Ensure dirty flags are set for modified settings. … … 4551 4615 } 4552 4616 4553 $autosave_revision_post = null;4617 $autosave_revision_post = null; 4554 4618 $autosave_autodraft_post = null; 4555 $changeset_post_id = $this->changeset_post_id();4619 $changeset_post_id = $this->changeset_post_id(); 4556 4620 if ( ! $this->saved_starter_content_changeset && ! $this->autosaved() ) { 4557 4621 if ( $changeset_post_id ) { 4558 4622 $autosave_revision_post = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); 4559 4623 } else { 4560 $autosave_autodraft_posts = $this->get_changeset_posts( array( 4561 'posts_per_page' => 1, 4562 'post_status' => 'auto-draft', 4563 'exclude_restore_dismissed' => true, 4564 ) ); 4624 $autosave_autodraft_posts = $this->get_changeset_posts( 4625 array( 4626 'posts_per_page' => 1, 4627 'post_status' => 'auto-draft', 4628 'exclude_restore_dismissed' => true, 4629 ) 4630 ); 4565 4631 if ( ! empty( $autosave_autodraft_posts ) ) { 4566 4632 $autosave_autodraft_post = array_shift( $autosave_autodraft_posts ); … … 4576 4642 $status_choices[] = array( 4577 4643 'status' => 'publish', 4578 'label' => __( 'Publish' ),4644 'label' => __( 'Publish' ), 4579 4645 ); 4580 4646 } 4581 4647 $status_choices[] = array( 4582 4648 'status' => 'draft', 4583 'label' => __( 'Save Draft' ),4649 'label' => __( 'Save Draft' ), 4584 4650 ); 4585 4651 if ( $current_user_can_publish ) { 4586 4652 $status_choices[] = array( 4587 4653 'status' => 'future', 4588 'label' => _x( 'Schedule', 'customizer changeset action/button label' ),4654 'label' => _x( 'Schedule', 'customizer changeset action/button label' ), 4589 4655 ); 4590 4656 } … … 4612 4678 4613 4679 $settings = array( 4614 'changeset' => array(4615 'uuid' => $this->changeset_uuid(),4616 'branching' => $this->branching(),4617 'autosaved' => $this->autosaved(),4618 'hasAutosaveRevision' => ! empty( $autosave_revision_post ),4619 'latestAutoDraftUuid' => $autosave_autodraft_post ? $autosave_autodraft_post->post_name : null,4620 'status' => $changeset_post ? $changeset_post->post_status : '',4680 'changeset' => array( 4681 'uuid' => $this->changeset_uuid(), 4682 'branching' => $this->branching(), 4683 'autosaved' => $this->autosaved(), 4684 'hasAutosaveRevision' => ! empty( $autosave_revision_post ), 4685 'latestAutoDraftUuid' => $autosave_autodraft_post ? $autosave_autodraft_post->post_name : null, 4686 'status' => $changeset_post ? $changeset_post->post_status : '', 4621 4687 'currentUserCanPublish' => $current_user_can_publish, 4622 'publishDate' => $initial_date,4623 'statusChoices' => $status_choices,4624 'lockUser' => $lock_user_id ? $this->get_lock_user_data( $lock_user_id ) : null,4688 'publishDate' => $initial_date, 4689 'statusChoices' => $status_choices, 4690 'lockUser' => $lock_user_id ? $this->get_lock_user_data( $lock_user_id ) : null, 4625 4691 ), 4626 'initialServerDate' => $current_time,4627 'dateFormat' => get_option( 'date_format' ),4628 'timeFormat' => get_option( 'time_format' ),4692 'initialServerDate' => $current_time, 4693 'dateFormat' => get_option( 'date_format' ), 4694 'timeFormat' => get_option( 'time_format' ), 4629 4695 'initialServerTimestamp' => floor( microtime( true ) * 1000 ), 4630 4696 'initialClientTimestamp' => -1, // To be set with JS below. 4631 'timeouts' => array(4632 'windowRefresh' => 250,4633 'changesetAutoSave' => AUTOSAVE_INTERVAL * 1000,4634 'keepAliveCheck' => 2500,4635 'reflowPaneContents' => 100,4697 'timeouts' => array( 4698 'windowRefresh' => 250, 4699 'changesetAutoSave' => AUTOSAVE_INTERVAL * 1000, 4700 'keepAliveCheck' => 2500, 4701 'reflowPaneContents' => 100, 4636 4702 'previewFrameSensitivity' => 2000, 4637 4703 ), 4638 'theme' => array(4704 'theme' => array( 4639 4705 'stylesheet' => $this->get_stylesheet(), 4640 4706 'active' => $this->is_theme_active(), 4641 4707 ), 4642 'url' => array(4708 'url' => array( 4643 4709 'preview' => esc_url_raw( $this->get_preview_url() ), 4644 4710 'return' => esc_url_raw( $this->get_return_url() ), … … 4651 4717 'login' => esc_url_raw( $login_url ), 4652 4718 ), 4653 'browser' => array(4719 'browser' => array( 4654 4720 'mobile' => wp_is_mobile(), 4655 4721 'ios' => $this->is_ios(), 4656 4722 ), 4657 'panels' => array(),4658 'sections' => array(),4659 'nonce' => $this->get_nonces(),4660 'autofocus' => $this->get_autofocus(),4661 'documentTitleTmpl' => $this->get_document_title_template(),4662 'previewableDevices' => $this->get_previewable_devices(),4663 'l10n' => array(4664 'confirmDeleteTheme' => __( 'Are you sure you want to delete this theme?' ),4723 'panels' => array(), 4724 'sections' => array(), 4725 'nonce' => $this->get_nonces(), 4726 'autofocus' => $this->get_autofocus(), 4727 'documentTitleTmpl' => $this->get_document_title_template(), 4728 'previewableDevices' => $this->get_previewable_devices(), 4729 'l10n' => array( 4730 'confirmDeleteTheme' => __( 'Are you sure you want to delete this theme?' ), 4665 4731 /* translators: %d: number of theme search results, which cannot currently consider singular vs. plural forms */ 4666 'themeSearchResults' => __( '%d themes found' ),4732 'themeSearchResults' => __( '%d themes found' ), 4667 4733 /* translators: %d: number of themes being displayed, which cannot currently consider singular vs. plural forms */ 4668 'announceThemeCount' => __( 'Displaying %d themes' ),4734 'announceThemeCount' => __( 'Displaying %d themes' ), 4669 4735 /* translators: %s: theme name */ 4670 4736 'announceThemeDetails' => __( 'Showing details for theme: %s' ), … … 4748 4814 $devices = array( 4749 4815 'desktop' => array( 4750 'label' => __( 'Enter desktop preview mode' ),4816 'label' => __( 'Enter desktop preview mode' ), 4751 4817 'default' => true, 4752 4818 ), 4753 'tablet' => array(4819 'tablet' => array( 4754 4820 'label' => __( 'Enter tablet preview mode' ), 4755 4821 ), 4756 'mobile' => array(4822 'mobile' => array( 4757 4823 'label' => __( 'Enter mobile preview mode' ), 4758 4824 ), … … 4782 4848 /* Themes (controls are loaded via ajax) */ 4783 4849 4784 $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( 4785 'title' => $this->theme()->display( 'Name' ), 4786 'description' => ( 4787 '<p>' . __( 'Looking for a theme? You can search or browse the WordPress.org theme directory, install and preview themes, then activate them right here.' ) . '</p>' . 4788 '<p>' . __( 'While previewing a new theme, you can continue to tailor things like widgets and menus, and explore theme-specific options.' ) . '</p>' 4789 ), 4790 'capability' => 'switch_themes', 4791 'priority' => 0, 4792 ) ) ); 4793 4794 $this->add_section( new WP_Customize_Themes_Section( $this, 'installed_themes', array( 4795 'title' => __( 'Installed themes' ), 4796 'action' => 'installed', 4797 'capability' => 'switch_themes', 4798 'panel' => 'themes', 4799 'priority' => 0, 4800 ) ) ); 4850 $this->add_panel( 4851 new WP_Customize_Themes_Panel( 4852 $this, 'themes', array( 4853 'title' => $this->theme()->display( 'Name' ), 4854 'description' => ( 4855 '<p>' . __( 'Looking for a theme? You can search or browse the WordPress.org theme directory, install and preview themes, then activate them right here.' ) . '</p>' . 4856 '<p>' . __( 'While previewing a new theme, you can continue to tailor things like widgets and menus, and explore theme-specific options.' ) . '</p>' 4857 ), 4858 'capability' => 'switch_themes', 4859 'priority' => 0, 4860 ) 4861 ) 4862 ); 4863 4864 $this->add_section( 4865 new WP_Customize_Themes_Section( 4866 $this, 'installed_themes', array( 4867 'title' => __( 'Installed themes' ), 4868 'action' => 'installed', 4869 'capability' => 'switch_themes', 4870 'panel' => 'themes', 4871 'priority' => 0, 4872 ) 4873 ) 4874 ); 4801 4875 4802 4876 if ( ! is_multisite() ) { 4803 $this->add_section( new WP_Customize_Themes_Section( $this, 'wporg_themes', array( 4804 'title' => __( 'WordPress.org themes' ), 4805 'action' => 'wporg', 4806 'filter_type' => 'remote', 4807 'capability' => 'install_themes', 4808 'panel' => 'themes', 4809 'priority' => 5, 4810 ) ) ); 4877 $this->add_section( 4878 new WP_Customize_Themes_Section( 4879 $this, 'wporg_themes', array( 4880 'title' => __( 'WordPress.org themes' ), 4881 'action' => 'wporg', 4882 'filter_type' => 'remote', 4883 'capability' => 'install_themes', 4884 'panel' => 'themes', 4885 'priority' => 5, 4886 ) 4887 ) 4888 ); 4811 4889 } 4812 4890 4813 4891 // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience). 4814 $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array( 4815 'capability' => 'switch_themes', 4816 ) ) ); 4892 $this->add_setting( 4893 new WP_Customize_Filter_Setting( 4894 $this, 'active_theme', array( 4895 'capability' => 'switch_themes', 4896 ) 4897 ) 4898 ); 4817 4899 4818 4900 /* Site Identity */ 4819 4901 4820 $this->add_section( 'title_tagline', array( 4821 'title' => __( 'Site Identity' ), 4822 'priority' => 20, 4823 ) ); 4824 4825 $this->add_setting( 'blogname', array( 4826 'default' => get_option( 'blogname' ), 4827 'type' => 'option', 4828 'capability' => 'manage_options', 4829 ) ); 4830 4831 $this->add_control( 'blogname', array( 4832 'label' => __( 'Site Title' ), 4833 'section' => 'title_tagline', 4834 ) ); 4835 4836 $this->add_setting( 'blogdescription', array( 4837 'default' => get_option( 'blogdescription' ), 4838 'type' => 'option', 4839 'capability' => 'manage_options', 4840 ) ); 4841 4842 $this->add_control( 'blogdescription', array( 4843 'label' => __( 'Tagline' ), 4844 'section' => 'title_tagline', 4845 ) ); 4902 $this->add_section( 4903 'title_tagline', array( 4904 'title' => __( 'Site Identity' ), 4905 'priority' => 20, 4906 ) 4907 ); 4908 4909 $this->add_setting( 4910 'blogname', array( 4911 'default' => get_option( 'blogname' ), 4912 'type' => 'option', 4913 'capability' => 'manage_options', 4914 ) 4915 ); 4916 4917 $this->add_control( 4918 'blogname', array( 4919 'label' => __( 'Site Title' ), 4920 'section' => 'title_tagline', 4921 ) 4922 ); 4923 4924 $this->add_setting( 4925 'blogdescription', array( 4926 'default' => get_option( 'blogdescription' ), 4927 'type' => 'option', 4928 'capability' => 'manage_options', 4929 ) 4930 ); 4931 4932 $this->add_control( 4933 'blogdescription', array( 4934 'label' => __( 'Tagline' ), 4935 'section' => 'title_tagline', 4936 ) 4937 ); 4846 4938 4847 4939 // Add a setting to hide header text if the theme doesn't support custom headers. 4848 4940 if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) { 4849 $this->add_setting( 'header_text', array( 4850 'theme_supports' => array( 'custom-logo', 'header-text' ), 4851 'default' => 1, 4852 'sanitize_callback' => 'absint', 4853 ) ); 4854 4855 $this->add_control( 'header_text', array( 4941 $this->add_setting( 4942 'header_text', array( 4943 'theme_supports' => array( 'custom-logo', 'header-text' ), 4944 'default' => 1, 4945 'sanitize_callback' => 'absint', 4946 ) 4947 ); 4948 4949 $this->add_control( 4950 'header_text', array( 4951 'label' => __( 'Display Site Title and Tagline' ), 4952 'section' => 'title_tagline', 4953 'settings' => 'header_text', 4954 'type' => 'checkbox', 4955 ) 4956 ); 4957 } 4958 4959 $this->add_setting( 4960 'site_icon', array( 4961 'type' => 'option', 4962 'capability' => 'manage_options', 4963 'transport' => 'postMessage', // Previewed with JS in the Customizer controls window. 4964 ) 4965 ); 4966 4967 $this->add_control( 4968 new WP_Customize_Site_Icon_Control( 4969 $this, 'site_icon', array( 4970 'label' => __( 'Site Icon' ), 4971 'description' => sprintf( 4972 '<p>' . __( 'Site Icons are what you see in browser tabs, bookmark bars, and within the WordPress mobile apps. Upload one here!' ) . '</p>' . 4973 /* translators: %s: site icon size in pixels */ 4974 '<p>' . __( 'Site Icons should be square and at least %s pixels.' ) . '</p>', 4975 '<strong>512 × 512</strong>' 4976 ), 4977 'section' => 'title_tagline', 4978 'priority' => 60, 4979 'height' => 512, 4980 'width' => 512, 4981 ) 4982 ) 4983 ); 4984 4985 $this->add_setting( 4986 'custom_logo', array( 4987 'theme_supports' => array( 'custom-logo' ), 4988 'transport' => 'postMessage', 4989 ) 4990 ); 4991 4992 $custom_logo_args = get_theme_support( 'custom-logo' ); 4993 $this->add_control( 4994 new WP_Customize_Cropped_Image_Control( 4995 $this, 'custom_logo', array( 4996 'label' => __( 'Logo' ), 4997 'section' => 'title_tagline', 4998 'priority' => 8, 4999 'height' => $custom_logo_args[0]['height'], 5000 'width' => $custom_logo_args[0]['width'], 5001 'flex_height' => $custom_logo_args[0]['flex-height'], 5002 'flex_width' => $custom_logo_args[0]['flex-width'], 5003 'button_labels' => array( 5004 'select' => __( 'Select logo' ), 5005 'change' => __( 'Change logo' ), 5006 'remove' => __( 'Remove' ), 5007 'default' => __( 'Default' ), 5008 'placeholder' => __( 'No logo selected' ), 5009 'frame_title' => __( 'Select logo' ), 5010 'frame_button' => __( 'Choose logo' ), 5011 ), 5012 ) 5013 ) 5014 ); 5015 5016 $this->selective_refresh->add_partial( 5017 'custom_logo', array( 5018 'settings' => array( 'custom_logo' ), 5019 'selector' => '.custom-logo-link', 5020 'render_callback' => array( $this, '_render_custom_logo_partial' ), 5021 'container_inclusive' => true, 5022 ) 5023 ); 5024 5025 /* Colors */ 5026 5027 $this->add_section( 5028 'colors', array( 5029 'title' => __( 'Colors' ), 5030 'priority' => 40, 5031 ) 5032 ); 5033 5034 $this->add_setting( 5035 'header_textcolor', array( 5036 'theme_supports' => array( 'custom-header', 'header-text' ), 5037 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 5038 5039 'sanitize_callback' => array( $this, '_sanitize_header_textcolor' ), 5040 'sanitize_js_callback' => 'maybe_hash_hex_color', 5041 ) 5042 ); 5043 5044 // Input type: checkbox 5045 // With custom value 5046 $this->add_control( 5047 'display_header_text', array( 5048 'settings' => 'header_textcolor', 4856 5049 'label' => __( 'Display Site Title and Tagline' ), 4857 5050 'section' => 'title_tagline', 4858 'settings' => 'header_text',4859 5051 'type' => 'checkbox', 4860 ) ); 4861 } 4862 4863 $this->add_setting( 'site_icon', array( 4864 'type' => 'option', 4865 'capability' => 'manage_options', 4866 'transport' => 'postMessage', // Previewed with JS in the Customizer controls window. 4867 ) ); 4868 4869 $this->add_control( new WP_Customize_Site_Icon_Control( $this, 'site_icon', array( 4870 'label' => __( 'Site Icon' ), 4871 'description' => sprintf( 4872 '<p>' . __( 'Site Icons are what you see in browser tabs, bookmark bars, and within the WordPress mobile apps. Upload one here!' ) . '</p>' . 4873 /* translators: %s: site icon size in pixels */ 4874 '<p>' . __( 'Site Icons should be square and at least %s pixels.' ) . '</p>', 4875 '<strong>512 × 512</strong>' 4876 ), 4877 'section' => 'title_tagline', 4878 'priority' => 60, 4879 'height' => 512, 4880 'width' => 512, 4881 ) ) ); 4882 4883 $this->add_setting( 'custom_logo', array( 4884 'theme_supports' => array( 'custom-logo' ), 4885 'transport' => 'postMessage', 4886 ) ); 4887 4888 $custom_logo_args = get_theme_support( 'custom-logo' ); 4889 $this->add_control( new WP_Customize_Cropped_Image_Control( $this, 'custom_logo', array( 4890 'label' => __( 'Logo' ), 4891 'section' => 'title_tagline', 4892 'priority' => 8, 4893 'height' => $custom_logo_args[0]['height'], 4894 'width' => $custom_logo_args[0]['width'], 4895 'flex_height' => $custom_logo_args[0]['flex-height'], 4896 'flex_width' => $custom_logo_args[0]['flex-width'], 4897 'button_labels' => array( 4898 'select' => __( 'Select logo' ), 4899 'change' => __( 'Change logo' ), 4900 'remove' => __( 'Remove' ), 4901 'default' => __( 'Default' ), 4902 'placeholder' => __( 'No logo selected' ), 4903 'frame_title' => __( 'Select logo' ), 4904 'frame_button' => __( 'Choose logo' ), 4905 ), 4906 ) ) ); 4907 4908 $this->selective_refresh->add_partial( 'custom_logo', array( 4909 'settings' => array( 'custom_logo' ), 4910 'selector' => '.custom-logo-link', 4911 'render_callback' => array( $this, '_render_custom_logo_partial' ), 4912 'container_inclusive' => true, 4913 ) ); 4914 4915 /* Colors */ 4916 4917 $this->add_section( 'colors', array( 4918 'title' => __( 'Colors' ), 4919 'priority' => 40, 4920 ) ); 4921 4922 $this->add_setting( 'header_textcolor', array( 4923 'theme_supports' => array( 'custom-header', 'header-text' ), 4924 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 4925 4926 'sanitize_callback' => array( $this, '_sanitize_header_textcolor' ), 4927 'sanitize_js_callback' => 'maybe_hash_hex_color', 4928 ) ); 4929 4930 // Input type: checkbox 4931 // With custom value 4932 $this->add_control( 'display_header_text', array( 4933 'settings' => 'header_textcolor', 4934 'label' => __( 'Display Site Title and Tagline' ), 4935 'section' => 'title_tagline', 4936 'type' => 'checkbox', 4937 'priority' => 40, 4938 ) ); 4939 4940 $this->add_control( new WP_Customize_Color_Control( $this, 'header_textcolor', array( 4941 'label' => __( 'Header Text Color' ), 4942 'section' => 'colors', 4943 ) ) ); 5052 'priority' => 40, 5053 ) 5054 ); 5055 5056 $this->add_control( 5057 new WP_Customize_Color_Control( 5058 $this, 'header_textcolor', array( 5059 'label' => __( 'Header Text Color' ), 5060 'section' => 'colors', 5061 ) 5062 ) 5063 ); 4944 5064 4945 5065 // Input type: Color 4946 5066 // With sanitize_callback 4947 $this->add_setting( 'background_color', array( 4948 'default' => get_theme_support( 'custom-background', 'default-color' ), 4949 'theme_supports' => 'custom-background', 4950 4951 'sanitize_callback' => 'sanitize_hex_color_no_hash', 4952 'sanitize_js_callback' => 'maybe_hash_hex_color', 4953 ) ); 4954 4955 $this->add_control( new WP_Customize_Color_Control( $this, 'background_color', array( 4956 'label' => __( 'Background Color' ), 4957 'section' => 'colors', 4958 ) ) ); 5067 $this->add_setting( 5068 'background_color', array( 5069 'default' => get_theme_support( 'custom-background', 'default-color' ), 5070 'theme_supports' => 'custom-background', 5071 5072 'sanitize_callback' => 'sanitize_hex_color_no_hash', 5073 'sanitize_js_callback' => 'maybe_hash_hex_color', 5074 ) 5075 ); 5076 5077 $this->add_control( 5078 new WP_Customize_Color_Control( 5079 $this, 'background_color', array( 5080 'label' => __( 'Background Color' ), 5081 'section' => 'colors', 5082 ) 5083 ) 5084 ); 4959 5085 4960 5086 /* Custom Header */ 4961 5087 4962 5088 if ( current_theme_supports( 'custom-header', 'video' ) ) { 4963 $title = __( 'Header Media' );5089 $title = __( 'Header Media' ); 4964 5090 $description = '<p>' . __( 'If you add a video, the image will be used as a fallback while the video loads.' ) . '</p>'; 4965 5091 4966 $width = absint( get_theme_support( 'custom-header', 'width' ) );5092 $width = absint( get_theme_support( 'custom-header', 'width' ) ); 4967 5093 $height = absint( get_theme_support( 'custom-header', 'height' ) ); 4968 5094 if ( $width && $height ) { … … 4989 5115 } 4990 5116 } else { 4991 $title = __( 'Header Image' );4992 $description = '';5117 $title = __( 'Header Image' ); 5118 $description = ''; 4993 5119 $control_description = ''; 4994 5120 } 4995 5121 4996 $this->add_section( 'header_image', array( 4997 'title' => $title, 4998 'description' => $description, 4999 'theme_supports' => 'custom-header', 5000 'priority' => 60, 5001 ) ); 5002 5003 $this->add_setting( 'header_video', array( 5004 'theme_supports' => array( 'custom-header', 'video' ), 5005 'transport' => 'postMessage', 5006 'sanitize_callback' => 'absint', 5007 'validate_callback' => array( $this, '_validate_header_video' ), 5008 ) ); 5009 5010 $this->add_setting( 'external_header_video', array( 5011 'theme_supports' => array( 'custom-header', 'video' ), 5012 'transport' => 'postMessage', 5013 'sanitize_callback' => array( $this, '_sanitize_external_header_video' ), 5014 'validate_callback' => array( $this, '_validate_external_header_video' ), 5015 ) ); 5016 5017 $this->add_setting( new WP_Customize_Filter_Setting( $this, 'header_image', array( 5018 'default' => sprintf( get_theme_support( 'custom-header', 'default-image' ), get_template_directory_uri(), get_stylesheet_directory_uri() ), 5019 'theme_supports' => 'custom-header', 5020 ) ) ); 5021 5022 $this->add_setting( new WP_Customize_Header_Image_Setting( $this, 'header_image_data', array( 5023 'theme_supports' => 'custom-header', 5024 ) ) ); 5122 $this->add_section( 5123 'header_image', array( 5124 'title' => $title, 5125 'description' => $description, 5126 'theme_supports' => 'custom-header', 5127 'priority' => 60, 5128 ) 5129 ); 5130 5131 $this->add_setting( 5132 'header_video', array( 5133 'theme_supports' => array( 'custom-header', 'video' ), 5134 'transport' => 'postMessage', 5135 'sanitize_callback' => 'absint', 5136 'validate_callback' => array( $this, '_validate_header_video' ), 5137 ) 5138 ); 5139 5140 $this->add_setting( 5141 'external_header_video', array( 5142 'theme_supports' => array( 'custom-header', 'video' ), 5143 'transport' => 'postMessage', 5144 'sanitize_callback' => array( $this, '_sanitize_external_header_video' ), 5145 'validate_callback' => array( $this, '_validate_external_header_video' ), 5146 ) 5147 ); 5148 5149 $this->add_setting( 5150 new WP_Customize_Filter_Setting( 5151 $this, 'header_image', array( 5152 'default' => sprintf( get_theme_support( 'custom-header', 'default-image' ), get_template_directory_uri(), get_stylesheet_directory_uri() ), 5153 'theme_supports' => 'custom-header', 5154 ) 5155 ) 5156 ); 5157 5158 $this->add_setting( 5159 new WP_Customize_Header_Image_Setting( 5160 $this, 'header_image_data', array( 5161 'theme_supports' => 'custom-header', 5162 ) 5163 ) 5164 ); 5025 5165 5026 5166 /* … … 5030 5170 */ 5031 5171 if ( current_theme_supports( 'custom-header', 'video' ) ) { 5032 $this->get_setting( 'header_image' )->transport = 'postMessage';5172 $this->get_setting( 'header_image' )->transport = 'postMessage'; 5033 5173 $this->get_setting( 'header_image_data' )->transport = 'postMessage'; 5034 5174 } 5035 5175 5036 $this->add_control( new WP_Customize_Media_Control( $this, 'header_video', array( 5037 'theme_supports' => array( 'custom-header', 'video' ), 5038 'label' => __( 'Header Video' ), 5039 'description' => $control_description, 5040 'section' => 'header_image', 5041 'mime_type' => 'video', 5042 'active_callback' => 'is_header_video_active', 5043 ) ) ); 5044 5045 $this->add_control( 'external_header_video', array( 5046 'theme_supports' => array( 'custom-header', 'video' ), 5047 'type' => 'url', 5048 'description' => __( 'Or, enter a YouTube URL:' ), 5049 'section' => 'header_image', 5050 'active_callback' => 'is_header_video_active', 5051 ) ); 5176 $this->add_control( 5177 new WP_Customize_Media_Control( 5178 $this, 'header_video', array( 5179 'theme_supports' => array( 'custom-header', 'video' ), 5180 'label' => __( 'Header Video' ), 5181 'description' => $control_description, 5182 'section' => 'header_image', 5183 'mime_type' => 'video', 5184 'active_callback' => 'is_header_video_active', 5185 ) 5186 ) 5187 ); 5188 5189 $this->add_control( 5190 'external_header_video', array( 5191 'theme_supports' => array( 'custom-header', 'video' ), 5192 'type' => 'url', 5193 'description' => __( 'Or, enter a YouTube URL:' ), 5194 'section' => 'header_image', 5195 'active_callback' => 'is_header_video_active', 5196 ) 5197 ); 5052 5198 5053 5199 $this->add_control( new WP_Customize_Header_Image_Control( $this ) ); 5054 5200 5055 $this->selective_refresh->add_partial( 'custom_header', array( 5056 'selector' => '#wp-custom-header', 5057 'render_callback' => 'the_custom_header_markup', 5058 'settings' => array( 'header_video', 'external_header_video', 'header_image' ), // The image is used as a video fallback here. 5059 'container_inclusive' => true, 5060 ) ); 5201 $this->selective_refresh->add_partial( 5202 'custom_header', array( 5203 'selector' => '#wp-custom-header', 5204 'render_callback' => 'the_custom_header_markup', 5205 'settings' => array( 'header_video', 'external_header_video', 'header_image' ), // The image is used as a video fallback here. 5206 'container_inclusive' => true, 5207 ) 5208 ); 5061 5209 5062 5210 /* Custom Background */ 5063 5211 5064 $this->add_section( 'background_image', array( 5065 'title' => __( 'Background Image' ), 5066 'theme_supports' => 'custom-background', 5067 'priority' => 80, 5068 ) ); 5069 5070 $this->add_setting( 'background_image', array( 5071 'default' => get_theme_support( 'custom-background', 'default-image' ), 5072 'theme_supports' => 'custom-background', 5073 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5074 ) ); 5075 5076 $this->add_setting( new WP_Customize_Background_Image_Setting( $this, 'background_image_thumb', array( 5077 'theme_supports' => 'custom-background', 5078 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5079 ) ) ); 5212 $this->add_section( 5213 'background_image', array( 5214 'title' => __( 'Background Image' ), 5215 'theme_supports' => 'custom-background', 5216 'priority' => 80, 5217 ) 5218 ); 5219 5220 $this->add_setting( 5221 'background_image', array( 5222 'default' => get_theme_support( 'custom-background', 'default-image' ), 5223 'theme_supports' => 'custom-background', 5224 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5225 ) 5226 ); 5227 5228 $this->add_setting( 5229 new WP_Customize_Background_Image_Setting( 5230 $this, 'background_image_thumb', array( 5231 'theme_supports' => 'custom-background', 5232 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5233 ) 5234 ) 5235 ); 5080 5236 5081 5237 $this->add_control( new WP_Customize_Background_Image_Control( $this ) ); 5082 5238 5083 $this->add_setting( 'background_preset', array( 5084 'default' => get_theme_support( 'custom-background', 'default-preset' ), 5085 'theme_supports' => 'custom-background', 5086 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5087 ) ); 5088 5089 $this->add_control( 'background_preset', array( 5090 'label' => _x( 'Preset', 'Background Preset' ), 5091 'section' => 'background_image', 5092 'type' => 'select', 5093 'choices' => array( 5094 'default' => _x( 'Default', 'Default Preset' ), 5095 'fill' => __( 'Fill Screen' ), 5096 'fit' => __( 'Fit to Screen' ), 5097 'repeat' => _x( 'Repeat', 'Repeat Image' ), 5098 'custom' => _x( 'Custom', 'Custom Preset' ), 5099 ), 5100 ) ); 5101 5102 $this->add_setting( 'background_position_x', array( 5103 'default' => get_theme_support( 'custom-background', 'default-position-x' ), 5104 'theme_supports' => 'custom-background', 5105 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5106 ) ); 5107 5108 $this->add_setting( 'background_position_y', array( 5109 'default' => get_theme_support( 'custom-background', 'default-position-y' ), 5110 'theme_supports' => 'custom-background', 5111 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5112 ) ); 5113 5114 $this->add_control( new WP_Customize_Background_Position_Control( $this, 'background_position', array( 5115 'label' => __( 'Image Position' ), 5116 'section' => 'background_image', 5117 'settings' => array( 5118 'x' => 'background_position_x', 5119 'y' => 'background_position_y', 5120 ), 5121 ) ) ); 5122 5123 $this->add_setting( 'background_size', array( 5124 'default' => get_theme_support( 'custom-background', 'default-size' ), 5125 'theme_supports' => 'custom-background', 5126 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5127 ) ); 5128 5129 $this->add_control( 'background_size', array( 5130 'label' => __( 'Image Size' ), 5131 'section' => 'background_image', 5132 'type' => 'select', 5133 'choices' => array( 5134 'auto' => __( 'Original' ), 5135 'contain' => __( 'Fit to Screen' ), 5136 'cover' => __( 'Fill Screen' ), 5137 ), 5138 ) ); 5139 5140 $this->add_setting( 'background_repeat', array( 5141 'default' => get_theme_support( 'custom-background', 'default-repeat' ), 5142 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5143 'theme_supports' => 'custom-background', 5144 ) ); 5145 5146 $this->add_control( 'background_repeat', array( 5147 'label' => __( 'Repeat Background Image' ), 5148 'section' => 'background_image', 5149 'type' => 'checkbox', 5150 ) ); 5151 5152 $this->add_setting( 'background_attachment', array( 5153 'default' => get_theme_support( 'custom-background', 'default-attachment' ), 5154 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5155 'theme_supports' => 'custom-background', 5156 ) ); 5157 5158 $this->add_control( 'background_attachment', array( 5159 'label' => __( 'Scroll with Page' ), 5160 'section' => 'background_image', 5161 'type' => 'checkbox', 5162 ) ); 5163 5239 $this->add_setting( 5240 'background_preset', array( 5241 'default' => get_theme_support( 'custom-background', 'default-preset' ), 5242 'theme_supports' => 'custom-background', 5243 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5244 ) 5245 ); 5246 5247 $this->add_control( 5248 'background_preset', array( 5249 'label' => _x( 'Preset', 'Background Preset' ), 5250 'section' => 'background_image', 5251 'type' => 'select', 5252 'choices' => array( 5253 'default' => _x( 'Default', 'Default Preset' ), 5254 'fill' => __( 'Fill Screen' ), 5255 'fit' => __( 'Fit to Screen' ), 5256 'repeat' => _x( 'Repeat', 'Repeat Image' ), 5257 'custom' => _x( 'Custom', 'Custom Preset' ), 5258 ), 5259 ) 5260 ); 5261 5262 $this->add_setting( 5263 'background_position_x', array( 5264 'default' => get_theme_support( 'custom-background', 'default-position-x' ), 5265 'theme_supports' => 'custom-background', 5266 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5267 ) 5268 ); 5269 5270 $this->add_setting( 5271 'background_position_y', array( 5272 'default' => get_theme_support( 'custom-background', 'default-position-y' ), 5273 'theme_supports' => 'custom-background', 5274 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5275 ) 5276 ); 5277 5278 $this->add_control( 5279 new WP_Customize_Background_Position_Control( 5280 $this, 'background_position', array( 5281 'label' => __( 'Image Position' ), 5282 'section' => 'background_image', 5283 'settings' => array( 5284 'x' => 'background_position_x', 5285 'y' => 'background_position_y', 5286 ), 5287 ) 5288 ) 5289 ); 5290 5291 $this->add_setting( 5292 'background_size', array( 5293 'default' => get_theme_support( 'custom-background', 'default-size' ), 5294 'theme_supports' => 'custom-background', 5295 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5296 ) 5297 ); 5298 5299 $this->add_control( 5300 'background_size', array( 5301 'label' => __( 'Image Size' ), 5302 'section' => 'background_image', 5303 'type' => 'select', 5304 'choices' => array( 5305 'auto' => __( 'Original' ), 5306 'contain' => __( 'Fit to Screen' ), 5307 'cover' => __( 'Fill Screen' ), 5308 ), 5309 ) 5310 ); 5311 5312 $this->add_setting( 5313 'background_repeat', array( 5314 'default' => get_theme_support( 'custom-background', 'default-repeat' ), 5315 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5316 'theme_supports' => 'custom-background', 5317 ) 5318 ); 5319 5320 $this->add_control( 5321 'background_repeat', array( 5322 'label' => __( 'Repeat Background Image' ), 5323 'section' => 'background_image', 5324 'type' => 'checkbox', 5325 ) 5326 ); 5327 5328 $this->add_setting( 5329 'background_attachment', array( 5330 'default' => get_theme_support( 'custom-background', 'default-attachment' ), 5331 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 5332 'theme_supports' => 'custom-background', 5333 ) 5334 ); 5335 5336 $this->add_control( 5337 'background_attachment', array( 5338 'label' => __( 'Scroll with Page' ), 5339 'section' => 'background_image', 5340 'type' => 'checkbox', 5341 ) 5342 ); 5164 5343 5165 5344 // If the theme is using the default background callback, we can update … … 5177 5356 */ 5178 5357 5179 $this->add_section( 'static_front_page', array( 5180 'title' => __( 'Homepage Settings' ), 5181 'priority' => 120, 5182 'description' => __( 'You can choose what’s displayed on the homepage of your site. It can be posts in reverse chronological order (classic blog), or a fixed/static page. To set a static homepage, you first need to create two Pages. One will become the homepage, and the other will be where your posts are displayed.' ), 5183 'active_callback' => array( $this, 'has_published_pages' ), 5184 ) ); 5185 5186 $this->add_setting( 'show_on_front', array( 5187 'default' => get_option( 'show_on_front' ), 5188 'capability' => 'manage_options', 5189 'type' => 'option', 5190 ) ); 5191 5192 $this->add_control( 'show_on_front', array( 5193 'label' => __( 'Your homepage displays' ), 5194 'section' => 'static_front_page', 5195 'type' => 'radio', 5196 'choices' => array( 5197 'posts' => __( 'Your latest posts' ), 5198 'page' => __( 'A static page' ), 5199 ), 5200 ) ); 5201 5202 $this->add_setting( 'page_on_front', array( 5203 'type' => 'option', 5204 'capability' => 'manage_options', 5205 ) ); 5206 5207 $this->add_control( 'page_on_front', array( 5208 'label' => __( 'Homepage' ), 5209 'section' => 'static_front_page', 5210 'type' => 'dropdown-pages', 5211 'allow_addition' => true, 5212 ) ); 5213 5214 $this->add_setting( 'page_for_posts', array( 5215 'type' => 'option', 5216 'capability' => 'manage_options', 5217 ) ); 5218 5219 $this->add_control( 'page_for_posts', array( 5220 'label' => __( 'Posts page' ), 5221 'section' => 'static_front_page', 5222 'type' => 'dropdown-pages', 5223 'allow_addition' => true, 5224 ) ); 5358 $this->add_section( 5359 'static_front_page', array( 5360 'title' => __( 'Homepage Settings' ), 5361 'priority' => 120, 5362 'description' => __( 'You can choose what’s displayed on the homepage of your site. It can be posts in reverse chronological order (classic blog), or a fixed/static page. To set a static homepage, you first need to create two Pages. One will become the homepage, and the other will be where your posts are displayed.' ), 5363 'active_callback' => array( $this, 'has_published_pages' ), 5364 ) 5365 ); 5366 5367 $this->add_setting( 5368 'show_on_front', array( 5369 'default' => get_option( 'show_on_front' ), 5370 'capability' => 'manage_options', 5371 'type' => 'option', 5372 ) 5373 ); 5374 5375 $this->add_control( 5376 'show_on_front', array( 5377 'label' => __( 'Your homepage displays' ), 5378 'section' => 'static_front_page', 5379 'type' => 'radio', 5380 'choices' => array( 5381 'posts' => __( 'Your latest posts' ), 5382 'page' => __( 'A static page' ), 5383 ), 5384 ) 5385 ); 5386 5387 $this->add_setting( 5388 'page_on_front', array( 5389 'type' => 'option', 5390 'capability' => 'manage_options', 5391 ) 5392 ); 5393 5394 $this->add_control( 5395 'page_on_front', array( 5396 'label' => __( 'Homepage' ), 5397 'section' => 'static_front_page', 5398 'type' => 'dropdown-pages', 5399 'allow_addition' => true, 5400 ) 5401 ); 5402 5403 $this->add_setting( 5404 'page_for_posts', array( 5405 'type' => 'option', 5406 'capability' => 'manage_options', 5407 ) 5408 ); 5409 5410 $this->add_control( 5411 'page_for_posts', array( 5412 'label' => __( 'Posts page' ), 5413 'section' => 'static_front_page', 5414 'type' => 'dropdown-pages', 5415 'allow_addition' => true, 5416 ) 5417 ); 5225 5418 5226 5419 /* Custom CSS */ 5227 $section_description = '<p>';5420 $section_description = '<p>'; 5228 5421 $section_description .= __( 'Add your own CSS code here to customize the appearance and layout of your site.' ); 5229 5422 $section_description .= sprintf( … … 5250 5443 esc_url( get_edit_profile_url() ), 5251 5444 'class="external-link" target="_blank"', 5252 sprintf( '<span class="screen-reader-text"> %s</span>', 5445 sprintf( 5446 '<span class="screen-reader-text"> %s</span>', 5253 5447 /* translators: accessibility text */ 5254 5448 __( '(opens in a new window)' ) … … 5262 5456 $section_description .= '</p>'; 5263 5457 5264 $this->add_section( 'custom_css', array( 5265 'title' => __( 'Additional CSS' ), 5266 'priority' => 200, 5267 'description_hidden' => true, 5268 'description' => $section_description, 5269 ) ); 5270 5271 $custom_css_setting = new WP_Customize_Custom_CSS_Setting( $this, sprintf( 'custom_css[%s]', get_stylesheet() ), array( 5272 'capability' => 'edit_css', 5273 'default' => '', 5274 ) ); 5458 $this->add_section( 5459 'custom_css', array( 5460 'title' => __( 'Additional CSS' ), 5461 'priority' => 200, 5462 'description_hidden' => true, 5463 'description' => $section_description, 5464 ) 5465 ); 5466 5467 $custom_css_setting = new WP_Customize_Custom_CSS_Setting( 5468 $this, sprintf( 'custom_css[%s]', get_stylesheet() ), array( 5469 'capability' => 'edit_css', 5470 'default' => '', 5471 ) 5472 ); 5275 5473 $this->add_setting( $custom_css_setting ); 5276 5474 5277 $this->add_control( new WP_Customize_Code_Editor_Control( $this, 'custom_css', array( 5278 'label' => __( 'CSS code' ), 5279 'section' => 'custom_css', 5280 'settings' => array( 'default' => $custom_css_setting->id ), 5281 'code_type' => 'text/css', 5282 'input_attrs' => array( 5283 'aria-describedby' => 'editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4', 5284 ), 5285 ) ) ); 5475 $this->add_control( 5476 new WP_Customize_Code_Editor_Control( 5477 $this, 'custom_css', array( 5478 'label' => __( 'CSS code' ), 5479 'section' => 'custom_css', 5480 'settings' => array( 'default' => $custom_css_setting->id ), 5481 'code_type' => 'text/css', 5482 'input_attrs' => array( 5483 'aria-describedby' => 'editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4', 5484 ), 5485 ) 5486 ) 5487 ); 5286 5488 } 5287 5489 … … 5336 5538 } 5337 5539 $theme_action = sanitize_key( $_POST['theme_action'] ); 5338 $themes = array();5339 $args = array();5540 $themes = array(); 5541 $args = array(); 5340 5542 5341 5543 // Define query filters based on user input. … … 5365 5567 $themes = array( 'themes' => wp_prepare_themes_for_js() ); 5366 5568 foreach ( $themes['themes'] as &$theme ) { 5367 $theme['type'] = 'installed';5569 $theme['type'] = 'installed'; 5368 5570 $theme['active'] = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] ); 5369 5571 } 5370 5371 5572 } elseif ( 'wporg' === $theme_action ) { 5372 5573 … … 5379 5580 $wporg_args = array( 5380 5581 'per_page' => 100, 5381 'fields' => array(5582 'fields' => array( 5382 5583 'screenshot_url' => true, 5383 'description' => true,5384 'rating' => true,5385 'downloaded' => true,5386 'downloadlink' => true,5387 'last_updated' => true,5388 'homepage' => true,5389 'num_ratings' => true,5390 'tags' => true,5391 'parent' => true,5584 'description' => true, 5585 'rating' => true, 5586 'downloaded' => true, 5587 'downloadlink' => true, 5588 'last_updated' => true, 5589 'homepage' => true, 5590 'num_ratings' => true, 5591 'tags' => true, 5592 'parent' => true, 5392 5593 // 'extended_author' => true, @todo: WordPress.org throws a 500 server error when this is here. 5393 5594 ), … … 5407 5608 5408 5609 // This list matches the allowed tags in wp-admin/includes/theme-install.php. 5409 $themes_allowedtags = array_fill_keys(5610 $themes_allowedtags = array_fill_keys( 5410 5611 array( 'a', 'abbr', 'acronym', 'code', 'pre', 'em', 'strong', 'div', 'p', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img' ), 5411 5612 array() 5412 5613 ); 5413 $themes_allowedtags['a'] = array_fill_keys( array( 'href', 'title', 'target' ), true );5614 $themes_allowedtags['a'] = array_fill_keys( array( 'href', 'title', 'target' ), true ); 5414 5615 $themes_allowedtags['acronym']['title'] = true; 5415 $themes_allowedtags['abbr']['title'] = true;5416 $themes_allowedtags['img'] = array_fill_keys( array( 'src', 'class', 'alt' ), true );5616 $themes_allowedtags['abbr']['title'] = true; 5617 $themes_allowedtags['img'] = array_fill_keys( array( 'src', 'class', 'alt' ), true ); 5417 5618 5418 5619 // Prepare a list of installed themes to check against before the loop. 5419 5620 $installed_themes = array(); 5420 $wp_themes = wp_get_themes();5621 $wp_themes = wp_get_themes(); 5421 5622 foreach ( $wp_themes as $theme ) { 5422 5623 $installed_themes[] = $theme->get_stylesheet(); … … 5426 5627 // Set up properties for themes available on WordPress.org. 5427 5628 foreach ( $themes->themes as &$theme ) { 5428 $theme->install_url = add_query_arg( array( 5429 'theme' => $theme->slug, 5430 '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), 5431 ), $update_php ); 5629 $theme->install_url = add_query_arg( 5630 array( 5631 'theme' => $theme->slug, 5632 '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), 5633 ), $update_php 5634 ); 5432 5635 5433 5636 $theme->name = wp_kses( $theme->name, $themes_allowedtags ); … … 5436 5639 $theme->description = wp_kses( $theme->description, $themes_allowedtags ); 5437 5640 $theme->tags = implode( ', ', $theme->tags ); 5438 $theme->stars = wp_star_rating( array( 5439 'rating' => $theme->rating, 5440 'type' => 'percent', 5441 'number' => $theme->num_ratings, 5442 'echo' => false, 5443 ) ); 5641 $theme->stars = wp_star_rating( 5642 array( 5643 'rating' => $theme->rating, 5644 'type' => 'percent', 5645 'number' => $theme->num_ratings, 5646 'echo' => false, 5647 ) 5648 ); 5444 5649 $theme->num_ratings = number_format_i18n( $theme->num_ratings ); 5445 5650 $theme->preview_url = set_url_scheme( $theme->preview_url ); … … 5506 5711 */ 5507 5712 public function _sanitize_header_textcolor( $color ) { 5508 if ( 'blank' === $color ) 5713 if ( 'blank' === $color ) { 5509 5714 return 'blank'; 5715 } 5510 5716 5511 5717 $color = sanitize_hex_color_no_hash( $color ); 5512 if ( empty( $color ) ) 5718 if ( empty( $color ) ) { 5513 5719 $color = get_theme_support( 'custom-header', 'default-text-color' ); 5720 } 5514 5721 5515 5722 return $color; … … 5592 5799 $size = filesize( $video ); 5593 5800 if ( 8 < $size / pow( 1024, 2 ) ) { // Check whether the size is larger than 8MB. 5594 $validity->add( 'size_too_large', 5801 $validity->add( 5802 'size_too_large', 5595 5803 __( 'This video file is too large to use as a header video. Try a shorter video or optimize the compression settings and re-upload a file that is less than 8MB. Or, upload your video to YouTube and link it with the option below.' ) 5596 5804 ); 5597 5805 } 5598 5806 if ( '.mp4' !== substr( $video, -4 ) && '.mov' !== substr( $video, -4 ) ) { // Check for .mp4 or .mov format, which (assuming h.264 encoding) are the only cross-browser-supported formats. 5599 $validity->add( 'invalid_file_type', sprintf( 5600 /* translators: 1: .mp4, 2: .mov */ 5601 __( 'Only %1$s or %2$s files may be used for header video. Please convert your video file and try again, or, upload your video to YouTube and link it with the option below.' ), 5602 '<code>.mp4</code>', 5603 '<code>.mov</code>' 5604 ) ); 5807 $validity->add( 5808 'invalid_file_type', sprintf( 5809 /* translators: 1: .mp4, 2: .mov */ 5810 __( 'Only %1$s or %2$s files may be used for header video. Please convert your video file and try again, or, upload your video to YouTube and link it with the option below.' ), 5811 '<code>.mp4</code>', 5812 '<code>.mov</code>' 5813 ) 5814 ); 5605 5815 } 5606 5816 }
Note: See TracChangeset
for help on using the changeset viewer.