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
- Possible to hide Custom Post Type UI/Menu from specific User Roles?
- New post status for custom post type
- Custom post type role permissions won’t let me read
- 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?
- Custom user role cannot see or modify featured image
- How to assign specific users the capability to edit specific pages / posts / custom post types
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Allow user to Edit Posts but not Add New?
- Defining capabilities for custom post type
- Assign a Custom Role to a Custom Post?
- Restrict custom post type view by user role
- Creating custom user roles
- Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter
- Can I make user role that can only access a certian content type?
- Associating an “author” with a custom taxonomy
- Restrict a Post Types Post Status
- Custom post status and preview
- 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]
- How to not allow custom roles to edit published custom post types?
- 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 can I get the last posts by user role?
- 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
- delete custom post based on custom field date
- Which User Role for Custom Post Type Menu – wp_nav
- Adding capabilities to default roles
- How do I check if a posts status is set to draft or pending?
- Error after deleting Custom Post Type with a function (no trash used)
- How to set default status to custom post type
- grant a privilege for roles (for example editors) and higher
- Prevent author role from editing all posts in custom post type?
- 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
- Role Capabilities: Add New Ones?
- 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”?
- Prevent authors from creating new posts of specific custom-post-type
- Custom post type capabilities require “create_posts” to access the edit posts list page
- 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
- 1 day after custom date change post status to draft
- Add custom capabilities to existing custom post type
- allow edit of custom post type but not regular posts?
- Allow Administrator role access to custom capabilities [duplicate]
- using add_role function to make some users to create a selected type post
- How to enable a custom post type to custom user role in WordPress
- Why is my Custom Post Type not showing up after adding capabilities?
- Auto-generated posts not showing in backend (but being counted!)
- Cannot attach media when capabilities added to custom post type
- After adding add_role to functions.php and creating a user, can not login into admin
- Restrict user to only one custom post type
- How to limit post of custom post status?
- only a certain role has access to a cpt
- How to restrict CPT post’s fronted view only for specific user roles?
- current_user_can() return FALSE but debugging says TRUE
- Role capability delete multiple post type posts doesn’t work
- How to allow a custom user role to create, edit, delete a specific custom post type only?
- Display content based on a users login
- map_meta_cap woes
- Roles for Custom Post Types
- Role scoping for contributors down to the field level
- Custom date changer post_date => future – missed schedule error
- can’t see custom post content filtered under “mine” filter in admin panel
- Define new user capability for custom post types?
- Custom post types as sub menu pages and role capabilities issue
- Hiding posts by other users and non-logged in
- WordPress multiple custom post types capability conflict in a single menu
- 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
- Giving permission to anyone (non-users as well) with a password to edit a post, possible?
- Featured image overlay when changing post status
- I want to create custom post in which user can share files like PDF & DOCx
- Custom post type suppress transition from future to publish
- WooCommerce Customer Role Delete Custom Post Type
- Custom role, capabilities, and post type: preview button wrecks things
- Reservations as Post
- Custom post type & role issues
- Custom role can’t create permalink
- empty dashboard for custom role
- Read-Only custom post type
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- WordPress Roles
- Comments not working (error not allowed) on posts with custom post status
- Need some suggestions with Relationship fields and CPT/ACF
- Can’t publish custom type posts that don’t support title and editor, instead they’re saved as draft
- Frontend delete CPT post with custom role user
- WordPress User Role Permissions For Custom Post Type
- Allowing a CPT post to be edited by a single user role