| 1 |
<?php |
| 2 |
/** |
| 3 |
* Statify: Statify_Table class |
| 4 |
* |
| 5 |
* This file contains class for the plugin's DB table handling. |
| 6 |
* |
| 7 |
* @package Statify |
| 8 |
* @since 0.6 |
| 9 |
*/ |
| 10 |
|
| 11 |
// Quit if accessed outside WP context. |
| 12 |
defined( 'ABSPATH' ) || exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* Statify Table |
| 16 |
* |
| 17 |
* @since 0.6 |
| 18 |
*/ |
| 19 |
class Statify_Table { |
| 20 |
|
| 21 |
/** |
| 22 |
* Definition of the custom table. |
| 23 |
* |
| 24 |
* @since 0.6.0 |
| 25 |
* @version 1.2.4 |
| 26 |
*/ |
| 27 |
public static function init() { |
| 28 |
|
| 29 |
// Global. |
| 30 |
global $wpdb; |
| 31 |
|
| 32 |
// Name. |
| 33 |
$table = 'statify'; |
| 34 |
|
| 35 |
// As array. |
| 36 |
$wpdb->tables[] = $table; |
| 37 |
|
| 38 |
// With prefix. |
| 39 |
$wpdb->$table = $wpdb->get_blog_prefix() . $table; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Create the table. |
| 45 |
* |
| 46 |
* @since 0.6.0 |
| 47 |
* @version 1.2.4 |
| 48 |
*/ |
| 49 |
public static function create() { |
| 50 |
|
| 51 |
global $wpdb; |
| 52 |
|
| 53 |
// If existent. |
| 54 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->statify'" ) === $wpdb->statify ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
// Include. |
| 59 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 60 |
|
| 61 |
// Create. |
| 62 |
dbDelta( |
| 63 |
"CREATE TABLE `$wpdb->statify` ( |
| 64 |
`id` bigint(20) unsigned NOT NULL auto_increment, |
| 65 |
`created` date NOT NULL default '0000-00-00', |
| 66 |
`referrer` varchar(255) NOT NULL default '', |
| 67 |
`target` varchar(255) NOT NULL default '', |
| 68 |
PRIMARY KEY (`id`), |
| 69 |
KEY `referrer` (`referrer`), |
| 70 |
KEY `target` (`target`), |
| 71 |
KEY `created` (`created`) |
| 72 |
);" |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* Remove the custom table. |
| 79 |
* |
| 80 |
* @since 0.6.0 |
| 81 |
* @version 1.2.4 |
| 82 |
*/ |
| 83 |
public static function drop() { |
| 84 |
|
| 85 |
global $wpdb; |
| 86 |
|
| 87 |
// Remove. |
| 88 |
$wpdb->query( "DROP TABLE IF EXISTS `$wpdb->statify`" ); |
| 89 |
} |
| 90 |
} |
| 91 |
|