There is a syntax error in the add_action(). You’ve used a period . instead of a comma , to separate the action and the callback. Otherwise the callback seems to work as expected when I tested it locally.
The correct syntax would be,
add_action( 'pending_to_publish', 'my_function', 10, 1 );
When doing development work with WordPress it is a good idea to have debugging on. This way you can check the log file for any errors when something is not working as expected. Further reading, Debugging in WordPress.
P.S. If you want the role change to happen only when your custom post type is published, then add a post type check to the top of the callback. Like so,
function my_function( $post )
{
if ( 'portfolio' !== $post->post_type ) {
return;
}
// code...
}
Related Posts:
- Allow member to have access to custom post type only. Permission to only edit their own posts
- Allowing custom role access to custom post type in back end
- Restrict Contributors to view only their own custom post types?
- Why does my custom WP role need edit_posts to edit images?
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Defining capabilities for custom post type
- Assign a Custom Role to a Custom Post?
- Creating custom user roles
- Can I make user role that can only access a certian content type?
- Restrict a Post Types Post Status
- Create user role restricted to specific CPT
- How to set individual capabilities on a taxonomy? Or how to re-register an existing taxonomy?
- User roles – enable custom posts disable posts
- Custom Post Status not showing in Custom Post Type ALL view
- Add Capabilities to Custom Post Type after it has been created [duplicate]
- Setting a title on a Custom Post Type that doesn’t support titles
- How to restrict specific post types from being read or added by specific user roles (eg. author)?
- How do I code access to the built-in UI of a CPT when it’s placed as submenu of another CPT that is protected by role?
- Custom user role not working as expected
- How do I check if a posts status is set to draft or pending?
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- Custom Role can’t trash Custom Post Type
- Limit access to page depending on user level
- Why does current_user_can(‘edit_posts’) return true, but current_user_can(‘edit_post’, $post->ID) returns false?
- How to publish custom post type for custom role user and not “submit for review”?
- Registration and Custom Post Types – How to synchronize information?
- Gutenberg Featured-Image-panel missing when user with custom role edits Custom Post Type
- Limit users by custom taxonomy and user roles
- Allow Administrator role access to custom capabilities [duplicate]
- How to enable a custom post type to custom user role in WordPress
- Auto-generated posts not showing in backend (but being counted!)
- After adding add_role to functions.php and creating a user, can not login into admin
- How to limit post of custom post status?
- How to restrict CPT post’s fronted view only for specific user roles?
- Display content based on a users login
- Custom date changer post_date => future – missed schedule error
- Custom post types as sub menu pages and role capabilities issue
- Hiding posts by other users and non-logged in
- Only view/edit/delete CPT made by users with the same role
- How to set individual capability of post type in individual category
- WordPress comments_open for specific user role or post type
- Restrict Access to Posts based on Custom User and Post Meta Data
- I want to create custom post in which user can share files like PDF & DOCx
- WooCommerce Customer Role Delete Custom Post Type
- Update postmeta Parent when post_status child change
- Disable user from updating certain posts
- Edit the author of custom post type
- Access to CPT but not to ‘post’ post type
- Deny user access to edit post while allow him to edit custom post type
- Removing all post statuses from a Custom Post Type
- Allow user to only access custom post type
- How to show featured image block in custom post type for Author?
- How to define which register_post_status goes to which register_post_type?
- WordPress custom post type capabilities issue
- Custom User role not working with custom post type
- Building Forums with Custom Post Types
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- Published post auto change status to pending after 90 days
- Manually adding or updating CPT automatically sets post_status of future
- Clone wp-admin/users.php (Users Admin Page)
- Why “Mine” is the default view when adding ‘capability_type’ in register_post_type
- Added new role with custom capability. But cannot access the page
- Create relationship between custom post types and users
- Restrict admin pages for specific user role
- Conditional editing CPT – using editor’s role and author’s usermeta
- How to only display all posts to a custom User Role?
- Remove plugin settings from post creation page for a user role
- Show custom post status when logged out
- Allowing custom role user to edit post assigned to them but don’t let them create new custom type post
- Update post status from “publish” to “trash” prior to year 2018
- edit.php all post not working
- I want to show post details based on roles user login
- Multiple useres editing specified content
- Instructor can view, edit, delete only theirs courses
- Front-end submitted post is published with admin ID as author
- Sql Update CPT from publish to draft and particular custom field
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- Custom status and permalinks don’t work?
- Front End users account with lots of user Roles (not Woocommerce)
- Capibilities of CPT WordPress
- Editor role isn’t seeing specific post type posts with only post_type parameter
- Implement post status update as frontend news announcement
- Allow viewing the edit screen for a post type, but not make/save/publish/update changes
- date archive future posts
- Control what custom posts a user can see
- Custom Post Type only display items created by user
- Prevent author role from editing others posts
- creating different edit screens for different roles
- Default taxonomy ‘post_tag’ added to CPT managing by custom role : nothing in the metabox
- Custom taxonomy archive is visible to only subscibed users
- Custom Post Type supports author
- Custom role, capabilities, and post type: preview button wrecks things
- Custom post type & role issues
- Custom role can’t create permalink
- Read-Only custom post type
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- Comments not working (error not allowed) on posts with custom post status
- Can’t publish custom type posts that don’t support title and editor, instead they’re saved as draft
- WordPress User Role Permissions For Custom Post Type
- Allowing a CPT post to be edited by a single user role