Guest User

Wordpress Plugin Google Plus One w3c validator neutral

a guest
Sep 6th, 2011
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: WP JS Plus One
  4. Version: 1.0
  5. Description: Adds Google's +1 button to posts using JavaScript
  6. Author: konqi
  7. Author URI: http://www.konqi.de
  8. License: Public Domain
  9. */        
  10.  
  11. /* Version Check */
  12.     global $wp_version;
  13.     $exit_msg='WP JS PlusOne This requires Wordpress 2.5 or newer.' .
  14.         '<a href="http://codex.wordpress.org/Upgrading_Wordpress">Please update!</a>';
  15.  
  16.  if (version_compare($wp_version,"2.5","<"))
  17.  {
  18.     exit ($exit_msg);
  19.  }
  20.  
  21. /* Adds the injection script to the Header of your Theme */  
  22. function wpjsplusonethis() {
  23.     echo '<script type="text/javascript">
  24.             <!--
  25.             function replaceGooglePlusLinks(elementID, postLink)
  26.             {
  27.                 targetElement = document.getElementById(elementID);
  28.                
  29.                 if(targetElement != undefined && targetElement != null)
  30.                 {
  31.                     targetElement.innerHTML = "<g:plusone size=\"small\" href=\"" + postLink +"\"></g:plusone>";
  32.                     targetElement.setAttribute("style","display:inline;float:right;margin-left:1em;");
  33.                 }
  34.             }
  35.             -->
  36.         </script>';
  37.     echo '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>' . "\n";  
  38. }
  39.    
  40. function WPPlusOneThis_Link()
  41. {
  42.     global $post;
  43.     global $googlejsplusonethis;
  44.  
  45.     // Insert place holder
  46.     echo '<div id="googleplusone' . get_the_ID() . '"></div>' . "\n";
  47.  
  48.     // get the URL to the post or page
  49.     $googlejsplusonethis .= 'replaceGooglePlusLinks("googleplusone' . get_the_ID() .'" , "'.get_permalink(get_the_ID()).'");' . "\n";
  50. }
  51.  
  52. function wpjsplusonethisfooter()
  53. {
  54.     // write & execute replacement, let Google do the rest
  55.     global $googlejsplusonethis;
  56.     echo '<script type="text/javascript">
  57.         <!--
  58.             ' . $googlejsplusonethis . '
  59.         -->
  60.         </script>' . "\n";
  61. }
  62.    
  63. function WPJWPlusOne_Filter($content)
  64. {        
  65.     return $content.WPPlusOneThis_Link();        
  66. }
  67.    
  68. add_action('wp_head','wpjsplusonethis');
  69. add_action('wp_footer','wpjsplusonethisfooter');
  70.  
  71. /* Show Google Plus One Link in content */
  72. add_filter('the_content', 'WPJWPlusOne_Filter');
  73.  ?>
Add Comment
Please, Sign In to add comment