WordPress Plugin: Open Files In New Tab or Window

On a recent WordPress project I had a requirement that any files be opened in a new tab or window. Now this can be easily accomplished by the users when they create the post or page by linking to the file and marking the checkbox “Open Link In A New Window/Tab”. But we all know users can’t be trusted so in order to “double check” them I wrote a WordPress plugin that will hunt the page for anchor tags that link to something with a file extension, and simply add “target=’_blank'” to them.

Basically all the plugin does is enqueue a jQuery script that does the work. I got the idea to use the jQuery .filter() method from @nickf and the regular expression (because I suck at them) from @már-Örlygsson.

jQuery Open Files In New Tab Or Window

Links and References

Fork On Github

WordPress Plugin Page

jQuery Script

Stackoverflow: Javascript regex for matching/extracting file extension

Stackoverflow: jQuery Selector Regular Expressions

Easy KnockoutJS Pagination with Data Tables

Data Tables makes it super easy to add pagination, searching, and sorting to tabular data bound with KnockoutJS

TL;DR: DataTables provides simple pagination, sorting, and searching capabilties to tabular data bound with KnockoutJS – DEMO

So I was working on a WordPress plugin that pulled data from a SQL Server database via ASP.Net Web API and was using KnockoutJS to make the binding super easy. This worked great and was surprisingly simple to accomplish. However some of the data that was coming back was over 1,000 rows. This obviously didn’t look great to the users and was not really practical nor usable.

So I started down the path of handling paging at the API level and passing the page as a parameter… Yada Yada Yada you’ve been there.

But then I found DataTables … an excellent table plugin for jQuery.

DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, and will add advanced interaction controls to any HTML table.

Hey I need that!

DataTables provides extremely simple pagination, searching, sorting and more functionality to any HTML table. So in order to get this to work you can use the declarative foreach feature of Knockout to build out your table with the JSON data coming back from your API.

Enough of the boring stuff, here’s the code.. And here’s the demo in action using JSON data from the Donor’s Choose API.

Bootstrap Styles for Gravity Forms WordPress Plugin

TL;DR: WordPress Plugin to apply Bootstrap Styles to Gravity Forms

Everyone loves Gravity Forms and everyone loves Bootstrap. But they don’t look too good when combined. So I set out to find a nice way to combine the two. After some Googling around I came across Devin Walker’s gist to apply Bootstrap styles to Gravity Forms. After a few tweaks using that I decided to package it up in to a WordPress plugin.

bootstrap gravity form

To accomplish this I modified Devin’s CSS and then properly enqueue the style into the WordPress theme with the plugin. Pretty straightforward.

Usage

  1. Install and enable the plugin via Dashboard or download
  2. In Gravity Forms Settings, turn off “Output CSS”
  3. In Gravity Forms Settings, turn on “Output HTML5″
  4. Done! Have a beer.

Links

Download Plugin

Fork on Github

Have an issue? Report on Github

WordPress Mass Update Post, Page, or Custom Post Type Taxonomies

I’m working on a massive WordPress migration project and after we defined taxonomies they needed to be changed or updated. I tried doing this with SQL but that turned into an Inner Join nightmare due to how taxonomies are related to posts in the database. This script also comes in handy if you want to run mass updates to add all posts to a new category. When you are dealing with thousands of pages doing this manually in the WordPress admin becomes tedious.

So, you can drop these handy little scripts in your theme’s functions.php file for one time updates. These work for posts, pages, custom post types along with categories, tags, and custom taxonomies.

Apply Category To All Posts

Swap All Pages From One Custom Taxonomy Category To Another

This is one of the main reasons I wrote this script. We had hundreds of miss-classified pages in our custom taxonomy and I wanted to swap everything categorized as “News Releases” to another category called “Featured”. As mentioned above

Hopefully this saves you some time. Let me know in the comments if you have any questions.