PluginProbe
Polylang / 2.3.6
Polylang v2.3.6
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 +63 -112 3.02.3.6 View file →
@@ -1,11 +1,8 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * Manages links related functions.
4 + * manages links related functions
8 5 *
9 6 * @since 1.8
10 7 */
11 8 class PLL_Admin_Links extends PLL_Links {
@@ -10,79 +7,24 @@
10 7 */
11 8 class PLL_Admin_Links extends PLL_Links {
12 9
13 10 /**
14 - * Returns the html markup for a new translation link.
11 + * get the link to create a new post translation
15 12 *
16 - * @since 2.6
17 - *
18 - * @param string $link The new translation link.
19 - * @param PLL_Language $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 the html markup for a translation link.
42 - *
43 - * @since 2.6
44 - *
45 - * @param string $link The translation link.
46 - * @param PLL_Language $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 - * Get the link to create a new post translation.
60 - *
61 13 * @since 1.5
62 14 *
63 - * @param int $post_id The source post id.
64 - * @param PLL_Language $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 - if ( empty( $post_type_object ) || ! current_user_can( $post_type_object->cap->create_posts ) ) {
22 + if ( ! current_user_can( $post_type_object->cap->create_posts ) ) {
73 23 return '';
74 24 }
75 25
76 - // Special case for the privacy policy page which is associated to a specific capability
77 - if ( 'page' === $post_type_object->name && ! current_user_can( 'manage_privacy_options' ) ) {
78 - $privacy_page = get_option( 'wp_page_for_privacy_policy' );
79 - if ( $privacy_page && in_array( $post_id, $this->model->post->get_translations( $privacy_page ) ) ) {
80 - return '';
81 - }
82 - }
83 -
84 - if ( 'attachment' === $post_type ) {
26 + if ( 'attachment' == $post_type ) {
85 27 $args = array(
86 28 'action' => 'translate_media',
87 29 'from_media' => $post_id,
88 30 'new_lang' => $language->slug,
@@ -87,16 +29,10 @@
87 29 'from_media' => $post_id,
88 30 'new_lang' => $language->slug,
89 31 );
90 32
91 - $link = add_query_arg( $args, admin_url( 'admin.php' ) );
92 -
93 - // 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 - }
33 + // add nonce for media as we will directly publish a new attachment from a click on this link
34 + $link = wp_nonce_url( add_query_arg( $args, admin_url( 'admin.php' ) ), 'translate_media' );
99 35 } else {
100 36 $args = array(
101 37 'post_type' => $post_type,
102 38 'from_post' => $post_id,
@@ -103,65 +39,69 @@
103 39 'new_lang' => $language->slug,
104 40 );
105 41
106 42 $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 - }
113 43 }
114 44
115 45 /**
116 - * Filters the new post translation link.
46 + * Filter the new post translation link
117 47 *
118 48 * @since 1.8
119 49 *
120 - * @param string $link The new post translation link.
121 - * @param PLL_Language $language The language of the new translation.
122 - * @param int $post_id The source post id.
50 + * @param string $link the new post translation link
51 + * @param object $language the language of the new translation
52 + * @param int $post_id the source post id
123 53 */
124 54 return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id );
125 55 }
126 56
127 57 /**
128 - * Returns the html markup for a new post translation link.
58 + * returns html markup for a new post translation link
129 59 *
130 60 * @since 1.8
131 61 *
132 - * @param int $post_id The source post id.
133 - * @param PLL_Language $language The language of the new translation.
62 + * @param int $post_id
63 + * @param object $language
134 64 * @return string
135 65 */
136 66 public function new_post_translation_link( $post_id, $language ) {
137 67 $link = $this->get_new_post_translation_link( $post_id, $language );
138 - return $this->new_translation_link( $link, $language );
68 + return $link ? sprintf(
69 + '<a href="%1$s" class="pll_icon_add"><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( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
73 + ) : '';
139 74 }
140 75
141 76 /**
142 - * Returns the html markup for a post translation link.
77 + * returns html markup for a translation link
143 78 *
144 79 * @since 1.4
145 80 *
146 - * @param int $post_id The translation post id.
81 + * @param int $post_id translation post id
147 82 * @return string
148 83 */
149 84 public function edit_post_translation_link( $post_id ) {
150 85 $link = get_edit_post_link( $post_id );
151 86 $language = $this->model->post->get_language( $post_id );
152 - return $this->edit_translation_link( $link, $language );
87 + return $link ? sprintf(
88 + '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
89 + esc_url( $link ),
90 + /* translators: accessibility text, %s is a native language name */
91 + esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
92 + ) : '';
153 93 }
154 94
155 95 /**
156 - * Get the link to create a new term translation.
96 + * get the link to create a new term translation
157 97 *
158 98 * @since 1.5
159 99 *
160 - * @param int $term_id Source term id.
161 - * @param string $taxonomy Taxonomy name.
162 - * @param string $post_type Post type name.
163 - * @param PLL_Language $language The language of the new translation.
100 + * @param int $term_id
101 + * @param string $taxonomy
102 + * @param string $post_type
103 + * @param object $language
164 104 * @return string
165 105 */
166 106 public function get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
167 107 $tax = get_taxonomy( $taxonomy );
@@ -178,49 +118,60 @@
178 118
179 119 $link = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
180 120
181 121 /**
182 - * Filters the new term translation link.
122 + * Filter the new term translation link
183 123 *
184 124 * @since 1.8
185 125 *
186 - * @param string $link The new term translation link.
187 - * @param PLL_Language $language The language of the new translation.
188 - * @param int $term_id The source term id.
189 - * @param string $taxonomy Taxonomy name.
190 - * @param string $post_type Post type name.
126 + * @param string $link the new term translation link
127 + * @param object $language the language of the new translation
128 + * @param int $term_id the source term id
129 + * @param string $taxonomy
130 + * @param string $post_type
191 131 */
192 132 return apply_filters( 'pll_get_new_term_translation_link', $link, $language, $term_id, $taxonomy, $post_type );
193 133 }
194 134
195 135 /**
196 - * Returns the html markup for a new term translation.
136 + * returns html markup for a new term translation
197 137 *
198 138 * @since 1.8
199 139 *
200 - * @param int $term_id Source term id.
201 - * @param string $taxonomy Taxonomy name.
202 - * @param string $post_type Post type name.
203 - * @param PLL_Language $language The language of the new translation.
140 + * @param int $term_id
141 + * @param string $taxonomy
142 + * @param string $post_type
143 + * @param object $language
204 144 * @return string
205 145 */
206 146 public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
207 147 $link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language );
208 - return $this->new_translation_link( $link, $language );
148 + return $link ? sprintf(
149 + '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
150 + esc_url( $link ),
151 + /* translators: accessibility text, %s is a native language name */
152 + esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
153 + ) : '';
209 154 }
210 155
211 156 /**
212 - * Returns the html markup for a term translation link.
157 + * returns html markup for a term translation link
213 158 *
214 159 * @since 1.4
215 160 *
216 - * @param int $term_id Translation term id.
217 - * @param string $taxonomy Taxonomy name.
218 - * @param string $post_type Post type name.
161 + * @param object $term_id translation term id
162 + * @param string $taxonomy
163 + * @param string $post_type
219 164 * @return string
220 165 */
221 166 public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) {
222 167 $link = get_edit_term_link( $term_id, $taxonomy, $post_type );
223 168 $language = $this->model->term->get_language( $term_id );
224 - return $this->edit_translation_link( $link, $language );
169 + return $link ? sprintf(
170 + '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
171 + esc_url( $link ),
172 + /* translators: accessibility text, %s is a native language name */
173 + esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
174 + ) : '';
225 175 }
226 176 }
177 +