| Conditions | 21 |
| Paths | 1278 |
| Total Lines | 172 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 8 | function podium_post_gallery($output, $attr) |
||
|
|
|||
| 9 | { |
||
| 10 | |||
| 11 | // Initialize |
||
| 12 | global $post, $wp_locale; |
||
| 13 | |||
| 14 | // Gallery instance counter |
||
| 15 | /** |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | static $instance = 0; |
||
| 19 | $instance++; |
||
| 20 | |||
| 21 | // Validate the author's orderby attribute |
||
| 22 | if (isset($attr['orderby'])) { |
||
| 23 | $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); |
||
| 24 | if (!$attr['orderby']) { |
||
| 25 | unset($attr['orderby']); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | // Get attributes from shortcode |
||
| 30 | extract(shortcode_atts([ |
||
| 31 | 'order' => 'ASC', |
||
| 32 | 'orderby' => 'menu_order ID', |
||
| 33 | 'id' => $post->ID, |
||
| 34 | 'itemtag' => 'dl', |
||
| 35 | 'icontag' => 'dt', |
||
| 36 | 'captiontag' => 'dd', |
||
| 37 | 'columns' => 2, |
||
| 38 | // 'size' => 'gallery-thumb-2', |
||
| 39 | 'include' => '', |
||
| 40 | 'exclude' => '' |
||
| 41 | ], $attr)); |
||
| 42 | |||
| 43 | $size = 'gallery-thumb-2'; |
||
| 44 | |||
| 45 | // You need to add size for your gallery and use it |
||
| 46 | |||
| 47 | // Initialize |
||
| 48 | $id = intval($id); |
||
| 49 | $attachments = []; |
||
| 50 | |||
| 51 | if ('RAND' == $order) { |
||
| 52 | $orderby = 'none'; |
||
| 53 | } |
||
| 54 | |||
| 55 | if (!empty($include)) { |
||
| 56 | // Include attribute is present |
||
| 57 | $include = preg_replace('/[^0-9,]+/', '', $include); |
||
| 58 | $_attachments = get_posts(['include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); |
||
| 59 | |||
| 60 | // Setup attachments array |
||
| 61 | foreach ($_attachments as $key => $val) { |
||
| 62 | $attachments[$val->ID] = $_attachments[$key]; |
||
| 63 | } |
||
| 64 | } elseif (!empty($exclude)) { |
||
| 65 | |||
| 66 | // Exclude attribute is present |
||
| 67 | $exclude = preg_replace('/[^0-9,]+/', '', $exclude); |
||
| 68 | |||
| 69 | // Setup attachments array |
||
| 70 | $attachments = get_children(['post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); |
||
| 71 | } else { |
||
| 72 | // Setup attachments array |
||
| 73 | $attachments = get_children(['post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (empty($attachments)) { |
||
| 77 | return ''; |
||
| 78 | } |
||
| 79 | |||
| 80 | // Filter gallery differently for feeds |
||
| 81 | if (is_feed()) { |
||
| 82 | $output = "\n"; |
||
| 83 | foreach ($attachments as $att_id => $attachment) { |
||
| 84 | $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $output; |
||
| 88 | } |
||
| 89 | |||
| 90 | // Filter tags and attributes |
||
| 91 | $itemtag = tag_escape($itemtag); |
||
| 92 | $captiontag = tag_escape($captiontag); |
||
| 93 | $columns = intval($columns); |
||
| 94 | $itemwidth = $columns > 0 ? floor(100 / $columns) : 100; |
||
| 95 | $float = is_rtl() ? 'right' : 'left'; |
||
| 96 | $selector = "gallery-{$instance}"; |
||
| 97 | |||
| 98 | // Filter gallery CSS |
||
| 99 | $output = apply_filters('gallery_style', " |
||
| 100 | <style type='text/css'> |
||
| 101 | #{$selector} { |
||
| 102 | margin: auto; |
||
| 103 | } |
||
| 104 | #{$selector} .gallery-item { |
||
| 105 | float: {$float}; |
||
| 106 | margin-top: 10px; |
||
| 107 | text-align: center; |
||
| 108 | width: {$itemwidth}%; |
||
| 109 | } |
||
| 110 | #{$selector} img { |
||
| 111 | border: 2px solid #cfcfcf; |
||
| 112 | } |
||
| 113 | #{$selector} .gallery-caption { |
||
| 114 | margin-left: 0; |
||
| 115 | } |
||
| 116 | </style> |
||
| 117 | <!-- see gallery_shortcode() in wp-includes/media.php --> |
||
| 118 | <div id='$selector' class='grid-x grid-padding-x small-up-1 large-up-{$columns} gallery galleryid-{$id}'>" |
||
| 119 | ); |
||
| 120 | |||
| 121 | // Iterate through the attachments in this gallery instance |
||
| 122 | $i = 0; |
||
| 123 | |||
| 124 | foreach ($attachments as $id => $attachment) { |
||
| 125 | |||
| 126 | // Attachment link |
||
| 127 | $img = wp_prepare_attachment_for_js($id); |
||
| 128 | $url = $img['sizes']['full']['url']; |
||
| 129 | $alt = $img['alt']; |
||
| 130 | |||
| 131 | // Start itemtag |
||
| 132 | $output .= "<{$itemtag} class='cell gallery-item'>"; |
||
| 133 | |||
| 134 | // icontag |
||
| 135 | $output .= "<{$icontag} class='gallery-icon'>"; |
||
| 136 | |||
| 137 | if (isset($attr['link']) && 'none' != $attr['link']) { |
||
| 138 | $output .= '<a data-open="galleryModal' . $post->ID . $id . '" class="thumbnail-wrap">'; |
||
| 139 | } |
||
| 140 | |||
| 141 | $output .= wp_get_attachment_image($id, $size); |
||
| 142 | |||
| 143 | if (isset($attr['link']) && 'none' != $attr['link']) { |
||
| 144 | $output .= '</a>'; |
||
| 145 | } |
||
| 146 | |||
| 147 | $output .= "</{$icontag}>"; |
||
| 148 | |||
| 149 | if ($captiontag && trim($attachment->post_excerpt)) { |
||
| 150 | // captiontag |
||
| 151 | $output .= " |
||
| 152 | <{$captiontag} class='gallery-caption'> |
||
| 153 | " . wptexturize($attachment->post_excerpt) . " |
||
| 154 | </{$captiontag}>"; |
||
| 155 | } |
||
| 156 | |||
| 157 | // End itemtag |
||
| 158 | $output .= "</{$itemtag}>"; |
||
| 159 | |||
| 160 | $output .= "<div class=\"gallery-reveal reveal large\" id=\"galleryModal{$post->ID}{$id}\" aria-labelledby=\"ModalHeader\" data-reveal> |
||
| 161 | <img src=\"{$url}\" alt=\"{$alt}\" /> |
||
| 162 | <button class=\"close-button\" data-close aria-label=\"Close Modal\" type=\"button\"> |
||
| 163 | <span aria-hidden=\"true\">×</span> |
||
| 164 | </button> |
||
| 165 | </div>"; |
||
| 166 | |||
| 167 | // Line breaks by columns set |
||
| 168 | if ($columns > 0 && ++$i % $columns == 0) { |
||
| 169 | $output .= '<br style="clear: both">'; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | // End gallery output |
||
| 174 | $output .= " |
||
| 175 | <br style='clear: both;'> |
||
| 176 | </div>\n"; |
||
| 177 | |||
| 178 | return $output; |
||
| 179 | } |
||
| 180 | |||
| 252 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.