~canonical-sysadmins/wordpress/4.1.3

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-customize-widgets.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:05:37 UTC
  • mfrom: (1.1.1 wp4-upstream)
  • Revision ID: nick.moffitt@canonical.com-20150115110537-8bp1y42eyg0jsa7c
Tags: 4.1
MergeĀ upstreamĀ versionĀ 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
        /**
117
117
         * Set up widget addition previews.
118
118
         *
119
 
         * Since the widgets get registered on 'widgets_init' before the customizer
 
119
         * Since the widgets get registered on 'widgets_init' before the Customizer
120
120
         * settings are set up on 'customize_register', we have to filter the options
121
121
         * similarly to how the setting previewer will filter the options later.
122
122
         *
146
146
                        return;
147
147
                }
148
148
 
149
 
                // Input from customizer preview.
 
149
                // Input from Customizer preview.
150
150
                if ( isset( $_POST['customized'] ) ) {
151
151
                        $this->_customized = json_decode( $this->get_post_value( 'customized' ), true );
152
152
                } else { // Input from ajax widget update request.
201
201
        /**
202
202
         * Ensure that newly-added widgets will appear in the widgets_sidebars.
203
203
         *
204
 
         * This is necessary because the customizer's setting preview filters
 
204
         * This is necessary because the Customizer's setting preview filters
205
205
         * are added after the widgets_init action, which is too late for the
206
206
         * widgets to be set up properly.
207
207
         *
225
225
         * Ensure newly-added widgets have empty instances so they
226
226
         * will be recognized.
227
227
         *
228
 
         * This is necessary because the customizer's setting preview
 
228
         * This is necessary because the Customizer's setting preview
229
229
         * filters are added after the widgets_init action, which is
230
230
         * too late for the widgets to be set up properly.
231
231
         *
287
287
        /**
288
288
         * Override sidebars_widgets for theme switch.
289
289
         *
290
 
         * When switching a theme via the customizer, supply any previously-configured
 
290
         * When switching a theme via the Customizer, supply any previously-configured
291
291
         * sidebars_widgets from the target theme as the initial sidebars_widgets
292
292
         * setting. Also store the old theme's existing settings so that they can
293
293
         * be passed along for storing in the sidebars_widgets theme_mod when the
313
313
        }
314
314
 
315
315
        /**
316
 
         * Filter old_sidebars_widgets_data customizer setting.
 
316
         * Filter old_sidebars_widgets_data Customizer setting.
317
317
         *
318
318
         * When switching themes, filter the Customizer setting
319
319
         * old_sidebars_widgets_data to supply initial $sidebars_widgets before they
325
325
         * @since 3.9.0
326
326
         * @access public
327
327
         *
328
 
         * @param array $sidebars_widgets
 
328
         * @param array $old_sidebars_widgets
329
329
         */
330
330
        public function filter_customize_value_old_sidebars_widgets_data( $old_sidebars_widgets ) {
331
331
                return $this->old_sidebars_widgets;
388
388
        }
389
389
 
390
390
        /**
391
 
         * Register customizer settings and controls for all sidebars and widgets.
 
391
         * Register Customizer settings and controls for all sidebars and widgets.
392
392
         *
393
393
         * @since 3.9.0
394
394
         * @access public
468
468
                                                'description' => $GLOBALS['wp_registered_sidebars'][ $sidebar_id ]['description'],
469
469
                                                'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
470
470
                                                'panel' => 'widgets',
 
471
                                                'sidebar_id' => $sidebar_id,
471
472
                                        );
472
473
 
473
474
                                        /**
481
482
                                         */
482
483
                                        $section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id );
483
484
 
484
 
                                        $this->manager->add_section( $section_id, $section_args );
 
485
                                        $section = new WP_Customize_Sidebar_Section( $this->manager, $section_id, $section_args );
 
486
                                        $this->manager->add_section( $section );
485
487
 
486
488
                                        $control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array(
487
489
                                                'section'    => $section_id,
534
536
        }
535
537
 
536
538
        /**
537
 
         * Covert a widget_id into its corresponding customizer setting ID (option name).
 
539
         * Covert a widget_id into its corresponding Customizer setting ID (option name).
538
540
         *
539
541
         * @since 3.9.0
540
542
         * @access public
556
558
         * Determine whether the widget is considered "wide".
557
559
         *
558
560
         * Core widgets which may have controls wider than 250, but can
559
 
         * still be shown in the narrow customizer panel. The RSS and Text
 
561
         * still be shown in the narrow Customizer panel. The RSS and Text
560
562
         * widgets in Core, for example, have widths of 400 and yet they
561
 
         * still render fine in the customizer panel. This method will
 
563
         * still render fine in the Customizer panel. This method will
562
564
         * return all Core widgets as being not wide, but this can be
563
565
         * overridden with the is_wide_widget_in_customizer filter.
564
566
         *
664
666
        }
665
667
 
666
668
        /**
667
 
         * Enqueue scripts and styles for customizer panel and export data to JavaScript.
 
669
         * Enqueue scripts and styles for Customizer panel and export data to JavaScript.
668
670
         *
669
671
         * @since 3.9.0
670
672
         * @access public
726
728
                                'removeBtnLabel'   => __( 'Remove' ),
727
729
                                'removeBtnTooltip' => __( 'Trash widget by moving it to the inactive widgets sidebar.' ),
728
730
                                'error'            => __( 'An error has occurred. Please reload the page and try again.' ),
 
731
                                'widgetMovedUp'    => __( 'Widget moved up' ),
 
732
                                'widgetMovedDown'  => __( 'Widget moved down' ),
729
733
                        ),
730
734
                        'tpl' => array(
731
735
                                'widgetReorderNav' => $widget_reorder_nav_tpl,
740
744
                $wp_scripts->add_data(
741
745
                        'customize-widgets',
742
746
                        'data',
743
 
                        sprintf( 'var _wpCustomizeWidgetsSettings = %s;', json_encode( $settings ) )
 
747
                        sprintf( 'var _wpCustomizeWidgetsSettings = %s;', wp_json_encode( $settings ) )
744
748
                );
745
749
        }
746
750
 
964
968
        }
965
969
 
966
970
        /**
967
 
         * Add hooks for the customizer preview.
 
971
         * Add hooks for the Customizer preview.
968
972
         *
969
973
         * @since 3.9.0
970
974
         * @access public
982
986
         * Because wp_get_sidebars_widgets() gets called early at init
983
987
         * (via wp_convert_widget_settings()) and can set global variable
984
988
         * $_wp_sidebars_widgets to the value of get_option( 'sidebars_widgets' )
985
 
         * before the customizer preview filter is added, we have to reset
 
989
         * before the Customizer preview filter is added, we have to reset
986
990
         * it after the filter has been added.
987
991
         *
988
992
         * @since 3.9.0
1039
1043
         */
1040
1044
        public function export_preview_data() {
1041
1045
 
1042
 
                // Prepare customizer settings to pass to Javascript.
 
1046
                // Prepare Customizer settings to pass to JavaScript.
1043
1047
                $settings = array(
1044
1048
                        'renderedSidebars'   => array_fill_keys( array_unique( $this->rendered_sidebars ), true ),
1045
1049
                        'renderedWidgets'    => array_fill_keys( array_keys( $this->rendered_widgets ), true ),
1055
1059
 
1056
1060
                ?>
1057
1061
                <script type="text/javascript">
1058
 
                        var _wpWidgetCustomizerPreviewSettings = <?php echo json_encode( $settings ); ?>;
 
1062
                        var _wpWidgetCustomizerPreviewSettings = <?php echo wp_json_encode( $settings ); ?>;
1059
1063
                </script>
1060
1064
                <?php
1061
1065
        }