Guest User

Untitled

a guest
Jul 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. /**
  2. * The Gallery shortcode.
  3. *
  4. * This implements the functionality of the Gallery Shortcode for displaying
  5. * WordPress images on a post.
  6. *
  7. * @since 2.5.0
  8. *
  9. * @param array $attr Attributes attributed to the shortcode.
  10. * @return string HTML content to display gallery.
  11. */
  12. //deactivate WordPress function
  13. remove_shortcode('gallery', 'gallery_shortcode');
  14.  
  15. //activate own function
  16. add_shortcode('gallery', 'wpe_gallery_shortcode');
  17.  
  18. //the own renamed function
  19. function wpe_gallery_shortcode($attr) {
  20. global $post, $wp_locale;
  21.  
  22. static $instance = 0;
  23. $instance++;
  24.  
  25. // Allow plugins/themes to override the default gallery template.
  26. $output = apply_filters('post_gallery', '', $attr);
  27. if ( $output != '' )
  28. return $output;
  29.  
  30. // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  31. if ( isset( $attr['orderby'] ) ) {
  32. $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
  33. if ( !$attr['orderby'] )
  34. unset( $attr['orderby'] );
  35. }
  36.  
  37. extract(shortcode_atts(array(
  38. 'order' => 'ASC',
  39. 'orderby' => 'menu_order ID',
  40. 'id' => $post->ID,
  41. 'itemtag' => 'li',
  42. 'columns' => 0,
  43. 'size' => 'medium',
  44. 'include' => '',
  45. 'exclude' => ''
  46. ), $attr));
  47.  
  48. $id = intval($id);
  49. if ( 'RAND' == $order )
  50. $orderby = 'none';
  51.  
  52. if ( !empty($include) ) {
  53. $include = preg_replace( '/[^0-9,]+/', '', $include );
  54. $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  55.  
  56. $attachments = array();
  57. foreach ( $_attachments as $key => $val ) {
  58. $attachments[$val->ID] = $_attachments[$key];
  59. }
  60. } elseif ( !empty($exclude) ) {
  61. $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
  62. $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  63. } else {
  64. $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  65. }
  66.  
  67. if ( empty($attachments) )
  68. return '';
  69.  
  70. if ( is_feed() ) {
  71. $output = "\n";
  72. foreach ( $attachments as $att_id => $attachment )
  73. $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
  74. return $output;
  75. }
  76.  
  77. $itemtag = tag_escape($itemtag);
  78. $captiontag = tag_escape($captiontag);
  79. $columns = intval($columns);
  80.  
  81.  
  82. $float = is_rtl() ? 'right' : 'left';
  83.  
  84. $selector = "gallery-{$instance}";
  85.  
  86. $size_class = sanitize_html_class( $size );
  87. $i = 0;
  88. //if ($itemtag) $output .= '<p>';
  89.  
  90. foreach ( $attachments as $id => $attachment )
  91. {
  92. ++$i;
  93. $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
  94.  
  95. if ($itemtag)
  96. {
  97. $output .= "<{$itemtag} class='gallery-item";
  98. if ( $columns > 0 && $i % $columns == 0 ) $output .= ' end';
  99. $output .= " '>";
  100. }
  101.  
  102. $output .= "$link";
  103.  
  104. if ($itemtag) $output .= "</{$itemtag}>";
  105.  
  106.  
  107. //if ($itemtag && $columns > 0 && ($i % 8 == 0) ) $output .= ' </p><p>';
  108.  
  109.  
  110. }
  111. //if ($itemtag) $output .= '</p>';
  112.  
  113. return $output;
  114. }
Add Comment
Please, Sign In to add comment