Fix variable name. Props bgracewood. fixes #4621
git-svn-id: http://svn.automattic.com/wordpress/trunk@5797 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ebf520f0d7
commit
c140ccb72d
|
@ -339,7 +339,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) {
|
||||||
asort($counts);
|
asort($counts);
|
||||||
|
|
||||||
if ( 'DESC' == $order )
|
if ( 'DESC' == $order )
|
||||||
$counts = array_reverse( $tag_counts, true );
|
$counts = array_reverse( $counts, true );
|
||||||
|
|
||||||
$a = array();
|
$a = array();
|
||||||
|
|
||||||
|
|
|
@ -184,5 +184,10 @@ add_action('mce_options', '_mce_set_direction');
|
||||||
add_action('init', 'smilies_init', 5);
|
add_action('init', 'smilies_init', 5);
|
||||||
add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
|
add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
|
||||||
add_action( 'shutdown', 'wp_ob_end_flush_all', 1);
|
add_action( 'shutdown', 'wp_ob_end_flush_all', 1);
|
||||||
|
add_action('publish_post', '_publish_post_hook', 5, 1);
|
||||||
|
add_action('future_post', '_future_post_hook', 5, 2);
|
||||||
|
add_action('future_page', '_future_post_hook', 5, 2);
|
||||||
|
add_action('save_post', '_save_post_hook', 5, 2);
|
||||||
|
add_action('transition_post_status', '_transition_post_status', 5, 3);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -139,7 +139,7 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
|
||||||
|
|
||||||
function get_post_field( $field, $post, $context = 'display' ) {
|
function get_post_field( $field, $post, $context = 'display' ) {
|
||||||
$post = (int) $post;
|
$post = (int) $post;
|
||||||
$post = get_term( $post );
|
$post = get_post( $post );
|
||||||
|
|
||||||
if ( is_wp_error($post) )
|
if ( is_wp_error($post) )
|
||||||
return $post;
|
return $post;
|
||||||
|
@ -420,9 +420,6 @@ function sanitize_post($post, $context = 'display') {
|
||||||
// TODO: Use array keys instead of hard coded list
|
// TODO: Use array keys instead of hard coded list
|
||||||
$fields = array('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');
|
$fields = array('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');
|
||||||
|
|
||||||
if ( 'raw' == $context )
|
|
||||||
return $post;
|
|
||||||
|
|
||||||
$do_object = false;
|
$do_object = false;
|
||||||
if ( is_object($post) )
|
if ( is_object($post) )
|
||||||
$do_object = true;
|
$do_object = true;
|
||||||
|
@ -442,6 +439,9 @@ function sanitize_post_field($field, $value, $post_id, $context) {
|
||||||
if ( in_array($field, $int_fields) )
|
if ( in_array($field, $int_fields) )
|
||||||
$value = (int) $value;
|
$value = (int) $value;
|
||||||
|
|
||||||
|
if ( 'raw' == $context )
|
||||||
|
return $value;
|
||||||
|
|
||||||
$prefixed = false;
|
$prefixed = false;
|
||||||
if ( false !== strpos($field, 'post_') ) {
|
if ( false !== strpos($field, 'post_') ) {
|
||||||
$prefixed = true;
|
$prefixed = true;
|
||||||
|
@ -586,8 +586,6 @@ function wp_insert_post($postarr = array()) {
|
||||||
'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '');
|
'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '');
|
||||||
|
|
||||||
$postarr = wp_parse_args($postarr, $defaults);
|
$postarr = wp_parse_args($postarr, $defaults);
|
||||||
|
|
||||||
if ( empty($postarr['no_filter']) )
|
|
||||||
$postarr = sanitize_post($postarr, 'db');
|
$postarr = sanitize_post($postarr, 'db');
|
||||||
|
|
||||||
// export array as variables
|
// export array as variables
|
||||||
|
@ -597,8 +595,9 @@ function wp_insert_post($postarr = array()) {
|
||||||
$update = false;
|
$update = false;
|
||||||
if ( !empty($ID) ) {
|
if ( !empty($ID) ) {
|
||||||
$update = true;
|
$update = true;
|
||||||
$post = & get_post($ID);
|
$previous_status = get_post_field('post_status', $ID);
|
||||||
$previous_status = $post->post_status;
|
} else {
|
||||||
|
$previous_status = 'new';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) )
|
if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) )
|
||||||
|
@ -608,7 +607,6 @@ function wp_insert_post($postarr = array()) {
|
||||||
if (0 == count($post_category) || !is_array($post_category)) {
|
if (0 == count($post_category) || !is_array($post_category)) {
|
||||||
$post_category = array(get_option('default_category'));
|
$post_category = array(get_option('default_category'));
|
||||||
}
|
}
|
||||||
$post_cat = $post_category[0];
|
|
||||||
|
|
||||||
if ( empty($post_author) )
|
if ( empty($post_author) )
|
||||||
$post_author = $user_ID;
|
$post_author = $user_ID;
|
||||||
|
@ -632,7 +630,6 @@ function wp_insert_post($postarr = array()) {
|
||||||
$post_name = sanitize_title($post_name);
|
$post_name = sanitize_title($post_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If the post date is empty (due to having been new or a draft) and status is not 'draft', set date to now
|
// If the post date is empty (due to having been new or a draft) and status is not 'draft', set date to now
|
||||||
if (empty($post_date)) {
|
if (empty($post_date)) {
|
||||||
if ( !in_array($post_status, array('draft', 'pending')) )
|
if ( !in_array($post_status, array('draft', 'pending')) )
|
||||||
|
@ -738,7 +735,6 @@ function wp_insert_post($postarr = array()) {
|
||||||
|
|
||||||
if ( 'page' == $post_type ) {
|
if ( 'page' == $post_type ) {
|
||||||
clean_page_cache($post_ID);
|
clean_page_cache($post_ID);
|
||||||
$wp_rewrite->flush_rules();
|
|
||||||
} else {
|
} else {
|
||||||
clean_post_cache($post_ID);
|
clean_post_cache($post_ID);
|
||||||
}
|
}
|
||||||
|
@ -747,55 +743,17 @@ function wp_insert_post($postarr = array()) {
|
||||||
if ( ! $update )
|
if ( ! $update )
|
||||||
$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
|
$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
|
||||||
|
|
||||||
if ( $update) {
|
$post = get_post($post_ID);
|
||||||
if ($previous_status != 'publish' && $post_status == 'publish') {
|
|
||||||
// Reset GUID if transitioning to publish.
|
|
||||||
$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
|
|
||||||
do_action('private_to_published', $post_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
do_action('edit_post', $post_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($post_status == 'publish' && $post_type == 'post') {
|
|
||||||
do_action('publish_post', $post_ID);
|
|
||||||
if ( defined('XMLRPC_REQUEST') )
|
|
||||||
do_action('xmlrpc_publish_post', $post_ID);
|
|
||||||
if ( defined('APP_REQUEST') )
|
|
||||||
do_action('app_publish_post', $post_ID);
|
|
||||||
|
|
||||||
if ( !defined('WP_IMPORTING') ) {
|
|
||||||
if ( $post_pingback )
|
|
||||||
$result = $wpdb->query("
|
|
||||||
INSERT INTO $wpdb->postmeta
|
|
||||||
(post_id,meta_key,meta_value)
|
|
||||||
VALUES ('$post_ID','_pingme','1')
|
|
||||||
");
|
|
||||||
$result = $wpdb->query("
|
|
||||||
INSERT INTO $wpdb->postmeta
|
|
||||||
(post_id,meta_key,meta_value)
|
|
||||||
VALUES ('$post_ID','_encloseme','1')
|
|
||||||
");
|
|
||||||
wp_schedule_single_event(time(), 'do_pings');
|
|
||||||
}
|
|
||||||
} else if ($post_type == 'page') {
|
|
||||||
if ( !empty($page_template) )
|
if ( !empty($page_template) )
|
||||||
if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template))
|
$post->page_template = $page_template;
|
||||||
add_post_meta($post_ID, '_wp_page_template', $page_template, true);
|
|
||||||
|
|
||||||
if ( $post_status == 'publish' )
|
wp_transition_post_status($post_status, $previous_status, $post);
|
||||||
do_action('publish_page', $post_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always clears the hook in case the post status bounced from future to draft.
|
if ( $update)
|
||||||
wp_clear_scheduled_hook('publish_future_post', $post_ID);
|
do_action('edit_post', $post_ID, $post);
|
||||||
|
|
||||||
// Schedule publication.
|
do_action('save_post', $post_ID, $post);
|
||||||
if ( 'future' == $post_status )
|
do_action('wp_insert_post', $post_ID, $post);
|
||||||
wp_schedule_single_event(strtotime($post_date_gmt. ' GMT'), 'publish_future_post', array($post_ID));
|
|
||||||
|
|
||||||
do_action('save_post', $post_ID);
|
|
||||||
do_action('wp_insert_post', $post_ID);
|
|
||||||
|
|
||||||
return $post_ID;
|
return $post_ID;
|
||||||
}
|
}
|
||||||
|
@ -841,6 +799,8 @@ function wp_update_post($postarr = array()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_publish_post($post_id) {
|
function wp_publish_post($post_id) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
|
|
||||||
if ( empty($post) )
|
if ( empty($post) )
|
||||||
|
@ -849,7 +809,15 @@ function wp_publish_post($post_id) {
|
||||||
if ( 'publish' == $post->post_status )
|
if ( 'publish' == $post->post_status )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id, 'no_filter' => true));
|
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID = '$post_id'" );
|
||||||
|
|
||||||
|
$old_status = $post->post_status;
|
||||||
|
$post->post_status = 'publish';
|
||||||
|
wp_transition_post_status('publish', $old_status, $post);
|
||||||
|
|
||||||
|
do_action('edit_post', $post_id, $post);
|
||||||
|
do_action('save_post', $post_id, $post);
|
||||||
|
do_action('wp_insert_post', $post_id, $post);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_add_post_tags($post_id = 0, $tags = '') {
|
function wp_add_post_tags($post_id = 0, $tags = '') {
|
||||||
|
@ -887,6 +855,14 @@ function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
|
||||||
return wp_set_object_terms($post_ID, $post_categories, 'category');
|
return wp_set_object_terms($post_ID, $post_categories, 'category');
|
||||||
} // wp_set_post_categories()
|
} // wp_set_post_categories()
|
||||||
|
|
||||||
|
function wp_transition_post_status($new_status, $old_status, $post) {
|
||||||
|
if ( $new_status != $old_status ) {
|
||||||
|
do_action('transition_post_status', $new_status, $old_status, $post);
|
||||||
|
do_action("${old_status}_to_$new_status", $post);
|
||||||
|
}
|
||||||
|
do_action("${new_status}_$post->post_type", $post->ID, $post);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trackback and ping functions
|
// Trackback and ping functions
|
||||||
//
|
//
|
||||||
|
@ -1843,4 +1819,67 @@ function update_postmeta_cache($post_id_list = '') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hooks
|
||||||
|
//
|
||||||
|
|
||||||
|
function _transition_post_status($new_status, $old_status, $post) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
if ( $old_status != 'publish' && $new_status == 'publish' ) {
|
||||||
|
// Reset GUID if transitioning to publish.
|
||||||
|
$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post->ID) . "' WHERE ID = '$post->ID'");
|
||||||
|
do_action('private_to_published', $post->ID); // Deprecated, use private_to_publish
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always clears the hook in case the post status bounced from future to draft.
|
||||||
|
wp_clear_scheduled_hook('publish_future_post', $post->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _future_post_hook($post_id, $post) {
|
||||||
|
// Schedule publication.
|
||||||
|
wp_schedule_single_event(strtotime($post->post_date_gmt. ' GMT'), 'publish_future_post', array($post->ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _publish_post_hook($post_id) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
if ( defined('XMLRPC_REQUEST') )
|
||||||
|
do_action('xmlrpc_publish_post', $post_id);
|
||||||
|
if ( defined('APP_REQUEST') )
|
||||||
|
do_action('app_publish_post', $post_id);
|
||||||
|
|
||||||
|
if ( defined('WP_IMPORTING') )
|
||||||
|
return;
|
||||||
|
|
||||||
|
$post = get_post($post_id);
|
||||||
|
|
||||||
|
if ( $post->post_pingback )
|
||||||
|
$result = $wpdb->query("
|
||||||
|
INSERT INTO $wpdb->postmeta
|
||||||
|
(post_id,meta_key,meta_value)
|
||||||
|
VALUES ('$post_id','_pingme','1')
|
||||||
|
");
|
||||||
|
$result = $wpdb->query("
|
||||||
|
INSERT INTO $wpdb->postmeta
|
||||||
|
(post_id,meta_key,meta_value)
|
||||||
|
VALUES ('$post_id','_encloseme','1')
|
||||||
|
");
|
||||||
|
wp_schedule_single_event(time(), 'do_pings');
|
||||||
|
}
|
||||||
|
|
||||||
|
function _save_post_hook($post_id, $post) {
|
||||||
|
if ( $post->post_type == 'page' ) {
|
||||||
|
if ( !empty($post->page_template) )
|
||||||
|
if ( ! update_post_meta($post_id, '_wp_page_template', $post->page_template))
|
||||||
|
add_post_meta($post_id, '_wp_page_template', $post->page_template, true);
|
||||||
|
|
||||||
|
clean_page_cache($post_id);
|
||||||
|
global $wp_rewrite;
|
||||||
|
$wp_rewrite->flush_rules();
|
||||||
|
} else {
|
||||||
|
clean_post_cache($post_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue