0

I tried to add wp_editor in this function but no success. Can someone help me to add wp_editor in the 'story' field..

    function guestposts_shortcode( $atts ) {
    extract ( shortcode_atts (array(
        'cat' => '1',
        'author' => '1',
        'thanks' => get_bloginfo('home'),
    ), $atts ) );

    return '<form class="guests-post" action="'. plugin_dir_url("guest-posts.php") .'guest-posts/guest-posts-submit.php" method="post">
        <strong>' . __('Post Title:', 'guest-posts') . '</strong><br>
            <input type="text" name="title" size="60" required="required" placeholder="' . __('Post title here', 'guest-posts') . '"><br>
        <strong>' . __('Story', 'guest-posts') . '</strong>
        '. wp_nonce_field() .'
            <textarea rows="15" cols="72" required="required" name="story" placeholder="' . __('Start writing your post here', 'guest-posts') . '"></textarea><br>
        <strong>' . __('Tags', 'guest-posts') . '</strong><br>
            <input type="text" name="tags" size="60" placeholder="' . __('Comma Separated Tags', 'guest-posts') . '"><br><br>
        <strong>' . __('Your Name', 'guest-posts') . '</strong><br>
            <input type="text" name="author" size="60" required="required" placeholder="' . __('Your name here', 'guest-posts') . '"><br>
        <strong>' . __('Your Email', 'guest-posts') . '</strong><br>
            <input type="email" name="email" size="60" required="required" placeholder="' . __('Your Email Here', 'guest-posts') . '"><br>
        <strong>' . __('Your Website', 'guest-posts') . '</strong><br>
            <input type="text" name="site" size="60" placeholder="' . __('Your Website Here', 'guest-posts') . '"><br><br><br>
        <input type="hidden" value="'. $cat .'" name="category"><input type="hidden" value="'. $author .'" name="authorid">
        <input type="hidden" value="'. $thanks .'" name="thanks">
        <input type="hidden" value="'. str_replace('/wp-content/themes', '', get_theme_root()) .'/wp-blog-header.php" name="rootpath">
        <input type="submit" value="' . __('Submit The Post', 'guest-posts') . '"> <input type="reset" value="' . __('Reset', 'guest-posts') . '"><br>
        </form>
        ';
    }
add_shortcode( 'guest-posts', 'guestposts_shortcode' );

?>

And this is the submit.php

    <?php

//Get the submitted form
ob_start();
require_once($_POST["rootpath"]);
$title = $_POST["title"];
$story = $_POST["story"];
$tags = $_POST["tags"];
$author = $_POST["author"];
$email = $_POST["email"];
$site = $_POST["site"];
$authorid = $_POST["authorid"];
$category = $_POST["category"];
$thankyou = $_POST["thanks"];
$path = $_POST["rootpath"];
$nonce=$_POST["_wpnonce"];

//Load WordPress
//require($path);

//Verify the form fields


   //Post Properties
    $new_post = array(
            'post_title'    => $title,
            'post_content'  => $story,
            'post_category' => $category,  // Usable for custom taxonomies too
            'tags_input'    => $tags,
            'post_status'   => 'pending',           // Choose: publish, preview, future, draft, etc.
            'post_type' => 'post',  //'post',page' or use a custom post type if you want to
            'post_author' => $authorid //Author ID
    );
    //save the new post
    $pid = wp_insert_post($new_post);

    /* Insert Form data into Custom Fields */
    add_post_meta($pid, 'author', $author, true);
    add_post_meta($pid, 'author-email', $email, true);
    add_post_meta($pid, 'author-website', $site, true);

header("Location: $thankyou");
?>
0

The wp_editor echos the editor including a textarea. So just replace the textarea with <?php wp_editor($content, $id, $args); ?> and set the arguments as you want them to be.

https://codex.wordpress.org/Function_Reference/wp_editor

  • Did as you said,but it returns nothing – user112212 Mar 4 '14 at 16:10
  • Oh I didn't see that you are returning it... So you have to buffer it using ob_ functions. – Jonathan Mar 4 '14 at 16:20
  • wp-editor is added but it goes above the form :( I'm new to this,I've added the remaining part also,can you please tell me exactly how to get this work... – user112212 Mar 4 '14 at 16:33
  • Replace the return with a variable (call it whatever you want, i use $return) $return = 'here goes the form until the editor'; ob_start(); wp_editor(...); $return .= ob_get_clean(); $return .= 'and here goes the form after the editor'; return $return; – Jonathan Mar 4 '14 at 16:40
  • ob_ functions is already used,now the problem is wp_editor is showing but it is not inside the form – user112212 Mar 4 '14 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.