WordPress.org

Make WordPress Core

Ticket #5750: 5750b.diff

File 5750b.diff, 4.5 KB (added by mdawaffe, 10 years ago)
  • wp-includes/widgets.php

     
    159159/* $options: height, width, id_base
    160160 *   height: never used
    161161 *   width:  width of fully expanded control form.  Try hard to use the default width.
    162  *   id_base: for widgets which allow multiple instances (such as the text widget), an id_base must be provided.
     162 *   id_base: for multi-widgets (widgets which allow multiple instances such as the text widget), an id_base must be provided.
    163163 *            the widget id will ennd up looking like {$id_base}-{$unique_number}
    164164 */
    165165function wp_register_widget_control($id, $name, $control_callback, $options = array()) {
     
    13891389
    13901390add_action('init', 'wp_widgets_init', 1);
    13911391
    1392 /* Pattern for widget which allows multiple instances (such as the text widget)
     1392/* Pattern for multi-widget (allows multiple instances such as the text widget).
    13931393
    13941394// Displays widget on blag
    13951395// $widget_args: number
  • wp-admin/includes/widgets.php

     
    2121                $no_widgets_shown = true;
    2222                $already_shown = array();
    2323                foreach ( $wp_registered_widgets as $name => $widget ) :
    24                         if ( in_array( $widget['callback'], $already_shown ) )
     24                        if ( in_array( $widget['callback'], $already_shown ) ) // We already showed this multi-widget
    2525                                continue;
    26                         $already_shown[] = $widget['callback'];
    2726
    2827                        if ( $search_terms ) {
    2928                                $hit = false;
     
    5251                        ob_end_clean();
    5352
    5453                        if ( !$sidebar || false !== strpos( $widget_control_template, '%i%' ) ) {
     54                                $already_shown[] = $widget['callback']; // it's a multi-widget.  We only need to show it in the list once.
    5555                                $action = 'add';
    5656                                $add_url = wp_nonce_url( add_query_arg( array(
    5757                                        'sidebar' => $sidebar,
     
    6666                                        'edit' => $widget['id'],
    6767                                        'key' => array_search( $widget['id'], $sidebars_widgets[$sidebar] ),
    6868                                ) );
    69                                 $widget_control_template = "<textarea>$widget_control_template</textarea>";
     69                                $widget_control_template = '<textarea>' . htmlspecialchars( $widget_control_template ) . '</textarea>';
    7070                        }
    7171
    7272                        $no_widgets_shown = false;
  • wp-admin/includes/dashboard.php

     
    108108        // Filter widget order
    109109        $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', $dashboard_widgets );
    110110
    111         $wp_dashboard_sidebars = array( 'wp_dashboard' => $dashboard_widgets );
     111        $wp_dashboard_sidebars = array( 'wp_dashboard' => $dashboard_widgets, 'array_version' => 3.5 );
    112112
    113113        add_filter( 'dynamic_sidebar_params', 'wp_dashboard_dynamic_sidebar_params' );
    114114
  • wp-admin/widgets.php

     
    5252
    5353        /* Hack #1
    5454         * The widget_control is overloaded.  It updates the widget's options AND echoes out the widget's HTML form.
    55          * Since we want to update before sending out any headers, we have to catchi it with an output buffer
     55         * Since we want to update before sending out any headers, we have to catch it with an output buffer,
    5656         */
    5757        ob_start();
    5858                /* There can be multiple widgets of the same type, but the widget_control for that
    59                  * widget type needs only be called once.
     59                 * widget type needs only be called once if it's a multi-widget.
    6060                 */
    6161                $already_done = array();
    6262
     
    6464                        if ( in_array( $control['callback'], $already_done ) )
    6565                                continue;
    6666
    67                         if ( is_callable( $control['callback'] ) )
     67                        if ( is_callable( $control['callback'] ) ) {
    6868                                call_user_func_array( $control['callback'], $control['params'] );
     69                                $control_output = ob_get_contents();
     70                                if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once.
     71                                        $already_done[] = $control['callback'];
     72                        }
     73
     74                        ob_clean();
    6975                }
    7076        ob_end_clean();
    7177
     
    7581                        unset($_POST['widget-id'][$key]);
    7682
    7783        // Reset the key numbering and stare
    78         $new_sidebar = array_values( $_POST['widget-id'] );
     84        $new_sidebar = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) ? array_values( $_POST['widget-id'] ) : array();
    7985        $sidebars_widgets[$_POST['sidebar']] = $new_sidebar;
    8086        wp_set_sidebars_widgets( $sidebars_widgets );
    8187