• Hi,

    When I insert a youtube link into the editor, the video is not embed.
    I see that WordPress need a valid post ID for embedding a youtube link in the tinymce editor. (And the widget can’t provide that.)

    I’m on a new install of WordPress ( 4.2.2 with Twenty Fifteen) and Black Studio TinyMCE Widget in the last version which is the only plugin enabled.

    So it doesn’t work on the widgets.php and also on the customize.php admin page.

    Thanks for your help !

    https://ww.wp.xz.cn/plugins/black-studio-tinymce-widget/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Marco Chiesi

    (@marcochiesi)

    Unfortunately this depend on a WordPress limitation, which needs a post ID for parsing embedded codes. See this topic for further info.
    Anyway the embed do render fine on the frontend. It’s just the preview that doesn’t work.

    Thread Starter Syhlver

    (@syhlver)

    Okay, thanks for your answer, I will see if I can do something to avoid this limitation.
    I’ll tell you if I found something !

    Thread Starter Syhlver

    (@syhlver)

    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’) );

    Thread Starter Syhlver

    (@syhlver)

    And for the function fAddIdPreviewWidgetPost, it’s better to use it in those hooks (better than show it in each widget) :

    add_action( ‘widgets_admin_page’, array( $this, ‘fAddIdPreviewWidgetPost’ ) );
    add_action( ‘customize_controls_init’, array( $this, ‘fAddIdPreviewWidgetPost’ ) );

    Plugin Author Marco Chiesi

    (@marcochiesi)

    Thank you for sharing your workaround. I think I’ll add it in one of the next releases.

    Plugin Author Marco Chiesi

    (@marcochiesi)

    Hi Syhlver,
    we finally implemented your idea, even if in a different way (in the meantime WordPress implementation changed).
    This feature is actually included in our dev version (available on GitHub), and it will be available in future releases.
    Thank you again for your suggestion.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Auto-embed not working’ is closed to new replies.