I am happy to see that so many people have found this plugin useful. I’ve had many feature requests, a couple code contributions, and plenty of bug reports. I appreciate it all.
It’s been over a year since there was an update to the Media Categories plugin, so I’ve been hard at work this past week adding a ton of new features. I’ve taken to heart as many feature requests and bug reports as I could handle.
Heres a detailed list of what you can expect in this new and improved version of Media Categories:
Improved Category Metabox: Filter terms as you type
Back in WordPress 3.4 and earlier, there were no metaboxes for taxonomy on attachments, so I had to roll my own fake metaboxes (“metafauxes”, I’ve started calling them). With the big push in WordPress 3.5 to improve the media modal, the need for that metafaux on the main editor page went away – but with it went one of everyone’s favorite features of this plugin. The “Searchable Categories” field, the input box that let users filter the categories that were showing, making the metabox easier to use.
In Media Categories 1.6, I’ve created a new set of custom metaboxes that bring back this feature! You can now type the name of the term your interested in and the list of terms in the metabox will filter as you type.
Drop-downs Filters in the Media Library & Media Modal
One of the most frequent feature requests made for this plugin has been the ability to filter items in the Media Library by taxonomy, just like you can on the Posts admin list. We’ll I’ve done that, so now you’ll have a separate drop-down for each taxonomy assigned to work with Media Categories.
Somewhat less frequent of a feature request, but still a great idea, has been to have the same ability to filter by taxonomy, but from within the Media Modal. This would be useful for obvious reasons to anyone with a large collection of images – especially for folks who’s website might happen to focus around imagery.
Media Categories 1.6 will include both of these new drop-down filters.
Sortable Columns in Media Library
Simple enhancement, but a frequent request. Click the header of the taxonomy columns to sort them by taxonomy. Not much to say about it except that getting it to work alongside the drop-down filters was pretty challenging.
Improved Media Modal “Metafauxes”
As I mentioned above, a metafaux is what I call a fake metabox - just a simplified version of the metabox meant to be used in places where the WordPress metabox framework doesn’t normally work. When WordPress 3.5 was released, it introduced the Media Modal/Media Manager. As a matter of chance, a bug was introduced. There was no way to distinguish between the media editor in sidebar of the Media Modal, and the main media editor in the Media Library. So my metafauxes were showing up in the modal, but they weren’t working.
I reported the bug, and they got it patched up quickly, but instead of taking out the metafauxes, I made them work – in the modal. However, they were kinda buggy.
I’ve fixed them up now, they look a little nicer, and they work a lot better – and just as before, they collapse to save space on the small modal sidebar, and you can filter as you type!
Gallery Shortcode Compatibility
To be honest, I should have known better. It was back in Media Categories 1.2 that I added the ability to select a taxonomy when using the “gallery” shortcode. This was very cool, and I think it became another big draw for people to use the plugin.
There was a terrible secret here though (thunder!), to make this work, I had to override the default WordPress shortcode (shreak!). This was bound to cause problems, and it did. I’ve received multiple reports of other plugins also interacting with the “gallery” shortcode, and when those plugins are on at the same time as this one – they don’t get along.
I figure most people dont have the conflicts (i think?) – so this plugin by default continues to modify the default “gallery” shortcode for the sake of not breaking people’s websites who already use it this way. However, it also creates a secondary shortcode called [media_gallery]
To stop the conflicts with other plugins, paste two line snippet of PHP into function.php file. This sets a property in the Media Categories object to false which stops my plugin from messing with the default gallery.
See the documentation for exact details on how this will work. I know its annoying that it requires code – but just you wait. An options page is coming.
Bulk Editing – its the one feature request that I really wanted to get into this release, but it turned out to me more work than I had time for. I’ll try to make this feature a top priority on the next major release.
Options/Settings Page – I want to eventually eliminate the need for people to drop lines of code into functions.php to control how this plugin works. I want this settings page to simply let users pick from a list of all available taxonomies, and select which ones should be made to work with attachments.
Code Cleanup/Refactor - Given that the scope of this plugin has changed, I also want to reevaluate how it is written. It is currently a lot clunkier than I’d like it to be.
This plugin was originally meant to only be a tool for developers, to let them easily turn on metaboxes and associate taxonomies with attachments. It’s become more than that, and the users aren’t all developers anymore. That said, I’ll keep intact the control developers already have. I’ll probably even make it so the settings page can be completely disabled by defining some property in functions.php
Can’t wait? Wanna help?
If you’d like to beta test the plugin, please do so. Its available in the master branch of its GitHub repository here: Media Categories 1.6 Beta
If you have a bug to report, I always prefer that you do so on GitHub Issues, since its so much better than the WordPress.org forums.
In the course of development, there are times you want to look at or retrieve a file deleted sometime in the past – and you probably don’t know when it was deleted. I’ve written a simple git alias that makes it super easy.
So how does this work? If you don’t care, then just copy and paste the config line above – if you want to know what’s going on here, read on.
It uses some simple features of the “git log” and “git checkout” commands that everyone is already familiar with. Each can have a file path passed to them after a couple of dashes “–”. First, you need to find out when in the git history the file was removed, for that you can just use “git log” with a “–” and a path.
This works just like normal git-log, but narrows the log to show only commits that affect the given path – keep in mind that the path can be a specific file or an entire directory.
What if you want to actually retrieve that file? Well, you can do that with the “git checkout” command by doing basically the same thing. First copy the SHA1 hash of the last commit affecting the file you want to retrieve – this is important because you it will tell git-checkout where to look for the file.
The commit hash you copied from the “git log” output doesn’t actually contain the file, its just when the file was deleted because that commit is by definition the last commit to affect the file. To get the last state of the file before its removal you need to look to the commit immediately before it, thats what the “^” does, it looks one commit back.
So that a bunch of stuff to remember – although its fairly simple compared to some other more complex tasks in git – but I made the git alias to make it even easier. I think I originally came up with this alias an an answer on StackOverflow, but its been sitting around as a gist on my github account for a while. I’ll probably be sharing more stuff from gist in the future.
It happens all the time. You open a file in VIM, you make three and a quarter trillion changes, and then realize you needed sudo but didn’t use it when you opened the file. What do you do?
Well, if you might save the file under a new name, then quit, delete the original and rename the new file with the original name. It works, but its really annoying.
Luckily there is a cool trick in VIM that lets you save with sudo, even after having opened a file without it. Here it is.
:w !sudo tee %
Hit enter after typing that in, you will be prompted for a password if necessary, and then you will then get the following message.
Press ENTER or type command to continue
Go ahead and hit enter, and assuming you actually made some changes, you will then get the following message.
Press ENTER or type command to continue W12: Warning: File "sites-available/webgrind.conf" has changed and the buffer was changed in Vim as well See ":help W12" for more info. [O]K, (L)oad File:
This is just telling you there are two versions of the file, the old one and the new one and gives you an option to simply acknowledge, or to load the new version. You are typically going to want to enter “L”.
Thats it, your file should be saved now. Cool trick, saved me some frustration many time.
Note: I first heard of this trick at WordCamp, but I can’t remember who it was that mentioned it.
It’s day 3 of WordCamp Chicago 2013. On day 1, the Foundation Friday, my hobby of 3D Printing came up in conversation and someone suggested that I print a WordPress logo. On day 2 I brought two 3D Printed logos, printed with Cherry Laywoo-d3, a material used for 3D printing made from repurposed sawdust mixed with a plolymer (pro tip: saying polymer in an meaningful context make you sound smart!).
During the after party I was showing the logo’s off. Matt Boynes (@senyob) tweeted a picture. A few people retweeted it and asked if they could have one. Today I come with a total of 6 logos to give away to anyone who is interested (although 3 are already committed to specific individuals).
I wish I had thought of printing the logo sooner, I would have printed 30 of them and just handed them out. Maybe next year.
If you want one and live in the Chicago area, or even work in the loop – let me know and we can work something out.
Someone asked me today how to use WP_Query to get posts by a relative date. The codex provides an example on how to achieve this. Heres what is shown on the codex.
I feel that its sloppy and not very flexible. Having to add the filter and remove it each time you want to do this is ugly. I solved this some time ago and had to dig through some old code to find it.
Ultimately what I have done is the same solution, using the same filter, and utilizing strtotime() to get the relative date. However i’ve wrapped it into a simple “since” parameter that can be used on any query. Just a little nicer and simpler to use.
This technique can easily be adapted to other custom parameters which result in modifications to the where or join filters.
Tricks for interacting with a branch, without checking it out.
Browse a directory (like ls):
git show [ref]:[path]
> git show master:your/path/
See contents of a file (command as above):
git show [ref]:[filepath]
> git show master:your/path/file.php
Checkout a specific file or directory from a different branch:
git checkout [ref] -- [path]
> git checkout master -- your/path/file.php
Note: There are other ways to do similar tasks such as `git ls-tree` and they may have more options. However I find these to be more accessible and easy to remember.
I just ran into a little gotcha with regard how fetch handles tags. When it pulls down commits, you will usually see that it also pulls down tags. I was a little confused today when fetch was refusing to pull a tag that was clearly in the repository (“
git ls-remote --tags“) lets you see tags available on the remote).
I kept running the fetch command but the tag wouldn’t get pulled down. The reason has to do with the way fetch works, it only fetches tags that are direct references to a commit that is in a branch being fetched. To get all tags regardless of what commits they reference use the fetch in the following way.
From the git manual (“git help fetch”):
-t, –tags Most of the tags are fetched automatically as branch heads are downloaded, but tags that do not point at objects reachable from the branch heads that are being tracked will not be fetched by this mechanism. This flag lets all tags and their associated objects be downloaded. The default behavior for a remote may be specified with the remote.<name>.tagopt setting. See git-config(1).
This will effectively do the inverse of normal fetch. It will fetch all tags, and bring with is any necessary commits.
Hope this helps some poor confused folks out there a little bit of greif.