-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoosenews.php
executable file
·74 lines (64 loc) · 2.09 KB
/
moosenews.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Moose News
*
* @wordpress-plugin
* Plugin Name: Moose News
* Description: [Обсудить] page for <a href="http://rcmp.me">RCMP.me</a>
* Version: 1.0.0
* Author: brevis
* Author URI: https://twitter.com/brevis_ua
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Text Domain: moosenews
*/
// If this file is called directly, abort.
if (!defined('WPINC')) die;
/**
* The code that runs during plugin activation.
*/
register_activation_hook(__FILE__, function() {
global $wpdb;
// Create DB tables
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$table_name = $wpdb->prefix . MooseNews::NEWS_TABLE;
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id int(11) NOT NULL AUTO_INCREMENT,
user_id int(11) NOT NULL,
content text COLLATE utf8_unicode_ci NOT NULL,
postdate DATETIME,
rating int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
) $charset_collate;";
dbDelta($sql);
}
$table_name = $wpdb->prefix . MooseNews::VOTES_TABLE;
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
user_id int(11) NOT NULL,
news_id int(11) NOT NULL,
vote_type ENUM('up', 'down')
)";
dbDelta($sql);
}
// add options
add_option('moosenews_form_position', 'down');
add_option('moosenews_message_maxlength', 5000);
add_option('moosenews_message_minlength', 10);
return true;
});
/**
* The core plugin class that is used to define internationalization,
* dashboard-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path(__FILE__) . 'includes/MooseNews.php';
/**
* Begins execution of the plugin.
*/
function run_moosenews() {
$plugin = new MooseNews();
$plugin->run();
}
run_moosenews();