We can't load the requested web page. This page requires cookies to be enabled in your browser settings. Please check this setting and enable cookies (if they are not enabled). Then try again. If this error persists, contact the site administrator for assistance.
Site Administrators: This error may indicate that users are accessing this page using a domain or URL other than the configured Base URL. EXAMPLE: Base URL is http://example.org, but some users are accessing the page via http://www.example.org or a domain alias like http://myotherexample.org.
Error type: Could not find a valid session key.
BELOW IS THE CODE RESPONSIBLE FOR THE ERROR "Error type: Could not find a valid session key"
$update_email = civicrm_api3('Email','get', $update_email_params);
if (isset($update_email['id']) && $update_email['values'][0]['email'] !=$objectRef[$parameters['email']]){
$update_email_final = civicrm_api3('Email','create', [
'sequential'=> 1,
'contact_id'=> $custom_44_result['id'],
'email' => $objectRef[$parameters['email']],
'is_primary'=> 1,
'id' => $update_email['id'],
]);
}
Above is the update email code snippet which --- when placed gives error Could not find a valid session key --- when removed the error vanishes and process is completed
The complete code is as seen below
define('FirstName2','custom_47');
define('LastName2','custom_48');
define('Email2','custom_50');
define('CID2','custom_49')
add_filter( 'civicrm_post', 'alter_profiles_event', 10, 4 );
function alter_profiles_event($op, $objectName, $objectId, &$objectRef){
if (is_user_logged_in()){
if ($objectName == 'Profile' && ($op == 'edit' ||$op == 'create' ) && isset($objectRef[FirstName1])) {
$parameters = array(
'first_name' => FirstName2,
'last_name' =>LastName2,
'email' =>Email2,
'cid' => CID2,
);
civicrm_alter_family_members($objectRef,$parameters);
}
}
}
function civicrm_alter_family_members($objectRef,$parameters) {
$custom_44_params = [
'sequential' => 1,
'contact_type' => "Individual",
'first_name' => $objectRef[$parameters['first_name']],
'last_name' => $objectRef[$parameters['last_name']],
];
if (isset($objectRef[$parameters['cid']]) && !empty($objectRef[$parameters['cid']])) {
$custom_44_params['contact_id'] = $objectRef[$parameters['cid']];
}
$custom_44_result = civicrm_api3('Contact','create',$custom_44_params);
if (!empty($objectRef[$parameters['email']])){
$update_email_params = [
'sequential'=> 1,
'contact_id'=> $custom_44_result['id'],
'is_primary'=> 1,
];
$update_email = civicrm_api3('Email','get', $update_email_params);
if (isset($update_email['id']) && $update_email['values'][0]['email'] !=$objectRef[$parameters['email']]){
$update_email_final = civicrm_api3('Email','create', [
'sequential'=> 1,
'contact_id'=> $custom_44_result['id'],
'email' => $objectRef[$parameters['email']],
'is_primary'=> 1,
'id' => $update_email['id'],
]);
}
}
}
I see updating civicrm email id gives session key error. I also have
CiviCRM WordPress Profile Sync
plugin enabled. Even when I disabled it, the error was existent. So, ruled out above plugin to be causing the error.
When above CiviCRM email is updated, it updates the Email of the Wordpress User.
'first_name' => FirstName2,
so I'd fix those first and repost your code when you're sure your code is error-free.