WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/20/2009 10:58:50 AM (11 years ago)
Author:
azaozz
Message:

Add and edit widget when js is disabled, see #9511

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/widgets.php

    r10941 r11009  
    2020    global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
    2121
    22     if ( $_search ) {
     22    if ( $_search ) {
    2323        // sanitize
    2424        $search = preg_replace( '/[^\w\s]/', '', $_search );
     
    6969            $no_widgets_shown = false;
    7070
    71             $args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
     71            $args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
    7272
    7373            if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
     
    8383
    8484            $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
    85             call_user_func_array( 'wp_widget_control', $args );
     85            call_user_func_array( 'wp_widget_control', $args );
    8686        }
    8787
    88         if ( $no_widgets_shown )
     88        if ( $no_widgets_shown )
    8989          echo '<li>' . __( 'No matching widgets' ) . "</li>\n";
    9090?>
     
    133133    $params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
    134134    if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
    135         $wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
     135        $wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
    136136        $wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
    137137    }
     
    165165    $widget_id = $sidebar_args['widget_id'];
    166166    $sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
    167 
     167    $key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar
    168168    $control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array();
    169     $widget  = $wp_registered_widgets[$widget_id];
    170 
    171     $key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar
    172 
    173     $edit = isset($_GET['editwidget']); // editing without js
    174     $nonce = $edit ? wp_create_nonce("edit-widget_$widget_id") : '';
     169    $widget = $wp_registered_widgets[$widget_id];
    175170
    176171    $id_format = $widget['id'];
    177 
    178172    $widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
    179173    $id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id;
     
    181175    $add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : '';
    182176
     177    $query_arg = array( 'editwidget' => $widget['id'] );
     178    if ( $add_new ) {
     179        $query_arg['addnew'] = 1;
     180        if ( $multi_number ) {
     181            $query_arg['num'] = $multi_number;
     182            $query_arg['base'] = $id_base;
     183        }
     184    } else {
     185        $query_arg['sidebar'] = $sidebar_id;
     186        $query_arg['key'] = $key;
     187    }
     188
    183189    // We aren't showing a widget control, we're outputing a template for a mult-widget control
    184190    if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) {
    185191        // number == -1 implies a template where id numbers are replaced by a generic '__i__'
    186192        $control['params'][0]['number'] = -1;
    187         // if given, id_base means widget id's should be constructed like {$id_base}-{$id_number}
     193        // with id_base widget id's are constructed like {$id_base}-{$id_number}
    188194        if ( isset($control['id_base']) )
    189195            $id_format = $control['id_base'] . '-__i__';
     
    194200
    195201    $widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) );
     202    $has_form = 0;
    196203
    197204    echo $sidebar_args['before_widget']; ?>
    198         <div class="widget-top">
    199         <div class="widget-title-action">
    200 <?php       if ( !$edit ) { ?>
    201             <a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( array( 'edit' => $id_format, 'key' => $key ) ) ); ?>"></a>
     205    <div class="widget-top">
     206    <div class="widget-title-action">
     207        <a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( $query_arg ) ); ?>"></a>
     208    </div>
     209    <div class="widget-title"><h4><?php echo $widget_title ?></h4></div>
     210    </div>
     211
     212    <div class="widget-inside">
     213    <form action="" method="post">
     214    <div class="widget-control">
     215<?php
     216    if ( isset($control['callback']) )
     217        $has_form = call_user_func_array( $control['callback'], $control['params'] );
     218    else
     219        echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
     220
     221    <input type="hidden" name="widget-id" class="widget-id" value="<?php echo $id_format; ?>" />
     222    <input type="hidden" name="id_base" class="id_base" value="<?php echo $id_base; ?>" />
     223    <input type="hidden" name="widget-width" class="widget-width" value="<?php echo $control['width']; ?>" />
     224    <input type="hidden" name="widget-height" class="widget-height" value="<?php echo $control['height']; ?>" />
     225    <input type="hidden" name="widget_number" class="widget_number" value="<?php echo $widget_number; ?>" />
     226    <input type="hidden" name="multi_number" class="multi_number" value="<?php echo $multi_number; ?>" />
     227    <input type="hidden" name="add_new" class="add_new" value="<?php echo $add_new; ?>" />
     228
     229    <div class="widget-control-actions">
     230        <a class="button widget-control-remove alignleft" href="<?php echo $edit ? clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#remove'; ?>"><?php _e('Remove'); ?></a>
     231<?php       if ( false !== $has_form ) { ?>
     232        <input type="submit" name="savewidget" class="button-primary widget-control-save alignright" value="<?php _e('Save'); ?>" />
    202233<?php       } ?>
    203         </div>
    204         <div class="widget-title"><h4><?php echo $widget_title ?></h4></div>
    205         </div>
    206 
    207         <div class="widget-inside">
    208         <form action="" method="post">
    209         <div class="widget-control">
    210 <?php
    211             if ( isset($control['callback']) )
    212                 call_user_func_array( $control['callback'], $control['params'] );
    213             else
    214                 echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
    215 
    216             <input type="hidden" name="widget-id" class="widget-id" value="<?php echo $id_format; ?>" />
    217             <input type="hidden" name="id_base" class="id_base" value="<?php echo $id_base; ?>" />
    218             <input type="hidden" name="widget-width" class="widget-width" value="<?php echo $control['width']; ?>" />
    219             <input type="hidden" name="widget-height" class="widget-height" value="<?php echo $control['height']; ?>" />
    220             <input type="hidden" name="widget_number" class="widget_number" value="<?php echo $widget_number; ?>" />
    221             <input type="hidden" name="multi_number" class="multi_number" value="<?php echo $multi_number; ?>" />
    222             <input type="hidden" name="add_new" class="add_new" value="<?php echo $add_new; ?>" />
    223 
    224             <div class="widget-control-actions">
    225                 <a class="button widget-control-remove alignleft" href="<?php echo $edit ? clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#remove'; ?>"><?php _e('Remove'); ?></a>
    226 <?php       if ( !empty($control) ) { ?>
    227                 <input type="submit" name="savewidget" class="button-primary widget-control-save alignright" value="<?php _e('Save'); ?>" />
    228 <?php       } ?>
    229                 <br class="clear" />
    230             </div>
    231         </div>
    232         </form>
    233         <div class="widget-description">
     234        <br class="clear" />
     235    </div>
     236    </div>
     237    </form>
     238
     239    <div class="widget-description">
    234240<?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?>
    235         </div>
    236         </div>
     241    </div>
     242    </div>
    237243<?php
    238244    echo $sidebar_args['after_widget'];
    239 
    240245    return $sidebar_args;
    241246}
Note: See TracChangeset for help on using the changeset viewer.