Creating settings upon plugin activation

The activation process of a plugin is handled by the built-in register_activation_hook function. In this scenario, we are developing a simple plugin to illustrate the importance of concepts in plugin development. Here, we will be using the built-in activation event to initialize the settings and data for this plugin, instead of creating separate installation process. Add the following code to the wpquick-post-attachments.php file, after the header comments section:

register_activation_hook( __FILE__, 'wpqpa_activate' );function wpqpa_activate(){  global $wpdb;  $table_attachments = $wpdb->prefix . 'wpqpa_post_attachments';  $sql_attachments = "CREATE TABLE IF NOT EXISTS $table_attachments ( id int(11) ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.