Snippets

Remove all meta boxes from WordPress post edit form

When you create a custom post type in WordPress, you can ask register_post_type to generate a default UI for managing your post type in the admin. When you edit your post type, WordPress generates the familiar post editor, just for your post type. You can change it through a variety of hooks, e.g. if you want to add some new meta boxes. But what if you don't want any meta boxes, not even the standard ones?

WordPress admin_init hook and the elusive typenow

In my quest to bring an object oriented separation of concerns to my WordPress plugins, I tend to separate the administration of each custom post type into its own class. I do this by looking at the global variable $typenow after the admin_init action is fired. But $typenow isn't always set after admin_init, so I have to improvise a little.

Using jQuery’s ajaxSend event to change an AJAX request

Customisation of web software sometimes requires that you get it to pass around some additional information whenever it makes a page request. Often, putting that information into a cookie isn't appropriate, so you try to squeeze it into the page query parameters, or form post data through hidden fields. But what if the software makes AJAX requests from jQuery? Luckily, jQuery can help you intercept AJAX requests so that you can customise them too.

WordPress is_ssl() doesn’t work behind some load balancers

WordPress has a function is_ssl() that it uses to check whether a page is loaded with the HTTPS protocol, so that it can use the same protocol to load scripts, stylesheets, and other assets. It relies on the web server giving it a couple of clues, but when your website is hosted behind a load balancer, those clues aren't always available. In particular, websites hosted by Network Solutions get no clues at all when pages are loaded over HTTPS.

Stop Events Manager from cropping thumbnails

Events Manager gives you a special placeholder that you can put into its templates, for inserting the event's "featured image" into lists and single event pages. If you want to insert a thumbnail, it uses the timthumb script to create one on the fly -- but it crops that thumbnail. Here's how to use the WordPress uncropped thumbnail (or any registered image size).

Events Manager locations map with directions

Events Manager is my events and bookings plugin of choice for WordPress, because it is very flexible, easy to integrate into a theme, and has hooks galore for customising to suit almost any requirement. Its location map doesn't offer a way to provide directions, however. So, here's how to replace the Events Manager locations map with WP Flexible Map and get a directions link on location pages.

Classic ASP, MySQL and UTF-8

Countless references on the web will tell you that you can access Unicode data in MySQL by setting the connection character set to utf8. Mostly, they tell you to execute the statement "set names 'utf8'" as the first statement in your connection. But when you are accessing MySQL from Classic ASP using the MySQL ODBC driver, you get an error: "SET NAMES not allowed by driver". Here's how you actually do it in Classic ASP.

Repair WordPress image meta

There are times when things just go wrong. I had one of those times the other day. The pressure was on to deliver a project, and there were bits of PHP and CSS and JavaScript flying everywhere here at WebAware Central. And so it happened: I wiped the image attachment meta data in the WordPress database.

Get custom fields for WordPress post

WordPress lets you store custom fields on your posts (and pages, and custom post types that allow it). However, it gives them to you in a rather inconvenient manner, with your values mixed in with its own special fields and any plugin's special fields, and with values in an array. Here's how to easily deal with that.