Example #1
0
 /**
  * Admin notice
  * @global object $current_screen
  * @global array $wp_crm
  * @return boolean
  */
 static function wp_crm_admin_notice()
 {
     global $current_screen, $wp_crm;
     if ($current_screen->id != 'crm_page_wp_crm_settings' || !is_array($wp_crm['data_structure']['attributes'])) {
         return false;
     }
     $required_fields = apply_filters('wp_crm_requires_fields', array('user_email'));
     foreach ($required_fields as $field) {
         if (!array_key_exists($field, $wp_crm['data_structure']['attributes'])) {
             WP_CRM_F::add_message(sprintf(__('Warning: there is no field with slug \'%s\' in list of user attributes on Data tab!', 'wp_crm'), $field), 'bad');
         }
     }
 }
<?php

global $wp_roles;
if (isset($_REQUEST['message'])) {
    switch ($_REQUEST['message']) {
        case 'updated':
            WP_CRM_F::add_message('Settings updated.');
            break;
    }
}
if (empty($wp_crm['notifications'])) {
    $wp_crm['notifications']['example']['subject'] = "Subject";
    $wp_crm['notifications']['example']['to'] = "[user_email]";
    $wp_crm['notifications']['example']['message'] = "Hello [display_name], \n\n Thank you for your message.";
    $wp_crm['notifications']['example']['send_from'] = get_bloginfo('admin_email');
}
if (empty($wp_crm['data_structure']['attributes'])) {
    $wp_crm['data_structure']['attributes'] = array('user_email' => array('title' => 'Email', 'primary' => 'true'));
}
$parseUrl = parse_url(trim(get_bloginfo('url')));
$this_domain = trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2)));
?>

 <script type="text/javascript">

  /* Build trigger action argument array */
  var notification_action_arguments = new Array();

  jQuery(document).ready(function() {
    jQuery("#wp_crm_settings_tabs").tabs({ cookie: { expires: 30,
      name: 'wpc_settings_page_tabs' } });
<?php

if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) {
    $attribute_keys = array_keys($wp_crm['data_structure']['attributes']);
} else {
    $attribute_keys = array();
}
if ($_REQUEST['message'] == 'created') {
    WP_CRM_F::add_message(__('Profile created.', 'wp_crm'));
} elseif ($_REQUEST['message'] == 'updated') {
    WP_CRM_F::add_message(__('Profile updated.', 'wp_crm'));
}
if ($wp_crm_user) {
    $user_id = $_REQUEST['user_id'];
    $object = $wp_crm_user;
    $title = WP_CRM_F::get_primary_display_value($object);
} else {
    $object = array();
    $object['new'] = true;
    $object['user_role']['default'][0] = get_option('default_role');
    $title = __('Add New Person', 'wp_crm');
}
$wp_crm_js = array('user_id' => is_numeric($user_id) ? $user_id : false, 'hidden_attributes' => $wp_crm['hidden_attributes']);
if ($wp_crm['configuration']['standardize_display_name'] == 'true' && !empty($wp_crm['configuration']['display_name_rule'])) {
    $wp_crm_js['standardize_display_name'] = true;
    $wp_crm_js['display_name_rule'] = $wp_crm['configuration']['display_name_rule'];
}
if (is_array($wp_crm_js)) {
    echo '<script type="text/javascript">var wp_crm = jQuery.parseJSON(' . json_encode(json_encode($wp_crm_js)) . '); </script>';
}
?>
Example #4
0
 /**
  * Saves Buddypress profile data.
  *
  * @uses WP_CRM_Core::wp_crm_save_user_data()
  * @param array $data. Request (POST,GET)
  * @author peshkov@UD
  */
 static function bp_save_profile_data($data)
 {
     global $bp;
     if (empty($data['bp']) || empty($data['user_id'])) {
         return;
     }
     //* Set necessary variables */
     $user_id = $data['user_id'];
     $user_data = $data['wp_crm']['user_data'];
     $data = $data['bp'];
     $errors = false;
     $posted_field_ids = array();
     $is_required = array();
     //* Set xprofile full name from display_name */
     $display_name = WP_CRM_F::get_first_value($user_data['display_name']);
     if (!empty($display_name)) {
         $fullname_field_name = bp_xprofile_fullname_field_name();
         $fullname_field_id = xprofile_get_field_id_from_name($fullname_field_name);
         $data["field_{$fullname_field_id}"] = $display_name;
     }
     //* Get all posted field ids */
     foreach ($data as $name => $value) {
         $field_id = str_replace(array('field_', '_day', '_month', '_year'), '', $name);
         array_push($posted_field_ids, $field_id);
     }
     $posted_field_ids = array_unique($posted_field_ids);
     //* Validate the field */
     foreach ($posted_field_ids as $field_id) {
         if (!isset($data['field_' . $field_id])) {
             if (!empty($data['field_' . $field_id . '_day']) && !empty($data['field_' . $field_id . '_month']) && !empty($data['field_' . $field_id . '_year'])) {
                 /* Concatenate the values */
                 $date_value = $data['field_' . $field_id . '_day'] . ' ' . $data['field_' . $field_id . '_month'] . ' ' . $data['field_' . $field_id . '_year'];
                 /* Turn the concatenated value into a timestamp */
                 $data['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
             }
         }
         $is_required[$field_id] = xprofile_check_is_required_field($field_id);
         if ($is_required[$field_id] && empty($data['field_' . $field_id])) {
             $errors = true;
         }
     }
     //** There are errors */
     if ($errors) {
         WP_CRM_F::add_message(__('Please make sure you fill in all required Buddypress fields in this profile field group before saving.', ud_get_wp_crm()->domain), 'bad');
         //** No errors */
     } else {
         //** Now we've checked for required fields, lets save the values. */
         foreach ($posted_field_ids as $field_id) {
             //** Certain types of fields (checkboxes, multiselects) may come through empty. */
             //** Save them as an empty array so that they don't get overwritten by the default on the next edit. */
             if (empty($data['field_' . $field_id])) {
                 $value = array();
             } else {
                 $value = $data['field_' . $field_id];
             }
             if (!xprofile_set_field_data($field_id, $user_id, $value, $is_required[$field_id])) {
                 $errors = true;
             } else {
                 do_action('xprofile_profile_field_data_updated', $field_id, $value);
             }
         }
         //** Set the feedback message if we have error */
         if ($errors) {
             WP_CRM_F::add_message(__('There was a problem updating some of Buddypress profile information, please try again.', ud_get_wp_crm()->domain), 'bad');
         }
     }
 }
Example #5
0
 /**
  * Saves user data
  *
  * @hooked_into WP_CRM_Core::admin_head();
  * @since 0.1
  */
 function wp_crm_save_user_data($user_data, $args = '')
 {
     global $wpdb, $wp_crm;
     $insert_data = array();
     $insert_custom_data = array();
     $args = wp_parse_args($args, array('use_global_messages' => 'true', 'match_login' => 'false', 'no_errors' => 'false', 'return_detail' => 'false', 'default_role' => get_option('default_role'), 'no_redirect' => 'false'));
     $wp_insert_user_vars = array('user_pass', 'user_email', 'user_login', 'user_url', 'role', 'user_nicename', 'display_name', 'user_registered', 'first_name', 'last_name', 'nickname');
     //** Get custom meta attributes */
     $wp_user_meta_data = array();
     if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) {
         foreach ($wp_crm['data_structure']['attributes'] as $slug => $value) {
             if (!in_array($slug, $wp_insert_user_vars)) {
                 $wp_user_meta_data[] = $slug;
             }
         }
     }
     //** Add custom keys that are not necessarily created in WP-CRM data but must be saved if passed */
     $wp_user_meta_data[] = 'show_admin_bar_front';
     $wp_user_meta_data[] = 'admin_color';
     $temp_data['user_id'] = WP_CRM_F::get_first_value($user_data['user_id']);
     // Prepare Data
     foreach ($user_data as $meta_key => $values) {
         //** Fix up values if they are not passed in the crazy CRM format */
         if (!empty($values) && !is_array($values)) {
             //** Check if Attribute TITLE was passed intead of the slug */
             foreach ($wp_crm['data_structure']['attributes'] as $attribute_slug => $attribute_data) {
                 if ($attribute_data['title'] == $meta_key) {
                     //** Actual slug / meta_key found, we overwrite the passed one */
                     $meta_key = $attribute_slug;
                     break;
                 }
             }
             //** Check if this is an option key, and value needs to be convered to 'on' */
             if ($wp_crm['data_structure']['attributes'][$meta_key]['has_options']) {
                 if (in_array($values, $wp_crm['data_structure']['attributes'][$meta_key]['option_labels'])) {
                     //** Get option key from passed option title */
                     $option_key = array_search($values, $wp_crm['data_structure']['attributes'][$meta_key]['option_labels']);
                     //** Restet $values, and update with checkbox friendly data entry */
                     $values = array(rand(10000, 99999) => array('value' => 'on', 'option' => $option_key));
                 }
             } else {
                 //** Handle Regular values */
                 $values = array(rand(10000, 99999) => array('value' => $values));
             }
         }
         //** Make sure values are always in array format */
         $values = (array) $values;
         foreach ($values as $temp_key => $data) {
             //** If this attribute is in the main user table, we store it here */
             if (in_array($meta_key, $wp_insert_user_vars)) {
                 //** Do not overwrite $insert_data if its already set */
                 if (!isset($insert_data[$meta_key])) {
                     $insert_data[$meta_key] = $data['value'];
                     continue;
                 }
                 //** Store data in meta table as well, as long as it's not already stored in main table */
                 if ($insert_data[$meta_key] != $data['value']) {
                     //** Store any extra keys in values in regular data */
                     $insert_custom_data[$meta_key][] = $data['value'];
                 }
             }
             //** If the attribute is a meta key created  by WP-CRM, we store it here */
             if (in_array($meta_key, $wp_user_meta_data)) {
                 switch (!empty($wp_crm['data_structure']['attributes'][$meta_key]['input_type']) ? $wp_crm['data_structure']['attributes'][$meta_key]['input_type'] : '') {
                     case 'checkbox':
                         if (!empty($data['option']) && $data['value'] == 'on') {
                             //** get full meta key of option */
                             $full_meta_key = $wp_crm['data_structure']['attributes'][$meta_key]['option_keys'][$data['option']];
                             if (empty($full_meta_key)) {
                                 $full_meta_key = $meta_key;
                             }
                             $insert_custom_data[$full_meta_key][] = 'on';
                         }
                         break;
                     case 'dropdown':
                         //** get full meta key of option */
                         $full_meta_key = $wp_crm['data_structure']['attributes'][$meta_key]['option_keys'][$data['option']];
                         if (empty($full_meta_key)) {
                             $full_meta_key = $meta_key;
                         }
                         if (!empty($data['option'])) {
                             $insert_custom_data[$full_meta_key][] = 'on';
                         }
                         break;
                     default:
                         //* Do not save empty values until this is being done on the profile editing page */
                         if (isset($data['value'])) {
                             if (!$args['admin_save_action'] && empty($data['value'])) {
                                 continue;
                             }
                         }
                         if (!empty($wp_crm['data_structure']['attributes'][$meta_key]['has_options'])) {
                             $full_meta_key = $wp_crm['data_structure']['attributes'][$meta_key]['option_keys'][$data['option']];
                             if (empty($full_meta_key)) {
                                 $full_meta_key = $meta_key;
                             }
                             $insert_custom_data[$full_meta_key][] = $data['value'];
                         } else {
                             $insert_custom_data[$meta_key][] = $data['value'];
                         }
                         break;
                 }
             }
         }
     }
     //* Determine user_id */
     if (empty($temp_data['user_id'])) {
         if ($args['match_login'] == 'true' && (isset($user_data['user_login']) || isset($user_data['user_email']))) {
             $temp_data['user_login'] = WP_CRM_F::get_first_value($user_data['user_login']);
             $temp_data['user_email'] = WP_CRM_F::get_first_value($user_data['user_email']);
             //* Try to get ID based on login and email */
             if ($temp_data['user_email']) {
                 $insert_data['ID'] = username_exists($temp_data['user_email']);
             }
             //* Validate e-mail */
             if (empty($insert_data['ID'])) {
                 $insert_data['ID'] = email_exists($temp_data['user_email']);
             }
         }
     } else {
         //** User ID was passed */
         $insert_data['ID'] = $temp_data['user_id'];
     }
     if (empty($insert_data['ID'])) {
         $new_user = true;
     }
     //** Set user_login from user_email or a guessed value if this is a new usr and user_login is not passed */
     if (!empty($new_user) && empty($insert_data['user_login'])) {
         //** Try getting it from e-mail address */
         if (!empty($insert_data['user_email'])) {
             $insert_data['user_login'] = $insert_data['user_email'];
         } else {
             //** Try to guess user_login from first passed user value */
             if ($user_login = WP_CRM_F::get_primary_display_value($user_data)) {
                 $user_login = sanitize_user($user_login, true);
                 $user_login = apply_filters('pre_user_login', $user_login);
                 $insert_data['user_login'] = $user_login;
             }
         }
     }
     //** If password is passed, we hash it */
     if (empty($insert_data['user_pass'])) {
         //** Unset password to prevent it being cleared out */
         unset($insert_data['user_pass']);
     } else {
         //** We don't need to do it because wp_insert/update_user does it too! @author korotkov@ud */
         /* if($new_user) {
            $insert_data['user_pass'] = wp_hash_password($insert_data['user_pass']);
            } */
     }
     //** Set default role if no role set and this isn't a new user */
     if (empty($insert_data['role']) && empty($insert_data['ID'])) {
         $insert_data['role'] = $args['default_role'];
     }
     //** @author korotkov@ud */
     if (empty($insert_data['user_email'])) {
         if ($wp_crm['configuration']['allow_account_creation_with_no_email'] == 'true') {
             $fake_user_email = rand(10000, 99999) . '@' . rand(10000, 99999) . '.com';
             $insert_data['user_email'] = $fake_user_email;
         } else {
             WP_CRM_F::add_message(__('Error saving user: Email address cannot be empty', 'wp_crm'), 'bad');
             return false;
         }
     } else {
         if (!filter_var($insert_data['user_email'], FILTER_VALIDATE_EMAIL)) {
             WP_CRM_F::add_message(__('Error saving user: Email address is invalid', 'wp_crm'), 'bad');
             return false;
         }
     }
     //** Determine if data has user_nicename we should sanitize it. peshkov@UD */
     if (isset($insert_data['user_nicename'])) {
         $user_nicename = sanitize_title($insert_data['user_nicename']);
         if (empty($user_nicename)) {
             unset($insert_data['user_nicename']);
         } else {
             $insert_data['user_nicename'] = $user_nicename;
         }
     }
     //** Always update display name if its blank */
     if (empty($insert_data['display_name']) && isset($insert_data['user_email'])) {
         $insert_data['display_name'] = $insert_data['user_email'];
     }
     if (!empty($new_user)) {
         $user_id = wp_insert_user($insert_data);
         //** If multisite - assign user to blog */
         if (is_multisite()) {
             global $blog_id;
             add_user_to_blog($blog_id, $user_id, $insert_data['role']);
         }
     } else {
         $user_id = wp_update_user($insert_data);
     }
     if (is_numeric($user_id)) {
         if (isset($fake_user_email)) {
             $wpdb->update($wpdb->users, array('user_email' => ''), array('ID' => $user_id));
         }
         //** Remove all old meta values if field is set (to avoid deleting unpasssed values) */
         foreach ($wp_user_meta_data as $meta_key) {
             if (isset($insert_custom_data[$meta_key])) {
                 delete_user_meta($user_id, $meta_key);
             }
             //** Delete old option meta keys for this meta_key  */
             if (!empty($wp_crm['data_structure']['attributes'][$meta_key]['has_options'])) {
                 //** Delete "holder" meta key (this may not be necessary */
                 delete_user_meta($user_id, $meta_key);
                 foreach ($wp_crm['data_structure']['attributes'][$meta_key]['option_keys'] as $old_meta_key) {
                     //** Delete individual long (optional) meta keys */
                     delete_user_meta($user_id, $old_meta_key);
                 }
             } elseif (isset($args['admin_save_action']) && !empty($wp_crm['data_structure']['attributes'][$meta_key]['input_type']) && $wp_crm['data_structure']['attributes'][$meta_key]['input_type'] == 'checkbox') {
                 delete_user_meta($user_id, $meta_key);
             }
         }
         //** Add meta values */
         if (is_array($insert_custom_data) && !empty($insert_custom_data)) {
             foreach ((array) $insert_custom_data as $meta_key => $meta_value) {
                 foreach ($meta_value as $single_value) {
                     add_user_meta($user_id, $meta_key, $single_value);
                 }
             }
         }
         $display_name = WP_CRM_F::get_primary_display_value($user_id);
         if ($display_name) {
             $wpdb->update($wpdb->users, array('display_name' => $display_name), array('ID' => $user_id));
         }
         if (!empty($new_user)) {
             if ($args['use_global_messages'] == 'true') {
                 WP_CRM_F::add_message(__('New user added.', 'wp_crm'));
             }
         } else {
             if ($args['use_global_messages'] == 'true') {
                 WP_CRM_F::add_message(__('User updated.', 'wp_crm'));
             }
         }
         do_action('wp_crm_save_user', array('user_id' => $user_id, 'insert_data' => $insert_data, 'insert_custom_data' => $insert_custom_data, 'args' => $args));
         // Don't redirect if data was passed
         if ($args['no_redirect'] != 'true') {
             if (!empty($_REQUEST['redirect_to'])) {
                 $url = urldecode($_REQUEST['redirect_to']) . "&message=updated";
             } else {
                 $url = admin_url("admin.php?page=wp_crm_add_new&user_id={$user_id}&message=" . (!empty($new_user) ? 'created' : 'updated'));
             }
             wp_redirect($url);
         }
     } else {
         if ($args['use_global_messages'] == 'true') {
             switch ($user_id->get_error_code()) {
                 case 'existing_user_email':
                     $existing_id = email_exists($insert_data['user_email']);
                     WP_CRM_F::add_message(sprintf(__('Error saving user: %s', 'wp_crm'), $user_id->get_error_message() . ' <a href="' . admin_url("admin.php?page=wp_crm_add_new&user_id={$existing_id}") . '">' . __('Go to user profile', 'wp_crm') . '</a>'), 'bad');
                     break;
                 default:
                     WP_CRM_F::add_message(sprintf(__('Error saving user: %s', 'wp_crm'), $user_id->get_error_message()), 'bad');
                     break;
             }
         }
     }
     if ($args['no_errors'] && is_wp_error($user_id)) {
         return false;
     }
     if ($args['return_detail'] == 'true') {
         $return['user_id'] = $user_id;
         if ($new_user) {
             $return['new_user'] = true;
         }
         return $return;
     }
     return $user_id;
 }
<?php

if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) {
    $attribute_keys = array_keys($wp_crm['data_structure']['attributes']);
} else {
    $attribute_keys = array();
}
if (!empty($_REQUEST['message']) && $_REQUEST['message'] == 'created') {
    WP_CRM_F::add_message(__('Profile created.', ud_get_wp_crm()->domain));
} elseif (!empty($_REQUEST['message']) && $_REQUEST['message'] == 'updated') {
    WP_CRM_F::add_message(__('Profile updated.', ud_get_wp_crm()->domain));
}
/** Set GET param redirect_to. After user saving server will redirect to the current screen (redirect_to is current_screen ID). */
$redirect_to = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : "";
if ($wp_crm_user) {
    $user_id = $_REQUEST['user_id'];
    $object = $wp_crm_user;
    $title = WP_CRM_F::get_primary_display_value($object);
} else {
    $object = array();
    $object['new'] = true;
    $object['user_role']['default'][0] = get_option('default_role');
    $title = __('Add New Person', ud_get_wp_crm()->domain);
}
$wp_crm_js = array('user_id' => isset($user_id) && is_numeric($user_id) ? $user_id : false, 'hidden_attributes' => !empty($wp_crm['hidden_attributes']) ? $wp_crm['hidden_attributes'] : array());
if (!empty($wp_crm['configuration']['standardize_display_name']) && $wp_crm['configuration']['standardize_display_name'] == 'true' && !empty($wp_crm['configuration']['display_name_rule'])) {
    $wp_crm_js['standardize_display_name'] = true;
    $wp_crm_js['display_name_rule'] = $wp_crm['configuration']['display_name_rule'];
}
if (is_array($wp_crm_js)) {
    echo '<script type="text/javascript">var wp_crm = jQuery.parseJSON(' . json_encode(json_encode($wp_crm_js)) . '); </script>';
Example #7
0
<?php

if (!empty($_REQUEST['message']) && $_REQUEST['message'] == 'user_deleted') {
    WP_CRM_F::add_message(__('User has been deleted and all associated posts have been trashed.', ud_get_wp_crm()->domain));
}
if (!empty($_REQUEST['message']) && $_REQUEST['message'] == 'plugin_updated') {
    WP_CRM_F::add_message(__('WP-CRM has been updated.', ud_get_wp_crm()->domain));
}
include ud_get_wp_crm()->path("lib/class_user_list_table.php", 'dir');
$wp_list_table = new CRM_User_List_Table("per_page=25");
$wp_list_table->prepare_items();
$wp_list_table->data_tables_script();
?>
<div class="wp_crm_overview_wrapper wrap">
<div class="wp_crm_ajax_result"></div>
    <?php 
screen_icon();
?>
    <h2><?php 
_e('CRM - All People', ud_get_wp_crm()->domain);
?>
 <?php 
if (current_user_can('WP-CRM: View Profiles') && (current_user_can('create_users') || current_user_can('add_users'))) {
    ?>
<a href="<?php 
    echo admin_url('admin.php?page=wp_crm_add_new');
    ?>
" class="button add-new-h2"><?php 
    _e('Add New', ud_get_wp_crm()->domain);
    ?>
</a><?php 
 <?php 
if ($_REQUEST['message'] == 'user_deleted') {
    WP_CRM_F::add_message(__('User has been deleted and all associated posts have been trashed.', 'wp_crm'));
}
if ($_REQUEST['message'] == 'plugin_updated') {
    WP_CRM_F::add_message(__('WP-CRM has been updated, and any premium features your domain qualifies for have been downloaded.', 'wp_crm'));
}
include WP_CRM_Path . '/core/class_user_list_table.php';
$wp_list_table = new CRM_User_List_Table("per_page=25");
$wp_list_table->prepare_items();
$wp_list_table->data_tables_script();
?>


<div class="wp_crm_overview_wrapper wrap">
<div class="wp_crm_ajax_result"></div>
    <?php 
screen_icon();
?>
    <h2><?php 
_e('CRM - All People');
?>
 <?php 
if (current_user_can('WP-CRM: View Profiles') && (current_user_can('create_users') || current_user_can('add_users'))) {
    ?>
<a href="<?php 
    echo admin_url('admin.php?page=wp_crm_add_new');
    ?>
" class="button add-new-h2"><?php 
    _e('Add New');
    ?>