bb_get_post_delete_link

The BuddyPress bb get post delete link function.

Description

bb_get_post_delete_link( (null) $args = null ); 

Parameters (1)

0. $args — Optional. (null) => null
The args.

Usage

  1. if ( !function_exists( 'bb_get_post_delete_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php'; 
  3.  
  4. // The args. 
  5. $args = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_get_post_delete_link($args); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-template.php  
  1. function bb_get_post_delete_link( $args = null ) 
  2. $defaults = array( 
  3. 'post_id' => 0,  
  4. 'before' => '',  
  5. 'after' => '',  
  6. 'text' => __( 'Delete' ),  
  7. 'redirect' => true 
  8. ); 
  9. if ( is_numeric( $args ) || is_object( $args ) ) { 
  10. $args = array( 'post_id' => $args ); 
  11. if ( isset( $args['delete_text'] ) && ( !isset( $args['text'] ) || !$args['text'] ) ) { 
  12. $args['text'] = $args['delete_text']; 
  13.  
  14. $args = wp_parse_args( $args, $defaults ); 
  15. extract( $args, EXTR_SKIP ); 
  16.  
  17. $bb_post = bb_get_post( get_post_id( $post_id ) ); 
  18. //if ( bb_is_first( $bb_post->post_id ) ) { 
  19. // $topic = get_topic( $bb_post->topic_id ); 
  20. // if ( 2 > $topic->topic_posts ) { 
  21. // Should delete the whole topic 
  22. // return; 
  23. // } 
  24. //} 
  25.  
  26. if ( !bb_current_user_can( 'delete_post', $bb_post->post_id ) ) { 
  27. return; 
  28.  
  29. if ( true === $redirect ) { 
  30. $redirect = $_SERVER['REQUEST_URI']; 
  31.  
  32. $uri = bb_get_uri('bb-admin/delete-post.php', array( 
  33. 'id' => $bb_post->post_id,  
  34. 'status' => 1,  
  35. '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false 
  36. $uri = esc_url( bb_nonce_url( $uri, 'delete-post_' . $bb_post->post_id ) ); 
  37.  
  38. if ( ( bb_is_admin() || isset( $_GET['view'] ) && 'all' == $_GET['view'] ) ) { 
  39. $ajax_class = 'dim:thread:post-' . $bb_post->post_id . ':deleted:FF3333:FFFF33:action=delete-post&status=1'; 
  40. } else { 
  41. $ajax_class = 'delete:thread:post-' . $bb_post->post_id . '::status=1'; 
  42.  
  43. $text = esc_html( $text ); 
  44.  
  45. // Make sure that the last tag in $before gets a class (if it's there) 
  46. if ( preg_match( '/.*(<[^>]+>)[^<]*/', $before, $_node ) ) { 
  47. if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 
  48. $before = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-delete-link ' . $_class[2] . $_class[1], $before ); 
  49. } else { 
  50. $before = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-delete-link"$3$4>$5', $before, 1 ); 
  51.  
  52. $r = $before . '<a href="' . $uri . '" class="' . $ajax_class . ' post-delete-link">' . $text . '</a>' . $after; 
  53. $r = apply_filters( 'post_delete_link', $r, $bb_post->post_status, $bb_post->post_id, $args ); 
  54. return $r;