Make WordPress Core

Ticket #2473: functions-post.diff

File functions-post.diff, 4.1 KB (added by skippy, 19 years ago)
  • functions-post.php

     
    22
    33/**** DB Functions ****/
    44
    5 /*
    6  * generic function for inserting data into the posts table.
     5/**
     6 * Insert or update data in the posts table
     7 * @param       array   $postarr        an array of the POSTed data from the Write screen
     8 * @return      int     the post_ID of the inserted or updated post
    79 */
    810function wp_insert_post($postarr = array()) {
    911        global $wpdb, $wp_rewrite, $allowedtags, $user_ID;
     
    219221        return $post_ID;
    220222}
    221223
     224/**
     225 * Insert or update an attachment to a post
     226 * @param       object  $object        an object of postdata
     227 * @param       bool    $file           whether to set the _wp_attached_file postmeta for this post
     228 * @param       int     $post_parent    the post_ID of the parent element to this post
     229 * @return      int     the post_ID of the inserted or updated post
     230*/
    222231function wp_insert_attachment($object, $file = false, $post_parent = 0) {
    223232        global $wpdb, $user_ID;
    224233
     
    359368        return $post_ID;
    360369}
    361370
     371/**
     372 * Remove an attachment, and delete any associated on-disk files (including thumbnails)
     373 * @param       int     $postid         the post_ID of the attachment to remove
     374 * @return      mixed                   the post object from which the attachment was deleted, or boolean false on error
     375*/
     376   
    362377function wp_delete_attachment($postid) {
    363378        global $wpdb;
    364379        $postid = (int) $postid;
     
    394409        return $post;
    395410}
    396411
     412/**
     413 * Select a single post from the database and includes the categories to which that post belongs
     414 * @param       int      $postid        the post_ID of the post to return
     415 * @param       constant $mode          Whether to return an OBJECT or an ARRAY
     416 * @return      mixed                   returns either an OBJECT or an ARRAY, as defined by $mode
     417*/
    397418function wp_get_single_post($postid = 0, $mode = OBJECT) {
    398419        global $wpdb;
    399420
     
    410431        return $post;
    411432}
    412433
     434**
     435 * Return some number of recent posts
     436 * @param       int     $num    the number of posts to return
     437 * @return      array           returns an array of posts sorted descending by date, or an empty array in case of failure
     438*/
     439 
    413440function wp_get_recent_posts($num = 10) {
    414441        global $wpdb;
    415442
     
    424451        return $result?$result:array();
    425452}
    426453
     454**
     455 * Update a post
     456 * @param       array   $postarr        the post data to update
     457 * @return      int                     returns the post_ID of the updated post (as returned by wp_insert_post())
     458*/ 
    427459function wp_update_post($postarr = array()) {
    428460        global $wpdb;
    429461
     
    464496        return wp_insert_post($postarr);
    465497}
    466498
     499**
     500 * Sets a post's status to "publish"
     501 * @param       int     $post_id        The post_ID of the post to publish
     502 * @return      int                     Returns the post_ID of the published post, or null if no change was performed
     503*/
    467504function wp_publish_post($post_id) {
    468505        $post = get_post($post_id);
    469506
     
    476513        return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id));     
    477514}
    478515
     516/**
     517 * Returns an array of categories to which a specific post is assigned
     518 * @param       int     $blogid         The ID of the blog that owns the post (used only for WPMU)
     519 * @param       int     $post_ID        the post_ID of the post who's categories are being selected
     520 * @return      array                   returns an array of category IDs
     521*/
    479522function wp_get_post_cats($blogid = '1', $post_ID = 0) {
    480523        global $wpdb;
    481524
     
    492535        return array_unique($result);
    493536}
    494537
     538/**
     539 *
     540 * @param       int     $blogid         the ID of the blog (used for WPMU)
     541 * @param       int     $post_ID        the post_ID for the post who's categories are being set
     542 * @param       array   $post_categories        an array of categories to which the post will be assigned
     543 * @return      none
     544*/
    495545function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
    496546        global $wpdb;
    497547        // If $post_categories isn't already an array, make it one:
     
    545595        }
    546596}       // wp_set_post_cats()
    547597
     598/**
     599 * Delete a post from the database
     600 * @param       int     $post_id        the post_id of the post to delete
     601 * @return      mixed                   an object containing the contents of the deleted post, or boolean false if nothing was deleted
     602*/
    548603function wp_delete_post($postid = 0) {
    549604        global $wpdb, $wp_rewrite;
    550605        $postid = (int) $postid;