| @@ -185,42 +185,30 @@ | ||
| 185 | 185 | |
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | 188 | /* Get the excerpt */ |
| 189 | - | |
| 190 | - $post_id = get_the_ID(); | |
| 191 | - | |
| 192 | - $excerpt = apply_filters('the_excerpt', | |
| 193 | - get_post_field( | |
| 194 | - 'post_excerpt', | |
| 195 | - $post_id, | |
| 196 | - 'display' | |
| 197 | - ) | |
| 198 | - ); | |
| 199 | - | |
| 200 | - if(empty($excerpt) && isset($attributes['excerptLength'])) { | |
| 201 | - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket -- Running the_excerpt directly, Previous rule doesn't take without the_excerpt being moved up a line | |
| 202 | - $excerpt = apply_filters('the_excerpt', | |
| 203 | - wp_trim_words( | |
| 204 | - preg_replace( | |
| 205 | - array( | |
| 206 | - '/\<figcaption>.*\<\/figcaption>/', | |
| 207 | - '/\[caption.*\[\/caption\]/', | |
| 208 | - ), | |
| 209 | - '', | |
| 210 | - get_the_content() | |
| 211 | - ), | |
| 212 | - $attributes['excerptLength'] | |
| 213 | - ) | |
| 214 | - ); | |
| 189 | + | |
| 190 | + global $post; | |
| 191 | + | |
| 192 | + | |
| 193 | + $excerpt = blockspare_post_excerpt($post_id, $post); | |
| 194 | + | |
| 195 | + if (!$excerpt) { | |
| 196 | + $excerpt = null; | |
| 215 | 197 | } |
| 216 | - | |
| 217 | - if(!$excerpt) { | |
| 218 | - $excerpt = null; | |
| 198 | + | |
| 199 | + if (!empty($excerpt)) { | |
| 200 | + $excerpt = explode(' ', $excerpt); | |
| 201 | + $trim_to_length = (int)$attributes['excerptLength'] ? (int)$attributes['excerptLength'] : 55; | |
| 202 | + if (count($excerpt) > $trim_to_length) { | |
| 203 | + $excerpt = implode(' ', array_slice($excerpt, 0, $trim_to_length)) . '...'; | |
| 204 | + } else { | |
| 205 | + $excerpt = implode(' ', $excerpt); | |
| 206 | + } | |
| 207 | + | |
| 219 | 208 | } |
| 220 | - | |
| 221 | - | |
| 222 | - | |
| 209 | + | |
| 210 | + | |
| 223 | 211 | if ((isset($attributes['displayPostExcerpt']) && $excerpt != null) || isset($attributes['displayPostLink'])) { |
| 224 | 212 | |
| 225 | 213 | |
| 226 | 214 | /* Wrap the excerpt content */ |