Global Data
8 min read
Global Data is a list of named, site-wide values. Each entry is called a variable: a label, a key, a type and a value. Define "Phone number" once and print it in the header, the footer and a page builder, then change it in one place.
Use Global Data for small, single values. For groups of related fields with their own layout (an address block, social links, a logo) use an options page with a field group instead.
Global Data is available on every plan.
Open the screen
Go to WPM Fields › Global Data. The subtitle reads "Site-wide values you can reuse in templates, field values and page builders." With no variables you see "No variables yet. Add a value such as a phone number or an address, then print it anywhere with {{ glb.key }}."
Only users who can manage_options (administrators) can open it and use its REST API.
Add a variable
- Click Add variable.
- Type a label, for example "Phone number". The key is built from it while the row is new (
phone_number). You can edit the key. - Choose a type (see below).
- Type the value.
- Click Save changes. You see "Global Data saved."
Each row has the label field, the key (shown in monospace), a type selector and four icon buttons:
Icon | Action |
|---|---|
Revert changes | Returns the row to its last saved state. Disabled when nothing changed. |
Edit value / Show value summary | Switches between a one-line summary and the full input. Rows with an empty value open the full input automatically. |
Advanced options | Opens the General, Validation and Display tabs. |
Remove variable (Discard new variable for an unsaved row) | Deletes the row when you save. |
Unsaved changes are protected: leaving the screen asks for confirmation.
Keys
- The key is what you use in code:
wpmcf_get_global( 'phone_number' ),{{ glb.phone_number }}. - It is cleaned to lowercase letters, numbers, hyphens and underscores (max 64 characters). Other characters, including spaces, are removed, not converted: a key typed as
Site Namebecomessitename. - Changing the key of a saved variable shows the warning "Changing this key may break references that use it elsewhere on the site."
- Every key must be unique. Errors: "Label is required.", "Key is required.",
Duplicate key "phone". The server also checks after cleaning, soPhoneandphonecollide: "Each variable needs its own key. Used more than once: phone". - "Fix the errors before saving." appears when rows have errors.
- A site can hold up to 500 variables; a label can be 200 characters.
All variables are saved together as one list. The REST endpoint PUT /wp-json/wpmcf/v1/global-data replaces the whole list, so a request must include every variable you want to keep.
Variable types
Type | Input | Output ( | Notes |
|---|---|---|---|
Text | single line | escaped text | Default. |
Text area | multi-line | escaped text, line breaks kept in the stored value | |
Number | number input | escaped text | |
Range | slider | escaped text | The slider uses the Min value, Max value and Step of the Validation tab (defaults 0, 100, 1). |
email input | escaped text | ||
URL | URL input | URL-escaped | |
Password | masked input | not printed | See below. |
Values are cleaned when saved: HTML tags are stripped and surrounding whitespace is trimmed. Password values are the exception, see below.
Password variables
Use Password for values that must never reach the page: API keys, tokens, secrets.
- The value is encrypted in the database (
sodiumsecretbox with a key derived from your site'sSECURE_AUTH_SALT) and shown as********in the screen and in REST responses. The real value never leaves the server. - To keep the stored value, leave the field showing
********and save. To replace it, type a new value. To clear it, empty the field. - In templates,
{{ glb.key }}is empty for passwords unless thewpmcf/global/the_passwordfilter returns true. wpmcf_the_global()and[wpmcf_global]print nothing for passwords unless thewpmcf/global/the_passwordfilter returns true.wpmcf_get_global()does return the real value, because PHP code is trusted. Never echo it into a page.- If you change your site's security salts, existing passwords cannot be decrypted and read back as empty; enter them again.
- Renaming the key of a password variable and saving in one step loses the stored password (the mask is matched by key). Re-enter it after a rename.
- Password values keep their characters exactly as typed (including
<and>); they are stored encrypted and never printed unless you allow it.
To allow output of passwords anyway, return true from the filter wpmcf/global/the_password. They then print HTML-escaped in every format, including auto, and {{ glb.key }} returns them too. Do this only in private, non-cached contexts.
Advanced options
Click Advanced options on a row. Three tabs appear.
General
Setting | Effect |
|---|---|
Placeholder | Hint shown inside the empty value input on this screen. |
Instructions | "(shown alongside this variable)" Help text for editors. |
Validation
Rules depend on the type:
Type | Rules |
|---|---|
Number, Range | Min value, Max value, Step (for example 0.5, 1, 10) |
Text, Text area, Password | Min length, Max length (characters) |
Email, URL | "No extra validation rules available for the email type." |
The rules are checked when you save. If a value breaks a rule the whole save fails with a message naming the variable, and nothing is stored (REST status 422):
- Text-like types:
"Label" is shorter or longer than allowed. - Number and Range:
"Label" must be a number.or"Label" is outside the allowed range. - Empty values and Password variables are not checked.
The Range type also uses Min value, Max value and Step to draw its slider.
Display
"These settings control how the value is rendered on the front-end via a template tag." A live preview shows the result.
Setting | Effect |
|---|---|
Wrapper CSS class | Added to the wrapper span, for example |
Wrapper HTML ID | Sets the span's |
Prefix | Text added before the value (for example "Tel:"). |
Suffix | Text added after the value (for example "USD"). |
Prefix and suffix are escaped and keep their leading and trailing spaces: a prefix of "Tel: " prints Tel: +90 555.
Display settings apply to wpmcf_the_global() and [wpmcf_global] with wrapping on. With wrap off, or in {{ glb.key }}, only the escaped value is output.
Print a variable
Template functions
// Echo, escaped, wrapped in <span class="wpmcf-global-value"> with the Display settings.
wpmcf_the_global( 'phone_number' );
// Echo only the escaped value.
wpmcf_the_global( 'phone_number', array( 'wrap' => false ) );
// Raw value for your own escaping.
$phone = wpmcf_get_global( 'phone_number' );
echo '<a href="tel:' . esc_attr( $phone ) . '">' . esc_html( $phone ) . '</a>';
// Does it have a value?
if ( wpmcf_has_global( 'promo_text' ) ) {
wpmcf_the_global( 'promo_text' );
}Function | Returns | Notes |
|---|---|---|
| raw value |
|
| echoes | Escaped. Prints nothing when the variable is missing or empty, unless you pass |
|
| True for any non-empty value. |
|
| Sets the value of an existing variable. False for an unknown key or an array. |
$args: format (auto, html, attr, url, js, post_html), wrap (false removes the span) and default. Formats:
Format | Escaping |
|---|---|
| By type: URL variables use |
|
|
|
|
|
|
|
|
|
|
wpmcf_update_global() fires wpmcf/global_data/saved, like saving on the screen, so cache plugins can purge.
Shortcode
[wpmcf_global key="phone_number"]
[wpmcf_global key="site_url" format="url" wrap="false"]Attributes: key (required), format (default auto), wrap (default true) and default. The shortcode prints through the same escaping as wpmcf_the_global().
default is used when the variable does not exist or its value is empty, in the shortcode, in wpmcf_the_global() and in wpmcf_get_global() (for an empty value). For example [wpmcf_global key="phone" default="Call us"] prints "Call us" while the phone variable is empty.
Variables
In field values, templates and page builders, {{ glb.key }} prints a global value:
Call us on {{ glb.phone_number }}.
Welcome to {{ glb.site_name | upper() }}
{{ glb.promo | default('No promotion today') }}An unknown key prints nothing. Values with {{ … }} inside are not expanded again in this namespace (to avoid loops). See Variables.
Hooks
Hook | Type | Purpose |
|---|---|---|
| filter | Change the value before output. Arguments: value, key, args. |
| filter | Change the escaped output. |
| filter | Change the final markup, wrapper included. |
| filter | Return |
| action | The list was saved (plain values). Use it to clear caches. |
Limits and notes
- All variables live in one settings row. Keep it for small values: if a value is long or structured, use a field group on an options page.
- Global Data is separate from field groups. It is not part of the JSON export of field groups, post types, taxonomies and options pages, so copy variables to a staging or production site manually (or with
wpmcf_update_global()after creating them). - On uninstall, data is only removed if you enabled that in WPM Fields › Settings.
Troubleshooting
Nothing prints. The key may be wrong (keys are lowercase with underscores), the value empty, or the variable a Password.
The key changed when I saved. Spaces and capital letters are removed or lowercased when saving.
Save fails with "Each variable needs its own key." Two rows end up with the same key after cleaning; rename one.
"Could not save Global Data. Try again." The request failed; check the REST API is reachable and your login has not expired. Reloading does not lose saved data.
"Global Data could not be loaded". "Reload the page to try again. Nothing was changed." Saving is disabled in that state so nothing is overwritten.
Still stuck? Contact support