-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoloader-sample.php
51 lines (43 loc) · 1.09 KB
/
autoloader-sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Plugin Name: Stat Collector
* Description: Adds WordPress hooks to enable the logging of data from the site to a specified MySQL database.
* Author: Blue State Digital, maintained by NYC Opportunity
*/
/**
*
*/
add_action('statc_register', function($statc) {
/**
* Hook to save data
*
* @param String $data My Data String
*/
add_action('my_action', function($data) use ($statc) {
if (gettype($data) === 'string') {
$statc->collect('my_table', [
'my_data' => $data,
]);
}
}, $statc->settings->priority, 2);
return true;
});
/**
* Creates the database tables for data if they do not exist.
*
* @param Object $db Instance of wpdb (WordPress DB abstraction method)
*/
add_action('statc_bootstrap', function($db) {
$db->query(
'CREATE TABLE IF NOT EXISTS my_table (
id INT(11) NOT NULL AUTO_INCREMENT,
my_data TEXT DEFAULT NULL,
PRIMARY KEY(id)
) ENGINE=InnoDB'
);
return true;
});
/**
* Include and initialize the plugin
*/
require plugin_dir_path(__FILE__) . '/stat-collector/StatCollector.php';