Module: Wpxf::WordPress::User

Defined in:
lib/wpxf/wordpress/user.rb

Overview

Provides functionality required to gather information about users.

Instance Method Summary collapse

Instance Method Details

#wordpress_user_exists?(user) ⇒ Boolean

Checks if a user exists.

Parameters:

  • user (String)

    username to check.

Returns:

  • (Boolean)

    true if the user exists.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wpxf/wordpress/user.rb', line 8

def wordpress_user_exists?(user)
  res = execute_post_request(
    url: ,
    body: (user, Wpxf::Utility::Text.rand_alpha(6))
  )

  return true if res && res.code == 200 && (
    res.body.to_s =~ /Incorrect password/ ||
    res.body.to_s =~ /document\.getElementById\('user_pass'\)/
  )

  false
end

#wordpress_user_profile_form_fields(cookie) ⇒ Hash?

Returns the profile form fields and their default values.

Parameters:

  • cookie (String)

    a valid session cookie.

Returns:

  • (Hash, nil)

    the profile form fields and their default values.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wpxf/wordpress/user.rb', line 24

def (cookie)
  res = execute_get_request(url: wordpress_url_admin_profile, cookie: cookie)
  return nil unless res.code == 200

  fields = {}
  res.body.scan(/<input.*?name="(.*?)".*?value="(.*?)".*?>/i) do |name, value|
    fields[name] = value
  end

  fields
end