Jump to content

Help in using wp_editor in lieu of textarea in Wordpress


peter_b

Recommended Posts

Hi,

I hope someone can help me with this.  It doesn't look like it should be too hard to do but I am not very good with php.

 

I will show two code snippets below.  The 1st one uses textarea and the second uses wp_editor.

I would like to keep all the arguments etc of the first code but use wp_editor instead of the textarea.  So basically combine the two scripts into one usable script.  I hope that makes sense.

 

Code snippet 1 (textarea):

/* Post editor */
function userpro_post_editor($i, $class, $args) {
    if (!isset($args['require_content'])) {$args['require_content'] = 1;} // default for content: required
    ?>
        <div class="userpro-field userpro-field-editor" data-key="<?php echo $class; ?>">
            <div class="userpro-input">
            <?php

            if(isset($_GET['post_id']))
            {
                $post = get_post($_GET['post_id']);
                $content=apply_filters(`the_content`, $post->post_content);
            }else 
                $content='';    

                echo "<textarea data-custom-error='".__('Provide some content','userpro')."'data-required='".$args['require_content']."'  name='$class-$i' id='$class-$i' placeholder='".__('Enter content here...','userpro')."'>".$content."</textarea>";

            ?>
            </div>
        </div><div class="userpro-clear"></div>
    <?php
}

Code Snippet 2 (wp_editor):

/* Post editor */
function userpro_post_editor($i, $class, $args) {
    ?>
        <div class="userpro-field userpro-field-editor" data-key="<?php echo $class; ?>">
            <div class="userpro-input">
            <?php
                $settings = array(
                    'wpautop' => true,
                    'media_buttons' => true,
                    'teeny' => true,
                    'quicktags' => true,
                    'editor_class' => $class,
                    'textarea_rows' => 10,
                    'tinymce' => array( 
                    'content_css' => userpro_url . 'css/userpro-editor.css'
                    )
                );
                $editor_id = $class;
                $content = '';

                wp_editor( $content, $editor_id, $settings );
            ?>
            </div>
        </div><div class="userpro-clear"></div>
    <?php
}

I appreciate anyone who can help and a big thank you in advance!!

 

Peter

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.