python-wordpress-xmlrpc icon indicating copy to clipboard operation
python-wordpress-xmlrpc copied to clipboard

Edit a post failed When user's role is Author

Open poustchi opened this issue 10 years ago • 2 comments

Hi, I create a user with Author role in wordpress. In python, I can create a new post BUT when I want to edit the same post I get the following error message: "Sorry, you are not allowed to stick this post" If I change the user's role to Editor then everything is OK. Why I can not edit my post???

Wordpress: 3.8.3 Python : 2.6.6 python-wordpress-xmlrpc: 2.2

wp = Client('http://www.xxx.xxx/xmlrpc.php', 'authoruser', '123456')

post = WordPressPost() post.title = 'Test' post.content = 'This is a wonderful blog post about XML-RPC.' post.id = wp.call(posts.NewPost(post))

post.post_status = 'publish' wp.call(posts.EditPost(post.id, post))

post = wp.call(posts.GetPost(post.id)) post.title = 'Post with Tags' wp.call(posts.EditPost(post.id, post))

poustchi avatar Apr 26 '14 18:04 poustchi

This happens because (by default) WordPress authors do not have permissions to make a post sticky, and the XML-RPC wp.editPost method will throw an error if it includes a value for sticky.

A workaround is to delete the sticky value from the post object before calling posts.EditPost:

post = wp.call(posts.GetPost(post.id))
post.title = 'Post with Tags'
del post.sticky
wp.call(posts.EditPost(post.id, post))

maxcutler avatar May 03 '14 16:05 maxcutler

Thanks. But "del post.sticky" raised an exception error. I have changed it to "del post.definition['sticky']" and now everything is working OK. Thanks a lot.

poustchi avatar May 04 '14 07:05 poustchi