Sivel.net  Throwing Hot Coals


Using MySQL Sockets in the WordPress wp-config.php

Recently I have been getting a lot of questions about how to use a MySQL socket in place of the DB_HOST constant for WordPress in the WordPress IRC channel.

Fortunately this is pretty easy, unfortunately if you are using the web based installer you cannot specify a socket in the “Database Host” field. However, you can do things the manual way and copy wp-config-sample.php to wp-config.php and go that route.

The first thing you need to do is determine the path to the MySQL socket. By inspecting my.cnf you would need to look for something that looks like:

socket      = /var/run/mysqld/mysqld.sock

If you don’t have access to look at my.cnf you can try to run the following MySQL query:

SHOW VARIABLES LIKE 'socket';

Now crack open your wp-config.php file and set DB_HOST to ‘:/path/to/mysql.sock’. Take careful note of the ‘:’ (colon) preceding the path. In my example the define for the DB_HOST looks like:

define('DB_HOST', ':/var/run/mysqld/mysqld.sock');
CoolStuff HowTo WordPress

Detect wp_head and wp_footer from a Plugin

Normally I start these posts with “Every so often someone asks a question in the WordPress IRC channel that sparks my interest”, however today, to my great surprise someone actually caught my attention on the wp-hackers mailing list.

For those of you who didn’t click through, the question was:

Couldn’t find this on forums or anywhere else.
What can I test to check if wp_footer was placed on the theme?

Before any replies came in I was already interested and when Peter Westwood replied with “The other way to do it is to do a http request based test which a special query arg on which you output a string on wp_footer.“, I was on the hook.

I spent a few minutes writing up a test plugin, to perform only this functionality and responded back to the list. It was pretty well accepted and I got a few comments from Ozh and Andrew Nacin on Twitter. One of the comments was actually an idea, to extend the checks to make sure that the calls to <?php wp_head(); ?> and

<?php wp_footer(); ?> were in the proper places in the code.

Before I get to the code, I want to spend a little time talking about the significance of wp_head() and wp_footer(). These 2 functions are the key to functionality of a lot of plugins and are the real work horses of themes. The wp_head and wp_footer functions allow WordPress core and plugins to hook into your theme either directly before the </head> or </body> html tags in your theme and perform actions. The majority of the time these actions are used to output style sheets or JavaScript, for use by plugins. WordPress core uses it to output a lot of good functionality such as relational links to your RSS and ATOM feeds into the head of the document. Joseph Scott wrote about this nearly a year ago. His post is fairly short but does a good job at explaining why it is important to include these functions.

Back to the original discussion, which was how do we detect whether or not wp_head and wp_footer are called in the active theme, and if called are they called, was it from the proper locations?

In my proof of concept plugin, we hook into admin_init, which will actually use wp_remote_get() to retrieve the frontend of our WordPress site. It calls the url with 2 query vars, that if present will cause the plugin to hook into wp_head and wp_footer and output some content that we will later look for. If the response was successful, as in returning a 200 response code, we will look at the content to see if <!--wp_head--> and

<!--wp_footer--> are present. If they are not we will see an admin notice telling us which problems were found. If those strings were found but they were not found directly before

</head> or </body> the notice will alert you of such.

Without further adieu:

Just in case you cannot see the code above, use this link: http://paste.sivel.net/24.

CoolStuff Fun HowTo PHP Plugins Questions Uncategorized WordPress

Shadowbox JS WordPress Plugin Updated to Version 3.0.3

This release of Shadowbox JS has been a long time coming and I am extremely happy to announce its release. With the upstream final release of shadowbox.js 3.0 came a lot of changes to the way this plugin had to work. The shadowbox.js file is now built on the fly and if possible cached to wp-content/uploads/shadowbox-js/. In the event that the file cannot be cached it will be built on the fly and delivered via admin-ajax.php with appropriate JS caching headers.

Other notable features:

  • More filters for overriding numerous URLs, including shadowbox.js and shadowbox.css
  • Require at least WordPress 2.8
  • Remove support for Ext and Dojo
  • Addition of new sub plugin titled “Shadowbox JS - Use Title from Image”, which will grab the title attribute from the child <img> tag if it exists and push it onto the parent <a> tag if a title does not exist.

If you run into any bugs please use the Shadowbox JS support forum for problems or questions with this plugin. Support questions will be ignored if left as comments on my site, through my contact form or by email. The only supported location for support questions is http://wordpress.org/tags/shadowbox-js.

News Plugins Release Shadowbox Support WordPress

Happy Pi Day

I’ve gotten into this bad habit of not writing about anything except WordPress on this site. It’s quite sad in a way that I have this great publishing platform and I only write about WordPress, and I do so very little.

Many years ago, I don’t remember how many exactly, I was challenged by my High School math teacher, that if I could memorize all the digits of pi that were on the poster (86) above the white board, that I would get an ‘A’ on the final without having to take it. I spent a week or two, I even wrote a program for the TI-83 to help me learn it. In the end I learned somewhere around 280 digits of pi and got that ‘A’.

From then until now, I have always held a special place in my heart for this number of numbers. I own the movie pi, I own the book a history of pi and I have spent the last eleven to twelve years incredibly interested in this number. Back in 1998 or so I actually ran a site dedicated to pi on geocities that is now long gone and forgotten.

So in keeping with the color scheme of that old site I used to run, which I now realize was very Matrix-esque, have a happy pi day!

pi

Happy pi day!

PS: From my days as an astrophysics major, I was taught that really only the first 42 digits of pi are useful for computational purposes. But what fun is that!? Keep learning and cranking out those digits of pi!

Astronomy Books Fun Holidays Movies Science Technology WordPress Pi

Busy Times Ahead

For those of you who follow me on twitter you likely already know that I am about to move half way across the country to take a new job. A few weeks ago I accepted a job with Rackspace and will be moving from Boonsboro, MD, population 3,399, to San Antonio, TX, population 1,351,305. I’m leaving for Texas on December 28 and have an expected move in date of December 31. Considering the time of year and the incredibly fast paced relocation I will be considerably less involved with WordPress and freenode until things start to settle down.

If you are in need of something just be patient, I’ll try to get to everything by sometime in mid March. I have some exciting updates to a few WordPress plugins that I hope to be able to get out in a reasonable amount time, so keep an eye out.

Boonsboro Locations Maryland News Plugins San Antonio Texas US WordPress

Finalizing Plugin Handoffs

A month or so ago I began giving away plugins to other authors. I just wanted to take a moment to announce which of the remaining pluigns are going where.

Two plugins will be transferring to Michael Torbert:

Another plugin will be going Andy Stratton:

As of now I am no longer supporting these plugins and requests for support should go to their new authors.

Thank you very much Andy and Michael for taking over development and supporting the community.

I am still finalizing details on the Ajaxify FAQ-Tastic plugin with another author. There should be an announcement for this plugin and author soon.

News Plugins WordPress

Slides From WordCamp NYC Are Up

For those of you who aren’t following me on Twitter, I have posted my slides from WordCamp NYC on SlideShare. Head on over and check them out! http://www.slideshare.net/mattmartz, and for those of you who want more variety in download formats, since the version on SlideShare is a PDF take a look at http://sivel.net/presentations/2009/wcnyc/.

Asides News WordCamp WordPress

Write Good Plug-ins and Get Involved in WordPress Development

This is cross posted from the WordCamp NYC site. This post will show up there at some point today.

Howdy, I’m Matt Martz. The majority of you probably know me as ‘sivel’ and I will be doing two separate talks at WordCamp NYC on Saturday, one in the Advanced Plug-in Dev Track and one in Beginners Plug-in Dev Track. The two topics I will be covering are Intermediate Plug-in Development Techniques and Writing Your First Core Patch. I will also be spending as much time as I can in the ‘Hacker Room’ helping people test and write patches for the upcoming WordPress 2.9. If time permits I’ll try do spend some time at the Genius Bar as well.

Giveaways

In both of my sessions I will be doing Twitter based giveaways. I will be giving away 5 items to randomly picked people who attend my sessions. If you want to find out what I am giving away you will have to come my sessions. Winners will be picked automatically at the end of each session using a WordPress plug-in I wrote specially for the occasion.

Intermediate Plug-in Development Techniques

We all strive to write good plug-ins. Plug-ins that not only function well, but plug-ins that have sexy code and use the WordPress APIs whenever possible for tight integration into core. I’ll go over some of the techniques which I believe will help take your plug-ins to that next level. Techniques will include:

  • Splitting Plug-ins into Multiple Files
  • Tips on When to Load
  • Using Classes
  • Localization
  • Ajax
  • If time permits I will try to touch base on a few other items

Writing Your First Core Patch

There are a lot of people out there that I see every day saying they found a bug or want a feature, but in the end never do anything about it. I’ll go over testing to verify the bug, getting assistance from the community, using the WordPress provided resources, explaining Trac and ticket fields and if time permits giving a few demos for actually creating that patch.

Code Plugins Talks Technology WordCamp WordPress

Shadowbox JS WordPress Plug-In Passes 100,000 Downloads

At 21:30UTC on November 5, 2009 my Shadowbox JS WordPress plug-in passed 100,000 downloads. Thank you to everyone who has downloaded and used this great plugi-n!

Asides News Plugins Release WordPress

Shadowbox JS WordPress Plugin Updated to Version 3.0.0.2

Another day and another update. The Shadowbox JS WordPress plugin has been updated to version 3.0.0.2. There are several new features such as generic image sizes and the option to not load sizzle.js. See the change log for a full list of changes.

Asides News Plugins Release WordPress