diggthis.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Digg changed their button API. |
| 5 | * |
| 6 | * The old style button was something like this: |
| 7 | * [digg=http://digg.com/some-digg-permalink] - uses digg permalink as id. |
| 8 | * |
| 9 | * The new style is: |
| 10 | * [digg class="wide"] # The class options are: 'wide', 'medium', 'compact', 'icon' |
| 11 | * and uses get_permalink() as id. |
| 12 | * |
| 13 | * @author Veselin Nikolov |
| 14 | */ |
| 15 | |
| 16 | function digg_shortcode_js() { |
| 17 | echo ' |
| 18 | <script type="text/javascript"> |
| 19 | (function(){var s=document.createElement("SCRIPT"),s1=document.getElementsByTagName("SCRIPT")[0];s.type="text/javascript";s.async=true;s.src="http://widgets.digg.com/buttons.js";s1.parentNode.insertBefore(s,s1);})(); |
| 20 | </script> |
| 21 | '; |
| 22 | } |
| 23 | |
| 24 | function digg_shortcode( $atts ) { |
| 25 | static $printed_digg_code = false; |
| 26 | |
| 27 | if ( ! $printed_digg_code ) { |
| 28 | add_action( 'wp_footer', 'digg_shortcode_js' ); |
| 29 | $printed_digg_code = true; |
| 30 | } |
| 31 | |
| 32 | if ( isset( $atts['class']) && in_array( $atts['class'], array( 'wide', 'medium', 'compact', 'icon' ) ) ) |
| 33 | $class = ucfirst( $atts['class'] ); |
| 34 | else |
| 35 | $class = 'Medium'; |
| 36 | |
| 37 | return '<a class="DiggThisButton Digg' . $class . '" href="http://digg.com/submit?url=' . urlencode( get_permalink() ) . '&title=' . urlencode( get_the_title() ) . '"></a>'; |
| 38 | } |
| 39 | |
| 40 | add_shortcode( 'digg', 'digg_shortcode' ); |
| 41 |