PLL_Admin_Links

Manages links related functions.

Defined (1)

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

/admin/admin-links.php  
  1. class PLL_Admin_Links extends PLL_Links { 
  2.  
  3. /** 
  4. * get the link to create a new post translation 
  5. * @since 1.5 
  6. * @param int $post_id the source post id 
  7. * @param object $language the language of the new translation 
  8. * @return string 
  9. */ 
  10. public function get_new_post_translation_link( $post_id, $language ) { 
  11. $post_type = get_post_type( $post_id ); 
  12. $post_type_object = get_post_type_object( get_post_type( $post_id ) ); 
  13. if ( ! current_user_can( $post_type_object->cap->create_posts ) ) { 
  14. return ''; 
  15.  
  16. if ( 'attachment' == $post_type ) { 
  17. $args = array( 
  18. 'action' => 'translate_media',  
  19. 'from_media' => $post_id,  
  20. 'new_lang' => $language->slug,  
  21. ); 
  22.  
  23. // add nonce for media as we will directly publish a new attachment from a clic on this link 
  24. $link = wp_nonce_url( add_query_arg( $args, admin_url( 'admin.php' ) ), 'translate_media' ); 
  25. } else { 
  26. $args = array( 
  27. 'post_type' => $post_type,  
  28. 'from_post' => $post_id,  
  29. 'new_lang' => $language->slug,  
  30. ); 
  31.  
  32. $link = add_query_arg( $args, admin_url( 'post-new.php' ) ); 
  33.  
  34. /** 
  35. * Filter the new post translation link 
  36. * @since 1.8 
  37. * @param string $link the new post translation link 
  38. * @param object $language the language of the new translation 
  39. * @param int $post_id the source post id 
  40. */ 
  41. return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id ); 
  42.  
  43. /** 
  44. * returns html markup for a new post translation link 
  45. * @since 1.8 
  46. * @param int $post_id 
  47. * @param object $language 
  48. * @return string 
  49. */ 
  50. public function new_post_translation_link( $post_id, $language ) { 
  51. $link = $this->get_new_post_translation_link( $post_id, $language ); 
  52. return $link ? sprintf( 
  53. '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',  
  54. esc_url( $link ),  
  55. /** translators: accessibility text, %s is a native language name */ 
  56. esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) ) 
  57. ) : ''; 
  58.  
  59. /** 
  60. * returns html markup for a translation link 
  61. * @since 1.4 
  62. * @param int $post_id translation post id 
  63. * @return string 
  64. */ 
  65. public function edit_post_translation_link( $post_id ) { 
  66. $link = get_edit_post_link( $post_id ); 
  67. $language = $this->model->post->get_language( $post_id ); 
  68. return $link ? sprintf( 
  69. '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',  
  70. esc_url( $link ),  
  71. /** translators: accessibility text, %s is a native language name */ 
  72. esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) ) 
  73. ) : ''; 
  74.  
  75. /** 
  76. * get the link to create a new term translation 
  77. * @since 1.5 
  78. * @param int $term_id 
  79. * @param string $taxonomy 
  80. * @param string $post_type 
  81. * @param object $language 
  82. * @return string 
  83. */ 
  84. public function get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) { 
  85. $tax = get_taxonomy( $taxonomy ); 
  86. if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) { 
  87. return ''; 
  88.  
  89. $args = array( 
  90. 'taxonomy' => $taxonomy,  
  91. 'post_type' => $post_type,  
  92. 'from_tag' => $term_id,  
  93. 'new_lang' => $language->slug,  
  94. ); 
  95.  
  96. $link = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); 
  97.  
  98. /** 
  99. * Filter the new term translation link 
  100. * @since 1.8 
  101. * @param string $link the new term translation link 
  102. * @param object $language the language of the new translation 
  103. * @param int $term_id the source term id 
  104. * @param string $taxonomy 
  105. * @param string $post_type 
  106. */ 
  107. return apply_filters( 'pll_get_new_term_translation_link', $link, $language, $term_id, $taxonomy, $post_type ); 
  108.  
  109. /** 
  110. * returns html markup for a new term translation 
  111. * @since 1.8 
  112. * @param int $term_id 
  113. * @param string $taxonomy 
  114. * @param string $post_type 
  115. * @param object $language 
  116. * @return string 
  117. */ 
  118. public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) { 
  119. $link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ); 
  120. return $link ? sprintf( 
  121. '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',  
  122. esc_url( $link ),  
  123. /** translators: accessibility text, %s is a native language name */ 
  124. esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) ) 
  125. ) : ''; 
  126.  
  127. /** 
  128. * returns html markup for a term translation link 
  129. * @since 1.4 
  130. * @param object $term_id translation term id 
  131. * @param string $taxonomy 
  132. * @param string $post_type 
  133. * @return string 
  134. */ 
  135. public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) { 
  136. $link = get_edit_term_link( $term_id, $taxonomy, $post_type ); 
  137. $language = $this->model->term->get_language( $term_id ); 
  138. return $link ? sprintf( 
  139. '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',  
  140. esc_url( $link ),  
  141. /** translators: accessibility text, %s is a native language name */ 
  142. esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) ) 
  143. ) : '';