Changeset 4478

Show
Ignore:
Timestamp:
11/18/06 06:09:48 (2 years ago)
Author:
matt
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 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