Edição de postagem frontal usando um formulário
3 respostas
- votos
-
- 2011-02-21
Se você quisereditar umpostexistente,tente meu editor defront-end plugin.
Se você quiser criarnovaspostagens,tente um desses:
If you want to edit an existing post, try my Front-end Editor plugin.
If you want to create new posts, try one of these:
-
Obrigado Scribo.Seuplugin éfantástico,masnão seencaixanaminhanecessidade.Euestoutentandoeditar umpostexistente com umformulário.Eufiz umapergunta semelhante sobre aedição de umperfil de um usuário com umformulárionofrontende recebiesta resposta: http://wordpress.stackexchange.com/Questions/9775/How-To-edit-a-user-profile-on-ofront-endissofuncionouperfeitamenteparamim.Se houver uma solução semelhanteparaeditarposts,seriamuitograto.Thanks Scribu. Your plugin is fantastic, but it does not fit my need. I am trying to edit an existing post with a form. I asked a similar question about editing a user's profile with a form in the frontend and I received this response: http://wordpress.stackexchange.com/questions/9775/how-to-edit-a-user-profile-on-the-front-end This worked perfectly for me. If there is a similar solution for editing posts I would be so grateful.
- 0
- 2011-02-21
- Carson
-
Épossível adicionarmetaboxesjunto comisso?is it possible to add metaboxes along with it??
- 0
- 2011-06-17
- nickfrancis.me
-
@ Nickfancis.me Use comentáriosparaessetipo de coisa -isso é o queelesestão lápara!@nickfancis.me use comments for this sort of thing - that's what they're there for!
- 0
- 2011-06-17
- TheDeadMedic
-
@ Nickfrancis.memetaboxes sãoestritamentepara obackend.Talvez você quer dizer widgets?@nickfrancis.me Metaboxes are strictly for the backend. Maybe you mean widgets?
- 0
- 2011-06-17
- scribu
-
- 2013-07-15
Aquiestão as soluçõesbásicaspara atualizar umapostagem/página. Eu adicionei uma demonstração rápida de campos demetapersonalizados. Isso ébonito,mas apontará-lona direção doplugin-menosedição depostsnofront-end. Issonão é superflexível,mas vocêpode adicionar o que vocêprecisa.
Adicioneeste códigono seu loop:
<form id="post" class="post-edit front-end-form" method="post" enctype="multipart/form-data"> <input type="hidden" name="post_id" value="<?php the_ID(); ?>" /> <?php wp_nonce_field( 'update_post_'. get_the_ID(), 'update_post_nonce' ); ?> <p><label for="post_title">Title</label> <input type="text" id="post_title" name="post_title" value="<?php echo $post->post_title; ?>" /></p> <p><?php wp_editor( $post->post_content, 'postcontent' ); ?></p> <p><label for="post_title">Test</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test', true); ?> <input type="text" id="edit_test" name="edit_test" value="<?php echo $value; ?>" /></p> <p><label for="post_title">Test 2</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test2', true); ?> <input type="text" id="edit_test2" name="edit_test2" value="<?php echo $value; ?>" /></p> <input type="submit" id="submit" value="Update" /> </form>
Adicioneeste códigonaparte superior dapáginaparaprocessar oformulário:
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && ! empty($_POST['post_id']) && ! empty($_POST['post_title']) && isset($_POST['update_post_nonce']) && isset($_POST['postcontent']) ) { $post_id = $_POST['post_id']; $post_type = get_post_type($post_id); $capability = ( 'page' == $post_type ) ? 'edit_page' : 'edit_post'; if ( current_user_can($capability, $post_id) && wp_verify_nonce( $_POST['update_post_nonce'], 'update_post_'. $post_id ) ) { $post = array( 'ID' => esc_sql($post_id), 'post_content' => esc_sql($_POST['postcontent']), 'post_title' => esc_sql($_POST['post_title']) ); wp_update_post($post); if ( isset($_POST['edit_test']) ) update_post_meta($post_id, 'edit_test', esc_sql($_POST['edit_test']) ); if ( isset($_POST['edit_test2']) ) update_post_meta($post_id, 'edit_test2', esc_sql($_POST['edit_test2']) ); } else { wp_die("You can't do that"); } }
Here is a basic solutions for updating a post/page. I added a quick demo of custom meta fields. This is pretty basic, but will point you in the direction of plugin-less editing of posts on the front-end. This isn't super flexible, but you can add whatever you need to it.
Add this code into your loop:
<form id="post" class="post-edit front-end-form" method="post" enctype="multipart/form-data"> <input type="hidden" name="post_id" value="<?php the_ID(); ?>" /> <?php wp_nonce_field( 'update_post_'. get_the_ID(), 'update_post_nonce' ); ?> <p><label for="post_title">Title</label> <input type="text" id="post_title" name="post_title" value="<?php echo $post->post_title; ?>" /></p> <p><?php wp_editor( $post->post_content, 'postcontent' ); ?></p> <p><label for="post_title">Test</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test', true); ?> <input type="text" id="edit_test" name="edit_test" value="<?php echo $value; ?>" /></p> <p><label for="post_title">Test 2</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test2', true); ?> <input type="text" id="edit_test2" name="edit_test2" value="<?php echo $value; ?>" /></p> <input type="submit" id="submit" value="Update" /> </form>
Then add this code at the top of the page to process the form:
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && ! empty($_POST['post_id']) && ! empty($_POST['post_title']) && isset($_POST['update_post_nonce']) && isset($_POST['postcontent']) ) { $post_id = $_POST['post_id']; $post_type = get_post_type($post_id); $capability = ( 'page' == $post_type ) ? 'edit_page' : 'edit_post'; if ( current_user_can($capability, $post_id) && wp_verify_nonce( $_POST['update_post_nonce'], 'update_post_'. $post_id ) ) { $post = array( 'ID' => esc_sql($post_id), 'post_content' => esc_sql($_POST['postcontent']), 'post_title' => esc_sql($_POST['post_title']) ); wp_update_post($post); if ( isset($_POST['edit_test']) ) update_post_meta($post_id, 'edit_test', esc_sql($_POST['edit_test']) ); if ( isset($_POST['edit_test2']) ) update_post_meta($post_id, 'edit_test2', esc_sql($_POST['edit_test2']) ); } else { wp_die("You can't do that"); } }
-
Eu adicionei Esc_SQL ().Acabei deme ocorrer que você deveescapar de dados sendo submetidos apartir de umaformapública (semi-pública) comoessa.I added esc_sql(). It just occurred to me that you should escape data being submitted from a public (semi-public) form like that.
- 0
- 2013-07-16
- Jake
-
Obrigado,masmeuformulário sóestá disponívelpara administrador.De qualquerforma,será útil se alguma vezeu usaresteformulárioparapostagempública.Thanks, But my form is only available for Admin. Anyway it will be helpful if ever I use this form for public posting.
- 1
- 2013-07-17
- user1983017
-
- 2013-07-14
Amaneiramaisfácil seria usar algo comoformasninjas com a seguinteextensãopaga:
http://wpninjas.com/downloads/front-end-posting/
Vocêtambémpode codificarisso sozinho. Essencialmente,você criará umformulárioe,em seguida,usará
wp_insert_post()
para criar umpost completo.Umformulário de amostra:
<form action="" id="primaryPostForm" method="POST"> <fieldset> <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label> <input type="text" name="postTitle" id="postTitle" class="required" /> </fieldset> <fieldset> <label for="postContent"><?php _e('Post Content:', 'framework') ?></label> <textarea name="postContent" id="postContent" rows="8" cols="30" class="required"></textarea> </fieldset> <fieldset> <input type="hidden" name="submitted" id="submitted" value="true" /> <button type="submit"><?php _e('Add Post', 'framework') ?></button> </fieldset>
e depoisem enviar,vocêeconomizariaprocesso algo como:
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) { if ( trim( $_POST['postTitle'] ) === '' ) { $postTitleError = 'Please enter a title.'; $hasError = true; } $post_information = array( 'post_title' => wp_strip_all_tags( $_POST['postTitle'] ), 'post_content' => $_POST['postContent'], 'post_type' => 'post', 'post_status' => 'pending' ); wp_insert_post( $post_information ); }
O código completoe otutorial é de: http://wp.tutsplus.com/Tutoriais/codificação criativa/postagem-via-front-inserção/
The easiest way would be to use something like Ninja Forms with the following paid extension:
http://wpninjas.com/downloads/front-end-posting/
You could also code this yourself. Essentially you'll create a form, and then use
wp_insert_post()
to create a full post.A sample form:
<form action="" id="primaryPostForm" method="POST"> <fieldset> <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label> <input type="text" name="postTitle" id="postTitle" class="required" /> </fieldset> <fieldset> <label for="postContent"><?php _e('Post Content:', 'framework') ?></label> <textarea name="postContent" id="postContent" rows="8" cols="30" class="required"></textarea> </fieldset> <fieldset> <input type="hidden" name="submitted" id="submitted" value="true" /> <button type="submit"><?php _e('Add Post', 'framework') ?></button> </fieldset>
and then on submit, you'd save process it something like:
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) { if ( trim( $_POST['postTitle'] ) === '' ) { $postTitleError = 'Please enter a title.'; $hasError = true; } $post_information = array( 'post_title' => wp_strip_all_tags( $_POST['postTitle'] ), 'post_content' => $_POST['postContent'], 'post_type' => 'post', 'post_status' => 'pending' ); wp_insert_post( $post_information ); }
The full code and tutorial is from: http://wp.tutsplus.com/tutorials/creative-coding/posting-via-the-front-end-inserting/
-
Eu só quero atualizar (editarexistente) opost/página,nãoinserir.I Just want to update (edit existing) the post/page, not insert.
- 0
- 2013-07-14
- user1983017
-
Entãopor quenãotentar oplugin "Editor defrontend"já referenciadopor Scribu?Then why not try the already-referenced "Front End Editor" plugin by Scribu?
- 0
- 2013-07-14
- helgatheviking
Eutenho umtipopersonalizado com as caixas demetapadrãoe alguns campospersonalizados.Comoeupoderiaeditar umpost através de umformulárionofrontend?