forked from ohsik/write-here
-
Notifications
You must be signed in to change notification settings - Fork 0
/
write-here-dashboard.php
102 lines (87 loc) · 3.69 KB
/
write-here-dashboard.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
** Write Here
Dashboard, shows all posts by current user
------------------------------------------------------------------
*/
// Edit post function
function wh_edit_post_link($link = 'Edit this', $before = '', $after = '') {
global $post;
// Get plug in options for Edit page URL
$wh_option_values = get_option( 'wirte_here_options' );
$edit_page_id = $wh_option_values['pid_num'];
$editLink = wp_nonce_url( get_bloginfo('url') . "/?p=".$edit_page_id."/?action=edit&post=" . $post->ID);
$htmllink = "<a href='" . $editLink . "'>".$link."</a>";
echo $before . $htmllink . $after;
}
// Delete post function
function wh_delete_post_link($link = 'Delete this', $before = '', $after = '') {
global $post;
$message = "Are you sure you want to delete ".get_the_title($post->ID)." ?";
$delLink = wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&post=" . $post->ID, 'delete-post_' . $post->ID);
$htmllink = "<a href='" . $delLink . "' onclick = \"if ( confirm('".$message."' ) ) { return true; } return false;\"/>".$link."</a>";
echo $before . $htmllink . $after;
}
function wh_post_status($postsdb){
if ($postsdb == "future"):
$wp_ps = "Scheduled";
elseif ($postsdb == "private"):
$wp_ps = "Private";
else:
$wp_ps = "Published";
endif;
echo $wp_ps;
}
function write_here_dashboard(){
global $current_user;
get_currentuserinfo();
$page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$author_total_posts = count_user_posts($current_user->ID);
$post_pp = 10; // Set number of posts per page
$pages = ceil($author_total_posts/$post_pp);
$offset = ($page * $post_pp) - $post_pp;
$author_query = array(
'posts_per_page' => $post_pp,
'offset'=> $offset,
'post_status' => array('publish', 'future', 'private'),
'author' => $current_user->ID
);
$author_posts = new WP_Query($author_query);
// Show all posts by current user
if($author_posts->have_posts()){
echo '<div class="write-here-dashboard"><ul>';
while($author_posts->have_posts()) : $author_posts->the_post();
$postsdb = get_post_status();
?>
<li>
<p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<p class="wh-post-meta"><?php wh_post_status($postsdb); ?> on <i><?php echo get_the_date(); ?></i> <span class="wh-edit"> <?php wh_edit_post_link('Edit', '', ''); ?> / <?php wh_delete_post_link('Delete', '', ''); ?></span></p>
</li>
<?php
endwhile;
echo '</ul></div>';
// Show pagination for the posts
echo '<div class="wh-pagenavi">';
$big = 999999999999; // need an unlikely integer
$prev_arrow = is_rtl() ? '→' : '←';
$next_arrow = is_rtl() ? '←' : '→';
$args = array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'total' => $pages,
'current' => $page,
'show_all' => False,
'end_size' => 1,
'mid_size' => 3,
'prev_next' => True,
'prev_text' => $prev_arrow,
'next_text' => $next_arrow,
'type' => 'list');
// ECHO THE PAGENATION
echo paginate_links( $args );
echo '</div>';
wp_reset_query();
}else{
echo '<p>Write your first post!</p>';
}
}