-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert to blocks in PHP #13163
Comments
@fisicx Thanks for the question and the opportunity to reflect on this. I believe the key point here is that a Post is still a Post and a Block is a smaller entity that is a constituent of a Post. The automatic conversion that you are referring to represents the designation of a paragraph with the Classic Block. Make sense? That is, if a post that your client is importing has 5 paragraphs, then the editor should contain 5 classic blocks after import. Having said that, once a post is imported and living in the WordPress database, you may choose to pull that post into a block that, for example, pulls in the latest posts for display in one area of a post or page. But going back to your original question about import, if you have a desired outcome, you could wrap the csv import in the appropriate html comments to render whatever blocks you like. |
I believe OP is asking for a the same "Convert to blocks" functionality we already have in JavaScript. In other words, a function that automatically adds these HTML comments. At the moment such a function does not exist. Mainly because block types are only registered in JavaScript and on the server you have no idea which blocks exist. However, server-side block registration is planned as per #2751. Once that is done, we will be able to provide such a function for developers. |
I have looked at adding the html comments to the content but it means I've got to do this for all possible elements. And this seems redundant when there is already a function to convert classic to blocks. I can go to 'More Options > Convert to Blocks'. I just want to be able to call a function like this when the post is created. Rather than go through each of the 100+ custom post types they import from the CSV. The people importing from a CSV are OK adding HTML tags and attributes, if I tell them they have got to learn a whole new way of doing things they won't be happy. It's this loss of simple content creation that is causing so many problems. Even more so for the thousands of plugins that use shortcodes attributes to manage content. |
That is a client-side JavaScript function, nothing that is available in PHP when importing from CSV. As I said, there is no such PHP function at the moment but this will likely be added in the future. |
Thanks for that. I will be patient. In the meantime I will have to do some basic str_replace on the more common elements. |
If you're adventurous, I think you can still use a node script running jsdom and use the |
This might help. Came accross it while researching this issue. |
Just wanted to voice my support for this issue! In the meantime, I wrote a script that automatically opens every WP post and converts it to Gutenberg by clicking the buttons on the Edit Post page. Gross, I know, but it worked for the 900 posts on our WP site. |
is there a way to hook this action onto the publish / update action so that it just automatically does it for new posts? |
Until this is possible in core you should check out convert-to-blocks by @10up |
Why are these all closed, and after 5 years still no method to solve this, yet they still expect everybody to happily jump on the Gutenberg train like these major gaps in coverage don't exist. |
A client creates posts from a CSV using a plugin that calls the wp_insert_post function.
The posts are created but all the content is in a classic editor block.
Can we have a function that automatically converts classic content into blocks. Or if there is already a way to do this programmatically where can I find the documentation?
The text was updated successfully, but these errors were encountered: