开发者

How to change page author in wordpress if user dont have permission to publish pages?

开发者 https://www.devze.com 2022-12-29 10:30 出处:网络
The thing is that i am using \"User Role Editor\" and i have one user group that can read and edit published pages. Now, i will be adding all the pages on that site, and we will have several use开发者

The thing is that i am using "User Role Editor" and i have one user group that can read and edit published pages. Now, i will be adding all the pages on that site, and we will have several use开发者_如何学JAVArs that will need to have only one page they can edit, so i need for that page to change "Page author" to that user. In case you didnt know, when user have "Edit published pages" enabled they can edit only pages where they are listed as author.

Problem is i can only do that by going in phpmyadmin and changing the page_author field to the id of that user because that user group, like i said, can only read and edit published pages. That is why i can not change page author from "Edit page" page to user from that user group.

So my question is: does anyone know any solution to this problem which does not involve me going to phpmyadmin and changing the id for page_author there?


You could try temporarily giving these users the ability to edit all pages (I think the capability is something like 'edit_others_pages'), creating all your pages and assigning them to the correct user, and then revoking the capability.


I found a hack which enabled me to change the author of a page to any users. For me I wanted to change the author of all of my pages to a user who has a custom role (created by the Roles plugin).

To do this I went to pages, selected them all, and hit bulk edit. I inspected the Author dropdown box using chrome dev tools and then edited one of the select options. Change the value of the select to the ID of the user who you want to take ownership** (you can change the inside html as well to make it more clear what you are doing) and then click out of editing more.

Now you will be able to drop down to the field that you changed and then hit update, and the ownership should change over.

I'm not sure exactly what the restrictions are in what caps the user has to have in order to do this, however it worked a treat for me.

**to find this go to users and hover over edit on the user, and it will show up in the url (same as finding post ids etc)

EDIT:

Instead of doing this I edited the WP core. There is probably a better way to do this but I edited class-wp-posts-list-table.php, around line 775 it sets $users_opt as the params for the later call to $authors = wp_dropdown_users( $users_opt ). If you comment out the param 'who' => 'authors', then WP will list ALL users (including subscribers admin etc - everyone).

If you check the documentation you'll notice that the 'who' param only takes author or all at the moment. I assume later it will be able to take other role types.


check the pages (while you are on "All Pages"), and select bulk edit from drop down and change the author..


Only temporalily changing user's role worked for me. Then set him as author, then change back.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号