You should set as below.
define(‘WPFC_CACHE_QUERYSTRING’, true);
the problem is not how I set it, the problem is that your plugin tries to set it again, whilst ignoring if/that it’s present already.
You should always check with defined() before using define(). Thanks
-
This reply was modified 1 year, 5 months ago by
lilmofo.
This is not a bug. The value is set as true when the following conditions are true.
public function remove_url_paramters(){
$action = false;
//to remove query strings for cache if Google Click Identifier are set
if(preg_match("/gclid\=/i", $this->cacheFilePath)){
$action = true;
}
//to remove query strings for cache if facebook parameters are set
if(preg_match("/fbclid\=/i", $this->cacheFilePath)){
$action = true;
}
//to remove query strings for cache if google analytics parameters are set
if(preg_match("/utm_(source|medium|campaign|content|term)/i", $this->cacheFilePath)){
$action = true;
}
if($action){
if(strlen($_SERVER["REQUEST_URI"]) > 1){ // for the sub-pages
$this->cacheFilePath = preg_replace("/\/*\?.+/", "", $this->cacheFilePath);
$this->cacheFilePath = $this->cacheFilePath."/";
define('WPFC_CACHE_QUERYSTRING', true);
}
}
}
Could you please do the following: simply add define('WPFC_CACHE_QUERYSTRING', true);
to your wp-config.php file.
Turn error reporting/display errors on and navigate to any frontend page. You will see the error that reads like “You cannot redefine global constants”.
So, either there’s no point in using a global define. Apparently you don’t want anybody to use it, so why expose it?
Or you properly check if it’s present before setting it, like all other wordpress plugins do. if (!defined('MY_CONSTANT')) { define('MY_CONSTANT', 'some val'); }
or shorter:
defined('MY_CONSTANT) or define('MY_CONSTANT', 'some val');
or in the case of your function:
public function remove_url_paramters(){
if (defined('WPFC_CACHE_QUERYSTRING')) {
return;
}
$action = false;
//to remove query strings for cache if Google Click Identifier are set
if(preg_match("/gclid\=/i", $this->cacheFilePath)){
$action = true;
}
//to remove query strings for cache if facebook parameters are set
if(preg_match("/fbclid\=/i", $this->cacheFilePath)){
$action = true;
}
//to remove query strings for cache if google analytics parameters are set
if(preg_match("/utm_(source|medium|campaign|content|term)/i", $this->cacheFilePath)){
$action = true;
}
if($action){
if(strlen($_SERVER["REQUEST_URI"]) > 1){ // for the sub-pages
$this->cacheFilePath = preg_replace("/\/*\?.+/", "", $this->cacheFilePath);
$this->cacheFilePath = $this->cacheFilePath."/";
define('WPFC_CACHE_QUERYSTRING', true);
}
}
}
This way you allow your plugins users to decide themselves, by defining the constant themselves.
-
This reply was modified 1 year, 5 months ago by
lilmofo.
-
This reply was modified 1 year, 5 months ago by
lilmofo.
-
This reply was modified 1 year, 5 months ago by
lilmofo.
-
This reply was modified 1 year, 5 months ago by
lilmofo.
To better illustrate my request, you can also create a file like so:
<?php
define(‘WPFC_CACHE_QUERYSTRING’, true);
define(‘WPFC_CACHE_QUERYSTRING’, true);
This will throw the same Error.
define(‘WPFC_CACHE_QUERYSTRING’, true) does not contain the google analytics and facebook links parameteres. Although a url contains any facebook ot google url, the url is served via cache as well. no need to define the WPFC_CACHE_QUERYSTRING constant.