Show all my active WordPress plugins


Recently, I needed to get a list of every plugin that I’ve activated on all of my WordPress local-hosted blogs.
So, instead of going to every blog’s dashboard and noting down the list of every active plugin, I decided to write a quick (and dirty, i.e. not optimized) script.

// initialize variables [you have to change them to their proper values]
$dbhost = "localhost";
$dbuser = "dbuser";
$dbpass = "dbpassword";

// connect to MySQL and get all database names
$db = mysql_connect( $dbhost, $dbuser, $dbpass)
      or die( "MySQL connection problem: " . mysql_error());

mysql_set_charset( "utf8");
mysql_select_db( "information_schema", $db) or die( mysql_error());
$u0 = mysql_query( $sql, $db) or die( mysql_error());
$alldb = array();
while ($u1 = mysql_fetch_row( $u0)) { $alldb[] = $u1[ 0]; }

// select each database found and check for active plugins
foreach( $alldb as $adb) {
    $conn = mysql_select_db( $adb, $db);

    // get *_options table name
    $sql = "SHOW TABLES FROM $adb LIKE '%_options'";
    $u0 = mysql_query( $sql, $db); // or continue;
    while ($u1 = mysql_fetch_row( $u0)) {
        if ($opt = $u1[0]) {
            // get active plugins list
            $sql = "SELECT * FROM $opt WHERE option_name='active_plugins'";
            $u00 = mysql_query( $sql, $db);
            if ($u01 = mysql_fetch_array( $u00)) {
                $apj = $u01[ 'option_value'];
                if ($apj) {
                    $ap = unserialize( $apj);
                    foreach( $ap as $apv)
                        echo "Database: $adb >>> $apvn";

mysql_close( $db);

The output of this script is a list of all active plugins, one for each line, so it can be used in a shell script, for example one can find out how many of them are active:

php show_all_active_plugins.php | wc -l

or find out which blogs are using a certain plugin:

php show_all_active_plugins.php | grep akismet

Disclaimer: as usual, this script works for my setup and, for this reason, I'm sharing it here for everyone interested. I hope it will work for anyone else who tries it, but I cannot guarantee it for every possible situation.

Visit The Light of the LAMP blog for more…

How to share an article from Google Reader to Google+

Just a quick tip for every Google Reader user who needs to share an interesting article with one or more of her Google+ Circles.

Given that we have the Google+ share box on the top-right corner of GReader, the simplest way I’ve found is:

  1. grab the URL of the article, by right-clicking on its title and select “Copy link location”
  2. click at the “Share” box (at the top-right corner of the window)
  3. click at the chain icon (“Add link”) and paste the copied URL there; press the “Add” button
  4. select the people or circles you want to share it with
  5. if you want, you can comment on the text-box above the link
  6. click at the “Share” button

Visit The Light of the LAMP blog for more…

CRON error: grandchild failed with exit status 1 [Solution]

Just after I upgraded my Ubuntu to 10.10 version, I noticed some cron-related error messages in my /var/log/syslog file, like these:

Jul  5 13:40:01 agriope2 CRON[971]: (CRON) error (grandchild #974 failed with exit status 1)
Jul  5 13:50:01 agriope2 CRON[7775]: (CRON) error (grandchild #7778 failed with exit status 1)
Jul  5 14:00:01 agriope2 CRON[14520]: (CRON) error (grandchild #14526 failed with exit status 1)
Jul  5 14:00:01 agriope2 CRON[14521]: (CRON) error (grandchild #14531 failed with exit status 1)

At first, I thought they were generated by one of my scripts, which runs via cron every 10 minutes and I wondered what happened during upgrade that caused its exit status to turn to 1 instead of 0. Unfortunately, I didn’t had the time to delve deeper back then and I ignored it, since everything seemed to work as expected.

Until today, when (after one more successful system upgrade in the meantime) I decided to examine it further.
Given that nothing has changed into my script, I thought that it would be a good idea to search into /etc/cron* directories and there I found that there was the script /etc/cron.d/update-motd, which was scheduled to run every 10 minutes and tried to run /usr/sbin/update-motd. The problem is that /usr/sbin/update-motd was not present any more at its whereabouts, probably because “the functionality formerly provided by update-motd package is now integrated into pam_motd, in libpam-modules” (as the description of update-motd package says).

So, I moved /etc/cron.d/update-motd to another location, just in case I will need it again some time in the future.

Update [2011/12/25]:
In case you are running fetchmail from cron, you ‘ll have messages like the above whenever you have no new mail. For this situation, the solution is already in the man page of fetchmail:

If you do not want “no mail” to be an error condition (for instance, for cron jobs), use a POSIX-compliant shell and add

              || [ $? -eq 1 ]
to  the  end  of  the  fetchmail command line, note that this leaves 0 untouched, maps 1 to 0, and maps all other codes to 1. See also item #C8 in the FAQ.

Visit The Light of the LAMP blog for more…

Look is like a restricted grep

The look command is for looking up if a word exists in /usr/share/dict/words file, at least for most users. But, as the man page defines:

look — display lines beginning with a given string

which means that, for example, this command:

look what file

is equivalent to this command (with the exception that look ignores all whitespace characters at start):

grep ‘^what’ file

With this in mind, we can search easily for comment lines in all javascript files:

look ‘//’ *.js

or in .bashrc

look ‘#’ ~/.bashrc

For more, there is always grep, of course.

Visit The Light of the LAMP blog for more…

PHP: print a calendar fast

Say you need to fill a file or a sheet of paper (if you print the output) with a range of consecutive dates (or dates with equal space between them). Then, the following PHP one-liner might be handy some day:

for ($i=1; $i<=365; $i++) echo date( “Y-m-d”, mktime( 0, 0, 0, 1, $i)). “\n”;

The above snippet prints each day of current year on its own line. If you want one day per week, then you can change accordingly the values of for-loop variable, for example:

for ($i=4; $i<=365; $i+=7) […]

 Or, for next year’s calendar:

for ($i=1; $i<=365; $i++) echo date( “Y-m-d”, mktime( 0, 0, 0, 1, $i, 1+date(“Y”))). “\n”;

Don’t forget to change 365 with 366 for a leap year.

Visit The Light of the LAMP blog for more…

Google secure search with Firefox

Google has announced recently the option to search the web via an encrypted, secure channel. For Firefox, this can be accomplished by making some changes, like the following:

  • in a new tab, open “about:config” and search for “” (search box is located at the top of the tab area). You ‘ll find “keyword.URL” setting and you can change its value by double-clicking on it. Just add “s” after “http”.
  • open bookmarks by pressing Ctrl+Shift+B and search for “ q=” (search box is located at the upper right corner of the window). At first, you can eliminate all duplicates (as I did), then change all “http” occurrences to “https”

For Google Toolbar users, I believe there will be an update very soon.

Visit The Light of the LAMP blog for more…

Google Wave as a chat web application

I admit that I’m not using Google Wave as much as I can and the main reason for this is the lack of coworkers/colleagues/friends who are actively using it. The tool must have a purpose, right?

So, yesterday, I’ve come with an idea to create a purpose for me and the members of one of my sites. Since Google allows me to make a wave public and embed it in a web page, I can’t see no reason not to create a public wave and use it as a web application for chat!

The benefits for this decision are more than the disadvantages. Actually, I can see only two of the latter: the small number of people who are using it and the fact that it is still in beta version and one can become a member only by invitation by another member [19 May 2010 update: Google announced today that access to Google Wave is free to everyone, given that she has a Google account]. On the other hand, the usage of a public wave as a chat application has the following advantages (at least, for me):

  • Easy setup: Just copy-paste the code from the Google Web Elements page and start using it. Also, there is no need for local storage or a dedicated database.
  • Instant notifications: The members can see the replies of the other members, as they are writing them or even replay the discussion step by step. There are also email notifications for new replies, so (a) there is no need to continuously check the web page and (b) you can react immediately if you detect any abuse.
  • Indented replies: The members can choose to reply to a discussion or start their own.
  • Identified members: There are no anonymous replies (possible spam), albeit the public nature of the wave.

There may be more, we ‘re still evaluating this solution and maybe there is something I didn’t reckon when I decided to follow this route. I know that there are other alternatives, but you can’t beat the simpleness of this one.

Visit The Light of the LAMP blog for more…

send mail to correct local host

After upgrading my previous server with a new one, I run a lot of migration scripts and update procedures to make sure that everything transferred OK and worked as expected. However, a little thing kept bugging me until today.

Usually, when you want to send an email message to a local user, you either send it to user@localhost or just to user and the mail service makes sure that the local hostname is added after the ‘@’ (if there is nothing there of course). But the problem for me was that messages to local users relayed through my external mailgate after the upgrade.

The /etc/hosts and the configuration files of postfix were already filled with the correct hostnames and I could not find anything until I tried to search all the files in /etc hierarchy for the old hostname.

To my surprise, I found that the old hostname was still in /etc/mailname which, according to its man page, is a plain ASCII configuration file, which on a Debian system contains the visible mail name of the system.

I don’t know if the upgrade kept it intact or it was the restoration of /etc data files that caused this discrepancy. The good thing is that I found it easily by searching with grep.

Visit The Light of the LAMP blog for more…

Change photo extensions by content

Recently I had an interesting problem.  I had a lot of files in a directory, all photos, with their filenames messed up, especially their extensions.  So, in order to clear them and keep only the good ones, I had first to rename them in a more consistent manner (the JPEG photos ending with .jpeg, the PNGs with .png and so on).

I guess there is probably a plethora of appropriate tools, but I had no time to search in the chaotic internet, so I wrote a small PHP script (with a little help from the shell: command ‘file‘) and run it from the command line.

The script just parses the output of the file command and renames each file accordingly.

I’m putting this here, just in case it will be useful to someone else also:


$res = array();
exec( "file *", $res);

foreach( $res as $f) {
list( $fn, $ft) = split( ':', $f);
if (strpos( $ft, "JPEG") !== false) {
rename( $fn, $fn .".jpeg");
} else if (strpos( $ft, "PNG") !== false) {
rename( $fn, $fn .".png");
} else
echo "cannot rename $fnn";

I’m actually testing only for JPEG & PNG files since I know that I have only these two types.
Don’t forget to make this file executable if you want to run it from the command line.

Visit The Light of the LAMP blog for more…

Focus-stealing applications

I don’t like focus-stealing applications (and I bet that I’m not the only one)! They are like kids who are struggling for your attention while you ‘re working with something else, constantly interrupting your thoughts and work flow.

Is it so difficult for the developers to take this thing into consideration?
Come on people, don’t you get annoyed when you are developing _and_ testing these applications?

An example:
I started using FriendFeed’s desktop application, which notifies me when something occurs in my friends streams. It’s a well designed application, taking very little area in my desktop, except when there are new bubble-notifications. Then, whatever I’m doing I have to stop, because little bubbles start popping up while, at the same time, becoming the top-level window (thus stealing my keystrokes)! Usually, if I’m in the middle of something important I end up unloading this little ghost!

I strongly believe that tray-located applications must be as transparent as they can be. They are there to work silently and (probably) notify the user, but without interrupting the work she’s doing, otherwise they are not useful but distracting.

Visit The Light of the LAMP blog for more…