xwp / wp-shortcode-ui-richtext

Shortcake (Shortcode UI) Richtext
15 stars 11 forks source link

inner_content transformed to richtext on first open #22

Open htrex opened 6 years ago

htrex commented 6 years ago

I'm seeing the bug in the subject. After clicking the insert element button and choosing a shortcake element, the inner_content field is shown as a rich text field using the tinyMCE editor. Closing the media window and repeating the same steps for a second or more times without reloading the post editing page shows the correct plain text inner_content field. If I disable wp-shortcode-ui-richtext plugin the bug is not present.

Here follows the code I'm using to register the shortcode.

        $fields = array(
            array(
                'label'       => esc_html__( 'File Audio mp3', 'opmag-shortcodes' ),
                'attr'        => 'attachment',
                'type'        => 'attachment',
                'libraryType' => array( 'audio/mpeg' ),
                'addButton'   => esc_html__( 'Select Audio mp3', 'opmag-shortcodes' ),
                'frameTitle'  => esc_html__( 'Select Audio mp3', 'opmag-shortcodes' ),
            )
        );

        $shortcode_ui_args = array(
            'label'         => esc_html__( 'Audio', 'opmag-shortcodes' ),
            'listItemImage' => 'dashicons-format-audio',
            'post_type'     => array( 'post' ),
            'inner_content' => array(
                'label'       => esc_html__( 'Description', 'opmag-shortcodes' ),
                'description' => esc_html__( 'Insert description', 'opmag-shortcodes' ),
            ),
            'attrs'         => $fields
        );

        shortcode_ui_register_for_shortcode( 'shortcake_download', $shortcode_ui_args );
mehigh commented 6 years ago

This was a contribution done a while back to allow rich text to happen on the inner_content automatically. I don't have a way to disable it by choice, sorry.

The actual bug is not seeing the rich text when you re-open the overlay.

If someone wants to contribute having an possibility to opt out from automatic inner_content, I'm OK to test it and release it.

dollup commented 6 years ago

I was able to reproduce the bug @mehigh mentioned above by:

Clicking on a shortcode in the Build Shortcode modal and closing the modal. On trying to insert a new shortcode with the inner_content field, TinyMCE does not load on the field.

This was triggering the error below yesterday, but I can't duplicate this particular JS error today. Despite not being able to duplicate the error, TinyMCE does still not load.

Uncaught TypeError: Cannot read property 'getRng' of undefined at m (tinymce.min.js?ver=4607-20180123:11) at Object.o [as focus] (tinymce.min.js?ver=4607-20180123:11) at q.focus (tinymce.min.js?ver=4607-20180123:14) at Object.p [as execCommand] (tinymce.min.js?ver=4607-20180123:11) at q.execCommand (tinymce.min.js?ver=4607-20180123:14) at Object.execCommand (tinymce.min.js?ver=4607-20180123:14) at richtext.js?ver=0.1:73

dollup commented 6 years ago

We added the following code "richText.unload( textarea_id );" at line 57 and this resolved issue and TinyMCE loads on the inner_content fields of all shortcodes on the page (new and on edit).

Attempted to create a branch, push, and open PR for this issue but access was denied.

mehigh commented 6 years ago

@dollup Can you issue a PR and I'll get it merged in.