-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-post.php
75 lines (57 loc) · 1.96 KB
/
create-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Template Name: Create Post
*
*/
$post = get_post($_GET['id']);
//add redirect if user can't edit this post
if(!is_user_logged_in()){
set_transient( 'originalRegisterRefererURL', $_SERVER['HTTP_REFERER'], 60 * 60 * 24 );
wp_redirect( wp_login_url() );
}
if(!(wp_get_current_user()->ID == $post->post_author)
&& !current_user_can( 'edit_others_posts')
&& $_GET['action'] == 'edit')
wp_redirect(home_url());
if(wp_get_current_user()->ID == $post->post_author && $_GET['action'] == 'create')
wp_redirect(get_permalink($_GET['id']));
acf_form_head();
get_header(); ?>
<div class="page main-container">
<?php
if( isset($_GET['id']) && isset($_GET['action']) && $_GET['action'] == 'edit' ){
acf_form(array(
'post_id' => $_GET['id'],
'post_title' => true,
'post_content' => false,
'return' => '%post_url%',
'submit_value' => __("Publicar", 'acf')
));
}
else{
if($_GET['action'] == "create" && isset($_GET['id']))
echo "<div class='excerp'>Responder a <a class='answer__to' href='".get_permalink($_GET['id'])."'>".get_the_title($_GET['id'])."</a></div>";
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => false,
'return' => '%post_url%',
'submit_value' => __("Publicar", 'acf'),
'new_post' => array(
'post_type' => 'post',
'post_status' => 'publish'
)
));
}
?>
</div>
<script>
jQuery("form").submit(function(e){
if(tinymce.activeEditor.getContent({format : 'text'}).length < 500){
e.preventDefault();
e.stopPropagation(); // Prevent the acf object from ever hearing about this form submission
alert("Respuesta no tiene un mínimo 500 caracteres");
}
});
</script>
<?php wp_footer() ?>