Preview custom post types and warn if not currently registered
This was an easy mistake to make. Having decided to give the new code something to chew on, importing content from many sites into one new WPMS site, including content from an existing WPMS network, I forgot to install and activate all the required plugins. Consequently the importer failed to import posts of a particular CPT.
It would be nice if the import file could be previewed and problems like this pointed out in advance. BTW: I would have let it import the content even though the post type wasn't registered.
I see no harm in importing the content when the post type doesn't exist. I mean it could perhaps show a small notice, but why should it prevent you from importing the post?
@swissspidy Permissions may be bothersome. You can't know the permissions of a post type until it's registered.
I don't have any problems with permissions. What difference would it make? To whom would the unregistered posts be visible? In my experience, the person performing the import would probably rather see the import succeed than fail.
If you import an unknown post type without an author, it will assign that to the current user. If the post type is later registered, you may not have permission to create posts in that post type, yet you will have posts that belong to you anyway.
As an example: imagine you have permission to write posts on a site, but not create WooCommerce plugins. During some maintenance, WooCommerce is disabled. You run an import containing products, which then get assigned to you. WooCommerce is re-enabled some time after the import. Despite not being able to create/edit products, you now have them :)
My scenario outline would entail a privacy case, if the post type defines exclude_from_search: true and/or publicly_queryable: false, if the plugin that registers these posts isn't activated then whatever data is contained within those posts that be published, if the site they were imported on is connected to the internet and publicly available then that data is now public.
@ntwb I tested your scenario using WordPress and my oik-types plugin.
- I created a post type called "books" which was public but excluded from search and not publicly queryable.
- I created some posts
- And viewed them using ?p=id and permalinks
- I then deactivated my plugin
I then tried to access them:
- The posts were not accessible through the front end
- BUT, a shortcode to display a link to one of these posts did produce a permalink - but following the link resulted in a 404.
- other shortcodes failed to find them.
The above tests were performed when logged in as admin.
My conclusion. WordPress protects post types which are not registered. It's not something that WordPress-Importer should be worried about.
OK, can we go back to the original point. It would be nice if the UI displayed the count of each CPT and offered the user the option of importing the post type or not. If the post type was not currently registered then it would also be nice to indicate this. It then becomes the user's responsibility to decide how to proceed.