Conditions | 10 |
Paths | 272 |
Total Lines | 104 |
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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
80 | public function shortcode_callback( $attr ) { |
||
81 | $post_id = get_the_ID(); |
||
82 | |||
83 | $attr = shortcode_atts( |
||
84 | array( |
||
85 | 'trans' => 'fade', |
||
86 | 'order' => 'ASC', |
||
87 | 'orderby' => 'menu_order ID', |
||
88 | 'id' => $post_id, |
||
89 | 'include' => '', |
||
90 | 'exclude' => '', |
||
91 | 'autostart' => true, |
||
92 | 'size' => '', |
||
93 | ), |
||
94 | $attr, |
||
95 | 'slideshow' |
||
96 | ); |
||
97 | |||
98 | if ( 'rand' === strtolower( $attr['order'] ) ) { |
||
99 | $attr['orderby'] = 'none'; |
||
100 | } |
||
101 | |||
102 | $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); |
||
103 | if ( ! $attr['orderby'] ) { |
||
104 | $attr['orderby'] = 'menu_order ID'; |
||
105 | } |
||
106 | |||
107 | if ( ! $attr['size'] ) { |
||
108 | $attr['size'] = 'full'; |
||
109 | } |
||
110 | |||
111 | // Don't restrict to the current post if include. |
||
112 | $post_parent = ( empty( $attr['include'] ) ) ? intval( $attr['id'] ) : null; |
||
113 | |||
114 | $attachments = get_posts( |
||
115 | array( |
||
116 | 'post_status' => 'inherit', |
||
117 | 'post_type' => 'attachment', |
||
118 | 'post_mime_type' => 'image', |
||
119 | 'posts_per_page' => - 1, |
||
120 | 'post_parent' => $post_parent, |
||
121 | 'order' => $attr['order'], |
||
122 | 'orderby' => $attr['orderby'], |
||
123 | 'include' => $attr['include'], |
||
124 | 'exclude' => $attr['exclude'], |
||
125 | 'suppress_filters' => false, |
||
126 | ) |
||
127 | ); |
||
128 | |||
129 | if ( count( $attachments ) < 1 ) { |
||
130 | return false; |
||
131 | } |
||
132 | |||
133 | $gallery_instance = sprintf( 'gallery-%d-%d', $attr['id'], ++$this->instance_count ); |
||
134 | |||
135 | $gallery = array(); |
||
136 | foreach ( $attachments as $attachment ) { |
||
137 | $attachment_image_src = wp_get_attachment_image_src( $attachment->ID, $attr['size'] ); |
||
138 | $attachment_image_src = $attachment_image_src[0]; // [url, width, height]. |
||
139 | $attachment_image_title = get_the_title( $attachment->ID ); |
||
140 | $attachment_image_alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ); |
||
141 | /** |
||
142 | * Filters the Slideshow slide caption. |
||
143 | * |
||
144 | * @module shortcodes |
||
145 | * |
||
146 | * @since 2.3.0 |
||
147 | * |
||
148 | * @param string wptexturize( strip_tags( $attachment->post_excerpt ) ) Post excerpt. |
||
149 | * @param string $attachment ->ID Attachment ID. |
||
150 | */ |
||
151 | $caption = apply_filters( 'jetpack_slideshow_slide_caption', wptexturize( wp_strip_all_tags( $attachment->post_excerpt ) ), $attachment->ID ); |
||
152 | |||
153 | $gallery[] = (object) array( |
||
154 | 'src' => (string) esc_url_raw( $attachment_image_src ), |
||
155 | 'id' => (string) $attachment->ID, |
||
156 | 'title' => (string) esc_attr( $attachment_image_title ), |
||
157 | 'alt' => (string) esc_attr( $attachment_image_alt ), |
||
158 | 'caption' => (string) $caption, |
||
159 | 'itemprop' => 'image', |
||
160 | ); |
||
161 | } |
||
162 | |||
163 | $color = Jetpack_Options::get_option( 'slideshow_background_color', 'black' ); |
||
164 | |||
165 | $js_attr = array( |
||
166 | 'gallery' => $gallery, |
||
167 | 'selector' => $gallery_instance, |
||
168 | 'trans' => $attr['trans'] ? $attr['trans'] : 'fade', |
||
169 | 'autostart' => $attr['autostart'] ? $attr['autostart'] : 'true', |
||
170 | 'color' => $color, |
||
171 | ); |
||
172 | |||
173 | // Show a link to the gallery in feeds. |
||
174 | if ( is_feed() ) { |
||
175 | return sprintf( |
||
176 | '<a href="%s">%s</a>', |
||
177 | esc_url( get_permalink( $post_id ) . '#' . $gallery_instance . '-slideshow' ), |
||
178 | esc_html__( 'Click to view slideshow.', 'jetpack' ) |
||
179 | ); |
||
180 | } |
||
181 | |||
182 | return $this->slideshow_js( $js_attr ); |
||
183 | } |
||
184 | |||
301 |