bs3_panel_shortcode icon indicating copy to clipboard operation
bs3_panel_shortcode copied to clipboard

restoreShortcodes( content ) problem when ran from multiple plugins

Open jasondavis opened this issue 9 years ago • 0 comments

If you try to duplicate this lugin for more than 1 plugin. It will have issues when you switch between visual and text editor where it changes from image to shortcode text and then from shortcode text back to image.

If more than 1 plugin run then they all fire this same function below which replaces the image into a shortcode text. The result is the last plugin to run having its data be the one used.

A solution would be to modify the RegEx to search the image for images with a matching CSS class name as the one the plugin adds to the image. THis way when this function is ran on each plugin it will only update the images that belong to that particular plugin resulting in the correct shortcodes to be built.

    function restoreShortcodes( content ) {
        return content.replace( /(?:<p(?: [^>]+)?>)*(<img [^>]+>)(?:<\/p>)*/g, function( match, image ) {
            var data = getAttr( image, 'data-sh-attr' );
            var con = getAttr( image, 'data-sh-content' );

            if ( data ) {
                return '<p>[' + sh_tag + data + ']' + con + '[/'+sh_tag+']</p>';
            }
            return match;
        });
    }

jasondavis avatar Jun 03 '16 00:06 jasondavis