-
Notifications
You must be signed in to change notification settings - Fork 94
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
Tutorial - Custom Database Tables #1867
Comments
You might consider making the title more specific - such as Custom Database tables - so that it is not confused with html tables, the table block in site content or selecting a table-specific plugin. Or direct it toward developers rather than users. |
That's a good point @SierraTR, edited. |
WIP video for review: Custom.Database.Tables.mp4In preparing this video for review, I realized there are two fixes I need to make
I will make sure to fix those before the video is published. |
Hello @jonathanbossenger , I thoroughly enjoyed your tutorial and here is what I noted during the video:
Great tutorial and I wouldn't change a thing about it other than the two items you mentioned above. |
Great tutorial @jonathanbossenger my only question is why did the custom table docs not get migrated from codex? |
I honestly don't know @digitalchild, you'd have to ask the docs team. If I had to guess, probably because no one knew to migrate certain Codex docs, or there wasn't a logical place for them in the new developer docs. |
Thank you @TinaCollier and @digitalchild for the reviews. |
This content is ready to be reviewed. Please follow the steps listed under Guidelines for reviewing content. Thank you for your contribution! ✨ |
@jonathanbossenger I have watched the preview and it looks great. I don't have much feedback to add. I think the tutorial is clear and serves its purpose. |
@jonathanbossenger I just watch the preview and I think it's great. There were a few thing that came to mind as I was watching.
|
@juanmaguitar thank you for the reivew |
@ryanwelcher thank you for the review, and the detailed feedback.
That is a great point, and worth mentioning in the tutorial.
That's a great question. It's sort of one of the reasons I didn't want to even mention inserting and updating data using query, but I do get your point. What about if we add this at the end of that section?
So I do want to dive more into custom tables in the future, including something about how one might manage the actual upgrade routine, and what to do if queries fail, etc. If it's ok with you, I'll leave this idea for that follow-up tutorial. This one was more of an "introduction to" style tutorial
That's a very valid point, and something that I left out of this tutorial, but included in the workshop. What I actually said in the workshop was that one should typically let the user decide if they want to clean up the data or not, and then use the relevant hook, but this got left out of the tutorial script somewhere along the line. Based on the other feedback above, what about this as an update to that "Cleaning up" section Cleaning upIt's also possible to delete your custom tables. To do this, you can use the
You should try to never use the Depending on your requirements, or the requirements of your plugin's users, you could delete the table in two ways. If your plugin users will not need the data in this table if they deactivate the plugin, you could trigger this on the plugin deactivation hook.
However, if the data in that table is important, and your users might want to keep it, even if the plugin is deactivated, you could delete the table using one of the two uninstall methods available to plugins. For example, if you choose to use the register_uninstall_hook.
It's generally recommended to check with your user and then use one of the uninstall methods over plugin deactivation. |
@jonathanbossenger that sounds great! Thanks for putting up with me :) |
The tutorial seems to be excellent, considering that it covers the entire CRUD process. The code examples are all well-organized. However, as I mentioned in the previous review, it is difficult to include all aspects in a short video, including best practices. For review: It is important to emphasize and explain to the user that certain practices were used only to illustrate a concept, but are not recommended. |
@ryanwelcher not at all, I appreciate the feedback and correction. |
Thanks for your review @Zebedeu
I'm just checking, do you feel that this needs to be added, or that this idea is already covered in the tutorial? |
Yes, this information is important and should be included in the tutorial. It is essential to emphasize to the user that when creating custom tables in WordPress, it is crucial to version them to control and update the table structure if necessary. Additionally, it is important to note that this technique allows for updates to be applied consistently without compromising the integrity of the stored data in the table. Therefore, versioning is a valuable and indispensable resource for managing custom tables in WordPress. |
@Zebedeu thanks for your feedback. As I mentioned to another reviewer in an earlier comment I do think that a follow-up tutorial on custom tables would be good here:
The problem exists in balancing the limitation of creating a tutorial video 5-10 minutes long, keeping the content engaging and easier to follow for viewers, without trying to rush through all the available information about a specific topic. Quite honestly, the topic of custom tables could be a series of tutorials, even a short course on the subject. So I just want to make sure I understand your specific review feedback here, as I think there are two action items:
Would you agree that a follow-up tutorial (or tutorials) including things like versioning, what to do if queries fail, and other topics related to custom tables would make sense? Additionally, if you're interested, this might be content you or another contributor might be interested in working on. |
@ryanwelcher for the "if table exists check" on inserting data, would you be happy with using function insert_record_into_table(){
global $wpdb;
$table_name = $wpdb->prefix . 'custom_table';
$table_exists = $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" );
if ( $table_exists ) {
$wpdb->insert(
$table_name,
array(
'time' => current_time( 'mysql' ),
'name' => 'John Doe',
'text' => 'Hello World!',
'url' => 'https://wordpress.org'
)
);
}
}
|
Explaining the why here is probably more important than the implementation but that looks great to me and demonstrates the steps perfectly. |
Thanks @ryanwelcher. I'm wondering now if this item, as well as the items about when to create tables and when to delete them, should be in the follow-up tutorial. What I'm thinking is: This tutorial = the basics of creating, inserting data, updating, and deleting custom tables (aka the theory) Follow-up tutorial = how you would actually implement this with real-world examples (aka in practice)
This would be similar to another two-part series I did recently on plugin vulns:
I'm thinking of this in terms not only of being able to create courses based on this content, where one small step follows the next, but also in terms of the learning pathways project. Thoughts? |
@jonathanbossenger that sounds like a good approach to me. It would be very easy to overwhelm the user with all of the nuances in a single tutorial and splitting them out mitigates that and allows you to spend more time on each. |
Thank you @ryanwelcher I appreciate your experienced feedback on this topic. |
Topic Description
While the default WordPress database schema is perfect for most content-related data types, there may be instances where you need to create custom tables in a WordPress database. One example of this is when a plugin has a specific use case that extends beyond what the custom post-type functionality of WordPress offers. In this tutorial, you will learn how to create and manage custom WordPress database tables, how to interact with these tables, and some maintenance considerations.
Related Resources
Links to related content on Learn, HelpHub, DevHub, GitHub Gutenberg Issues, DevNotes, etc.
Guidelines
Review the team guidelines
Tutorial Development Checklist
The text was updated successfully, but these errors were encountered: