Categories
Programming

WP Admin Notes – Quick Bit of Code

I just added a feature to one of my sites that allows me to write a “note to the admin” (me) that doesn’t show up on the site. Here’s a look at one of the widgets in my admin area:

Wp trr notes

I really don’t want a title for that widget, but I also don’t want to have to open every text widget to remember what it is (many of my text widgets are without titles). By creating that shortcode I can surround any bits of text that is a note to myself, but it won’t appear on the site.

Creating a shortcode is really easy — and this one was especially easy because nothing is really happening. WP passes me the text that’s surrounded by the shortcode and I don’t do anything with it — just pass WP back an empty string.

I put this code inside the functions.php of my current theme:

function trr_note( $atts, $content = null ) {
	return '';
}
add_shortcode( 'trr_note', 'trr_note' );

Because of the way shortcodes work I can also call it like this:

[trr_note foo="This is my note for my eyes only!"]

The variable named foo can be named anything — since I’m doing nothing with that it doesn’t matter what it’s called.

The only other thing I had to do was tell WP to process shortcodes inside widget titles and text — apparently that’s not standard (which seems weird to me). I added these lines of code to the functions.php file:

add_filter('widget_text', 'do_shortcode');
add_filter('widget_title', 'do_shortcode');

It’s not rocket science, but it makes my admin duties easier since I can tell at a glance what specific widgets are for. I can also use it to “comment out” text on pages that I want to save for later.

Categories
Content Creation Programming

WP Plugin for WLM – Sell Bundles

I created my first WordPress plugin last night. It allows me to sell “bundles” of courses on my MasteringCoronaSDK.com site. WishList Member is an awesome way to handle my membership stuff, but doesn’t have any way to let you sell a bundle of courses at once. So I changed that.

Using their API I dusted off my PHP skillz and created a plugin that allows me to create bundles — I can specify as few or as many courses as I want and when someone buys it, they are added as members to those specific courses.

Besides bundles, it also allows me to add on a course as a bonus. The old, “Buy X now and I’ll also throw in Y, for free!” As far as the plugin is concerned, that’s just another type of bundle.

Selling Bundles in WLM

That link will take you to a 4-minute video that shows what it’s all about. It also allows you to grab the code to make it all happen. It’s free. It’s also *not* the plugin version, but I do tell you how to incorporate it into your site. (Warning, it’s a solution for people who are more technically-oriented.)