bp_forums_update_topic

Update a topic's details.

Description

(object) bp_forums_update_topic( (string) $args = '' ); 

Returns (object)

Details about the new topic, as returned by {@link bp_forums_get_topic_details()}.

Parameters (1)

0. $args — Optional. (string) => ''
Array of arguments.

Options

  • topic_id (int) => 0

    ID of the topic being updated.

  • topic_title (string) => ''

    Updated title of the topic.

  • topic_text (string) => ''

    Updated text of the topic.

array(

    /**
     * ID of the topic being updated.
     *
     * @type int
     */
    'topic_id' => 0,

    /**
     * Updated title of the topic.
     *
     * @type string
     * @default ''
     */
    'topic_title' => '',

    /**
     * Updated text of the topic.
     *
     * @type string
     * @default ''
     */
    'topic_text' => ''
);        


Usage

  1. if ( !function_exists( 'bp_forums_update_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bp-forums-functions.php'; 
  3.  
  4. // Array of arguments. 
  5. $args = array( 
  6. 'topic_id' => 0, 
  7. 'topic_title' => '', 
  8. 'topic_text' => '' 
  9. ); 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_forums_update_topic($args); 
  13.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bp-forums-functions.php  
  1. function bp_forums_update_topic( $args = '' ) { 
  2.  
  3. /** This action is documented in bp-forums/bp-forums-screens.php */ 
  4.  
  5. $r = wp_parse_args( $args, array( 
  6. 'topic_id' => false,  
  7. 'topic_title' => '',  
  8. 'topic_text' => '',  
  9. 'topic_tags' => false 
  10. ) ); 
  11. extract( $r, EXTR_SKIP ); 
  12.  
  13. // Check if the user is a spammer. 
  14. return false; 
  15.  
  16. // The bb_insert_topic() function will append tags, but not remove them. So we remove all existing tags. 
  17. bb_remove_topic_tags( $topic_id ); 
  18.  
  19. if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ), 'tags' => $topic_tags ) ) ) 
  20. return false; 
  21.  
  22. if ( !$post = bb_get_first_post( $topic_id ) ) 
  23. return false; 
  24.  
  25. // Update the first post. 
  26. if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) ) 
  27. return false; 
  28.  
  29. return bp_forums_get_topic_details( $topic_id );