campaignmonitor_general_form() passes on the global $user object onto _campaignmonitor_is_subscribed(). However, if you're editing a user as admin, it'll always use your details to populate that checkbox and not the users.

Comments

ssherriff’s picture

Status: Active » Fixed

This has now been fixed and the next release will include the fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

djschoone’s picture

i checked the code for the fix, but i am unable to find it.

function campaignmonitor_user_form() {
  global $user;
  // Replace api_key and list_id with your own details
  $api_key = variable_get('campaignmonitor_api_key', '');
  $list_id = variable_get('campaignmonitor_list_id', '');
  $email = $user->mail;
  if (_campaignmonitor_is_subscribed($api_key, $list_id, $email, TRUE)) {
    $default = TRUE;
  }
  else {
    $default = FALSE;
  }

is incorrect

Now looking for the mailadress for the current requested user page (e.g. user/1023/newsletters)

djschoone’s picture

trying to quick fix... getting closer

--- current.campaignmonitor.module      2011-03-29 16:26:50.000000000 +0200
+++ campaignmonitor.module      2011-03-29 16:31:56.000000000 +0200
@@ -45,6 +45,7 @@ function campaignmonitor_menu() {
   $items['user/%user/newsletters'] = array(
     'title' => 'My Newsletters',
     'page callback' => 'campaignmonitor_user_page',
+    'page arguments' => array(1),
     'access arguments' => array('join newsletter'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 5,
@@ -293,16 +294,21 @@ function campaignmonitor_newsletter_arch
   return $content;
 }

-function campaignmonitor_user_page() {
-  return drupal_get_form('campaignmonitor_user_form');
+function campaignmonitor_user_page($account) {
+  return drupal_get_form('campaignmonitor_user_form', $account);
 }

-function campaignmonitor_user_form() {
+function campaignmonitor_user_form(&$form_state = NULL, $account = NULL) {
   global $user;
   // Replace api_key and list_id with your own details
   $api_key = variable_get('campaignmonitor_api_key', '');
   $list_id = variable_get('campaignmonitor_list_id', '');
+  if(!is_object($account)){
   $email = $user->mail;
+  }
+  else{
+    $email = $account->mail;
+  }
   if (_campaignmonitor_is_subscribed($api_key, $list_id, $email, TRUE)) {
     $default = TRUE;
   }

it now passes the first argument (the %user) as an argument. Checking if subscribed works, now we need to change campaignmonitor_user_form_submit() to use also the %user argument or the previously set $form-values