bp_docs_attachment_item_markup

The BuddyPress Docs bp docs attachment item markup function.

Description

bp_docs_attachment_item_markup( $attachment_id, (string) $format = 'full' ); 

Parameters (2)

0. $attachment_id
The attachment id.
1. $format — Optional. (string) => 'full'
The format.

Usage

  1. if ( !function_exists( 'bp_docs_attachment_item_markup' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/templatetags.php'; 
  3.  
  4. // The attachment id. 
  5. $attachment_id = null; 
  6.  
  7. // The format. 
  8. $format = 'full'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_docs_attachment_item_markup($attachment_id, $format); 
  12.  

Defined (1)

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

/includes/templatetags.php  
  1. function bp_docs_attachment_item_markup( $attachment_id, $format = 'full' ) { 
  2. $markup = ''; 
  3.  
  4. $att_url = bp_docs_get_attachment_url( $attachment_id ); 
  5.  
  6. $attachment = get_post( $attachment_id ); 
  7. $att_base = basename( get_attached_file( $attachment_id ) ); 
  8. $doc_url = bp_docs_get_doc_link( $attachment->post_parent ); 
  9.  
  10. $attachment_ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $att_url ); 
  11.  
  12. if ( 'full' === $format ) { 
  13. $attachment_delete_html = ''; 
  14. if ( current_user_can( 'bp_docs_edit' ) && ( bp_docs_is_doc_edit() || bp_docs_is_doc_create() ) ) { 
  15. $attachment_delete_url = wp_nonce_url( $doc_url, 'bp_docs_delete_attachment_' . $attachment_id ); 
  16. $attachment_delete_url = add_query_arg( array( 
  17. 'delete_attachment' => $attachment_id,  
  18. ), $attachment_delete_url ); 
  19. $attachment_delete_html = sprintf( 
  20. '<a href="%s" class="doc-attachment-delete confirm button">%s</a> ',  
  21. $attachment_delete_url,  
  22. __( 'Delete', 'bp-docs' ) 
  23. ); 
  24.  
  25. $markup = sprintf( 
  26. '<li id="doc-attachment-%d"><span class="doc-attachment-mime-icon doc-attachment-mime-%s"></span><a href="%s" title="%s">%s</a>%s</li>',  
  27. $attachment_id,  
  28. $attachment_ext,  
  29. $att_url,  
  30. esc_attr( $att_base ),  
  31. esc_html( $att_base ),  
  32. $attachment_delete_html 
  33. ); 
  34. } else { 
  35. $markup = sprintf( 
  36. '<li id="doc-attachment-%d"><span class="doc-attachment-mime-icon doc-attachment-mime-%s"></span><a href="%s" title="%s">%s</a></li>',  
  37. $attachment_id,  
  38. $attachment_ext,  
  39. $att_url,  
  40. esc_attr( $att_base ),  
  41. esc_html( $att_base ) 
  42. ); 
  43.  
  44. return $markup;