How to get Data To WordPress TinyMCE Listbox from Database

I am developing a WordPress shot-code plugin.

i have added a listbox in TinyMCE and i need to load data to TinyMCE from wordpress database. i can not hard code the listbox values since all my shortcodes values are saved in wordpress database.

Read More

is there any possible way to do this ?

(function() {
    tinymce.PluginManager.add('AP_tc_button', function( editor, url ) {
        editor.addButton( 'AP_tc_button', {
            text: 'My test button',
            icon: 'wp_code',
            onclick: function() {
    editor.windowManager.open( {
        title: 'Select Your AD',
        body: [
        {
            type: 'listbox', 
            name: 'level', 
            label: 'Header level', 
           values: getValues()
        }],
        onsubmit: function( e ) {
            editor.insertContent('dd');
        }
    });
}
        });
    });


})();


function getValues() {
     //Set new values to myKeyValueList (i need this values get from the db)
tinyMCE.activeEditor.settings.myKeyValueList = [{text: 'newtext', value: 'newvalue'}];
      return tinyMCE.activeEditor.settings.myKeyValueList;
   }

Related posts

Leave a Reply

1 comment

  1. if it helps someone who visit this post.

    My solution was retrieving the data through a ajax request. The trick is doing a synchronous request (async: false).

    function getValues() {
    
        var data = {'action': 'getValuesAjax'};
    
        var q = jQuery.ajax({
            type: 'POST',
            url: ajaxurl,
            data: data,
            async: false,
            dataType: 'json'
        });      
    
        var values = q.responseJSON;
        return values;
    }