I am creating a tinyMCE button for the wp WYSIWYG editor. Basically what happens is when a use clicks on the button a modal form pops up and they have to enter a few fields. However One of the fields needs to be a list box that lists every post category and the user will select one. The basic syntax for that is as follows:
{
type: 'listbox',
name: 'sds-category',
label: 'Category',
'values': [
{text: 'Name Of Cat', value: 'Cat ID'},
{text: 'Name Of Cat', value: 'Cat ID'},
{text: 'Name Of Cat', value: 'Cat ID'}]}
So in order to get all the categories displaying like that I have used a PHPfunction which will spit out that {text: '', value: ''}
syntax for every category and it goes as follows:
function write_cat_list($cat){
$cats = get_categories('hide_empty=false&orderby=name&order=ASC&parent=' . $cat);
if($cats) :
foreach ($cats as $cat) :
$tinyMCE_list[] = "{text: '".$cat->name."', value: '".$cat->term_id."'}";
write_cat_list($cat->term_id);
endforeach;
echo implode(',', $tinyMCE_list);
endif;
}
So now all that is left is placing the PHP function write_cat_list(0)
into my .js file, and that is where I am completely stuck!
I am not sure how to go about doing this, because I am very very inexperienced with AJAX, is there an easy way or a jquery function that will make it easy to include my php function to this js file?