When you click on “delete”, the action ‘delete_user’ will be launched: https://core.trac.wordpress.org/browser/tags/4.4.1/src/wp-admin/includes/user.php#L313
After that you can check, if the user has written at least one ‘portfolio’ post.
add_action('delete_user', 'sw_portfolio_check');
function sw_portfolio_check( $user_id ) {
$result = new WP_Query(
array(
'author'=>$user_id,
'post_type'=>'portfolio',
'posts_per_page'=>1,
)
);
if ( count($result->posts) !== 0 ){
wp_die("User has a portfolio and can't be deleted");
}
}
Related Posts:
- WordPress auto login after registration not working
- Execute a function when admin changes the user role
- Extending WP_User class and using this sub-class during the whole lifecycle
- How to delete all post and attachments of a user when I delete it?
- New User Save Filter
- New User ID not working in custom function with user_register hook
- Retrieve New user’s ID
- Ban a user and end their session
- How to limit users to one comment per post
- Is there an upper limit for users in WP?
- How to let user set password on registration
- Display edit link if post author is current user
- Change user’s display name programmatically
- Do not allow users to create new posts and pages
- Send activation email to user after signup [duplicate]
- wp_update_user() does not update user_data
- Set user after wp_create_user?
- Sort get_users by custom field
- How to add follow functionality to multi-author wordpress site?
- Search multiple meta keys at once
- Get user input from a form
- Redirecting user after updating profile?
- How to add new custom field in default add user form through plugin
- How to add wordpress username after url?
- ACF Upload Image in front-end with custom form
- User fields that can be edited by administrator?
- Admins can’t edit each other’s posts
- Update user_login to change username
- Multiple authors with different “author roles”
- Exclude subscriber users from user list
- Can’t add users in admin after copying database
- How can I check if a user’s email exists in the database
- Getting users by specific capability, not role
- Creating user in Firebase after WordPress user registration
- Exclude admin from user list
- How to display total number of post done by user, it should display at authors page wordpress [duplicate]
- Displaying different in-page content to cliente/admin
- Can i add password field into my wp registration form?
- User capability for editing their own comments
- Delete User via Frontend
- how to get WordPress admin user table columns name in my plugin
- Allow Contributors to Upload Files
- Limit a number of users returned from sorting users by latest posts function
- Will wordpress tools import do everything I need to copy one site to another
- Create Next and Previous Link to User orderby Last Name
- OAuth 2 and saving the authenticated user
- Spam users registers even when registration is disabled
- How to notify specific users when i’m posting/modifying a new post
- Limitations when adding new users
- User description only displayed for logged user
- Get an array of all users of a custom role type to send an email notification on post update
- Allow users to create post without logging in?
- How to get the count
- WordPress Password security related questions
- How to make Users sort in reverse order by default?
- Assign random (and unique) user meta upon registration
- How to get ID of Edit User page during wp_handle_upload_prefilter, whilst in Media picker?
- What is correct way to change user’s email?
- Display the line breaks in user bio without using html
- Get registered user’s country or IP
- Custom capability for a single user
- wp_dropdown_users() to include null value
- Adding more fields to the add user page on dashboard
- Change User Role based on Point System Issue
- Remove users access to dashboard
- Allow users to upload flash videos?
- Allow Weak Passwords
- delete_user_meta from a foreach results page
- How to display all user profile info in myaccount page wordpress
- Need to use WordPress page as authentication for different service
- How can I clone a suscriber profile in wordpress
- Reading additional fields in PMPro
- How to put the ‘assign to new user’ select when you delete a user that has custom post type posts, but no normal posts
- How can I show a button in WordPress but make it unclickable unless logged in?
- How to display extra fields for user
- Display custom user profile fields in wordpress
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- How to grab data after wp user search is complete
- How to make custom user profile page public?
- Help hooking into user_register
- Query for post term that matches user ID
- User Role not showing in Users Screen
- Change user URL
- User email verification without a plugin, is it possible?
- Deleting anonymous wp_users function not working?
- List all users based on array of domains
- Add method for tracking who referred new users
- Cloning admin pages like users.php
- User count only for role frontend vendor
- Does WordPress Need BuddyPress to Handle Large Amounts of Users?
- Using and saving custom dropdown boxes on user profiles
- Giving users an editable homepage/business directory
- Buddypress – New user type with no profile and can’t interact but can be admin of a group
- Store subscription details for users in WordPress
- Disable editing profile for second time
- No one can edit post/pages by Administrator
- How to add custom detail page for a Subscriber at Admin Panel
- How to allow users to make quizzes or tests in WordPress?
- Sorting Users page admin column with ACF field
- Can we get user profile page using user_id in the URL?