· 6 years ago · Jun 25, 2019, 03:14 PM
1// main plugin file, frequentVisitorCoupons.php
2require 'vendor/autoload.php';
3
4// the first argument points to this file because I think
5// autoload automatically loads the Utilities class here
6register_activation_hook(plugin_dir_url(__FILE__) . 'frequentVisitorCoupons.php',
7 'Utilities::createTablesIfNotExists');
8
9
10// classes/utilities.php
11<?php
12class Utilities {
13 public static function createTablesIfNotExists() {
14 global $wpdb;
15
16 $createCouponTableQuery = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}frequentVisitorCoupons_coupons (
17 couponId MEDIUMINT NOT NULL AUTO_INCREMENT UNIQUE,
18 PRIMARY KEY (couponId),
19 totalHits MEDIUMINT NOT NULL,
20 isText BOOLEAN NOT NULL,
21 imageUrl TEXT(1000)
22 )";
23
24 <2 more table create queries removed>
25
26 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
27 dbDelta($createCouponTableQuery);
28
29 var_dump($wpdb->queries);
30 echo <<<'EOD'
31 =====$wpdb->queries=====
32EOD;
33 }
34}