patternphpMinor
User Registration compress to use less querry, CPU posible
Viewed 0 times
posibleregistrationusercompresslesscpuquerryuse
Problem
I want to find out if there are any improvements I can make to this code. How can I make it better, faster and use less queries? Or is it fine the way I wrote it?
Bine ai revenit !
Utilizatori|Profil|" title="Logout">Logout
user_email, 40 );
}
?>
/wp-login.php" method="post">
Recuperare parolaInregistrare Retine parola?
" type="hidden">
Solution
Ok, a few things of note. Not really related to perfomance, but readability. To be fair though these are just details for better readability, your code is not so bad.
This code is not expensive process wise, I was curious as to where
On line 12-14, I would put that php code up at top, all in a single php block.
This would separate the php from the html and make for better readability.
Also, same thing for the php block on line 21. You call once again
I would take this block to the top, and change the
By initialising the variable (best practice), in your html "template code" below you can get away with just:
This habit leaves minimal
I assume indentation was lost when you pasted, so I will not patronize you on this.
Hope this helps, happy coding.
This code is not expensive process wise, I was curious as to where
$User_id comes from, because that is where the query you are worried about comes into play, but I trust your tables are properly indexed and output data is properly escaped.On line 12-14, I would put that php code up at top, all in a single php block.
This would separate the php from the html and make for better readability.
Also, same thing for the php block on line 21. You call once again
$current_user = wp_get_current_user(); , but you already have $current_user from line 15. I would take this block to the top, and change the
echo get_avatar() call to :$avatar = "";
if ( ($current_user instanceof WP_User) ) {
$avatar = get_avatar( $current_user->user_email, 40 );
}By initialising the variable (best practice), in your html "template code" below you can get away with just:
if ($avatar) { print $avatar; }This habit leaves minimal
php in the html and thus separates the logic from presentation.I assume indentation was lost when you pasted, so I will not patronize you on this.
Hope this helps, happy coding.
Code Snippets
$avatar = "";
if ( ($current_user instanceof WP_User) ) {
$avatar = get_avatar( $current_user->user_email, 40 );
}if ($avatar) { print $avatar; }Context
StackExchange Code Review Q#23220, answer score: 2
Revisions (0)
No revisions yet.