PluginProbe
Polylang / 1.8
Polylang v1.8
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 1.8, at admin/admin-links.php

157 lines 4.4 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
16 * @param object $language
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 return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id );
46 }
47
48 /*
49 * returns html markup for a new post translation link
50 *
51 * @since 1.8
52 *
53 * @param int $post_id
54 * @param object $language
55 * @return string
56 */
57 public function new_post_translation_link( $post_id, $language ) {
58 $link = $this->get_new_post_translation_link( $post_id, $language );
59 return $link ? sprintf(
60 '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
61 esc_url( $link ),
62 /* translators: %s is a native language name */
63 esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
64 ) : '';
65 }
66
67 /*
68 * returns html markup for a translation link
69 *
70 * @since 1.4
71 *
72 * @param int $post_id translation post id
73 * @return string
74 */
75 public function edit_post_translation_link( $post_id ) {
76 $link = get_edit_post_link( $post_id );
77 $language = $this->model->post->get_language( $post_id );
78 return $link ? sprintf(
79 '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
80 esc_url( $link ),
81 /* translators: %s is a native language name */
82 esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
83 ) : '';
84 }
85
86 /*
87 * get the link to create a new term translation
88 *
89 * @since 1.5
90 *
91 * @param int $term_id
92 * @param string $taxonomy
93 * @param string $post_type
94 * @param object $language
95 * @return string
96 */
97 public function get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
98 $tax = get_taxonomy( $taxonomy );
99 if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) {
100 return '';
101 }
102
103 $args = array(
104 'taxonomy' => $taxonomy,
105 'post_type' => $post_type,
106 'from_tag' => $term_id,
107 'new_lang' => $language->slug,
108 );
109
110 $link = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
111 return apply_filters( 'pll_get_new_term_translation_link', $link, $language, $term_id, $taxonomy, $post_type );
112 }
113
114 /*
115 * returns html markup for a new term translation
116 *
117 * @since 1.8
118 *
119 * @param int $term_id
120 * @param string $taxonomy
121 * @param string $post_type
122 * @param object $language
123 * @return string
124 */
125 public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
126 $link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language );
127 return $link ? sprintf(
128 '<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
129 esc_url( $link ),
130 /* translators: %s is a native language name */
131 esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
132 ) : '';
133 }
134
135 /*
136 * returns html markup for a term translation link
137 *
138 * @since 1.4
139 *
140 * @param object $term_id translation term id
141 * @param string $taxonomy
142 * @param string $post_type
143 * @return string
144 */
145 public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) {
146 $link = get_edit_term_link( $term_id, $taxonomy, $post_type );
147 $language = $this->model->term->get_language( $term_id );
148 return $link ? sprintf(
149 '<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
150 esc_url( $link ),
151 /* translators: %s is a native language name */
152 esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
153 ) : '';
154 }
155 }
156
157