Пример #1
0
 /**
  * Wrapper function to send notification with WP-CRM or without one
  * @param mixed $args['user']
  * @param sting $args['trigger_action']
  * @param sting $args['data']             aka $notification_data
  * @param sting $args['crm_log_message']
  * @param sting $args['subject']          using in email notification
  * @param sting $args['message']          using in email notification
  * @uses self::replace_data()
  * @uses wp_crm_send_notification()
  * @return boolean false if notification was not sent successfully
  * @autor odokienko@UD
  */
 public static function send_notification($args = array())
 {
     $args = wp_parse_args($args, array('ignore_wp_crm' => false, 'user' => false, 'trigger_action' => false, 'data' => array(), 'message' => '', 'subject' => '', 'crm_log_message' => ''));
     if (is_numeric($args['user'])) {
         $args['user'] = get_user_by('id', $args['user']);
     } elseif (filter_var($args['user'], FILTER_VALIDATE_EMAIL)) {
         $args['user'] = get_user_by('email', $args['user']);
     } elseif (is_string($args['user'])) {
         $args['user'] = get_user_by('login', $args['user']);
     }
     if (!is_object($args['user']) || empty($args['user']->data->user_email)) {
         return false;
     }
     if (function_exists('wp_crm_send_notification') && empty($args['ignore_wp_crm'])) {
         if (!empty($args['crm_log_message'])) {
             wp_crm_add_to_user_log($args['user']->ID, self::replace_data($args['crm_log_message'], $args['data']));
         }
         if (!empty($args['trigger_action']) && is_callable('WP_CRM_N', 'get_trigger_action_notification')) {
             $notifications = WP_CRM_N::get_trigger_action_notification($args['trigger_action']);
             if (!empty($notifications)) {
                 return wp_crm_send_notification($args['trigger_action'], $args['data']);
             }
         }
     }
     if (empty($args['message'])) {
         return false;
     }
     return wp_mail($args['user']->data->user_email, self::replace_data($args['subject'], $args['data']), self::replace_data($args['message'], $args['data']));
 }
Пример #2
0
 /**
  * Fires off when a user retrieves their WordPres password.
  *
  * Adds note to user stream.
  *
  */
 function wp_crm_retrieve_password($user_login)
 {
     global $wpdb;
     $user_id = username_exists($user_login);
     if (!$user_id) {
         return;
     }
     $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM {$wpdb->users} WHERE user_login = %s", $user_login));
     if (empty($key)) {
         $key = wp_generate_password(20, false);
         do_action('retrieve_password_key', $user_login, $key);
         $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
     }
     $reset_url = network_site_url("wp-login.php?action=rp&key={$key}&login="******"' . $reset_url . '">' . $reset_url . '</a>');
     wp_crm_add_to_user_log($user_id, $message);
 }
Пример #3
0
 /**
  * Handle "quick actions" via ajax
  *
  * Return json instructions on next action.  User by several JS functions.
  *
  * @since 0.1
  *
  */
 static function quick_action($array = false)
 {
     global $wpdb;
     $action = !empty($_REQUEST['wp_crm_quick_action']) ? $_REQUEST['wp_crm_quick_action'] : false;
     $object_id = !empty($_REQUEST['object_id']) ? $_REQUEST['object_id'] : false;
     switch ($action) {
         case 'reset_user_password':
             $user_password = wp_generate_password(12, false);
             if ($object_id && $wpdb->update($wpdb->users, array('user_pass' => wp_hash_password($user_password)), array('ID' => $object_id))) {
                 $user_data = get_userdata($object_id);
                 $user_login = $user_data->user_login;
                 $user_email = $user_data->user_email;
                 $reset_key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM {$wpdb->users} WHERE user_login = %s", $user_login));
                 if (empty($reset_key)) {
                     $key = wp_generate_password(20, false);
                     $wpdb->update($wpdb->users, array('user_activation_key' => $reset_key), array('user_login' => $user_login));
                 }
                 wp_crm_add_to_user_log($object_id, __('Password reset. A random password has been generated for user by system.', 'wp_crm'));
                 $args['user_login'] = $user_login;
                 $args['user_email'] = $user_email;
                 $args['user_password'] = $user_password;
                 $args['reset_key'] = $reset_key;
                 $args['reset_url'] = network_site_url("wp-login.php?action=rp&key={$reset_key}&login="******"DELETE FROM {$wpdb->crm_log} WHERE id = {$object_id}")) {
                 $return['success'] = 'true';
                 $return['message'] = __('Message deleted.', 'wp_crm');
                 $return['action'] = 'hide_element';
             }
             break;
         case 'trash_message_and_user':
             if (current_user_can('delete_users')) {
                 $user_id = $wpdb->get_var("SELECT object_id FROM {$wpdb->crm_log} WHERE id = {$object_id} AND object_type = 'user' ");
                 if ($user_id) {
                     wp_delete_user($user_id);
                 }
                 $return['success'] = 'true';
                 $return['message'] = __('Sender trashed.', 'wp_crm');
                 $return['action'] = 'hide_element';
             }
             break;
         default:
             $return = apply_filters('wp_crm_quick_action', array('action' => $action, 'object_id' => $object_id));
             break;
     }
     if (is_array($return)) {
         return json_encode($return);
     } else {
         return false;
     }
 }
Пример #4
0
/**
 * Sends notification to invoice creator
 *
 * @global array $wpi_settings
 *
 * @param array $invoice
 *
 * @author korotkov@UD
 *
 * @refactoring odokienko@UD
 */
function wp_invoice_send_creator_notification($invoice, $notification_data)
{
    global $wpi_settings;
    $headers = array("From: {$notification_data['business_name']} <{$notification_data['from']}>\r\n", "Content-Type: text/html");
    $subject = sprintf(__("Invoice #%s has been paid", WPI), $notification_data['invoice_id']);
    $message = sprintf(__("Hello %1s,<br><br>%2s has paid invoice #%3s.<br><br>%4s<br>Total payments: %5s %6s of %7s %8s.<br><br>You can overview invoice status and payment history by clicking this link:<br>%9s<br><br>User information:<br><br>ID: %10s<br>Name: %11s<br>Email: %12s<br><br>--------------------<br>%13s", WPI), $notification_data['creator_name'], $notification_data['user_name'], $notification_data['invoice_id'], $notification_data['invoice_title'], $notification_data['default_currency_code'], $notification_data['total_payments'], $notification_data['default_currency_code'], $notification_data['total'], $notification_data['permalink'], $notification_data['user_id'], $notification_data['user_name'], $notification_data['user_email'], $notification_data['site']);
    if (function_exists('wp_crm_send_notification') && !empty($wpi_settings['use_wp_crm_to_send_notifications']) && $wpi_settings['use_wp_crm_to_send_notifications'] == 'true') {
        wp_crm_send_notification('wpi_send_invoice_creator_email', $notification_data);
        //** Add message to user activity stream */
        wp_crm_add_to_user_log($notification_data['creator_id'], sprintf(__("WP-Invoice: Message with subject '%1s' was sent", WPI), $subject), false, array('attribute' => 'wpi_notification'));
    } else {
        $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
        $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
        wp_mail("{$notification_data['creator_name']} <{$notification_data['creator_email']}>", $subject, $message, implode("\r\n", (array) $headers) . "\r\n");
    }
}