|
17 | 17 |
|
18 | 18 | /** |
19 | 19 | * A shortcode to simplify the process of embedding articles using pym.js |
| 20 | + * |
| 21 | + * @param Array $atts the attributes passed in the shortcode. |
| 22 | + * @param String $content the enclosed content; should be empty for this shortcode. |
| 23 | + * @param String $tag the shortcode tag. |
20 | 24 | */ |
21 | | -function pym_shortcode( $atts, $context, $tag ) { |
| 25 | +function pym_shortcode( $atts, $content, $tag ) { |
22 | 26 |
|
23 | | - // generate an ID for this embed, necessary to prevent conflicts |
| 27 | + // generate an ID for this embed; necessary to prevent conflicts. |
24 | 28 | global $pym_id; |
25 | 29 | if ( ! isset( $pym_id ) ) { |
26 | 30 | $pym_id = 0; |
27 | 31 | } else { |
28 | 32 | ++$pym_id; |
29 | 33 | } |
30 | 34 |
|
| 35 | + // Set us up the vars. |
31 | 36 | $pymsrc = empty( $atts['pymsrc'] ) ? plugins_url( '/js/pym.v1.min.js', __FILE__ ) : $atts['pymsrc']; |
32 | 37 | $pymoptions = empty( $atts['pymoptions'] ) ? '' : $atts['pymoptions']; |
33 | 38 | $id = empty( $atts['id'] ) ? '' : esc_attr( $atts['id'] ); |
34 | 39 | $actual_id = empty( $id ) ? 'pym_' . $pym_id : $id; |
35 | 40 |
|
| 41 | + /** |
| 42 | + * Filter pym_shortcode_default_class allows setting the default class on embeds |
| 43 | + * |
| 44 | + * @param String $default |
| 45 | + * @return String the default class name |
| 46 | + */ |
| 47 | + $default_class = apply_filters( 'pym_shortcode_default_class', 'pym' ); |
| 48 | + $class = empty( $atts['class'] ) ? '' : esc_attr( $atts['class'] ); |
| 49 | + $actual_classes = $default_class . ' ' . $class; |
| 50 | + |
36 | 51 | $src = $atts['src']; |
37 | 52 |
|
38 | 53 | ob_start(); |
39 | 54 |
|
40 | 55 | printf( |
41 | | - '<div id="%1$s"></div>', |
42 | | - $actual_id |
| 56 | + '<div id="%1$s" class="%2$s"></div>', |
| 57 | + esc_attr( $actual_id ), |
| 58 | + esc_attr( $actual_classes ) |
43 | 59 | ); |
44 | 60 |
|
45 | 61 | // If this is the first one on the page, output the pym src |
46 | 62 | // or if the pymsrc is set, output that. |
47 | 63 | if ( 0 === $pym_id || ! empty( $atts['pymsrc'] ) ) { |
48 | 64 | echo sprintf( |
49 | 65 | '<script src="%s"></script>', |
50 | | - $pymsrc |
| 66 | + esc_attr( $pymsrc ) |
51 | 67 | ); |
52 | 68 | } |
53 | 69 |
|
54 | | - // Output the parent's scripts |
| 70 | + // Output the parent's scripts. |
55 | 71 | echo '<script>'; |
56 | 72 | echo sprintf( |
57 | 73 | 'var pym_%1$s = new pym.Parent(\'%2$s\', \'%3$s\', {%4$s})', |
58 | | - $pym_id, |
59 | | - $actual_id, |
60 | | - $src, |
| 74 | + esc_js( $pym_id ), |
| 75 | + esc_js( $actual_id ), |
| 76 | + esc_js( $src ), |
61 | 77 | $pymoptions |
62 | 78 | ); |
63 | 79 | echo '</script>'; |
64 | 80 |
|
65 | | - // What is output to the page |
| 81 | + // What is output to the page: |
66 | 82 | $ret = ob_get_clean(); |
67 | 83 | return $ret; |
68 | 84 | } |
|
0 commit comments