@Chouby - I am having trouble with the URL not working. I have created two pages with the name "Blog" one in en and the other in de: /en/blog/ and /de/blog/. The problem is that when I call _get_page_link() on using the id for the de page I get /en/blog/ instead of /de/blog/.
I was testing it with this code and and I was getting _get_page_link()
return /en/blog/ and $polylang->links_model->add_language_to_link($link, $polylang->model->get_post_language( $post->ID) )
return /de/blog/. I am not sure why it is doing so.
function my_admin_notice(){
global $wp_rewrite, $post, $polylang;
$post = get_post( $post );
$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
$link = $wp_rewrite->get_page_permastruct();
if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
if ( ! $leavename ) {
$link = str_replace('%pagename%', get_page_uri( $post ), $link);
}
$link = home_url($link);
$link = user_trailingslashit($link, 'page');
} else {
$link = home_url( '?page_id=' . $post->ID );
}
echo '<div class="updated"><p>' . _get_page_link() . '</p><p>' . $polylang->links_model->add_language_to_link($link, $polylang->model->get_post_language( $post->ID) ) . '</p></div>';
}
add_action('admin_notices', 'my_admin_notice');