-
Notifications
You must be signed in to change notification settings - Fork 0
/
dr-redirect.php
149 lines (116 loc) · 3.2 KB
/
dr-redirect.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Plugin Name: Delektre Redirect
* Plugin URI: http://www.delektre.fi
* Description: A brief description about your plugin.
* Version: 1.0.0
* Author: Tommi Rintala
* Author URI: http://www.delektre.fi/tommi.rintala
* License: GPLv2
* Domain Path: /dr-redirect
*/
defined('ABSPATH') or die('No script kiddies please!');
define('DR_VERSION', '1.0.0');
define('DR_DIR', plugin_dir_path(__FILE__). '/dr-redirect');
define('DR_URL', plugins_url(__FILE__) . '/dr-redirect');
function dr_plugin_install() {
}
function dr_plugin_uninstall() {
}
function dr_db_install() {
global $wpdb;
$table_name = $wpdb->prefix . "_dredir";
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT NOW(),
src_url text NOT NULL,
src_title text NOT NULL,
dst_url text NOT NULL,
enabled int DEFAULT 0
) $charset_collate;";
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
dbDelta( $sql );
update_option('dr_db_version', DR_VERSION);
}
function dr_update_db_check() {
if ( get_site_option('dr_db_version') != DR_VERSION) {
dr_db_install();
}
}
add_action('plugins_loaded', 'dr_update_db_check');
function dr_register() {
}
function dr_activation() {
}
function dr_insert_rule() {
global $wpdb;
$table_name = $wpdb->prefix . "_dredir";
$wpdb->insert(
$table_name,
array(
'src_url' => '',
'dst_url' => '',
'src_title' => '',
'enabled' => 0
),
array(
'%s', '%s', '%s', '%d'
)
);
}
function dr_update_rule($ruleid, $src_url, $src_title, $dst_url, $enabled) {
global $wpdb;
$table_name = $wpdb->prefix . "_dredir";
$wpdb->insert(
$table_name,
array(
'src_url' => $src_url,
'dst_url' => $dst_url,
'src_title' => $src_title,
'enabled' => $enabled
),
array('id' => $ruleid ),
array('%s', '%s', '%s', '%d')
);
}
function dr_delete_rule($ruleid) {
global $wpdb;
$table_name = $wpdb->prefix . "_dredir";
$wpdb->delete(
$table_name,
array('id' => $ruleid)
);
}
function dr_create_menu() {
// create top-level menu
add_menu_page('DR Redirect', 'DR Redirect', 'administrator', __FILE__,
'dr_settings_page', plugins_url('/images/icon.png', __FILE__));
// call register settings function
add_action('admin_init', 'dr_register_settings');
}
function dr_register_settings() {
register_setting('dr_redirect_site', 'sitename');
}
function dr_settings_page() {
?>
<div class="wrap">
<h2>Redirect settings</h2>
<form method="post" action="dr-redirect.php">
<table class="wp-list-table widefat fixed striped posts">
<tr valign="top">
<th>Enabled</th>
<th>Src URL</th>
<th>Src Title</th>
<th>Dst Page</th>
</tr>
</table>
<?php submit_button ?>
</form>
<?php
}
if (is_admin()) {
add_action('init', 'dr_register');
// register_activation_hook(__FILE__, 'dr_activation');
add_action('admin_menu', 'dr_create_menu');
}