| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* Add a link for edit translations on page and post list |
| 11 |
* |
| 12 |
* @param array $actions An array of row action links (string) |
| 13 |
* @param WP_Post $post The post object |
| 14 |
* @return array |
| 15 |
*/ |
| 16 |
function wplng_row_edit_translation_link( $actions, $post ) { |
| 17 |
|
| 18 |
/** |
| 19 |
* Check the current page |
| 20 |
*/ |
| 21 |
|
| 22 |
if ( 'post' !== $post->post_type && 'page' !== $post->post_type ) { |
| 23 |
return $actions; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Check if a target language is defined |
| 28 |
*/ |
| 29 |
|
| 30 |
$languages_target_ids = wplng_get_languages_target_ids(); |
| 31 |
|
| 32 |
if ( empty( $languages_target_ids[0] ) ) { |
| 33 |
return $actions; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Make the edit translations link |
| 38 |
*/ |
| 39 |
|
| 40 |
$url = get_permalink( $post ); |
| 41 |
|
| 42 |
if ( empty( $url ) || ! wplng_url_is_translatable( $url ) ) { |
| 43 |
return $actions; |
| 44 |
} |
| 45 |
|
| 46 |
$url = add_query_arg( |
| 47 |
'wplng-mode', |
| 48 |
'list', |
| 49 |
wplng_url_translate( |
| 50 |
$url, |
| 51 |
$languages_target_ids[0] |
| 52 |
) |
| 53 |
); |
| 54 |
|
| 55 |
$html = '<a'; |
| 56 |
$html .= ' href="' . esc_url( $url ) . '"'; |
| 57 |
$html .= ' aria-label="' . esc_attr__( 'Edit translations', 'wplingua' ) . '"'; |
| 58 |
$html .= '>'; |
| 59 |
$html .= esc_html__( 'Translations', 'wplingua' ); |
| 60 |
$html .= '</a>'; |
| 61 |
|
| 62 |
/** |
| 63 |
* Add link and return updated actions |
| 64 |
*/ |
| 65 |
|
| 66 |
$actions['wplng-edit-link'] = $html; |
| 67 |
|
| 68 |
return $actions; |
| 69 |
} |
| 70 |
|