-
Notifications
You must be signed in to change notification settings - Fork 4
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 Shortcodes to blocks #8
Comments
Brain dump
|
@bph I have asked folks to comment on this ticket with comments/ideas/suggestions of things to cover, in the hopes that it will help uncover the hurdles folks are experiencing. I'll probably leave this open for about 2 weeks, and then get cracking once I've gathered whatever feedback I get. |
Looking at it the other way around, every block should have a shortcode! Why? Because of the dozen or so popular page builders that all understand shortcodes, but don't understand blocks. ( Or maybe, encourage all page builders to understand blocks / incorporate Gutenberg?) Assuming the former, as a plugin dev having two code lines one for blocks and one for shortcodes is a hard thing, but having three code lines, one for shortcodes, one for block editor and one for block display is even worse. This is just random thoughts, not structured. My path has probably been a typical PHP/jQuery path of many devs in this space, so a jump into REACT for just the editor is a steep learning curve which I'm maybe 6 months into and only scratching the surface. Shortcodes are dead easy, just a couple of lines of PHP with a text editor and you are up and running. Blocks are harder unless you have a local dev env, node / npm installed then create_block is useful, but a as plugin dev it was no use until the recent --no-plugin option was released. But there still is the unanswered question in my head 'What is the appropriate architecture for a block/shortcode plugin without duplicating functionality across the code lines'. |
I have converted several shortcodes to blocks, and the one thing I still struggle with is getting data, such as posts and users. For some reason, I never wrote a simple shortcode. :) Here are some examples that I painstakingly cobbled together:
When I was building those bits of code, I never felt like there were any good resources for getting the data I needed on the JS side (something that has always felt super easy in PHP). "Getting data and doing something with it" is probably one of the most important things for plugin developers, so any extra focus in that area helps. |
The main hurdle is the tooling around here and not fully understanding webpack. We tweak the wordpress/scripts webpack to adjust the entry and output points to fit our file structure. What we need is to output to assets/js and entry point would be /blocks (with various subfolders). Right now, it nukes everything in the assets/js whenever you use wp-scripts start or build. Not sure if this is a NPM version thing or if there's a setting we can use to keep pre-existing files (other .js files for plugin frontend/admin etc) and just rebuild the files we need (i.e. blocks.build.js). Also a standardized file structure for blocks (within a plugin) would help us, this is something we're working on for our own team (not paving the way for WP) but with the ever evolving tools and understanding of blocks we need to neaten this up internally as we built blocks before wp-scripts was a thing or we just didn't know about it (I can't remember 5 years ago what was our thought approach). We have moved over to wp-scripts ever since which made things easier but still gets confusing to troubleshoot this when things don't work. Our goal now is to to move to a set file structure and webpack config in upcoming plugins that already have shortcodes and other /js files. We have made some workarounds but I don't feel that these are ideal. Here is an example where we adopted blocks early on and you may see the file structure we'd typically work with - https://github.com/strangerstudios/paid-memberships-pro (Most of our shortcodes and pages have turned into blocks to make working with our plugin easier). +1 for justin's comment, getting data wasn't easy and often confusing (when coming from PHP to REACT). |
TIL about the core-data package! I just ended up using apiFetch package and DIYing it. Might be useful to cover both options |
@jonathanbossenger Start with 3. Not every Shortcode should be a block! Good luck! Thanks for commenting also @andrewlimaza - That's in interesting observation. Come to think it if, I am also confused about how Webpack and WordPress packages interact, and it would be a great separate blog post for the new site. What do you think? |
@bph this sounds like a good plan. I'd also be happy to write the "how Webpack and WordPress packages interact" blog post as a sort of "follow-up" once this post is published. |
General outline
|
"how Webpack and WordPress packages interact" @andrewlimaza @jonathanbossenger I created a discussion under ideas to see what other people would need to learn in that regard. Please share with your colleagues and network so people can chime in. So this issue can be about @jonathanbossenger's blog post moving forward. |
Update: This weekend I completed the first rough draft of this post. During the course of this week, I plan to review/edit the post, create relevant screenshots, and test my code examples. I'm working towards having this ready for review by the end of this week. |
Quick update here, I've had to put this on hold for a bit, as I need to wrap up my second block theme course (by end of this week). I hope to pick it up and have it ready for peer review next week. |
@jonathanbossenger Thanks for the update! |
That wouldn't work, because I'd just get the clone to do my work, and I'd spend all day doing other things...😁 |
Update, I had some time this week to work on the draft, and it's almost there https://gist.github.com/jonathanbossenger/e0f3337325a72fa5ee1c2efa9f9696e1 I need to write the final section, add some images, and do a final review, which I should get done next week. |
That sounds great. When you feel you are ready for review, could you please
Looking forward to reading your post 👏 You should have access to the blog already. Let me know if there is trouble. 😋 |
Picking this up this week. |
This post is now ready for review https://developer.wordpress.org/news/?p=520&preview=1&_ppp=f9621ab6b7 |
In progress: @bph doing first review, @abhansnuk doing second review. Adding this to test my GitHub access on this as there was a problem earlier with a laptop change. I had volunteered to read some of the beginner items. Nalini |
Feedback / ReviewThis is a great hands-on tutorial. The discussion of when and when not to create a block for short code functionality is fabulous. From the depth of the content I would categorize this not as a beginner tutorial, so keeping the getting started part short would be best. At the moment, it does a bit too much before it actually gets to the meat of the matter. It is an excellent journey description from your duplicate code to Custom Components, great use case for JSX. I really enjoyed the reading and learn something. I have a few suggestions on how to streamline the beginning and the end of things. I might be a little overzealous in suggestions on where to cut. Please don't take it the wrong way. I think this tutorial is fantastic in what it teaches, and it will be successful if aimed at users who have a more advanced knowledge, and assume the reader already have beginner knowledge. Getting startedYou could shorten the runway, so to speak, in the getting started section, by referring to two official sources. Video EmbeddingInstead of embedding the create-block video taking away too much space from the heart of the post, suggest just linking to it. The other links should go in the Resources section. Not every short code should be a blockYou should have the discussion on “Not every shortcode should be a block!” after the ‘Getting Started’ piece. The example for not creating a block for the [time] short code is a great one, and it could use a bit more detail. It would gain some immediate insight for the reader if you add a front end view of this particular short code, as it would show that's rendered inline in a paragraph. Then you could mention that kind of inline rendering is not possible with Gutenberg right now. There are some first attempts to find a way to make those dynamic strings possible without using a short code, but it's not available yet. If someone wants to dive into this discussion, it is very fascinating Discussion, with a draft PR for implementation. External Links
External Link policy is for now really strict. You could link to React itself and its introduction tutorial. https://reactjs.org/tutorial/tutorial.html Links need to have a descriptive text (title of the post/document) + URL not just the blank urls. As mentioned, the videos should go into the Resource section. I would think you wrote most of what you said in the video also in this post, and if not, you might include it in your post. Visuals beyond CodeThe tutorial would gain a lot if you could also show editor views on your examples in addition to the code examples. That way the reader gets a mental image to see a difference between classic editor short code view and block editor view. Code BlocksIf you select a language from the Code block sidebar, you get some nice color coding added to your code examples. You could add the “Example HTML” as Title to the code block settings. Recommendation is if you have under the same heading more than one code example, you should add a title to each code block. Resources to learn more"Where to find help" - Maybe retitle to "Resources to learn more"
The #core-editor channel is not really meant for developer support. You can also offer to comment on the post with questions, that's immediate, and we can handle that. Discussions on the Gutenberg Repo are a good place, or StackExchange. |
Thanks for the feedback @bph will review and implement |
Hello @bph and @abhansnuk I've completed the update to the post based on the feedback, so this is ready for the second review. |
Thanks @jonathanbossenger could you share a public preview link please? The earlier one has expired. Thanks. Looking forward to reading this and thanks for incorporating all the comments. |
Sure, here is the new preview link https://developer.wordpress.org/news/?p=520&preview=1&_ppp=6ca85b2512 |
I took another look, and we are almost ready to publish.
Here is the pre-publish check list.
The tips and guidelines for writers you already read, so this is just a reminder. this sentence is a bit awkward. "Through my connections in the WordPress community, I was able to make connections with a few folks who were willing to help me answer specific questions." only marginally better, but maybe this works? Please check the excerpt, and update the props section... |
That amendment by @bph would be my suggestion too, it keeps the essence of what is said. I can do the second review in a few hours depending on another doc I am looking at on the release, and if not in my tomorrow afternoon (UTC). |
@jonathanbossenger could we update the post to include https://learn.wordpress.org/course/converting-a-shortcode-to-a-block/ ? |
@juanmaguitar good idea, done! ✅ |
by @jonathanbossenger
Case study of how to approach shortcut conversion, using Seriously Simple Podcast plugin for some "real world" examples, that now has both, regular blocks and the dynamic rendering option, based on the requirements of the block.
The text was updated successfully, but these errors were encountered: