PLL_Links

Manages links related functions.

Defined (1)

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

/include/links.php  
  1. class PLL_Links { 
  2. public $links_model, $model, $options; 
  3.  
  4. /** 
  5. * Constructor 
  6. * @since 1.2 
  7. * @param object $polylang 
  8. */ 
  9. public function __construct( &$polylang ) { 
  10. $this->links_model = &$polylang->links_model; 
  11. $this->model = &$polylang->model; 
  12. $this->options = &$polylang->options; 
  13.  
  14. /** 
  15. * Returns the home url in the requested language 
  16. * @since 1.3 
  17. * @param object|string $language 
  18. * @param bool $is_search optional wether we need the home url for a search form, defaults to false 
  19. */ 
  20. public function get_home_url( $language, $is_search = false ) { 
  21. $language = is_object( $language ) ? $language : $this->model->get_language( $language ); 
  22. return $is_search ? $language->search_url : $language->home_url; 
  23.  
  24. /** 
  25. * Checks if the current user can read the post 
  26. * @since 1.5 
  27. * @param int $post_id 
  28. * @return bool 
  29. */ 
  30. public function current_user_can_read( $post_id ) { 
  31. $post = get_post( $post_id ); 
  32.  
  33. if ( 'inherit' === $post->post_status && $post->post_parent ) { 
  34. $post = get_post( $post->post_parent ); 
  35.  
  36. if ( 'inherit' === $post->post_status || in_array( $post->post_status, get_post_stati( array( 'public' => true ) ) ) ) { 
  37. return true; 
  38.  
  39. // Follow WP practices, which shows links to private posts ( when readable ), but not for draft posts ( ex: get_adjacent_post_link() ) 
  40. if ( in_array( $post->post_status, get_post_stati( array( 'private' => true ) ) ) ) { 
  41. $post_type_object = get_post_type_object( $post->post_type ); 
  42. $user = wp_get_current_user(); 
  43. return is_user_logged_in() && ( current_user_can( $post_type_object->cap->read_private_posts ) || $user->ID == $post->post_author ); // Comparison must not be strict! 
  44.  
  45. return false;