Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load wp_editor using Jquery?

I want to add WordPress editor dynamically using jquery in my custom plugin as follow:

 <?php

  $content = '';

  $editor_id = 'mycustomeditor';      

?>

 $('#container').append('<?php wp_editor( $content, $editor_id );?>');

I am getting error:

SyntaxError: missing ) after argument list

...-active"><link rel='stylesheet' id='editor-buttons-css'  href='http://localhost 

I have also tried bellow code(here I have replaced single quotes to double quotes):

  <?php

     $content = '';

     $editor_id = 'mycustomeditor';      

  ?>

  $('#container').append("<?php wp_editor( $content, $editor_id );?>");

I am getting error:

 SyntaxError: missing ) after argument list   


$('#container').append("<div id="wp-mycustomeditor-wrap" class="wp-core-ui wp-ed...

If you have any solution please let me know.

Thanks in advance

like image 995
shashank Avatar asked Sep 03 '14 12:09

shashank


Video Answer


2 Answers

I know late answer. but it will help others. Try this jQuery plugin.

https://github.com/anteprimorac/js-wp-editor

you can use simple like below

    jQuery(document).ready(function (){

        jQuery('#container').wp_editor();

    });
like image 106
Vel Avatar answered Sep 27 '22 19:09

Vel


   add_action('init','my_wpEditOUPUTT');function my_wpEditOUPUTT(){
if (isset($_POST['Give_me_editorrr'])){
    wp_editor( '' , 'txtrID_'.$_POST['myNumber'], $settings = array( 'editor_class'=>'my_class',     'textarea_name'=>'named_'. $_POST['myNumber'],  'tinymce'=>true , 'media_buttons' => true , 'teeny' => false,));
    exit;   
}}

<div id="MyPlace"></div> <a href="javascript:myLoad();">Click to load</a>

<script type="text/javascript">
  startNumber = 1;
  function myLoad(){ alert('wait 1 sec');
  startNumber ++;
  $.post('./index.php', '&Give_me_editorrr=1&myNumber='+startNumber ,
    function(data,status){ 
        if (status == "success") {  
            document.getElementById('MyPlace').innerHTML += data; alert("Inserted!");   
            tinymce.init({ selector: 'txtrID_'+startNumber, theme:'modern',  skin:'lightgray'}); tinyMCE.execCommand('mceAddEditor', false, 'txtrID_'+startNumber);
        }
});}

like image 40
kaushik dey Avatar answered Sep 27 '22 19:09

kaushik dey