Changeset 11711
- Timestamp:
- 03/28/2022 09:00:52 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/core/credits/shortcode.php
r11344 r11711 5 5 add_shortcode( 'wpcredits', 'wporg_wordpress_credits_shortcode' ); 6 6 7 function wporg_wordpress_credits_shortcode( $attrs, $content = null ) { 7 /** 8 * Shortcode callback to render a list of props names, given a WP version. 9 * 10 * Example: [wpcredits 5.9 separator="bullet"] 11 * 12 * @param array $attrs 13 * @type string Required. Nameless parameter specifying the WP version. Must be the first parameter. 14 * @type string $class Optional. Space-separated list of class names to add to the container element. 15 * @type string $exclude Optional. Comma-separated list of props names to exclude. 16 * @type string $separator Optional. Style of separator to use between props names. 'bullet' or 'comma'. Default 'bullet'. 17 * 18 * @return string 19 */ 20 function wporg_wordpress_credits_shortcode( $attrs ) { 21 $attrs = wp_parse_args( 22 $attrs, 23 array( 24 'class' => 'is-style-wporg-props-long alignfull', 25 'exclude' => '', 26 'separator' => 'bullet', 27 ) 28 ); 29 8 30 if ( ! isset( $attrs[0] ) ) { 9 31 return ''; … … 25 47 } 26 48 27 if ( isset( $attrs['exclude'] ) ) {49 if ( ! empty( $attrs['exclude'] ) ) { 28 50 $exclude = explode( ',', strtolower( $attrs['exclude'] ) ); 29 51 $props = array_diff_key( $props, array_flip( $exclude ) ); … … 36 58 } 37 59 38 return '<p>' . wp_sprintf( '%l.', $output ) . '</p>'; 60 $container_atts = ''; 61 if ( ! empty( $attrs['class'] ) ) { 62 $container_atts .= ' class="' . esc_attr( $attrs['class'] ) . '"'; 63 } 64 65 $content = ''; 66 switch ( $attrs['separator'] ) { 67 case 'comma': 68 default: 69 $content .= wp_sprintf( '%l.', $output ); 70 break; 71 72 case 'bullet': 73 $content .= implode( ' · ', $output ); 74 break; 75 } 76 77 return "<p{$container_atts}>" . $content . '</p>'; 39 78 }
Note: See TracChangeset
for help on using the changeset viewer.