📄 upgrade-functions.php
字号:
maybe_add_column($tableposts, 'post_content_filtered', "ALTER TABLE $tableposts ADD `post_content_filtered` TEXT NOT NULL");
maybe_add_column($tablecategories, 'category_nicename', "ALTER TABLE `$tablecategories` ADD `category_nicename` VARCHAR(200) NOT NULL");
maybe_add_column($tablecategories, 'category_description', "ALTER TABLE `$tablecategories` ADD `category_description` TEXT NOT NULL");
maybe_add_column($tablecategories, 'category_parent', "ALTER TABLE `$tablecategories` ADD `category_parent` INT(4) NOT NULL");
maybe_add_column($tablelinks, 'link_rss', "ALTER TABLE `$tablelinks` ADD `link_rss` VARCHAR( 255 ) NOT NULL;");
maybe_add_column($tableusers, 'user_description', "ALTER TABLE `$tableusers` ADD `user_description` TEXT NOT NULL");
maybe_add_column($tablecomments, 'comment_approved', "ALTER TABLE $tablecomments ADD COLUMN comment_approved ENUM('0', '1') DEFAULT '1' NOT NULL");
// Create indicies
add_clean_index($tableposts, 'post_name');
add_clean_index($tablecategories, 'category_nicename');
add_clean_index($tablecomments, 'comment_approved');
// Options stuff
if (!$wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'comment_moderation'")) {
$wpdb->query("INSERT INTO $tableoptions
(option_id, blog_id, option_name, option_can_override, option_type, option_value, option_width, option_height, option_description, option_admin_level)
VALUES
('0', '0', 'comment_moderation', 'Y', '5',' none', 20, 8, 'If enabled, comments will only be shown after they have been approved.', 8)");
}
$oid = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'comment_moderation'");
$gid = $wpdb->get_var("SELECT group_id FROM $tableoptiongroups WHERE group_name = 'General blog settings'");
$seq = $wpdb->get_var("SELECT MAX(seq) FROM $tableoptiongroup_options WHERE group_id = '$gid'");
++$seq;
if (!$wpdb->get_row("SELECT * FROM $tableoptiongroup_options WHERE group_id = '$gid' AND option_id = '$oid'")) {
$wpdb->query("INSERT INTO $tableoptiongroup_options
(group_id, option_id, seq)
VALUES
('$gid', '$oid', '$seq')");
}
if (!$wpdb->get_row("SELECT * FROM $tableoptionvalues WHERE option_id = $oid AND optionvalue = 'auto'")) {
$wpdb->query("INSERT INTO $tableoptionvalues
(option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
VALUES
('$oid','auto', 'Automatic', NULL, NULL, 3)");
}
if (!$wpdb->get_row("SELECT * FROM $tableoptionvalues WHERE option_id = $oid AND optionvalue = 'none'")) {
$wpdb->query("INSERT INTO $tableoptionvalues
(option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
VALUES
('$oid', 'none', 'None', NULL, NULL, 1)");
}
if (!$wpdb->get_row("SELECT * FROM $tableoptionvalues WHERE option_id = $oid AND optionvalue = 'manual'")) {
$wpdb->query("INSERT INTO $tableoptionvalues
(option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
VALUES
('$oid', 'manual', 'Manual', NULL, NULL, 2)");
}
if (!$wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'moderation_notify'")) {
$wpdb->query("INSERT INTO $tableoptions
(option_id, blog_id, option_name, option_can_override, option_type, option_value, option_width, option_height, option_description, option_admin_level)
VALUES
('0', '0', 'moderation_notify' , 'Y', '2', '1', 20, 8, 'Set this to true if you want to be notified about new comments that wait for approval', 8)");
}
$oid = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'moderation_notify'");
$seq = $wpdb->get_var("SELECT MAX(seq) FROM $tableoptiongroup_options WHERE group_id = '$gid'");
++$seq;
if (!$wpdb->get_row("SELECT * FROM $tableoptiongroup_options WHERE group_id = '$gid' AND option_id = '$oid'")) {
$wpdb->query("INSERT INTO $tableoptiongroup_options
(group_id, option_id, seq)
VALUES
('$gid', '$oid', '$seq')");
}
// Get the title and ID of every post, post_name to check if it already has a value
$posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $tableposts WHERE post_name = ''");
if ($posts) {
foreach($posts as $post) {
if ('' == $post->post_name) {
$newtitle = sanitize_title($post->post_title);
$wpdb->query("UPDATE $tableposts SET post_name = '$newtitle' WHERE ID = '$post->ID'");
}
}
}
$categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $tablecategories");
foreach ($categories as $category) {
if ('' == $category->category_nicename) {
$newtitle = sanitize_title($category->cat_name);
$wpdb->query("UPDATE $tablecategories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'");
}
}
if (!$wpdb->get_var("SELECT option_name FROM $tableoptions WHERE option_name = 'permalink_structure'")) { // If it's not already there
$wpdb->query("INSERT INTO `$tableoptions`
(`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`)
VALUES
('', '0', 'permalink_structure', 'Y', '3', '', '20', '8', 'How the permalinks for your site are constructed. See <a href=\"options-permalink.php\">permalink options page</a> for necessary mod_rewrite rules and more information.', '8');");
}
if (!$wpdb->get_var("SELECT option_name FROM $tableoptions WHERE option_name = 'gzipcompression'")) { // If it's not already there
$wpdb->query("INSERT INTO `$tableoptions`
(`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`)
VALUES
('', '0', 'gzipcompression', 'Y', '2', '0', '20', '8', 'Whether your output should be gzipped or not. Enable this if you don’t already have mod_gzip running.', '8');");
$optionid = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'gzipcompression'");
$wpdb->query("INSERT INTO $tableoptiongroup_options
(group_id, option_id, seq)
VALUES
(2, $optionid, 5)");
}
if (!$wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'hack_file'")) {
$wpdb->query("INSERT INTO `$tableoptions`
( `option_id` , `blog_id` , `option_name` , `option_can_override` , `option_type` , `option_value` , `option_width` , `option_height` , `option_description` , `option_admin_level` )
VALUES
('', '0', 'hack_file', 'Y', '2', '0', '20', '8', 'Set this to true if you plan to use a hacks file. This is a place for you to store code hacks that won’t be overwritten when you upgrade. The file must be in your wordpress root and called <code>my-hacks.php</code>', '8')");
$optionid = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'hack_file'");
$wpdb->query("INSERT INTO $tableoptiongroup_options
(group_id, option_id, seq)
VALUES
(2, $optionid, 5)");
}
$wpdb->query("UPDATE $tableoptionvalues SET optionvalue_max = 23 , optionvalue_min = -23 WHERE option_id = 51");
// fix upload users description
$wpdb->query("UPDATE $tableoptions SET option_description = '...or you may authorize only some users. enter their logins here, separated by spaces. if you leave this variable blank, all users who have the minimum level are authorized to upload. example: \'barbara anne george\'' WHERE option_id = 37");
// and file types
$wpdb->query("UPDATE $tableoptions SET option_description = 'accepted file types, separated by spaces. example: \'jpg gif png\'' WHERE option_id = 34");
// add link to php date format. this could be to a wordpress.org page in the future
$wpdb->query("UPDATE $tableoptions SET option_description = 'see <a href=\"http://php.net/date\">help</a> for format characters' WHERE option_id = 52");
$wpdb->query("UPDATE $tableoptions SET option_description = 'see <a href=\"http://php.net/date\">help</a> for format characters' WHERE option_id = 53");
$wpdb->query("UPDATE $tableoptions SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
WHERE option_name LIKE 'links_rating_image%'
AND option_value LIKE 'wp-links/links-images/%'");
$wpdb->query("DELETE FROM $tableoptions WHERE option_name = 'comment_allowed_tags'");
$wpdb->query("DELETE FROM $tableoptions WHERE option_name = 'use_preview'");
$wpdb->query("DELETE FROM $tableoptions WHERE option_name = 'search_engine_friendly_urls'");
// Multiple categories
maybe_create_table($tablepost2cat, "
CREATE TABLE `$tablepost2cat` (
`rel_id` INT NOT NULL AUTO_INCREMENT ,
`post_id` INT NOT NULL ,
`category_id` INT NOT NULL ,
PRIMARY KEY ( `rel_id` ) ,
INDEX ( `post_id` , `category_id` )
)
");
$done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $tablepost2cat");
if ($done_ids) :
foreach ($done_ids as $done_id) :
$done_posts[] = $done_id->post_id;
endforeach;
$catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
else:
$catwhere = '';
endif;
$allposts = $wpdb->get_results("SELECT ID, post_category FROM $tableposts WHERE post_category != '0' $catwhere");
if ($allposts) :
foreach ($allposts as $post) {
// Check to see if it's already been imported
$cat = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post->ID AND category_id = $post->post_category");
if (!$cat && 0 != $post->post_category) { // If there's no result
$wpdb->query("
INSERT INTO $tablepost2cat
(post_id, category_id)
VALUES
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -