PHP


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:
  1. function get_users_with_role ($role) {
  2.  
  3.     // gets all users with specified role
  4.     $wp_user_search = new WP_User_Search( '', '', $role);
  5.  
  6.     return $wp_user_search->get_results();
  7.  
  8. }

As John notes, remember this is for use in the admin panels. Thanks, John.
I have a old client who wants to add a link directory to his web pages. I have been suggesting WordPress as his basic web site CMS and I found the following WordPress Link Directory Which should make administering his web site a lot easier. The Plugin author seems very responsive to adding features and fixing bugs. I may be able to squeak by without having to hack my own version. I'll post a comment here with the url of the new directory and my success (or failure) with the Plugin.

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:
  1. if ( $grab == 'Ammo' ) {
  2.     $check = mysql_query("SELECT * FROM BF WHERE owner= 'None' AND country='$fetch->location'");
  3.     $num_rows = mysql_num_rows($check);
  4.  
  5.     if ( $num_rows != 0 ) {
  6.         if ( $fetch->location == $location ) {
  7.             mysql_query("UPDATE BF SET owner='$username', profit='0' WHERE country='$fetch->location' LIMIT 1");
  8.             $this->content .= "You got the Bullet Factory!";
  9.         }
  10.     }
  11. }

When writing database applications, you need to be as good at writing queries as you are at writing code. Here's a rewrite:

(more...)

I guess this is more a reminder to myself than useful information, but here goes.

Recently, I read up on PHP 5.x header() function. I ran across this tidbit of info.

HTTP/1.1 requires an absolute URI as argument to ยป Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.

I don't know about you, but I find RFCs incredibly boring, so I'm glad that some insomniac took the time to find this gem.

Following this standard eliminates another problem in a different language. In Perl, many people correctly use CGI.pm to perform redirects. The CGI manual gives the same advice. Use full URLs to redirect.

Here's a mini guide to redirection: (Basically, you just print the redirect out.)

(more...)