PHP WP_Error Code Examples

This page contains top rated real world PHP examples of WP_Error extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: dana-don-boom-boom-doo.php Project: mimosafa/dana-don-boom-boom-doo
0
 public function error_message()
 {
     foreach ($this->e->get_error_messages() as $message) {
         add_settings_error('dana-don-boom-boom-doo-requirement', 'plugin_requirement', $message, 'error');
     }
     add_action('admin_notices', [$this, 'show_error']);
 }
Example #2
Show file File: loginprotect_cooldown.php Project: Wikipraca/Wikipraca-WikiSquare
0
 /**
  * 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;
 }
Example #3
Show file File: SignUp.php Project: zulfnore/MarketCheck
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;
 }
Example #4
Show file File: wpbb_admin.php Project: hell4ween/wpphpbbunicorn
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');
 }
Example #5
Show file File: action-reset-password.php Project: WordImpress/User-Frontend
0
/**
 * 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;
    }
}
Example #6
Show file File: mixcloud-embed-core.php Project: seoduda/Patua
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;
 }
Example #7
Show file File: user.php Project: schr/wordpress
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_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;
}
Example #8
Show file File: redirect-queries.php Project: AvalaraDev/redirect-queries
0
function redqs_redirection_filter($data)
{
    //array of key names we're expecting in $data from Redirection
    $required = array('url', 'action_type', 'regex', 'position', 'match_type', 'action_data', 'action_code', 'last_access', 'group_id');
    //validate $data array contains expected keys & size hasn't changed
    if (!array_key_exists_in_array($required, $data) || count($data) != 9) {
        $item = new WP_Error('redirect-add', __('Was Redirection updated? The $data array may have changed...', 'redirection'));
        $json['error'] = $item->get_error_message();
        header('Content-Type: application/json');
        echo json_encode($json);
        die;
    }
    $pattern = '/\\/(?<request>[^?#\\n\\r]+)?(?<query>[^#\\n\\r]*)?/';
    $match = preg_match($pattern, $data['action_data'], $matches);
    if (!empty($matches['query'])) {
        return $data;
    } else {
        $data['url'] = rtrim($data['url'], '/');
        //strip trailing /
        $data['url'] = '(?i)\\' . preg_quote($data['url']) . '(.*)';
        //add regex formatting & escaping
        $data['action_data'] = $data['action_data'] . "\$1";
        $data['regex'] = 1;
        return $data;
    }
}
Example #9
Show file File: class-bc-oauth.php Project: gopinathshiva/wordpress-vip-plugins
0
 /**
  * Uses the Brightcove oAuth API to retrieve and store an access key for use with requests. The token is stored as a transient
  * with an expiration time matching that which is returned from Brightcove. The call to the API is only performed if that transient
  * is invalid or expired. Return a WP_Error object for use in WordPress in the case of failure.
  *
  * @since  1.0.0
  *
  * @see    get_transient()
  * @see    set_transient()
  * @see    delete_transient()
  * @see    wp_remote_post()
  *
  * @param bool $force_new_token whether or not to obtain a new OAuth token
  * @param bool $retry           true to retry on failure or false
  *
  * @return string|WP_Error
  */
 public function _request_access_token($force_new_token = false, $retry = true)
 {
     $transient_name = $this->transient_name;
     $token = $force_new_token ? false : get_transient($transient_name);
     if (!$token) {
         $endpoint = esc_url_raw(self::ENDPOINT_BASE . '/access_token?grant_type=client_credentials');
         $request = wp_remote_post($endpoint, $this->_http_headers);
         if ('400' == wp_remote_retrieve_response_code($request)) {
             // Just in case
             delete_transient($transient_name);
             $oauth_error = new WP_Error('oauth_access_token_failure', sprintf(__('There is a problem with your Brightcove %1$s or %2$s', 'brightcove'), '<code>client_id</code>', '<code>client_secret</code>'));
             BC_Logging::log(sprintf('BC OAUTH ERROR: %s', $oauth_error->get_error_message()));
             return $oauth_error;
         }
         $body = wp_remote_retrieve_body($request);
         $data = json_decode($body);
         if (isset($data->access_token)) {
             $token = $data->access_token;
             set_transient($transient_name, $token, $data->expires_in);
         } else {
             if (!$retry) {
                 return new WP_Error('oauth_access_token_response_failure', sprintf(esc_html__('oAuth API did not return us an access token', 'brightcove')));
             }
             return $this->_request_access_token($force_new_token, false);
         }
     }
     return $token;
 }
Example #10
Show file File: user.php Project: jao/jpcamargo
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_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;
}
Example #11
Show file File: debug.php Project: kalushta/darom
0
/**
 * 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;
        }
    }
}
Example #12
Show file File: eFrontWPI.php Project: ntwrkguru/eFrontWPI
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);
    }
}
Example #13
Show file File: template-settings.php Project: amirkchetu/dokan
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;
 }
Example #14
Show file File: authorize.php Project: stanislav-chechun/campus-rize
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;
    }
}
Example #15
Show file File: auth.php Project: amimoto-ami/c3-cloudfront-clear-cache
0
 /**
  * Authenication for Amazon CloudFront
  *
  * @return boolean | WP_Error
  * @since 4.0.0
  * @access public
  */
 public function auth($options)
 {
     if (!isset($options['distribution_id']) || !$options['distribution_id']) {
         return new WP_Error('C3 Notice', "CloudFront Distribution ID is not defined.");
     }
     if (c3_is_later_than_php_55()) {
         $sdk = C3_Client_V3::get_instance();
     } else {
         $sdk = C3_Client_V2::get_instance();
         //@TODO: for php ~5.4, do not Authenication now.
         return true;
     }
     $cf_client = $sdk->create_cloudfront_client($options);
     if (is_wp_error($cf_client)) {
         return $cf_client;
     }
     try {
         $result = $cf_client->getDistribution(array('Id' => $options['distribution_id']));
         return true;
     } catch (Exception $e) {
         if ('NoSuchDistribution' === $e->getAwsErrorCode()) {
             $e = new WP_Error('C3 Auth Error', "Can not find CloudFront Distribution ID: {$options['distribution_id']} is not found.");
         } elseif ('InvalidClientTokenId' == $e->getAwsErrorCode()) {
             $e = new WP_Error('C3 Auth Error', "AWS AWS Access Key or AWS Secret Key is invalid.");
         } else {
             $e = new WP_Error('C3 Auth Error', $e->getMessage());
         }
         error_log($e->get_error_messages(), 0);
         return $e;
     }
 }
Example #16
Show file File: Auth.php Project: ssnepenthe/metis
0
 /**
  * @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;
 }
Example #17
Show file File: login.php Project: annguyenit/getdeal
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;
}
Example #18
Show file File: class-wxr-import-ui.php Project: kucrut/WordPress-Importer
0
 protected function display_error(WP_Error $err, $step = 0)
 {
     $this->render_header();
     echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br />';
     echo $err->get_error_message();
     echo '</p>';
     printf('<p><a class="button" href="%s">Try Again</a></p>', esc_url($this->get_url($step)));
     $this->render_footer();
 }
Example #19
Show file File: class.user_metabox.php Project: pierreglardon/gdv-ttc
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;
 }
Example #20
Show file File: fourtwo-password-policy-enforcement.php Project: 42Web/FourTwo-Password-Policy-Enforcement
0
/**
 * validate complex password
 *
 * @author  Joe Sexton <joe.@webtipblog.com>
 * @param   WP_Error $errors
 * @param   stdClass $userData
 * @return  WP_Error
 */
function fourtwo_ppe_validateComplexPassword($errors)
{
    $password = isset($_POST['pass1']) && trim($_POST['pass1']) ? $_POST['pass1'] : null;
    // no password or already has password error
    if (empty($password) || $errors->get_error_data('pass')) {
        return $errors;
    }
    $pass = fourtwo_ppe_isStrongPassword($password);
    // validate
    if (!$pass['length']) {
        $errors->add('pass', '<strong>ERROR</strong>: Your password must contain at least eight (8) characters.');
    }
    if (!$pass['num']) {
        $errors->add('pass', '<strong>ERROR</strong>: Your password must contain at least one (1) number.');
    }
    if (!$pass['alpha']) {
        $errors->add('pass', '<strong>ERROR</strong>: Your password must contain at least one (1) letter.');
    }
    if (!$pass['upper']) {
        $errors->add('pass', '<strong>ERROR</strong>: Your password must contain at least one (1) uppercase letter.');
    }
    if (!$pass['lower']) {
        $errors->add('pass', '<strong>ERROR</strong>: Your password must contain at least one (1) lowercase letter.');
    }
    if (!$pass['special']) {
        $errors->add('pass', '<strong>ERROR</strong>: Your password must contain at least one (1) special character.');
    }
    return $errors;
}
Example #21
Show file File: form-reg.php Project: Vasiliy28/MyJewelry
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>';
        }
    }
}
Example #22
Show file File: user.php Project: staylor/develop.svn.wordpress.org
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;
}
Example #23
Show file File: rescheduler.php Project: postmatic/beta-dist
0
 /**
  * Whether the job result indicates that the service is unavailable and will return.
  *
  * @since 1.4.10
  *
  * @return boolean
  */
 protected function is_service_unavailable()
 {
     $data = is_wp_error($this->job_result) ? $this->job_result->get_error_data() : $this->job_result;
     if (!is_array($data)) {
         return false;
     }
     if (!isset($data['response']['code'])) {
         return false;
     }
     return 503 == $data['response']['code'];
 }
Example #24
Show file File: xtec-settings.php Project: ignacioabejaro/xtecblocs
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;
    }
}
Example #25
Show file File: class-login-screen.php Project: AmerisFCI/AmerisWordpress
0
 /**
  * Disallow using the same password as before on reset.
  *
  * @action validate_password_reset
  *
  * @param WP_Error $errors
  * @param WP_User  $user
  */
 public function validate_password_reset($errors, $user)
 {
     $new_pass1 = filter_input(INPUT_POST, 'pass1');
     $new_pass2 = filter_input(INPUT_POST, 'pass2');
     if (!$new_pass1 || !$new_pass2 || $new_pass1 !== $new_pass2 || !Expire_Passwords::has_expirable_role($user)) {
         return;
     }
     $is_same = wp_check_password($new_pass1, $user->data->user_pass, $user->ID);
     if ($is_same) {
         $errors->add('password_already_used', esc_html__('You cannot reuse your old password.'));
     }
 }
Example #26
Show file File: core.php Project: kasparsd/limit-login-attempts
0
function limit_login_wp_authenticate_user($user, $password)
{
    if (is_wp_error($user) || is_limit_login_ok()) {
        return $user;
    }
    global $limit_login_my_error_shown;
    $limit_login_my_error_shown = true;
    $error = new WP_Error();
    // This error should be the same as in "shake it" filter below
    $error->add('too_many_retries', limit_login_error_msg());
    return $error;
}
Example #27
Show file File: AbstractModel.php Project: asmbs/wp-schedule-builder
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);
             }
         }
     }
 }
Example #28
Show file File: WP_Exception.php Project: goblindegook/syllables
0
 /**
  * WordPress exception constructor.
  *
  * The class constructor accepts either the traditional `\Exception` creation
  * parameters or a `\WP_Error` instance in place of the previous exception.
  *
  * If a `\WP_Error` instance is given in this way, the `$message` and `$code`
  * parameters are ignored in favour of the message and code provided by the
  * `\WP_Error` instance.
  *
  * Depending on whether a `\WP_Error` instance was received, the instance is kept
  * or a new one is created from the provided parameters.
  *
  * @param string               $message  Exception message (optional, defaults to empty).
  * @param string               $code     Exception code (optional, defaults to empty).
  * @param \Exception|\WP_Error $previous Previous exception or error (optional).
  *
  * @uses \WP_Error
  * @uses \WP_Error::get_error_code()
  * @uses \WP_Error::get_error_message()
  *
  * @codeCoverageIgnore
  */
 public function __construct($message = '', $code = '', $previous = null)
 {
     $exception = $previous;
     $wp_error = null;
     if ($previous instanceof \WP_Error) {
         $code = $previous->get_error_code();
         $message = $previous->get_error_message($code);
         $wp_error = $previous;
         $exception = null;
     }
     parent::__construct($message, null, $exception);
     $this->code = $code;
     $this->wp_error = $wp_error;
 }
Example #29
Show file File: class-update-manager.php Project: donwea/nhap.org
0
        /**
         * If the update check returned a WP_Error, show it to the user
         */
        public function show_update_error()
        {
            if ($this->wp_error === null) {
                return;
            }
            ?>
			<div class="error">
			<p><?php 
            printf(__('%s failed to check for updates because of the following error: <em>%s</em>', $this->product->get_text_domain()), $this->product->get_item_name(), $this->wp_error->get_error_message());
            ?>
</p>
			</div>
	<?php 
        }
Example #30
Show file File: AdminScreenOptOut.php Project: NYC2015/team-12
0
 /**
  * Show opt out options page
  * 
  */
 public function options()
 {
     global $wpdb;
     $errors = array();
     $success = false;
     $opt_out_level = get_option("bbpp_thankmelater_opt_out_level", "disabled");
     $opt_out_form_type = get_option("bbpp_thankmelater_opt_out_form_type", "out");
     $opt_out_form_out_text = get_option("bbpp_thankmelater_opt_out_form_out_text", "1");
     $opt_out_form_out_text_custom = get_option("bbpp_thankmelater_opt_out_form_out_text_custom", "");
     $opt_out_form_in_text = get_option("bbpp_thankmelater_opt_out_form_in_text", "1");
     $opt_out_form_in_text_custom = get_option("bbpp_thankmelater_opt_out_form_in_text_custom", "");
     if ($_POST) {
         check_admin_referer("bbpp_thankmelater_opt_out_options");
         $data = stripslashes_deep($_POST);
         $opt_out_level = isset($data["bbpp_thankmelater_opt_out_level"]) ? $data["bbpp_thankmelater_opt_out_level"] : NULL;
         $opt_out_form_type = isset($data["bbpp_thankmelater_opt_out_form_type"]) ? $data["bbpp_thankmelater_opt_out_form_type"] : NULL;
         $opt_out_form_out_text = isset($data["bbpp_thankmelater_opt_out_form_out_text"]) ? $data["bbpp_thankmelater_opt_out_form_out_text"] : NULL;
         $opt_out_form_out_text_custom = isset($data["bbpp_thankmelater_opt_out_form_out_text_custom"]) ? $data["bbpp_thankmelater_opt_out_form_out_text_custom"] : NULL;
         $opt_out_form_in_text = isset($data["bbpp_thankmelater_opt_out_form_in_text"]) ? $data["bbpp_thankmelater_opt_out_form_in_text"] : NULL;
         $opt_out_form_in_text_custom = isset($data["bbpp_thankmelater_opt_out_form_in_text_custom"]) ? $data["bbpp_thankmelater_opt_out_form_in_text_custom"] : NULL;
         $error = new WP_Error();
         if (!in_array($opt_out_level, array("disabled", "email", "form"))) {
             $error->add("opt_out_level", __("You must select an option.", "bbpp-thankmelater"));
         }
         if ($opt_out_level == "form") {
             if (!in_array($opt_out_form_type, array("out", "in"))) {
                 $error->add("opt_out_form_type", __("You must select an option.", "bbpp-thankmelater"));
             }
             if ($opt_out_form_type == "out") {
                 if (!in_array($opt_out_form_out_text, array("1", "custom"))) {
                     $error->add("opt_out_form_out_text", __("You must select an option.", "bbpp-thankmelater"));
                 }
                 if ($opt_out_form_out_text == "custom" && empty($opt_out_form_out_text_custom)) {
                     $error->add("opt_out_form_out_text", __("This must not be blank.", "bbpp-thankmelater"));
                 }
             } elseif ($opt_out_form_type == "in") {
                 if (!in_array($opt_out_form_in_text, array("1", "custom"))) {
                     $error->add("opt_out_form_in_text", __("You must select an option.", "bbpp-thankmelater"));
                 }
                 if ($opt_out_form_in_text == "custom" && empty($opt_out_form_in_text_custom)) {
                     $error->add("opt_out_form_in_text", __("This must not be blank.", "bbpp-thankmelater"));
                 }
             }
         }
         if ($error->get_error_codes()) {
             $errors[] = $error;
         } else {
             update_option("bbpp_thankmelater_opt_out_level", $opt_out_level);
             update_option("bbpp_thankmelater_opt_out_form_type", $opt_out_form_type);
             update_option("bbpp_thankmelater_opt_out_form_out_text", $opt_out_form_out_text);
             update_option("bbpp_thankmelater_opt_out_form_out_text_custom", $opt_out_form_out_text_custom);
             update_option("bbpp_thankmelater_opt_out_form_in_text", $opt_out_form_in_text);
             update_option("bbpp_thankmelater_opt_out_form_in_text_custom", $opt_out_form_in_text_custom);
             $success = true;
         }
     }
     // get a list of the most recent opt outs
     $opt_out_results = $wpdb->get_results("\r\n\t\t\tSELECT `email`, `date_gmt`\r\n\t\t\tFROM `{$wpdb->prefix}bbpp_thankmelater_opt_outs`\r\n\t\t\tORDER BY `date_gmt` DESC\r\n\t\t\tLIMIT 100\r\n\t\t");
     require_once BBPP_THANKMELATER_PLUGIN_PATH . "admin/opt-out/options.php";
 }