| 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 |
|