Arms crossed picture of James Auble
ACF and wpengine logos with a hidden symbol icon

Hide ACF Custom Fields On WPEngine Production Environment

PublishedDec 30th, 2022

On my list of todos for my current Wordpress project was to hide the Advanced Custom Fields menu item on WPEngine's production environment. I havn't yet had a problem with clients messing with the field groups, but I imagine it's just a matter of time until it happens. I didn't however, want to hide them while on the Development or Staging environments as I see myself needing to get in there from time to time and add inputs.

After reaching out to WPEngine through the support chat, I was surprised to find out there is no global variable for the environment and also no function that will return the environment either.


The WPEngine chat assistant was kind enough though to tip me off to using the PWP_NAME constant that stays within the environment when environments are copied over each other.

PWP_NAME will be equal to the subdomain of any environment, so it might be helpful if you have a convention for naming your subdomains like mysitedev, mysitestg, and mysite (or mysiteprod).

Given a site with these subdomains, I could then hide my ACF Custom Fields admin page with the following:

if (PWP_NAME === 'mysite') {
  add_filter( 'acf/settings/show_admin', '__return_false' );

If you want to see where PWP_NAME is defined, check out wp-config.php in your Wordpress root directory.

My PHP intellisense complained because it has no idea of this foreign constant, so I just defined it as NULL if it wasn't defined by my environment.

if (!defined('PWP_NAME')) {
  define('PWP_NAME', null);

Hope that helped.

Code on web assassins!

Need a web developer?

Contact Me
Back to Blog
Scrolldown Icon