Back to Browse

Wordpress Plugin Development tutorial from scratch (Part 9) Drop Table when Plugin Uninstalls/Delete

9.0K views
Nov 16, 2017
16:05

In this video session i have explained about creating database table while plugin activation, #WordpressTutorialsPoint #WordpressLearnersHub #WordpressCustomizations #LearnWordpressStepbyStep #WordpressBySanjay Steps to do this task: #1: Create Drop table Sql Query First #2: Embed generated code to function #3: Bind with action hook First we need Sql Query to create table, =============== DROP table IF Exists wp_custom_plugin Then we have to make a seperate function to run when plugin deactivates/uninstalls, // table deleting code function deactivate_table(){ // uninstall mysql code global $wpdb; $wpdb-query("DROP table IF Exists wp_custom_plugin"); // step1: we get the id of post means page // delete the post from table $the_post_id = get_option("custom_plugin_page_id"); if(!empty($the_post_id)){ wp_delete_post($the_post_id,true); } } and Finally we have to attach with Action hook, If we want to delete table while deactivates then we should use register_deactivation_hook(__FILE__,"deactivate_table"); If we want to delete then we have to change action hook, register_uninstall_hook(__FILE__,"deactivate_table"); About 'register_uninstall_hook' Action hook https://developer.wordpress.org/reference/functions/register_uninstall_hook/ To create table while plugin activates, Click here to see: https://www.youtube.com/watch?v=nzRyFF95jXI SOCIAL : =============== Subscribe : https://www.youtube.com/channel/UCB2flCo-gW6RhpVVXySqcMg FACEBOOK : https://www.facebook.com/onlinewebtutorhub/ TWITTER: https://twitter.com/owthub BLOG: https://onlinewebtutorhub.blogspot.in/ RECOMMENDATION: =============== 1. Some knowledge of PHP, HTML for this video series 2. How to Install Wordpress: https://www.youtube.com/watch?v=MREgql9jmf0 3. register_deactivation_hook: https://developer.wordpress.org/reference/functions/register_deactivation_hook/ Also you can learn Wordpress Custom =============== Theme Development: https://www.youtube.com/watch?v=MREgql9jmf0&list=PLT9miexWCpPV9WxY_QG3qxUGKzw54LboW Widget Development: https://www.youtube.com/watch?v=ZSbdYG1svV8&list=PLT9miexWCpPUgibUXDZ7JP1j3U-m61U8m Tags =============== online web tutor, profotech solutions, wordpress plugin development from scratch in hindi, wordpress plugin development from scratch in easy steps, wordpress plugin development, wordpress plugin development in easy steps, plugin development in wordpress from scratch in hindi, plugin development in wordpress by online web tutor, plugin development in wordpress tutorials from scratch in hindi, plugin theme development tutorials in hindi, plugin development tutorials in hindi, owt tuts, Thanks Online Web Tutor Keep learning and Sharing :) -~-~~-~~~-~~-~- Please watch: "Learn backbone.js tutorial from scratch" https://www.youtube.com/watch?v=HOAU-nfy5Sc -~-~~-~~~-~~-~-

Download

0 formats

No download links available.

Wordpress Plugin Development tutorial from scratch (Part 9) Drop Table when Plugin Uninstalls/Delete | NatokHD