function wp_insert_post($postarr = array()) { global $wpdb, $wp_rewrite, $allowedtags, $user_ID; if ( is_object($postarr) ) $postarr = get_object_vars($postarr); // export array as variables extract($postarr); // Are we updating or creating? $update = false; if ( !empty($ID) ) { $update = true; $post = & get_post($ID); $previous_status = $post->post_status; } // Get the basics. $post_content = apply_filters('content_save_pre', $post_content); $post_excerpt = apply_filters('excerpt_save_pre', $post_excerpt); $post_title = apply_filters('title_save_pre', $post_title); $post_category = apply_filters('category_save_pre', $post_category); $post_status = apply_filters('status_save_pre', $post_status); $post_name = apply_filters('name_save_pre', $post_name); $comment_status = apply_filters('comment_status_pre', $comment_status); $ping_status = apply_filters('ping_status_pre', $ping_status); // Make sure we set a valid category if (0 == count($post_category) || !is_array($post_category)) { $post_category = array(get_option('default_category')); } $post_cat = $post_category[0]; if ( empty($post_author) ) $post_author = $user_ID; if ( empty($post_status) ) $post_status = 'draft'; // Get the post ID. if ( $update ) $post_ID = $ID; // Create a valid post name. Drafts are allowed to have an empty // post name. if ( empty($post_name) ) { if ( 'draft' != $post_status ) $post_name = sanitize_title($post_title); } else { $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 (empty($post_date)) { if ( 'draft' != $post_status ) $post_date = current_time('mysql'); } if (empty($post_date_gmt)) { if ( 'draft' != $post_status ) $post_date_gmt = get_gmt_from_date($post_date); } if ( empty($comment_status) ) { if ( $update ) $comment_status = 'closed'; else $comment_status = get_settings('default_comment_status'); } if ( empty($ping_status) ) $ping_status = get_settings('default_ping_status'); if ( empty($post_pingback) ) $post_pingback = get_option('default_pingback_flag'); if ( isset($to_ping) ) $to_ping = preg_replace('|\s+|', "\n", $to_ping); else $to_ping = ''; if ( ! isset($pinged) ) $pinged = ''; if ( isset($post_parent) ) $post_parent = (int) $post_parent; else $post_parent = 0; if ( isset($menu_order) ) $menu_order = (int) $menu_order; else $menu_order = 0; 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 ($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"); $suffix++; } $post_name = $alt_post_name; } } if ($update) { $wpdb->query( "UPDATE IGNORE $wpdb->posts SET post_author = '$post_author', post_date = '$post_date', post_date_gmt = '$post_date_gmt', post_content = '$post_content', post_content_filtered = '$post_content_filtered', post_title = '$post_title', post_excerpt = '$post_excerpt', post_status = '$post_status', comment_status = '$comment_status', ping_status = '$ping_status', post_password = '******', post_name = '$post_name', to_ping = '$to_ping', pinged = '$pinged', post_modified = '".current_time('mysql')."', post_modified_gmt = '".current_time('mysql',1)."', post_parent = '$post_parent', menu_order = '$menu_order' WHERE ID = $post_ID"); } 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) 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_ID = $wpdb->insert_id; } if ( empty($post_name) && 'draft' != $post_status ) { $post_name = sanitize_title($post_title, $post_ID); $wpdb->query( "UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = '$post_ID'" ); } wp_set_post_cats('', $post_ID, $post_category); if ( 'static' == $post_status ) { clean_page_cache($post_ID); wp_cache_delete($post_ID, 'pages'); } else { clean_post_cache($post_ID); } // Set GUID if ( ! $update ) $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'"); if ( $update) { 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') { do_action('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') "); spawn_pinger(); } } else if ($post_status == 'static') { wp_cache_delete('all_page_ids', 'pages'); $wp_rewrite->flush_rules(); if ( !empty($page_template) ) if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template)) add_post_meta($post_ID, '_wp_page_template', $page_template, true); } do_action('save_post', $post_ID); do_action('wp_insert_post', $post_ID); return $post_ID; }
<p> <a href="http://codex.wordpress.org/"><?php _e('Documentation'); ?> </a> — <a href="http://wordpress.org/support/"><?php _e('Support Forums'); ?> </a> <br /> <?php bloginfo('version'); ?> — <?php printf(__('%s seconds'), timer_stop(0, 2)); ?> </p> </div> <?php do_action('admin_footer', ''); ?> <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> <?php if (substr(php_sapi_name(), 0, 3) == 'cgi' && spawn_pinger()) { echo '<iframe id="pingcheck" src="' . get_settings('siteurl') . '/wp-admin/execute-pings.php?time=' . time() . '" style="border:none;width:1px;height:1px;"></iframe>'; } ?> </body> </html>