Git Product home page Git Product logo

wordpress-mce-view-and-shortcode-editor's Introduction

note: updated to work with WordPress 4.2

WordPress custom TinyMCE view and shortcode editor

This file converts a plain WordPress shortcode....

plain shortocde

... into a nice custom MCE view that matches the frontend ...

nice wp mce view

... and lets you click on it ...

edit delete buttons

... and easily edit the shortcode through a popup ...

edit wordpress shortcode in popup

.. also adds a button for inserting a new shortcode:

tinymce shortcode insert button

wordpress-mce-view-and-shortcode-editor's People

Contributors

dtbaker avatar georgestephanis avatar gillesgoetsch avatar lewiscowles1986 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wordpress-mce-view-and-shortcode-editor's Issues

Using the same template in front and in tinymce

Hi.
First, thank for your work !
it help me a lot.

I would like to know with we can imagine a system where we can use the same html template in front and in tinymce.

finding a way to merge this to html

public function dtbaker_shortcode_banner($atts=array(), $innercontent='', $code='') {
        extract(shortcode_atts(array(
            'id' => false,
            'title' => 'Special:',
            'link' => '',
            'linkhref' => '',
        ), $atts));

        $banner_id = strtolower(preg_replace('#\W+#','',$title));

        ob_start();
        ?>
        <div class="full_banner" id="banner_<?php echo $banner_id;?>">
            <span class="title"><?php echo $title;?></span>
            <span class="content"><?php echo $innercontent;?></span>
            <?php if($link && $linkhref){ ?>
            <a href="<?php echo $linkhref;?>" class="link dtbaker_button_light"><?php echo $link;?></a>
            <?php } ?>
        </div>
        <?php
        return ob_get_clean();
    }

and

public function print_media_templates() {
        if ( ! isset( get_current_screen()->id ) || get_current_screen()->base != 'post' )
            return;
        ?>
        <script type="text/html" id="tmpl-editor-boutique-banner">
            <div class="boutique_banner_{{ data.type }}"></div>
            <div class="full_banner" id="banner_{{ data.id }}">
                <span class="title">{{ data.title }}</span>
                <span class="content">{{ data.innercontent }}</span>
                <# if ( data.link ) { #>
                    <# if ( data.linkhref ) { #>
                        <a href="{{ data.linkhref }}" class="link dtbaker_button_light">{{ data.link }}</a>
                    <# } #>
                <# } #>
            </div>
        </script>
        <?php
    }

thanks

GetContent fired twice

Hi, i've noticed a stange behavior

when puttin a console.log on the 'getContent' this event is fired twice or more time...

I'm looking for a way to have thie event fired only one time...any idea ?

    public function admin_print_footer_scripts() {
        if ( ! isset( get_current_screen()->id ) || get_current_screen()->base != 'post' )
            return;
        ?>
        <script type="text/javascript">
            (function($){
                var media = wp.media, shortcode_string = 'boutique_banner';
                wp.mce = wp.mce || {};
                wp.mce.boutique_banner = {
                    shortcode_data: {},
                    template: media.template( 'editor-boutique-banner' ),
                    getContent: function() {
                        console.log('getContent')
                            var options = this.shortcode.attrs.named;
                            options['innercontent'] = this.shortcode.content;
                            return this.template(options);
                        },
                    View: {
                        // before WP 4.2:
                        template: media.template( 'editor-boutique-banner' ),
                        ...

Fails in WP 4.5.x

It's hard to find any good examples of creating TinyMCE plugins with editor preview, and this is the best one yet. However, it fails with Underscore and wp.media.template in WordPress 4.5.x. Any chance this code can be updated?

Required Fields for mce.views.register

More of a question because youre the only reliable information about this.

I understand the second argument for register accepts a View object for extending. What is the basic requirements for this just to get something in tinymce?

I wish wordpress includes usage docs... :(

Typo in file name

Typo.. in file name

/views/dtbake_shortcode_banner_view.php

should be

/views/dtbaker_shortcode_banner_view.php

Problem with editing single type shortcode

Hi,

when I try to use your shortcode without content so something like this.
[boutique_banner title="hello world" link="more" linkhref="#"] it works until I want to edit it.

When I try to edit the shortcode via the popupWindow It will not edit the shortcode, but instead it inserts new one to the editor, so I end up with tho shortcodes instead of one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.