If you’re a WordPress developer who uses Advanced Custom Fields regularly, you may have taken advantage of the plugin’s built-in exporting utilities which allow you to easily export your fields as either XML or PHP. The latter method (PHP) can be highly useful for a number of purposes, such as packaging fields into commercial themes or creating a streamlined deployment process.
While ACF’s export utility is highly useful, however, I found myself becoming frustrated with needing to constantly copy + paste my exported PHP into a file every time I needed to update my code. I began to wonder: How might I be able to automate this process to make it virtually effortless?
Well, I’m happy to say that after poking around in ACF’s native exporting utility I was able to devise the exact solution I was looking for: a way to make Advanced Custom Fields automatically export all fields to a PHP file every time I save. Check out the details below!
Those who know me or have seen me speak at WordCamps know that Advanced Custom Fields is my all-time favorite WordPress plugin. The speed with which you can build robust custom options panels via this plugin is absolutely unrivaled, and as a result it’s become one of my primary tools for building highly customized & user-friendly interfaces within WordPress. I’ve used the plugin on countless projects and have had amazing success with it. Despite the plugin’s many advantages, however, there is a substantial risk associated with using it if you do not have exclusive control over the management of a website’s plugins.
A lot of sites I’ve developed have front-end components that rely heavily on data stored by Advanced Custom Fields. I do this to make customizing the website as easy as possible for end-users, but this comes with a rather large risk: If Advanced Custom Fields ever becomes deactivated or removed by accident, the website could start functioning improperly or (at worst) cease to work altogether. This is because WordPress can only understand how to use ACF’s functions if the plugin is enabled. Without ACF enabled, functions such as the_field() and get_field() have no meaning and will either cause the site to throw a Fatal Error, or display incomplete pages.
I realized that this was an unacceptable risk to be taking with my clients’ websites, but I still very much wanted the convenience of using this amazing plugin. Fortunately, the solution turns out to be rather simple: All we need to do is use “wrapper functions” to provide fallbacks for our data in the event that ACF is not active.
If you develop WordPress websites as frequently as I do, you probably find yourself using a core set of go-to plugins for almost every project you take on. And If any of these plugins are of “premium” or “commerical” variety, you’ll usually be faced with the repetitive task of entering in their license keys each and every time you want to set up a new website.
For a while I would circumvent this task by cloning a pre-existing database in order to carry over all settings (including my license keys), but I ultimately found that it required more effort than it’s worth. What I really wanted was a way to register all of my premium plugins and extensions automatically whenever I set up a new WordPress installation, without needing to use a pre-existing database.
I was pleased to find that this is in fact really easy to accomplish, simply by hard-coding license keys into the wp-config file of the WordPress installation. In this post I will outline exactly how you can take advantage of this technique on your own websites.
When working on large development projects, a great way to keep your code organized and manageable is by dividing it into separate files according to purpose or functionality. When you’re coding in PHP though, the downside to doing this is you often end up having to manually include() each new file you create, which can get a bit tedious if you’re managing enough files.
I decided to do some research and ultimately came across this handy PHP loop that will automatically include all files in a specific folder of your choosing. By eliminating the need to manually include() every new file, it has made my WordPress theme development noticeably more efficient.
While the WordPress back-end offers users a wide array of useful tools and features, I’ve found that most sites rarely end up requiring more than a fraction of them. As a result, I’ve gotten in the habit of removing unneeded items from the WordPress admin menu in order to de-clutter the interface and make it less overwhelming for my clients that are new to WordPress.
In this post I’ll walk through how you can simplify your admin menu by using two newer core WordPress functions, remove_menu_page and remove_submenu_page.