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