PressTigers

How to create Custom Database Table on Plugin Activation

You might require a custom database table to store your records originating from your custom plugin. You can utilize WordPress’ hook named “register_activation_hook” to perform any task when a plugin is activated. From this article, you will learn how to make a custom database table with some essential fields once plugin is activated.

You can utilize the following code to create another table in your database on plugin activation:

The hook will be called on activation that will further proceed to a function provided in the parameters i.e. “pt_my_activation_function”. This function defines a global variable and runs a query to create a new table in the database. $wpdb->prefix will automatically get the prefix of your database already in use. You can change the query as per your requirements.

User Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Get in Touch