Changeset 2975
- Timestamp:
- 04/01/2011 04:51:27 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-topic-functions.php
r2970 r2975 9 9 10 10 /** Post Form Handlers ********************************************************/ 11 12 /**13 * Insert a topic.14 *15 * If $topicarr has 'ID' set to a value, then topic will be updated.16 *17 * You can set the topic date manually, by setting the values for 'post_date'18 * and 'post_date_gmt' keys. You can open or close replies by setting the value19 * for 'post_status' key.20 *21 * The defaults for the parameter $postarr are:22 * 'post_status' - Default is 'draft'.23 * 'post_type' - Default is 'post'.24 * 'post_author' - Default is current user ID ($user_ID). The ID of the user who added the post.25 * 'ping_status' - Default is the value in 'default_ping_status' option.26 * Whether the attachment can accept pings.27 * 'post_parent' - Default is 0. Set this for the post it belongs to, if any.28 * 'menu_order' - Default is 0. The order it is displayed.29 * 'to_ping' - Whether to ping.30 * 'pinged' - Default is empty string.31 * 'post_password' - Default is empty string. The password to access the attachment.32 * 'guid' - Global Unique ID for referencing the attachment.33 * 'post_content_filtered' - Post content filtered.34 * 'post_excerpt' - Post excerpt.35 *36 * @since 1.0.037 *38 * @uses $wpdb39 * @uses $wp_rewrite40 * @uses $user_ID41 *42 * @uses do_action() Calls 'pre_post_update' on post ID if this is an update.43 * @uses do_action() Calls 'edit_post' action on post ID and post data if this is an update.44 * @uses do_action() Calls 'save_post' and 'wp_insert_post' on post id and post data just before returning.45 * @uses apply_filters() Calls 'wp_insert_post_data' passing $data, $postarr prior to database update or insert.46 * @uses wp_transition_post_status()47 *48 * @param array $postarr Elements that make up post to insert.49 * @param bool $wp_error Optional. Allow return of WP_Error on failure.50 * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.51 */52 function bbp_insert_topic( $post_args = '', $meta_args = '' ) {53 global $bbp, $wpdb, $wp_rewrite;54 55 // Default post fields and post meta56 $post_defaults = array(57 58 // Pass a topic_id if you want to update rather than insert59 'topic_id' => 0,60 61 // Essential post fields62 'post_title' => '',63 'post_content' => '',64 'post_content_filtered' => '',65 'post_excerpt' => '',66 'post_author' => $user_ID,67 'post_status' => 'publish',68 'post_type' => bbp_get_topic_post_type(),69 'post_parent' => 0,70 'post_password' => '',71 'menu_order' => 0,72 73 // Ping fields - (Not yet used by bbPress core)74 'ping_status' => get_option( 'default_ping_status' ),75 'to_ping' => '',76 'pinged' => '',77 78 // Additional post fields79 'guid' => '',80 'import_id' => 0,81 82 );83 84 // Parse85 $p = wp_parse_args( $post_args, $post_defaults );86 extract( $p, EXTR_SKIP );87 88 // Additional parameters for bbPress topics89 $meta_defaults = array(90 91 // 'forum_id' typically be synced with post_parent above92 'forum_id' => 0,93 94 // Anonymous user95 'anonymous_name' => '',96 'anonymous_email' => '',97 'anonymous_ip' => '',98 'anonymous_website' => '',99 100 // Reply and voice counts101 'anonymous_reply_count' => 0,102 'reply_count' => 0,103 'hidden_reply_count' => 0,104 'voice_count' => 0,105 106 // Last active107 'last_active_id' => 0,108 'last_active_time' => '',109 'last_reply_id' => 0,110 111 // Additional post meta112 'revision_log' => false,113 'status' => '',114 'spam_meta_status' => '',115 'pre_trashed_replies' => '',116 117 );118 119 // Parse120 $m = wp_parse_args( $meta_args, $meta_defaults );121 extract( $m, EXTR_SKIP );122 123 // Handle the post insertion124 $topic = wp_insert_post( $r );125 126 //127 foreach( $m as $meta_key => $meta_value ) {128 update_post_meta( $topic->ID, '_bbp_' . $meta_key, $meta_value );129 }130 bbp_update_topic_last_active_id( $topic->ID, $last_active_id );131 132 $post = wp_insert_post( $r );133 134 // Updating an existing post135 if ( !empty( $ID ) ) {136 $update = true;137 $previous_status = get_post_field( 'post_status', $ID );138 $post_ID = (int) $ID;139 $guid = get_post_field( 'guid', $post_ID );140 $post_before = get_post( $post_ID );141 142 // Not updating143 } else {144 $update = false;145 $previous_status = 'new';146 }147 148 }149 11 150 12 /**
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)