MWUG notes from Wednesday 21 January 2015

Some notes from last night’s MWUG meeting. Something I don’t get along to often enough, as Mike has mentioned on occasion. :)
Continue reading MWUG notes from Wednesday 21 January 2015

A quick and dirty logger for Gravity Forms

Today I noticed pieces of code to hook into a logger scattered throughout Gravity Forms, when I was trying to track down an issue. Here’s some quick and dirty code which hooks into the logging methods and writes to the PHP error log: Continue reading A quick and dirty logger for Gravity Forms

Using the OSX clipboard from the command line

The OSX pbcopy terminal command, which adds “stuff” to the clipboard to be pasted later, is really useful. For example, to download some webpage and put the HTML source in the clipboard:

curl -s http://example.com/ | pbcopy

Here’s a WordPress example; want to get some fresh API salts and keys for a wp-config.php? Try this:

curl -s https://api.wordpress.org/secret-key/1.1/salt/ | pbcopy

Want to be notified when the download and copy are complete? Add the say command, like this:

curl -s https://api.wordpress.org/secret-key/1.1/salt/ | pbcopy; say 'Ready to paste';

I use DTerm, which is an excellent little “popup terminal” which inherits the current context, and these commands are super handy here.

Spot the duplicates, using a Gravatar identicon hack

A project at work needed me to write a UI to find and delete duplicate attachments on a single post, from a client’s WordPress website. Creating a couple of queries where I could look over each post in turn, and check a hash for each file attached, then spot the duplicate hashes wasn’t too hard. Where I was struggling was making the rows with the duplicates stand out visually, file hashes, e.g. bc38d8d8993b5e9f4617576d2adeb875, are just not that easy to distinguish from other hashes, e.g. dbe0256fe35b88ebd4e4e433604b7487… see the problem?

What I wanted was some way of mapping a file hash to a colour, or something strongly visual. Which is when it occurred to me; Gravatar could do this! Continue reading Spot the duplicates, using a Gravatar identicon hack

Issues with embedding Vimeo videos with HTTPS URLs

As documented in WordPress trac ticket #20102, there is an issue with oEmbeds from some services which have started allowing/using https URLs rather than http URLs. The ticket documents an issue with the oEmbed functionality, oEmbed is the technology which allows you to paste a YouTube URL into your blog and have that converted to an embedded YouTube video when someone looks at the post. The problem is that the list of “safe services to embed from” does not account for URLs prefixed with the secure https protocol (as opposed to the non-secure http which is used for most web traffic which simply does not need the security).

The solution from ticket #20102 should be included in the next release of WordPress (hopefully), but in the meantime you can use this quick plugin I wrote which implements the new providers list, I’m waiting on WordPress.org plugin approval but in the meantime here’s the Github URL: HTTPS oEmbed Providers on Github

Download the files as a “zip”, unzip on your computer, then upload to your WordPress plugins directory; or upload the zip through the plugins page in your WordPress admin area.

The plugin is designed to warn you when the next version of WordPress is released, when hopefully you can deactivate and delete it.

The plugin only enables HTTPS for the providers which are already listed by WordPress, it does not add new providers (i.e. if you want an extra oEmbed provider then you need to look elsewhere, sorry).

(Post updated after publication to, hopefully, make the problem clearer.)

A quick custom plugin to import redirections into Safe Redirect Manager

At Code for the People we’ve just imported a load of blogposts from Drupal into WordPress. One of the differences is that Drupal encodes fancy characters, like typographically nice “quote marks”, into the URL whereas WordPress mostly drops them. We ended up with about 80 URLs which had changed and the need for a redirections plugin… enter Safe Redirect Manager by Taylor Lovett at 10up. I didn’t want to manually type in 80 redirects though, I wanted to get them in automatically and to this end I wrote a quick custom plugin which hooked into Safe Redirect Manager in a couple of places. Continue reading A quick custom plugin to import redirections into Safe Redirect Manager

Capabilities for custom post types in WordPress

I’ve just had to break out some serious Capabilities in WordPress today, and I’m documenting the process here in case it helps me in the future (or the past, though it seems unlikely) or anyone else.

The scenario i: I have a custom post type (Video) and I want to allow Editors and Admins to do whatever they want with it. Contributors and Authors (and below) shouldn’t be able to do anything with Video, and I want to create a separate Video Editor role which can do whatever it wants with Video posts. Video Editors should be able to upload images to use as Featured Image for a Video post, but not, as far as possible, mess with the other images in the site.

Continue reading Capabilities for custom post types in WordPress

Dragging, dropping and sorting, with jQuery UI

I spy a nice opportunity to document some jQuery UI functionality I’ve been playing with this afternoon, for a soon-to-be-revealed client project. The project needs photo galleries, and as these need to be tied into the other custom post types and taxonomies, I’m quickly rolling my own so I can completely control the experience for admins and viewers. This is not so much a tutorial, as a quick glance through the code from the back of a galloping horse.

Here’s a quick screen capture of the organiser in action.

Continue reading Dragging, dropping and sorting, with jQuery UI