Plantilla personalizada y formulario de envío en WordPress

  • Autor Autor Felipe
  • Fecha de inicio Fecha de inicio
F

Felipe

"Guest Post" para que cualquiera envíe un post en wordpress. No se MUCHO de programación (en realidad casi nada), el siguiente código lo arme con extractos encontrados por Internet. La cosa es que quiero lograr crear una plantilla personalizada para wordpress (o quizás un plugin) donde al crear una página pueda poner un formulario donde un usuaio CUALQUIERA (no necesariamente que esté registrado) envíe un texto y una foto. Este es el código que tengo:

Insertar CODE, HTML o PHP:
<?php
/*
Template Name: Enviar tu post
*/
?>

<?php
get_header(); ?>


		<div id="container">
			<div id="content" role="main">

<h1 class="entry-title"><?php the_title(); ?></h1>

<div class="entry-content"><?php the_content(); ?>
</div>
<?php 


if(isset($_POST['new_post']) == '1') {
$post_title = $_POST['post_title'];
$post_category = 'fashion';
$post_content = $_POST['post_content'];

$new_post = array(
      'ID' => '',
      'post_author' => $user->ID, 
      'post_category' => array($post_category),
      'post_content' => $post_content,
      'post_title' => $post_title,
      'post_status' => 'draft'
    );

$post_id = wp_insert_post($new_post);


        if (!function_exists('wp_generate_attachment_metadata')){
            require_once(ABSPATH . "wp-admin" . '/includes/image.php');
            require_once(ABSPATH . "wp-admin" . '/includes/file.php');
            require_once(ABSPATH . "wp-admin" . '/includes/media.php');
        }
         if ($_FILES) {
            foreach ($_FILES as $file => $array) {
                if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
                    return "upload error : " . $_FILES[$file]['error'];
                }
                $attach_id = media_handle_upload( $file, $post_id );
            }   
        }
if ($attach_id > 0){
    $post = get_post($post_id,'ARRAY_A');
    $image = wp_get_attachment_image_src( $attach_id );
    $image_tag = '<img src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" />';

    //add image above the content
    $post['post_content'] = $image_tag . $post['post_content'];

    //add image under the content
    //$post['post_content'] = $post['post_content'] . $image_tag;

    $post_id =  wp_update_post( $post );
}


// This will redirect you to the newly created post
$post = get_post($post_id);
wp_redirect( get_permalink($post_id));
exit();
}

?>      

<script>
contenido_textarea = ""
num_caracteres_permitidos = 200

function valida_longitud(){
   num_caracteres = document.forms[0].post_content.value.length

   if (num_caracteres > num_caracteres_permitidos){
      document.forms[0].post_content.value = contenido_textarea
   }else{
      contenido_textarea = document.forms[0].post_content.value
   }

   if (num_caracteres >= num_caracteres_permitidos){
      document.forms[0].caracteres.style.color="#ff0000";
   }else{
      document.forms[0].caracteres.style.color="#000000";
   }

   cuenta()
}
function cuenta(){
   document.forms[0].caracteres.value=document.forms[0].post_content.value.length
}

</script> 

<style>
.verif{ display: none; }
</style>

<form method="post" action="/wordpress/envio-del-post" enctype="multipart/form-data">
Titulo de la foto:<br>
<input type="text" name="post_title" size="45" id="input-title" value="" required/><br>
Elige la foto:<br><input type="file" name="thumbnail" id="thumbnail" multiple accept='image/*' required><br>
Escribe una breve descripción:<br><textarea rows="5" name="post_content" cols="66" id="text-desc" onKeyDown="valida_longitud()" onKeyUp="valida_longitud()" required></textarea> <br>
Solo tienes 200 caracteres. <input type="text" name="caracteres" size="4" /> <br>
<input type="hidden" name="new_post" value="1"/> <br>
     <label for="verificacion" class="verif">¡Si ves esto, no llenes el siguiente campo!</label>
     <input name="verificacion" class="verif" />
<input class="subput round" type="submit" name="submit" value="Post"/><br>
</form>

			</div><!-- #content -->
		</div><!-- #container -->

<?php get_footer(); ?>

¿Que es lo que me falta?
Bueno, la verdad es que funciona... El pero está en que no logro limitar el tamaño de la imagen y tampoco logro integrarle un "control antispam".

Alguien, algún programador que sepa podría ayudarme? yo libero el código, cualquiera lo puede usar, no busco hacerme rico con esto es un "Aporte" a la comunidad.

Saludos ojala puedan ayudarme a hacer lo que me falta.
 
En wordpress puedes hacerlo por defecto. Sólo tienes que permitir que la gente se registre como editores y ya está, suben sus post y tú los publicas o no.
 
En wordpress puedes hacerlo por defecto. Sólo tienes que permitir que la gente se registre como editores y ya está, suben sus post y tú los publicas o no.
Lo sé, es que para la audiencia que quiero llegar, difícilmente se registrarán... La pereza y facilitar las cosas para el usuario.
 
Yo hice una nueva página y ahí puse un formulario con el plugin Contact Form, así de simple 😛
 
Yo hice una nueva página y ahí puse un formulario con el plugin Contact Form, así de simple 😛
Pero como lo haces para que las entradas queden en borrador en el panel de wordpress?

Yo hasta ahora tambien ocupo contact form, pero las entradas tengo que estarlas tomando del correo para postearlas en el blog...
 
"Guest Post" para que cualquiera envíe un post en wordpress. No se MUCHO de programación (en realidad casi nada), el siguiente código lo arme con extractos encontrados por Internet. La cosa es que quiero lograr crear una plantilla personalizada para wordpress (o quizás un plugin) donde al crear una página pueda poner un formulario donde un usuaio CUALQUIERA (no necesariamente que esté registrado) envíe un texto y una foto. Este es el código que tengo:

Insertar CODE, HTML o PHP:
<?php
/*
Template Name: Enviar tu post
*/
?>

<?php
get_header(); ?>


		<div id="container">
			<div id="content" role="main">

<h1 class="entry-title"><?php the_title(); ?></h1>

<div class="entry-content"><?php the_content(); ?>
</div>
<?php 


if(isset($_POST['new_post']) == '1') {
$post_title = $_POST['post_title'];
$post_category = 'fashion';
$post_content = $_POST['post_content'];

$new_post = array(
      'ID' => '',
      'post_author' => $user->ID, 
      'post_category' => array($post_category),
      'post_content' => $post_content,
      'post_title' => $post_title,
      'post_status' => 'draft'
    );

$post_id = wp_insert_post($new_post);


        if (!function_exists('wp_generate_attachment_metadata')){
            require_once(ABSPATH . "wp-admin" . '/includes/image.php');
            require_once(ABSPATH . "wp-admin" . '/includes/file.php');
            require_once(ABSPATH . "wp-admin" . '/includes/media.php');
        }
         if ($_FILES) {
            foreach ($_FILES as $file => $array) {
                if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
                    return "upload error : " . $_FILES[$file]['error'];
                }
                $attach_id = media_handle_upload( $file, $post_id );
            }   
        }
if ($attach_id > 0){
    $post = get_post($post_id,'ARRAY_A');
    $image = wp_get_attachment_image_src( $attach_id );
    $image_tag = '<img src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" />';

    //add image above the content
    $post['post_content'] = $image_tag . $post['post_content'];

    //add image under the content
    //$post['post_content'] = $post['post_content'] . $image_tag;

    $post_id =  wp_update_post( $post );
}


// This will redirect you to the newly created post
$post = get_post($post_id);
wp_redirect( get_permalink($post_id));
exit();
}

?>      

<script>
contenido_textarea = ""
num_caracteres_permitidos = 200

function valida_longitud(){
   num_caracteres = document.forms[0].post_content.value.length

   if (num_caracteres > num_caracteres_permitidos){
      document.forms[0].post_content.value = contenido_textarea
   }else{
      contenido_textarea = document.forms[0].post_content.value
   }

   if (num_caracteres >= num_caracteres_permitidos){
      document.forms[0].caracteres.style.color="#ff0000";
   }else{
      document.forms[0].caracteres.style.color="#000000";
   }

   cuenta()
}
function cuenta(){
   document.forms[0].caracteres.value=document.forms[0].post_content.value.length
}

</script> 

<style>
.verif{ display: none; }
</style>

<form method="post" action="/wordpress/envio-del-post" enctype="multipart/form-data">
Titulo de la foto:<br>
<input type="text" name="post_title" size="45" id="input-title" value="" required/><br>
Elige la foto:<br><input type="file" name="thumbnail" id="thumbnail" multiple accept='image/*' required><br>
Escribe una breve descripción:<br><textarea rows="5" name="post_content" cols="66" id="text-desc" onKeyDown="valida_longitud()" onKeyUp="valida_longitud()" required></textarea> <br>
Solo tienes 200 caracteres. <input type="text" name="caracteres" size="4" /> <br>
<input type="hidden" name="new_post" value="1"/> <br>
     <label for="verificacion" class="verif">¡Si ves esto, no llenes el siguiente campo!</label>
     <input name="verificacion" class="verif" />
<input class="subput round" type="submit" name="submit" value="Post"/><br>
</form>

			</div><!-- #content -->
		</div><!-- #container -->

<?php get_footer(); ?>

¿Que es lo que me falta?
Bueno, la verdad es que funciona... El pero está en que no logro limitar el tamaño de la imagen y tampoco logro integrarle un "control antispam".

Alguien, algún programador que sepa podría ayudarme? yo libero el código, cualquiera lo puede usar, no busco hacerme rico con esto es un "Aporte" a la comunidad.

Saludos ojala puedan ayudarme a hacer lo que me falta.


Este plugin es lo que necesitas WordPress ? User Submitted Posts « WordPress Plugins

saludos
 
Bueno, es el que voy a ocupar... por ahora, mientras encuentro la forma de limitar el peso de las imagenes y agregarle un captach o control anty spam.

Muchas, gracias! 🙂

tiene todo eso que deseas, anti spam y tamaño de imágenes
 
Atrás
Arriba