-
-
Save matheusgimenez/15387a5f6ddc14265ba38cf93fb1f85f to your computer and use it in GitHub Desktop.
salvamento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: verificando | |
* | |
* @package WordPress | |
* @subpackage Twenty_Fourteen | |
* @since Twenty Fourteen 1.0 | |
*/ | |
get_header(); ?> | |
<meta http-equiv="refresh" content="1; url=<?php echo esc_url( home_url( '/category/' ) ); ?><?php echo $_POST['categoria'];?>"> | |
<div id="wrapper"> | |
<body> | |
<div id="wrapper"> | |
<div id="page-wrapper"> | |
<div class="row"> | |
<div class="col-lg-12"> | |
<h1 class="page-header"> | |
Aguarde Processando... </h1> | |
</div> | |
<!-- /.col-lg-12 --> | |
</div> | |
<!-- /.row --> | |
<!-- /.row --> | |
<div class="progress"> | |
<div class="progress-bar progress-bar-striped active" role="progressbar" | |
aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%"> | |
</div> | |
</div> | |
</div> | |
<!-- /.panel-footer --> | |
</div> | |
<!-- /.panel .chat-panel --> | |
</div> | |
<!-- /.col-lg-4 --> | |
</div> | |
<!-- /.row --> | |
</div> | |
<!-- /#page-wrapper --> | |
</div> | |
<!-- /#wrapper --> | |
</body> | |
</html> | |
<?php | |
// Functions.php content: | |
function insert_attachment($file_handler,$post_id,$setthumb='false') { | |
// check to make sure its a successful upload | |
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false(); | |
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); | |
require_once(ABSPATH . "wp-admin" . '/includes/file.php'); | |
require_once(ABSPATH . "wp-admin" . '/includes/media.php'); | |
$attach_id = media_handle_upload( $file_handler, $post_id ); | |
$filetype = wp_check_filetype('$attach_id'); | |
echo $filetype['type']; | |
if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id); | |
return $attach_id; | |
} | |
// pega o objeto da categoria de forma dinamica | |
$category = get_category_by_slug($_POST['categoria']); | |
// Post form content | |
if ( ! isset( $_REQUEST[ 'post_id'] ) ) { | |
$post_id = wp_insert_post( | |
array( | |
//'comment_status' => 'open', | |
//'ping_status' => 'closed', | |
//'post_author' => $user_id, | |
//'post_name' => $slug, | |
'post_title' => $_POST['Nome'], | |
'post_status' => 'publish', | |
'post_type' => 'post', | |
//'post_content' => $_POST['quick-post-area'], | |
'post_category' => array( $category->term_id ), | |
) | |
); | |
} else { | |
$post_id = wp_update_post( | |
array( | |
//'comment_status' => 'open', | |
//'ping_status' => 'closed', | |
//'post_author' => $user_id, | |
//'post_name' => $slug, | |
'ID' => $_REQUEST[ 'post_id'], | |
'post_title' => $_POST['Nome'], | |
'post_status' => 'publish', | |
'post_type' => 'post', | |
//'post_content' => $_POST['quick-post-area'], | |
'post_category' => array( $category->term_id ), | |
) | |
); | |
} | |
if ( isset( $_POST[ 'Nome'] ) && $post_id ) { | |
// Seta os posts meta | |
foreach ( $_POST as $key => $value) { | |
// limpa pra evitar invasores | |
$value = esc_html( $value ); | |
if ( get_post_meta( $post_id, strtolower( $key ), true ) { | |
$key = strtolower( $key ); | |
} | |
update_post_meta( $post_id, $key, $value ); | |
} | |
} | |
if ($_FILES) { | |
foreach ($_FILES as $file => $array) { | |
if ( intval( $array[ 'size' ] ) > 0 ) { | |
$newupload = insert_attachment($file,$post_id); | |
} | |
// $newupload returns the attachment id of the file that | |
// was just uploaded. Do whatever you want with that now. | |
} | |
} | |
?> | |
<p>Hey! You are creating the post #<?php echo $post_id; ?></p> | |
<input type="hidden" name="draft_id" value="<?php echo $post_id; ?>"> | |
<?php echo $post_id ; ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment