public function wpua_avatar_upload($file)
 {
     $filetype = wp_check_filetype($file->name);
     $media_upload = array();
     $media_upload['file'] = array('name' => $file->name, 'type' => $filetype['type'], 'tmp_name' => $file->path, 'error' => 0, 'size' => filesize($file->path));
     $media_file = wp_handle_upload($media_upload['file'], array('test_form' => false, 'test_upload' => false, 'action' => 'custom_action'));
     if ($media_file['file']) {
         $url = $media_file['url'];
         $filepath = $media_file['file'];
         if ($image_meta = @wp_read_image_metadata($filepath)) {
             if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
                 $title = $image_meta['title'];
             }
         }
         $attachment = array('guid' => $url, 'post_mime_type' => $filetype['type'], 'post_title' => $title);
         $attachment_id = wp_insert_attachment($attachment, $filepath);
         if (!is_wp_error($attachment_id)) {
             $this->delete_attachment_by_user($this->user_id);
             wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $filepath));
             update_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $this->user_id);
             $arr = wp_get_attachment_image_src($attachment_id, 'full');
             $this->avatar_url = $arr[0];
             $this->avatar_filename = basename($filepath);
             $this->resource = $attachment_id;
             $saved = $this->save();
             if (!$saved) {
                 $this->delete_attachment($attachment_id);
                 return $saved;
             }
             return $saved;
         }
     } else {
         return WP_Error('file_upload_problem', __("Media avatar could't uploading please check you have right permission for uploads folder.", 'wp-user-avatar-pro'));
     }
 }
Example #2
0
 public function run($arguments)
 {
     if (empty($arguments['id'])) {
         return array('error' => 'User ID Required');
     }
     $user = get_user_by('id', absint($arguments['id']));
     if (!is_object($user) || !is_a($user, 'WP_User')) {
         return WP_Error('invalid-user-id', "Unable to find the requested user with an ID of {$arguments['id']}.");
     }
     $meta_key = 'ithemes-sync-admin-bar-items-' . get_current_blog_id();
     return get_user_meta($user->ID, $meta_key, true);
 }
 public function run($arguments)
 {
     if (empty($arguments['id'])) {
         return WP_Error('user-id-required', 'User ID Required');
     }
     if (!isset($arguments['whitelist'])) {
         return WP_Error('whitelist-required', 'Whitelist is a required parameter');
     }
     if (!is_array($arguments['whitelist'])) {
         return WP_Error('invalid-whitelist', 'Whitelist is invalid. Please specify as an array of IDs.');
     }
     $user = get_user_by('id', absint($arguments['id']));
     if (!is_object($user) || !is_a($user, 'WP_User')) {
         return WP_Error('invalid-user-id', "Unable to find the requested user with an ID of {$arguments['id']}.");
     }
     $meta_key = 'ithemes-sync-admin-bar-item-whitelist-' . get_current_blog_id();
     return update_user_meta($user->ID, $meta_key, $arguments['whitelist']);
 }
Example #4
0
 /**
  * Deletes meta.
  *
  * @global object $wpdb
  *
  * @param type $meta_key
  *
  */
 function delete($meta_id)
 {
     global $wpdb;
     $r = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta}\n                        WHERE post_id = %d\n                        AND meta_id = %d", $this->post->ID, intval($meta_id)));
     if ($r === false) {
         return WP_Error('wpcf_repeater_delete_field', 'Repeater failed deleting post_ID: ' . $this->post->ID . '; meta_ID: ' . intval($meta_id));
     }
     return $r;
 }
Example #5
0
/**
 * Creates, stores, then returns a password reset key for user.
 *
 * @since 4.4.0
 *
 * @global wpdb         $wpdb      WordPress database abstraction object.
 * @global PasswordHash $wp_hasher Portable PHP password hashing framework.
 *
 * @param WP_User $user User to retrieve password reset key for.
 *
 * @return string|WP_Error Password reset key on success. WP_Error on error.
 */
function get_password_reset_key($user)
{
    global $wpdb, $wp_hasher;
    /**
     * Fires before a new password is retrieved.
     *
     * @since 1.5.0
     * @deprecated 1.5.1 Misspelled. Use 'retrieve_password' hook instead.
     *
     * @param string $user_login The user login name.
     */
    do_action('retreive_password', $user->user_login);
    /**
     * Fires before a new password is retrieved.
     *
     * @since 1.5.1
     *
     * @param string $user_login The user login name.
     */
    do_action('retrieve_password', $user->user_login);
    /**
     * Filter whether to allow a password to be reset.
     *
     * @since 2.7.0
     *
     * @param bool true           Whether to allow the password to be reset. Default true.
     * @param int  $user_data->ID The ID of the user attempting to reset a password.
     */
    $allow = apply_filters('allow_password_reset', true, $user->ID);
    if (!$allow) {
        return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
    } elseif (is_wp_error($allow)) {
        return $allow;
    }
    // Generate something random for a password reset key.
    $key = wp_generate_password(20, false);
    /**
     * Fires when a password reset key is generated.
     *
     * @since 2.5.0
     *
     * @param string $user_login The username for the user.
     * @param string $key        The generated password reset key.
     */
    do_action('retrieve_password_key', $user->user_login, $key);
    // Now insert the key, hashed, into the DB.
    if (empty($wp_hasher)) {
        require_once ABSPATH . WPINC . '/class-phpass.php';
        $wp_hasher = new PasswordHash(8, true);
    }
    $hashed = time() . ':' . $wp_hasher->HashPassword($key);
    $key_saved = $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user->user_login));
    if (false === $key_saved) {
        return WP_Error('no_password_key_update', __('Could not save password reset key to database.'));
    }
    return $key;
}
 /**
  * Deletes meta.
  *
  * @global object $wpdb
  *
  * @param type $meta_key
  *
  */
 function delete($meta_id)
 {
     global $wpdb;
     $r = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta}\r\r\n                        WHERE user_id = %d\r\r\n                        AND umeta_id = %d", $this->currentUID, intval($meta_id)));
     if ($r === false) {
         return WP_Error('wpcf_repeater_delete_field', 'Repeater failed deleting user_ID: ' . $this->currentUID . '; meta_ID: ' . intval($meta_id));
     }
     return $r;
 }
 function install_theme($name, $values)
 {
     include_once ABSPATH . 'wp-admin/includes/theme-install.php';
     //for themes_api..
     if ($values['url']) {
         $download_link = $values['url'];
     } else {
         $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false)));
         //Save on a bit of bandwidth.
         if (is_wp_error($api)) {
             return WP_Error(__('Failed to contact theme API', 'ls-installer'), $api);
         }
         $download_link = $api->download_link;
     }
     $title = sprintf(__('Installing Theme: %s', 'ls-installer'), $values['label']);
     $theme = $name;
     $type = 'web';
     //Install theme type, From Web or an Upload.
     $upgrader = new Theme_Upgrader(new LSInstaller_Theme_Installer_Skin(compact('title', 'theme', 'api')));
     $upgrader->install($download_link);
     return $upgrader->result;
 }
 /**
  * Displays current version details on Plugin's page
  *
  * @since 0.1.0
  *
  * @param $product
  * @param $key
  * @param $version
  */
 public function get_version_details($product, $key, $version, $early_access)
 {
     $version_info = $this->get_version_info($product, $key, $version, $early_access, false);
     if ($version_info == false || (!array_key_exists('version_details', $version_info) || empty($version_info['version_details']))) {
         return WP_Error('no_version_info', __('An unexpected error occurred. Unable to find version details for this plugin. Please contact support.'));
     }
     $response = new stdClass();
     $response->name = $version_info['version_details']['name'];
     $response->slug = $version_info['version_details']['slug'];
     $response->version = $version_info['version'];
     $response->download_link = str_replace("{KEY}", $key, $version_info['package']);
     $response->author = $version_info['version_details']['author'];
     $response->requires = $version_info['version_details']['requires'];
     $response->tested = $version_info['version_details']['tested'];
     $response->last_updated = $version_info['version_details']['last_updated'];
     $response->homepage = $version_info['version_details']['homepage'];
     $response->sections = $version_info['version_details']['sections'];
     return $response;
 }
 /**
  * Flips current image
  *
  * @param boolean $horz Horizonal Flip
  * @param boolean $vert Vertical Flip
  * @returns boolean|WP_Error
  */
 public function flip($horz, $vert)
 {
     $w = $this->size['width'];
     $h = $this->size['height'];
     $dst = wp_imagecreatetruecolor($w, $h);
     if (is_resource($dst)) {
         $sx = $vert ? $w - 1 : 0;
         $sy = $horz ? $h - 1 : 0;
         $sw = $vert ? -$w : $w;
         $sh = $horz ? -$h : $h;
         if (imagecopyresampled($dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh)) {
             imagedestroy($this->image);
             $this->image = $dst;
             return true;
         }
     }
     return WP_Error('image_flip_error', __('Image flip failed.'), $this->file);
 }