Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 7feab6c

Browse files
committed
Add methods to build hash of profile form fields
1 parent 685c8fe commit 7feab6c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/wpxf/wordpress/urls.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,9 @@ def wordpress_url_new_user
106106
def wordpress_url_uploads
107107
normalize_uri(wordpress_url_wp_content, 'uploads')
108108
end
109+
110+
# @return [String] the edit profile page URL.
111+
def wordpress_url_admin_profile
112+
normalize_uri(wordpress_url_admin, 'profile.php')
113+
end
109114
end

lib/wpxf/wordpress/user.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@ def wordpress_user_exists?(user)
1616

1717
false
1818
end
19+
20+
# @param cookie [String] a valid session cookie.
21+
# @return [Hash, nil] the profile form fields and their default values.
22+
def wordpress_user_profile_form_fields(cookie)
23+
res = execute_get_request(url: wordpress_url_admin_profile, cookie: cookie)
24+
return nil unless res.code == 200
25+
26+
fields = {}
27+
res.body.scan(/<input.*?name="(.*?)".*?value="(.*?)".*?>/i) do |name, value|
28+
fields[name] = value
29+
end
30+
31+
fields
32+
end
1933
end

0 commit comments

Comments
 (0)