Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm creating a plugin that shows a frontend editor that will be the content of the current post. But I don't know who to save the content from the wp_editor to the post content;

I tried using on form action admin_url('post.php'), but I didn't work. I have been checking around but I didn't find any solution.

Thanks!

Here's what I have now:

function front_end_editor(){
    //if(is_user_logged_in()){
        $settings = array(
            'wpautop' => true,
            'media_buttons' => true,
            'tinymce' => true,
            'textarea_name' => 'fe_content'
        );
        if(is_single() || is_page()){
            //admin_url('post.php')
            echo '<form action="' . get_permalink() . '" method="get">';
            wp_editor(esc_html(get_the_content()), 'textarea_post', $settings);
            echo '<input type="hidden" name="save" value="true"/>';
            echo '<input type="submit" value="Submit" /></form>';

            if($_REQUEST['save'] == true){
                global $post;
                $post->post_content = '$_REQUEST['fe_content'];
            }
        }
    //}
}

add_action('the_content', 'front_end_editor');
share|improve this question
add comment

1 Answer 1

Use WordPress's Ajax API. like this:

$.ajax({
    data: {
        action: 'save_post_frontend',
        content: // get your text
    },
    method: 'POST',
    url: ajaxurl,
    success: // on success
});

Now save the data in wp_ajax_save_post_frontend hook. See documentation for more info.

share|improve this answer
    
Thanks but works with wp_insert_post() –  jepser Apr 11 '12 at 21:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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