WordPress.org

Make WordPress Core

Changeset 4478


Ignore:
Timestamp:
11/18/2006 06:09:48 AM (12 years ago)
Author:
matt
Message:

Admin functions cleanup, and change how we do titles and parents in the backend

Location:
trunk/wp-admin
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r4418 r4478  
    33function write_post() {
    44    $result = wp_write_post();
    5     if( is_wp_error($result) )
     5    if( is_wp_error( $result ) )
    66        wp_die( $result->get_error_message() );
    77    else
     
    1414
    1515    if ( 'page' == $_POST['post_type'] ) {
    16         if ( !current_user_can('edit_pages') )
    17             return new WP_Error('edit_pages', __('You are not allowed to create pages on this blog.'));
    18     } else {
    19         if ( !current_user_can('edit_posts') )
    20             return new WP_Error('edit_posts', __('You are not allowed to create posts or drafts on this blog.'));
     16        if ( !current_user_can( 'edit_pages' ) )
     17            return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
     18    } else {
     19        if ( !current_user_can( 'edit_posts' ) )
     20            return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
    2121    }
    2222
     
    2727    $_POST['to_ping'] = $_POST['trackback_url'];
    2828
    29     if (!empty ($_POST['post_author_override'])) {
     29    if (!empty ( $_POST['post_author_override'] ) ) {
    3030        $_POST['post_author'] = (int) $_POST['post_author_override'];
    3131    } else {
    32         if (!empty ($_POST['post_author'])) {
     32        if (!empty ( $_POST['post_author'] ) ) {
    3333            $_POST['post_author'] = (int) $_POST['post_author'];
    3434        } else {
     
    3838    }
    3939
    40     if ($_POST['post_author'] != $_POST['user_ID']) {
     40    if ( $_POST['post_author'] != $_POST['user_ID'] ) {
    4141        if ( 'page' == $_POST['post_type'] ) {
    42             if ( !current_user_can('edit_others_pages') )
    43                 return new WP_Error('edit_others_pages', __('You cannot create pages as this user.'));
     42            if ( !current_user_can( 'edit_others_pages' ) )
     43                return new WP_Error( 'edit_others_pages', __( 'You cannot create pages as this user.' ) );
    4444        } else {
    45             if ( !current_user_can('edit_others_posts') )
    46                 return new WP_Error('edit_others_posts', __('You cannot post as this user.'));
     45            if ( !current_user_can( 'edit_others_posts' ) )
     46                return new WP_Error( 'edit_others_posts', __( 'You cannot post as this user.' ) );
    4747
    4848        }
     
    5050
    5151    // What to do based on which button they pressed
    52     if ('' != $_POST['saveasdraft'])
     52    if ('' != $_POST['saveasdraft'] )
    5353        $_POST['post_status'] = 'draft';
    54     if ('' != $_POST['saveasprivate'])
     54    if ('' != $_POST['saveasprivate'] )
    5555        $_POST['post_status'] = 'private';
    56     if ('' != $_POST['publish'])
     56    if ('' != $_POST['publish'] )
    5757        $_POST['post_status'] = 'publish';
    58     if ('' != $_POST['advanced'])
     58    if ('' != $_POST['advanced'] )
    5959        $_POST['post_status'] = 'draft';
    6060
    6161    if ( 'page' == $_POST['post_type'] ) {
    62         if ('publish' == $_POST['post_status'] && !current_user_can('publish_pages'))
     62        if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
    6363            $_POST['post_status'] = 'draft';
    6464    } else {
    65         if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts'))
     65        if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
    6666            $_POST['post_status'] = 'draft';
    6767    }
    6868
    69     if (!isset ($_POST['comment_status']))
     69    if (!isset( $_POST['comment_status'] ))
    7070        $_POST['comment_status'] = 'closed';
    7171
    72     if (!isset ($_POST['ping_status']))
     72    if (!isset( $_POST['ping_status'] ))
    7373        $_POST['ping_status'] = 'closed';
    7474
    75     if (!empty ($_POST['edit_date'])) {
     75    if (!empty ( $_POST['edit_date'] ) ) {
    7676        $aa = $_POST['aa'];
    7777        $mm = $_POST['mm'];
     
    8080        $mn = $_POST['mn'];
    8181        $ss = $_POST['ss'];
    82         $jj = ($jj > 31) ? 31 : $jj;
    83         $hh = ($hh > 23) ? $hh -24 : $hh;
    84         $mn = ($mn > 59) ? $mn -60 : $mn;
    85         $ss = ($ss > 59) ? $ss -60 : $ss;
    86         $_POST['post_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss);
    87         $_POST['post_date_gmt'] = get_gmt_from_date($_POST['post_date']);
     82        $jj = ($jj > 31 ) ? 31 : $jj;
     83        $hh = ($hh > 23 ) ? $hh -24 : $hh;
     84        $mn = ($mn > 59 ) ? $mn -60 : $mn;
     85        $ss = ($ss > 59 ) ? $ss -60 : $ss;
     86        $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     87        $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
    8888    }
    8989
    9090    // Create the post.
    91     $post_ID = wp_insert_post($_POST);
    92     add_meta($post_ID);
     91    $post_ID = wp_insert_post( $_POST);
     92    add_meta( $post_ID );
    9393
    9494    // Reunite any orphaned attachments with their parent
    9595    if ( $_POST['temp_ID'] )
    96         relocate_children($_POST['temp_ID'], $post_ID);
     96        relocate_children( $_POST['temp_ID'], $post_ID );
    9797
    9898    // Now that we have an ID we can fix any attachment anchor hrefs
    99     fix_attachment_links($post_ID);
     99    fix_attachment_links( $post_ID );
    100100
    101101    return $post_ID;
     
    103103
    104104// Move child posts to a new parent
    105 function relocate_children($old_ID, $new_ID) {
     105function relocate_children( $old_ID, $new_ID ) {
    106106    global $wpdb;
    107107    $old_ID = (int) $old_ID;
    108108    $new_ID = (int) $new_ID;
    109     return $wpdb->query("UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID");
     109    return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" );
    110110}
    111111
    112112// Replace hrefs of attachment anchors with up-to-date permalinks.
    113 function fix_attachment_links($post_ID) {
     113function fix_attachment_links( $post_ID ) {
    114114    global $wp_rewrite;
    115115
    116     $post = & get_post($post_ID, ARRAY_A);
    117 
    118     $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
     116    $post = & get_post( $post_ID, ARRAY_A );
     117
     118    $search = "#<a[^>]+rel=('|\" )[^'\"]*attachment[^>]*>#ie";
    119119
    120120    // See if we have any rel="attachment" links
    121     if ( 0 == preg_match_all($search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER) )
     121    if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) )
    122122        return;
    123123
    124124    $i = 0;
    125     $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i";
     125    $search = "#[\s]+rel=(\"|' )(.*? )wp-att-(\d+ )\\1#i";
    126126    foreach ( $anchor_matches[0] as $anchor ) {
    127         if ( 0 == preg_match($search, $anchor, $id_matches) )
     127        if ( 0 == preg_match( $search, $anchor, $id_matches ) )
    128128            continue;
    129129
     
    131131
    132132        // While we have the attachment ID, let's adopt any orphans.
    133         $attachment = & get_post($id, ARRAY_A);
    134         if ( ! empty($attachment) && ! is_object(get_post($attachment['post_parent'])) ) {
     133        $attachment = & get_post( $id, ARRAY_A );
     134        if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) {
    135135            $attachment['post_parent'] = $post_ID;
    136136            // Escape data pulled from DB.
    137             $attachment = add_magic_quotes($attachment);
    138             wp_update_post($attachment);
     137            $attachment = add_magic_quotes( $attachment);
     138            wp_update_post( $attachment);
    139139        }
    140140
    141141        $post_search[$i] = $anchor;
    142         $post_replace[$i] = preg_replace("#href=(\"|')[^'\"]*\\1#e", "stripslashes('href=\\1').get_attachment_link($id).stripslashes('\\1')", $anchor);
     142        $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
    143143        ++$i;
    144144    }
    145145
    146     $post['post_content'] = str_replace($post_search, $post_replace, $post['post_content']);
     146    $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
    147147
    148148    // Escape data pulled from DB.
    149     $post = add_magic_quotes($post);
    150 
    151     return wp_update_post($post);
     149    $post = add_magic_quotes( $post);
     150
     151    return wp_update_post( $post);
    152152}
    153153
     
    159159
    160160    if ( 'page' == $_POST['post_type'] ) {
    161         if ( !current_user_can('edit_page', $post_ID) )
    162             wp_die(__('You are not allowed to edit this page.'));
    163     } else {
    164         if ( !current_user_can('edit_post', $post_ID) )
    165             wp_die(__('You are not allowed to edit this post.'));
     161        if ( !current_user_can( 'edit_page', $post_ID ) )
     162            wp_die( __('You are not allowed to edit this page.' ));
     163    } else {
     164        if ( !current_user_can( 'edit_post', $post_ID ) )
     165            wp_die( __('You are not allowed to edit this post.' ));
    166166    }
    167167
     
    173173    $_POST['to_ping'] = $_POST['trackback_url'];
    174174
    175     if (!empty ($_POST['post_author_override'])) {
     175    if (!empty ( $_POST['post_author_override'] ) ) {
    176176        $_POST['post_author'] = (int) $_POST['post_author_override'];
    177177    } else
    178         if (!empty ($_POST['post_author'])) {
     178        if (!empty ( $_POST['post_author'] ) ) {
    179179            $_POST['post_author'] = (int) $_POST['post_author'];
    180180        } else {
     
    182182        }
    183183
    184     if ($_POST['post_author'] != $_POST['user_ID']) {
     184    if ( $_POST['post_author'] != $_POST['user_ID'] ) {
    185185        if ( 'page' == $_POST['post_type'] ) {
    186             if ( !current_user_can('edit_others_pages') )
    187                 wp_die(__('You cannot edit pages as this user.'));
     186            if ( !current_user_can( 'edit_others_pages' ) )
     187                wp_die( __('You cannot edit pages as this user.' ));
    188188        } else {
    189             if ( !current_user_can('edit_others_posts') )
    190                 wp_die(__('You cannot edit posts as this user.'));
     189            if ( !current_user_can( 'edit_others_posts' ) )
     190                wp_die( __('You cannot edit posts as this user.' ));
    191191
    192192        }
     
    194194
    195195    // What to do based on which button they pressed
    196     if ('' != $_POST['saveasdraft'])
     196    if ('' != $_POST['saveasdraft'] )
    197197        $_POST['post_status'] = 'draft';
    198     if ('' != $_POST['saveasprivate'])
     198    if ('' != $_POST['saveasprivate'] )
    199199        $_POST['post_status'] = 'private';
    200     if ('' != $_POST['publish'])
     200    if ('' != $_POST['publish'] )
    201201        $_POST['post_status'] = 'publish';
    202     if ('' != $_POST['advanced'])
     202    if ('' != $_POST['advanced'] )
    203203        $_POST['post_status'] = 'draft';
    204204
    205205    if ( 'page' == $_POST['post_type'] ) {
    206         if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_pages'))
     206        if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' ))
    207207            $_POST['post_status'] = 'draft';
    208208    } else {
    209         if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_posts'))
     209        if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' ))
    210210            $_POST['post_status'] = 'draft';
    211211    }
    212212
    213     if (!isset ($_POST['comment_status']))
     213    if (!isset( $_POST['comment_status'] ))
    214214        $_POST['comment_status'] = 'closed';
    215215
    216     if (!isset ($_POST['ping_status']))
     216    if (!isset( $_POST['ping_status'] ))
    217217        $_POST['ping_status'] = 'closed';
    218218
    219     if (!empty ($_POST['edit_date'])) {
     219    if (!empty ( $_POST['edit_date'] ) ) {
    220220        $aa = $_POST['aa'];
    221221        $mm = $_POST['mm'];
     
    224224        $mn = $_POST['mn'];
    225225        $ss = $_POST['ss'];
    226         $jj = ($jj > 31) ? 31 : $jj;
    227         $hh = ($hh > 23) ? $hh -24 : $hh;
    228         $mn = ($mn > 59) ? $mn -60 : $mn;
    229         $ss = ($ss > 59) ? $ss -60 : $ss;
     226        $jj = ($jj > 31 ) ? 31 : $jj;
     227        $hh = ($hh > 23 ) ? $hh -24 : $hh;
     228        $mn = ($mn > 59 ) ? $mn -60 : $mn;
     229        $ss = ($ss > 59 ) ? $ss -60 : $ss;
    230230        $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    231         $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
     231        $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
    232232    }
    233233
    234234    // Meta Stuff
    235     if ($_POST['meta']) {
    236         foreach ($_POST['meta'] as $key => $value)
    237             update_meta($key, $value['key'], $value['value']);
    238     }
    239 
    240     if ($_POST['deletemeta']) {
    241         foreach ($_POST['deletemeta'] as $key => $value)
    242             delete_meta($key);
    243     }
    244 
    245     add_meta($post_ID);
    246 
    247     wp_update_post($_POST);
     235    if ( $_POST['meta'] ) {
     236        foreach ( $_POST['meta'] as $key => $value )
     237            update_meta( $key, $value['key'], $value['value'] );
     238    }
     239
     240    if ( $_POST['deletemeta'] ) {
     241        foreach ( $_POST['deletemeta'] as $key => $value )
     242            delete_meta( $key );
     243    }
     244
     245    add_meta( $post_ID );
     246
     247    wp_update_post( $_POST);
    248248
    249249    // Now that we have an ID we can fix any attachment anchor hrefs
    250     fix_attachment_links($post_ID);
     250    fix_attachment_links( $post_ID );
    251251
    252252    return $post_ID;
     
    259259    $comment_post_ID = (int) $_POST['comment_post_ID'];
    260260
    261     if (!current_user_can('edit_post', $comment_post_ID))
    262         wp_die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.'));
     261    if (!current_user_can( 'edit_post', $comment_post_ID ))
     262        wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
    263263
    264264    $_POST['comment_author'] = $_POST['newcomment_author'];
     
    269269    $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    270270
    271     if (!empty ($_POST['edit_date'])) {
     271    if (!empty ( $_POST['edit_date'] ) ) {
    272272        $aa = $_POST['aa'];
    273273        $mm = $_POST['mm'];
     
    276276        $mn = $_POST['mn'];
    277277        $ss = $_POST['ss'];
    278         $jj = ($jj > 31) ? 31 : $jj;
    279         $hh = ($hh > 23) ? $hh -24 : $hh;
    280         $mn = ($mn > 59) ? $mn -60 : $mn;
    281         $ss = ($ss > 59) ? $ss -60 : $ss;
     278        $jj = ($jj > 31 ) ? 31 : $jj;
     279        $hh = ($hh > 23 ) ? $hh -24 : $hh;
     280        $mn = ($mn > 59 ) ? $mn -60 : $mn;
     281        $ss = ($ss > 59 ) ? $ss -60 : $ss;
    282282        $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    283283    }
    284284
    285     wp_update_comment($_POST);
     285    wp_update_comment( $_POST);
    286286}
    287287
    288288// Get an existing post and format it for editing.
    289 function get_post_to_edit($id) {
    290 
    291     $post = get_post($id);
    292 
    293     $post->post_content = format_to_edit($post->post_content, user_can_richedit());
    294     $post->post_content = apply_filters('content_edit_pre', $post->post_content);
    295 
    296     $post->post_excerpt = format_to_edit($post->post_excerpt);
    297     $post->post_excerpt = apply_filters('excerpt_edit_pre', $post->post_excerpt);
    298 
    299     $post->post_title = format_to_edit($post->post_title);
    300     $post->post_title = apply_filters('title_edit_pre', $post->post_title);
    301 
    302     $post->post_password = format_to_edit($post->post_password);
    303 
    304     if ($post->post_type == 'page')
    305         $post->page_template = get_post_meta($id, '_wp_page_template', true);
     289function get_post_to_edit( $id ) {
     290
     291    $post = get_post( $id );
     292
     293    $post->post_content = format_to_edit( $post->post_content, user_can_richedit() );
     294    $post->post_content = apply_filters( 'content_edit_pre', $post->post_content);
     295
     296    $post->post_excerpt = format_to_edit( $post->post_excerpt);
     297    $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt);
     298
     299    $post->post_title = format_to_edit( $post->post_title );
     300    $post->post_title = apply_filters( 'title_edit_pre', $post->post_title );
     301
     302    $post->post_password = format_to_edit( $post->post_password );
     303
     304    if ( $post->post_type == 'page' )
     305        $post->page_template = get_post_meta( $id, '_wp_page_template', true );
    306306
    307307    return $post;
     
    310310// Default post information to use when populating the "Write Post" form.
    311311function get_default_post_to_edit() {
    312     if ( !empty($_REQUEST['post_title']) )
    313         $post_title = wp_specialchars(stripslashes($_REQUEST['post_title']));
    314     else if ( !empty($_REQUEST['popuptitle']) ) {
    315         $post_title = wp_specialchars(stripslashes($_REQUEST['popuptitle']));
    316         $post_title = funky_javascript_fix($post_title);
     312    if ( !empty( $_REQUEST['post_title'] ) )
     313        $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
     314    else if ( !empty( $_REQUEST['popuptitle'] ) ) {
     315        $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] ));
     316        $post_title = funky_javascript_fix( $post_title );
    317317    } else {
    318318        $post_title = '';
    319319    }
    320320
    321     if ( !empty($_REQUEST['content']) )
    322         $post_content = wp_specialchars(stripslashes($_REQUEST['content']));
    323     else if ( !empty($post_title) ) {
    324         $text       = wp_specialchars(stripslashes(urldecode($_REQUEST['text'])));
    325         $text       = funky_javascript_fix($text);
    326         $popupurl   = wp_specialchars($_REQUEST['popupurl']);
     321    if ( !empty( $_REQUEST['content'] ) )
     322        $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] ));
     323    else if ( !empty( $post_title ) ) {
     324        $text       = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) );
     325        $text       = funky_javascript_fix( $text);
     326        $popupurl   = wp_specialchars( $_REQUEST['popupurl'] );
    327327        $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
    328328    }
    329329
    330     if ( !empty($_REQUEST['excerpt']) )
    331         $post_excerpt = wp_specialchars(stripslashes($_REQUEST['excerpt']));
     330    if ( !empty( $_REQUEST['excerpt'] ) )
     331        $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] ));
    332332    else
    333333        $post_excerpt = '';
    334334
    335335    $post->post_status = 'draft';
    336     $post->comment_status = get_option('default_comment_status');
    337     $post->ping_status = get_option('default_ping_status');
    338     $post->post_pingback = get_option('default_pingback_flag');
    339     $post->post_category = get_option('default_category');
    340     $post->post_content = apply_filters('default_content', $post_content);
    341     $post->post_title = apply_filters('default_title', $post_title);
    342     $post->post_excerpt = apply_filters('default_excerpt', $post_excerpt);
     336    $post->comment_status = get_option( 'default_comment_status' );
     337    $post->ping_status = get_option( 'default_ping_status' );
     338    $post->post_pingback = get_option( 'default_pingback_flag' );
     339    $post->post_category = get_option( 'default_category' );
     340    $post->post_content = apply_filters( 'default_content', $post_content);
     341    $post->post_title = apply_filters( 'default_title', $post_title );
     342    $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
    343343    $post->page_template = 'default';
    344344    $post->post_parent = 0;
     
    348348}
    349349
    350 function get_comment_to_edit($id) {
    351     $comment = get_comment($id);
    352 
    353     $comment->comment_content = format_to_edit($comment->comment_content, user_can_richedit());
    354     $comment->comment_content = apply_filters('comment_edit_pre', $comment->comment_content);
    355 
    356     $comment->comment_author = format_to_edit($comment->comment_author);
    357     $comment->comment_author_email = format_to_edit($comment->comment_author_email);
    358     $comment->comment_author_url = format_to_edit($comment->comment_author_url);
     350function get_comment_to_edit( $id ) {
     351    $comment = get_comment( $id );
     352
     353    $comment->comment_content = format_to_edit( $comment->comment_content, user_can_richedit() );
     354    $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
     355
     356    $comment->comment_author = format_to_edit( $comment->comment_author );
     357    $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
     358    $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
    359359
    360360    return $comment;
    361361}
    362362
    363 function get_category_to_edit($id) {
    364     $category = get_category($id);
     363function get_category_to_edit( $id ) {
     364    $category = get_category( $id );
    365365
    366366    return $category;
     
    370370    global $wp_roles;
    371371    $r = '';
    372     foreach($wp_roles->role_names as $role => $name)
     372    foreach( $wp_roles->role_names as $role => $name )
    373373        if ( $default == $role ) // Make default first in list
    374374            $p = "\n\t<option selected='selected' value='$role'>$name</option>";
     
    379379
    380380
    381 function get_user_to_edit($user_id) {
    382     $user = new WP_User($user_id);
    383     $user->user_login = wp_specialchars($user->user_login, 1);
    384     $user->user_email = wp_specialchars($user->user_email, 1);
    385     $user->user_url = wp_specialchars($user->user_url, 1);
    386     $user->first_name = wp_specialchars($user->first_name, 1);
    387     $user->last_name = wp_specialchars($user->last_name, 1);
    388     $user->display_name = wp_specialchars($user->display_name, 1);
    389     $user->nickname = wp_specialchars($user->nickname, 1);
    390     $user->aim = wp_specialchars($user->aim, 1);
    391     $user->yim = wp_specialchars($user->yim, 1);
    392     $user->jabber = wp_specialchars($user->jabber, 1);
    393     $user->description = wp_specialchars($user->description);
     381function get_user_to_edit( $user_id ) {
     382    $user = new WP_User( $user_id );
     383    $user->user_login = wp_specialchars( $user->user_login, 1 );
     384    $user->user_email = wp_specialchars( $user->user_email, 1 );
     385    $user->user_url = wp_specialchars( $user->user_url, 1 );
     386    $user->first_name = wp_specialchars( $user->first_name, 1 );
     387    $user->last_name = wp_specialchars( $user->last_name, 1 );
     388    $user->display_name = wp_specialchars( $user->display_name, 1 );
     389    $user->nickname = wp_specialchars( $user->nickname, 1 );
     390    $user->aim = wp_specialchars( $user->aim, 1 );
     391    $user->yim = wp_specialchars( $user->yim, 1 );
     392    $user->jabber = wp_specialchars( $user->jabber, 1 );
     393    $user->description = wp_specialchars( $user->description );
    394394
    395395    return $user;
     
    401401    if ( func_num_args() ) { // The hackiest hack that ever did hack
    402402        global $current_user, $wp_roles;
    403         $user_id = func_get_arg(0);
    404 
    405         if (isset ($_POST['role'])) {
    406             if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) {
    407                 $user = new WP_User($user_id);
    408                 $user->set_role($_POST['role']);
     403        $user_id = func_get_arg( 0 );
     404
     405        if ( isset( $_POST['role'] ) ) {
     406            if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) {
     407                $user = new WP_User( $user_id );
     408                $user->set_role( $_POST['role'] );
    409409            }
    410410        }
    411411    } else {
    412         add_action('user_register', 'add_user'); // See above
     412        add_action( 'user_register', 'add_user' ); // See above
    413413        return edit_user();
    414414    }
    415415}
    416416
    417 function edit_user($user_id = 0) {
     417function edit_user( $user_id = 0 ) {
    418418    global $current_user, $wp_roles, $wpdb;
    419     if ($user_id != 0) {
     419    if ( $user_id != 0 ) {
    420420        $update = true;
    421421        $user->ID = $user_id;
    422         $userdata = get_userdata($user_id);
    423         $user->user_login = $wpdb->escape($userdata->user_login);
     422        $userdata = get_userdata( $user_id );
     423        $user->user_login = $wpdb->escape( $userdata->user_login );
    424424    } else {
    425425        $update = false;
     
    427427    }
    428428
    429     if (isset ($_POST['user_login']))
    430         $user->user_login = wp_specialchars(trim($_POST['user_login']));
     429    if ( isset( $_POST['user_login'] ))
     430        $user->user_login = wp_specialchars( trim( $_POST['user_login'] ));
    431431
    432432    $pass1 = $pass2 = '';
    433     if (isset ($_POST['pass1']))
     433    if ( isset( $_POST['pass1'] ))
    434434        $pass1 = $_POST['pass1'];
    435     if (isset ($_POST['pass2']))
     435    if ( isset( $_POST['pass2'] ))
    436436        $pass2 = $_POST['pass2'];
    437437
    438     if (isset ($_POST['role']) && current_user_can('edit_users')) {
    439         if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users'))
     438    if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {
     439        if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ))
    440440            $user->role = $_POST['role'];
    441441    }
    442442
    443     if (isset ($_POST['email']))
    444         $user->user_email = wp_specialchars(trim($_POST['email']));
    445     if (isset ($_POST['url'])) {
    446         $user->user_url = wp_specialchars(trim($_POST['url']));
    447         $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;
    448     }
    449     if (isset ($_POST['first_name']))
    450         $user->first_name = wp_specialchars(trim($_POST['first_name']));
    451     if (isset ($_POST['last_name']))
    452         $user->last_name = wp_specialchars(trim($_POST['last_name']));
    453     if (isset ($_POST['nickname']))
    454         $user->nickname = wp_specialchars(trim($_POST['nickname']));
    455     if (isset ($_POST['display_name']))
    456         $user->display_name = wp_specialchars(trim($_POST['display_name']));
    457     if (isset ($_POST['description']))
    458         $user->description = trim($_POST['description']);
    459     if (isset ($_POST['jabber']))
    460         $user->jabber = wp_specialchars(trim($_POST['jabber']));
    461     if (isset ($_POST['aim']))
    462         $user->aim = wp_specialchars(trim($_POST['aim']));
    463     if (isset ($_POST['yim']))
    464         $user->yim = wp_specialchars(trim($_POST['yim']));
     443    if ( isset( $_POST['email'] ))
     444        $user->user_email = wp_specialchars( trim( $_POST['email'] ));
     445    if ( isset( $_POST['url'] ) ) {
     446        $user->user_url = wp_specialchars( trim( $_POST['url'] ));
     447        $user->user_url = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url ) ? $user->user_url : 'http://'.$user->user_url;
     448    }
     449    if ( isset( $_POST['first_name'] ))
     450        $user->first_name = wp_specialchars( trim( $_POST['first_name'] ));
     451    if ( isset( $_POST['last_name'] ))
     452        $user->last_name = wp_specialchars( trim( $_POST['last_name'] ));
     453    if ( isset( $_POST['nickname'] ))
     454        $user->nickname = wp_specialchars( trim( $_POST['nickname'] ));
     455    if ( isset( $_POST['display_name'] ))
     456        $user->display_name = wp_specialchars( trim( $_POST['display_name'] ));
     457    if ( isset( $_POST['description'] ))
     458        $user->description = trim( $_POST['description'] );
     459    if ( isset( $_POST['jabber'] ))
     460        $user->jabber = wp_specialchars( trim( $_POST['jabber'] ));
     461    if ( isset( $_POST['aim'] ))
     462        $user->aim = wp_specialchars( trim( $_POST['aim'] ));
     463    if ( isset( $_POST['yim'] ))
     464        $user->yim = wp_specialchars( trim( $_POST['yim'] ));
    465465
    466466    $errors = new WP_Error();
    467467
    468468    /* checking that username has been typed */
    469     if ($user->user_login == '')
    470         $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.'));
     469    if ( $user->user_login == '' )
     470        $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));
    471471
    472472    /* checking the password has been typed twice */
    473     do_action_ref_array('check_passwords', array ($user->user_login, & $pass1, & $pass2));
    474 
    475     if (!$update) {
    476         if ($pass1 == '' || $pass2 == '')
    477             $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.'));
    478     } else {
    479         if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1)))
    480             $errors->add('pass', __("<strong>ERROR</strong>: you typed your new password only once."));
     473    do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 ));
     474
     475    if (!$update ) {
     476        if ( $pass1 == '' || $pass2 == '' )
     477            $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ));
     478    } else {
     479        if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) )
     480            $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." ));
    481481    }
    482482
    483483    /* Check for "\" in password */
    484484    if( strpos( " ".$pass1, "\\" ) )
    485         $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'));
     485        $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ));
    486486
    487487    /* checking the password has been typed twice the same */
    488     if ($pass1 != $pass2)
    489         $errors->add('pass', __('<strong>ERROR</strong>: Please type the same password in the two password fields.'));
    490 
    491     if (!empty ($pass1))
     488    if ( $pass1 != $pass2 )
     489        $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' ));
     490
     491    if (!empty ( $pass1 ))
    492492        $user->user_pass = $pass1;
    493493
    494     if ( !validate_username($user->user_login) )
    495         $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.'));
    496 
    497     if (!$update && username_exists($user->user_login))
    498         $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
     494    if ( !validate_username( $user->user_login ) )
     495        $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.' ));
     496
     497    if (!$update && username_exists( $user->user_login ))
     498        $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ));
    499499
    500500    /* checking e-mail address */
    501     if (empty ($user->user_email)) {
    502         $errors->add('user_email', __("<strong>ERROR</strong>: please type an e-mail address"));
     501    if ( empty ( $user->user_email ) ) {
     502        $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" ));
    503503    } else
    504         if (!is_email($user->user_email)) {
    505             $errors->add('user_email', __("<strong>ERROR</strong>: the email address isn't correct"));
     504        if (!is_email( $user->user_email ) ) {
     505            $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" ));
    506506        }
    507507
     
    509509        return $errors;
    510510
    511     if ($update) {
    512         $user_id = wp_update_user(get_object_vars($user));
    513     } else {
    514         $user_id = wp_insert_user(get_object_vars($user));
    515         wp_new_user_notification($user_id);
     511    if ( $update ) {
     512        $user_id = wp_update_user( get_object_vars( $user ));
     513    } else {
     514        $user_id = wp_insert_user( get_object_vars( $user ));
     515        wp_new_user_notification( $user_id );
    516516    }
    517517    return $user_id;
     
    519519
    520520
    521 function get_link_to_edit($link_id) {
    522     $link = get_link($link_id);
    523 
    524     $link->link_url = wp_specialchars($link->link_url, 1);
    525     $link->link_name = wp_specialchars($link->link_name, 1);
    526     $link->link_image = wp_specialchars($link->link_image, 1);
    527     $link->link_description = wp_specialchars($link->link_description, 1);
    528     $link->link_notes = wp_specialchars($link->link_notes);
    529     $link->link_rss = wp_specialchars($link->link_rss, 1);
    530     $link->link_rel = wp_specialchars($link->link_rel, 1);
     521function get_link_to_edit( $link_id ) {
     522    $link = get_link( $link_id );
     523
     524    $link->link_url = wp_specialchars( $link->link_url, 1 );
     525    $link->link_name = wp_specialchars( $link->link_name, 1 );
     526    $link->link_image = wp_specialchars( $link->link_image, 1 );
     527    $link->link_description = wp_specialchars( $link->link_description, 1 );
     528    $link->link_notes = wp_specialchars( $link->link_notes );
     529    $link->link_rss = wp_specialchars( $link->link_rss, 1 );
     530    $link->link_rel = wp_specialchars( $link->link_rel, 1 );
    531531    $link->post_category = $link->link_category;
    532532
     
    535535
    536536function get_default_link_to_edit() {
    537     if ( isset($_GET['linkurl']) )
    538         $link->link_url = wp_specialchars($_GET['linkurl'], 1);
     537    if ( isset( $_GET['linkurl'] ) )
     538        $link->link_url = wp_specialchars( $_GET['linkurl'], 1 );
    539539    else
    540540        $link->link_url = '';
    541541
    542     if ( isset($_GET['name']) )
    543         $link->link_name = wp_specialchars($_GET['name'], 1);
     542    if ( isset( $_GET['name'] ) )
     543        $link->link_name = wp_specialchars( $_GET['name'], 1 );
    544544    else
    545545        $link->link_name = '';
     
    554554}
    555555
    556 function edit_link($link_id = '') {
    557     if (!current_user_can('manage_links'))
    558         wp_die(__("Cheatin' uh ?"));
    559 
    560     $_POST['link_url'] = wp_specialchars($_POST['link_url']);
    561     $_POST['link_url'] = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url']) ? $_POST['link_url'] : 'http://' . $_POST['link_url'];
    562     $_POST['link_name'] = wp_specialchars($_POST['link_name']);
    563     $_POST['link_image'] = wp_specialchars($_POST['link_image']);
    564     $_POST['link_rss'] = wp_specialchars($_POST['link_rss']);
     556function edit_link( $link_id = '' ) {
     557    if (!current_user_can( 'manage_links' ))
     558        wp_die( __("Cheatin' uh ?" ));
     559
     560    $_POST['link_url'] = wp_specialchars( $_POST['link_url'] );
     561    $_POST['link_url'] = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url'] ) ? $_POST['link_url'] : 'http://' . $_POST['link_url'];
     562    $_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
     563    $_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
     564    $_POST['link_rss'] = wp_specialchars( $_POST['link_rss'] );
    565565    $_POST['link_category'] = $_POST['post_category'];
    566566
    567     if ( !empty($link_id) ) {
     567    if ( !empty( $link_id ) ) {
    568568        $_POST['link_id'] = $link_id;
    569         return wp_update_link($_POST);
    570     } else {
    571         return wp_insert_link($_POST);
    572     }
    573 }
    574 
    575 function url_shorten($url) {
    576     $short_url = str_replace('http://', '', stripslashes($url));
    577     $short_url = str_replace('www.', '', $short_url);
    578     if ('/' == substr($short_url, -1))
    579         $short_url = substr($short_url, 0, -1);
    580     if (strlen($short_url) > 35)
    581         $short_url = substr($short_url, 0, 32).'...';
     569        return wp_update_link( $_POST);
     570    } else {
     571        return wp_insert_link( $_POST);
     572    }
     573}
     574
     575function url_shorten( $url ) {
     576    $short_url = str_replace( 'http://', '', stripslashes( $url ));
     577    $short_url = str_replace( 'www.', '', $short_url );
     578    if ('/' == substr( $short_url, -1 ))
     579        $short_url = substr( $short_url, 0, -1 );
     580    if ( strlen( $short_url ) > 35 )
     581        $short_url = substr( $short_url, 0, 32 ).'...';
    582582    return $short_url;
    583583}
    584584
    585 function selected($selected, $current) {
    586     if ($selected == $current)
     585function selected( $selected, $current) {
     586    if ( $selected == $current)
    587587        echo ' selected="selected"';
    588588}
    589589
    590 function checked($checked, $current) {
    591     if ($checked == $current)
     590function checked( $checked, $current) {
     591    if ( $checked == $current)
    592592        echo ' checked="checked"';
    593593}
    594594
    595 function return_categories_list($parent = 0) {
     595function return_categories_list( $parent = 0 ) {
    596596    global $wpdb;
    597     return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC");
    598 }
    599 
    600 function sort_cats($cat1, $cat2) {
    601     return strcasecmp($cat1['cat_name'], $cat2['cat_name']);
    602 }
    603 
    604 function get_nested_categories($default = 0, $parent = 0) {
     597    return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC" );
     598}
     599
     600function sort_cats( $cat1, $cat2 ) {
     601    return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] );
     602}
     603
     604function get_nested_categories( $default = 0, $parent = 0 ) {
    605605    global $post_ID, $link_id, $mode, $wpdb;
    606606
    607     if ($post_ID) {
    608         $checked_categories = $wpdb->get_col("
     607    if ( $post_ID ) {
     608        $checked_categories = $wpdb->get_col( "
    609609             SELECT category_id
    610610             FROM $wpdb->categories, $wpdb->post2cat
    611611             WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
    612              ");
    613 
    614         if (count($checked_categories) == 0) {
     612             " );
     613
     614        if ( count( $checked_categories ) == 0 ) {
    615615            // No selected categories, strange
    616616            $checked_categories[] = $default;
    617617        }
    618     } else if ($link_id) {
    619         $checked_categories = $wpdb->get_col("
     618    } else if ( $link_id ) {
     619        $checked_categories = $wpdb->get_col( "
    620620             SELECT category_id
    621621             FROM $wpdb->categories, $wpdb->link2cat
    622622             WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id'
    623              ");
    624 
    625         if (count($checked_categories) == 0) {
     623             " );
     624
     625        if ( count( $checked_categories ) == 0 ) {
    626626            // No selected categories, strange
    627627            $checked_categories[] = $default;
     
    631631    }
    632632
    633     $cats = return_categories_list($parent);
     633    $cats = return_categories_list( $parent);
    634634    $result = array ();
    635635
    636     if (is_array($cats)) {
    637         foreach ($cats as $cat) {
    638             $result[$cat]['children'] = get_nested_categories($default, $cat);
     636    if ( is_array( $cats ) ) {
     637        foreach ( $cats as $cat) {
     638            $result[$cat]['children'] = get_nested_categories( $default, $cat);
    639639            $result[$cat]['cat_ID'] = $cat;
    640             $result[$cat]['checked'] = in_array($cat, $checked_categories);
    641             $result[$cat]['cat_name'] = get_the_category_by_ID($cat);
    642         }
    643     }
    644 
    645     usort($result, 'sort_cats');
     640            $result[$cat]['checked'] = in_array( $cat, $checked_categories );
     641            $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
     642        }
     643    }
     644
     645    usort( $result, 'sort_cats' );
    646646
    647647    return $result;
    648648}
    649649
    650 function write_nested_categories($categories) {
    651     foreach ($categories as $category) {
    652         echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label></li>\n";
     650function write_nested_categories( $categories ) {
     651    foreach ( $categories as $category ) {
     652        echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( $category['cat_name'] ), "</label></li>\n";
    653653
    654654        if ( $category['children'] ) {
    655655            echo "<ul>\n";
    656             write_nested_categories($category['children']);
     656            write_nested_categories( $category['children'] );
    657657            echo "</ul>\n";
    658658        }
     
    660660}
    661661
    662 function dropdown_categories($default = 0) {
    663     write_nested_categories(get_nested_categories($default));
    664 }
    665 
    666 function return_link_categories_list($parent = 0) {
     662function dropdown_categories( $default = 0 ) {
     663    write_nested_categories( get_nested_categories( $default) );
     664}
     665
     666function return_link_categories_list( $parent = 0 ) {
    667667    global $wpdb;
    668     return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC");
     668    return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC" );
    669669}
    670670
     
    672672    global $post_ID, $link_id, $mode, $wpdb;
    673673
    674     if ($link_id) {
    675         $checked_categories = $wpdb->get_col("
     674    if ( $link_id ) {
     675        $checked_categories = $wpdb->get_col( "
    676676             SELECT category_id
    677677             FROM $wpdb->categories, $wpdb->link2cat
    678678             WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id'
    679              ");
    680 
    681         if (count($checked_categories) == 0) {
     679             " );
     680
     681        if ( count( $checked_categories ) == 0 ) {
    682682            // No selected categories, strange
    683683            $checked_categories[] = $default;
     
    687687    }
    688688
    689     $cats = return_link_categories_list($parent);
     689    $cats = return_link_categories_list( $parent);
    690690    $result = array ();
    691691
    692     if (is_array($cats)) {
    693         foreach ($cats as $cat) {
    694             $result[$cat]['children'] = get_nested_link_categories($default, $cat);
     692    if ( is_array( $cats ) ) {
     693        foreach ( $cats as $cat) {
     694            $result[$cat]['children'] = get_nested_link_categories( $default, $cat);
    695695            $result[$cat]['cat_ID'] = $cat;
    696             $result[$cat]['checked'] = in_array($cat, $checked_categories);
    697             $result[$cat]['cat_name'] = get_the_category_by_ID($cat);
    698         }
    699     }
    700 
    701     usort($result, 'sort_cats');
     696            $result[$cat]['checked'] = in_array( $cat, $checked_categories );
     697            $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
     698        }
     699    }
     700
     701    usort( $result, 'sort_cats' );
    702702
    703703    return $result;
    704704}
    705705
    706 function dropdown_link_categories($default = 0) {
    707     write_nested_categories(get_nested_link_categories($default));
     706function dropdown_link_categories( $default = 0 ) {
     707    write_nested_categories( get_nested_link_categories( $default) );
    708708}
    709709
    710710// Dandy new recursive multiple category stuff.
    711 function cat_rows($parent = 0, $level = 0, $categories = 0) {
    712     if (!$categories)
    713         $categories = get_categories('hide_empty=0');
    714 
    715     if ($categories) {
    716         foreach ($categories as $category) {
    717             if ($category->category_parent == $parent) {
     711function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
     712    if (!$categories )
     713        $categories = get_categories( 'hide_empty=0' );
     714
     715    if ( $categories ) {
     716        foreach ( $categories as $category ) {
     717            if ( $category->category_parent == $parent) {
    718718                echo "\t" . _cat_row( $category, $level );
    719                 cat_rows($category->cat_ID, $level +1, $categories);
     719                cat_rows( $category->cat_ID, $level +1, $categories );
    720720            }
    721721        }
     
    728728    global $class;
    729729
    730     $pad = str_repeat('&#8212; ', $level);
    731     if ( current_user_can('manage_categories') ) {
    732         $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>";
    733         $default_cat_id = get_option('default_category');
    734         $default_link_cat_id = get_option('default_link_category');
    735 
    736         if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) )
    737             $edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&amp;cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category &quot;%s&quot;.\\nAll of its posts will go into the default category of &quot;%s&quot;\\nAll of its bookmarks will go into the default category of &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), js_escape($category->cat_name), js_escape(get_catname($default_cat_id)), js_escape(get_catname($default_link_cat_id))) . "' );\" class='delete'>".__('Delete')."</a>";
     730    $pad = str_repeat( '&#8212; ', $level );
     731    if ( current_user_can( 'manage_categories' ) ) {
     732        $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__( 'Edit' )."</a></td>";
     733        $default_cat_id = get_option( 'default_category' );
     734        $default_link_cat_id = get_option( 'default_link_category' );
     735
     736        if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) )
     737            $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&amp;cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf( __("You are about to delete the category &quot;%s&quot;.\\nAll of its posts will go into the default category of &quot;%s&quot;\\nAll of its bookmarks will go into the default category of &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop." ), js_escape( $category->cat_name ), js_escape( get_catname( $default_cat_id )), js_escape( get_catname( $default_link_cat_id ) ) ) . "' );\" class='delete'>".__( 'Delete' )."</a>";
    738738        else
    739             $edit .= "<td style='text-align:center'>".__("Default");
     739            $edit .= "<td style='text-align:center'>".__( "Default" );
    740740    } else
    741741        $edit = '';
    742742
    743     $class = ( ( defined('DOING_AJAX') && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
     743    $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
    744744
    745745    $category->category_count = number_format( $category->category_count );
     
    754754}
    755755
    756 function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) {
     756function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) {
    757757    global $wpdb, $class, $post;
    758758
    759     if (!$pages)
    760         $pages = get_pages('sort_column=menu_order');
    761 
    762     if (! $pages)
     759    if (!$pages )
     760        $pages = get_pages( 'sort_column=menu_order' );
     761
     762    if (! $pages )
    763763        return false;
    764764
    765     foreach ($pages as $post) {
    766         setup_postdata($post);
     765    foreach ( $pages as $post) {
     766        setup_postdata( $post);
    767767        if ( $hierarchy && ($post->post_parent != $parent) )
    768768            continue;
    769769
    770         $post->post_title = wp_specialchars($post->post_title);
    771         $pad = str_repeat('&#8212; ', $level);
     770        $post->post_title = wp_specialchars( $post->post_title );
     771        $pad = str_repeat( '&#8212; ', $level );
    772772        $id = $post->ID;
    773         $class = ('alternate' == $class) ? '' : 'alternate';
     773        $class = ('alternate' == $class ) ? '' : 'alternate';
    774774?>
    775775  <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
     
    777777    <td>
    778778      <?php echo $pad; ?><?php the_title() ?>
    779       <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?>
     779      <?php if ('private' == $post->post_status ) _e( ' - <strong>Private</strong>' ); ?>
    780780    </td>
    781781    <td><?php the_author() ?></td>
    782     <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
    783     <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
    784     <td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
    785     <td><?php if ( current_user_can('delete_page', $id) ) { echo "<a href='" . wp_nonce_url("page.php?action=delete&amp;post=$id", 'delete-page_' . $id) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), js_escape(get_the_title()) ) . "' );\">" . __('Delete') . "</a>"; } ?></td>
     782    <td><?php echo mysql2date( 'Y-m-d g:i a', $post->post_modified ); ?></td>
     783    <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td>
     784    <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
     785    <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf( __("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop." ), js_escape( get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
    786786  </tr>
    787787
    788788<?php
    789         if ( $hierarchy) page_rows($id, $level + 1, $pages);
     789        if ( $hierarchy ) page_rows( $id, $level + 1, $pages );
    790790    }
    791791}
    792792
    793793function user_row( $user_object, $style = '' ) {
    794     if ( !(is_object($user_object) && is_a($user_object, 'WP_User')) )
     794    if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
    795795        $user_object = new WP_User( (int) $user_object );
    796796    $email = $user_object->user_email;
    797797    $url = $user_object->user_url;
    798     $short_url = str_replace('http://', '', $url);
    799     $short_url = str_replace('www.', '', $short_url);
    800     if ('/' == substr($short_url, -1))
    801         $short_url = substr($short_url, 0, -1);
    802     if (strlen($short_url) > 35)
    803         $short_url =  substr($short_url, 0, 32).'...';
    804     $numposts = get_usernumposts($user_object->ID);
     798    $short_url = str_replace( 'http://', '', $url );
     799    $short_url = str_replace( 'www.', '', $short_url );
     800    if ('/' == substr( $short_url, -1 ))
     801        $short_url = substr( $short_url, 0, -1 );
     802    if ( strlen( $short_url ) > 35 )
     803        $short_url =  substr( $short_url, 0, 32 ).'...';
     804    $numposts = get_usernumposts( $user_object->ID );
    805805    $r = "<tr id='user-$user_object->ID'$style>
    806806        <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
    807807        <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
    808808        <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
    809         <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td>
     809        <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
    810810        <td><a href='$url' title='website: $url'>$short_url</a></td>";
    811811    $r .= "\n\t\t<td align='center'>";
    812     if ($numposts > 0) {
    813         $r .= "<a href='edit.php?author=$user_object->ID' title='" . __('View posts by this author') . "' class='edit'>";
    814         $r .= sprintf(__('View %1$s %2$s'), $numposts, __ngettext('post', 'posts', $numposts));
     812    if ( $numposts > 0 ) {
     813        $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
     814        $r .= sprintf( __('View %1$s %2$s' ), $numposts, __ngettext( 'post', 'posts', $numposts ));
    815815    }
    816816    $r .= "</td>\n\t\t<td>";
    817     $edit_link = add_query_arg('wp_http_referer', wp_specialchars(urlencode(stripslashes($_SERVER['REQUEST_URI']))), "user-edit.php?user_id=$user_object->ID");
    818     if ( current_user_can('edit_user', $user_object->ID) )
    819         $r .= "<a href='$edit_link' class='edit'>".__('Edit')."</a>";
     817    $edit_link = add_query_arg( 'wp_http_referer', wp_specialchars( urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" );
     818    if ( current_user_can( 'edit_user', $user_object->ID ) )
     819        $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>";
    820820    $r .= "</td>\n\t</tr>";
    821821    return $r;
    822822}
    823823
    824 function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) {
     824function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
    825825    global $wpdb;
    826     if (!$categories)
    827         $categories = get_categories('hide_empty=0');
    828 
    829     if ($categories) {
    830         foreach ($categories as $category) {
    831             if ($currentcat != $category->cat_ID && $parent == $category->category_parent) {
    832                 $pad = str_repeat('&#8211; ', $level);
    833                 $category->cat_name = wp_specialchars($category->cat_name);
     826    if (!$categories )
     827        $categories = get_categories( 'hide_empty=0' );
     828
     829    if ( $categories ) {
     830        foreach ( $categories as $category ) {
     831            if ( $currentcat != $category->cat_ID && $parent == $category->category_parent) {
     832                $pad = str_repeat( '&#8211; ', $level );
     833                $category->cat_name = wp_specialchars( $category->cat_name );
    834834                echo "\n\t<option value='$category->cat_ID'";
    835                 if ($currentparent == $category->cat_ID)
     835                if ( $currentparent == $category->cat_ID )
    836836                    echo " selected='selected'";
    837837                echo ">$pad$category->cat_name</option>";
    838                 wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level +1, $categories);
     838                wp_dropdown_cats( $currentcat, $currentparent, $category->cat_ID, $level +1, $categories );
    839839            }
    840840        }
     
    844844}
    845845
    846 function wp_create_thumbnail($file, $max_side, $effect = '') {
     846function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
    847847
    848848        // 1 = GIF, 2 = JPEG, 3 = PNG
    849849
    850     if (file_exists($file)) {
    851         $type = getimagesize($file);
     850    if ( file_exists( $file ) ) {
     851        $type = getimagesize( $file );
    852852
    853853        // if the associated function doesn't exist - then it's not
    854854        // handle. duh. i hope.
    855855
    856         if (!function_exists('imagegif') && $type[2] == 1) {
    857             $error = __('Filetype not supported. Thumbnail not created.');
    858         }
    859         elseif (!function_exists('imagejpeg') && $type[2] == 2) {
    860             $error = __('Filetype not supported. Thumbnail not created.');
    861         }
    862         elseif (!function_exists('imagepng') && $type[2] == 3) {
    863             $error = __('Filetype not supported. Thumbnail not created.');
     856        if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
     857            $error = __( 'Filetype not supported. Thumbnail not created.' );
     858        }
     859        elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
     860            $error = __( 'Filetype not supported. Thumbnail not created.' );
     861        }
     862        elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
     863            $error = __( 'Filetype not supported. Thumbnail not created.' );
    864864        } else {
    865865
    866866            // create the initial copy from the original file
    867             if ($type[2] == 1) {
    868                 $image = imagecreatefromgif($file);
     867            if ( $type[2] == 1 ) {
     868                $image = imagecreatefromgif( $file );
    869869            }
    870             elseif ($type[2] == 2) {
    871                 $image = imagecreatefromjpeg($file);
     870            elseif ( $type[2] == 2 ) {
     871                $image = imagecreatefromjpeg( $file );
    872872            }
    873             elseif ($type[2] == 3) {
    874                 $image = imagecreatefrompng($file);
     873            elseif ( $type[2] == 3 ) {
     874                $image = imagecreatefrompng( $file );
    875875            }
    876876
    877             if (function_exists('imageantialias'))
    878                 imageantialias($image, TRUE);
    879 
    880             $image_attr = getimagesize($file);
     877            if ( function_exists( 'imageantialias' ))
     878                imageantialias( $image, TRUE );
     879
     880            $image_attr = getimagesize( $file );
    881881
    882882            // figure out the longest side
    883883
    884             if ($image_attr[0] > $image_attr[1]) {
     884            if ( $image_attr[0] > $image_attr[1] ) {
    885885                $image_width = $image_attr[0];
    886886                $image_height = $image_attr[1];
     
    900900            }
    901901
    902             $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
    903             @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
     902            $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
     903            @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
    904904
    905905            // If no filters change the filename, we'll do a default transformation.
    906             if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )
    907                 $thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
    908 
    909             $thumbpath = str_replace(basename($file), $thumb, $file);
     906            if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
     907                $thumb = preg_replace( '!(\.[^.]+)?$!', __( '.thumbnail' ).'$1', basename( $file ), 1 );
     908
     909            $thumbpath = str_replace( basename( $file ), $thumb, $file );
    910910
    911911            // move the thumbnail to it's final destination
    912             if ($type[2] == 1) {
    913                 if (!imagegif($thumbnail, $thumbpath)) {
    914                     $error = __("Thumbnail path invalid");
     912            if ( $type[2] == 1 ) {
     913                if (!imagegif( $thumbnail, $thumbpath ) ) {
     914                    $error = __( "Thumbnail path invalid" );
    915915                }
    916916            }
    917             elseif ($type[2] == 2) {
    918                 if (!imagejpeg($thumbnail, $thumbpath)) {
    919                     $error = __("Thumbnail path invalid");
     917            elseif ( $type[2] == 2 ) {
     918                if (!imagejpeg( $thumbnail, $thumbpath ) ) {
     919                    $error = __( "Thumbnail path invalid" );
    920920                }
    921921            }
    922             elseif ($type[2] == 3) {
    923                 if (!imagepng($thumbnail, $thumbpath)) {
    924                     $error = __("Thumbnail path invalid");
     922            elseif ( $type[2] == 3 ) {
     923                if (!imagepng( $thumbnail, $thumbpath ) ) {
     924                    $error = __( "Thumbnail path invalid" );
    925925                }
    926926            }
     
    928928        }
    929929    } else {
    930         $error = __('File not found');
    931     }
    932 
    933     if (!empty ($error)) {
     930        $error = __( 'File not found' );
     931    }
     932
     933    if (!empty ( $error ) ) {
    934934        return $error;
    935935    } else {
     
    940940
    941941// Some postmeta stuff
    942 function has_meta($postid) {
     942function has_meta( $postid ) {
    943943    global $wpdb;
    944944
    945     return $wpdb->get_results("
     945    return $wpdb->get_results( "
    946946            SELECT meta_key, meta_value, meta_id, post_id
    947947            FROM $wpdb->postmeta
    948948            WHERE post_id = '$postid'
    949             ORDER BY meta_key,meta_id", ARRAY_A);
    950 
    951 }
    952 
    953 function list_meta($meta) {
     949            ORDER BY meta_key,meta_id", ARRAY_A );
     950
     951}
     952
     953function list_meta( $meta ) {
    954954    global $post_ID;
    955955    // Exit if no meta
    956     if (!$meta) {
     956    if (!$meta ) {
    957957        echo '<tbody id="the-list"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS
    958958        return;
     
    962962    <thead>
    963963    <tr>
    964         <th><?php _e('Key') ?></th>
    965         <th><?php _e('Value') ?></th>
    966         <th colspan='2'><?php _e('Action') ?></th>
     964        <th><?php _e( 'Key' ) ?></th>
     965        <th><?php _e( 'Value' ) ?></th>
     966        <th colspan='2'><?php _e( 'Action' ) ?></th>
    967967    </tr>
    968968    </thead>
    969969<?php
    970970    $r ="\n\t<tbody id='the-list'>";
    971     foreach ($meta as $entry) {
     971    foreach ( $meta as $entry ) {
    972972        ++ $count;
    973         if ($count % 2)
     973        if ( $count % 2 )
    974974            $style = 'alternate';
    975975        else
    976976            $style = '';
    977         if ('_' == $entry['meta_key'] { 0 })
     977        if ('_' == $entry['meta_key'] { 0 } )
    978978            $style .= ' hidden';
    979979
    980         if ( is_serialized($entry['meta_value']) ) {
    981             if ( is_serialized_string($entry['meta_value']) ) {
     980        if ( is_serialized( $entry['meta_value'] ) ) {
     981            if ( is_serialized_string( $entry['meta_value'] ) ) {
    982982                // this is a serialized string, so we should display it
    983                 $entry['meta_value'] = maybe_unserialize($entry['meta_value']);
     983                $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
    984984            } else {
    985985                // this is a serialized array/object so we should NOT display it
     
    989989        }
    990990
    991         $key_js = js_escape($entry['meta_key']);
     991        $key_js = js_escape( $entry['meta_key'] );
    992992        $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true );
    993993        $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true );
     
    995995        $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
    996996        $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
    997         $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />";
     997        $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__( 'Update' )."' /><br />";
    998998        $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
    999         $r .= sprintf(__("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), $key_js);
    1000         $r .= "' );\" class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>";
     999        $r .= sprintf( __("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop." ), $key_js );
     1000        $r .= "' );\" class='deletemeta' tabindex='6' value='".__( 'Delete' )."' /></td>";
    10011001        $r .= "\n\t</tr>";
    10021002    }
     
    10091009    global $wpdb;
    10101010
    1011     $keys = $wpdb->get_col("
     1011    $keys = $wpdb->get_col( "
    10121012            SELECT meta_key
    10131013            FROM $wpdb->postmeta
    10141014            GROUP BY meta_key
    1015             ORDER BY meta_key");
     1015            ORDER BY meta_key" );
    10161016
    10171017    return $keys;
     
    10201020function meta_form() {
    10211021    global $wpdb;
    1022     $limit = (int) apply_filters('postmeta_form_limit', 30);
    1023     $keys = $wpdb->get_col("
     1022    $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
     1023    $keys = $wpdb->get_col( "
    10241024        SELECT meta_key
    10251025        FROM $wpdb->postmeta
    10261026        GROUP BY meta_key
    10271027        ORDER BY meta_id DESC
    1028         LIMIT $limit");
    1029     natcasesort($keys);
     1028        LIMIT $limit" );
     1029    natcasesort( $keys );
    10301030?>
    1031 <h3><?php _e('Add a new custom field:') ?></h3>
     1031<h3><?php _e( 'Add a new custom field:' ) ?></h3>
    10321032<table id="newmeta" cellspacing="3" cellpadding="3">
    10331033    <tr>
    1034 <th colspan="2"><?php _e('Key') ?></th>
    1035 <th><?php _e('Value') ?></th>
     1034<th colspan="2"><?php _e( 'Key' ) ?></th>
     1035<th><?php _e( 'Value' ) ?></th>
    10361036</tr>
    10371037    <tr valign="top">
     
    10391039<?php if ( $keys ) : ?>
    10401040<select id="metakeyselect" name="metakeyselect" tabindex="7">
    1041 <option value="#NONE#"><?php _e('- Select -'); ?></option>
     1041<option value="#NONE#"><?php _e( '- Select -' ); ?></option>
    10421042<?php
    10431043
    10441044    foreach ( $keys as $key ) {
    1045         $key = wp_specialchars($key, 1);
     1045        $key = wp_specialchars( $key, 1 );
    10461046        echo "\n\t<option value='$key'>$key</option>";
    10471047    }
    10481048?>
    1049 </select> <?php _e('or'); ?>
     1049</select> <?php _e( 'or' ); ?>
    10501050<?php endif; ?>
    10511051</td>
     
    10551055
    10561056</table>
    1057 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
     1057<p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field &raquo;' ) ?>" /></p>
    10581058<?php
    10591059
    10601060}
    10611061
    1062 function add_meta($post_ID) {
     1062function add_meta( $post_ID ) {
    10631063    global $wpdb;
    10641064    $post_ID = (int) $post_ID;
    10651065
    1066     $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect'])));
    1067     $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput'])));
    1068     $metavalue = maybe_serialize(stripslashes((trim($_POST['metavalue']))));
    1069     $metavalue = $wpdb->escape($metavalue);
    1070 
    1071     if ( ('0' === $metavalue || !empty ($metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) {
     1066    $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) );
     1067    $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) );
     1068    $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) ));
     1069    $metavalue = $wpdb->escape( $metavalue );
     1070
     1071    if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
    10721072        // We have a key/value pair. If both the select and the
    10731073        // input for the key have data, the input takes precedence:
     
    10761076            $metakey = $metakeyselect;
    10771077
    1078         if ($metakeyinput)
     1078        if ( $metakeyinput)
    10791079            $metakey = $metakeyinput; // default
    10801080
    1081         $result = $wpdb->query("
     1081        $result = $wpdb->query( "
    10821082                        INSERT INTO $wpdb->postmeta
    1083                         (post_id,meta_key,meta_value)
    1084                         VALUES ('$post_ID','$metakey','$metavalue')
    1085                     ");
     1083                        (post_id,meta_key,meta_value )
     1084                        VALUES ('$post_ID','$metakey','$metavalue' )
     1085                    " );
    10861086        return $wpdb->insert_id;
    10871087    }
     
    10891089} // add_meta
    10901090
    1091 function delete_meta($mid) {
     1091function delete_meta( $mid ) {
    10921092    global $wpdb;
    10931093    $mid = (int) $mid;
    10941094
    1095     return $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
    1096 }
    1097 
    1098 function update_meta($mid, $mkey, $mvalue) {
     1095    return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
     1096}
     1097
     1098function update_meta( $mid, $mkey, $mvalue ) {
    10991099    global $wpdb;
    1100     $mvalue = maybe_serialize(stripslashes($mvalue));
    1101     $mvalue = $wpdb->escape($mvalue);
     1100    $mvalue = maybe_serialize( stripslashes( $mvalue ));
     1101    $mvalue = $wpdb->escape( $mvalue );
    11021102    $mid = (int) $mid;
    1103     return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
    1104 }
    1105 
    1106 function get_post_meta_by_id($mid) {
     1103    return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" );
     1104}
     1105
     1106function get_post_meta_by_id( $mid ) {
    11071107    global $wpdb;
    11081108    $mid = (int) $mid;
    11091109
    1110     $meta = $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'");
    1111     if ( is_serialized_string($meta->meta_value) )
    1112         $meta->meta_value = maybe_unserialize($meta->meta_value);
     1110    $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
     1111    if ( is_serialized_string( $meta->meta_value ) )
     1112        $meta->meta_value = maybe_unserialize( $meta->meta_value );
    11131113    return $meta;
    11141114}
    11151115
    1116 function touch_time($edit = 1, $for_post = 1) {
     1116function touch_time( $edit = 1, $for_post = 1 ) {
    11171117    global $wp_locale, $post, $comment;
    11181118
    11191119    if ( $for_post )
    1120         $edit = ( ('draft' == $post->post_status) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date) ) ? false : true;
     1120        $edit = ( ('draft' == $post->post_status ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
    11211121 
    1122     echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__('Edit timestamp').'</label></legend>';
    1123 
    1124     $time_adj = time() + (get_option('gmt_offset') * 3600);
     1122    echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
     1123
     1124    $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
    11251125    $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
    1126     $jj = ($edit) ? mysql2date('d', $post_date) : gmdate('d', $time_adj);
    1127     $mm = ($edit) ? mysql2date('m', $post_date) : gmdate('m', $time_adj);
    1128     $aa = ($edit) ? mysql2date('Y', $post_date) : gmdate('Y', $time_adj);
    1129     $hh = ($edit) ? mysql2date('H', $post_date) : gmdate('H', $time_adj);
    1130     $mn = ($edit) ? mysql2date('i', $post_date) : gmdate('i', $time_adj);
    1131     $ss = ($edit) ? mysql2date('s', $post_date) : gmdate('s', $time_adj);
     1126    $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
     1127    $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
     1128    $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
     1129    $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
     1130    $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
     1131    $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
    11321132
    11331133    echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n";
    1134     for ($i = 1; $i < 13; $i = $i +1) {
     1134    for ( $i = 1; $i < 13; $i = $i +1 ) {
    11351135        echo "\t\t\t<option value=\"$i\"";
    1136         if ($i == $mm)
     1136        if ( $i == $mm )
    11371137            echo ' selected="selected"';
    1138         echo '>' . $wp_locale->get_month($i) . "</option>\n";
     1138        echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
    11391139    }
    11401140?>
     
    11471147<?php
    11481148    if ( $edit ) {
    1149         _e('Existing timestamp');
    1150         //echo ': ' . $wp_locale->get_month($mm) . "$jj, $aa @ $hh:$mn";
    1151         echo sprintf(__(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn);
     1149        _e( 'Existing timestamp' );
     1150        //echo ': ' . $wp_locale->get_month( $mm ) . "$jj, $aa @ $hh:$mn";
     1151        echo sprintf( __(': %1$s %2$s, %3$s @ %4$s:%5$s' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn );
    11521152    }
    11531153?>
     
    11581158
    11591159// insert_with_markers: Owen Winkler, fixed by Eric Anderson
    1160 // Inserts an array of strings into a file (.htaccess), placing it between
     1160// Inserts an array of strings into a file (.htaccess ), placing it between
    11611161// BEGIN and END markers.  Replaces existing marked info.  Retains surrounding
    11621162// data.  Creates file if none exists.
    11631163// Returns true on write success, false on failure.
    1164 function insert_with_markers($filename, $marker, $insertion) {
    1165     if (!file_exists($filename) || is_writeable($filename)) {
    1166         if (!file_exists($filename)) {
     1164function insert_with_markers( $filename, $marker, $insertion ) {
     1165    if (!file_exists( $filename ) || is_writeable( $filename ) ) {
     1166        if (!file_exists( $filename ) ) {
    11671167            $markerdata = '';
    11681168        } else {
    1169             $markerdata = explode("\n", implode('', file($filename)));
    1170         }
    1171 
    1172         $f = fopen($filename, 'w');
     1169            $markerdata = explode( "\n", implode( '', file( $filename ) ) );
     1170        }
     1171
     1172        $f = fopen( $filename, 'w' );
    11731173        $foundit = false;
    1174         if ($markerdata) {
     1174        if ( $markerdata ) {
    11751175            $state = true;
    1176             foreach ($markerdata as $n => $markerline) {
    1177                 if (strstr($markerline, "# BEGIN {$marker}"))
     1176            foreach ( $markerdata as $n => $markerline ) {
     1177                if ( strstr( $markerline, "# BEGIN {$marker}" ))
    11781178                    $state = false;
    1179                 if ($state) {
    1180                     if ( $n + 1 < count($markerdata) )
    1181                         fwrite($f, "{$markerline}\n");
     1179                if ( $state ) {
     1180                    if ( $n + 1 < count( $markerdata ) )
     1181                        fwrite( $f, "{$markerline}\n" );
    11821182                    else
    1183                         fwrite($f, "{$markerline}");
     1183                        fwrite( $f, "{$markerline}" );
    11841184                }
    1185                 if (strstr($markerline, "# END {$marker}")) {
    1186                     fwrite($f, "# BEGIN {$marker}\n");
    1187                     if (is_array($insertion))
    1188                         foreach ($insertion as $insertline)
    1189                             fwrite($f, "{$insertline}\n");
    1190                     fwrite($f, "# END {$marker}\n");
     1185                if ( strstr( $markerline, "# END {$marker}" ) ) {
     1186                    fwrite( $f, "# BEGIN {$marker}\n" );
     1187                    if ( is_array( $insertion ))
     1188                        foreach ( $insertion as $insertline )
     1189                            fwrite( $f, "{$insertline}\n" );
     1190                    fwrite( $f, "# END {$marker}\n" );
    11911191                    $state = true;
    11921192                    $foundit = true;
     
    11951195        }
    11961196        if (!$foundit) {
    1197             fwrite($f, "# BEGIN {$marker}\n");
    1198             foreach ($insertion as $insertline)
    1199                 fwrite($f, "{$insertline}\n");
    1200             fwrite($f, "# END {$marker}\n");
    1201         }
    1202         fclose($f);
     1197            fwrite( $f, "# BEGIN {$marker}\n" );
     1198            foreach ( $insertion as $insertline )
     1199                fwrite( $f, "{$insertline}\n" );
     1200            fwrite( $f, "# END {$marker}\n" );
     1201        }
     1202        fclose( $f );
    12031203        return true;
    12041204    } else {
     
    12081208
    12091209// extract_from_markers: Owen Winkler
    1210 // Returns an array of strings from a file (.htaccess) from between BEGIN
     1210// Returns an array of strings from a file (.htaccess ) from between BEGIN
    12111211// and END markers.
    1212 function extract_from_markers($filename, $marker) {
     1212function extract_from_markers( $filename, $marker ) {
    12131213    $result = array ();
    12141214
    1215     if (!file_exists($filename)) {
     1215    if (!file_exists( $filename ) ) {
    12161216        return $result;
    12171217    }
    12181218
    1219     if ($markerdata = explode("\n", implode('', file($filename))));
     1219    if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
    12201220    {
    12211221        $state = false;
    1222         foreach ($markerdata as $markerline) {
    1223             if (strstr($markerline, "# END {$marker}"))
     1222        foreach ( $markerdata as $markerline ) {
     1223            if ( strstr( $markerline, "# END {$marker}" ))
    12241224                $state = false;
    1225             if ($state)
     1225            if ( $state )
    12261226                $result[] = $markerline;
    1227             if (strstr($markerline, "# BEGIN {$marker}"))
     1227            if ( strstr( $markerline, "# BEGIN {$marker}" ))
    12281228                $state = true;
    12291229        }
     
    12401240        return false;
    12411241
    1242     if ( function_exists('apache_get_modules') ) {
    1243         if ( !in_array('mod_rewrite', apache_get_modules()) )
     1242    if ( function_exists( 'apache_get_modules' ) ) {
     1243        if ( !in_array( 'mod_rewrite', apache_get_modules() ) )
    12441244            return false;
    12451245    }
     
    12521252    $home_path = get_home_path();
    12531253
    1254     if (!$wp_rewrite->using_mod_rewrite_permalinks())
     1254    if (!$wp_rewrite->using_mod_rewrite_permalinks() )
    12551255        return;
    12561256
    1257     if (!((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess')))
     1257    if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) )
    12581258        return;
    12591259
    1260     if (! got_mod_rewrite())
     1260    if (! got_mod_rewrite() )
    12611261        return;
    12621262
    1263     $rules = explode("\n", $wp_rewrite->mod_rewrite_rules());
    1264     insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
     1263    $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
     1264    insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules );
    12651265}
    12661266
     
    12781278    $page_templates = array ();
    12791279
    1280     if (is_array($templates)) {
    1281         foreach ($templates as $template) {
    1282             $template_data = implode('', file(ABSPATH.$template));
    1283             preg_match("|Template Name:(.*)|i", $template_data, $name);
    1284             preg_match("|Description:(.*)|i", $template_data, $description);
     1280    if ( is_array( $templates ) ) {
     1281        foreach ( $templates as $template ) {
     1282            $template_data = implode( '', file( ABSPATH.$template ));
     1283            preg_match( "|Template Name:(.* )|i", $template_data, $name );
     1284            preg_match( "|Description:(.* )|i", $template_data, $description );
    12851285
    12861286            $name = $name[1];
    12871287            $description = $description[1];
    12881288
    1289             if (!empty ($name)) {
    1290                 $page_templates[trim($name)] = basename($template);
     1289            if (!empty ( $name ) ) {
     1290                $page_templates[trim( $name )] = basename( $template );
    12911291            }
    12921292        }
     
    12961296}
    12971297
    1298 function page_template_dropdown($default = '') {
     1298function page_template_dropdown( $default = '' ) {
    12991299    $templates = get_page_templates();
    1300     foreach (array_keys($templates) as $template)
    1301         : if ($default == $templates[$template])
     1300    foreach (array_keys( $templates ) as $template )
     1301        : if ( $default == $templates[$template] )
    13021302            $selected = " selected='selected'";
    13031303        else
     
    13071307}
    13081308
    1309 function parent_dropdown($default = 0, $parent = 0, $level = 0) {
     1309function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
    13101310    global $wpdb, $post_ID;
    1311     $items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order");
    1312 
    1313     if ($items) {
    1314         foreach ($items as $item) {
     1311    $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" );
     1312
     1313    if ( $items ) {
     1314        foreach ( $items as $item ) {
    13151315            // A page cannot be it's own parent.
    1316             if (!empty ($post_ID)) {
    1317                 if ($item->ID == $post_ID) {
     1316            if (!empty ( $post_ID ) ) {
     1317                if ( $item->ID == $post_ID ) {
    13181318                    continue;
    13191319                }
    13201320            }
    1321             $pad = str_repeat('&nbsp;', $level * 3);
    1322             if ($item->ID == $default)
     1321            $pad = str_repeat( '&nbsp;', $level * 3 );
     1322            if ( $item->ID == $default)
    13231323                $current = ' selected="selected"';
    13241324            else
     
    13261326
    13271327            echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>";
    1328             parent_dropdown($default, $item->ID, $level +1);
     1328            parent_dropdown( $default, $item->ID, $level +1 );
    13291329        }
    13301330    } else {
     
    13441344    /*echo "pa: $parent pn: $pagenow pp: $plugin_page<br/>";
    13451345    echo "<pre>";
    1346     print_r($_wp_menu_nopriv);
    1347     print_r($_wp_submenu_nopriv);
     1346    print_r( $_wp_menu_nopriv );
     1347    print_r( $_wp_submenu_nopriv );
    13481348    echo "</pre>";*/
    1349     if ( isset($_wp_submenu_nopriv[$parent][$pagenow]) )
     1349    if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
    13501350        return false;
    13511351
    1352     if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$parent][$plugin_page]) )
     1352    if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) )
    13531353        return false;
    13541354   
    1355     if ( empty($parent) ) {
    1356         if ( isset($_wp_menu_nopriv[$pagenow]) )
     1355    if ( empty( $parent) ) {
     1356        if ( isset( $_wp_menu_nopriv[$pagenow] ) )
    13571357            return false;
    1358         if ( isset($_wp_submenu_nopriv[$pagenow][$pagenow]) )
     1358        if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) )
    13591359            return false;
    1360         if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) )
     1360        if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) )
    13611361            return false;
    1362         foreach (array_keys($_wp_submenu_nopriv) as $key) {
    1363             if ( isset($_wp_submenu_nopriv[$key][$pagenow]) )
     1362        foreach (array_keys( $_wp_submenu_nopriv ) as $key ) {
     1363            if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) )
    13641364                return false;
    1365             if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$key][$plugin_page]) )
     1365            if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) )
    13661366            return false;   
    13671367        }
     
    13691369    }
    13701370
    1371     if (isset ($submenu[$parent])) {
    1372         foreach ($submenu[$parent] as $submenu_array) {
    1373             if ($submenu_array[2] == $pagenow) {
    1374                 if (current_user_can($submenu_array[1]))
     1371    if ( isset( $submenu[$parent] ) ) {
     1372        foreach ( $submenu[$parent] as $submenu_array ) {
     1373            if ( $submenu_array[2] == $pagenow ) {
     1374                if ( current_user_can( $submenu_array[1] ))
    13751375                    return true;
    13761376                else
     
    13801380    }
    13811381
    1382     foreach ($menu as $menu_array) {
    1383         if ($menu_array[2] == $parent) {
    1384             if (current_user_can($menu_array[1]))
     1382    foreach ( $menu as $menu_array ) {
     1383        if ( $menu_array[2] == $parent) {
     1384            if ( current_user_can( $menu_array[1] ))
    13851385                return true;
    13861386            else
     
    13991399    global $plugin_page;
    14001400
    1401     if (isset ($title) && !empty ($title)) {
     1401    if ( isset( $title ) && !empty ( $title ) ) {
    14021402        return $title;
    14031403    }
    14041404
    1405     $hook = get_plugin_page_hook($plugin_page, $pagenow);
     1405    $hook = get_plugin_page_hook( $plugin_page, $pagenow );
    14061406
    14071407    $parent = $parent1 = get_admin_page_parent();
    1408     if (empty ($parent)) {
    1409         foreach ($menu as $menu_array) {
    1410             if (isset ($menu_array[3])) {
    1411                 if ($menu_array[2] == $pagenow) {
     1408    if ( empty ( $parent) ) {
     1409        foreach ( $menu as $menu_array ) {
     1410            if ( isset( $menu_array[3] ) ) {
     1411                if ( $menu_array[2] == $pagenow ) {
    14121412                    $title = $menu_array[3];
    14131413                    return $menu_array[3];
    14141414                } else
    1415                     if (isset ($plugin_page) && ($plugin_page == $menu_array[2]) && ($hook == $menu_array[3])) {
     1415                    if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) {
    14161416                        $title = $menu_array[3];
    14171417                        return $menu_array[3];
    14181418                    }
     1419            } else {
     1420                $title = $menu_array[0];
     1421                return $title;
    14191422            }
    14201423        }
    14211424    } else {
    1422         foreach (array_keys($submenu) as $parent) {
    1423             foreach ($submenu[$parent] as $submenu_array) {
    1424                 if (isset ($submenu_array[3])) {
    1425                     if ($submenu_array[2] == $pagenow) {
     1425        foreach (array_keys( $submenu ) as $parent) {
     1426            foreach ( $submenu[$parent] as $submenu_array ) {
     1427                if ( isset( $plugin_page ) &&
     1428                    ($plugin_page == $submenu_array[2] ) &&
     1429                    (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) )
     1430                    ) {
    14261431                        $title = $submenu_array[3];
    14271432                        return $submenu_array[3];
    1428                     } else
    1429                         if (isset ($plugin_page) && ($plugin_page == $submenu_array[2]) && (($parent == $pagenow) || ($parent == $plugin_page) || ($plugin_page == $hook) || (($pagenow == 'admin.php') && ($parent1 != $submenu_array[2])))) {
    1430                             $title = $submenu_array[3];
    1431                             return $submenu_array[3];
    1432                         }
     1433                    }
     1434
     1435                if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page
     1436                    continue;
     1437
     1438                if ( isset( $submenu_array[3] ) ) {
     1439                    $title = $submenu_array[3];
     1440                    return $submenu_array[3];
     1441                } else {
     1442                    $title = $submenu_array[0];
     1443                    return $title;
    14331444                }
    14341445            }
     
    14361447    }
    14371448
    1438     return '';
     1449    return $title;
    14391450}
    14401451
     
    14491460    global $_wp_submenu_nopriv;
    14501461
    1451     if ( !empty ($parent_file) ) {
    1452         if ( isset($_wp_real_parent_file[$parent_file]) )
     1462    if ( !empty ( $parent_file ) ) {
     1463        if ( isset( $_wp_real_parent_file[$parent_file] ) )
    14531464            $parent_file = $_wp_real_parent_file[$parent_file];
    14541465
     
    14561467    }
    14571468
    1458     if ($pagenow == 'admin.php' && isset ($plugin_page)) {
    1459         foreach ($menu as $parent_menu) {
    1460             if ($parent_menu[2] == $plugin_page) {
     1469    if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) {
     1470        foreach ( $menu as $parent_menu ) {
     1471            if ( $parent_menu[2] == $plugin_page ) {
    14611472                $parent_file = $plugin_page;
    1462                 if ( isset($_wp_real_parent_file[$parent_file]) )
     1473                if ( isset( $_wp_real_parent_file[$parent_file] ) )
    14631474                    $parent_file = $_wp_real_parent_file[$parent_file];
    14641475                return $parent_file;
    14651476            }
    14661477        }
    1467         if ( isset($_wp_menu_nopriv[$plugin_page]) ) {
     1478        if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) {
    14681479            $parent_file = $plugin_page;
    1469             if ( isset($_wp_real_parent_file[$parent_file]) )
     1480            if ( isset( $_wp_real_parent_file[$parent_file] ) )
    14701481                    $parent_file = $_wp_real_parent_file[$parent_file];
    14711482            return $parent_file;
     
    14731484    }
    14741485
    1475     if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) ) {
     1486    if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) {
    14761487        $parent_file = $pagenow;
    1477         if ( isset($_wp_real_parent_file[$parent_file]) )
     1488        if ( isset( $_wp_real_parent_file[$parent_file] ) )
    14781489            $parent_file = $_wp_real_parent_file[$parent_file];
    14791490        return $parent_file;       
    14801491    }
    14811492
    1482     foreach (array_keys($submenu) as $parent) {
    1483         foreach ($submenu[$parent] as $submenu_array) {
    1484             if ( isset($_wp_real_parent_file[$parent]) )
     1493    foreach (array_keys( $submenu ) as $parent) {
     1494        foreach ( $submenu[$parent] as $submenu_array ) {
     1495            if ( isset( $_wp_real_parent_file[$parent] ) )
    14851496                $parent = $_wp_real_parent_file[$parent];
    1486             if ($submenu_array[2] == $pagenow) {
     1497            if ( $submenu_array[2] == $pagenow ) {
    14871498                $parent_file = $parent;
    14881499                return $parent;
    14891500            } else
    1490                 if (isset ($plugin_page) && ($plugin_page == $submenu_array[2])) {
     1501                if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) {
    14911502                    $parent_file = $parent;
    14921503                    return $parent;
     
    14991510}
    15001511
    1501 function add_menu_page($page_title, $menu_title, $access_level, $file, $function = '') {
     1512function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
    15021513    global $menu, $admin_page_hooks;
    15031514
    1504     $file = plugin_basename($file);
    1505 
    1506     $menu[] = array ($menu_title, $access_level, $file, $page_title);
    1507 
    1508     $admin_page_hooks[$file] = sanitize_title($menu_title);
    1509 
    1510     $hookname = get_plugin_page_hookname($file, '');
    1511     if (!empty ($function) && !empty ($hookname))
    1512         add_action($hookname, $function);
     1515    $file = plugin_basename( $file );
     1516
     1517    $menu[] = array ( $menu_title, $access_level, $file, $page_title );
     1518
     1519    $admin_page_hooks[$file] = sanitize_title( $menu_title );
     1520
     1521    $hookname = get_plugin_page_hookname( $file, '' );
     1522    if (!empty ( $function ) && !empty ( $hookname ))
     1523        add_action( $hookname, $function );
    15131524
    15141525    return $hookname;
    15151526}
    15161527
    1517 function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') {
     1528function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) {
    15181529    global $submenu;
    15191530    global $menu;
     
    15221533    global $_wp_menu_nopriv;
    15231534
    1524     $file = plugin_basename($file);
    1525 
    1526     $parent = plugin_basename($parent);
    1527     if ( isset($_wp_real_parent_file[$parent]) )
     1535    $file = plugin_basename( $file );
     1536
     1537    $parent = plugin_basename( $parent);
     1538    if ( isset( $_wp_real_parent_file[$parent] ) )
    15281539        $parent = $_wp_real_parent_file[$parent];
    15291540
    1530     if ( !current_user_can($access_level) ) {
     1541    if ( !current_user_can( $access_level ) ) {
    15311542        $_wp_submenu_nopriv[$parent][$file] = true;
    15321543        return false;
     
    15371548    // parent file someone is trying to link back to the parent manually.  In
    15381549    // this case, don't automatically add a link back to avoid duplication.
    1539     if (!isset ($submenu[$parent]) && $file != $parent  ) {
    1540         foreach ($menu as $parent_menu) {
    1541             if ( $parent_menu[2] == $parent && current_user_can($parent_menu[1]) ) {
     1550    if (!isset( $submenu[$parent] ) && $file != $parent  ) {
     1551        foreach ( $menu as $parent_menu ) {
     1552            if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) {
    15421553                $submenu[$parent][] = $parent_menu;
    15431554            }
     
    15451556    }
    15461557
    1547     $submenu[$parent][] = array ($menu_title, $access_level, $file, $page_title);
    1548 
    1549     $hookname = get_plugin_page_hookname($file, $parent);
    1550     if (!empty ($function) && !empty ($hookname))
    1551         add_action($hookname, $function);
     1558    $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title );
     1559
     1560    $hookname = get_plugin_page_hookname( $file, $parent);
     1561    if (!empty ( $function ) && !empty ( $hookname ))
     1562        add_action( $hookname, $function );
    15521563
    15531564    return $hookname;
    15541565}
    15551566
    1556 function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') {
    1557     return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function);
    1558 }
    1559 
    1560 function add_management_page($page_title, $menu_title, $access_level, $file, $function = '') {
    1561     return add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file, $function);
    1562 }
    1563 
    1564 function add_theme_page($page_title, $menu_title, $access_level, $file, $function = '') {
    1565     return add_submenu_page('themes.php', $page_title, $menu_title, $access_level, $file, $function);
    1566 }
    1567 
    1568 function validate_file($file, $allowed_files = '') {
    1569     if (false !== strpos($file, './'))
     1567function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
     1568    return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function );
     1569}
     1570
     1571function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
     1572    return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function );
     1573}
     1574
     1575function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
     1576    return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function );
     1577}
     1578
     1579function validate_file( $file, $allowed_files = '' ) {
     1580    if ( false !== strpos( $file, './' ))
    15701581        return 1;
    15711582
    1572     if (':' == substr($file, 1, 1))
     1583    if (':' == substr( $file, 1, 1 ))
    15731584        return 2;
    15741585
    1575     if (!empty ($allowed_files) && (!in_array($file, $allowed_files)))
     1586    if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
    15761587        return 3;
    15771588
     
    15791590}
    15801591
    1581 function validate_file_to_edit($file, $allowed_files = '') {
    1582     $file = stripslashes($file);
    1583 
    1584     $code = validate_file($file, $allowed_files);
    1585 
    1586     if (!$code)
     1592function validate_file_to_edit( $file, $allowed_files = '' ) {
     1593    $file = stripslashes( $file );
     1594
     1595    $code = validate_file( $file, $allowed_files );
     1596
     1597    if (!$code )
    15871598        return $file;
    15881599
    1589     switch ($code) {
     1600    switch ( $code ) {
    15901601        case 1 :
    1591             wp_die(__('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.'));
     1602            wp_die( __('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' ));
    15921603
    15931604        case 2 :
    1594             wp_die(__('Sorry, can&#8217;t call files with their real path.'));
     1605            wp_die( __('Sorry, can&#8217;t call files with their real path.' ));
    15951606
    15961607        case 3 :
    1597             wp_die(__('Sorry, that file cannot be edited.'));
     1608            wp_die( __('Sorry, that file cannot be edited.' ));
    15981609    }
    15991610}
    16001611
    16011612function get_home_path() {
    1602     $home = get_option('home');
    1603     if ($home != '' && $home != get_option('siteurl')) {
    1604         $home_path = parse_url($home);
     1613    $home = get_option( 'home' );
     1614    if ( $home != '' && $home != get_option( 'siteurl' ) ) {
     1615        $home_path = parse_url( $home );
    16051616        $home_path = $home_path['path'];
    1606         $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"]);
    1607         $home_path = trailingslashit($root.$home_path);
     1617        $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
     1618        $home_path = trailingslashit( $root.$home_path );
    16081619    } else {
    16091620        $home_path = ABSPATH;
     
    16131624}
    16141625
    1615 function get_real_file_to_edit($file) {
    1616     if ('index.php' == $file || '.htaccess' == $file) {
     1626function get_real_file_to_edit( $file ) {
     1627    if ('index.php' == $file || '.htaccess' == $file ) {
    16171628        $real_file = get_home_path().$file;
    16181629    } else {
     
    16231634}
    16241635
    1625 $wp_file_descriptions = array ('index.php' => __('Main Index Template'), 'style.css' => __('Stylesheet'), 'comments.php' => __('Comments'), 'comments-popup.php' => __('Popup Comments'), 'footer.php' => __('Footer'), 'header.php' => __('Header'), 'sidebar.php' => __('Sidebar'), 'archive.php' => __('Archives'), 'category.php' => __('Category Template'), 'page.php' => __('Page Template'), 'search.php' => __('Search Results'), 'single.php' => __('Single Post'), '404.php' => __('404 Template'), 'my-hacks.php' => __('my-hacks.php (legacy hacks support)'), '.htaccess' => __('.htaccess (for rewrite rules)'),
     1636$wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ),
    16261637    // Deprecated files
    1627     'wp-layout.css' => __('Stylesheet'), 'wp-comments.php' => __('Comments Template'), 'wp-comments-popup.php' => __('Popup Comments Template'));
    1628 
    1629 function get_file_description($file) {
     1638    'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' ));
     1639
     1640function get_file_description( $file ) {
    16301641    global $wp_file_descriptions;
    16311642
    1632     if (isset ($wp_file_descriptions[basename($file)])) {
    1633         return $wp_file_descriptions[basename($file)];
     1643    if ( isset( $wp_file_descriptions[basename( $file )] ) ) {
     1644        return $wp_file_descriptions[basename( $file )];
    16341645    }
    16351646    elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) {
    1636         $template_data = implode('', file( ABSPATH . $file ));
    1637         if (preg_match("|Template Name:(.*)|i", $template_data, $name))
     1647        $template_data = implode( '', file( ABSPATH . $file ) );
     1648        if ( preg_match( "|Template Name:(.* )|i", $template_data, $name ))
    16381649            return $name[1];
    16391650    }
    16401651
    1641     return basename($file);
    1642 }
    1643 
    1644 function update_recently_edited($file) {
    1645     $oldfiles = (array) get_option('recently_edited');
    1646     if ($oldfiles) {
    1647         $oldfiles = array_reverse($oldfiles);
     1652    return basename( $file );
     1653}
     1654
     1655function update_recently_edited( $file ) {
     1656    $oldfiles = (array ) get_option( 'recently_edited' );
     1657    if ( $oldfiles ) {
     1658        $oldfiles = array_reverse( $oldfiles );
    16481659        $oldfiles[] = $file;
    1649         $oldfiles = array_reverse($oldfiles);
    1650         $oldfiles = array_unique($oldfiles);
    1651         if (5 < count($oldfiles))
    1652             array_pop($oldfiles);
     1660        $oldfiles = array_reverse( $oldfiles );
     1661        $oldfiles = array_unique( $oldfiles );
     1662        if ( 5 < count( $oldfiles ))
     1663            array_pop( $oldfiles );
    16531664    } else {
    16541665        $oldfiles[] = $file;
    16551666    }
    1656     update_option('recently_edited', $oldfiles);
    1657 }
    1658 
    1659 function get_plugin_data($plugin_file) {
    1660     $plugin_data = implode('', file($plugin_file));
    1661     preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
    1662     preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
    1663     preg_match("|Description:(.*)|i", $plugin_data, $description);
    1664     preg_match("|Author:(.*)|i", $plugin_data, $author_name);
    1665     preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
    1666     if (preg_match("|Version:(.*)|i", $plugin_data, $version))
    1667         $version = trim($version[1]);
     1667    update_option( 'recently_edited', $oldfiles );
     1668}
     1669
     1670function get_plugin_data( $plugin_file ) {
     1671    $plugin_data = implode( '', file( $plugin_file ));
     1672    preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name );
     1673    preg_match( "|Plugin URI:(.*)|i", $plugin_data, $plugin_uri );
     1674    preg_match( "|Description:(.*)|i", $plugin_data, $description );
     1675    preg_match( "|Author:(.*)|i", $plugin_data, $author_name );
     1676    preg_match( "|Author URI:(.*)|i", $plugin_data, $author_uri );
     1677    if ( preg_match( "|Version:(.*)|i", $plugin_data, $version ))
     1678        $version = trim( $version[1] );
    16681679    else
    16691680        $version = '';
    16701681
    1671     $description = wptexturize(trim($description[1]));
     1682    $description = wptexturize( trim( $description[1] ));
    16721683
    16731684    $name = $plugin_name[1];
    1674     $name = trim($name);
     1685    $name = trim( $name );
    16751686    $plugin = $name;
    1676     if ('' != $plugin_uri[1] && '' != $name) {
    1677         $plugin = '<a href="' . trim($plugin_uri[1]) . '" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>';
    1678     }
    1679 
    1680     if ('' == $author_uri[1]) {
    1681         $author = trim($author_name[1]);
    1682     } else {
    1683         $author = '<a href="' . trim($author_uri[1]) . '" title="'.__('Visit author homepage').'">' . trim($author_name[1]) . '</a>';
    1684     }
    1685 
    1686     return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
     1687    if ('' != $plugin_uri[1] && '' != $name ) {
     1688        $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>';
     1689    }
     1690
     1691    if ('' == $author_uri[1] ) {
     1692        $author = trim( $author_name[1] );
     1693    } else {
     1694        $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>';
     1695    }
     1696
     1697    return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1] );
    16871698}
    16881699
     
    16901701    global $wp_plugins;
    16911702
    1692     if (isset ($wp_plugins)) {
     1703    if ( isset( $wp_plugins ) ) {
    16931704        return $wp_plugins;
    16941705    }
     
    16981709
    16991710    // Files in wp-content/plugins directory
    1700     $plugins_dir = @ dir($plugin_root);
    1701     if ($plugins_dir) {
    1702         while (($file = $plugins_dir->read()) !== false) {
    1703             if (preg_match('|^\.+$|', $file))
     1711    $plugins_dir = @ dir( $plugin_root);
     1712    if ( $plugins_dir ) {
     1713        while (($file = $plugins_dir->read() ) !== false ) {
     1714            if ( preg_match( '|^\.+$|', $file ))
    17041715                continue;
    1705             if (is_dir($plugin_root.'/'.$file)) {
    1706                 $plugins_subdir = @ dir($plugin_root.'/'.$file);
    1707                 if ($plugins_subdir) {
    1708                     while (($subfile = $plugins_subdir->read()) !== false) {
    1709                         if (preg_match('|^\.+$|', $subfile))
     1716            if ( is_dir( $plugin_root.'/'.$file ) ) {
     1717                $plugins_subdir = @ dir( $plugin_root.'/'.$file );
     1718                if ( $plugins_subdir ) {
     1719                    while (($subfile = $plugins_subdir->read() ) !== false ) {
     1720                        if ( preg_match( '|^\.+$|', $subfile ))
    17101721                            continue;
    1711                         if (preg_match('|\.php$|', $subfile))
     1722                        if ( preg_match( '|\.php$|', $subfile ))
    17121723                            $plugin_files[] = "$file/$subfile";
    17131724                    }
    17141725                }
    17151726            } else {
    1716                 if (preg_match('|\.php$|', $file))
     1727                if ( preg_match( '|\.php$|', $file ))
    17171728                    $plugin_files[] = $file;
    17181729            }
     
    17241735
    17251736    foreach ( $plugin_files as $plugin_file ) {
    1726         if ( !is_readable("$plugin_root/$plugin_file") )
     1737        if ( !is_readable( "$plugin_root/$plugin_file" ) )
    17271738            continue;
    17281739
    1729         $plugin_data = get_plugin_data("$plugin_root/$plugin_file");
    1730 
    1731         if ( empty ($plugin_data['Name']) )
     1740        $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" );
     1741
     1742        if ( empty ( $plugin_data['Name'] ) )
    17321743            continue;
    17331744
    1734         $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    1735     }
    1736 
    1737     uasort($wp_plugins, create_function('$a, $b', 'return strnatcasecmp($a["Name"], $b["Name"]);'));
     1745        $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;
     1746    }
     1747
     1748    uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
    17381749
    17391750    return $wp_plugins;
    17401751}
    17411752
    1742 function get_plugin_page_hookname($plugin_page, $parent_page) {
     1753function get_plugin_page_hookname( $plugin_page, $parent_page ) {
    17431754    global $admin_page_hooks;
    17441755
    17451756    $parent = get_admin_page_parent();
    17461757
    1747     if (empty ($parent_page) || 'admin.php' == $parent_page) {
    1748         if (isset ($admin_page_hooks[$plugin_page]))
     1758    if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) {
     1759        if ( isset( $admin_page_hooks[$plugin_page] ))
    17491760            $page_type = 'toplevel';
    17501761        else
    1751             if (isset ($admin_page_hooks[$parent]))
     1762            if ( isset( $admin_page_hooks[$parent] ))
    17521763                $page_type = $admin_page_hooks[$parent];
    17531764    } else
    1754         if (isset ($admin_page_hooks[$parent_page])) {
     1765        if ( isset( $admin_page_hooks[$parent_page] ) ) {
    17551766            $page_type = $admin_page_hooks[$parent_page];
    17561767        } else {
     
    17581769        }
    17591770
    1760     $plugin_name = preg_replace('!\.php!', '', $plugin_page);
     1771    $plugin_name = preg_replace( '!\.php!', '', $plugin_page );
    17611772
    17621773    return $page_type.'_page_'.$plugin_name;
    17631774}
    17641775
    1765 function get_plugin_page_hook($plugin_page, $parent_page) {
     1776function get_plugin_page_hook( $plugin_page, $parent_page ) {
    17661777    global $wp_filter;
    17671778
    1768     $hook = get_plugin_page_hookname($plugin_page, $parent_page);
    1769     if (isset ($wp_filter[$hook]))
     1779    $hook = get_plugin_page_hookname( $plugin_page, $parent_page );
     1780    if ( isset( $wp_filter[$hook] ))
    17701781        return $hook;
    17711782    else
     
    17741785
    17751786function browse_happy() {
    1776     $getit = __('WordPress recommends a better browser');
     1787    $getit = __( 'WordPress recommends a better browser' );
    17771788    echo '
    17781789        <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p>
    17791790        ';
    17801791}
    1781 if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
    1782     add_action('admin_footer', 'browse_happy');
    1783 
    1784 function documentation_link($for) {
     1792if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ))
     1793    add_action( 'admin_footer', 'browse_happy' );
     1794
     1795function documentation_link( $for ) {
    17851796    return;
    17861797}
    17871798
    1788 function register_importer($id, $name, $description, $callback) {
     1799function register_importer( $id, $name, $description, $callback ) {
    17891800    global $wp_importers;
    17901801
    1791     $wp_importers[$id] = array ($name, $description, $callback);
     1802    $wp_importers[$id] = array ( $name, $description, $callback );
    17921803}
    17931804
     
    18181829// array wp_handle_upload ( array &file [, array overrides] )
    18191830// file: reference to a single element of $_FILES. Call the function once for each uploaded file.
    1820 // overrides: an associative array of names=>values to override default variables with extract($overrides, EXTR_OVERWRITE).
     1831// overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
    18211832// On success, returns an associative array of file attributes.
    1822 // On failure, returns $overrides['upload_error_handler'](&$file, $message) or array('error'=>$message).
    1823 function wp_handle_upload(&$file, $overrides = false) {
     1833// On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
     1834function wp_handle_upload( &$file, $overrides = false ) {
    18241835    // The default error handler.
    1825     if (! function_exists('wp_handle_upload_error') ) {
    1826         function wp_handle_upload_error(&$file, $message) {
    1827             return array('error'=>$message);
     1836    if (! function_exists( 'wp_handle_upload_error' ) ) {
     1837        function wp_handle_upload_error( &$file, $message ) {
     1838            return array( 'error'=>$message );
    18281839        }
    18291840    }
     
    18361847
    18371848    // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
    1838     $upload_error_strings = array(false,
    1839         __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."),
    1840         __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."),
    1841         __("The uploaded file was only partially uploaded."),
    1842         __("No file was uploaded."),
    1843         __("Missing a temporary folder."),
    1844         __("Failed to write file to disk."));
     1849    $upload_error_strings = array( false,
     1850        __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ),
     1851        __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ),
     1852        __( "The uploaded file was only partially uploaded." ),
     1853        __( "No file was uploaded." ),
     1854        __( "Missing a temporary folder." ),
     1855        __( "Failed to write file to disk." ));
    18451856
    18461857    // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
     
    18521863
    18531864    // Install user overrides. Did we mention that this voids your warranty?
    1854     if ( is_array($overrides) )
    1855         extract($overrides, EXTR_OVERWRITE);
     1865    if ( is_array( $overrides ) )
     1866        extract( $overrides, EXTR_OVERWRITE );
    18561867
    18571868    // A correct form post will pass this test.
    1858     if ( $test_form && (!isset($_POST['action']) || ($_POST['action'] != $action)) )
    1859         return $upload_error_handler($file, __('Invalid form submission.'));
     1869    if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
     1870        return $upload_error_handler( $file, __( 'Invalid form submission.' ));
    18601871
    18611872    // A successful upload will pass this test. It makes no sense to override this one.
    18621873    if ( $file['error'] > 0 )
    1863         return $upload_error_handler($file, $upload_error_strings[$file['error']]);
     1874        return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
    18641875
    18651876    // A non-empty file will pass this test.
    1866     if ( $test_size && !($file['size'] > 0) )
    1867         return $upload_error_handler($file, __('File is empty. Please upload something more substantial.'));
     1877    if ( $test_size && !($file['size'] > 0 ) )
     1878        return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial.' ));
    18681879
    18691880    // A properly uploaded file will pass this test. There should be no reason to override this one.
    1870     if (! @ is_uploaded_file($file['tmp_name']) )
    1871         return $upload_error_handler($file, __('Specified file failed upload test.'));
     1881    if (! @ is_uploaded_file( $file['tmp_name'] ) )
     1882        return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
    18721883
    18731884    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    18741885    if ( $test_type ) {
    1875         $wp_filetype = wp_check_filetype($file['name'], $mimes);
    1876 
    1877         extract($wp_filetype);
     1886        $wp_filetype = wp_check_filetype( $file['name'], $mimes );
     1887
     1888        extract( $wp_filetype );
    18781889
    18791890        if ( !$type || !$ext )
    1880             return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
     1891            return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
    18811892    }
    18821893
    18831894    // A writable uploads dir will pass this test. Again, there's no point overriding this one.
    18841895    if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
    1885         return $upload_error_handler($file, $uploads['error']);
     1896        return $upload_error_handler( $file, $uploads['error'] );
    18861897
    18871898    // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
    1888     if ( isset($unique_filename_callback) && function_exists($unique_filename_callback) ) {
    1889         $filename = $unique_filename_callback($uploads['path'], $file['name']);
     1899    if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) {
     1900        $filename = $unique_filename_callback( $uploads['path'], $file['name'] );
    18901901    } else {
    18911902        $number = '';
    1892         $filename = str_replace('#', '_', $file['name']);
    1893         $filename = str_replace(array('\\', "'"), '', $filename);
    1894         if ( empty($ext) )
     1903        $filename = str_replace( '#', '_', $file['name'] );
     1904        $filename = str_replace( array( '\\', "'" ), '', $filename );
     1905        if ( empty( $ext) )
    18951906            $ext = '';
    18961907        else
    18971908            $ext = ".$ext";
    1898         while ( file_exists($uploads['path'] . "/$filename") ) {
     1909        while ( file_exists( $uploads['path'] . "/$filename" ) ) {
    18991910            if ( '' == "$number$ext" )
    19001911                $filename = $filename . ++$number . $ext;
    19011912            else
    1902                 $filename = str_replace("$number$ext", ++$number . $ext, $filename);
    1903         }
    1904         $filename = str_replace($ext, '', $filename);
    1905         $filename = sanitize_title_with_dashes($filename) . $ext;
     1913                $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
     1914        }
     1915        $filename = str_replace( $ext, '', $filename );
     1916        $filename = sanitize_title_with_dashes( $filename ) . $ext;
    19061917    }
    19071918
    19081919    // Move the file to the uploads dir
    19091920    $new_file = $uploads['path'] . "/$filename";
    1910     if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) )
    1911         wp_die(printf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
     1921    if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
     1922        wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ));
    19121923
    19131924    // Set correct file permissions
    1914     $stat = stat(dirname($new_file));
     1925    $stat = stat( dirname( $new_file ));
    19151926    $perms = $stat['mode'] & 0000666;
    1916     @ chmod($new_file, $perms);
     1927    @ chmod( $new_file, $perms );
    19171928
    19181929    // Compute the URL
    19191930    $url = $uploads['url'] . "/$filename";
    19201931   
    1921     $return = apply_filters( 'wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type) );
     1932    $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
    19221933
    19231934    return $return;
    19241935}
    19251936
    1926 function wp_shrink_dimensions($width, $height, $wmax = 128, $hmax = 96) {
     1937function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
    19271938    if ( $height <= $hmax && $width <= $wmax )
    1928         return array($width, $height);
     1939        return array( $width, $height);
    19291940    elseif ( $width / $height > $wmax / $hmax )
    1930         return array($wmax, (int) ($height / $width * $wmax));
     1941        return array( $wmax, (int) ($height / $width * $wmax ));
    19311942    else
    1932         return array((int) ($width / $height * $hmax), $hmax);
    1933 }
    1934 
    1935 function wp_import_cleanup($id) {
    1936     wp_delete_attachment($id);
    1937 }
    1938 
    1939 function wp_import_upload_form($action) {
    1940     $size = strtolower( ini_get('upload_max_filesize') );
     1943        return array( (int) ($width / $height * $hmax ), $hmax );
     1944}
     1945
     1946function wp_import_cleanup( $id ) {
     1947    wp_delete_attachment( $id );
     1948}
     1949
     1950function wp_import_upload_form( $action ) {
     1951    $size = strtolower( ini_get( 'upload_max_filesize' ) );
    19411952    $bytes = 0;
    19421953    if ( strstr( $size, 'k' ) )
     
    19491960<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo $action ?>">
    19501961<p>
    1951 <label for="upload"><?php _e('Choose a file from your computer:'); ?></label> (<?php printf( __('Maximum size: %s'), $size ); ?>)
     1962<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?> )
    19521963<input type="file" id="upload" name="import" size="25" />
    19531964<input type="hidden" name="action" value="save" />
     
    19551966</p>
    19561967<p class="submit">
    1957 <input type="submit" value="<?php _e('Upload file and import'); ?> &raquo;" />
     1968<input type="submit" value="<?php _e( 'Upload file and import' ); ?> &raquo;" />
    19581969</p>
    19591970</form>
     
    19621973
    19631974function wp_import_handle_upload() {
    1964     $overrides = array('test_form' => false, 'test_type' => false);
    1965     $file = wp_handle_upload($_FILES['import'], $overrides);
    1966 
    1967     if ( isset($file['error']) )
     1975    $overrides = array( 'test_form' => false, 'test_type' => false );
     1976    $file = wp_handle_upload( $_FILES['import'], $overrides );
     1977
     1978    if ( isset( $file['error'] ) )
    19681979        return $file;
    19691980
    19701981    $url = $file['url'];
    19711982    $file = addslashes( $file['file'] );
    1972     $filename = basename($file);
     1983    $filename = basename( $file );
    19731984
    19741985    // Construct the object array
    1975     $object = array(
    1976         'post_title' => $filename,
     1986    $object = array( 'post_title' => $filename,
    19771987        'post_content' => $url,
    19781988        'post_mime_type' => 'import',
     
    19811991
    19821992    // Save the data
    1983     $id = wp_insert_attachment($object, $file);
    1984 
    1985     return array('file' => $file, 'id' => $id);
    1986 }
    1987 
    1988 function the_attachment_links($id = false) {
     1993    $id = wp_insert_attachment( $object, $file );
     1994
     1995    return array( 'file' => $file, 'id' => $id );
     1996}
     1997
     1998function the_attachment_links( $id = false ) {
    19891999    $id = (int) $id;
    1990     $post = & get_post($id);
     2000    $post = & get_post( $id );
    19912001
    19922002    if ( $post->post_type != 'attachment' )
    19932003        return false;
    19942004
    1995     $icon = get_attachment_icon($post->ID);
     2005    $icon = get_attachment_icon( $post->ID );
    19962006    $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
    1997     $thumb = isset($attachment_data['thumb']);
     2007    $thumb = isset( $attachment_data['thumb'] );
    19982008?>
    19992009<form id="the-attachment-links">
     
    20022012    <col class="widefat" />
    20032013    <tr>
    2004         <th scope="row"><?php _e('URL') ?></th>
     2014        <th scope="row"><?php _e( 'URL' ) ?></th>
    20052015        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo $post->guid ?></textarea></td>
    20062016    </tr>
    20072017<?php if ( $icon ) : ?>
    20082018    <tr>
    2009         <th scope="row"><?php $thumb ? _e('Thumbnail linked to file') : _e('Image linked to file'); ?></th>
     2019        <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
    20102020        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid; ?>"><?php echo $icon ?></a></textarea></td>
    20112021    </tr>
    20122022    <tr>
    2013         <th scope="row"><?php $thumb ? _e('Thumbnail linked to page') : _e('Image linked to file'); ?></th>
    2014         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
     2023        <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to file' ); ?></th>
     2024        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
    20152025    </tr>
    20162026<?php else : ?>
    20172027    <tr>
    2018         <th scope="row"><?php _e('Link to file') ?></th>
    2019         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid);  ?></a></textarea></td>
     2028        <th scope="row"><?php _e( 'Link to file' ) ?></th>
     2029        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename( $post->guid );  ?></a></textarea></td>
    20202030    </tr>
    20212031    <tr>
    2022         <th scope="row"><?php _e('Link to page') ?></th>
    2023         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
     2032        <th scope="row"><?php _e( 'Link to page' ) ?></th>
     2033        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
    20242034    </tr>
    20252035<?php endif; ?>
     
    20292039}
    20302040
    2031 function get_udims($width, $height) {
     2041function get_udims( $width, $height) {
    20322042    if ( $height <= 96 && $width <= 128 )
    2033         return array($width, $height);
     2043        return array( $width, $height);
    20342044    elseif ( $width / $height > 4 / 3 )
    2035         return array(128, (int) ($height / $width * 128));
     2045        return array( 128, (int) ($height / $width * 128 ));
    20362046    else
    2037         return array((int) ($width / $height * 96), 96);
    2038 }
    2039 
    2040 function wp_reset_vars($vars) {
    2041     for ($i=0; $i<count($vars); $i += 1) {
     2047        return array( (int) ($width / $height * 96 ), 96 );
     2048}
     2049
     2050function wp_reset_vars( $vars ) {
     2051    for ( $i=0; $i<count( $vars ); $i += 1 ) {
    20422052        $var = $vars[$i];
    20432053        global $$var;
    20442054
    2045         if (!isset($$var)) {
    2046             if (empty($_POST["$var"])) {
    2047                 if (empty($_GET["$var"]))
     2055        if (!isset( $$var ) ) {
     2056            if ( empty( $_POST["$var"] ) ) {
     2057                if ( empty( $_GET["$var"] ) )
    20482058                    $$var = '';
    20492059                else
     
    20572067
    20582068// If siteurl or home changed, reset cookies and flush rewrite rules.
    2059 function update_home_siteurl($old_value, $value) {
     2069function update_home_siteurl( $old_value, $value ) {
    20602070    global $wp_rewrite, $user_login, $user_pass_md5;
    20612071
    2062     if ( defined("WP_INSTALLING") )
     2072    if ( defined( "WP_INSTALLING" ) )
    20632073        return;
    20642074
     
    20682078    wp_clearcookie();
    20692079    // Set cookies for new paths.
    2070     wp_setcookie($user_login, $user_pass_md5, true, get_option('home'), get_option('siteurl'));
    2071 }
    2072 
    2073 add_action('update_option_home', 'update_home_siteurl', 10, 2);
    2074 add_action('update_option_siteurl', 'update_home_siteurl', 10, 2);
    2075 
    2076 function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false) {
    2077     if ( ctype_digit($src_file) ) // Handle int as attachment ID
    2078         $src_file = get_attached_file($src_file);
    2079 
    2080     $src = wp_load_image($src_file);
    2081 
    2082     if ( !is_resource($src) )
     2080    wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' ));   
     2081}
     2082
     2083add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
     2084add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
     2085
     2086function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
     2087    if ( ctype_digit( $src_file ) ) // Handle int as attachment ID
     2088        $src_file = get_attached_file( $src_file );
     2089
     2090    $src = wp_load_image( $src_file );
     2091
     2092    if ( !is_resource( $src ))
    20832093        return $src;
    20842094
    2085     $dst = imagecreatetruecolor($dst_w, $dst_h);
     2095    $dst = imagecreatetruecolor( $dst_w, $dst_h );
    20862096
    20872097    if ( $src_abs ) {
     
    20902100    }
    20912101
    2092     imageantialias($dst, true);
    2093     imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
     2102    imageantialias( $dst, true );
     2103    imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
    20942104
    20952105    if ( !$dst_file )
    2096         $dst_file = str_replace(basename($src_file), 'cropped-'.basename($src_file), $src_file);
    2097 
    2098     $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file);
    2099 
    2100     if ( imagejpeg($dst, $dst_file) )
     2106        $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file );
     2107
     2108    $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
     2109
     2110    if ( imagejpeg( $dst, $dst_file ) )
    21012111        return $dst_file;
    21022112    else
     
    21042114}
    21052115
    2106 function wp_load_image($file) {
    2107     if ( ctype_digit($file) )
    2108         $file = get_attached_file($file);
    2109 
    2110     if ( !file_exists($file) )
     2116function wp_load_image( $file ) {
     2117    if ( ctype_digit( $file ) )
     2118        $file = get_attached_file( $file );
     2119
     2120    if ( !file_exists( $file ) )
    21112121        return "File '$file' doesn't exist?";
    21122122
    2113     $contents = file_get_contents($file);
    2114 
    2115     $image = imagecreatefromstring($contents);
    2116 
    2117     if ( !is_resource($image) )
     2123    $contents = file_get_contents( $file );
     2124
     2125    $image = imagecreatefromstring( $contents );
     2126
     2127    if ( !is_resource( $image ) )
    21182128        return "File '$file' is not image?";
    21192129
  • trunk/wp-admin/admin-header.php

    r4218 r4478  
    1717<head>
    1818<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
    19 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title; ?> &#8212; WordPress</title>
     19<title><?php bloginfo('name') ?> &rsaquo; <?php echo wp_specialchars( strip_tags( $title ) ); ?> &#8212; WordPress</title>
    2020<link rel="stylesheet" href="<?php echo get_option('siteurl') ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    2121<?php if ( ('rtl' == $wp_locale->text_direction) ) : ?>
  • trunk/wp-admin/admin.php

    r4349 r4478  
    8383    include(ABSPATH . "wp-admin/import/$importer.php");
    8484
    85     $parent_file = 'edit.php';
    8685    $submenu_file = 'import.php';
    87     $title = __('Import');
    8886
    8987    if (! isset($_GET['noheader']))
  • trunk/wp-admin/categories.php

    r4468 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Categories');
    5 $parent_file = 'edit.php';
    63
    74wp_reset_vars(array('action', 'cat'));
  • trunk/wp-admin/comment.php

    r4468 r4478  
    22require_once('admin.php');
    33
    4 $parent_file = 'edit.php';
    54$submenu_file = 'edit-comments.php';
    65
  • trunk/wp-admin/edit-comments.php

    r4474 r4478  
    22require_once('admin.php');
    33
    4 $title = __('Edit Comments');
    5 $parent_file = 'edit-comments.php';
    64wp_enqueue_script( 'admin-comments' );
    75
  • trunk/wp-admin/edit-pages.php

    r4258 r4478  
    11<?php
    22require_once('admin.php');
    3 $title = __('Pages');
    4 $parent_file = 'edit.php';
    53wp_enqueue_script( 'listman' );
    64require_once('admin-header.php');
  • trunk/wp-admin/edit.php

    r4465 r4478  
    22require_once('admin.php');
    33
    4 $title = __('Posts');
    5 $parent_file = 'edit.php';
    64wp_enqueue_script( 1 == $_GET['c'] ? 'admin-comments' : 'listman' );
    75require_once('admin-header.php');
  • trunk/wp-admin/export.php

    r4477 r4478  
    11<?php
    22require_once ('admin.php');
    3 $title = __('Export');
    4 $parent_file = 'edit.php';
    53
    64if ( isset( $_GET['download'] ) )
  • trunk/wp-admin/import.php

    r3986 r4478  
    11<?php
    22require_once ('admin.php');
    3 $title = __('Import');
    4 $parent_file = 'edit.php';
    53require_once ('admin-header.php');
    64?>
  • trunk/wp-admin/index.php

    r4399 r4478  
    11<?php
    22require_once('admin.php');
    3 $title = __('Dashboard');
    4 $parent_file = 'index.php';
    53require_once('admin-header.php');
    64require_once (ABSPATH . WPINC . '/rss.php');
  • trunk/wp-admin/link-add.php

    r4448 r4478  
    22require_once('admin.php');
    33
    4 $title = __('Add Bookmark');
    54$this_file = 'link-manager.php';
    6 $parent_file = 'link-manager.php';
    7 
    85
    96wp_reset_vars(array('action', 'cat_id', 'linkurl', 'name', 'image',
  • trunk/wp-admin/link-import.php

    r4006 r4478  
    44
    55require_once('admin.php');
    6 $parent_file = 'link-manager.php';
    7 $title = __('Import Blogroll');
    86$this_file = 'link-import.php';
    97
  • trunk/wp-admin/link-manager.php

    r4258 r4478  
    77require_once ('admin.php');
    88
    9 $title = __('Manage Bookmarks');
    109$this_file = $parent_file = 'link-manager.php';
    1110wp_enqueue_script( 'listman' );
  • trunk/wp-admin/menu-header.php

    r4443 r4478  
    44$self = preg_replace('|^.*/plugins/|i', '', $self);
    55
    6 get_admin_page_parent();
     6foreach ( $submenu as $parent => $subpages ) {
     7    foreach ( $subpages as $page ) {
     8    // 0 menu title, 1 cap, 2 file or slug, 3 page title
     9        if ( $self == $page[2] )
     10            $parent_file = $parent;
     11    }
     12}
    713
    814foreach ($menu as $item) {
  • trunk/wp-admin/menu.php

    r4474 r4478  
    55// The minimum level the user needs to access the item: between 0 and 10
    66// The URL of the item's file
    7 $menu[0] = array(__('Dashboard'), 'read', 'index.php');
     7// Slug
     8$menu[0] = array(__('Dashboard'), 'read', 'index.php', 'home');
    89
     10// So when people switch between write and manage they go to the appropiate page/post mode they were on
    911if ( strstr($_SERVER['REQUEST_URI'], 'edit-pages.php') )
    10     $menu[5] = array(__('Write'), 'edit_pages', 'page-new.php');
     12    $menu[5] = array(__('Write'), 'edit_pages', 'page-new.php', 'write');
    1113else
    12     $menu[5] = array(__('Write'), 'edit_posts', 'post-new.php');
     14    $menu[5] = array(__('Write'), 'edit_posts', 'post-new.php', 'write');
     15
    1316if ( strstr($_SERVER['REQUEST_URI'], 'page-new.php') )
    14     $menu[10] = array(__('Manage'), 'edit_pages', 'edit-pages.php');
     17    $menu[10] = array(__('Manage'), 'edit_pages', 'edit-pages.php', 'manage');
    1518else
    16     $menu[10] = array(__('Manage'), 'edit_posts', 'edit.php');
     19    $menu[10] = array(__('Manage'), 'edit_posts', 'edit.php', 'manage');
    1720   
    18 $menu[15] = array(__('Comments'), 'edit_posts', 'edit-comments.php');
    19 $menu[20] = array(__('Blogroll'), 'manage_links', 'link-manager.php');
    20 $menu[25] = array(__('Presentation'), 'switch_themes', 'themes.php');
    21 $menu[30] = array(__('Plugins'), 'activate_plugins', 'plugins.php');
     21$menu[15] = array(__('Comments'), 'edit_posts', 'edit-comments.php', 'comments');
     22$menu[20] = array(__('Blogroll'), 'manage_links', 'link-manager.php', 'blogroll');
     23$menu[25] = array(__('Presentation'), 'switch_themes', 'themes.php', 'themes');
     24$menu[30] = array(__('Plugins'), 'activate_plugins', 'plugins.php', 'plugins');
     25
    2226if ( current_user_can('edit_users') )
    23     $menu[35] = array(__('Users'), 'edit_users', 'users.php');
     27    $menu[35] = array(__('Users'), 'edit_users', 'users.php', 'users');
    2428else
    25     $menu[35] = array(__('Profile'), 'read', 'profile.php');
    26 $menu[40] = array(__('Options'), 'manage_options', 'options-general.php');
     29    $menu[35] = array(__('Profile'), 'read', 'profile.php', 'profile');
     30
     31$menu[40] = array(__('Options'), 'manage_options', 'options-general.php', 'options');
    2732
    2833
     
    7075
    7176// Create list of page plugin hook names.
    72 foreach ($menu as $menu_page) {
     77foreach ( $menu as $menu_page )
    7378    $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
    74 }
    7579
    7680$_wp_submenu_nopriv = array();
     
    129133}
    130134
    131 unset($id);
     135unset( $id );
    132136
    133 uksort($menu, "strnatcasecmp"); // make it all pretty
     137uksort( $menu, 'strnatcasecmp' );
    134138
    135 if (! user_can_access_admin_page()) {
     139if ( !user_can_access_admin_page() )
    136140    wp_die( __('You do not have sufficient permissions to access this page.') );
    137 }
    138141
    139142?>
  • trunk/wp-admin/moderation.php

    r4474 r4478  
    22require_once('admin.php');
    33
    4 $title = __('Moderate comments');
    5 $parent_file = 'edit-comments.php';
    64wp_enqueue_script( 'admin-comments' );
    75
  • trunk/wp-admin/options-discussion.php

    r4337 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Discussion Options');
    5 $parent_file = 'options-general.php';
    6 
    73include('admin-header.php');
    84?>
  • trunk/wp-admin/options-general.php

    r4297 r4478  
    11<?php
    22require_once('./admin.php');
    3 
    4 $title = __('General Options');
    5 $parent_file = 'options-general.php';
    6 
    73include('./admin-header.php');
    84?>
  • trunk/wp-admin/options-misc.php

    r4196 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Miscellaneous Options');
    5 $parent_file = 'options-general.php';
    6 
    73include('admin-header.php');
    84
  • trunk/wp-admin/options-permalink.php

    r4197 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Permalink Options');
    5 $parent_file = 'options-general.php';
    6 
    73function add_js() {
    84?>
  • trunk/wp-admin/options-privacy.php

    r4424 r4478  
    11<?php
    22require_once('./admin.php');
    3 
    4 $title = __('Privacy Options');
    5 $parent_file = 'options-general.php';
    6 
    73include('./admin-header.php');
    84?>
  • trunk/wp-admin/options-reading.php

    r4457 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Reading Options');
    5 $parent_file = 'options-general.php';
    6 
    73include('admin-header.php');
    84?>
  • trunk/wp-admin/options-writing.php

    r4327 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Writing Options');
    5 $parent_file = 'options-general.php';
    6 
    73include('admin-header.php');
    84?>
  • trunk/wp-admin/options.php

    r4383 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Options');
    5 $this_file = 'options.php';
    6 $parent_file = 'options-general.php';
    73
    84wp_reset_vars(array('action'));
  • trunk/wp-admin/page-new.php

    r4338 r4478  
    11<?php
    22require_once('admin.php');
    3 $title = __('New Page');
    4 $parent_file = 'post-new.php';
    53$editing = true;
    64wp_enqueue_script('prototype');
  • trunk/wp-admin/plugin-editor.php

    r4202 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __("Edit Plugins");
    5 $parent_file = 'plugins.php';
    6 
    73wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
    84
  • trunk/wp-admin/plugins.php

    r4453 r4478  
    3030}
    3131
    32 $title = __('Manage Plugins');
    3332require_once('admin-header.php');
    3433
  • trunk/wp-admin/post-new.php

    r4429 r4478  
    11<?php
    22require_once('admin.php');
    3 $title = __('Create New Post');
    4 $parent_file = 'post-new.php';
    53$editing = true;
    64wp_enqueue_script('prototype');
  • trunk/wp-admin/profile.php

    r4447 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __('Profile');
    5 
    6 if ( current_user_can('edit_users') )
    7     $parent_file = 'users.php';
    8 else
    9     $parent_file = 'profile.php';
    103include_once('admin-header.php');
    114$profileuser = get_user_to_edit($user_ID);
  • trunk/wp-admin/templates.php

    r4415 r4478  
    11<?php
    22require_once('admin.php');
    3 $title = __('Template &amp; File Editing');
    4 $parent_file =  'edit.php';
    5 
    63wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
    74
  • trunk/wp-admin/theme-editor.php

    r4349 r4478  
    11<?php
    22require_once('admin.php');
    3 
    4 $title = __("Edit Themes");
    5 $parent_file = 'themes.php';
    6 
    73wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme'));
    84
  • trunk/wp-admin/themes.php

    r3928 r4478  
    1919}
    2020
    21 $title = __('Manage Themes');
    22 $parent_file = 'themes.php';
    2321require_once('admin-header.php');
    2422?>
  • trunk/wp-admin/user-edit.php

    r4447 r4478  
    22require_once('admin.php');
    33
    4 $title = __('Edit User');
    5 if ( current_user_can('edit_users') )
    6     $parent_file = 'users.php';
    7 else
    8     $parent_file = 'profile.php';
    94$submenu_file = 'users.php';
    105
  • trunk/wp-admin/users.php

    r4468 r4478  
    22require_once('admin.php');
    33require_once( ABSPATH . WPINC . '/registration.php');
    4 
    5 $title = __('Users');
    6 if ( current_user_can('edit_users') )
    7     $parent_file = 'users.php';
    8 else
    9     $parent_file = 'profile.php';
    104
    115$action = $_REQUEST['action'];
Note: See TracChangeset for help on using the changeset viewer.