WordPress.org

Make WordPress Core

Ticket #11644: 11644.13.diff

File 11644.13.diff, 14.0 KB (added by nacin, 11 years ago)

Suggestions for some more ms-functions.php pruning, including removal of strtolower_usernames() and lowercase_username() which were both simply strtolower()

  • wp-admin/includes/file.php

     
    325325        // Compute the URL
    326326        $url = $uploads['url'] . "/$filename";
    327327
     328        if ( is_multisite() )
     329                delete_transient( 'dirsize_cache' );
     330
    328331        return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
    329332}
    330333
  • wp-includes/ms-default-filters.php

     
    44add_action ( 'init', 'maybe_add_existing_user_to_blog' );
    55add_action ( 'wpmu_new_user', 'newuser_notify_siteadmin' );
    66add_action ( 'wpmu_activate_user', 'add_new_user_to_blog', 10, 3 );
    7 add_action ( 'sanitize_user', 'strtolower_usernames', 10, 3 );
     7add_action ( 'sanitize_user', 'strtolower' );
    88
    99// Blogs
    1010add_filter ( 'wpmu_validate_blog_signup', 'signup_nonce_check' );
  • wp-includes/ms-functions.php

     
    1717
    1818function get_blogaddress_by_id( $blog_id ) {
    1919        $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    20         return clean_url("http://" . $bloginfo->domain . $bloginfo->path);
     20        return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
    2121}
    2222
    2323function get_blogaddress_by_name( $blogname ) {
     
    2626        if ( is_subdomain_install() ) {
    2727                if ( $blogname == 'main' )
    2828                        $blogname = 'www';
    29                 return clean_url( "http://" . $blogname . "." . $current_site->domain . $current_site->path );
     29                return esc_url( 'http://' . $blogname . '.' . $current_site->domain . $current_site->path );
    3030        } else {
    31                 return clean_url( "http://" . $current_site->domain . $current_site->path . $blogname . '/' );
     31                return esc_url( 'http://' . $current_site->domain . $current_site->path . $blogname . '/' );
    3232        }
    3333}
    3434
     
    3838        } else {
    3939                if ( $domain != $_SERVER['HTTP_HOST'] ) {
    4040                        $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
    41                         if ( $blogname != 'www.' ) {
    42                                 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path . $blogname . '/';
    43                         } else { // we're installing the main blog
    44                                 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
    45                         }
     41                        $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
     42                        // we're not installing the main blog
     43                        if ( $blogname != 'www.' )
     44                                $url .= $blogname . '/';
    4645                } else { // main blog
    4746                        $url = 'http://' . $domain . $path;
    4847                }
    4948        }
    50         return clean_url($url);
     49        return esc_url( $url );
    5150}
    5251
    5352function get_sitestats() {
     
    5554
    5655        $stats['blogs'] = get_blog_count();
    5756
    58         $count_ts = get_site_option( "get_user_count_ts" );
     57        $count_ts = get_site_option( 'user_count_ts' );
    5958        if ( time() - $count_ts > 3600 ) {
    60                 $count = $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->users}" );
    61                 update_site_option( "user_count", $count );
    62                 update_site_option( "user_count_ts", time() );
     59                $count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->users" );
     60                update_site_option( 'user_count', $count );
     61                update_site_option( 'user_count_ts', time() );
    6362        } else {
    64                 $count = get_site_option( "user_count" );
     63                $count = get_site_option( 'user_count' );
    6564        }
    6665        $stats['users'] = $count;
    6766        return $stats;
     
    7069function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
    7170        global $wpdb;
    7271
    73         if ( $sitedomain == '' )
     72        if ( ! $sitedomain )
    7473                $site_id = $wpdb->siteid;
    7574        else
    76                 $site_id = $wpdb->get_var( $wpdb->prepare("SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
     75                $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
    7776
    78         if ( $site_id != false )
    79                 return $wpdb->get_results( $wpdb->prepare("SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id), ARRAY_A );
     77        if ( $site_id )
     78                return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A );
    8079
    8180        return false;
    8281}
     
    119118        $details = wp_cache_get( $blog_id . $all, 'blog-details' );
    120119
    121120        if ( $details ) {
    122                 if ( !is_object($details) && $details == -1 )
    123                         return false;
    124                 elseif ( !is_object($details) ) // Clear old pre-serialized objects. Cache clients do better with that.
    125                         wp_cache_delete( $blog_id . $all, 'blog-details' );
    126                 else
    127                         return $details;
     121                if ( ! is_object( $details ) ) {
     122                        if ( $details == -1 )
     123                                return false;
     124                        else
     125                                // Clear old pre-serialized objects. Cache clients do better with that.
     126                                wp_cache_delete( $blog_id . $all, 'blog-details' );
     127                }
     128                return $details;
    128129        }
    129130
    130         $details = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id) );
    131         if ( !$details ) {
     131        $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
     132        if ( ! $details ) {
    132133                wp_cache_set( $blog_id . $all, -1, 'blog-details' );
    133134                return false;
    134135        }
    135136
    136         if ( !$get_all ) {
     137        if ( ! $get_all ) {
    137138                wp_cache_set( $blog_id . $all, $details, 'blog-details' );
    138139                return $details;
    139140        }
    140141
    141         $wpdb->suppress_errors();
    142         switch_to_blog( $blog_id );
    143         $details->blogname              = get_option( 'blogname' );
    144         $details->siteurl               = get_option( 'siteurl' );
    145         $details->post_count    = get_option( 'post_count' );
    146         restore_current_blog();
    147         $wpdb->suppress_errors( false );
     142        $details->blogname              = get_blog_option( $blog_id, 'blogname' );
     143        $details->siteurl               = get_blog_option( $blog_id, 'siteurl' );
     144        $details->post_count    = get_blog_option( $blog_id, 'post_count' );
    148145
    149         $details = apply_filters('blog_details', $details);
     146        $details = apply_filters( 'blog_details', $details );
    150147
    151148        wp_cache_set( $blog_id . $all, $details, 'blog-details' );
    152149
     
    629626                if ( is_array( $most_active ) ) {
    630627                        reset( $most_active );
    631628                        foreach ( (array) $most_active as $key => $details ) {
    632                                 $url = clean_url("http://" . $details['domain'] . $details['path']);
     629                                $url = esc_url("http://" . $details['domain'] . $details['path']);
    633630                                echo "<li>" . $details['postcount'] . " <a href='$url'>$url</a></li>";
    634631                        }
    635632                }
     
    11511148        else
    11521149                $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key";
    11531150
    1154         $activate_url = clean_url($activate_url);
     1151        $activate_url = esc_url($activate_url);
    11551152        $admin_email = get_site_option( "admin_email" );
    11561153        if ( $admin_email == '' )
    11571154                $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
    11581155        $from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
    11591156        $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    1160         $message = sprintf( apply_filters( 'wpmu_signup_blog_notification_email', __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your blog here:\n\n%s" ) ), $activate_url, clean_url( "http://{$domain}{$path}" ), $key );
     1157        $message = sprintf( apply_filters( 'wpmu_signup_blog_notification_email', __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your blog here:\n\n%s" ) ), $activate_url, esc_url( "http://{$domain}{$path}" ), $key );
    11611158        // TODO: Don't hard code activation link.
    1162         $subject = sprintf( apply_filters( 'wpmu_signup_blog_notification_subject', __( '[%1s] Activate %2s' ) ), $from_name, clean_url( 'http://' . $domain . $path ) );
     1159        $subject = sprintf( apply_filters( 'wpmu_signup_blog_notification_subject', __( '[%1s] Activate %2s' ) ), $from_name, esc_url( 'http://' . $domain . $path ) );
    11631160        wp_mail($user_email, $subject, $message, $message_headers);
    11641161        return true;
    11651162}
     
    13261323        if ( is_email($email) == false )
    13271324                return false;
    13281325
    1329         $options_site_url = clean_url("http://{$current_site->domain}{$current_site->path}wp-admin/ms-options.php");
     1326        $options_site_url = esc_url("http://{$current_site->domain}{$current_site->path}wp-admin/ms-options.php");
    13301327
    13311328        switch_to_blog( $blog_id );
    13321329        $blogname = get_option( 'blogname' );
     
    13571354
    13581355        $user = new WP_User($user_id);
    13591356
    1360         $options_site_url = clean_url("http://{$current_site->domain}{$current_site->path}wp-admin/ms-options.php");
     1357        $options_site_url = esc_url("http://{$current_site->domain}{$current_site->path}wp-admin/ms-options.php");
    13611358        $msg = sprintf(__("New User: %1s
    13621359Remote IP: %2s
    13631360
     
    15941591        return $dirsize[ $directory ][ 'size' ];
    15951592}
    15961593
    1597 function clear_dirsize_cache( $file = true ) {
    1598         delete_transient( 'dirsize_cache' );
    1599         return $file;
    1600 }
    1601 add_filter( 'wp_handle_upload', 'clear_dirsize_cache' );
    1602 add_action( 'delete_attachment', 'clear_dirsize_cache' );
    1603 
    16041594function recurse_dirsize( $directory ) {
    16051595        $size = 0;
    16061596
     
    18351825        update_blog_status( $wpdb->blogid, 'public', (int) $value );
    18361826}
    18371827add_action('update_option_blog_public', 'update_blog_public', 10, 2);
    1838 
    1839 function strtolower_usernames( $username, $raw, $strict ) {
    1840         return strtolower( $username );
    1841 }
    1842 
     1828       
    18431829/* Redirect all hits to "dashboard" blog to wp-admin/ Dashboard. */
    18441830function redirect_mu_dashboard() {
    18451831        global $current_site, $current_blog;
     
    18541840add_action( 'template_redirect', 'redirect_mu_dashboard' );
    18551841
    18561842function get_dashboard_blog() {
    1857         global $current_site;
     1843        if ( $blog = get_site_option( 'dashboard_blog' ) )
     1844                return get_blog_details( $blog );
    18581845
    1859         if ( get_site_option( 'dashboard_blog' ) == false )
    1860                 return get_blog_details( $current_site->blog_id );
    1861         else
    1862                 return get_blog_details( get_site_option( 'dashboard_blog' ) );
     1846        return get_blog_details( $GLOBALS['current_site']->blog_id );
    18631847}
    18641848
    18651849function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
     
    18781862        return false;
    18791863}
    18801864
    1881 function retrieve_password_sitename( $title ) {
    1882         global $current_site;
    1883         return sprintf( __( '[%s] Password Reset' ), $current_site->site_name );
    1884 }
    1885 add_filter( 'retrieve_password_title', 'retrieve_password_sitename' );
    1886 
    1887 function reset_password_sitename( $title ) {
    1888         global $current_site;
    1889         return sprintf( __( '[%s] Your new password' ), $current_site->site_name );
    1890 }
    1891 add_filter( 'password_reset_title', 'reset_password_sitename' );
    1892 
    1893 function lowercase_username( $username, $raw_username, $strict ) {
    1894         return strtolower( $username );
    1895 }
    1896 add_filter( 'sanitize_user', 'lowercase_username', 10, 3 );
    1897 
    18981865function users_can_register_signup_filter() {
    18991866        $registration = get_site_option('registration');
    19001867        if ( $registration == 'all' || $registration == 'user' )
    19011868                return true;
    1902         else
    1903                 return false;
     1869
     1870        return false;
    19041871}
    19051872add_filter('option_users_can_register', 'users_can_register_signup_filter');
    19061873
     
    19491916 *
    19501917 * @since 2.8.5
    19511918 **/
    1952 function filter_SSL( $url) {
     1919function filter_SSL( $url ) {
    19531920        if ( !is_string( $url ) )
    19541921                return get_bloginfo( 'url' ); //return home blog url with proper scheme
    19551922
  • wp-includes/post.php

     
    31773177        $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
    31783178        $file = get_attached_file( $post_id );
    31793179
     3180        if ( is_multisite() )
     3181                delete_transient( 'dirsize_cache' );
     3182
    31803183        do_action('delete_attachment', $post_id);
    31813184
    31823185        wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
  • wp-login.php

     
    195195        else
    196196                $message .= 'http://' . trailingslashit( $current_site->domain . $current_site->path ) . "wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login) . "\r\n";
    197197
    198         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    199         // we want to reverse this for the plain text arena of emails.
    200         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     198        if ( is_multisite() )
     199                $blogname = $GLOBALS['current_site']->site_name;
     200        else
     201                // The blogname option is escaped with esc_html on the way into the database in sanitize_option
     202                // we want to reverse this for the plain text arena of emails.
     203                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    201204
    202         $title = sprintf(__('[%s] Password Reset'), $blogname);
     205        $title = sprintf( __('[%s] Password Reset'), $blogname );
    203206
    204207        $title = apply_filters('retrieve_password_title', $title);
    205208        $message = apply_filters('retrieve_password_message', $message, $key);
     
    244247        $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
    245248        $message .= site_url('wp-login.php', 'login') . "\r\n";
    246249
    247         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    248         // we want to reverse this for the plain text arena of emails.
    249         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     250        if ( is_multisite() )
     251                $blogname = $GLOBALS['current_site']->site_name;
     252        else
     253                // The blogname option is escaped with esc_html on the way into the database in sanitize_option
     254                // we want to reverse this for the plain text arena of emails.
     255                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    250256
    251         $title = sprintf(__('[%s] Your new password'), $blogname);
     257        $title = sprintf( __('[%s] Your new password'), $blogname );
    252258
    253259        $title = apply_filters('password_reset_title', $title);
    254260        $message = apply_filters('password_reset_message', $message, $new_pass);