PluginProbe
Polylang / 2.2.4
Polylang v2.2.4
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
polylang / admin / admin-links.php

admin-links.php in Polylang 2.2.4, at admin/admin-links.php

178 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * manages links related functions
5 *
6 * @since 1.8
7 */
8 class PLL_Admin_Links extends PLL_Links {
9
10 /**
11 * get the link to create a new post translation
12 *
13 * @since 1.5
14 *
15 * @param int $post_id the source post id
16 * @param object $language the language of the new translation
17 * @return string
18 */
19 public function get_new_post_translation_link( $post_id, $language ) {
20 $post_type = get_post_type( $post_id );
21 $post_type_object = get_post_type_object( get_post_type( $post_id ) );
22 if ( ! current_user_can( $post_type_object->cap->create_posts ) ) {
23 return '';
24 }
25
26 if ( 'attachment' == $post_type ) {
27 $args = array(
28 'action' => 'translate_media',
29 'from_media' => $post_id,
30 'new_lang' => $language->slug,
31 );
32
33 // add nonce for media as we will directly publish a new attachment from a clic on this link
34 $link = wp_nonce_url( add_query_arg( $args, admin_url( 'admin.php' ) ), 'translate_media' );
35 } else {
36 $args = array(
37 'post_type' => $post_type,
38 'from_post' => $post_id,
39 'new_lang' => $language->slug,
40 );
41
42 $link = add_query_arg( $args, admin_url( 'post-new.php' ) );
43 }
44
45 /**
46 * Filter the new post translation link
47 *
48 * @since 1.8
49 *
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
53 */
54 return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id );
55 }
56
57 /**
58 * returns html markup for a new post translation link
59 *
60 * @since 1.8
61 *
62 * @param int $post_id
63 * @param object $language
64 * @return string
65 */
66 public function new_post_translation_link( $post_id, $language ) {
67 $link = $this->get_new_post_translation_link( $post_id, $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 ) : '';
74 }
75
76 /**
77 * returns html markup for a translation link
78 *
79 * @since 1.4
80 *
81 * @param int $post_id translation post id
82 * @return string
83 */
84 public function edit_post_translation_link( $post_id ) {
85 $link = get_edit_post_link( $post_id );
86 $language = $this->model->post->get_language( $post_id );
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 ) : '';
93 }
94
95 /**
96 * get the link to create a new term translation
97 *
98 * @since 1.5
99 *
100 * @param int $term_id
101 * @param string $taxonomy
102 * @param string $post_type
103 * @param object $language
104 * @return string
105 */
106 public function get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
107 $tax = get_taxonomy( $taxonomy );
108 if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) {
109 return '';
110 }
111
112 $args = array(
113 'taxonomy' => $taxonomy,
114 'post_type' => $post_type,
115 'from_tag' => $term_id,
116 'new_lang' => $language->slug,
117 );
118
119 $link = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
120
121 /**
122 * Filter the new term translation link
123 *
124 * @since 1.8
125 *
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
131 */
132 return apply_filters( 'pll_get_new_term_translation_link', $link, $language, $term_id, $taxonomy, $post_type );
133 }
134
135 /**
136 * returns html markup for a new term translation
137 *
138 * @since 1.8
139 *
140 * @param int $term_id
141 * @param string $taxonomy
142 * @param string $post_type
143 * @param object $language
144 * @return string
145 */
146 public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
147 $link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $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 ) : '';
154 }
155
156 /**
157 * returns html markup for a term translation link
158 *
159 * @since 1.4
160 *
161 * @param object $term_id translation term id
162 * @param string $taxonomy
163 * @param string $post_type
164 * @return string
165 */
166 public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) {
167 $link = get_edit_term_link( $term_id, $taxonomy, $post_type );
168 $language = $this->model->term->get_language( $term_id );
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 ) : '';
175 }
176 }
177
178