This commit is contained in:
2024-08-29 17:07:22 +08:00
commit 6032bd1237
1790 changed files with 349463 additions and 0 deletions
@@ -0,0 +1,10 @@
"""
Implementations of standard WordPress XML-RPC APIs.
"""
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc.methods import pages
from wordpress_xmlrpc.methods import demo
from wordpress_xmlrpc.methods import users
from wordpress_xmlrpc.methods import options
from wordpress_xmlrpc.methods import comments
from wordpress_xmlrpc.methods import media
@@ -0,0 +1,126 @@
from wordpress_xmlrpc.base import *
from wordpress_xmlrpc.wordpress import WordPressComment
class GetComment(AuthenticatedMethod):
"""
Retrieve an individual comment.
Parameters:
`comment_id`: ID of the comment to retrieve.
Returns: :class:`WordPressPost` instance.
"""
method_name = 'wp.getComment'
method_args = ('comment_id',)
results_class = WordPressComment
class NewComment(AuthenticatedMethod):
"""
Create a new comment on a post.
Parameters:
`post_id`: The id of the post to add a comment to.
`comment`: A :class:`WordPressComment` instance with at least the `content` value set.
Returns: ID of the newly-created comment (an integer).
"""
method_name = 'wp.newComment'
method_args = ('post_id', 'comment')
class NewAnonymousComment(AnonymousMethod):
"""
Create a new comment on a post without authenticating.
NOTE: Requires support on the blog by setting the following filter in a plugin or theme:
add_filter( 'xmlrpc_allow_anonymous_comments', '__return_true' );
Parameters:
`post_id`: The id of the post to add a comment to.
`comment`: A :class:`WordPressComment` instance with at least the `content` value set.
Returns: ID of the newly-created comment (an integer).
"""
method_name = 'wp.newComment'
method_args = ('post_id', 'comment')
class EditComment(AuthenticatedMethod):
"""
Edit an existing comment.
Parameters:
`comment_id`: The id of the comment to edit.
`comment`: A :class:`WordPressComment` instance with at least the `content` value set.
Returns: `True` on successful edit.
"""
method_name = 'wp.editComment'
method_args = ('comment_id', 'comment')
class DeleteComment(AuthenticatedMethod):
"""
Delete an existing comment.
Parameters:
`comment_id`: The id of the comment to be deleted.
Returns: `True` on successful deletion.
"""
method_name = 'wp.deleteComment'
method_args = ('comment_id',)
class GetCommentStatusList(AuthenticatedMethod):
"""
Retrieve the set of possible blog comment statuses (e.g., "approve," "hold," "spam").
Parameters:
None
Returns: `dict` of values and their pretty names.
Example:
>>> client.call(GetCommentStatusList())
{'hold': 'Unapproved', 'approve': 'Approved', 'spam': 'Spam'}
"""
method_name = 'wp.getCommentStatusList'
class GetCommentCount(AuthenticatedMethod):
"""
Retrieve comment count for a specific post.
Parameters:
`post_id`: The id of the post to retrieve comment count for.
Returns: `dict` of comment counts for the post divided by comment status.
Example:
>>> client.call(GetCommentCount(1))
{'awaiting_moderation': '2', 'total_comments': 23, 'approved': '18', 'spam': 3}
"""
method_name = 'wp.getCommentCount'
method_args = ('post_id',)
class GetComments(AuthenticatedMethod):
"""
Gets a set of comments for a post.
Parameters:
`filter`: a `dict` with the following values:
* `post_id`: the id of the post to retrieve comments for
* `status`: type of comments of comments to retrieve (optional, defaults to 'approve')
* `number`: number of comments to retrieve (optional, defaults to 10)
* `offset`: retrieval offset (optional, defaults to 0)
Returns: `list` of :class:`WordPressComment` instances.
"""
method_name = 'wp.getComments'
method_args = ('filter',)
results_class = WordPressComment
@@ -0,0 +1,10 @@
from wordpress_xmlrpc.base import *
class SayHello(AnonymousMethod):
method_name = 'demo.sayHello'
class AddTwoNumbers(AnonymousMethod):
method_name = 'demo.addTwoNumbers'
method_args = ('number1', 'number2')
@@ -0,0 +1,55 @@
from wordpress_xmlrpc.base import *
from wordpress_xmlrpc.wordpress import WordPressMedia
class GetMediaLibrary(AuthenticatedMethod):
"""
Retrieve filtered list of media library items.
Parameters:
`filter`: `dict` with optional keys:
* `number`: number of media items to retrieve
* `offset`: query offset
* `parent_id`: ID of post the media item is attached to.
Use empty string (default) to show all media items.
Use `0` to show unattached media items.
* `mime_type`: file mime-type to filter by (e.g., 'image/jpeg')
Returns: `list` of :class:`WordPressMedia` instances.
"""
method_name = 'wp.getMediaLibrary'
method_args = ('filter',)
results_class = WordPressMedia
class GetMediaItem(AuthenticatedMethod):
"""
Retrieve an individual media item.
Parameters:
`attachment_id`: ID of the media item.
Returns: :class:`WordPressMedia` instance.
"""
method_name = 'wp.getMediaItem'
method_args = ('attachment_id',)
results_class = WordPressMedia
class UploadFile(AuthenticatedMethod):
"""
Upload a file to the blog.
Note: the file is not attached to or inserted into any blog posts.
Parameters:
`data`: `dict` with three items:
* `name`: filename
* `type`: MIME-type of the file
* `bits`: base-64 encoded contents of the file. See xmlrpclib.Binary()
* `overwrite` (optional): flag to override an existing file with this name
Returns: `dict` with keys `id`, `file` (filename), `url` (public URL), and `type` (MIME-type).
"""
method_name = 'wp.uploadFile'
method_args = ('data',)
@@ -0,0 +1,35 @@
from wordpress_xmlrpc.base import *
from wordpress_xmlrpc.wordpress import WordPressOption
class GetOptions(AuthenticatedMethod):
"""
Retrieve list of blog options.
Parameters:
`options`: `list` of option names to retrieve; if empty, all options will be retrieved
Returns: `list` of :class:`WordPressOption` instances.
"""
method_name = 'wp.getOptions'
method_args = ('options',)
def process_result(self, options_dict):
options = []
for key, value in options_dict.items():
value['name'] = key
options.append(WordPressOption(value))
return options
class SetOptions(GetOptions):
"""
Update the value of an existing blog option.
Parameters:
`options`: `dict` of key/value pairs
Returns: `list` of :class:`WordPressOption` instances representing the updated options.
"""
method_name = 'wp.setOptions'
method_args = ('options',)
@@ -0,0 +1,33 @@
from wordpress_xmlrpc.base import *
class GetPageStatusList(AuthenticatedMethod):
"""
Retrieve the set of possible blog page statuses (e.g., "draft," "private," "publish").
Parameters:
None
Returns: `dict` of values and their pretty names.
Example:
>>> client.call(GetPageStatusList())
{'draft': 'Draft', 'private': 'Private', 'publish': 'Published'}
"""
method_name = 'wp.getPageStatusList'
class GetPageTemplates(AuthenticatedMethod):
"""
Retrieve the list of blog templates.
Parameters:
None
Returns: `dict` of values and their paths.
Example:
>>> client.call(GetPageTemplates())
{'Default': 'default', 'Sidebar Template': 'sidebar-page.php', 'Showcase Template': 'showcase.php'}
"""
method_name = 'wp.getPageTemplates'
@@ -0,0 +1,177 @@
from wordpress_xmlrpc.base import *
from wordpress_xmlrpc.wordpress import WordPressPost, WordPressPostType
class GetPosts(AuthenticatedMethod):
"""
Retrieve posts from the blog.
Parameters:
`filter`: optional `dict` of filters:
* `number`
* `offset`
* `orderby`
* `order`: 'ASC' or 'DESC'
* `post_type`: Defaults to 'post'
* `post_status`
Returns: `list` of :class:`WordPressPost` instances.
"""
method_name = 'wp.getPosts'
optional_args = ('filter', 'fields')
results_class = WordPressPost
class GetPost(AuthenticatedMethod):
"""
Retrieve an individual blog post.
Parameters:
`post_id`: ID of the blog post to retrieve.
Returns: :class:`WordPressPost` instance.
"""
method_name = 'wp.getPost'
method_args = ('post_id',)
optional_args = ('fields',)
results_class = WordPressPost
class NewPost(AuthenticatedMethod):
"""
Create a new post on the blog.
Parameters:
`content`: A :class:`WordPressPost` instance with at least the `title` and `content` values set.
Returns: ID of the newly-created blog post (an integer).
"""
method_name = 'wp.newPost'
method_args = ('content',)
class EditPost(AuthenticatedMethod):
"""
Edit an existing blog post.
Parameters:
`post_id`: ID of the blog post to edit.
`content`: A :class:`WordPressPost` instance with the new values for the blog post.
Returns: `True` on successful edit.
"""
method_name = 'wp.editPost'
method_args = ('post_id', 'content')
class DeletePost(AuthenticatedMethod):
"""
Delete a blog post.
Parameters:
`post_id`: ID of the blog post to delete.
Returns: `True` on successful deletion.
"""
method_name = 'wp.deletePost'
method_args = ('post_id', )
class GetPostStatusList(AuthenticatedMethod):
"""
Retrieve the set of possible blog post statuses (e.g., "draft," "private," "publish").
Parameters:
None
Returns: `dict` of values and their pretty names.
Example:
>>> client.call(GetPostStatusList())
{'draft': 'Draft', 'private': 'Private', 'pending': 'Pending Review', 'publish': 'Published'}
"""
method_name = 'wp.getPostStatusList'
class GetPostFormats(AuthenticatedMethod):
"""
Retrieve the set of post formats used by the blog.
Parameters:
None
Returns: `dict` containing a `dict` of all blog post formats (`all`)
and a list of formats `supported` by the theme.
Example:
>>> client.call(GetPostFormats())
{'all': {'status': 'Status', 'quote': 'Quote', 'image': 'Image', 'aside': 'Aside', 'standard': 'Standard', 'link': 'Link', 'chat': 'Chat', 'video': 'Video', 'audio': 'Audio', 'gallery': 'Gallery'},
'supported': ['aside', 'link', 'gallery', 'status', 'quote', 'image']}
"""
method_name = 'wp.getPostFormats'
def get_args(self, client):
args = super(GetPostFormats, self).get_args(client)
args += ({'show-supported': True},)
return args
class GetPostTypes(AuthenticatedMethod):
"""
Retrieve a list of post types used by the blog.
Parameters:
None
Returns: `dict` with names as keys and :class:`WordPressPostType` instances as values.
"""
method_name = 'wp.getPostTypes'
results_class = WordPressPostType
def process_result(self, raw_result):
result = {}
for name, raw_value in raw_result.items():
result[name] = self.results_class(raw_value)
return result
class GetPostType(AuthenticatedMethod):
"""
Retrieve an individual blog post type.
Parameters:
`post_type`: Name of the blog post type to retrieve.
Returns: :class:`WordPressPostType` instance.
"""
method_name = 'wp.getPostType'
method_args = ('post_type',)
results_class = WordPressPostType
class GetRevisions(AuthenticatedMethod):
"""
Retrieve all revisions of a post.
Parameters:
`post_id`: ID of the post.
Returns: `list` of :class:`WordPressPost` instances.
"""
method_name = 'wp.getRevisions'
method_args = ('post_id',)
optional_args = ('fields',)
results_class = WordPressPost
class RestoreRevision(AuthenticatedMethod):
"""
Restores a post to a previous revision.
Parameters:
`revision_id`: ID of the revision to revert to.
Returns: `True` on successful reversion.
"""
method_name = 'wp.restoreRevision'
method_args = ('revision_id',)
@@ -0,0 +1,111 @@
from wordpress_xmlrpc.base import *
from wordpress_xmlrpc.wordpress import WordPressTaxonomy, WordPressTerm
class GetTaxonomies(AuthenticatedMethod):
"""
Retrieve the list of available taxonomies for the blog.
Parameters:
None
Returns: `list` of :class:`WordPressTaxonomy` instances.
"""
method_name = 'wp.getTaxonomies'
results_class = WordPressTaxonomy
class GetTaxonomy(AuthenticatedMethod):
"""
Retrieve an individual taxonomy.
Parameters:
`taxonomy`: name of the taxonomy
Returns: :class:`WordPressTaxonomy` instance.
"""
method_name = 'wp.getTaxonomy'
method_args = ('taxonomy',)
results_class = WordPressTaxonomy
class GetTerms(AuthenticatedMethod):
"""
Retrieve the list of available terms for a taxonomy.
Parameters:
`taxonomy`: name of the taxonomy
`filter`: optional `dict` of filters:
* `number`
* `offset`
* `orderby`
* `order`: 'ASC' or 'DESC'
* `hide_empty`: Whether to return terms with count==0
* `search`: Case-insensitive search on term names
Returns: `list` of :class:`WordPressTerm` instances.
"""
method_name = 'wp.getTerms'
method_args = ('taxonomy',)
optional_args = ('filter',)
results_class = WordPressTerm
class GetTerm(AuthenticatedMethod):
"""
Retrieve an individual term.
Parameters:
`taxonomy`: name of the taxonomy
`term_id`: ID of the term
Returns: :class:`WordPressTerm` instance.
"""
method_name = 'wp.getTerm'
method_args = ('taxonomy', 'term_id')
results_class = WordPressTerm
class NewTerm(AuthenticatedMethod):
"""
Create new term.
Parameters:
`term`: instance of :class:`WordPressTerm`
Returns: ID of newly-created term (an integer).
"""
method_name = 'wp.newTerm'
method_args = ('term',)
class EditTerm(AuthenticatedMethod):
"""
Edit an existing term.
Parameters:
`term_id`: ID of the term to edit.
`term`: A :class:`WordPressTerm` instance with the new values for the term.
Returns: `True` on successful edit.
"""
method_name = 'wp.editTerm'
method_args = ('term_id', 'term')
class DeleteTerm(AuthenticatedMethod):
"""
Delete a term.
Parameters:
`taxonomy`: name of the taxonomy
`term_id`: ID of the term to delete.
Returns: `True` on successful deletion.
"""
method_name = 'wp.deleteTerm'
method_args = ('taxonomy', 'term_id')
@@ -0,0 +1,98 @@
from wordpress_xmlrpc.base import *
from wordpress_xmlrpc.wordpress import WordPressBlog, WordPressAuthor, WordPressUser
class GetUsers(AuthenticatedMethod):
"""
Retrieve list of users in the blog.
Parameters:
`filter`: optional `dict` of filters:
* `number`
* `offset`
* `role`
`fields`: optional `list` of fields to return. Specific fields, or groups 'basic' or 'all'.
Returns: `list` of :class:`WordPressUser` instances.
"""
method_name = 'wp.getUsers'
optional_args = ('filter', 'fields')
results_class = WordPressUser
class GetUser(AuthenticatedMethod):
"""
Retrieve an individual user.
Parameters:
`user_id`: ID of the user
`fields`: (optional) `list` of fields to return. Specific fields, or groups 'basic' or 'all'.
Returns: :class:`WordPressUser` instance.
"""
method_name = 'wp.getUser'
method_args = ('user_id',)
optional_args = ('fields',)
results_class = WordPressUser
class GetProfile(AuthenticatedMethod):
"""
Retrieve information about the connected user.
Parameters:
None
Returns: instance of :class:`WordPressUser` representing the user whose credentials are being used with the XML-RPC API.
"""
method_name = 'wp.getProfile'
results_class = WordPressUser
class EditProfile(AuthenticatedMethod):
"""
Edit profile fields of the connected user.
Parameters:
`user`: `WordPressUser` instance.
Returns: `True` on successful edit.
"""
method_name = 'wp.editProfile'
method_args = ('user',)
class GetUserInfo(GetProfile):
"""Alias for GetProfile for backwards compatibility"""
pass
class GetUsersBlogs(AuthenticatedMethod):
"""
Retrieve list of blogs that this user belongs to.
Parameters:
None
Returns: `list` of :class:`WordPressBlog` instances.
"""
method_name = 'wp.getUsersBlogs'
results_class = WordPressBlog
def get_args(self, client):
# strip off first (blog_id) parameter
return super(GetUsersBlogs, self).get_args(client)[1:]
class GetAuthors(AuthenticatedMethod):
"""
Retrieve list of authors in the blog.
Parameters:
None
Returns: `list` of :class:`WordPressAuthor` instances.
"""
method_name = 'wp.getAuthors'
results_class = WordPressAuthor