How to Check Whether a PHP Constant Is Defined (Without Breaking Production)

Illustrated infographic summarizing: How to Check Whether a PHP Constant Is Defined (Without Breaking Production)

By Greg Nowak. Updated 19 November 2026.

A WordPress plugin update is unavailable in production but works on staging. The theme file editor has disappeared. Before changing permissions or disabling plugins, check whether a PHP constant controls the behaviour.

The technical check is small. The useful outcome is understanding whether you have found a configuration mistake or an intentional deployment safeguard. For business owners and agency teams, that distinction determines who needs to act and whether anything should change.

The quick answer: use defined() before reading a constant

Pass the constant’s name as a quoted string:

if (defined('MY_FLAG')) {
    $value = constant('MY_FLAG');
}

PHP’s defined() function checks whether the name exists. It does not tell you whether its value is true. A constant defined as false still exists.

When the name is stored in a variable, constant($name) retrieves its value. Keep that call inside the existence check: since PHP 8.0, constant() throws an Error for an undefined name.

For a known Boolean flag, this checks whether its value evaluates as true:

if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
    // The flag is active.
}

The second condition runs only when the first succeeds. If the setting expects a Boolean, inspect unexpected strings or numbers rather than relying on truthiness alone.

Inspect only the settings connected to the problem

For missing WordPress file editors or update controls, start with these two names. Have the maintainer run this in a protected diagnostic context after WordPress has loaded:

<?php

$names = ['DISALLOW_FILE_EDIT', 'DISALLOW_FILE_MODS'];

foreach ($names as $name) {
    if (!defined($name)) {
        echo $name . ': undefined' . PHP_EOL;
        continue;
    }

    echo $name . ': ' . var_export(constant($name), true) . PHP_EOL;
}

This reads the settings without changing them. var_export() makes Boolean values, strings and numbers distinguishable; a plain echo can make false look blank. Do not paste the snippet into a public template or leave an accessible diagnostic PHP file on the server.

Finding Meaning Next step
Undefined This runtime has no constant with that name. Check application defaults and whether the expected configuration loaded.
Boolean false The constant exists with a false value. Investigate permissions or other controls if the action remains unavailable.
Boolean true The restriction is explicitly enabled. Confirm its purpose and owner before proposing a change.
A string or number The value needs interpretation. Check the consuming code and configuration format.
Record the actual state before deciding what to change.

What the WordPress flags actually control

DISALLOW_FILE_EDIT disables the built-in plugin and theme file editors. It does not disable ordinary page or post editing.

DISALLOW_FILE_MODS blocks plugin and theme installation and updates through WordPress administration, and also disables those file editors. The WordPress configuration handbook documents this broader restriction.

That can be a deliberate arrangement: an agency may deploy code through a repository while keeping dashboard editing unavailable. Before removing a restriction, establish how updates are supposed to reach production and who handles urgent fixes.

These constants are useful evidence, but they do not fully explain every unavailable action. User capabilities, Multisite rules and plugin controls may also matter. An undefined or false flag is a reason to continue investigating.

Compare staging and production in the right context

A standalone PHP script does not automatically load WordPress. Likewise, a command-line process may use different configuration or environment variables from a web request. Record how the check ran, the PHP version, the site path and when in the application bootstrap it ran.

Run the same narrow check in each environment. If the affected behaviour occurs in a web request, confirm any command-line finding in an equivalent protected web context before drawing conclusions.

When values differ, trace the definition through wp-config.php, included configuration files, deployment templates and host-managed bootstrap code. The runtime result tells you what exists at that point; it does not identify the source file or explain the decision behind it.

If you do not yet know the name, get_defined_constants(true) provides a grouped snapshot. The expression get_defined_constants(true)['user'] ?? [] retrieves the user category when present. Review it privately: configuration constants can contain credentials, and a complete dump rarely belongs in a support ticket.

Avoid the common implementation traps

For a namespaced constant, include the namespace in the string. For a class constant, include the class and :::

defined('App\Config\FEATURE_ENABLED');

if (defined('App\Config::TIMEOUT')) {
    $timeout = constant('App\Config::TIMEOUT');
}

String names do not inherit the current namespace or use aliases. Reflection is another option for inspecting a class: (new ReflectionClass(App\Config::class))->hasConstant('TIMEOUT'), assuming that class is available.

If you are writing fallback configuration, guard the definition:

if (!defined('MY_FLAG')) {
    define('MY_FLAG', false);
}

define() creates the constant at runtime. This guard supplies a default when absent; it does not override an existing value. Fix a conflicting setting at its source instead of adding another definition later.

For variables, use the appropriate variable check: isset($var) means set and not null. It is not a substitute for checking constants.

Leave the next maintainer a clear decision

Finish the investigation with a short record: the affected action and user role, each setting’s actual state, where it originates, and who owns the policy. If a change is needed, test it on staging, deploy through the normal process, and verify the intended action with the affected role. Remove temporary diagnostics afterwards.

If configuration differences keep delaying releases or complicating agency handovers, Greg can help trace the setup, clarify ownership and document a practical delivery process. Bring the symptom and the environment details; those provide a useful starting point.

Related on GrN.dk

Need help with this kind of work?

Talk to Greg about your delivery setup Get in touch with Greg.

Sources

Latest articles

See how SharePoint access changes reach internal AI search, and test how long revoked content can still appear in results, generated answers, and citations.

At month-end, reconcile Shopify Payments against your bank statement and e-conomic. Use the payout ID to trace fees, refunds, and payouts that reach your bank the following month.

Trace an intermittent NGINX 502 through Cloudflare, upstream attempts, and application logs so you can see where the request failed and who should pick it up.

Find the apps, scripts and printers that still send mail through Microsoft 365 with a mailbox password, then test a replacement before the December 2026 change.

Find subscriptions and insurance expenses in e-conomic that should be spread over several months. See how AI reads the supporting documents and how your finance lead approves the proposed allocations.

Before relying on an AI project briefing, check which files it covered. A practical workflow for tracking documents, recording gaps and verifying key claims.

Check whether your contact form rejects missing or invalid Turnstile tokens, handles failed checks for genuine users and delivers accepted enquiries to your team.

Compare Bing citations, identifiable AI visits and verified enquiries to see which pages deserve attention before you increase your AI search marketing budget.

Teamtailor is phasing out Riminder on 21 November 2026. Check your parser settings, contact fields and integrations, and make sure you have a process for deleting applicant data.

WordPress jobs running late? Learn how to separate scheduling problems, task errors and a growing backlog, then choose the right scheduler or runner.