Try the following code:
add_action( 'transition_post_status', 'wpse_206193_new_user_from_custom_post', 10, 3 );
function wpse_206193_new_user_from_custom_post( $new_status, $old_status, $post )
{
if ( 'publish' !== $new_status or 'publish' === $old_status
or 'my_custom_post' !== get_post_type( $post ) )
return;
$userdata = array(
'user_login' => 'user_name',
'user_email' => '[email protected]',
'user_pass' => NULL,
'role' => 'contributor'
);
if ( !username_exists( $userdata['user_login'] ) && !email_exists( $userdata['user_email'] ) ) {
wp_insert_user($userdata);
}
}
You don’t need to fire that wp_create_user
on init
or use a separate function in the function.
Related Posts:
- Front end post editing using a form
- Get posts based on meta key/value
- Set relationship between custom_post_types
- List Categories for Custom Post Types – WordPress
- How to list custom taxonomy categories?
- How to intercept publish post for a custom post type “event”
- clients list using wordpress
- How to add relationships between custom post types?
- Can I have Post Types under other Post Types in Admin menu?
- Custom taxonomy query for a custom post type
- How to do a custom bookmarks post type?
- How do I add media to a custom post type?
- Is flush_rewrite_rules necessary when creating a custom post type? Why?
- Custom Post Type – Archive page title
- [Plugin: Posts 2 Posts] Changing display order of connections
- How to display Custom Taxonomy of Custom post type
- Custom Post Type Meta Boxes
- associate custom post type with tags with specific pages
- how to alter args of a custom post type
- Display only custom post type count for current author on the “At a Glance” dashboard widget
- How to display recent posts added in several custom post types
- Help with CPT template pagination
- Get categories and descriptions from custom post type
- Dynamically add / duplicate custom meta in custom post types
- Comprehensively Restrict Post Type Taxonomy to Logged-in Users
- Custom post template for particular posts
- Custom Post type and Custom Field WP_Query
- Repeating posts when paginating random posts
- Order By Post Type ThenBy Taxonomy
- How to show CPTs in term archive
- Custom query to filter posts that have current post as a taxonomy [closed]
- Query/list all terms and their custom post count
- Modify action buttons for custom post type
- How can I make a custom post type sticky?
- Custom Post Type Dynamically Updates other Custom Post Type
- Pagination on with query_posts in custom post type template
- How to noindex for certain custom post type without using plugins..?
- Get Taxonomy Term Title by it’s URL
- Number of Custom Post Types published are not being shown in the custom page
- Using meta_query and tax_query at the same time
- Post Type rewrite rule to point to custom Page/template
- Load Custom_post_type categories post with ajax
- Post author for revision not being set on update/insert
- Filtering results for post_type tells me I don’t have permission
- How to add multiple markers on the google map, at a certain meta_key and meta_value
- Why is my WP_Query outputting my entries twice?
- Optimise WP custom post type query
- How to solve this custom post type goes to 404 page?
- Custom Post Type with Custom Taxonomy as Category
- WP_Query() with custom post type and taxonomy — get all terms?
- How do I get the custom category URL from the custom post type?
- Associate all Custom Post Types with Taxonomy
- Is it possible to use array_walk() to append terms to an array of posts?
- Enabling permalinks disables custom page template
- pre_get_posts works in post type archive but not in single post
- 4 posts per page from single category
- Copying over taxonomy structure from one CPT to another
- Returning an image url from its attachment ID using a custom post type plugin
- CMS – User confusion when creating new page and having to select template and save first to see correct fields
- Can I set the post_type query_var as a link is clicked?
- Disable permalinks, but allow RSS feeds
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- Put featured image under post title in admin area
- How to limit the number of custom posts certain users can publish in WordPress using php script?
- Changing CPT permalink
- Using wp_insert_post for one custom type inside another custom post types’s save function – big problem
- Issue on Getting URL of Uploaded Image to a Custom Post Type
- Add liked posts to user account
- Dropdown with CPT terms redirects to 404
- How to show link to product in custom fields?
- Load custom post type with ID in a shortcode
- Missing permalink for custom post type
- Error when moving custom post type to bin
- Custom post type structure + permalink structure
- filter the title changed also the page titles
- automatic creation of custom post type articles
- How to Show all Values in category.php page using post_type
- Display a Custom Post Type within another with hierarchically slug
- Decrement term in for each
- Duplicate “Pages” Item in Admin Menu
- Updated from 3.8 to 4.2 and all post types changed to “post”
- Popup panel is only displaying 1 entry ignoring all others
- Custom post type single display is ommited
- Fetch post meta in the same query as the main loop
- Archive.php is not displaying tags
- Change custom post status to draft before today
- Include Custom Post Type Archive in wp_list_pages
- “regular” pages not found after changing permalink
- How to save an integer as taxonomy term?
- Sort custom post type items by taxonomy description
- empty dashboard for custom role
- Get all custom_post_type posts + blog posts from one category in a single query
- How to turn custom-post archive into an overview page, listing the metadata of the posts?
- Loop to pull content from parent element in custom post type [duplicate]
- How is get_the_author connected to a custom post type?
- Get custom post type parent category
- add_filter > posts_where works partially
- How to create custom page templates with default page layout framework?
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- Remote database access on another wordpress site’s custom post type