One of the most useful things you can do in terms of performance is to cache the page you’re currently serving so that no code gets executed again and again when it isn’t needed. I’ve provided a sample below of how you can set-up quick and dirty page caching by including template files in your code.
Below is a piece of code showing how to transform an Object into a Multidimensional Array, there are quite a few functions in PHP that return stdClass objects such as some MySQL, JSON or XML functions. If it is a one dimensional array, you’ll probably typecast it (array)$data; to get the result you want – But if the Object has multiple dimensions to it and you typecast it you’ll get a mixture of Array with elements that contain Objects.
Below is an example class of a basic permission framework with permissions worked out by using bitwise operations. This provides basic functions such as hasAccess() can() and permNeeded()
I won’t be going into detail regarding binary math and why it works as it does, as there are many other sites out there explaining this in great detail. This is just an example code post.
One of the most useful things you may need when iterating through an array is to know whether or not there is another element after the current and in some cases you’ll want to know what the next element is. It’s actually not that hard to do, thanks to the PHP CachingIterator. I have provided a sample snippet below showing what can be done with it.
I’ve need this a few times, where I have to take input of a CD-KEY in a specific format and it needs to be checked to see if it’s in valid or not before proceeding. Normally – I would just write a small regular expression, but when using multiple formats and the length of the key needs to be configurable I wrote the following function.
Straight in from the WordPress.org website…
“WordPress 3.3 is ready for beta testers.
As always, this is software still in development and we don’t recommend that you run it on a production site — set up a test site just to play with the new version. If you break it (find a bug), please report it, and if you’re a developer, try to help us fix it.
The Restler packer is a RESTful API server framework that is written in PHP that aids your mobile / web / desktop applications. A framework, but with a difference – Restler is all here to bend and mend to your needs. While designing your application, RESTful server makes use of the Web’s well known architecture to your benefit, you will just need to simply declare the function as protected and add an authentication class.
Ever since I started using WordPress I’ve been learning some quick-neat tricks to get the functionality I want. Some useful WordPress ‘template hacks’ are below that I have used in the past, ranging from custom fields to printing posts from a certain category. If you have any requests just leave them in the comments.