phpjquerywordpresswp-editor

Adding wp_editor to user created metabox


So, I've set up a plugin that allows my client to be able to add metaboxes with a button and therefore add new content that is more dynamic, with additional titles/headings etc. This is how it's set up right now...

function Print_price_fileds($cnt, $p = null) {
if ($p === null){
    $a = $b = $c = '';
}else{
    $a = $p['n'];
    $b = $p['d'];
    $c = $p['p'];
}
return  <<<HTML
<li>
  <input type="text" name="additional_content[$cnt][d]" size="50" value="$b" placeholder="Title"/>

  <textarea name="additional_content[$cnt][p]" class="wp-editor-area" style="height: 320px; width: 100%; margin-top: 37px;" autocomplete="off" placeholder="Content">$c</textarea>
  <span class="remove submitdelete deletion">Remove</span>
</li>
HTML
;
}



function additional_content_boxes(){
 global $post;

  $data = get_post_meta($post->ID,"additional_content",true);

  echo '<div>';
  echo '<ul id="additional_content_items">';
  $c = 0;
    if (count($data) > 0){
        foreach((array)$data as $p ){
            if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){
                echo Print_price_fileds($c,$p);
                $c = $c +1;
            }
        }

    }
    echo '</ul>';

    ?>
        <span id="here"></span>
        <span class="add button button-primary button-large"><?php echo __('Add Additional Content'); ?></span>
        <script>
            var $ =jQuery.noConflict();
                $(document).ready(function() {
                var count = <?php echo $c - 1; ?>; // substract 1 from $c
                $(".add").click(function() {
                    count = count + 1;
                   $('#additional_content_items').append('<? echo implode('',explode("\n",Print_price_fileds('count'))); ?>'.replace(/count/g, count));
                    return false;
                });
                $(".remove").live('click', function() {
                    $(this).parent().remove();
                });
            });
        </script>
        <style>#additional_content_items {list-style: none; padding-bottom: 20px; border-bottom: 1px solid #ddd; margin-top: 30px; display: block;}</style>
    <?php
    echo '</div>';
}

This works just fine right now, but I'd like to be able to add the wp_editor to the additional metaboxes, thereby replacing the <textarea>. How can I make this happen?

Thanks guys. J


Solution

  • So, I took Noman's advice and I'm using the Advanced Custom Fields plugin. Don't know why I hadn't heard of it before, because it's perfect. Thanks everyone!

    https://wordpress.org/plugins/advanced-custom-fields/