Hello,
I have created a custom global variable because I want to use it inside a calculated form field and the same time to display this variable in various places on my website.
For example, my variable is [cgv?variable-name] and I want to create a form where the user will input a number in a text field e.g. 200 and the calculated field will display this: [cgv?variable-name]*200
I am using Elementor if it helps.
Could you let me know which form plugin supports this? I don’t mind if it is free or not.
Thank you
]]>I have experienced the loss of variable settings previously reported in the earlier topic under the same title. It happened the day after I had made the settings (without my knowledge).
bitnami@bitnami-wordpress-ngnix-2:~$ ls -al /bitnami/wordpress/wp-content/custom-global-variables/
total 12
drwxrwxr-x 2 daemon daemon 4096 Oct 15 16:26 .
drwxrwxr-x 11 bitnami daemon 4096 Oct 7 08:24 ..
-rw-r--r-- 1 daemon daemon 0 Oct 8 16:25 6181d5aba697300d21994fd4c446d40e.json
-rw-r--r-- 1 daemon daemon 0 Oct 15 16:26 69299d011032f9c3aa6f9fb9c4864559.json
-rw-r--r-- 1 daemon daemon 398 Oct 7 08:49 d57fd4a6de20165f493fea8f1d78c7b6.json
My guess is maybe the Sucuri Security plugin cleared the file but there is nothing in the log to confirm that. My plugins are listed below:
Blocks Animation: CSS Animations for Gutenberg Blocks by ThemeIsle.
Burst Statistics - Privacy-Friendly Analytics for WordPress by Really Simple Plugins.
Complianz | GDPR/CCPA Cookie Consent by Really Simple Plugins.
Disable Comments by WPDeveloper.
Disable WP REST API by Jeff Starr.
Disable XML-RPC by Philip Erb.
Duplicate Page by mndpsingh287.
Easy FancyBox by RavanH.
FileBird Lite by Ninja Team.
Inactive Logout by Deepen Bajracharya.
Layout Grid by Automattic.
MetaSlider by MetaSlider.
MetaSlider Lightbox by MetaSlider.
Plugins List by David Artiss.
Sitemap Generator by Auctollo.
Sucuri Security - Auditing, Malware Scanner and Hardening by Sucuri Inc..
UpdraftPlus - Backup/Restore by UpdraftPlus.Com, DavidAnderson.
WP Mail SMTP by WP Mail SMTP.
WPS Hide Login by WPServeur, NicolasKulka, wpformation.
WPS Limit Login by WPServeur, NicolasKulka, wpformation.
WP Super Cache by Automattic.
Sadly that is “End Ex” for my use of this plugin. I am still amazed that something like this plugin’s function is not a standard part of WordPress, i.e. the ability to make use of parameterisation in pages.
An extra feature which would be extremely useful is to allow users with the Author role to change the values of variables. In this way the Editor would parameterise the relevant parts of the page, e.g. “admission price” on the Home page and the Author would be able to set/update the values of the parameters as required over time. This facility could be enabled/disabled via a setting accessible only to the Editor role.
]]>I would like to nest one variable inside another thus:
site_email [email protected]
site_email_link <a href="mailto:[cgv site_email]">[cgv site_email]</a>
Trying it out doesn’t seem to work: I get
<a href="mailto:[email protected]">[cgv site_email]</a>
Is there a way to do this in such a way that an admin is not retyping the site email?
]]>Hello,
I need to uptate the value of a cgv variable. Is it possible to do it in someway, php for exemple?
Best regards
Jacques
]]>Hi, I have set up my wordpress site to point to an external application where i handle content changes approval workflow, may I know what is the function/api that I can call that performs the save action, so that I can call it in my external workflow? Thank you.
]]>is there any way I can use the shortcode to output the raw value without the <code> element?
]]>It’s there a way to add variables to the page with Javascript support or at least display them hidden in HTML to get the value.
]]>Hi,
just started using the plugin but it seems to work very fine. Even inside an on-the-fly generated gravity flow pdf.
What I find kinda uncomfortable is that I have to “merge” the shortcode and pdf myself. Wouldn’t it be possible to have some sort of copy-buttons behind every variable declaration. One Button for the shortcode, one for the php code which sends an ready to use text to the clipboard?
You know what I mean?
]]>The Shortcode don’t work in header and footer elementor PRO Template.
any solution or alternative?
Hello everyone who uses this plugin,
I can’t seem to comment to the closed thread from @tfr79 and @aaronbiby so I’ve created this new one.
The multisite support is now ready for testing in this Bitbucket’s special branch.
https://bitbucket.org/ntosdev/custom-global-variables/commits/branch/multisite
I would appreciate if anybody contributes testing on this version and I will release a new version.
]]>Basically, we have an online magazine and the current issue is #220. Basically, I want articles with category of 220 to show up for the issue, along with the correct magazine cover and title and I’d love all this to come from variables (that probably will come from some custom fields on each issue’s main page).
But if we click on an archive page, ie. #214, then all the variables (cover image, title, issue number, etc) will switch and stay active/persist until the user goes back to the home page (restoring the latest issue details) or clicks on another archived issue.
I was doing this with cookies before but there are some strange issues with CloudFlare and on some browsers in Windows, cookie values aren’t printing (despite the fact that I can look in DevTools and see that the cookies DO exists).
But I have read that using variables directly works better than cookies and I’d like to try.
Thanks for reading!
]]>Hi, great plugin! Thank you.
I have LightSpeed Cache (LSCache) enabled for my website, and it looks like updates in Custom Global Variables does not trigger cache update in LSCache.
I had to manually trigger an unrelated change on a page for it to re-cache the proper updated global variable value. Is there a workaround for this? Thank you!
Hello there,
thanks for this plugin, it is a lifesaver.
Is there any chance to use shortcodes in the backend?
I’ve got a Forminator form in which I’d like to callback some variables, but it does not display the real value of the variable, just its name.
Waiting for some explanations that may help.
Thanks again.
Regards
Sadly it happened the 2nd time in the last 2 weeks that suddenly all my variables were gone. I had to type them in again.
Did that happen to anybody? Any ideas what could be the problem?
I’m happy to provide more information if needed.
Thanks!
I see where I can set the variable value when I create the variable. Is there a way to update or change the value by going to a certain page or reading another variables value. I have an input field in a form for a zip code and I want the global variable to get that value any time it’s changed. Is the global variable value only for a specific user?
]]>Hello everyone,
at first: thanks for this simple and yet very useful plugin. My question is: For your next release, could you maybe add the blog_id or something to the filename where the variables are stored? Then the plugin would be able to be used in multisite installations. Unfortunately there is no way to contribute code yet…
Best regards!
]]>Hello author of this plugin!
Thank you for building this simple but convenient plugin.
We love using this plugin but unfortunately it’s closed because of unresolved security issues.
I have a fixed code and I would like to push it to the repository to make this great plugin available for all.
Please let me know how I can help.
Thanks,
Akira
Hi,
Great plugin.
Is there a way to pass variables in?
ie. [cgv name variable]
Thanks.
Skye
Hi,
I’m not sure if this is being maintained anymore, but here are my answers to the two problems that I found with this plugin:
“0” value variables are deleted on on save:
in custom-global-variables.php on line 88;
change
if ( ! empty( $var[‘name’] ) && !empty( $var[‘val’] ) ) {
to
if ( ! empty( $var[‘name’] ) && !is_null( $var[‘val’] ) ) {
N.B. this change will preserve variables even is they have just a space (” “) for a value.
Long variable names display are truncated:
in style.css line 1 edit:
#custom-global-variables-table-definitions>tbody>tr>td textarea{border:1px solid #ddd;box-shadow:none;padding:0.75em;width:100%}
and delete “;width:100%”
Hope this helpa,
Mike
]]>I tried both formats but they don’t work in Widgets, fine in pages.
This what was displayed at runtime:
<?php echo $GLOBALS[‘cgv’][‘va_companyiris’] ?>
Cloud enabled Booking and Inspection system
Software As A Service (SAAS) Inspections
[cgv va_iris] is an Internet enabled Booking and Inspection system that captures Inspection results on an iPhone or iPad, with final reports published on the Web.
Configuration filename is built with AUTH_KEY value.
Since Securepress changes AUTH_KEY value every month, data is lost every month.
]]>Hi,
I wanted to have the functionality to use this plugin in my custom theme I was creating. Without making a complete installation step.
For that reason I installed this functionality:
https://tgmpluginactivation.com/
giving the user the suggestion to install:
Custom Global Variables
Because I didn’t want the user to manually add the different variables I made some changes to the class Custom_Global_Variables
Usually I try to use Github to push changes, but couldn’t find a GIT repository
The complete file:
<?php
/**
* Plugin Name: Custom Global Variables
* Plugin URI: https://www.konnectdigital.com.au
* Description: Easily create custom variables that can be accessed globally in WordPress and PHP. Retrieval of information is extremely fast, with no database calls.
* Version: 1.0.4
* Author: Abdullah Khalfan
* Author URI: https://www.konnectdigital.com.au
* License: GPL2
*/
define('CustomGlobalVariables', NULL);
class Custom_Global_Variables {
private $file_path = '';
// Constructor
function __construct($external_use = false) {
$this->file_path = WP_CONTENT_DIR . '/custom-global-variables/' . md5( AUTH_KEY ) . '.json';
/* Retrieve locally the current definitions. */
if ( file_exists( $this->file_path ) ) {
$vars = file_get_contents( $this->file_path );
if ( ! empty( $vars ) ) {
$GLOBALS['cgv'] = json_decode( $vars, true );
}
else {
$GLOBALS['cgv'] = array();
}
}
// Create the directory and file when it doesn't exist.
else {
if ( wp_mkdir_p( WP_CONTENT_DIR . '/custom-global-variables' ) ) {
file_put_contents( $this->file_path, '' );
}
$GLOBALS['cgv'] = array();
}
if(!$external_use) {
// Add the menu item.
add_action( 'admin_menu', array( &$this, 'add_menu' ) );
// Setup the shortcode.
add_shortcode( 'cgv', array( &$this, 'shortcode' ) );
}
}
// Adds the menu item under Settings
function add_menu() {
add_submenu_page(
'options-general.php',
'Custom Global Variables',
'Custom Global Variables',
'manage_options',
'custom-global-variables',
array( &$this, 'admin_page' )
);
}
function save_vars($new_vars = array(), $update = true) {
$old_vars = $GLOBALS['cgv'];
$vars = array();
// Create vars if not exist
if ( !$update ) {
foreach ( $new_vars as $name => $val ) {
if( isset( $old_vars[$name] ) ) {
$vars[$name] = $old_vars[$name];
} else {
$vars[$name] = $val;
}
}
} else {
$vars = $new_vars;
}
if ( file_put_contents( $this->file_path, json_encode( $vars ) ) !== false ) {
return true;
} else {
return false;
}
}
// Admin page
function admin_page() {
// Terminate if the user isn't allowed to access the page.
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( 'You do not have sufficient permissions.' );
}
wp_enqueue_style( 'custom-global-variables-style', plugins_url( 'style.css', __FILE__ ) );
wp_enqueue_script( 'custom-global-variables-script', plugins_url( 'script.js', __FILE__ ), array( 'jquery' ) );
$vars = $GLOBALS['cgv'];
// Save definitions upon submission.
if ( isset( $_POST['vars'] ) ) {
$vars_new = array();
foreach ( $_POST['vars'] as $var ) {
if ( ! empty( $var['name'] ) && !empty( $var['val'] ) ) {
$name = trim( strtolower( str_replace( ' ', '_', $var['name'] ) ) );
$vars_new[ $name ] = stripslashes( $var['val'] );
}
}
if ( $this->save_vars( $vars_new ) ) {
$vars = $vars_new;
echo '<div id="message" class="updated"><p>Your variables have successfully been saved.</p></div>';
}
else {
echo '<div id="message" class="error"><p>Your variables could not be saved. Check to see if the following folder exists and has sufficient write permissions:</p><p><strong>' . WP_CONTENT_DIR . '/custom-global-variables' . '</strong></p></div>';
}
}
?>
<div class="wrap">
<h2>Custom Global Variables</h2>
<div class="card">
<h3>Usage</h3>
<p>Display your variables using the shortcode syntax:</p>
<p><code>[cgv <em>variable-name</em>]</code></p>
<p>Or using the superglobal in PHP:</p>
<p><code><?php echo $GLOBALS['cgv']['<em>variable-name</em>'] ?></code></p>
</div>
<div class="card">
<h3>Define your variables</h3>
<form method="POST" action="">
<table id="custom-global-variables-table-definitions">
<tbody>
<?php
$i = 0;
if ( !empty( $vars ) ):
?>
<?php foreach ( $vars as $key => $val ): ?>
<tr>
<td><input autocomplete="off" name="vars[<?php echo $i ?>][name]" placeholder="name" type="text" value="<?php echo $key ?>"></td>
<td><span class="equals">=</span></td>
<td class="value-input">
<?php if ( $val == strip_tags( $val ) ): ?>
<input autocomplete="off" name="vars[<?php echo $i ?>][val]" placeholder="value" type="text" value="<?php echo htmlentities( $val ) ?>">
<?php else: ?>
<textarea name="vars[<?php echo $i ?>][val]" placeholder="value"><?php echo htmlentities( $val ) ?></textarea>
<?php endif ?>
</td>
<td class="options">
<img alt="delete" class="delete" src="<?php echo plugin_dir_url( __FILE__ ) ?>/delete.png">
</td>
</tr>
<?php $i++; endforeach; ?>
<?php endif ?>
<tr>
<td><input autocomplete="off" name="vars[<?php echo $i ?>][name]" placeholder="name" type="text"></td>
<td><span class="equals">=</span></td>
<td><input autocomplete="off" name="vars[<?php echo $i ?>][val]" placeholder="value" type="text"></td>
<td></td>
</tr>
</tbody>
</table>
<p><input type="submit" value="Save" class="button-primary"></p>
</form>
</div>
<div id="custom-global-variables-author-info">
<img alt="Konnect Digital" class="konnect" src="<?php echo plugin_dir_url( __FILE__ ) ?>/konnect.png"> This is a <a href="https://www.konnectdigital.com.au" target="_blank">Konnect Digital</a> plugin created by <em>Abdullah Khalfan</em>.
</div>
</div>
<?php
}
// Shortcode for displaying values
function shortcode( $params ) {
if ( ! empty( $GLOBALS['cgv'][ $params[0] ] ) ) {
return $GLOBALS['cgv'][ $params[0] ];
}
return false;
}
}
$custom_global_variables = new Custom_Global_Variables;
]]>
Inside <td class="value-input">
I’ve changed echo htmlentities( $val )
into echo htmlspecialchars($val, ENT_QUOTES, "UTF-8")
in both the input and textarea tags.
That seems to do the trick for me.
Works like a charm.
Great plugin, very clean. Is there a way to SET a variable that I have already defined programmatically? I need a variable that can change, depending on what page someone is viewing, so I need to be able to set it dynamically, not just once in the settings screen.
I have access to writing PHP code where I need to set the variable.
]]>It would be helpful to be able to keep empty variables like “” or especially 0. Sometimes you want to use a 0 and keep the variable available so that it can be adjusted in the future. I use global variables as coefficients in formulas that sometimes need to be adjusted by non-technical users, which this plugin is great for, but currently setting the value to an empty string or a 0 results in the variable being completely deleted.
]]>Helo Abdullah,
Can you tell me how to display variables in title of post or page?
I tried to put on post line, but does not work.
Thanks
]]>It would be fantastic if it was possible to include html in variable contents, like links
www.remarpro.com
It seems as if the plugin doesn’t accept uppercase characters in variables.
thatWouldBeUseful ??
Is there any way to the editor to modify the variables?
]]>