PluginProbe
Advanced Excerpt / 4.2
Advanced Excerpt v4.2
trunk 0.2.2 3.0 3.1 4.0 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 All 30 releases
advanced-excerpt / functions / functions.php

functions.php in Advanced Excerpt 4.2, at functions/functions.php

61 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Do not use outside the Loop!
4 function the_advanced_excerpt( $args = '', $get = false ) {
5 global $advanced_excerpt;
6 if ( !empty( $args ) && !is_array( $args ) ) {
7 $args = wp_parse_args( $args );
8
9 // Parse query style parameters
10 if ( isset( $args['ellipsis'] ) ) {
11 $args['ellipsis'] = urldecode( $args['ellipsis'] );
12 }
13
14 if ( isset( $args['allowed_tags'] ) ) {
15 $args['allowed_tags'] = preg_split( '/[\s,]+/', $args['allowed_tags'] );
16 }
17
18 if ( isset( $args['exclude_tags'] ) ) {
19 $args['exclude_tags'] = preg_split( '/[\s,]+/', $args['exclude_tags'] );
20 }
21 }
22
23 // convert legacy arg use_words to it's udpated equivalent
24 if ( isset( $args['use_words'] ) ) {
25 $args['length_type'] = ( 1 == $args['use_words'] ) ? 'words' : 'characters';
26 unset( $args['use_words'] );
27 }
28
29 // convert legacy args finish_word & finish_sentence to their udpated equivalents
30 if ( isset( $args['finish_word'] ) || isset( $args['finish_sentence'] ) ) {
31
32 $defaults = array(
33 'finish_word' => 0,
34 'finish_sentence' => 0
35 );
36
37 $args = wp_parse_args( $args, $defaults );
38
39 if ( 0 == $args['finish_word'] && 0 == $args['finish_sentence'] ) {
40 $args['finish'] = 'exact';
41 } else if ( 1 == $args['finish_word'] && 1 == $args['finish_sentence'] ) {
42 $args['finish'] = 'sentence';
43 } else if ( 0 == $args['finish_word'] && 1 == $args['finish_sentence'] ) {
44 $args['finish'] = 'sentence';
45 } else {
46 $args['finish'] = 'word';
47 }
48
49 unset( $args['finish_word'] );
50 unset( $args['finish_sentence'] );
51 }
52
53 // Set temporary options
54 $advanced_excerpt->options = $args;
55
56 if ( $get ) {
57 return get_the_excerpt();
58 } else {
59 the_excerpt();
60 }
61 }