Module: Wpxf::WordPress::Posts
- Defined in:
- lib/wpxf/wordpress/posts.rb
Overview
Provides helper functions for interacting with posts.
Instance Method Summary collapse
-
#get_post_id_from_body(body) ⇒ String?
Get the post ID from a post body.
-
#get_post_id_from_permalink(url) ⇒ String?
Get the post ID from a permalink.
Instance Method Details
#get_post_id_from_body(body) ⇒ String?
Get the post ID from a post body.
8 9 10 11 12 13 14 15 16 |
# File 'lib/wpxf/wordpress/posts.rb', line 8 def get_post_id_from_body(body) return nil unless body res = body.match(/<body class="[^=]*postid-(\d+)[^=]*">/i) if res && res[1] emit_info "Found post #{res[1]}", true return res[1] end nil end |
#get_post_id_from_permalink(url) ⇒ String?
Get the post ID from a permalink.
21 22 23 24 25 |
# File 'lib/wpxf/wordpress/posts.rb', line 21 def get_post_id_from_permalink(url) res = execute_get_request(url: url) return nil unless res && res.code == 200 get_post_id_from_body(res.body) end |