A little while ago, I created a plugin called Suspend Transients. It is a helpful tool that allows developers to bypass
get_transient() calls on any page by clicking a button on the admin bar.
I felt that the name was not accurate so I have renamed it and it is now available for download on WordPress.org as Bypass Transients.
Development is happening on GitHub and pull requests are welcome along with any and all feedback in the comments below!
When unit testing your code, there are times when you need to test the same method or function with a variety of different parameters. For example, we have a function to check to see if a passed email is both valid and not already in the list of known emails: Continue reading “Better Unit Testing with DataProviders”
I have run into a bug a few times in the past little while that had me stumped. When creating meta boxes on the admin side of WordPress that contained custom loops, I couldn’t reset $post using wp_reset_postdata() – it just didn’t work.
Originally, I thought maybe I was doing it wrong because I was using get_posts, so I tried WP_Query with the same results. So, thinking I had a legitimate bug, I went to report it and found that there was already a ticket and a patch for it ( gotta love the WordPress community ). The patch is a nice, elegant fix that worked well when I tested it – but until it’s accepted into core it’s not really an option to use because hacking core is bad. So I rolled my own in the meantime. Continue reading “Resetting $post in WordPress admin”
Sometimes when we’re developing a plug-in, it’s easy to forget that we’re not building something that is meant to be standalone. What we’re building is going to exist as part of the WordPress ecosystem and as such it should respect it’s configuration. Simply put, if WordPress is in debug mode, than your plugin should be to. Continue reading “WordPress Plugins and debug mode”
Sometimes it is necessary to modify or remove the default WordPress post updated messages that are displayed when making changes to a Post in WordPress.
One example is when you are creating a custom post type that does not have a permalink. When you save a draft, publish or update a published post, you are presented with messaging that includes a link to the post – which in that case will take the user to a 404 page. Continue reading “Change the WordPress post updated messages”
When I was at WordCamp Ottawa this year, I was asked a question about how to create custom post types without generating permalinks. This is actually something I do a lot of as I am creating internal content types that are not meant to be viewed individually at their own url.
The snippet below will register the post type and you’ll notice that there is no Permalink line below the title. Continue reading “Custom post types with no permalinks”
Building custom widgets is fun, rebuilding them because we need to change the way it looks is not. With that in mind, lets build a skinnable WordPress widget that separates how it looks from what it does. For the purposes of this tutorial, I am assuming that you are comfortable creating a Widget and working with the API. Please refer to the Widget API as needed. Continue reading “Creating a skinnable WordPress widget”
If you ever have an automatic update fail sometimes your WordPress install can get stuck in maintenance mode. I just had this happen to me and was able to find a quick solution.
Log into your server via FTP and look for a .maintenance file, delete it and you should be up and running again.
I have been creating a code base for a Screen Manager system that I am using for an iOS app I am building in AS3. I wanted to create a dynamic way to reference and instantiate classes that represent each of the Screens in the app so I can reuse this for other applications in the future and to make it a lot less code intensive.
I setup a series of static variables that held string names to represent each of the Screens in the application. Then when I want to create the screen and add it to the stage I use the getDefinitionByName() method and pass the string name of the class. Continue reading “getDefinitionByName”
Garbage collection can be a big deal when writing complex programs in Actionscript. Not removing EventListeners is probably one of the biggest sources of AS holding onto memory it doesn’t need.
There is a very easy way to allow GC to handle your event listener clean-up for you when creating a new event listener – the useWeakReference argument.
Here is some standard code we’ve all done million times when creating a button:
var button:MovieClip = new MovieClip();
The two arguments are pretty straight forward the first is the event we’re listing for and the second is the function that is called once the event is fired, but there are actually 5 arguments that can be passed to addEventListener() here is the method definition:
<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/IEventDispatcher.html#addEventListener%28%29">addEventListener</a>(type:<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html">String</a>, listener:<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html">Function</a>, useCapture:<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Boolean.html">Boolean</a> = false, priority:<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/int.html">int</a> = 0, useWeakReference:<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Boolean.html">Boolean</a> = false):<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/specialTypes.html#void">void</a>
the 5th argument (useWeakReference) is false by default but by setting to true, this eventListener will be automatically removed and freed for Garbage Collection when required.
Here is the new eventListener code updated to make use of useWeakReference.