GPAISRFilter

* * * * * * * * * * * * * * * * * * Shows the author links * * * * * * * * * * * * * * * * * *.

Defined (1)

The class is defined in the following location(s).

/class.filter.php  
  1. class GPAISRFilter { 
  2.  
  3. /** 
  4. * @since 0.6 
  5. */ 
  6. function __construct() { 
  7. $options = get_option( 'gpaisr' ); 
  8.  
  9. if ( isset( $options['into_header'] ) && 1 == $options['into_header'] ) { 
  10. add_action( 'wp_head', array( &$this, 'to_header' ) ); 
  11. elseif ( isset( $options['replacement'] ) && $options['replacement'] == 1 ) { 
  12. add_filter( 'author_link', array( $this, 'author_link_filter' ), 0, 3 ); 
  13. else { 
  14. add_filter( 'the_content', array( $this, 'author_link_in_content' ), 15 ); 
  15.  
  16. /** 
  17. * Just replaces the link with the google+ url 
  18. * @param $link 
  19. * @param $author_id 
  20. * @param $author_nicename 
  21. * @since 0.6 
  22. * @return string 
  23. */ 
  24. function author_link_filter( $link, $author_id, $author_nicename ) { 
  25. $gplus_author_link = get_the_author_meta( 'googleplus', $author_id ); 
  26. if ( ! empty( $gplus_author_link ) ) { 
  27. return $gplus_author_link . '?rel=author'; 
  28. return $link; 
  29.  
  30. /** 
  31. * Writes the Google+-URL right after the Content 
  32. * @param $content 
  33. * @since 0.6 
  34. * @return string 
  35. */ 
  36. function author_link_in_content( $content ) { 
  37.  
  38. if ( ! is_singular() ) { 
  39. return $content; 
  40.  
  41. // load the options from the settings page 
  42. $options = get_option( 'gpaisr' ); 
  43.  
  44. // is this the feed? if yes, should we display the link? 
  45. if ( ! isset( $options['in_feed'] ) ) { 
  46. $options['in_feed'] = 0; 
  47. if ( is_feed() && $options['in_feed'] != 1 ) { 
  48. return $content; 
  49.  
  50. // what's the author id? 
  51. $authorId = get_the_author_meta( 'ID' ); 
  52.  
  53. // find the link 
  54. $gplus_author_link = get_the_author_meta( 'googleplus', $authorId ); 
  55. if ( ! empty( $gplus_author_link ) ) { 
  56. $gplus_author_link = $gplus_author_link . '?rel=author'; 
  57.  
  58. // open in a new window? 
  59. $newWindow = ''; 
  60. if ( isset( $options['new_window'] ) && $options['new_window'] == 1 ) { 
  61. $newWindow = 'target="_blank"'; 
  62.  
  63. // show or hide? 
  64. $showHide = ''; 
  65. if ( isset( $options['hide'] ) && $options['hide'] == 1 ) { 
  66. $showHide = 'style="display:none;"'; 
  67.  
  68. // is there a linktext? 
  69. $linktext = 'Google+'; 
  70. if ( ! empty( $options['link_text'] ) ) { 
  71. $linktext = $options['link_text']; 
  72.  
  73. return $content .= '<a rel="author" href="' . $gplus_author_link . '" ' . $newWindow . ' ' . $showHide . '>' . $linktext . '</a>'; 
  74.  
  75.  
  76. /** 
  77. * Adds the Google profile link to the header 
  78. * @since 0.7.2 
  79. * @return void 
  80. */ 
  81. function to_header() { 
  82.  
  83. global $post; 
  84. if ( ! $post instanceof WP_Post ) { 
  85. return; 
  86.  
  87. if ( ! is_singular() ) { 
  88. return; 
  89.  
  90. $authorId = $post->post_author; 
  91.  
  92. // find the link 
  93. $gplus_author_link = get_the_author_meta( 'googleplus', $authorId ); 
  94.  
  95. if ( ! empty( $gplus_author_link ) ) { 
  96. echo '<link href="' . $gplus_author_link . '" rel="author" />'; 
  97.  
  98.  
  99.