Allow draft pages. Use post_type for object types. Reserve post_status strictly for status. fixes #1820

git-svn-id: http://svn.automattic.com/wordpress/trunk@3510 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-02-09 10:03:48 +00:00
parent 28dbf2bf37
commit f812294867
21 changed files with 143 additions and 95 deletions

View File

@ -34,13 +34,13 @@ function write_post() {
$_POST['post_status'] = 'publish';
if ('' != $_POST['advanced'])
$_POST['post_status'] = 'draft';
if ('' != $_POST['savepage'])
$_POST['post_status'] = 'static';
//if ('' != $_POST['savepage']) {
// $_POST['post_status'] = 'draft';
if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts'))
$_POST['post_status'] = 'draft';
if ('static' == $_POST['post_status'] && !current_user_can('edit_pages'))
if ('page' == $_POST['post_type'] && !current_user_can('edit_pages'))
die(__('This user cannot edit pages.'));
if (!empty ($_POST['edit_date'])) {
@ -154,8 +154,8 @@ function edit_post() {
$_POST['post_status'] = 'publish';
if ('' != $_POST['advanced'])
$_POST['post_status'] = 'draft';
if ('' != $_POST['savepage'])
$_POST['post_status'] = 'static';
//if ('' != $_POST['savepage'])
// $_POST['post_status'] = 'static';
if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts'))
$_POST['post_status'] = 'draft';
@ -254,7 +254,7 @@ function get_post_to_edit($id) {
$post->post_title = format_to_edit($post->post_title);
$post->post_title = apply_filters('title_edit_pre', $post->post_title);
if ($post->post_status == 'static')
if ($post->post_type == 'page')
$post->page_template = get_post_meta($id, '_wp_page_template', true);
return $post;
@ -613,7 +613,7 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) {
function page_rows($parent = 0, $level = 0, $pages = 0) {
global $wpdb, $class, $post;
if (!$pages)
$pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static' ORDER BY menu_order");
$pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' ORDER BY menu_order");
if ($pages) {
foreach ($pages as $post) {
@ -1176,7 +1176,7 @@ function page_template_dropdown($default = '') {
function parent_dropdown($default = 0, $parent = 0, $level = 0) {
global $wpdb, $post_ID;
$items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = 'static' ORDER BY menu_order");
$items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order");
if ($items) {
foreach ($items as $item) {
@ -1848,7 +1848,7 @@ function the_attachment_links($id = false) {
$id = (int) $id;
$post = & get_post($id);
if ( $post->post_status != 'attachment' )
if ( $post->post_type != 'attachment' )
return false;
$icon = get_attachment_icon($post->ID);

View File

@ -51,6 +51,7 @@ if (empty($post->post_status)) $post->post_status = 'draft';
<input type="hidden" name="user_ID" value="<?php echo $user_ID ?>" />
<input type="hidden" name="action" value="<?php echo $form_action ?>" />
<input type="hidden" name="post_author" value="<?php echo $post->post_author ?>" />
<input type="hidden" name="post_type" value="post" />
<?php echo $form_extra ?>
<?php if (isset($_GET['message']) && 2 > $_GET['message']) : ?>

View File

@ -30,7 +30,7 @@ if (isset($mode) && 'bookmarklet' == $mode) {
<input type="hidden" name="user_ID" value="<?php echo $user_ID ?>" />
<input type="hidden" name="action" value='<?php echo $form_action ?>' />
<?php echo $form_extra ?>
<input type="hidden" name="post_status" value="static" />
<input type="hidden" name="post_type" value="page" />
<script type="text/javascript">
<!--
@ -55,6 +55,15 @@ addLoadEvent(focusit);
</div>
</fieldset>
<fieldset class="dbx-box">
<h3 class="dbx-handle"><?php _e('Page Status') ?></h3>
<div class="dbx-content"><?php if ( current_user_can('publish_posts') ) : ?>
<label for="post_status_publish" class="selectit"><input id="post_status_publish" name="post_status" type="radio" value="publish" <?php checked($post->post_status, 'publish'); ?> /> <?php _e('Published') ?></label>
<?php endif; ?>
<label for="post_status_draft" class="selectit"><input id="post_status_draft" name="post_status" type="radio" value="draft" <?php checked($post->post_status, 'draft'); ?> /> <?php _e('Draft') ?></label>
<label for="post_status_private" class="selectit"><input id="post_status_private" name="post_status" type="radio" value="private" <?php checked($post->post_status, 'private'); ?> /> <?php _e('Private') ?></label></div>
</fieldset>
<fieldset id="passworddiv" class="dbx-box">
<h3 class="dbx-handle"><?php _e('Password-Protect Post') ?></h3>
<div class="dbx-content"><input name="post_password" type="text" size="13" id="post_password" value="<?php echo $post->post_password ?>" /></div>

View File

@ -25,7 +25,7 @@ $show_post_type = 'page';
if ( isset($_GET['s']) )
wp();
else
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static'");
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page'");
if ($posts) {
?>

View File

@ -60,7 +60,7 @@ foreach ($comments as $comment) {
<?php endif; ?>
<?php
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) :
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) :
?>
<div>
<h3><?php _e('Posts'); ?> <a href="edit.php" title="<?php _e('More posts...'); ?>">&raquo;</a></h3>
@ -79,7 +79,7 @@ foreach ($recentposts as $post) {
<?php endif; ?>
<?php
if ( $scheduled = $wpdb->get_results("SELECT ID, post_title, post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt > '$today' ORDER BY post_date ASC") ) :
if ( $scheduled = $wpdb->get_results("SELECT ID, post_title, post_date_gmt FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND post_date_gmt > '$today' ORDER BY post_date ASC") ) :
?>
<div>
<h3><?php _e('Scheduled Entries:') ?></h3>
@ -98,7 +98,7 @@ foreach ($scheduled as $post) {
<div>
<h3><?php _e('Blog Stats'); ?></h3>
<?php
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts);
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");

View File

@ -60,7 +60,7 @@ $filename = basename($file);
$attachment = array(
'post_title' => $imgtitle ? $imgtitle : $filename,
'post_content' => $descr,
'post_status' => 'attachment',
'post_type' => 'attachment',
'post_parent' => $post,
'post_mime_type' => $type,
'guid' => $url
@ -124,7 +124,7 @@ if (! current_user_can('edit_others_posts') )
$and_user = "AND post_author = " . $user_ID;
if ( $last )
$start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' $and_user $and_post") - $num;
$start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment' $and_user $and_post") - $num;
else
$start = (int) $start;
@ -134,7 +134,7 @@ if ( $start < 0 )
if ( '' == $sort )
$sort = "post_date_gmt DESC";
$attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_status = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A);
$attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_type = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A);
if ( count($attachments) == 0 ) {
header("Location: ".basename(__FILE__)."?post=$post&action=upload");
@ -643,7 +643,7 @@ th {
<?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post'") ) { ?>
<li<?php echo $current_2; ?>><a href="<?php echo basename(__FILE__); ?>?action=view&amp;post=<?php echo $post; ?>&amp;all=false"><?php _e('Browse'); ?></a></li>
<?php } ?>
<?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment'")) { ?>
<?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment'")) { ?>
<li<?php echo $current_3; ?>><a href="<?php echo basename(__FILE__); ?>?action=view&amp;post=<?php echo $post; ?>&amp;all=true"><?php _e('Browse All'); ?></a></li>
<?php } ?>
<li> </li>

View File

@ -170,7 +170,7 @@ $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comm
// First Page
$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'static', '', '', '')");
$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
$wp_rewrite->flush_rules();
// Set up admin user

View File

@ -16,7 +16,7 @@ if ( current_user_can('edit_pages') ) {
get_currentuserinfo();
$post = get_default_post_to_edit();
$post->post_status = 'static';
$post->post_type = 'page';
include('edit-page-form.php');
}

View File

@ -23,7 +23,7 @@ $action = "delete";
}
// Fix submenu highlighting for pages.
if ( isset($_REQUEST['post']) && 'static' == get_post_status($_REQUEST['post']) )
if ( isset($_REQUEST['post']) && 'page' == get_post_type($_REQUEST['post']) )
$submenu_file = 'page-new.php';
$editing = true;
@ -50,7 +50,7 @@ case 'post':
$location = 'post.php?posted=true';
}
if ( 'static' == $_POST['post_status'] )
if ( 'page' == $_POST['post_type'] )
$location = "page-new.php?saved=true";
if ( isset($_POST['save']) )
@ -72,7 +72,7 @@ case 'edit':
$post = get_post_to_edit($post_ID);
if ($post->post_status == 'static')
if ($post->post_type == 'page')
include('edit-page-form.php');
else
include('edit-form-advanced.php');
@ -90,7 +90,7 @@ case 'editattachment':
// Don't let these be changed
unset($_POST['guid']);
$_POST['post_status'] = 'attachment';
$_POST['post_type'] = 'attachment';
// Update the thumbnail filename
$oldmeta = $newmeta = get_post_meta($post_id, '_wp_attachment_metadata', true);
@ -134,7 +134,7 @@ case 'delete':
if ( !current_user_can('edit_post', $post_id) )
die( __('You are not allowed to delete this post.') );
if ( $post->post_status == 'attachment' ) {
if ( $post->post_type == 'attachment' ) {
if ( ! wp_delete_attachment($post_id) )
die( __('Error in deleting...') );
} else {

View File

@ -33,6 +33,9 @@ function upgrade_all() {
if ( $wp_current_db_version < 3308 )
upgrade_160();
if ( $wp_current_db_version < 3506 )
upgrade_210();
$wp_rewrite->flush_rules();
update_option('db_version', $wp_db_version);
@ -326,6 +329,28 @@ function upgrade_160() {
}
}
function upgrade_210() {
global $wpdb, $table_prefix, $wp_current_db_version;
// Update status and type.
$posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
if ( ! empty($posts) ) foreach ($posts as $post) {
$status = $post->post_status;
$type = 'post';
if ( 'static' == $status ) {
$status = 'publish';
$type = 'page';
} else if ( 'attachment' == $status ) {
$status = 'inherit';
$type = 'attachment';
}
$wpdb->query("UPDATE $wpdb->posts SET post_status = '$status', post_type = '$type' WHERE ID = '$post->ID'");
}
}
// The functions we use to actually do stuff
// General

View File

@ -106,7 +106,7 @@ CREATE TABLE $wpdb->posts (
post_title text NOT NULL,
post_category int(4) NOT NULL default '0',
post_excerpt text NOT NULL,
post_status enum('publish','draft','private','static','object','attachment') NOT NULL default 'publish',
post_status enum('publish','draft','private','static','object','attachment','inherit') NOT NULL default 'publish',
comment_status enum('open','closed','registered_only') NOT NULL default 'open',
ping_status enum('open','closed') NOT NULL default 'open',
post_password varchar(20) NOT NULL default '',
@ -119,7 +119,7 @@ CREATE TABLE $wpdb->posts (
post_parent bigint(20) NOT NULL default '0',
guid varchar(255) NOT NULL default '',
menu_order int(11) NOT NULL default '0',
post_type varchar(100) NOT NULL default '',
post_type varchar(100) NOT NULL default 'post',
post_mime_type varchar(100) NOT NULL default '',
comment_count bigint(20) NOT NULL default '0',
PRIMARY KEY (ID),

View File

@ -234,7 +234,7 @@ default:
if (strlen($short_url) > 35)
$short_url = substr($short_url, 0, 32).'...';
$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$user_object->ID' and post_status = 'publish'");
$numposts = get_usernumposts($user_object->ID);
if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_object->ID' title='" . __('View posts') . "'>$numposts</a>";
echo "
<tr $style>

View File

@ -32,14 +32,14 @@ if (have_posts()) :
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id'
AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status IN ('publish', 'static', 'object')
AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish')
AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'
ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') );
} else { // if no post id passed in, we'll just ue the last 10 comments.
$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status IN ('publish', 'static', 'object')
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "'
ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') );
}

View File

@ -593,23 +593,20 @@ class WP_Query {
}
if ( $this->is_attachment ) {
$where .= ' AND (post_status = "attachment")';
$where .= ' AND (post_type = "attachment")';
} elseif ($this->is_page) {
$where .= ' AND (post_status = "static")';
$where .= ' AND (post_type = "page")';
} elseif ($this->is_single) {
$where .= ' AND (post_status != "static")';
$where .= ' AND (post_type = "post")';
} else {
$where .= ' AND (post_status = "publish"';
$where .= ' AND (post_type = "post" AND post_status = "publish"';
if (isset($user_ID) && ('' != intval($user_ID)))
$where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
$where .= " OR post_author = $user_ID AND post_status = 'private')";
else
$where .= ')';
}
if (! $this->is_attachment )
$where .= ' AND post_status != "attachment"';
// Apply filters on where and join prior to paging so that any
// manipulations to them are reflected in the paging by day queries.
$where = apply_filters('posts_where', $where);
@ -654,10 +651,10 @@ class WP_Query {
$this->posts = $wpdb->get_results($this->request);
// Check post status to determine if post should be displayed.
if ($this->is_single) {
if ($this->is_single || $this->is_page) {
$status = get_post_status($this->posts[0]);
if ( ('publish' != $status) && ('static' != $status) ) {
if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
if ( ('publish' != $status) ) {
if ( ! is_user_logged_in() ) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {

View File

@ -43,7 +43,10 @@ function wp_insert_post($postarr = array()) {
if ( empty($post_status) )
$post_status = 'draft';
if ( empty($post_type) )
$post_type = 'post';
// Get the post ID.
if ( $update )
$post_ID = $ID;
@ -101,18 +104,14 @@ function wp_insert_post($postarr = array()) {
if ( !isset($post_password) )
$post_password = '';
if ( ('publish' == $post_status) || ('static' == $post_status) ) {
$post_name_check = ('publish' == $post_status)
? $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1")
: $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'static' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
if ( 'draft' != $post_status ) {
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
if ($post_name_check) {
$suffix = 2;
while ($post_name_check) {
$alt_post_name = $post_name . "-$suffix";
$post_name_check = ('publish' == $post_status)
? $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1")
: $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'static' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
$suffix++;
}
$post_name = $alt_post_name;
@ -130,6 +129,7 @@ function wp_insert_post($postarr = array()) {
post_title = '$post_title',
post_excerpt = '$post_excerpt',
post_status = '$post_status',
post_type = '$post_type',
comment_status = '$comment_status',
ping_status = '$ping_status',
post_password = '$post_password',
@ -144,9 +144,9 @@ function wp_insert_post($postarr = array()) {
} else {
$wpdb->query(
"INSERT IGNORE INTO $wpdb->posts
(post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type)
(post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type)
VALUES
('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type')");
('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$post_type', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type')");
$post_ID = $wpdb->insert_id;
}
@ -157,7 +157,7 @@ function wp_insert_post($postarr = array()) {
wp_set_post_cats('', $post_ID, $post_category);
if ( 'static' == $post_status ) {
if ( 'page' == $post_type ) {
clean_page_cache($post_ID);
wp_cache_delete($post_ID, 'pages');
} else {
@ -178,7 +178,7 @@ function wp_insert_post($postarr = array()) {
do_action('edit_post', $post_ID);
}
if ($post_status == 'publish') {
if ($post_status == 'publish' && $post_type == 'post') {
do_action('publish_post', $post_ID);
if ( !defined('WP_IMPORTING') ) {
@ -195,7 +195,7 @@ function wp_insert_post($postarr = array()) {
");
spawn_pinger();
}
} else if ($post_status == 'static') {
} else if ($post_type == 'page') {
wp_cache_delete('all_page_ids', 'pages');
$wp_rewrite->flush_rules();
@ -238,7 +238,8 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) {
if ( empty($post_author) )
$post_author = $user_ID;
$post_status = 'attachment';
$post_type = 'attachment';
$post_status = 'inherit';
// Are we updating or creating?
$update = false;
@ -305,6 +306,7 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) {
post_title = '$post_title',
post_excerpt = '$post_excerpt',
post_status = '$post_status',
post_type = '$post_type',
comment_status = '$comment_status',
ping_status = '$ping_status',
post_password = '$post_password',
@ -321,9 +323,9 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) {
} else {
$wpdb->query(
"INSERT INTO $wpdb->posts
(post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type, guid)
(post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type, guid)
VALUES
('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type', '$guid')");
('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$post_type', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type', '$guid')");
$post_ID = $wpdb->insert_id;
}
@ -355,7 +357,7 @@ function wp_delete_attachment($postid) {
if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
return $post;
if ( 'attachment' != $post->post_status )
if ( 'attachment' != $post->post_type )
return false;
$meta = get_post_meta($postid, '_wp_attachment_metadata', true);
@ -407,7 +409,7 @@ function wp_get_recent_posts($num = 10) {
$limit = "LIMIT $num";
}
$sql = "SELECT * FROM $wpdb->posts WHERE post_status IN ('publish', 'draft', 'private') ORDER BY post_date DESC $limit";
$sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC $limit";
$result = $wpdb->get_results($sql,ARRAY_A);
return $result?$result:array();
@ -447,7 +449,7 @@ function wp_update_post($postarr = array()) {
$postarr['post_date_gmt'] = '';
}
if ($postarr['post_status'] == 'attachment')
if ($postarr['post_type'] == 'attachment')
return wp_insert_attachment($postarr);
return wp_insert_post($postarr);
@ -516,7 +518,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
// Update category counts.
$all_affected_cats = array_unique(array_merge($post_categories, $old_categories));
foreach ( $all_affected_cats as $cat_id ) {
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status='publish' AND category_id = '$cat_id'");
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$cat_id'");
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
wp_cache_delete($cat_id, 'category');
}
@ -529,12 +531,12 @@ function wp_delete_post($postid = 0) {
if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
return $post;
if ( 'attachment' == $post->post_status )
if ( 'attachment' == $post->post_type )
return wp_delete_attachment($postid);
do_action('delete_post', $postid);
if ( 'publish' == $post->post_status) {
if ( 'publish' == $post->post_status && 'post' == $post->post_type ) {
$categories = wp_get_post_cats('', $post->ID);
if( is_array( $categories ) ) {
foreach ( $categories as $cat_id ) {
@ -544,8 +546,8 @@ function wp_delete_post($postid = 0) {
}
}
if ( 'static' == $post->post_status )
$wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_status = 'static'");
if ( 'page' == $post->post_type )
$wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_type = 'page'");
$wpdb->query("DELETE FROM $wpdb->posts WHERE ID = $postid");
@ -555,7 +557,7 @@ function wp_delete_post($postid = 0) {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
if ( 'static' == $post->post_status ) {
if ( 'page' == $post->type ) {
wp_cache_delete('all_page_ids', 'pages');
$wp_rewrite->flush_rules();
}
@ -794,7 +796,7 @@ function generate_page_rewrite_rules() {
global $wpdb;
//get pages in order of hierarchy, i.e. children after parents
$posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'static'"));
$posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'"));
//now reverse it, because we need parents after children for rewrite rules to work properly
$posts = array_reverse($posts, true);
@ -807,7 +809,7 @@ function generate_page_rewrite_rules() {
// URI => page name
$uri = get_page_uri($id);
$attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'attachment' AND post_parent = '$id'");
$attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$id'");
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$attach_uri = get_page_uri($attachment->ID);
@ -829,7 +831,7 @@ function get_post_status($ID = '') {
$post = get_post($ID);
if ( is_object($post) ) {
if ( ('attachment' == $post->post_status) && $post->post_parent && ($post->ID != $post->post_parent) )
if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) )
return get_post_status($post->post_parent);
else
return $post->post_status;
@ -838,6 +840,20 @@ function get_post_status($ID = '') {
return false;
}
function get_post_type($post = false) {
global $wpdb, $posts;
if ( false === $post )
$post = $posts[0];
elseif ( (int) $post )
$post = get_post($post, OBJECT);
if ( is_object($post) )
return $post->post_type;
return false;
}
// Takes a post ID, returns its mime type.
function get_post_mime_type($ID = '') {
$post = & get_post($ID);

View File

@ -171,7 +171,7 @@ function user_pass_ok($user_login,$user_pass) {
function get_usernumposts($userid) {
global $wpdb;
return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_status = 'publish'");
return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_type = 'post' AND post_status = 'publish'");
}
@ -574,7 +574,7 @@ function &get_post(&$post, $output = OBJECT) {
else
$_post = null;
} elseif ( is_object($post) ) {
if ( 'static' == $post->post_status )
if ( 'page' == $post->post_type )
return get_page($post, $output);
if ( !isset($post_cache[$post->ID]) )
$post_cache[$post->ID] = &$post;
@ -587,7 +587,7 @@ function &get_post(&$post, $output = OBJECT) {
else {
$query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
$_post = & $wpdb->get_row($query);
if ( 'static' == $_post->post_status )
if ( 'page' == $_post->post_type )
return get_page($_post, $output);
$post_cache[$post] = & $_post;
}
@ -678,7 +678,7 @@ function &get_page(&$page, $output = OBJECT) {
$_page = null;
}
} elseif ( is_object($page) ) {
if ( 'static' != $page->post_status )
if ( 'post' == $page->post_type )
return get_post($page, $output);
wp_cache_add($page->ID, $page, 'pages');
$_page = $page;
@ -693,7 +693,7 @@ function &get_page(&$page, $output = OBJECT) {
} else {
$query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1";
$_page = & $wpdb->get_row($query);
if ( 'static' != $_page->post_status )
if ( 'post' == $_page->post_type )
return get_post($_page, $output);
wp_cache_add($_page->ID, $_page, 'pages');
}
@ -701,7 +701,7 @@ function &get_page(&$page, $output = OBJECT) {
if (!isset($_page->fullpath)) {
$_page = set_page_path($_page);
wp_cache_replace($_page->cat_ID, $_page, 'pages');
wp_cache_replace($_page->ID, $_page, 'pages');
}
if ( $output == OBJECT ) {
@ -815,7 +815,7 @@ function get_all_page_ids() {
global $wpdb;
if ( ! $page_ids = wp_cache_get('all_page_ids', 'pages') ) {
$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status='static'");
$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'page'");
wp_cache_add('all_page_ids', $page_ids, 'pages');
}
@ -1325,7 +1325,7 @@ function get_posts($args) {
$posts = $wpdb->get_results(
"SELECT DISTINCT * FROM $wpdb->posts " .
( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) .
" WHERE post_date <= '$now' AND (post_status = 'publish') ".
" WHERE post_date <= '$now' AND (post_type = 'post' AND post_status = 'publish') ".
( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .
" GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] );

View File

@ -308,7 +308,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
$cat_dates = $wpdb->get_results(" SELECT category_id,
UNIX_TIMESTAMP( MAX(post_date) ) AS ts
FROM $wpdb->posts, $wpdb->post2cat, $wpdb->categories
WHERE post_status = 'publish' AND post_id = ID $exclusions
WHERE post_type = 'post' AND post_status = 'publish' AND post_id = ID $exclusions
GROUP BY category_id");
foreach ( $cat_dates as $cat_date ) {
$category_timestamp["$cat_date->category_id"] = $cat_date->ts;

View File

@ -330,7 +330,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
$now = current_time('mysql');
if ( 'monthly' == $type ) {
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
if ( $arcresults ) {
$afterafter = $after;
foreach ( $arcresults as $arcresult ) {
@ -345,7 +345,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
}
}
} elseif ( 'daily' == $type ) {
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
$url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
@ -356,7 +356,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
}
} elseif ( 'weekly' == $type ) {
$start_of_week = get_settings('start_of_week');
$arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_date < '$now' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
$arc_w_last = '';
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
@ -373,7 +373,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
}
}
} elseif ( 'postbypost' == $type ) {
$arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
@ -403,7 +403,7 @@ function get_calendar($daylength = 1) {
// Quick check. If we have no posts at all, abort!
if ( !$posts ) {
$gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
$gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
if ( !$gotsome )
return;
}
@ -443,14 +443,14 @@ function get_calendar($daylength = 1) {
$previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date < '$thisyear-$thismonth-01'
AND post_status = 'publish'
AND post_type = 'post' AND post_status = 'publish'
ORDER BY post_date DESC
LIMIT 1");
$next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date > '$thisyear-$thismonth-01'
AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
AND post_status = 'publish'
AND post_type = 'post' AND post_status = 'publish'
ORDER BY post_date ASC
LIMIT 1");
@ -508,7 +508,7 @@ function get_calendar($daylength = 1) {
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
FROM $wpdb->posts WHERE MONTH(post_date) = $thismonth
AND YEAR(post_date) = $thisyear
AND post_status = 'publish'
AND post_type = 'post' AND post_status = 'publish'
AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
if ( $dayswithposts ) {
foreach ( $dayswithposts as $daywith ) {
@ -531,7 +531,7 @@ function get_calendar($daylength = 1) {
."WHERE YEAR(post_date) = '$thisyear' "
."AND MONTH(post_date) = '$thismonth' "
."AND post_date < '".current_time('mysql')."' "
."AND post_status = 'publish'"
."AND post_type = 'post' AND post_status = 'publish'"
);
if ( $ak_post_titles ) {
foreach ( $ak_post_titles as $ak_post_title ) {

View File

@ -42,9 +42,9 @@ function get_permalink($id = 0) {
);
$post = &get_post($id);
if ( $post->post_status == 'static' )
if ( $post->post_type == 'page' )
return get_page_link($post->ID);
elseif ($post->post_status == 'attachment')
elseif ($post->post_type == 'attachment')
return get_attachment_link($post->ID);
$permalink = get_settings('permalink_structure');
@ -261,7 +261,7 @@ function get_previous_post($in_same_cat = false, $excluded_categories = '') {
$posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
}
return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < '$current_post_date' AND post_status = 'publish' $posts_in_ex_cats_sql ORDER BY post_date DESC LIMIT 1");
return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < '$current_post_date' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql ORDER BY post_date DESC LIMIT 1");
}
function get_next_post($in_same_cat = false, $excluded_categories = '') {
@ -296,7 +296,7 @@ function get_next_post($in_same_cat = false, $excluded_categories = '') {
$now = current_time('mysql');
return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
}

View File

@ -314,7 +314,7 @@ function &get_pages($args = '') {
$pages = $wpdb->get_results("SELECT * " .
"FROM $wpdb->posts " .
"WHERE post_status = 'static' " .
"WHERE post_type = 'page' AND post_status = 'publish' " .
"$exclusions " .
"ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
@ -450,7 +450,7 @@ function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false)
$id = (int) $id;
$_post = & get_post($id);
if ( ('attachment' != $_post->post_status) || ('' == $_post->guid) )
if ( ('attachment' != $_post->post_type) || ('' == $_post->guid) )
return __('Missing Attachment');
if (! empty($_post->guid) ) {

View File

@ -2,7 +2,7 @@
// This just holds the version number, in a separate file so we can bump it without cluttering the SVN
$wp_version = '2.0.1';
$wp_db_version = 3437;
$wp_version = '2.1-aplha1';
$wp_db_version = 3506;
?>