function openfire_authenticate($user, $username, $password)
{
    global $openfire;
    $openfire->of_logInfo("openfire_authenticate 1 " . $username . " " . $password);
    if (!openfire_wants_to_login()) {
        return new WP_Error('user_logged_out', sprintf(__('You are now logged out of Azure AD.', AADSSO), $username));
    }
    // Don't re-authenticate if already authenticated
    if (strrpos($username, "@") == false || is_a($user, 'WP_User')) {
        return $user;
    }
    $openfire->of_logInfo("openfire_authenticate 2 ");
    // Try to find an existing user in WP where the UPN of the current AAD user is
    // (depending on config) the 'login' or 'email' field
    if ($username && $password && $openfire->of_authenticate_365($username, $password)) {
        $user = get_user_by("email", $username);
        if (!is_a($user, 'WP_User')) {
            $openfire->of_logInfo("openfire_authenticate 3");
            // Since the user was authenticated with AAD, but not found in WordPress,
            // need to decide whether to create a new user in WP on-the-fly, or to stop here.
            $openfire->of_logInfo("openfire_authenticate 4");
            $paras = explode("@", $username);
            $userid = $paras[0] . "." . $paras[1];
            $new_user_id = wp_create_user($userid, $password, $username);
            $user = new WP_User($new_user_id);
            $user->set_role('subscriber');
            $first_name = $openfire->of_get_given_name();
            $last_name = $openfire->get_family_name();
            $display_name = $first_name . " " . $last_name;
            wp_update_user(array('ID' => $new_user_id, 'display_name' => $display_name, 'first_name' => $first_name, 'last_name' => $last_name));
        }
    }
    return $user;
}
 public function load_user()
 {
     if ($this->id > 0) {
         $current_user = get_user_by('ID', $this->id);
     } elseif (function_exists('is_user_logged_in') && is_user_logged_in()) {
         $current_user = wp_get_current_user();
     }
     if (isset($current_user) && $current_user) {
         $this->id = $current_user->ID;
         $this->first_name = $current_user->user_firstname;
         $this->last_name = $current_user->user_lastname;
         $this->email = $current_user->user_email;
         $this->address = get_user_meta($current_user->ID, 'address', TRUE);
         $this->is_on_mailing_list = get_user_meta($current_user->ID, 'mailing_list', TRUE);
         $this->is_on_mailing_list = $this->is_on_mailing_list == 1 ? TRUE : FALSE;
         $neighborhood_id = get_user_meta($current_user->ID, 'neighborhood_id', TRUE);
         if (!empty($neighborhood_id) && $neighborhood_id > 0) {
             $args = array('post_type' => 'wbb_neighborhood', 'post_status' => 'publish');
             $query = new \WP_Query($args);
             while ($query->have_posts()) {
                 $query->the_post();
                 if (get_the_ID() == $neighborhood_id) {
                     $this->neighborhood = new Neighborhood();
                     $this->neighborhood->post_id = get_the_ID();
                     $this->neighborhood->title = get_the_title();
                     break;
                 }
             }
         }
         $this->get_locations();
     }
 }
Example #3
1
function xfac_get_avatar($avatar = '', $id_or_email, $size = 96, $default = '', $alt = '')
{
    if (is_numeric($id_or_email)) {
        $wpUserId = (int) $id_or_email;
    } elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) {
        $wpUserId = $user->ID;
    } elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) {
        $wpUserId = (int) $id_or_email->user_id;
    }
    if (empty($wpUserId)) {
        // cannot figure out the user id...
        return $avatar;
    }
    $apiRecords = xfac_user_getRecordsByUserId($wpUserId);
    if (empty($apiRecords)) {
        // no api records
        return $avatar;
    }
    $apiRecord = reset($apiRecords);
    if (empty($apiRecord->profile['links']['avatar'])) {
        // no avatar?
        return $avatar;
    }
    $avatar = $apiRecord->profile['links']['avatar'];
    $size = (int) $size;
    if (empty($alt)) {
        $alt = get_the_author_meta('display_name', $wpUserId);
    }
    $author_class = is_author($wpUserId) ? ' current-author' : '';
    $avatar = "<img alt='" . esc_attr($alt) . "' src='" . esc_url($avatar) . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
    return $avatar;
}
 protected function _load_user($user = null)
 {
     if (is_user_logged_in() && !$user) {
         $this->user = wp_get_current_user();
     } else {
         if ($user instanceof WP_User) {
             $this->user = $user;
         } else {
             if (is_integer($user)) {
                 $this->user = get_user_by('id', $user);
             } else {
                 if (is_string($user) && is_email($user)) {
                     $this->user = get_user_by('email', $user);
                 } else {
                     if (is_string($user)) {
                         $this->user = get_user_by('login', $user);
                     }
                 }
             }
         }
     }
     if (!$this->user) {
         $message = __('User not found.', 'crb');
         throw new Exception($message);
     }
     return $this;
 }
Example #5
0
 /**
  * Grant super-admin privileges to one or more users.
  *
  * <user>...
  * : One or more user IDs, user emails, or user logins.
  */
 public function add($args, $_)
 {
     $users = $this->fetcher->get_many($args);
     $user_logins = wp_list_pluck($users, 'user_login');
     $super_admins = self::get_admins();
     $num_super_admins = count($super_admins);
     foreach ($user_logins as $user_login) {
         $user = get_user_by('login', $user_login);
         if (!$user) {
             WP_CLI::warning("Couldn't find {$user_login} user.");
             continue;
         }
         if (in_array($user->user_login, $super_admins)) {
             WP_CLI::warning("User {$user_login} already has super-admin capabilities.");
             continue;
         }
         $super_admins[] = $user->user_login;
     }
     if ($num_super_admins === count($super_admins)) {
         WP_CLI::log('No changes.');
     } else {
         if (update_site_option('site_admins', $super_admins)) {
             WP_CLI::success('Granted super-admin capabilities.');
         } else {
             WP_CLI::error('Site options update failed!');
         }
     }
 }
 /**
  * trigger function.
  *
  * @access public
  * @return void
  */
 function trigger($comment, $message)
 {
     global $woothemes_sensei, $sensei_email_data;
     $this->comment = $comment;
     $this->message = $message;
     $this->commenter = get_userdata($comment->user_id);
     $original_sender = get_post_meta($this->message->ID, '_sender', true);
     $this->original_sender = get_user_by('login', $original_sender);
     $original_receiver = get_post_meta($this->message->ID, '_receiver', true);
     $this->original_receiver = get_user_by('login', $original_receiver);
     $content_type = get_post_meta($this->message->ID, '_posttype', true);
     $content_id = get_post_meta($this->message->ID, '_post', true);
     $content_title = get_the_title($content_id);
     $comment_link = get_comment_link($comment);
     // Construct data array
     $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'commenter_name' => $this->commenter->display_name, 'message' => $this->comment->comment_content, 'comment_link' => $comment_link, 'content_title' => $content_title, 'content_type' => $content_type), $this->template);
     // Set recipient
     if ($this->commenter->user_login == $original_sender) {
         $this->recipient = stripslashes($this->original_receiver->user_email);
     } else {
         $this->recipient = stripslashes($this->original_sender->user_email);
     }
     // Send mail
     $woothemes_sensei->emails->send($this->recipient, $this->subject, $woothemes_sensei->emails->get_content($this->template));
 }
/**
Plugin Name: SSO
Author: Garth Mortensen, Mike Hansen
Version: 0.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
function sso_check()
{
    if (!isset($_GET['salt']) || !isset($_GET['nonce']) || !isset($_GET['user'])) {
        sso_req_login();
    }
    if (sso_check_blocked()) {
        sso_req_login();
    }
    $nonce = esc_attr($_GET['nonce']);
    $salt = esc_attr($_GET['salt']);
    $user = esc_attr($_GET['user']);
    $hash = base64_encode(hash('sha256', $nonce . $salt, false));
    $hash = substr($hash, 0, 64);
    if (get_transient('sso_token') == $hash) {
        if (is_email($user)) {
            $user = get_user_by('email', $user);
        } else {
            $user = get_user_by('id', (int) $user);
        }
        if (is_a($user, 'WP_User')) {
            wp_set_current_user($user->ID, $user->user_login);
            wp_set_auth_cookie($user->ID);
            do_action('wp_login', $user->user_login);
            delete_transient('sso_token');
            wp_safe_redirect(admin_url());
        } else {
            sso_req_login();
        }
    } else {
        sso_add_failed_attempt();
        sso_req_login();
    }
    die;
}
/**
 * Process Login Form
 *
 * @since 1.0
 * @param array $data Data sent from the login form
 * @return void
*/
function edd_process_login_form($data)
{
    if (wp_verify_nonce($data['edd_login_nonce'], 'edd-login-nonce')) {
        $user_data = get_user_by('login', $data['edd_user_login']);
        if (!$user_data) {
            $user_data = get_user_by('email', $data['edd_user_login']);
        }
        if ($user_data) {
            $user_ID = $user_data->ID;
            $user_email = $user_data->user_email;
            if (wp_check_password($data['edd_user_pass'], $user_data->user_pass, $user_data->ID)) {
                edd_log_user_in($user_data->ID, $data['edd_user_login'], $data['edd_user_pass']);
            } else {
                edd_set_error('password_incorrect', __('The password you entered is incorrect', 'edd'));
            }
        } else {
            edd_set_error('username_incorrect', __('The username you entered does not exist', 'edd'));
        }
        // Check for errors and redirect if none present
        $errors = edd_get_errors();
        if (!$errors) {
            $redirect = apply_filters('edd_login_redirect', $data['edd_redirect'], $user_ID);
            wp_redirect($redirect);
            edd_die();
        }
    }
}
 public function do_affiliates($step = 1)
 {
     global $wpdb;
     $offset = ($step - 1) * 100;
     $affiliates = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}affiliates_tbl LIMIT {$offset}, 100;");
     $to_delete = array();
     if ($affiliates) {
         foreach ($affiliates as $affiliate) {
             if (empty($affiliate->email)) {
                 continue;
             }
             $user = get_user_by('email', $affiliate->email);
             if (is_wp_error($user) || !$user) {
                 $user_id = wp_insert_user(array('user_email' => $affiliate->email, 'first_name' => $affiliate->firstname, 'last_name' => $affiliate->lastname, 'user_url' => $affiliate->website, 'user_pass' => '', 'user_login' => $affiliate->email));
             } else {
                 $user_id = $user->ID;
             }
             $payment_email = !empty($affiliate->paypalemail) ? $affiliate->paypalemail : $affiliate->email;
             $status = 'approved' == $affiliate->account_status ? 'active' : 'pending';
             $args = array('date_registered' => date('Y-n-d H:i:s', strtotime($affiliate->date)), 'user_id' => $user_id, 'payment_email' => $payment_email, 'rate' => $affiliate->commissionlevel, 'status' => $status);
             // Try to get an existing affiliate based on the user_id
             $existing_affiliate = affiliate_wp()->affiliates->get_by('user_id', $user_id);
             if ($existing_affiliate) {
                 continue;
             }
             // Insert a new affiliate - we need to always insert to make sure the affiliate_ids will match
             $id = affiliate_wp()->affiliates->insert($args, 'affiliate');
         }
         return true;
     } else {
         // No affiliates found, so all done
         return false;
     }
 }
Example #10
0
 function activate($blog_id, $user_id, $domain, $path)
 {
     // mlog("FUNCTION: activate [$blog_id, $user_id, $domain, $path]");
     $this->log("activate: {$blog_id}, {$user_id}, {$domain}, {$path}");
     $email = '';
     if ($user_id) {
         $user = get_user_by('id', $user_id);
         $email = $user ? $user->user_email : 'unknown';
     }
     $sk_subscription_id = get_option("sk_subscription_id");
     $sk_selected_library = get_option("sk_selected_library");
     if (isset($sk_selected_library) && $sk_selected_library && $sk_selected_library !== -1 && $sk_selected_library !== '-1') {
         $data = array('domainName' => $domain . '/' . $path, 'productId' => $sk_selected_library);
     } elseif (isset($sk_subscription_id) && intval($sk_subscription_id)) {
         $data = array('domainName' => $domain . '/' . $path, 'subscriptionId' => $sk_subscription_id);
     } else {
         update_option('sk_auto_activation_error', "No selected library or subscriptionId set");
         return false;
     }
     $result = $this->send_request('post', '/domains', $data);
     if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
         $this->log("activate: success");
         $this->activationSuccessful($result, $blog_id, $email);
     } else {
         $this->log("activate: error");
         $this->activationError($result);
     }
     return $result;
 }
 public function checkUserExistance($resp = false)
 {
     $response = $resp;
     if ($resp == false) {
         $response = $_POST['fbResponse'];
     }
     $email = $response['email'];
     $user = get_user_by('email', $email);
     if ($user != false) {
         //IF USER EXISTS PREPARE FOR LOGIN
         $user_id = $user->ID;
         if ($user_id > 0) {
             wp_set_auth_cookie($user_id);
             wp_set_current_user($user_id);
             echo json_encode(array('result' => 'loggedIn', 'user_id' => $user_id));
             die;
         } else {
             echo "User created with 0 id";
         }
     } else {
         $new_user = $this->create_user($response);
         if (is_wp_error($new_user)) {
             echo $new_user->get_error_message();
         } else {
             $this->checkUserExistance($response);
         }
     }
 }
 /**
  * Handles actions on candidate dashboard
  */
 public function lost_licence_key_form_handler()
 {
     if (!empty($_REQUEST['submit_lost_licence_form'])) {
         $activation_email = sanitize_text_field($_REQUEST['activation_email']);
         if (!is_email($activation_email)) {
             wc_add_notice(__('Invalid email address.'), 'error');
             return;
         }
         $keys = wppl_get_licences_from_activation_email($activation_email);
         if (!$keys) {
             wc_add_notice(__('No licences found.'), 'error');
         } else {
             ob_start();
             // Try to get a user name
             $user = get_user_by('email', $activation_email);
             if ($user && !empty($user->first_name)) {
                 $user_first_name = $user->first_name;
             } else {
                 $user_first_name = false;
             }
             wc_get_template('lost-licence-email.php', array('keys' => $keys, 'activation_email' => $activation_email, 'blogname' => get_option('blogname'), 'user_first_name' => $user_first_name), 'wp-plugin-licencing', WP_PLUGIN_LICENCING_PLUGIN_DIR . '/templates/');
             // Get contents
             $message = ob_get_clean();
             if (wp_mail($activation_email, __('Your licence keys for WP Job Manager', 'wp-plugin-licencing'), $message)) {
                 wc_add_notice(sprintf(__('Your licences have been emailed to %s.'), $activation_email), 'success');
             } else {
                 wc_add_notice(__('Your licences could not be sent. Please contact us for support.'), 'error');
             }
         }
     }
 }
Example #13
0
/**
 * Find duplicates according to settings
 */
function pmxi_findDuplicates($articleData, $custom_duplicate_name = '', $custom_duplicate_value = '', $duplicate_indicator = 'title')
{
    global $wpdb;
    if ('custom field' == $duplicate_indicator) {
        $duplicate_ids = array();
        if (!empty($articleData['post_type'])) {
            $post_types = (class_exists('PMWI_Plugin') and $articleData['post_type'] == 'product') ? array('product', 'product_variation') : array($articleData['post_type']);
            $args = array('post_type' => $post_types, 'post_status' => array('any'), 'meta_query' => array(array('key' => trim($custom_duplicate_name), 'value' => htmlspecialchars(trim($custom_duplicate_value)))), 'order' => 'ASC', 'orderby' => 'ID');
            $query = new WP_Query($args);
            if ($query->have_posts()) {
                $duplicate_ids[] = $query->post->ID;
            }
            wp_reset_postdata();
            if (empty($duplicate_ids)) {
                $query = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON (" . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id) WHERE 1=1 AND " . $wpdb->posts . ".post_type IN ('" . implode("','", $post_types) . "') AND (" . $wpdb->posts . ".post_status = 'publish' OR " . $wpdb->posts . ".post_status = 'future' OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'trash' OR " . $wpdb->posts . ".post_status = 'private') AND ( (" . $wpdb->postmeta . ".meta_key = '%s' AND CAST(" . $wpdb->postmeta . ".meta_value AS CHAR) = '%s') ) GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC LIMIT 0, 20", trim($custom_duplicate_name), htmlspecialchars(trim($custom_duplicate_value))));
                if (!empty($query)) {
                    foreach ($query as $p) {
                        $duplicate_ids[] = $p->ID;
                    }
                }
            }
        } else {
            $args = array('meta_query' => array(0 => array('key' => $custom_duplicate_name, 'value' => $custom_duplicate_value, 'compare' => '=')));
            $user_query = new WP_User_Query($args);
            if (!empty($user_query->results)) {
                foreach ($user_query->results as $user) {
                    $duplicate_ids[] = $user->ID;
                }
            } else {
                $query = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS " . $wpdb->users . ".ID FROM " . $wpdb->users . " INNER JOIN " . $wpdb->usermeta . " ON (" . $wpdb->users . ".ID = " . $wpdb->usermeta . ".user_id) WHERE 1=1 AND ( (" . $wpdb->usermeta . ".meta_key = '%s' AND CAST(" . $wpdb->usermeta . ".meta_value AS CHAR) = '%s') ) GROUP BY " . $wpdb->users . ".ID ORDER BY " . $wpdb->users . ".ID ASC LIMIT 0, 20", $custom_duplicate_name, $custom_duplicate_value));
                if (!empty($query)) {
                    foreach ($query as $p) {
                        $duplicate_ids[] = $p->ID;
                    }
                }
            }
        }
        return $duplicate_ids;
    } elseif ('parent' == $duplicate_indicator) {
        $field = 'post_title';
        // post_title or post_content
        return $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT ID FROM " . $wpdb->posts . "\n\t\t\tWHERE\n\t\t\t\tpost_type = %s\n\t\t\t\tAND ID != %s\n\t\t\t\tAND post_parent = %s\n\t\t\t\tAND REPLACE(REPLACE(REPLACE({$field}, ' ', ''), '\\t', ''), '\\n', '') = %s\n\t\t\t", $articleData['post_type'], isset($articleData['ID']) ? $articleData['ID'] : 0, !empty($articleData['post_parent']) ? $articleData['post_parent'] : 0, preg_replace('%[ \\t\\n]%', '', $articleData[$field])));
    } else {
        if (!empty($articleData['post_type'])) {
            $field = 'post_' . $duplicate_indicator;
            // post_title or post_content
            return $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT ID FROM " . $wpdb->posts . "\n\t\t\t\tWHERE\n\t\t\t\t\tpost_type = %s\n\t\t\t\t\tAND ID != %s\n\t\t\t\t\tAND REPLACE(REPLACE(REPLACE({$field}, ' ', ''), '\\t', ''), '\\n', '') = %s\n\t\t\t\t", $articleData['post_type'], isset($articleData['ID']) ? $articleData['ID'] : 0, preg_replace('%[ \\t\\n]%', '', $articleData[$field])));
        } else {
            if ($duplicate_indicator == 'title') {
                $field = 'user_login';
                $u = get_user_by('login', $articleData[$field]);
                return !empty($u) ? array($u->ID) : false;
            } else {
                $field = 'user_email';
                $u = get_user_by('email', $articleData[$field]);
                return !empty($u) ? array($u->ID) : false;
            }
        }
    }
}
Example #14
0
 /**
  * Returns a wp user object containg user's data.
  * The user is retrieved based on the current permalink structure.
  * This function is currently used only through the wpum_profile shortcode.
  * If no data is set, returns currently logged in user data.
  *
  * @since 1.0.0
  * @access public
  * @return object
  */
 function wpum_get_user_by_data()
 {
     $user_data = null;
     $permalink_structure = get_option('wpum_permalink', 'user_id');
     $who = get_query_var('user') ? get_query_var('user') : null;
     // Checks we are on the profile page
     if (is_page(wpum_get_core_page_id('profile'))) {
         // Verify the user isset
         if ($who) {
             switch ($permalink_structure) {
                 case 'user_id':
                     $user_data = get_user_by('id', intval(get_query_var('user')));
                     break;
                 case 'username':
                     $user_data = get_user_by('login', esc_attr(get_query_var('user')));
                     break;
                 case 'nickname':
                     // WP_User_Query arguments
                     $args = array('search' => esc_attr(get_query_var('user')), 'search_columns' => array('user_nicename'));
                     // The User Query
                     $user_query = new WP_User_Query($args);
                     $user_query = $user_query->get_results();
                     $user_data = $user_query[0];
                     break;
                 default:
                     $user_data = apply_filters("wpum_get_user_by_data", $permalink_structure, $who);
                     break;
             }
         } else {
             $user_data = get_user_by('id', get_current_user_id());
         }
     }
     return $user_data;
 }
function um_get_avatar($avatar = '', $id_or_email = '', $size = '96', $avatar_class = '', $default = '', $alt = '')
{
    if (is_numeric($id_or_email)) {
        $user_id = (int) $id_or_email;
    } elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) {
        $user_id = $user->ID;
    } elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) {
        $user_id = (int) $id_or_email->user_id;
    }
    if (empty($user_id)) {
        return $avatar;
    }
    um_fetch_user($user_id);
    $avatar = um_user('profile_photo', $size);
    if (!um_profile('profile_photo') && um_get_option('use_gravatars')) {
        if (is_ssl()) {
            $protocol = 'https://';
        } else {
            $protocol = 'http://';
        }
        $default = get_option('avatar_default', 'mystery');
        if ($default == 'gravatar_default') {
            $default = '';
        }
        $rating = get_option('avatar_rating');
        if (!empty($rating)) {
            $rating = "&amp;r={$rating}";
        }
        $avatar = '<img src="' . $protocol . 'gravatar.com/avatar/' . md5(um_user('user_email')) . '?d=' . $default . '&amp;s=' . $size . $rating . '" class="gravatar avatar avatar-' . $size . ' um-avatar" width="' . $size . '" height="' . $size . '" alt="" />';
    }
    return $avatar;
}
 /**
  * Filter the user to authenticate.
  *
  * @since 0.1-dev
  *
  * @access public
  * @static
  *
  * @param WP_User $input_user User to authenticate.
  * @param string  $username   User login.
  * @param string  $password   User password.
  */
 public static function authenticate($input_user, $username, $password)
 {
     $api_request = defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
     if (!apply_filters('application_password_is_api_request', $api_request)) {
         return $input_user;
     }
     $user = get_user_by('login', $username);
     // If the login name is invalid, short circuit.
     if (!$user) {
         return $input_user;
     }
     /*
      * Strip out anything non-alphanumeric. This is so passwords can be used with
      * or without spaces to indicate the groupings for readability.
      */
     $password = preg_replace('/[^a-z\\d]/i', '', $password);
     $hashed_passwords = get_user_meta($user->ID, self::USERMETA_KEY_APPLICATION_PASSWORDS, true);
     foreach ($hashed_passwords as $key => $item) {
         if (wp_check_password($password, $item['password'], $user->ID)) {
             $item['last_used'] = time();
             $item['last_ip'] = $_SERVER['REMOTE_ADDR'];
             $hashed_passwords[$key] = $item;
             update_user_meta($user->ID, self::USERMETA_KEY_APPLICATION_PASSWORDS, $hashed_passwords);
             return $user;
         }
     }
     // By default, return what we've been passed.
     return $input_user;
 }
Example #17
0
 /**
  * load data needed for board's javascript
  * @param  string $template the passed in template path
  * @return string           the same template path
  */
 static function send_page_data_to_template($template)
 {
     if (!isset(Kanban_Template::get_instance()->slug) || Kanban_Template::get_instance()->slug != self::$slug) {
         return $template;
     }
     global $wp_query;
     $wp_query->query_vars['kanban'] = (object) array();
     $wp_query->query_vars['kanban']->board = (object) array();
     // // get all data for the javascript
     $wp_query->query_vars['kanban']->board->allowed_users = Kanban_User::get_allowed_users();
     $wp_query->query_vars['kanban']->board->estimates = Kanban_Terms::terms_in_order('task', 'estimate');
     $wp_query->query_vars['kanban']->board->status_tax_key = Kanban_Utils::format_key('task', 'status');
     $wp_query->query_vars['kanban']->board->status_color_field_name = sprintf('%s_colors', $wp_query->query_vars['kanban']->board->status_tax_key);
     $wp_query->query_vars['kanban']->board->status_colors = Kanban_Settings::get_option($wp_query->query_vars['kanban']->board->status_color_field_name, null, array());
     $wp_query->query_vars['kanban']->board->statuses = Kanban_Terms::terms_in_order('task', 'status');
     foreach ($wp_query->query_vars['kanban']->board->statuses as $status) {
         if (!isset($wp_query->query_vars['kanban']->board->status_colors[$status->term_id])) {
             continue;
         }
         $status->color = $wp_query->query_vars['kanban']->board->status_colors[$status->term_id];
     }
     $wp_query->query_vars['kanban']->board->projects = Kanban_Project::get_all();
     $wp_query->query_vars['kanban']->board->tasks = Kanban_Task::get_all();
     $current_user_id = get_current_user_id();
     $wp_query->query_vars['kanban']->board->current_user = get_user_by('id', $current_user_id);
     unset($wp_query->query_vars['kanban']->board->current_user->data->user_pass);
     $wp_query->query_vars['kanban']->board->current_user->data->long_name_email = Kanban_User::format_user_name($wp_query->query_vars['kanban']->board->current_user);
     $wp_query->query_vars['kanban']->board->current_user->data->short_name = Kanban_User::format_user_name($wp_query->query_vars['kanban']->board->current_user, TRUE);
     $wp_query->query_vars['kanban']->board->current_user->data->initials = Kanban_User::get_initials($wp_query->query_vars['kanban']->board->current_user);
     $wp_query->query_vars['kanban']->board->col_percent_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / count($wp_query->query_vars['kanban']->board->statuses) : 100;
     $wp_query->query_vars['kanban']->board->sidebar_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / (count($wp_query->query_vars['kanban']->board->statuses) - 2) : 0;
     return $template;
 }
 public function send_friend_request()
 {
     global $wpdb, $xoouserultra;
     require_once ABSPATH . 'wp-includes/formatting.php';
     $logged_user_id = get_current_user_id();
     $receiver_id = $_POST["user_id"];
     $sender = get_user_by('id', $logged_user_id);
     $sender_id = $sender->ID;
     $receiver = get_user_by('id', $receiver_id);
     //store in the db
     if ($this->check_if_sent($receiver_id)) {
         if (isset($logged_user_id) && $logged_user_id > 0) {
             if ($logged_user_id == $receiver_id) {
                 echo __(" You can't be your own friend. ", 'xoousers');
             } else {
                 $data = array('friend_id' => NULL, 'friend_receiver_id' => $receiver_id, 'friend_sender_user_id' => $sender_id, 'friend_status' => '0', 'friend_date' => date('Y-m-d H:i:s'));
                 // insert into database
                 $wpdb->insert($wpdb->prefix . 'usersultra_friends', $data, array('%d', '%s', '%s', '%s', '%s'));
                 $xoouserultra->messaging->send_friend_request($receiver, $sender);
                 echo __(" Friend Request Sent ", 'xoousers');
             }
         } else {
             echo __("You have to be logged in to send a friend request ", 'xoousers');
         }
     } else {
         echo __("Request Already Sent", 'xoousers');
     }
     die;
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function getByEmail($email)
 {
     if ($user = get_user_by('email', $email)) {
         return $this->_convertToEntity($user);
     }
     return null;
 }
Example #20
0
 public function ajax_edit_balance($user_id, $action)
 {
     $user = get_user_by('id', $user_id);
     if (is_null($user)) {
         $message = __("The specified User doesn't exists.", 'AWPCP');
         $response = array('status' => 'error', 'message' => $message);
     }
     if (isset($_POST['save'])) {
         $payments = awpcp_payments_api();
         $amount = (int) awpcp_post_param('amount', 0);
         if ($action == 'debit') {
             $payments->remove_credit($user->ID, $amount);
         } else {
             $payments->add_credit($user->ID, $amount);
         }
         $balance = $payments->format_account_balance($user->ID);
         $response = array('status' => 'success', 'balance' => $balance);
     } else {
         // load the table so the get_columns methods is properly called
         // when attempt to find out the number of columns in the table
         $table = $this->get_table();
         $columns = $_POST['columns'];
         ob_start();
         include AWPCP_DIR . '/admin/templates/admin-panel-users-balance-form.tpl.php';
         $html = ob_get_contents();
         ob_end_clean();
         $response = array('html' => $html);
     }
     return $response;
 }
Example #21
0
 private function load($ID)
 {
     $this->ID = $ID;
     // get everything in one place.
     // it is never stored
     $this->data = get_user_by('id', $ID);
     $data = get_user_meta($ID, $this->name, TRUE);
     if (!$data) {
         // no object
         $this->valid = FALSE;
         return $this;
     }
     $this->valid = TRUE;
     foreach ($data as $key => $value) {
         $this->{$key} = $value;
     }
     /**
     DO NOT LOAD API EXPOSED FIELDS
     FROM THE USER META
     AS THEY WILL BE SYNCED BACK IN VIA API_SAVE()!
     */
     // http://codex.wordpress.org/Plugin_API/Filter_Reference/show_admin_bar
     if ($this->hide_admin_bar) {
         add_filter('show_admin_bar', '__return_false');
     }
     do_action('ym_user_is_loaded');
     return $this;
 }
Example #22
0
 public function send_email_confirm()
 {
     global $wpdb;
     $datas = array($_POST["users"], $_POST["id"]);
     $res = $wpdb->get_results("select * from cjm_mail where id=" . $_POST["id"] . ";");
     $title = stripslashes($res[0]->title);
     $content = stripslashes($res[0]->content);
     foreach ($_POST["users"] as $key => $value) {
         $infos = explode("&", $value);
         $user = get_user_by("login", $infos[0]);
         $user_id = $user->ID;
         $user_infos = $wpdb->get_results("select nbplace,nbplace_enf,prix_total from cjm_reservation where id_participant={$user_id} and id_evenement={$infos['1']}");
         $tarif_adulte = get_post_meta($infos[1], "_tarif_adulte", true);
         $tarif_enf = get_post_meta($infos[1], "_tarif_enfant", true);
         $tarif_adh = get_post_meta($infos[1], "_tarif_adherent", true);
         $event_name = get_post_meta($infos[1], "_nom_voyage", true);
         $title = str_replace("%prix_total%", $user_infos[0]->prix_total, $title);
         $content = str_replace("%prix_total%", $user_infos[0]->prix_total, $content);
         $content = str_replace("%USERNAME%", $user->display_name, $content);
         $content = str_replace("%evenement%", $event_name, $content);
         $content = str_replace("%nbplace_enf%", $user_infos[0]->nbplace_enf, $content);
         $content = str_replace("%nbplace%", $user_infos[0]->nbplace, $content);
         $content = str_replace("%prix_place%", $tarif_adulte, $content);
         $content = str_replace("%prix_place_enf%", $tarif_enf, $content);
         $content = str_replace("%prix_place_adh%", $tarif_adh, $content);
         $content = str_replace("%lien%", get_site_url() . "/?p=" . $infos[1], $content);
         $isSent = wp_mail($infos[0], $title, $content);
     }
     if ($isSent) {
         $last_query = $wpdb->update('cjm_reservation', array("mail_confirm" => 1), array("id_evenement" => $infos[1], "id_participant" => $user_id), array("%d"), array("%d", "%d"));
     }
     echo json_encode($last_query);
     // echo json_encode(array($last_query,$datas));
     // echo json_encode("test");
 }
/**
 * Set basic settings on the activation of the plugin.
 * - Saved in 'options' table.
 * - Creating custom table for storing email addresses.
 * ------------------------------------------------------------------------------
 */
function nanodesigns_email_downloads_activate()
{
    /**
     * Creating a custom table.
     * @since 1.0.1
     * -----------
     */
    global $wpdb, $nano_db_version;
    $table = $wpdb->prefix . 'download_email';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") != $table) {
        $sql = "CREATE TABLE {$table} (\n                  id mediumint(9) NOT NULL AUTO_INCREMENT,\n                  email tinytext NOT NULL,\n                  UNIQUE KEY id (id)\n                );";
        //reference to upgrade.php file
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
    }
    //endif($wpdb->get_var
    update_option("nano_ed_db_version", $nano_db_version);
    /**
     * Add the necessary default settings to the 'options table'.
     * @since 1.0.0
     * -----------
     */
    $noreply_email = noreply_email();
    $admin_email = get_option('admin_email');
    $admin_user = get_user_by('email', $admin_email);
    $ed_settings = array('ed_sender_email' => $noreply_email, 'ed_sender_name' => $admin_user->display_name);
    update_option('email_downloads_settings', $ed_settings);
}
Example #24
0
function eFrontWPI_authenticate($user, $user_login, $password)
{
    //Do our basic error checking
    if (is_a($user, 'WP_User')) {
        return $user;
    }
    if (empty($user_login) || empty($password)) {
        $error = new WP_Error();
        if (empty($user_login)) {
            $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
        }
        if (empty($password)) {
            $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
        }
        return $error;
    }
    //Attempt Login
    $user = get_user_by('login', $user_login);
    if (!$user || strtolower($user->user_login) != strtolower($user_login)) {
        do_action('wp_login_failed', $user_login);
        return new WP_Error('invalid_username', __('<strong>eFrontWPI</strong>: Login failed, invalid username.'));
    } else {
        eFrontWPI_DoLogin($user, $user_login, $password);
    }
}
function rcl_confirm_user_registration()
{
    global $wpdb, $rcl_options;
    $reglogin = $_GET['rglogin'];
    $regpass = $_GET['rgpass'];
    $regcode = md5($reglogin);
    if ($regcode == $_GET['rgcode']) {
        if ($user = get_user_by('login', $reglogin)) {
            wp_update_user(array('ID' => $user->ID, 'role' => get_option('default_role')));
            $time_action = current_time('mysql');
            $action = $wpdb->get_var($wpdb->prepare("SELECT time_action FROM " . RCL_PREF . "user_action WHERE user = '******'", $user->ID));
            if (!$action) {
                $wpdb->insert(RCL_PREF . 'user_action', array('user' => $user->ID, 'time_action' => $time_action));
            }
            $creds = array();
            $creds['user_login'] = $reglogin;
            $creds['user_password'] = $regpass;
            $creds['remember'] = true;
            $sign = wp_signon($creds, false);
            if (!is_wp_error($sign)) {
                rcl_update_timeaction_user();
                do_action('rcl_confirm_registration', $user->ID);
                wp_redirect(rcl_get_authorize_url($user->ID));
                exit;
            }
        }
    }
    if ($rcl_options['login_form_recall'] == 2) {
        wp_safe_redirect('wp-login.php?checkemail=confirm');
    } else {
        wp_redirect(get_bloginfo('wpurl') . '?action-rcl=login&error=confirm');
    }
    exit;
}
Example #26
0
/**
 * Return the count of all customer orders through WC.
 *
 * If no $user_id is provided, or no orders exist for the given user and an
 * email address is provided, we can query the PayPal address to query previous orders
 * to cover guest checkout.
 *
 * @param int $user_id		Optional: The user ID to query.
 * @param str $email		Optional: The user email address.
 * 
 * @since	0.0.1
 * @return	int		Total number of orders from this customer.
 */
function wc_nod_get_customer_purchase_count($user_id = '', $email = '')
{
    if (empty($user_id) && empty($email)) {
        return false;
    }
    $orders = 0;
    // Retrieve the WP user
    if (!empty($user_id)) {
        $field = 'id';
    } elseif (is_email(trim($email))) {
        $field = 'email';
    }
    if (empty($field)) {
        return $orders;
    }
    $user = get_user_by($field, $user_id);
    // If we did not retrieve a user by ID and we have an email, try that.
    if (!$user && $field == 'id' && !empty($email)) {
        $user = get_user_by('email', trim($email));
    }
    if ($user) {
        $orders += nod_get_order_count_by('id', $user->ID);
    }
    // If an email is provided query orders by email
    if (!empty($email)) {
        $orders += nod_get_order_count_by('email', trim($email));
    }
    return $orders;
}
Example #27
0
function fa_avatar_hook($avatar, $id_or_email, $size, $default, $alt)
{
    $user = false;
    if (is_numeric($id_or_email)) {
        $id = (int) $id_or_email;
        $user = get_user_by('id', $id);
    } elseif (is_object($id_or_email)) {
        if (!empty($id_or_email->user_id)) {
            $id = (int) $id_or_email->user_id;
            $user = get_user_by('id', $id);
        }
    } else {
        $user = get_user_by('email', $id_or_email);
    }
    if ($user && is_object($user)) {
        if (get_user_meta($user->data->ID, 'weixin_avatar', true)) {
            $avatar = get_user_meta($user->data->ID, 'weixin_avatar', true);
            $avatar = str_replace('http', 'https', $avatar);
            $avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
        } else {
            if (get_user_meta($user->data->ID, 'sina_avatar', true)) {
                $avatar = get_user_meta($user->data->ID, 'sina_avatar', true);
                $avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
            }
        }
        //根据你的存储头像的key来写
    }
    return $avatar;
}
Example #28
0
/**
 * Process Login Form
 *
 * @since	1.0
 * @param	arr		$data	Data sent from the login form
 * @return void
 */
function kbs_process_login_form($data)
{
    if (wp_verify_nonce($data['kbs_login_nonce'], 'kbs-login-nonce')) {
        $user_data = get_user_by('login', $data['kbs_user_login']);
        if (!$user_data) {
            $user_data = get_user_by('email', $data['kbs_user_login']);
        }
        if ($user_data) {
            $user_ID = $user_data->ID;
            $user_email = $user_data->user_email;
            if (wp_check_password($data['kbs_user_pass'], $user_data->user_pass, $user_data->ID)) {
                kbs_log_user_in($user_data->ID, $data['kbs_user_login'], $data['kbs_user_pass']);
            } else {
                $message = 'password_incorrect';
            }
        } else {
            $message = 'username_incorrect';
        }
        if (!empty($message)) {
            $url = remove_query_arg('message');
            wp_redirect(add_query_arg('message', $message, $url));
            die;
        }
        $redirect = apply_filters('kbs_login_redirect', $data['kbs_redirect'], $user_ID);
        wp_redirect($redirect);
        die;
    }
}
 /**
  * @Given /^Users exist:$/
  */
 public function usersExist(TableNode $table)
 {
     $usersData = $table->getHash();
     add_filter('send_password_change_email', '__return_false');
     add_filter('send_email_change_email', '__return_false');
     foreach ($usersData as $userData) {
         if (empty($userData['login'])) {
             throw new \InvalidArgumentException('You must provide a user login!');
         }
         $user = get_user_by('login', $userData['login']);
         $data = $this->getUserDataFromTable($userData);
         if ($user) {
             $data['ID'] = $user->ID;
         }
         $result = $user ? wp_update_user($data) : wp_insert_user($data);
         if (is_wp_error($result)) {
             throw new \UnexpectedValueException('User could not be created: ' . $result->get_error_message());
         }
         foreach ($this->getUserMetaDataFromTable($userData) as $key => $value) {
             update_user_meta($user->ID, $key, $value);
         }
     }
     remove_filter('send_password_change_email', '__return_false');
     remove_filter('send_email_change_email', '__return_false');
 }
Example #30
0
 public function load_access_data_for_user($user)
 {
     if (is_object($user)) {
         $id = $user->ID;
     } else {
         if (is_int($user)) {
             $id = $user;
             $user = get_user_by('id', $user);
         } else {
             $user = get_user_by('login', $user);
             $id = $user->ID;
         }
     }
     $blocked = get_user_meta($user->ID, self::ACCESS_DATA_KEY, true);
     if (!is_array($blocked)) {
         $blocked = array();
     }
     $access_data = get_option(self::ACCESS_DATA_KEY);
     if (empty($access_data)) {
         $access_data = array();
     }
     foreach ($user->roles as $role) {
         if (isset($access_data[$role])) {
             $blocked = array_merge($blocked, $access_data[$role]);
         }
     }
     $blocked = array_unique($blocked);
     return $blocked;
 }