0

Hello this is mi first question here I hope I get some answer, since i ve seen lots of unanswered questions.

I am making a plugin and I need to save values entered in tinymce button popup.

The values must go to database in any way that makes it possible. I ve tried with AJAX, jquery, but still cant make it. Thanks for your answer

This is mi code:

<?php
//colocamos boton en el editor visual de los posts
add_action('admin_head', 'add_my_tc_button');
function add_my_tc_button() {
    global $typenow;
    // check user permissions
    if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) {
    return;
    }
    // verify the post type
    if( ! in_array( $typenow, array( 'post', 'page' ) ) )
        return;
    // check if WYSIWYG is enabled
    if ( get_user_option('rich_editing') == 'true') {
        add_filter("mce_external_plugins", "add_tinymce_plugin");
        add_filter('mce_buttons', 'register_my_tc_button');
    }
}
function add_tinymce_plugin($plugin_array) {
    $plugin_array['gavickpro_tc_button'] = plugins_url( '../Admin/js/text-button.js', __FILE__ ); 
    return $plugin_array;


}
function register_my_tc_button($buttons) {
   array_push($buttons, "gavickpro_tc_button");
   return $buttons;
}

function gavickpro_tc_css() {
    wp_enqueue_style('gavickpro-tc', plugins_url('../Admin/CSS/estilo.css', __FILE__));
}

add_action('admin_enqueue_scripts', 'gavickpro_tc_css');

?>

And the text_button.js file is:

(function() {
    tinymce.PluginManager.add('gavickpro_tc_button', function( editor, url ) {
        editor.addButton( 'gavickpro_tc_button', {
            title: 'Smartlink',
            icon: 'icon gavickpro-own-icon',           
            onclick: function() {
                editor.windowManager.open( {
        title: 'Ingrese URLs (min=2 / max=5)',
                body: [{
                    type: 'textbox',
                    name: 'url1',
                    label: 'URL 1'                
                },
                {
                    type: 'textbox',
                    name: 'url2',
                    label: 'URL 2'

                },
                {
                    type: 'textbox',
                    name: 'url3',
                    label: 'URL 3'
                },
                {
                    type: 'textbox',
                    name: 'url4',
                    label: 'URL 4'
                },
                {
                    type: 'textbox',
                    name: 'url5',
                    label: 'URL 5'
                }


        ],


/************   Ingresar minimo de 2 URLs ****************   <- OK   **  */

        onsubmit: function( e ) {  
            if(e.data.url1 === '' || e.data.url2 === '') {
                var window_id = this._id;
                var inputs = jQuery('#' + window_id + '-body').find('.mce-formitem input');
                //editor.windowManager.alert("ingresa minimo 2 urls");
                        if(e.data.url1 === '') {
                            $(inputs.get(0)).css('border-color', 'red');
                        }                
                        if(e.data.url2 === '') {
                            $(inputs.get(1)).css('border-color', 'red');
                        }
                return false;


    }                           
           editor.insertContent( "<a id='crono' href='#'>anchor text</a>");

        } 
    });
              }
        });
    });
})();

I know mi code is full of errors and maybe useless lines.. I'm a beginner and learning so please I would really appreciate the words of experts here.. Thanks

  • 1
    Would you please edit your question and add the code you're using to add the button popup? – Dave Romsey Mar 24 '18 at 22:59
  • @DaveRomsey , its done, thanks. I ve been looking around for a solution but didnt find the way to do this... I give up and now working same thing but with metabox.. but if it could be done trough TMC button... That would be much better, – Sebas Rossi Mar 26 '18 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.