PluginProbe
Polylang / 2.5.2
Polylang v2.5.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | admin/admin-links.php +30 -72 2.92.5.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages links related functions
8 5 *
@@ -10,64 +7,17 @@
10 7 */
11 8 class PLL_Admin_Links extends PLL_Links {
12 9
13 10 /**
14 - * Returns html markup for a new translation link
15 - *
16 - * @since 2.6
17 - *
18 - * @param string $link The new translation link.
19 - * @param object $language The language of the new translation.
20 - * @return string
21 - */
22 - protected function new_translation_link( $link, $language ) {
23 - $str = '';
24 -
25 - if ( $link ) {
26 - /* translators: accessibility text, %s is a native language name */
27 - $hint = sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name );
28 -
29 - $str = sprintf(
30 - '<a href="%1$s" title="%2$s" class="pll_icon_add"><span class="screen-reader-text">%3$s</span></a>',
31 - esc_url( $link ),
32 - esc_attr( $hint ),
33 - esc_html( $hint )
34 - );
35 - }
36 -
37 - return $str;
38 - }
39 -
40 - /**
41 - * Returns html markup for a translation link
42 - *
43 - * @since 2.6
44 - *
45 - * @param string $link The translation link.
46 - * @param object $language The language of the translation.
47 - * @return string
48 - */
49 - public function edit_translation_link( $link, $language ) {
50 - return $link ? sprintf(
51 - '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
52 - esc_url( $link ),
53 - /* translators: accessibility text, %s is a native language name */
54 - esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
55 - ) : '';
56 - }
57 -
58 - /**
59 11 * Get the link to create a new post translation
60 12 *
61 13 * @since 1.5
62 14 *
63 - * @param int $post_id The source post id.
64 - * @param object $language The language of the new translation.
65 - * @param string $context Optional. Defaults to 'display' which encodes '&' to '&amp;'.
66 - * Otherwise, preserves '&'.
15 + * @param int $post_id the source post id
16 + * @param object $language the language of the new translation
67 17 * @return string
68 18 */
69 - public function get_new_post_translation_link( $post_id, $language, $context = 'display' ) {
19 + public function get_new_post_translation_link( $post_id, $language ) {
70 20 $post_type = get_post_type( $post_id );
71 21 $post_type_object = get_post_type_object( get_post_type( $post_id ) );
72 22 if ( ! current_user_can( $post_type_object->cap->create_posts ) ) {
73 23 return '';
@@ -80,9 +30,9 @@
80 30 return '';
81 31 }
82 32 }
83 33
84 - if ( 'attachment' === $post_type ) {
34 + if ( 'attachment' == $post_type ) {
85 35 $args = array(
86 36 'action' => 'translate_media',
87 37 'from_media' => $post_id,
88 38 'new_lang' => $language->slug,
@@ -87,16 +37,10 @@
87 37 'from_media' => $post_id,
88 38 'new_lang' => $language->slug,
89 39 );
90 40
91 - $link = add_query_arg( $args, admin_url( 'admin.php' ) );
92 -
93 41 // Add nonce for media as we will directly publish a new attachment from a click on this link
94 - if ( 'display' === $context ) {
95 - $link = wp_nonce_url( $link, 'translate_media' );
96 - } else {
97 - $link = add_query_arg( '_wpnonce', wp_create_nonce( 'translate_media' ), $link );
98 - }
42 + $link = wp_nonce_url( add_query_arg( $args, admin_url( 'admin.php' ) ), 'translate_media' );
99 43 } else {
100 44 $args = array(
101 45 'post_type' => $post_type,
102 46 'from_post' => $post_id,
@@ -102,15 +46,9 @@
102 46 'from_post' => $post_id,
103 47 'new_lang' => $language->slug,
104 48 );
105 49
106 - $link = add_query_arg( $args, admin_url( 'post-new.php' ) );
107 -
108 - if ( 'display' === $context ) {
109 - $link = wp_nonce_url( $link, 'new-post-translation' );
110 - } else {
111 - $link = add_query_arg( '_wpnonce', wp_create_nonce( 'new-post-translation' ), $link );
112 - }
50 + $link = wp_nonce_url( add_query_arg( $args, admin_url( 'post-new.php' ) ), 'new-post-translation' );
113 51 }
114 52
115 53 /**
116 54 * Filter the new post translation link
@@ -134,9 +72,14 @@
134 72 * @return string
135 73 */
136 74 public function new_post_translation_link( $post_id, $language ) {
137 75 $link = $this->get_new_post_translation_link( $post_id, $language );
138 - return $this->new_translation_link( $link, $language );
76 + return $link ? sprintf(
77 + '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
78 + esc_url( $link ),
79 + /* translators: accessibility text, %s is a native language name */
80 + esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
81 + ) : '';
139 82 }
140 83
141 84 /**
142 85 * Returns html markup for a translation link
@@ -148,9 +91,14 @@
148 91 */
149 92 public function edit_post_translation_link( $post_id ) {
150 93 $link = get_edit_post_link( $post_id );
151 94 $language = $this->model->post->get_language( $post_id );
152 - return $this->edit_translation_link( $link, $language );
95 + return $link ? sprintf(
96 + '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
97 + esc_url( $link ),
98 + /* translators: accessibility text, %s is a native language name */
99 + esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
100 + ) : '';
153 101 }
154 102
155 103 /**
156 104 * Get the link to create a new term translation
@@ -204,9 +152,14 @@
204 152 * @return string
205 153 */
206 154 public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
207 155 $link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language );
208 - return $this->new_translation_link( $link, $language );
156 + return $link ? sprintf(
157 + '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
158 + esc_url( $link ),
159 + /* translators: accessibility text, %s is a native language name */
160 + esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
161 + ) : '';
209 162 }
210 163
211 164 /**
212 165 * Returns html markup for a term translation link
@@ -220,7 +173,12 @@
220 173 */
221 174 public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) {
222 175 $link = get_edit_term_link( $term_id, $taxonomy, $post_type );
223 176 $language = $this->model->term->get_language( $term_id );
224 - return $this->edit_translation_link( $link, $language );
177 + return $link ? sprintf(
178 + '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
179 + esc_url( $link ),
180 + /* translators: accessibility text, %s is a native language name */
181 + esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
182 + ) : '';
225 183 }
226 184 }