So, I have a solution.
It’s a workaround, but it respond to my needs.
For embeding a link, WordPress need a post ID of an existing post.
So my solution is to create a custom post type (not public, not queryable, etc..).
Then, I create a single post for this custom post type (in the code) and I register the given ID in an option.
And finally in each widget form content, I put a hidden input named « post_ID » containing the previously created post ID as value.
# —————————————————————-
# Create a private custom post type
# This CPT will only contain a single post. This will be used for links embed preview in widget tinymce editor
function fCreateHiddenCPT()
{
# ———————————————————–
# Register the post type
$args = array(
‘public’ => false,
‘publicly_queryable’ => false,
‘show_ui’ => false,
‘query_var’ => false,
‘rewrite’ => false,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘show_in_nav_menus’ => false,
‘has_archive’ => false
);
register_post_type(‘hiddencpt’,$args);
}
# ———————————————————–
# Create the single post
function fCreateSingleHiddenCPT()
{
$queryPost = new WP_Query(‘post_type=hiddencpt’);
$totalPost = $queryPost->post_count;
if($totalPost == 0)
{
$argPost = array(‘post_type’ => ‘hiddencpt’);
$idPreviewWidgetPost = wp_insert_post($argPost);
// Add the id of the post reference in an option
update_option(‘idPreviewWidgetPost’,$idPreviewWidgetPost);
}
}
# ———————————————————–
# For make it working in customize.php
function fAddIdPreviewWidgetPost()
{
echo ‘<input type=”hidden” id=”post_ID” name=”post_ID” value=”‘.get_option(‘idPreviewWidgetPost’).'”>’;
}
add_action(‘customize_register’, array( $this, ‘fAddIdPreviewWidgetPost’) );