예제 #1
0
파일: user.php 프로젝트: jao/jpcamargo
function wp_authenticate_username_password($user, $username, $password)
{
    if (is_a($user, 'WP_User')) {
        return $user;
    }
    if (empty($username) || empty($password)) {
        $error = new WP_Error();
        if (empty($username)) {
            $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;
    }
    $userdata = get_userdatabylogin($username);
    if (!$userdata) {
        return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));
    }
    $userdata = apply_filters('wp_authenticate_user', $userdata, $password);
    if (is_wp_error($userdata)) {
        return $userdata;
    }
    if (!wp_check_password($password, $userdata->user_pass, $userdata->ID)) {
        return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: Incorrect password. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));
    }
    $user = new WP_User($userdata->ID);
    return $user;
}
function registrar_usuario($parametros)
{
    $errors = new WP_Error();
    if ($parametros['email'] == NULL) {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.'));
        return $errors;
    }
    if (!es_email($parametros['email'])) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
        return $errors;
    }
    if (email_exists($parametros['email'])) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
        return $errors;
    }
    if ($parametros['nombre'] == NULL) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.'));
        return $errors;
    }
    $user_pass = $parametros['clave'] == NULL ? wp_generate_password(12, false) : $parametros['clave'];
    $user_id = wp_create_user($parametros['email'], $user_pass, $parametros['email']);
    if (!$user_id) {
        $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
        return $errors;
    }
    update_user_option($user_id, 'default_password_nag', true, true);
    //Set up the Password change nag.
    wp_new_user_notification($user_id, $user_pass);
    // Actualización de tabla clientes...
    return $user_id;
}
예제 #3
0
 function __toString()
 {
     // if the playlist are saved to db, i load it from db
     $playlist = $this->wpdb->get_row("SELECT ID, url, playlist FROM " . $this->table_name . " WHERE url = '" . $this->url . "'");
     if ($this->wpdb->num_rows > 0) {
         $playlist = unserialize($playlist->playlist);
     } else {
         $playlist = array();
         $code = implode("", file($this->url));
         if ($code == "") {
             $this->errors->add('no_content', __('The url $url are not valid!'));
         }
         preg_match_all("/section-row-track(.+)/", $code, $results);
         for ($i = 0; $i < sizeof($results[0]); $i++) {
             preg_match("/class=\"tracklisttrackname mx-link\">(.+)<\\/a>/U", $results[0][$i], $match);
             $title = $match[1];
             preg_match("/class=\"tracklistartistname mx-link\">(.+)<\\/a>/U", $results[0][$i], $match);
             $artist = $match[1];
             if ($title != "" || $artist != "") {
                 $playlist[] = array("title" => $title, "artist" => $artist);
             }
         }
         $this->wpdb->show_errors();
         // save to db the playlist for this url
         $this->wpdb->insert($this->table_name, array("url" => $this->url, "playlist" => serialize($playlist)), array("%s", "%s"));
     }
     $code = "<h3>Playlist</h3><ul class='mixcloud-embed-playlist'>";
     for ($i = 0; $i < count($playlist); $i++) {
         $code .= "<li><span class='mixcloud-embed-position'>" . ($i + 1) . "</span>";
         $code .= "<span class='mixcloud-embed-artist'>" . $playlist[$i]["artist"] . "</span>";
         $code .= "<span class='mixcloud-embed-title'>" . $playlist[$i]["title"] . "</span></li>";
     }
     $code .= "</ul>";
     return $code;
 }
예제 #4
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);
    }
}
예제 #5
0
 function validate()
 {
     if (!isset($_POST['dokan_update_profile'])) {
         return false;
     }
     if (!wp_verify_nonce($_POST['_wpnonce'], 'dokan_settings_nonce')) {
         wp_die(__('Are you cheating?', 'dokan'));
     }
     $error = new WP_Error();
     $dokan_name = sanitize_text_field($_POST['dokan_store_name']);
     if (empty($dokan_name)) {
         $error->add('dokan_name', __('Dokan name required', 'dokan'));
     }
     if (isset($_POST['setting_category'])) {
         if (!is_array($_POST['setting_category']) || !count($_POST['setting_category'])) {
             $error->add('dokan_type', __('Dokan type required', 'dokan'));
         }
     }
     if (!empty($_POST['setting_paypal_email'])) {
         $email = filter_var($_POST['setting_paypal_email'], FILTER_VALIDATE_EMAIL);
         if (empty($email)) {
             $error->add('dokan_email', __('Invalid email', 'dokan'));
         }
     }
     if ($error->get_error_codes()) {
         return $error;
     }
     return true;
 }
예제 #6
0
 function WPPHPBBU_SettingsPage()
 {
     do_action('wpphpbbu_before_admin_settings');
     if (isset($_POST['action']) && $_POST['action'] == 'update') {
         $e = new WP_Error();
         if (!wp_verify_nonce($_POST['_wpnonce'], 'wpphpbbu_settings_page')) {
             $e->add('access_denied', __('You submition does not meet the WordPress security level.', 'wpphpbbu'));
         } else {
             $wpphpbbu_path = stripslashes($_POST['wpphpbbu_path']);
             $wpphpbbu_url = stripslashes($_POST['wpphpbbu_url']);
             $wpphpbbu_post_posts = isset($_POST['wpphpbbu_post_posts']) ? 'yes' : 'no';
             $wpphpbbu_post_locked = isset($_POST['wpphpbbu_post_locked']) ? 'yes' : 'no';
             update_option('wpphpbbu_path', $wpphpbbu_path);
             $is_path = wpphpbbu\Path::is_path_ok();
             if (!$is_path) {
                 $e->add('file_not_exists', __('The file config.php does not exists in the path you have enter', 'wpphpbbu'));
             }
             update_option('wpphpbbu_path_ok', $is_path);
             update_option('wpphpbbu_url', $wpphpbbu_url);
             do_action('wpphpbbu_changed');
             update_option('wpphpbbu_post_posts', $wpphpbbu_post_posts);
             update_option('wpphpbbu_post_locked', $wpphpbbu_post_locked);
         }
     }
     $wpphpbbu_path = trim(get_option('wpphpbbu_path', ABSPATH . 'phpbb3/config.php'));
     $wpphpbbu_url = trim(get_option('wpphpbbu_url', ''));
     $wpphpbbu_post_posts = trim(get_option('wpphpbbu_post_posts', 'yes'));
     $wpphpbbu_post_locked = trim(get_option('wpphpbbu_post_locked', 'yes'));
     require_once __DIR__ . '/admin/settings.php';
     do_action('wpphpbbu_after_admin_settings');
 }
예제 #7
0
 public function checkPurchaseForm()
 {
     $errors = new \WP_Error();
     $title = __('Check Purchase Key', 'marketcheck');
     $purchaseKey = $this->getPurchaseKey();
     $selectedMarket = $this->getSelectedMarket();
     $isSubmited = $this->getPostVar('marketcheck-submitted');
     if ($isSubmited) {
         if (!$selectedMarket) {
             $errors->add('invalid-market', __('<strong>Error</strong>: Invalid Market Selected.', 'marketcheck'));
         }
         if (!$purchaseKey) {
             $errors->add('empty_purchase', __('<strong>Error</strong>: Empty Purchase Code.', 'marketcheck'));
         }
     }
     if ($isSubmited && $selectedMarket && $purchaseKey) {
         $this->getCurrentMarket()->setPurchaseKey($purchaseKey);
         $isValidPurchase = $this->getCurrentMarket()->isValidPurchase();
         if (is_wp_error($isValidPurchase)) {
             $errors = $isValidPurchase;
         } else {
             return;
         }
     }
     login_header($title, '<p class="message register">' . $title, $errors);
     $this->showPreRegisterForm();
     login_footer('purchase-key');
     die;
 }
예제 #8
0
파일: user.php 프로젝트: schr/wordpress
function wp_authenticate_username_password($user, $username, $password)
{
    if (is_a($user, 'WP_User')) {
        return $user;
    }
    if (empty($username) || empty($password)) {
        $error = new WP_Error();
        if (empty($username)) {
            $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;
    }
    $userdata = get_userdatabylogin($username);
    if (!$userdata || $userdata->user_login != $username) {
        return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Invalid username.'));
    }
    $userdata = apply_filters('wp_authenticate_user', $userdata, $password);
    if (is_wp_error($userdata)) {
        return $userdata;
    }
    if (!wp_check_password($password, $userdata->user_pass, $userdata->ID)) {
        return new WP_Error('incorrect_password', __('<strong>ERROR</strong>: Incorrect password.'));
    }
    $user = new WP_User($userdata->ID);
    return $user;
}
예제 #9
0
/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password()
{
    global $wpdb;
    $errors = new WP_Error();
    if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
    }
    if (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by_email(trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_userdatabylogin($login);
    }
    do_action('lostpassword_post');
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
        return $errors;
    }
    // redefining user_login ensures we return the right case in the email
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    do_action('retreive_password', $user_login);
    // Misspelled and deprecated
    do_action('retrieve_password', $user_login);
    $allow = apply_filters('allow_password_reset', true, $user_data->ID);
    if (!$allow) {
        return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
    } else {
        if (is_wp_error($allow)) {
            return $allow;
        }
    }
    $user_email = $_POST['user_email'];
    $user_login = $_POST['user_login'];
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_login = %s", $user_login));
    if (empty($user)) {
        return new WP_Error('invalid_key', __('Invalid key'));
    }
    $new_pass = wp_generate_password(12, false);
    do_action('password_reset', $user, $new_pass);
    wp_set_password($new_pass, $user->ID);
    update_usermeta($user->ID, 'default_password_nag', true);
    //Set up the Password change nag.
    $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
    $message .= site_url() . '/?ptype=affiliate' . "\r\n";
    $title = sprintf(__('[%s] Your new password'), get_option('blogname'));
    $title = apply_filters('password_reset_title', $title);
    $message = apply_filters('password_reset_message', $message, $new_pass);
    if ($message && !wp_mail($user_email, $title, $message)) {
        die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
    }
    return true;
}
예제 #10
0
function rcl_get_login_user()
{
    global $wp_errors;
    $pass = sanitize_text_field($_POST['user_pass']);
    $login = sanitize_user($_POST['user_login']);
    $member = isset($_POST['rememberme']) ? intval($_POST['rememberme']) : 0;
    $url = esc_url($_POST['redirect_to']);
    $wp_errors = new WP_Error();
    if (!$pass || !$login) {
        $wp_errors->add('rcl_login_empty', __('Fill in the required fields!', 'wp-recall'));
        return $wp_errors;
    }
    if ($user = get_user_by('login', $login)) {
        $user_data = get_userdata($user->ID);
        $roles = $user_data->roles;
        $role = array_shift($roles);
        if ($role == 'need-confirm') {
            $wp_errors->add('rcl_login_confirm', __('Your email is not confirmed!', 'wp-recall'));
            return $wp_errors;
        }
    }
    $creds = array();
    $creds['user_login'] = $login;
    $creds['user_password'] = $pass;
    $creds['remember'] = $member;
    $user = wp_signon($creds, false);
    if (is_wp_error($user)) {
        $wp_errors = $user;
        return $wp_errors;
    } else {
        rcl_update_timeaction_user();
        wp_redirect(rcl_get_authorize_url($user->ID));
        exit;
    }
}
예제 #11
0
function widget_retrieve_password()
{
    global $wpdb;
    $errors = new WP_Error();
    if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.', 'templatic'));
    }
    if (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by_email(trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.', 'templatic'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_userdatabylogin($login);
    }
    do_action('lostpassword_post');
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.', 'templatic'));
        return $errors;
    }
    // redefining user_login ensures we return the right case in the email
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    do_action('retreive_password', $user_login);
    // Misspelled and deprecated
    do_action('retrieve_password', $user_login);
    ////////////////////////////////////
    $user_email = $_POST['user_email'];
    $user_login = $_POST['user_login'];
    $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login like \"{$user_login}\" or user_email like \"{$user_login}\"");
    if (empty($user)) {
        return new WP_Error('invalid_key', __('Invalid key', 'templatic'));
    }
    $new_pass = wp_generate_password(12, false);
    do_action('password_reset', $user, $new_pass);
    wp_set_password($new_pass, $user->ID);
    update_usermeta($user->ID, 'default_password_nag', true);
    //Set up the Password change nag.
    $message = '<p><b>' . __('Your login Information :', 'templatic') . '</b></p>';
    $message .= '<p>' . sprintf(__('Username: %s', 'templatic'), $user->user_login) . "</p>";
    $message .= '<p>' . sprintf(__('Password: %s', 'templatic'), $new_pass) . "</p>";
    $message .= '<p>You can login to : <a href="' . get_option('siteurl') . '/' . "\">Login</a> or the URL is :  " . get_option('siteurl') . "/?ptype=login</p>";
    $message .= '<p>Thank You,<br> ' . get_option('blogname') . '</p>';
    $user_email = $user_data->user_email;
    $user_name = $user_data->user_nicename;
    $fromEmail = get_site_emailId();
    $fromEmailName = get_site_emailName();
    $title = sprintf(__('[%s] Your new password', 'templatic'), get_option('blogname'));
    $title = apply_filters('password_reset_title', $title);
    $message = apply_filters('password_reset_message', $message, $new_pass);
    templ_sendEmail($fromEmail, $fromEmailName, $user_email, $user_name, $title, $message, $extra = '');
    ///forgot password email
    return true;
}
예제 #12
0
function wp_signon($credentials = '')
{
    if (empty($credentials)) {
        if (!empty($_POST['log'])) {
            $credentials['user_login'] = $_POST['log'];
        }
        if (!empty($_POST['pwd'])) {
            $credentials['user_password'] = $_POST['pwd'];
        }
        if (!empty($_POST['rememberme'])) {
            $credentials['remember'] = $_POST['rememberme'];
        }
    }
    if (!empty($credentials['user_login'])) {
        $credentials['user_login'] = sanitize_user($credentials['user_login']);
    }
    if (!empty($credentials['user_password'])) {
        $credentials['user_password'] = trim($credentials['user_password']);
    }
    if (!empty($credentials['remember'])) {
        $credentials['remember'] = true;
    } else {
        $credentials['remember'] = false;
    }
    do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password']));
    // If no credential info provided, check cookie.
    if (empty($credentials['user_login']) && empty($credentials['user_password'])) {
        $user = wp_validate_auth_cookie();
        if ($user) {
            return new WP_User($user);
        }
        if (!empty($_COOKIE[AUTH_COOKIE])) {
            return new WP_Error('expired_session', __('Please log in again.'));
        }
        // If the cookie is not set, be silent.
        return new WP_Error();
    }
    if (empty($credentials['user_login']) || empty($credentials['user_password'])) {
        $error = new WP_Error();
        if (empty($credentials['user_login'])) {
            $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
        }
        if (empty($credentials['user_password'])) {
            $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
        }
        return $error;
    }
    $user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
    if (is_wp_error($user)) {
        return $user;
    }
    wp_set_auth_cookie($user->ID, $credentials['remember']);
    do_action('wp_login', $credentials['user_login']);
    return $user;
}
/**
 * Pre-handle AJAX Callbacks results to detect errors
 * 
 * Execute the callback and filter the result to prepare the AJAX
 * response. If errors are detected, return a WP_Error instance.
 * If no error, return the callback results.
 * 
 * @param    mixed    $callback Array containing Callback Class and Method or simple string for functions
 * @param    array    $args Array of arguments for callback
 * 
 * @return   array|WP_Error    Array of callback results if no error,
 *                             WP_Error instance if anything went wrong.
 */
function wpmoly_ajax_filter($callback, $args = array(), $loop = false)
{
    $loop = true === $loop ? true : false;
    $response = array();
    $errors = new WP_Error();
    // Simple function callback
    if (!is_array($callback) && function_exists(esc_attr($callback))) {
        // Loop through the arg
        if ($loop && is_array($args) && !empty($args)) {
            foreach ($args[0] as $arg) {
                $_response = call_user_func_array($callback, array($arg));
                if (is_wp_error($_response)) {
                    $errors->add($_response->get_error_code(), $_response->get_error_message());
                } else {
                    $response[] = $_response;
                }
            }
        } else {
            $_response = call_user_func_array($callback, $args);
            if (is_wp_error($_response)) {
                $errors->add($_response->get_error_code(), $_response->get_error_message());
            } else {
                $response[] = $_response;
            }
        }
    } else {
        if (is_array($callback) && 2 == count($callback) && class_exists($callback[0]) && method_exists($callback[0], $callback[1])) {
            // Loop through the arg
            if ($loop && is_array($args) && !empty($args)) {
                foreach ($args[0] as $arg) {
                    $_response = call_user_func_array(array($callback[0], $callback[1]), array($arg));
                    if (is_wp_error($_response)) {
                        $errors->add($_response->get_error_code(), $_response->get_error_message());
                    } else {
                        $response[] = $_response;
                    }
                }
            } else {
                $_response = call_user_func_array(array($callback[0], $callback[1]), $args);
                if (is_wp_error($_response)) {
                    $errors->add($_response->get_error_code(), $_response->get_error_message());
                } else {
                    $response[] = $_response;
                }
            }
        } else {
            $errors->add('callback_error', __('An error occured when trying to perform the request: invalid callback or data.', 'wpmovielibrary'));
        }
    }
    if (!empty($errors->errors)) {
        $response = $errors;
    }
    return $response;
}
예제 #14
0
/**
 * Deny password reset.
 *
 * @param bool $b
 * @param int $userid The ID of a user.
 * @return WP_Error.
 */
function xtec_settings_allow_password_reset($b, $userid)
{
    $user = get_user_by('id', $userid);
    if (strlen($user->user_login) < 9) {
        $error = new WP_Error('no_password_reset', "<strong>No és possible reinicialitzar la contrasenya.</strong>");
        $error->add('no_password_reset', "Si sou un usuari de la XTEC i heu perdut la vostra contrasenya podeu visitar <a href=\"http://www.xtec.cat/web/at_usuari/at_usuari\">l'enllaç següent</a>.");
        $error->add('no_password_reset', "En cas que no sigueu un usuari de la XTEC i hàgiu perdut la vostra contrasenya, us haureu de posar en contacte amb l'usuari que us va donar d'alta al servei de blocs.");
        return $error;
    } else {
        return true;
    }
}
예제 #15
0
/**
* Verify the code using the envato api
**/
function px_verify_purchase($code, $check = true)
{
    $errors = new WP_Error();
    if (empty($code)) {
        $errors->add('incomplete_form', '<strong>Error</strong>: Incomplete form fields.');
        return $errors;
    }
    $options = get_option('px_verifiy_settings');
    $personal_token = $options['px_verifiy_token'];
    if ($personal_token == false) {
        $errors->add('incomplete_settings', '<strong>Error</strong>: Please contact admin to setup the plugin settings.');
        return $errors;
    }
    $api_url = 'https://api.envato.com/v2/market/author/sale?code=' . $code;
    $verified = false;
    // check if purchase code already used
    if ($check) {
        global $wpdb;
        $query = $wpdb->prepare("SELECT umeta.user_id\n\t\t\tFROM {$wpdb->usermeta} as umeta\n\t\t\tWHERE umeta.meta_value LIKE '%%%s%%' ", $code);
        $registered = $wpdb->get_var($query);
        if ($registered) {
            $errors->add('used_purchase_code', 'Sorry, but that item purchase code has already been registered with another account. Please login to that account to continue, or create a new account with another purchase code.');
            return $errors;
        }
    }
    // Send request to envato to verify purchase
    $headers = array('Authorization' => 'Bearer ' . $personal_token);
    $response = wp_remote_get($api_url, array('headers' => $headers));
    $result = '';
    if (isset($response['body'])) {
        $result = json_decode($response['body'], true);
        if (isset($result['error']) && isset($result['response_code'])) {
            $errors->add('invalid_purchase_code', '<strong>Error ' . $result['response_code'] . '</strong>: ' . $result['error']);
            return $errors;
        } else {
            if (isset($result['error']) && isset($result['error_description'])) {
                $errors->add('invalid_purchase_code', '<strong>' . $result['error'] . '</strong>: ' . $result['error_description']);
                return $errors;
            } else {
                if (isset($result['error']) && isset($result['description'])) {
                    $errors->add('invalid_purchase_code', '<strong>' . $result['error'] . '</strong>: ' . $result['description']);
                    return $errors;
                } else {
                    $verify = array('px_envato_username' => $result['buyer'], 'px_envato_purchase_date' => $result['sold_at'], 'px_envato_purchase_code' => $code, 'px_envato_license' => $result['license'], 'px_envato_item' => $result['item']['name'], 'px_envato_support_amount' => $result['support_amount'], 'px_envato_support_until' => $result['supported_until']);
                    return $verify;
                }
            }
        }
    } else {
        $errors->add('invalid_api_response', '<strong>Invalid response from the API</strong>');
        return $errors;
    }
}
예제 #16
0
 public function registration($userdata)
 {
     $reg_errors = new WP_Error();
     if (!isset($userdata) && empty($userdata) && !is_array($userdata)) {
         $reg_errors->add('data_invalid', 'Chybí vstupní data');
         return $reg_errors;
     }
     $userLogin = array_key_exists('user_login', $userdata) ? sanitize_user($userdata['user_login']) : '';
     $userPass = array_key_exists('user_pass', $userdata) ? esc_attr($userdata['user_pass']) : '';
     $userEmail = array_key_exists('user_email', $userdata) ? sanitize_email($userdata['user_email']) : '';
     $userUrl = array_key_exists('user_url', $userdata) ? esc_url($userdata['user_url']) : '';
     $firstName = array_key_exists('first_name', $userdata) ? sanitize_text_field($userdata['first_name']) : '';
     $lastName = array_key_exists('last_name', $userdata) ? sanitize_text_field($userdata['last_name']) : '';
     $nickname = array_key_exists('nickname', $userdata) ? sanitize_text_field($userdata['nickname']) : '';
     $description = array_key_exists('description', $userdata) ? sanitize_text_field($userdata['description']) : '';
     if (empty($userLogin) || empty($userPass) || empty($userEmail)) {
         $reg_errors->add('field', 'Nejsou vyplnněny povinné pole formuláře.');
     }
     if (4 > strlen($userLogin)) {
         $reg_errors->add('username_length', 'Příliš krátké uživatelské jméno. Zadejte minimálně 5 znaků.');
     }
     if (username_exists($userLogin)) {
         $reg_errors->add('user_name', 'Je nám líto ale uživatelské jméno již existuje.');
     }
     if (!validate_username($userLogin)) {
         $reg_errors->add('username_invalid', 'Neplatné uživatelské jméno.');
     }
     if (5 > strlen($userPass)) {
         $reg_errors->add('password', 'Heslo musí obsahovat minimálně 6 znaků.');
     }
     if (!is_email($userEmail)) {
         $reg_errors->add('email_invalid', 'Zadaný e-mail je ve špatném formátu.');
     }
     if (email_exists($userEmail)) {
         $reg_errors->add('email', 'Zadaný e-mail již existuje.');
     }
     if (!empty($userUrl)) {
         if (!filter_var($userUrl, FILTER_VALIDATE_URL)) {
             $reg_errors->add('website', 'Url adresa Vašich stránek není validní.');
         }
     }
     if (is_wp_error($reg_errors) && count($reg_errors->errors) > 0) {
         return $reg_errors;
     }
     $_userdata = array('user_login' => $userLogin, 'user_email' => $userEmail, 'user_pass' => $userPass, 'user_url' => $userUrl, 'first_name' => $firstName, 'last_name' => $lastName, 'nickname' => $nickname, 'description' => $description, 'role' => 'customer');
     $user_id = wp_insert_user($_userdata);
     if (is_wp_error($user_id)) {
         $reg_errors->add('insert_user', 'Registraci nelze dokončit. Kontaktujte prosím správce webu.');
         return $reg_errors;
     }
     // Woocomerce data
     if (array_key_exists('billing_first_name', $userdata)) {
         add_user_meta($user_id, $meta_key, $meta_value, $unique);
     }
     $description = array_key_exists('description', $userdata) ? sanitize_text_field($userdata['description']) : '';
     return $user_id;
 }
예제 #17
0
 /**
  * Merge errors from another WP_Error object into the one dedicated to this model object.
  *
  * @param  \WP_Error  $otherErrors
  */
 protected function importErrors(\WP_Error $otherErrors)
 {
     foreach ($otherErrors->get_error_codes() as $code) {
         $errors = $otherErrors->get_error_messages($code);
         $data = $otherErrors->get_error_data($code);
         for ($i = 0; $i < max(count($errors), count($data)); $i++) {
             if (array_key_exists($i, $errors)) {
                 $data = array_key_exists($i, $data) ? $data[$i] : null;
                 $this->errors->add($code, $errors[$i], $data);
             }
         }
     }
 }
 private function compare()
 {
     if (version_compare($this->php, self::PHP, '<')) {
         $this->e->add('error', 'Dana Don Boom Boom Doo plugin cannot be activated.');
     }
     if (version_compare($this->wp, self::WP, '<')) {
         $this->e->add('error', 'Dana Don Boom Boom Doo plugin cannot be activated.');
     }
     if ($this->e->get_error_code()) {
         add_action('admin_init', [$this, 'error_message']);
         return false;
     }
     return true;
 }
 /**
  * @ticket 28092
  */
 function test_remove_error()
 {
     $error = new WP_Error();
     $error->add('foo', 'This is the first error message', 'some error data');
     $error->add('foo', 'This is the second error message');
     $error->add('bar', 'This is another error');
     $error->remove('foo');
     // Check the error has been removed.
     $this->assertEmpty($error->get_error_data('foo'));
     $this->assertEmpty($error->get_error_messages('foo'));
     // The 'bar' error should now be the 'first' error retrieved.
     $this->assertEquals('bar', $error->get_error_code());
     $this->assertEmpty($error->get_error_data());
 }
예제 #20
0
 public function isValidPurchase()
 {
     $parsedPurchase = $this->parsePurchase($this->retreiveApi());
     $errors = new \WP_Error();
     if (!$parsedPurchase) {
         $errors->add('invalid_purchase_key', __('<strong>Error</strong>: Invalid Purchase Key.', 'marketcheck'));
         return $errors;
     }
     if ($this->isUniqueLicense()) {
         return true;
     } else {
         $errors->add('purchase_key_already_used', __('<strong>Error</strong>: License is already used by another user.', 'marketcheck'));
         return $errors;
     }
 }
/**
 * Performs the reset password action
 *
 * @wp-hook	uf_reset_password
 * @return	void
 */
function uf_perform_reset_password()
{
    // get user
    $user = uf_check_password_reset_key($_POST['user_key'], $_POST['user_login']);
    // check for key
    if (is_wp_error($user)) {
        wp_safe_redirect(home_url('/user-reset-password/?message=invalid_key'));
        exit;
    }
    // check password
    $errors = new WP_Error();
    if (isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2']) {
        $errors->add('password_reset_mismatch', __('The passwords do not match.'));
    }
    // action for plugins
    do_action('validate_password_reset', $errors, $user);
    // set action
    if (!$errors->get_error_code() && isset($_POST['pass1']) && !empty($_POST['pass1'])) {
        uf_reset_password($user, $_POST['pass1']);
        wp_safe_redirect(home_url('/user-login/?message=password_resetted'));
        exit;
    } else {
        wp_safe_redirect(home_url('/user-reset-password/?message=validate_password_reset'));
        exit;
    }
}
예제 #22
0
파일: debug.php 프로젝트: kalushta/darom
/**
 * Prints warning about any hooked method with bad visibility (that are either protected or private)
 * @return void
 */
function appthemes_bad_method_visibility()
{
    global $wp_filter;
    $arguments = func_get_args();
    $tag = array_shift($arguments);
    $errors = new WP_Error();
    if (!isset($wp_filter[$tag])) {
        return;
    }
    foreach ($wp_filter[$tag] as $prioritized_callbacks) {
        foreach ($prioritized_callbacks as $callback) {
            $function = $callback['function'];
            if (is_array($function)) {
                try {
                    $method = new ReflectionMethod($function[0], $function[1]);
                    if ($method->isPrivate() || $method->isProtected()) {
                        $class = get_class($function[0]);
                        if (!$class) {
                            $class = $function[0];
                        }
                        $errors->add('visiblity', $class . '::' . $function[1] . ' was hooked into "' . $tag . '", but is either protected or private.');
                    }
                } catch (Exception $e) {
                    // Failure to replicate method. Might be magic method. Fail silently
                }
            }
        }
    }
    if ($errors->get_error_messages()) {
        foreach ($errors->get_error_messages() as $message) {
            echo $message;
        }
    }
}
예제 #23
0
 /**
  * Add error.
  *
  * Add a new error to the WP_Error object
  * and create the object if it doesn't exist yet.
  *
  * @since  3.3
  *
  * @param string $message Error message to add
  *
  * @return void
  */
 private function add_error($message)
 {
     if (!is_object($this->error) || !is_a($this->error, 'WP_Error')) {
         $this->error = new WP_Error();
     }
     $this->error->add('addon_error', $message);
 }
 /**
  * Should be a filter added to WordPress's "authenticate" filter, but before WordPress performs
  * it's own authentication (theirs is priority 30, so we could go in at around 20).
  *
  * @param null|WP_User|WP_Error $oUserOrError
  * @param string $sUsername
  * @return WP_User|WP_Error
  */
 public function checkLoginInterval($oUserOrError, $sUsername)
 {
     // No login attempt was made and we do nothing
     if (empty($sUsername)) {
         return $oUserOrError;
     }
     // If we're outside the interval, let the login process proceed as per normal and
     // update our last login time.
     $bWithinCooldownPeriod = $this->getIsWithinCooldownPeriod();
     if (!$bWithinCooldownPeriod) {
         $this->updateLastLoginTime();
         $this->doStatIncrement('login.cooldown.success');
         return $oUserOrError;
     }
     // At this point someone has attempted to login within the previous login wait interval
     // So we remove WordPress's authentication filter and our own user check authentication
     // And finally return a WP_Error which will be reflected back to the user.
     $this->doStatIncrement('login.cooldown.fail');
     remove_filter('authenticate', 'wp_authenticate_username_password', 20);
     // wp-includes/user.php
     $oWp = $this->loadWpFunctionsProcessor();
     $sErrorString = _wpsf__("Login Cooldown in effect.") . ' ' . sprintf(_wpsf__("You must wait %s seconds before attempting to %s again."), $this->getLoginCooldownInterval() - $this->getSecondsSinceLastLoginTime(), $oWp->getIsLoginRequest() ? _wpsf__('login') : _wpsf__('register'));
     if (!is_wp_error($oUserOrError)) {
         $oUserOrError = new WP_Error();
     }
     $oUserOrError->add('wpsf_logininterval', $sErrorString);
     // We now black mark this IP
     add_filter($this->getFeatureOptions()->doPluginPrefix('ip_black_mark'), '__return_true');
     return $oUserOrError;
 }
예제 #25
0
파일: Auth.php 프로젝트: ssnepenthe/metis
 /**
  * @hook
  */
 public function wp_login_errors(\WP_Error $errors, $redirect_to)
 {
     if (!isset($_GET['metis'])) {
         return $errors;
     }
     $errors->add('login_required', 'You must be logged in to view this page.', 'message');
     return $errors;
 }
예제 #26
0
function rhm_ajax_register()
{
    $user_login = '';
    $user_email = '';
    extract($_POST);
    // Should include $user_login and $user_email.
    $errors = new WP_Error();
    $sanitized_user_login = sanitize_user($user_login);
    $user_email = apply_filters('user_registration_email', $user_email);
    // Check the username
    if ($sanitized_user_login == '') {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.'));
    } elseif (!validate_username($user_login)) {
        $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
        $sanitized_user_login = '';
    } elseif (username_exists($sanitized_user_login)) {
        $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    // Check the e-mail address
    if ($user_email == '') {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.'));
    } elseif (!is_email($user_email)) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
        $user_email = '';
    } elseif (email_exists($user_email)) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
    }
    do_action('register_post', $sanitized_user_login, $user_email, $errors);
    $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email);
    if ($errors->get_error_code()) {
        echo $errors->get_error_message();
        die;
    }
    $user_pass = wp_generate_password(12, false);
    $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email);
    if (!$user_id) {
        $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
        echo $errors->get_error_message();
        die;
    }
    update_user_option($user_id, 'default_password_nag', true, true);
    //Set up the Password change nag.
    wp_new_user_notification($user_id, $user_pass);
    echo '<strong>Success!</strong> Your registration is complete. A randomly-generated password has been emailed to you.';
    die;
}
예제 #27
0
function registration_validation($username, $password, $email)
{
    global $reg_errors;
    $reg_errors = new WP_Error();
    if (empty($username) || empty($password) || empty($email)) {
        $reg_errors->add('field', 'Required form field is missing');
    }
    if (4 > strlen($username)) {
        $reg_errors->add('username_length', 'Username too short. At least 4 characters is required');
    }
    if (username_exists($username)) {
        $reg_errors->add('user_name', 'Sorry, that username already exists!');
    }
    if (!validate_username($username)) {
        $reg_errors->add('username_invalid', 'Sorry, the username you entered is not valid');
    }
    if (5 > strlen($password)) {
        $reg_errors->add('password', 'Password length must be greater than 5');
    }
    if (!is_email($email)) {
        $reg_errors->add('email_invalid', 'Email is not valid');
    }
    if (email_exists($email)) {
        $reg_errors->add('email', 'Email Already in use');
    }
    if (is_wp_error($reg_errors)) {
        foreach ($reg_errors->get_error_messages() as $error) {
            echo '<div>';
            echo '<strong>ERROR</strong>:';
            echo $error . '<br/>';
            echo '</div>';
        }
    }
}
예제 #28
0
function wp_authenticate_username_password($user, $username, $password)
{
    if (is_a($user, 'WP_User')) {
        return $user;
    }
    if (empty($username) || empty($password)) {
        $error = new WP_Error();
        if (empty($username)) {
            $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;
    }
    $userdata = get_user_by('login', $username);
    if (!$userdata) {
        return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), wp_lostpassword_url()));
    }
    if (is_multisite()) {
        // Is user marked as spam?
        if (1 == $userdata->spam) {
            return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Your account has been marked as a spammer.'));
        }
        // Is a user's blog marked as spam?
        if (!is_super_admin($userdata->ID) && isset($userdata->primary_blog)) {
            $details = get_blog_details($userdata->primary_blog);
            if (is_object($details) && $details->spam == 1) {
                return new WP_Error('blog_suspended', __('Site Suspended.'));
            }
        }
    }
    $userdata = apply_filters('wp_authenticate_user', $userdata, $password);
    if (is_wp_error($userdata)) {
        return $userdata;
    }
    if (!($userdata->user_pass == $password)) {
        return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?'), $username, wp_lostpassword_url()));
    }
    //if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) )
    //return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?' ),
    //$username, wp_lostpassword_url() ) );
    $user = new WP_User($userdata->ID);
    return $user;
}
예제 #29
0
function registration_validation($email)
{
    global $reg_errors;
    $reg_errors = new WP_Error();
    if (!is_email($email)) {
        $reg_errors->add('email_invalid', 'Ogiltig e-postadress');
    }
    if (email_exists($email)) {
        $reg_errors->add('email', 'E-postadressen finns redan registrerad');
    }
    if (is_wp_error($reg_errors)) {
        foreach ($reg_errors->get_error_messages() as $error) {
            echo '<div class="alert alert-warning text-center"><i class="fa fa-exclamation-triangle"></i> ';
            echo $error;
            echo '</div>';
        }
    }
}
예제 #30
0
 /**
  * Check metabox configuration. Trigger error if configuration is wrong.
  *
  * @since 1.1.0
  * @access private
  * @param variable $meta_box 
  */
 private function check_meta_box($meta_box)
 {
     $errors = new WP_Error();
     // Check that the id exists
     if (!array_key_exists('id', $meta_box)) {
         $errors->add('metabox-id-missing', __('Error: user metabox must have an ID.', 'wppf', 'wpum'));
     }
     return $errors;
 }