Posted by Charles Clarkson under PHP, Programming, WordPress
No Comments
John Kolbert
wrote a function to to get a list (array) of users by their role name. For example, he shows how to get a list of editors. I would only change the function slightly to accommodate my own programming style (and because I can't leave well enough alone).
PHP:
function get_users_with_role ($role) {
// gets all users with specified role
$wp_user_search = new WP_User_Search( '', '', $role);
return $wp_user_search->get_results();
}
As John notes, remember this is for use in the admin panels.
Thanks, John.
Posted by Charles Clarkson under PHP, Programming
No Comments
I ran across this piece of code in a program I am updating. The original author is a great game designer, but only a fair programmer. He also seems to have very limited experience with SQL.
PHP:
if ( $grab == 'Ammo' ) {
$check =
mysql_query("SELECT * FROM BF WHERE owner= 'None' AND country='$fetch->location'");
if ( $num_rows != 0 ) {
if ( $fetch->location == $location ) {
mysql_query("UPDATE BF SET owner='$username', profit='0' WHERE country='$fetch->location' LIMIT 1");
$this->content .= "You got the Bullet Factory!";
}
}
}
When writing database applications, you need to be as good at writing queries as you are at writing code. Here's a rewrite:
(more...)