本文整理汇总了PHP中WP_Error类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Error类的具体用法?PHP WP_Error怎么用?PHP WP_Error使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Error类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkLoginInterval
/**
* 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;
}
示例2: checkPurchaseForm
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;
}
示例3: WPPHPBBU_SettingsPage
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');
}
示例4: uf_perform_reset_password
/**
* 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;
}
}
示例5: wp_authenticate_username_password
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;
}
示例6: redqs_redirection_filter
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;
}
}
示例7: _request_access_token
/**
* 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;
}
示例8: wp_authenticate_username_password
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;
}
示例9: appthemes_bad_method_visibility
/**
* 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;
}
}
}
示例10: eFrontWPI_authenticate
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);
}
}
示例11: validate
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;
}
示例12: rcl_get_login_user
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;
}
}
示例13: auth
/**
* 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;
}
}
示例14: wp_login_errors
/**
* @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;
}
示例15: widget_retrieve_password
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;
}