Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41621 r42343  
    1111
    1212/** WordPress Administration Widgets API */
    13 require_once(ABSPATH . 'wp-admin/includes/widgets.php');
     13require_once( ABSPATH . 'wp-admin/includes/widgets.php' );
    1414
    1515if ( ! current_user_can( 'edit_theme_options' ) ) {
     
    2222
    2323$widgets_access = get_user_setting( 'widgets_access' );
    24 if ( isset($_GET['widgets-access']) ) {
     24if ( isset( $_GET['widgets-access'] ) ) {
    2525    check_admin_referer( 'widgets-access' );
    2626
     
    3232    add_filter( 'admin_body_class', 'wp_widgets_access_body_class' );
    3333} else {
    34     wp_enqueue_script('admin-widgets');
    35 
    36     if ( wp_is_mobile() )
     34    wp_enqueue_script( 'admin-widgets' );
     35
     36    if ( wp_is_mobile() ) {
    3737        wp_enqueue_script( 'jquery-touch-punch' );
     38    }
    3839}
    3940
     
    4647do_action( 'sidebar_admin_setup' );
    4748
    48 $title = __( 'Widgets' );
     49$title       = __( 'Widgets' );
    4950$parent_file = 'themes.php';
    5051
    51 get_current_screen()->add_help_tab( array(
    52 'id'        => 'overview',
    53 'title'     => __('Overview'),
    54 'content'   =>
    55     '<p>' . __('Widgets are independent sections of content that can be placed into any widgetized area provided by your theme (commonly called sidebars). To populate your sidebars/widget areas with individual widgets, drag and drop the title bars into the desired area. By default, only the first widget area is expanded. To populate additional widget areas, click on their title bars to expand them.') . '</p>
    56     <p>' . __('The Available Widgets section contains all the widgets you can choose from. Once you drag a widget into a sidebar, it will open to allow you to configure its settings. When you are happy with the widget settings, click the Save button and the widget will go live on your site. If you click Delete, it will remove the widget.') . '</p>'
    57 ) );
    58 get_current_screen()->add_help_tab( array(
    59 'id'        => 'removing-reusing',
    60 'title'     => __('Removing and Reusing'),
    61 'content'   =>
    62     '<p>' . __('If you want to remove the widget but save its setting for possible future use, just drag it into the Inactive Widgets area. You can add them back anytime from there. This is especially helpful when you switch to a theme with fewer or different widget areas.') . '</p>
    63     <p>' . __('Widgets may be used multiple times. You can give each widget a title, to display on your site, but it&#8217;s not required.') . '</p>
    64     <p>' . __('Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.') . '</p>'
    65 ) );
    66 get_current_screen()->add_help_tab( array(
    67 'id'        => 'missing-widgets',
    68 'title'     => __('Missing Widgets'),
    69 'content'   =>
    70     '<p>' . __('Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.') . '</p>' .
    71         '<p>' . __('When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive Widgets area, where all of your widgets and their settings will have been saved.') . '</p>'
    72 ) );
     52get_current_screen()->add_help_tab(
     53    array(
     54        'id'      => 'overview',
     55        'title'   => __( 'Overview' ),
     56        'content' =>
     57                 '<p>' . __( 'Widgets are independent sections of content that can be placed into any widgetized area provided by your theme (commonly called sidebars). To populate your sidebars/widget areas with individual widgets, drag and drop the title bars into the desired area. By default, only the first widget area is expanded. To populate additional widget areas, click on their title bars to expand them.' ) . '</p>
     58    <p>' . __( 'The Available Widgets section contains all the widgets you can choose from. Once you drag a widget into a sidebar, it will open to allow you to configure its settings. When you are happy with the widget settings, click the Save button and the widget will go live on your site. If you click Delete, it will remove the widget.' ) . '</p>',
     59    )
     60);
     61get_current_screen()->add_help_tab(
     62    array(
     63        'id'      => 'removing-reusing',
     64        'title'   => __( 'Removing and Reusing' ),
     65        'content' =>
     66                 '<p>' . __( 'If you want to remove the widget but save its setting for possible future use, just drag it into the Inactive Widgets area. You can add them back anytime from there. This is especially helpful when you switch to a theme with fewer or different widget areas.' ) . '</p>
     67    <p>' . __( 'Widgets may be used multiple times. You can give each widget a title, to display on your site, but it&#8217;s not required.' ) . '</p>
     68    <p>' . __( 'Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.' ) . '</p>',
     69    )
     70);
     71get_current_screen()->add_help_tab(
     72    array(
     73        'id'      => 'missing-widgets',
     74        'title'   => __( 'Missing Widgets' ),
     75        'content' =>
     76                 '<p>' . __( 'Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.' ) . '</p>' .
     77                     '<p>' . __( 'When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive Widgets area, where all of your widgets and their settings will have been saved.' ) . '</p>',
     78    )
     79);
    7380
    7481get_current_screen()->set_help_sidebar(
    75     '<p><strong>' . __('For more information:') . '</strong></p>' .
    76     '<p>' . __('<a href="https://codex.wordpress.org/Appearance_Widgets_Screen">Documentation on Widgets</a>') . '</p>' .
    77     '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
     82    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     83    '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Widgets_Screen">Documentation on Widgets</a>' ) . '</p>' .
     84    '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    7885);
    7986
     
    8592$sidebars_widgets = wp_get_sidebars_widgets();
    8693
    87 if ( empty( $sidebars_widgets ) )
     94if ( empty( $sidebars_widgets ) ) {
    8895    $sidebars_widgets = wp_get_widget_defaults();
     96}
    8997
    9098foreach ( $sidebars_widgets as $sidebar_id => $widgets ) {
    91     if ( 'wp_inactive_widgets' == $sidebar_id )
     99    if ( 'wp_inactive_widgets' == $sidebar_id ) {
    92100        continue;
     101    }
    93102
    94103    if ( ! is_registered_sidebar( $sidebar_id ) ) {
    95104        if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar
    96             register_sidebar(array(
    97                 'name' => __( 'Inactive Sidebar (not used)' ),
    98                 'id' => $sidebar_id,
    99                 'class' => 'inactive-sidebar orphan-sidebar',
    100                 'description' => __( 'This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.' ),
    101                 'before_widget' => '',
    102                 'after_widget' => '',
    103                 'before_title' => '',
    104                 'after_title' => '',
    105             ));
     105            register_sidebar(
     106                array(
     107                    'name'          => __( 'Inactive Sidebar (not used)' ),
     108                    'id'            => $sidebar_id,
     109                    'class'         => 'inactive-sidebar orphan-sidebar',
     110                    'description'   => __( 'This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.' ),
     111                    'before_widget' => '',
     112                    'after_widget'  => '',
     113                    'before_title'  => '',
     114                    'after_title'   => '',
     115                )
     116            );
    106117        } else {
    107118            unset( $sidebars_widgets[ $sidebar_id ] );
     
    111122
    112123// register the inactive_widgets area as sidebar
    113 register_sidebar(array(
    114     'name' => __('Inactive Widgets'),
    115     'id' => 'wp_inactive_widgets',
    116     'class' => 'inactive-sidebar',
    117     'description' => __( 'Drag widgets here to remove them from the sidebar but keep their settings.' ),
    118     'before_widget' => '',
    119     'after_widget' => '',
    120     'before_title' => '',
    121     'after_title' => '',
    122 ));
     124register_sidebar(
     125    array(
     126        'name'          => __( 'Inactive Widgets' ),
     127        'id'            => 'wp_inactive_widgets',
     128        'class'         => 'inactive-sidebar',
     129        'description'   => __( 'Drag widgets here to remove them from the sidebar but keep their settings.' ),
     130        'before_widget' => '',
     131        'after_widget'  => '',
     132        'before_title'  => '',
     133        'after_title'   => '',
     134    )
     135);
    123136
    124137retrieve_widgets();
    125138
    126139// We're saving a widget without js
    127 if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) {
     140if ( isset( $_POST['savewidget'] ) || isset( $_POST['removewidget'] ) ) {
    128141    $widget_id = $_POST['widget-id'];
    129     check_admin_referer("save-delete-widget-$widget_id");
    130 
    131     $number = isset($_POST['multi_number']) ? (int) $_POST['multi_number'] : '';
     142    check_admin_referer( "save-delete-widget-$widget_id" );
     143
     144    $number = isset( $_POST['multi_number'] ) ? (int) $_POST['multi_number'] : '';
    132145    if ( $number ) {
    133146        foreach ( $_POST as $key => $val ) {
    134             if ( is_array($val) && preg_match('/__i__|%i%/', key($val)) ) {
    135                 $_POST[$key] = array( $number => array_shift($val) );
     147            if ( is_array( $val ) && preg_match( '/__i__|%i%/', key( $val ) ) ) {
     148                $_POST[ $key ] = array( $number => array_shift( $val ) );
    136149                break;
    137150            }
     
    140153
    141154    $sidebar_id = $_POST['sidebar'];
    142     $position = isset($_POST[$sidebar_id . '_position']) ? (int) $_POST[$sidebar_id . '_position'] - 1 : 0;
     155    $position   = isset( $_POST[ $sidebar_id . '_position' ] ) ? (int) $_POST[ $sidebar_id . '_position' ] - 1 : 0;
    143156
    144157    $id_base = $_POST['id_base'];
    145     $sidebar = isset($sidebars_widgets[$sidebar_id]) ? $sidebars_widgets[$sidebar_id] : array();
     158    $sidebar = isset( $sidebars_widgets[ $sidebar_id ] ) ? $sidebars_widgets[ $sidebar_id ] : array();
    146159
    147160    // Delete.
    148     if ( isset($_POST['removewidget']) && $_POST['removewidget'] ) {
    149 
    150         if ( !in_array($widget_id, $sidebar, true) ) {
    151             wp_redirect( admin_url('widgets.php?error=0') );
     161    if ( isset( $_POST['removewidget'] ) && $_POST['removewidget'] ) {
     162
     163        if ( ! in_array( $widget_id, $sidebar, true ) ) {
     164            wp_redirect( admin_url( 'widgets.php?error=0' ) );
    152165            exit;
    153166        }
    154167
    155         $sidebar = array_diff( $sidebar, array($widget_id) );
    156         $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
     168        $sidebar = array_diff( $sidebar, array( $widget_id ) );
     169        $_POST   = array(
     170            'sidebar'            => $sidebar_id,
     171            'widget-' . $id_base => array(),
     172            'the-widget-id'      => $widget_id,
     173            'delete_widget'      => '1',
     174        );
    157175
    158176        /**
     
    171189
    172190    foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
    173         if ( $name != $id_base || !is_callable($control['callback']) )
     191        if ( $name != $id_base || ! is_callable( $control['callback'] ) ) {
    174192            continue;
     193        }
    175194
    176195        ob_start();
     
    181200    }
    182201
    183     $sidebars_widgets[$sidebar_id] = $sidebar;
     202    $sidebars_widgets[ $sidebar_id ] = $sidebar;
    184203
    185204    // Remove old position.
    186     if ( !isset($_POST['delete_widget']) ) {
     205    if ( ! isset( $_POST['delete_widget'] ) ) {
    187206        foreach ( $sidebars_widgets as $key => $sb ) {
    188             if ( is_array($sb) )
    189                 $sidebars_widgets[$key] = array_diff( $sb, array($widget_id) );
    190         }
    191         array_splice( $sidebars_widgets[$sidebar_id], $position, 0, $widget_id );
    192     }
    193 
    194     wp_set_sidebars_widgets($sidebars_widgets);
    195     wp_redirect( admin_url('widgets.php?message=0') );
     207            if ( is_array( $sb ) ) {
     208                $sidebars_widgets[ $key ] = array_diff( $sb, array( $widget_id ) );
     209            }
     210        }
     211        array_splice( $sidebars_widgets[ $sidebar_id ], $position, 0, $widget_id );
     212    }
     213
     214    wp_set_sidebars_widgets( $sidebars_widgets );
     215    wp_redirect( admin_url( 'widgets.php?message=0' ) );
    196216    exit;
    197217}
     
    203223    if ( $_POST['removeinactivewidgets'] ) {
    204224        foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) {
    205             $pieces = explode( '-', $widget_id );
     225            $pieces       = explode( '-', $widget_id );
    206226            $multi_number = array_pop( $pieces );
    207             $id_base = implode( '-', $pieces );
    208             $widget = get_option( 'widget_' . $id_base );
    209             unset( $widget[$multi_number] );
     227            $id_base      = implode( '-', $pieces );
     228            $widget       = get_option( 'widget_' . $id_base );
     229            unset( $widget[ $multi_number ] );
    210230            update_option( 'widget_' . $id_base, $widget );
    211             unset( $sidebars_widgets['wp_inactive_widgets'][$key] );
     231            unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] );
    212232        }
    213233
     
    220240
    221241// Output the widget form without js
    222 if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
     242if ( isset( $_GET['editwidget'] ) && $_GET['editwidget'] ) {
    223243    $widget_id = $_GET['editwidget'];
    224244
    225     if ( isset($_GET['addnew']) ) {
     245    if ( isset( $_GET['addnew'] ) ) {
    226246        // Default to the first sidebar
    227         $keys = array_keys( $wp_registered_sidebars );
     247        $keys    = array_keys( $wp_registered_sidebars );
    228248        $sidebar = reset( $keys );
    229249
    230         if ( isset($_GET['base']) && isset($_GET['num']) ) { // multi-widget
     250        if ( isset( $_GET['base'] ) && isset( $_GET['num'] ) ) { // multi-widget
    231251            // Copy minimal info from an existing instance of this widget to a new instance
    232252            foreach ( $wp_registered_widget_controls as $control ) {
    233253                if ( $_GET['base'] === $control['id_base'] ) {
    234                     $control_callback = $control['callback'];
    235                     $multi_number = (int) $_GET['num'];
    236                     $control['params'][0]['number'] = -1;
    237                     $widget_id = $control['id'] = $control['id_base'] . '-' . $multi_number;
    238                     $wp_registered_widget_controls[$control['id']] = $control;
     254                    $control_callback                                = $control['callback'];
     255                    $multi_number                                    = (int) $_GET['num'];
     256                    $control['params'][0]['number']                  = -1;
     257                    $widget_id                                       = $control['id'] = $control['id_base'] . '-' . $multi_number;
     258                    $wp_registered_widget_controls[ $control['id'] ] = $control;
    239259                    break;
    240260                }
     
    243263    }
    244264
    245     if ( isset($wp_registered_widget_controls[$widget_id]) && !isset($control) ) {
    246         $control = $wp_registered_widget_controls[$widget_id];
     265    if ( isset( $wp_registered_widget_controls[ $widget_id ] ) && ! isset( $control ) ) {
     266        $control          = $wp_registered_widget_controls[ $widget_id ];
    247267        $control_callback = $control['callback'];
    248     } elseif ( !isset($wp_registered_widget_controls[$widget_id]) && isset($wp_registered_widgets[$widget_id]) ) {
    249         $name = esc_html( strip_tags($wp_registered_widgets[$widget_id]['name']) );
    250     }
    251 
    252     if ( !isset($name) )
    253         $name = esc_html( strip_tags($control['name']) );
    254 
    255     if ( !isset($sidebar) )
    256         $sidebar = isset($_GET['sidebar']) ? $_GET['sidebar'] : 'wp_inactive_widgets';
    257 
    258     if ( !isset($multi_number) )
    259         $multi_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
    260 
    261     $id_base = isset($control['id_base']) ? $control['id_base'] : $control['id'];
     268    } elseif ( ! isset( $wp_registered_widget_controls[ $widget_id ] ) && isset( $wp_registered_widgets[ $widget_id ] ) ) {
     269        $name = esc_html( strip_tags( $wp_registered_widgets[ $widget_id ]['name'] ) );
     270    }
     271
     272    if ( ! isset( $name ) ) {
     273        $name = esc_html( strip_tags( $control['name'] ) );
     274    }
     275
     276    if ( ! isset( $sidebar ) ) {
     277        $sidebar = isset( $_GET['sidebar'] ) ? $_GET['sidebar'] : 'wp_inactive_widgets';
     278    }
     279
     280    if ( ! isset( $multi_number ) ) {
     281        $multi_number = isset( $control['params'][0]['number'] ) ? $control['params'][0]['number'] : '';
     282    }
     283
     284    $id_base = isset( $control['id_base'] ) ? $control['id_base'] : $control['id'];
    262285
    263286    // Show the widget form.
    264     $width = ' style="width:' . max($control['width'], 350) . 'px"';
    265     $key = isset($_GET['key']) ? (int) $_GET['key'] : 0;
     287    $width = ' style="width:' . max( $control['width'], 350 ) . 'px"';
     288    $key   = isset( $_GET['key'] ) ? (int) $_GET['key'] : 0;
    266289
    267290    require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
     
    274297    <div class="widget-inside">
    275298<?php
    276     if ( is_callable( $control_callback ) )
    277         call_user_func_array( $control_callback, $control['params'] );
    278     else
    279         echo '<p>' . __('There are no options for this widget.') . "</p>\n"; ?>
    280     </div>
    281 
    282     <p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p>
     299if ( is_callable( $control_callback ) ) {
     300    call_user_func_array( $control_callback, $control['params'] );
     301} else {
     302    echo '<p>' . __( 'There are no options for this widget.' ) . "</p>\n";
     303}
     304        ?>
     305    </div>
     306
     307    <p class="describe"><?php _e( 'Select both the sidebar for this widget and the position of the widget in that sidebar.' ); ?></p>
    283308    <div class="widget-position">
    284     <table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody>
    285 <?php
    286     foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
    287         echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
    288         if ( 'wp_inactive_widgets' == $sbname || 'orphaned_widgets' == substr( $sbname, 0, 16 ) ) {
    289             echo '&nbsp;';
     309    <table class="widefat"><thead><tr><th><?php _e( 'Sidebar' ); ?></th><th><?php _e( 'Position' ); ?></th></tr></thead><tbody>
     310<?php
     311foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
     312    echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr( $sbname ) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
     313    if ( 'wp_inactive_widgets' == $sbname || 'orphaned_widgets' == substr( $sbname, 0, 16 ) ) {
     314        echo '&nbsp;';
     315    } else {
     316        if ( ! isset( $sidebars_widgets[ $sbname ] ) || ! is_array( $sidebars_widgets[ $sbname ] ) ) {
     317            $j                           = 1;
     318            $sidebars_widgets[ $sbname ] = array();
    290319        } else {
    291             if ( !isset($sidebars_widgets[$sbname]) || !is_array($sidebars_widgets[$sbname]) ) {
    292                 $j = 1;
    293                 $sidebars_widgets[$sbname] = array();
    294             } else {
    295                 $j = count($sidebars_widgets[$sbname]);
    296                 if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) )
    297                     $j++;
     320            $j = count( $sidebars_widgets[ $sbname ] );
     321            if ( isset( $_GET['addnew'] ) || ! in_array( $widget_id, $sidebars_widgets[ $sbname ], true ) ) {
     322                $j++;
    298323            }
    299             $selected = '';
    300             echo "\t\t<select name='{$sbname}_position'>\n";
    301             echo "\t\t<option value=''>" . __('&mdash; Select &mdash;') . "</option>\n";
    302             for ( $i = 1; $i <= $j; $i++ ) {
    303                 if ( in_array($widget_id, $sidebars_widgets[$sbname], true) )
    304                     $selected = selected( $i, $key + 1, false );
    305                 echo "\t\t<option value='$i'$selected> $i </option>\n";
     324        }
     325        $selected = '';
     326        echo "\t\t<select name='{$sbname}_position'>\n";
     327        echo "\t\t<option value=''>" . __( '&mdash; Select &mdash;' ) . "</option>\n";
     328        for ( $i = 1; $i <= $j; $i++ ) {
     329            if ( in_array( $widget_id, $sidebars_widgets[ $sbname ], true ) ) {
     330                $selected = selected( $i, $key + 1, false );
    306331            }
    307             echo "\t\t</select>\n";
    308         }
    309         echo "</td></tr>\n";
    310     } ?>
     332            echo "\t\t<option value='$i'$selected> $i </option>\n";
     333        }
     334        echo "\t\t</select>\n";
     335    }
     336    echo "</td></tr>\n";
     337}
     338    ?>
    311339    </tbody></table>
    312340    </div>
     
    314342    <div class="widget-control-actions">
    315343<?php
    316     if ( isset($_GET['addnew']) ) { ?>
    317     <a href="widgets.php" class="button alignleft"><?php _e('Cancel'); ?></a>
    318 <?php
    319     } else {
    320         submit_button( __( 'Delete' ), 'alignleft', 'removewidget', false );
    321     }
    322     submit_button( __( 'Save Widget' ), 'primary alignright', 'savewidget', false ); ?>
    323     <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($widget_id); ?>" />
    324     <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
    325     <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" />
    326 <?php   wp_nonce_field("save-delete-widget-$widget_id"); ?>
     344if ( isset( $_GET['addnew'] ) ) {
     345    ?>
     346    <a href="widgets.php" class="button alignleft"><?php _e( 'Cancel' ); ?></a>
     347<?php
     348} else {
     349    submit_button( __( 'Delete' ), 'alignleft', 'removewidget', false );
     350}
     351    submit_button( __( 'Save Widget' ), 'primary alignright', 'savewidget', false );
     352    ?>
     353    <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr( $widget_id ); ?>" />
     354    <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr( $id_base ); ?>" />
     355    <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr( $multi_number ); ?>" />
     356<?php   wp_nonce_field( "save-delete-widget-$widget_id" ); ?>
    327357    <br class="clear" />
    328358    </div>
     
    336366
    337367$messages = array(
    338     __('Changes saved.')
     368    __( 'Changes saved.' ),
    339369);
    340370
    341371$errors = array(
    342     __('Error while saving.'),
    343     __('Error in displaying the widget settings form.')
    344 );
    345 
    346 require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
     372    __( 'Error while saving.' ),
     373    __( 'Error in displaying the widget settings form.' ),
     374);
     375
     376require_once( ABSPATH . 'wp-admin/admin-header.php' );
     377?>
    347378
    348379<div class="wrap">
    349 <h1 class="wp-heading-inline"><?php
     380<h1 class="wp-heading-inline">
     381<?php
    350382echo esc_html( $title );
    351 ?></h1>
     383?>
     384</h1>
    352385
    353386<?php
     
    355388    printf(
    356389        ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>',
    357         esc_url( add_query_arg(
    358             array(
    359                 array( 'autofocus' => array( 'panel' => 'widgets' ) ),
    360                 'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) )
    361             ),
    362             admin_url( 'customize.php' )
    363         ) ),
     390        esc_url(
     391            add_query_arg(
     392                array(
     393                    array( 'autofocus' => array( 'panel' => 'widgets' ) ),
     394                    'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ),
     395                ),
     396                admin_url( 'customize.php' )
     397            )
     398        ),
    364399        __( 'Manage with Live Preview' )
    365400    );
     
    369404<hr class="wp-header-end">
    370405
    371 <?php if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) { ?>
    372 <div id="message" class="updated notice is-dismissible"><p><?php echo $messages[$_GET['message']]; ?></p></div>
     406<?php if ( isset( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) { ?>
     407<div id="message" class="updated notice is-dismissible"><p><?php echo $messages[ $_GET['message'] ]; ?></p></div>
    373408<?php } ?>
    374 <?php if ( isset($_GET['error']) && isset($errors[$_GET['error']]) ) { ?>
    375 <div id="message" class="error"><p><?php echo $errors[$_GET['error']]; ?></p></div>
     409<?php if ( isset( $_GET['error'] ) && isset( $errors[ $_GET['error'] ] ) ) { ?>
     410<div id="message" class="error"><p><?php echo $errors[ $_GET['error'] ]; ?></p></div>
    376411<?php } ?>
    377412
     
    382417 * @since 3.0.0
    383418 */
    384 do_action( 'widgets_admin_page' ); ?>
     419do_action( 'widgets_admin_page' );
     420?>
    385421
    386422<div class="widget-liquid-left">
     
    396432        <div class="widget-holder">
    397433            <div class="sidebar-description">
    398                 <p class="description"><?php _e('To activate a widget drag it to a sidebar or click on it. To deactivate a widget and delete its settings, drag it back.'); ?></p>
     434                <p class="description"><?php _e( 'To activate a widget drag it to a sidebar or click on it. To deactivate a widget and delete its settings, drag it back.' ); ?></p>
    399435            </div>
    400436            <div id="widget-list">
     
    412448    if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) {
    413449        $wrap_class = 'widgets-holder-wrap';
    414         if ( !empty( $registered_sidebar['class'] ) )
     450        if ( ! empty( $registered_sidebar['class'] ) ) {
    415451            $wrap_class .= ' ' . $registered_sidebar['class'];
     452        }
    416453
    417454        $is_inactive_widgets = 'wp_inactive_widgets' == $registered_sidebar['id'];
     
    428465                            $attributes = array( 'id' => 'inactive-widgets-control-remove' );
    429466
    430                             if ( empty($sidebars_widgets['wp_inactive_widgets']) ) {
     467                            if ( empty( $sidebars_widgets['wp_inactive_widgets'] ) ) {
    431468                                $attributes['disabled'] = '';
    432469                            }
     
    448485
    449486    } else {
    450         $theme_sidebars[$sidebar] = $registered_sidebar;
    451     }
    452 }
    453 
    454 ?>
    455 </div>
    456 </div>
    457 <?php
    458 
    459 $i = $split = 0;
     487        $theme_sidebars[ $sidebar ] = $registered_sidebar;
     488    }
     489}
     490
     491?>
     492</div>
     493</div>
     494<?php
     495
     496$i                    = $split = 0;
    460497$single_sidebar_class = '';
    461 $sidebars_count = count( $theme_sidebars );
     498$sidebars_count       = count( $theme_sidebars );
    462499
    463500if ( $sidebars_count > 1 ) {
     
    475512foreach ( $theme_sidebars as $sidebar => $registered_sidebar ) {
    476513    $wrap_class = 'widgets-holder-wrap';
    477     if ( !empty( $registered_sidebar['class'] ) )
     514    if ( ! empty( $registered_sidebar['class'] ) ) {
    478515        $wrap_class .= ' sidebar-' . $registered_sidebar['class'];
    479 
    480     if ( $i > 0 )
     516    }
     517
     518    if ( $i > 0 ) {
    481519        $wrap_class .= ' closed';
     520    }
    482521
    483522    if ( $split && $i == $split ) {
Note: See TracChangeset for help on using the changeset viewer.