820 ), |
821 ), |
821 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), |
822 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), |
822 ); |
823 ); |
823 |
824 |
824 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { |
825 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { |
825 unset( $registered_widget['callback'] ); // May not be JSON-serializeable. |
826 unset( $registered_widget['callback'] ); // May not be JSON-serializable. |
826 } |
827 } |
827 |
828 |
828 $wp_scripts->add_data( |
829 $wp_scripts->add_data( |
829 'customize-widgets', |
830 'customize-widgets', |
830 'data', |
831 'data', |
888 ?> |
889 ?> |
889 <div id="widgets-left"><!-- compatibility with JS which looks for widget templates here --> |
890 <div id="widgets-left"><!-- compatibility with JS which looks for widget templates here --> |
890 <div id="available-widgets"> |
891 <div id="available-widgets"> |
891 <div class="customize-section-title"> |
892 <div class="customize-section-title"> |
892 <button class="customize-section-back" tabindex="-1"> |
893 <button class="customize-section-back" tabindex="-1"> |
893 <span class="screen-reader-text"><?php _e( 'Back' ); ?></span> |
894 <span class="screen-reader-text"> |
|
895 <?php |
|
896 /* translators: Hidden accessibility text. */ |
|
897 _e( 'Back' ); |
|
898 ?> |
|
899 </span> |
894 </button> |
900 </button> |
895 <h3> |
901 <h3> |
896 <span class="customize-action"> |
902 <span class="customize-action"> |
897 <?php |
903 <?php |
898 /* translators: ▸ is the unicode right-pointing triangle. %s: Section title in the Customizer. */ |
904 /* translators: ▸ is the unicode right-pointing triangle. %s: Section title in the Customizer. */ |
901 </span> |
907 </span> |
902 <?php _e( 'Add a Widget' ); ?> |
908 <?php _e( 'Add a Widget' ); ?> |
903 </h3> |
909 </h3> |
904 </div> |
910 </div> |
905 <div id="available-widgets-filter"> |
911 <div id="available-widgets-filter"> |
906 <label class="screen-reader-text" for="widgets-search"><?php _e( 'Search Widgets' ); ?></label> |
912 <label for="widgets-search"> |
907 <input type="text" id="widgets-search" placeholder="<?php esc_attr_e( 'Search widgets…' ); ?>" aria-describedby="widgets-search-desc" /> |
913 <?php |
|
914 /* translators: Hidden accessibility text. */ |
|
915 _e( 'Search Widgets' ); |
|
916 ?> |
|
917 </label> |
|
918 <input type="text" id="widgets-search" aria-describedby="widgets-search-desc" /> |
908 <div class="search-icon" aria-hidden="true"></div> |
919 <div class="search-icon" aria-hidden="true"></div> |
909 <button type="button" class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></button> |
920 <button type="button" class="clear-results"><span class="screen-reader-text"> |
910 <p class="screen-reader-text" id="widgets-search-desc"><?php _e( 'The search results will be updated as you type.' ); ?></p> |
921 <?php |
|
922 /* translators: Hidden accessibility text. */ |
|
923 _e( 'Clear Results' ); |
|
924 ?> |
|
925 </span></button> |
|
926 <p class="screen-reader-text" id="widgets-search-desc"> |
|
927 <?php |
|
928 /* translators: Hidden accessibility text. */ |
|
929 _e( 'The search results will be updated as you type.' ); |
|
930 ?> |
|
931 </p> |
911 </div> |
932 </div> |
912 <div id="available-widgets-list"> |
933 <div id="available-widgets-list"> |
913 <?php foreach ( $this->get_available_widgets() as $available_widget ) : ?> |
934 <?php foreach ( $this->get_available_widgets() as $available_widget ) : ?> |
914 <div id="widget-tpl-<?php echo esc_attr( $available_widget['id'] ); ?>" data-widget-id="<?php echo esc_attr( $available_widget['id'] ); ?>" class="widget-tpl <?php echo esc_attr( $available_widget['id'] ); ?>" tabindex="0"> |
935 <div id="widget-tpl-<?php echo esc_attr( $available_widget['id'] ); ?>" data-widget-id="<?php echo esc_attr( $available_widget['id'] ); ?>" class="widget-tpl <?php echo esc_attr( $available_widget['id'] ); ?>" tabindex="0"> |
915 <?php echo $available_widget['control_tpl']; ?> |
936 <?php echo $available_widget['control_tpl']; ?> |
959 $args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' ); |
980 $args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' ); |
960 $args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' ); |
981 $args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' ); |
961 $args['transport'] = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh'; |
982 $args['transport'] = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh'; |
962 } elseif ( preg_match( $this->setting_id_patterns['widget_instance'], $id, $matches ) ) { |
983 } elseif ( preg_match( $this->setting_id_patterns['widget_instance'], $id, $matches ) ) { |
963 $id_base = $matches['id_base']; |
984 $id_base = $matches['id_base']; |
964 $args['sanitize_callback'] = function( $value ) use ( $id_base ) { |
985 $args['sanitize_callback'] = function ( $value ) use ( $id_base ) { |
965 return $this->sanitize_widget_instance( $value, $id_base ); |
986 return $this->sanitize_widget_instance( $value, $id_base ); |
966 }; |
987 }; |
967 $args['sanitize_js_callback'] = function( $value ) use ( $id_base ) { |
988 $args['sanitize_js_callback'] = function ( $value ) use ( $id_base ) { |
968 return $this->sanitize_widget_js_instance( $value, $id_base ); |
989 return $this->sanitize_widget_js_instance( $value, $id_base ); |
969 }; |
990 }; |
970 $args['transport'] = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh'; |
991 $args['transport'] = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh'; |
971 } |
992 } |
972 |
993 |
1261 * @global array $wp_registered_widgets |
1282 * @global array $wp_registered_widgets |
1262 */ |
1283 */ |
1263 public function export_preview_data() { |
1284 public function export_preview_data() { |
1264 global $wp_registered_sidebars, $wp_registered_widgets; |
1285 global $wp_registered_sidebars, $wp_registered_widgets; |
1265 |
1286 |
1266 $switched_locale = switch_to_locale( get_user_locale() ); |
1287 $switched_locale = switch_to_user_locale( get_current_user_id() ); |
1267 |
1288 |
1268 $l10n = array( |
1289 $l10n = array( |
1269 'widgetTooltip' => __( 'Shift-click to edit this widget.' ), |
1290 'widgetTooltip' => __( 'Shift-click to edit this widget.' ), |
1270 ); |
1291 ); |
1271 |
1292 |
1285 'l10n' => $l10n, |
1306 'l10n' => $l10n, |
1286 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), |
1307 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), |
1287 ); |
1308 ); |
1288 |
1309 |
1289 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { |
1310 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { |
1290 unset( $registered_widget['callback'] ); // May not be JSON-serializeable. |
1311 unset( $registered_widget['callback'] ); // May not be JSON-serializable. |
1291 } |
1312 } |
1292 |
1313 wp_print_inline_script_tag( |
1293 ?> |
1314 sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings ) ) |
1294 <script type="text/javascript"> |
1315 ); |
1295 var _wpWidgetCustomizerPreviewSettings = <?php echo wp_json_encode( $settings ); ?>; |
|
1296 </script> |
|
1297 <?php |
|
1298 } |
1316 } |
1299 |
1317 |
1300 /** |
1318 /** |
1301 * Tracks the widgets that were rendered. |
1319 * Tracks the widgets that were rendered. |
1302 * |
1320 * |
2036 * |
2054 * |
2037 * @param string $option_name Option name. |
2055 * @param string $option_name Option name. |
2038 * @return bool Whether the option capture is ignored. |
2056 * @return bool Whether the option capture is ignored. |
2039 */ |
2057 */ |
2040 protected function is_option_capture_ignored( $option_name ) { |
2058 protected function is_option_capture_ignored( $option_name ) { |
2041 return ( 0 === strpos( $option_name, '_transient_' ) ); |
2059 return ( str_starts_with( $option_name, '_transient_' ) ); |
2042 } |
2060 } |
2043 |
2061 |
2044 /** |
2062 /** |
2045 * Retrieves captured widget option updates. |
2063 * Retrieves captured widget option updates. |
2046 * |
2064 * |