Page 2 of 2

Ajax Async Requests in WordPress

Ajax can be a confusing topic. I’ve spoken with developers who didn’t have a grasp of where Javascript ended and Ajax began. So before we dip into Ajax with WordPress, lets take a look at ajax itself.

Ajax is a request to your server

At it’s heart, Ajax is nothing more than an http request. It is a single request to a server which then sends back a response. This is very similar to typing in an address in your browser and hitting enter. It makes a request to a server which then sends back a response.

The magic of Ajax is that this is done without unloading the current page and loading a new one.
Continue reading

Add Plugin Hooks on plugins_loaded

The way the plugin system works in WordPress, plugin files are included in whatever order they happen to be in when the list of active plugins is saved to the database. There are plugins to control the load order of your plugins, but these are somewhat glorified hacks. There is certainly nothing wrong with them, but it is a bit bothersome to me that they are needed at all.

Whenever I write plugins, I make an effort put off the set up of everything, including adding any actions or filters, until the plugins_loaded hook. This action happens immediately proceeding including the plugin files themselves, which in my mind makes it the perfect time to run set up.

Nothing else has run yet, but everybody’s been invited to the party.

If all plugins are written this way and one plugin needs to make a modification before another plugin sets up, or needs to load earlier than other plugins, or needs to make sure it loads after other plugins, it’s a simple matter of setting the correct priority on the add_action() call that registers the setup function.

By this same token, I wait to do any theme setup until the after_setup_theme hook. All theme files have been included, nothing else has run. This is somewhat less important since you’re not often running more than one theme, but in a child theme situation I still find it can be worthwhile.

Understanding when your code runs in relation to when other code runs can be very valuable. This little change in mindset when authoring code can help you keep your code just a bit more organized. It may also help another developer down the line when they need to get a bit of code running before yours does.

Register Widgets with a Static Method

Registering widgets in WordPress is annoying.

All of the functionality is bundled up nicely in the WP_Widget class, but you can’t use an object method for the registration. Most PHP classes I see used in the WordPress space are pseudo namespace singletons. They have a helper for registering methods to hooks, and then the object is instantiated and the helper called. The various class methods are hooked in with something like add_action( 'init', array( $this, 'method_name' ) );. There is nothing inherently wrong with this approach. It provides a nice pseudo namespace for code that is PHP 5.2 compatible. When it comes to widget registration, though, that pattern just doesn’t work.
Continue reading

Learn to succeed

I spend my days at a desk behind a keyboard typing. While I can type relatively quickly, I can tell you I was not hired because I write 100 words a minute. I am a knowledge worker. I get paid because of what I know, not for a particular skill I possess.

The funny thing is, my current profession uses knowledge that I gained not from school, but from teaching things to myself through a combination of book reading, podcast listening, tutorials, conversations, and more. The list of sources is long, but I have savored ever scrap I could pick up. I have always enjoyed learning and tucking things away. The moment I stop learning is the moment I will start becoming worthless.

Knowledge is valuable. Without it, most of us would be out of a job.

Continue reading

Why I like distributed working

I currently work for 10up as a Senior Strategic Engineer. 10up is a distributed company, which means we have no central location or main office, it’s just a group of individuals in different cities around the world working out of home offices, co-working spaces, or sometimes even coffee shops. Don’t let that fool you into thinking we are a group of freelancers, though. We are a tight knit group doing some exciting work for equally exciting clients. A benefit of working to create amazing websites is that as long as there is some kind of wifi available, it’s possible to do some work.

Continue reading

NPM Inception: using NPM to update Node and NPM

I had some fun yesterday setting up a new Gruntfile. I copied over the package.json files and wanted to update the versions of the packages. Unfortunately I started hitting errors because my versions of NPM and Node were out of date. I knew I could just go download the node package, but I decided to find another way.

Continue reading

Installing Bluehost PHP extensions with a non-default PHP version

I’m still hosting this site on Bluehost currently. I have considered a number of times moving to something like Digital Ocean, but for now, I’m here. Until then, I’ve worked to make the best of what Bluehost has to offer. As part of that, I wanted to set up a legitimate object cache for the site. Furthermore, I much prefer something like batcache to act as a full page caching system which requires some kind of persistent caching.

Continue reading

Git Auto Deployment from GitHub or BitBucket

For some time I’ve been wanting to put together some easy to use git auto deployment scripts that I can use with GitHub and BitBucket. Despite hearing anecdotes to the contrary, I kept thinking to myself “It can’t be that hard to auto deploy a git repo from these services”.  Now I’ve finally spent some time digging into it and have come to the conclusion that while it is not super simple, it is not impossible either. And now with code in hand, it should be much easier to get going! Continue reading

© 2024 Luke on Everything

Theme by Anders NorénUp ↑