I need to collect data through a contact form and track customer referrals. I am creating a tag for the form, but I need it to be filled only if there was a transition from a referral that contained partner
my code
// Original Referrer
function wpshore_set_session_values()
{
if (!session_id())
{
session_start();
}
if (!isset($_SESSION['OriginalRef']))
{
$_SESSION['OriginalRef'] = $_SERVER['HTTP_REFERER'];
}
if (!isset($_SESSION['LandingPage']))
{
$_SESSION['LandingPage'] = $_SERVER["REQUEST_URI"];
}
}
add_action('init', 'wpshore_set_session_values');
///
function getRefererPage3( $form_tag ){
$partner = array (
'/partner/',
);
$parts = parse_url($_SERVER['HTTP_REFERER'];
if (!empty($parts['path']) || in_array($parts['path'], $partner)){ //this row. I doubt how it should be
if ( $form_tag['name'] == 'referer-page3' ) {
$form_tag['values'][] = $_SESSION['LandingPage'];
}
}
return $form_tag;
}
if ( !is_admin() ) {
add_filter( 'wpcf7_form_tag', 'getRefererPage3' );
}
I found my problem. Maybe this solution will help anyone in the future.
function getRefererPage3( $form_tag ){
if (strpos($_SESSION['LandingPage'], 'partner') !== false) {
if ( $form_tag['name'] == 'referer-page3 ) {
$form_tag['values'][] = $_SESSION['LandingPage'];
}
}
return $form_tag;
}
if ( !is_admin() ) {
add_filter( 'wpcf7_form_tag', 'getRefererPage3' );
}
Related
I'm getting an endless redirect loop that results in a too many redirects error when trying to redirect a user when detecting a specific country.
What I'm trying to achieve is to add to the end of the request url a param that is the language and redirect to the same page that will result in them viewing the site in their own language.
Here's what I've done:
add_action('template_redirect', 'geoip_redirect');
function geoip_redirect()
{
if (function_exists('geoip_detect2_get_info_from_current_ip')) {
$user_info = geoip_detect2_get_info_from_current_ip();
$country_code = $user_info->country->isoCode;
$request_url = $_SERVER['REQUEST_URI'].'?lang=he';
$url = get_site_url(null, $request_url);
if ($country_code == 'IL') {
wp_redirect($url);
exit();
}
}
}
You need to add a condition like checking for the lang parameter before executing the code otherwise It will keep executing forever.
add_action('template_redirect', 'geoip_redirect');
function geoip_redirect()
{
if (function_exists('geoip_detect2_get_info_from_current_ip')) {
if ( ! isset( $_GET['lang'] ) ) {
$user_info = geoip_detect2_get_info_from_current_ip();
$country_code = $user_info->country->isoCode;
$request_url = $_SERVER['REQUEST_URI'].'?lang=he';
$url = get_site_url(null, $request_url);
if ($country_code == 'IL') {
wp_redirect($url);
exit();
}
}
}
}
Using this code which works fine if the user enters all capital letters. However, I need to automatically accept lowercase and sentence case as valid inputs by the user. Currently, this doesnt work, any ideas?
add_filter( 'gform_field_validation_17_4', 'custom_validation', 10, 4 );
function custom_validation( $result, $value, $form, $field ) {
$arrWhitelist = array('KNITS10', 'KATNA20');
if ( $result['is_valid'] && !in_array( $value, $arrWhitelist )) {
$result['is_valid'] = false;
$result['message'] = 'Incorrect code';
}
return $result;
}
use strtoupper(), to make the users input match yours:
add_filter( 'gform_field_validation_17_4', 'custom_validation', 10, 4 );
function custom_validation( $result, $value, $form, $field ) {
$arrWhitelist = array('KNITS10', 'KATNA20');
if ( $result['is_valid'] && !in_array( strtoupper($value), $arrWhitelist )) {
$result['is_valid'] = false;
$result['message'] = 'Incorrect code';
}
return $result;
}
You could also use strcasecmp(), but the cleaner option in this scenario would be strtoupper.
The resulting code using strcasecmp would be:
function custom_validation($result, $value, $form, $field)
{
$arrWhitelist = array('KNITS10', 'KATNA20');
array_walk(
$arrWhitelist, function ($item) use ($value, $result) {
if (strcasecmp($item, $value) === 0) {
$result['is_valid'] = false;
$result['message'] = 'Incorrect code';
}
}
);
return $result;
}
WPML Woocommerce Multilingual does not support currency setting depending on user location, so we made our own code:
function geoIPLocator() {
global $woocommerce_wpml;
$currency='EUR';
$geo=new WC_Geolocation();
$geo->init();
$country=$geo::geolocate_ip($geo::get_ip_address() );
if(isset($_SESSION['locator'])) {
if($_SESSION['locator']['IP']= =$_SERVER['REMOTE_ADDR'] && strlen($_SESSION['locator']['IP' ])>0) {
$woocommerce_wpml->multi_currency_support->s et_client_currency($_SESSION['locator'][ 'currency']);
return;
}
}
if($country['country']=="RU" || $country['country']=="BY") {
$woocommerce_wpml->multi_currency_support->s et_client_currency('RUB');
$currency='RUB';
} else {
$woocommerce_wpml->multi_currency_support->s et_client_currency('EUR');
$currency='EUR';
}
$_SESSION['locator']=array("IP" =>$_SERVER['REMOTE_ADDR'], "ISO"=>$country['country'], "currency"=>$currency);
}
add_action( 'init', 'geoIPLocator', 5);
The problem is that it breaks regular currency switcher. When this code is on, we can't switch currency to any other. Is it because we don't save or check if a user already has some currency set up to him (like the manual switcher does)?
This is corrected code
function geoIPLocator() {
try {
global $woocommerce;
if ( isset($woocommerce) && gettype($woocommerce) == 'object' && property_exists($woocommerce,'session') && gettype($woocommerce->session) == 'object' && property_exists($woocommerce->session,'get') ) {
$manual_switch=$woocommerce->session->get('client_currency', null);
if ( $manual_switch == null ) {
global $woocommerce_wpml;
$currency='EUR';
$geo=new WC_Geolocation();
$geo->init();
$country=$geo::geolocate_ip($geo::get_ip_address());
if(isset($_SESSION['locator'])) {
if($_SESSION['locator']['IP']==$_SERVER['REMOTE_ADDR'] && strlen($_SESSION['locator']['IP'])>0) {
$woocommerce_wpml->multi_currency_support->set_client_currency($_SESSION['locator']['currency']);
return;
}
}
if($country['country']=="RU" || $country['country']=="BY") {
$woocommerce_wpml->multi_currency_support->set_client_currency('RUB');
$currency='RUB';
}
else {
$woocommerce_wpml->multi_currency_support->set_client_currency('EUR');
$currency='EUR';
}
$_SESSION['locator']=array("IP"=>$_SERVER['REMOTE_ADDR'], "ISO"=>$country['country'], "currency"=>$currency);
}
}
} catch (Exception $e) {
$e->getMessage();
}
}
add_action( 'init', 'geoIPLocator', 5);
This question already has answers here:
Creating default object from empty value in PHP?
(18 answers)
Closed 7 years ago.
I have a PHP file on my website that is producing errors after upgrading from PHP 5.3 to PHP 5.4. This is the error it produces:
Warning: Creating default object from empty value in (removing this
part of the error)/arcade.php on line 60
This is what the code looks like after like 60:
{
$this->arcade->version = '';
}else
{
$this->arcade->version = '3.4.0';
}
I'm assuming it has to do with the blank value there. I researched some similar fixes, but I'm still having trouble figuring out exactly what I should add to the php file to fix it.
Thank you very much for any help ahead of time!
Edit: Here's the rest of the code I'm not sure where it intializes. I'm pretty ignorant of these things.
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files. <br /> <b>File Version 3.3.0</b>";
exit();
}
class component_public
{
var $ipsclass = '';
var $arcade = '';
function run_component()
{
$this->ipsclass->load_language( 'lang_Arcade' );
if( !$this->ipsclass->cache['arcade_settings']['allow_user_skin'] )
{
if( $this->ipsclass->cache['arcade_settings']['skin'] == 0 ) {
$this->ipsclass->load_template('skin_Arcade1');
}
if( $this->ipsclass->cache['arcade_settings']['skin'] == 1 ) {
$this->ipsclass->load_template('skin_Arcade2');
}
if( $this->ipsclass->cache['arcade_settings']['skin'] == 2 ) {
$this->ipsclass->load_template('skin_Arcade3');
}
}else
if( $this->ipsclass->cache['arcade_settings']['allow_user_skin'] && !$this->ipsclass->member['id'] )
{
if( $this->ipsclass->cache['arcade_settings']['skin'] == 0 ) {
$this->ipsclass->load_template('skin_Arcade1');
}
if( $this->ipsclass->cache['arcade_settings']['skin'] == 1 ) {
$this->ipsclass->load_template('skin_Arcade2');
}
if( $this->ipsclass->cache['arcade_settings']['skin'] == 2 ) {
$this->ipsclass->load_template('skin_Arcade3');
}
}else
if( $this->ipsclass->cache['arcade_settings']['allow_user_skin'] && $this->ipsclass->member['id'] )
{
$this->ipsclass->DB->query("SELECT arcade_skin FROM ".$this->ipsclass->vars['sql_tbl_prefix']."members WHERE id=".intval($this->ipsclass->member['id']));
$this->arcade->lib->user = $this->ipsclass->DB->fetch_row();
if( $this->arcade->lib->user['arcade_skin'] == 0) {
$this->ipsclass->load_template('skin_Arcade1');
}
if( $this->arcade->lib->user['arcade_skin'] == 1) {
$this->ipsclass->load_template('skin_Arcade2');
}
if( $this->arcade->lib->user['arcade_skin'] == 2) {
$this->ipsclass->load_template('skin_Arcade3');
}
}
if( !$this->ipsclass->cache['arcade_settings']['build'] )
{
$this->arcade->version = '';
}else
{
$this->arcade->version = '3.4.0';
}
$this->ipsclass->vars['arcade_dir'] = 'arcade';
$component_copyright = '<div class="copyright" align="center">ibProArcade '.$this->arcade->version.' © '.date('Y').'</div>';
$this->ipsclass->skin['_wrapper'] = str_replace("<% COPYRIGHT %>", $component_copyright . "<% COPYRIGHT %>", $this->ipsclass->skin['_wrapper']);
require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/db/arcade_mysql.php';
$this->arcade->db = new arcade_db;
$this->arcade->db->ipsclass =& $this->ipsclass;
require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/arcadelib.php';
$this->arcade->lib = new arcadelib;
$this->arcade->lib->ipsclass =& $this->ipsclass;
$this->arcade->lib->arcade =& $this->arcade;
$this->arcade->lib->init();
require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/scoreboard.php';
$this->arcade->sb = new scoreboard;
$this->arcade->sb->ipsclass =& $this->ipsclass;
$this->arcade->sb->arcade =& $this->arcade;
require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/arcadeskin.php';
$this->arcade->skin = new arcadeskin;
$this->arcade->skin->ipsclass =& $this->ipsclass;
$this->arcade->skin->arcade =& $this->arcade;
require_once ROOT_PATH.'sources/api/api_topics_and_posts.php';
$this->arcade->api = new api_topics_and_posts();
$this->arcade->api->ipsclass =& $this->ipsclass;
if( $this->arcade->lib->settings['arcade_status'] )
{
$this->arcade->lib->arcade_error( array( LEVEL => 1, MSG => 'arcade_offlinemsg' ) );
}
$page = (isset($this->ipsclass->input['p'])) ? $this->ipsclass->txt_alphanumerical_clean( $this->ipsclass->input['p'] ) : 'default';
$code = (isset($this->ipsclass->input['code'])) ? $this->ipsclass->input['code'] : '';
// Backwords compatibility with older games
if( isset($this->ipsclass->input['do']) && ($this->ipsclass->input['do'] == 'newscore') )
{
$code = 'newscore';
}
if( isset($this->ipsclass->input['do']) && ($this->ipsclass->input['do'] == 'verifyscore') )
{
$code = 'verifyscore';
}
if( isset($this->ipsclass->input['do']) && ($this->ipsclass->input['do'] == 'savescore') )
{
$code = 'savescore';
}
$file = ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/page_'.$page.'.php';
if( file_exists($file) )
{
require $file;
}
else
{
require ROOT_PATH.$this->ipsclass->vars['arcade_dir'].'/modules/page_default.php';
}
$runme = new arcade_page;
$runme->ipsclass =& $this->ipsclass;
$runme->arcade =& $this->arcade;
$runme->exec_page( $code );
}
}
You got that error if trying to access properties of unexistent objects, like this:
$arcade = null;
$arcade->version = '3.4.0';
In order to fix it, yours $this->arcade property should not be empty.
Upd.
First, remove the line with arcade definition/initialization entirely:
class component_public
{
var $ipsclass = '';
function run_component()
{
$this->ipsclass->load_language( 'lang_Arcade' );
Next, add this piece of code:
class SilentAssasin {
public function __get($property) {
return $this->{$property} = new static();
}
}
class component_public extends SilentAssasin
{
instead of this:
class component_public
{
That must fix that creating from empty error.
Ah, forgot to mention... That SilentAssasin is just a name for custom class, you actually can name it anything you like, like PathosErrorSuppressor or OversizedBanHammerForThatStupidError etc.
Code ONE (WORK ARIGHT):
function Hello( $rel ) {
$res = mysqli("SELECT * FROM TABLE");
$result = $res->num_rows;
if ( $rel == 1 ) {
print $result;
} elseif ( $rel == 2 ) {
echo $result;
} elseif ( $rel == 3 ) {
return $result;
} else {
return $result;
}
}
$pr = HELLO(3);
echo $pr;
It code work aright.
Then I wanted to do one function to process the data and output the result.
Code:
function out( $rel, $result ) {
if ( $rel == 1 ) {
print $result;
} elseif ( $rel == 2 ) {
echo $result;
} elseif ( $rel == 3 ) {
return $result;
} else {
return $result;
}
}
function Hello( $rel ) {
$res = mysqli("SELECT * FROM TABLE");
$result = $res->num_rows;
out( $rel, $result )
}
$pr = HELLO(3);
echo $pr;
But now code not work(not show results on line echo $pr;)...
Tell me please why i have error and how write aright?
P.S.: i not know that need use return before function.
Thanks all for my new knowledge.
You simply forgot to add return to out($rel,$result)
as it is right now, your Hello() function doesn't have return value.
You have not return the value in the second code.
you need to use like this:
return out($rel,$result).
The return is in the second function, second function returns the value to function first, now function first also needs to return, so u need to add return there too.