<?php 
/***********删除文章页面**********/
if ( is_user_logged_in() ) {
	global $wpdb, $userdata,$ashu_option,$wp_query,$wp_rewrite;
	$post_id = isset( $wp_query->query_vars['post_id'] ) ? $wp_query->query_vars['post_id'] : 0; 
	
	if ( $ashu_option['user']['enable_post_edit'] != 'yes' ) {
		$errors[] = '对不起，删除文章功能未启用';
	}
	$curpost = get_post( $post_id ); //根据ID获取文章
	if ( !$curpost ) {
		$errors[] = '无效的文章';
	}
	//判断权限
	if ( !current_user_can( 'delete_others_posts' ) && ( $userdata->ID != $curpost->post_author ) ) {
		$errors[] = '对不起，你没有编辑这篇文章的权限';
	}
	
	//输出错误信息
    if ( $errors ) {
		echo user_error_msg( $errors );
	}else{
		if(isset($_POST['are_you_sure'])){
			if ( ($curpost->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
				wp_delete_post( $_REQUEST['pid'] );
				//重定向
				$redirect = add_query_arg( array('msg' => 'deleted'), smzdm_my_account_link().'/my-posts' );
				wp_redirect( $redirect );
			} else {
				echo '<div class="error">你不是文章作者，不能删除文章</div>';
			}
		}else{
	?>
	
		<h2 class="box_title">删除文章：<?php echo $curpost->post_title; ?></h2>
		<form method="post" enctype="application/x-www-form-urlencoded">
		您确定要删除这篇文章？<br/><br/>
		<input type="submit" name="are_you_sure" value="确定删除"  />
		</form>
	<?php }
	}
	
} else {
	printf( "对不起，没有浏览权限，请 %s 再试", wp_loginout( '', false ) );
}
?><?php 
/***********删除文章页面**********/
if ( is_user_logged_in() ) {
	global $wpdb, $userdata,$ashu_option,$wp_query,$wp_rewrite;
	$post_id = isset( $wp_query->query_vars['post_id'] ) ? $wp_query->query_vars['post_id'] : 0; 
	
	if ( $ashu_option['user']['enable_post_edit'] != 'yes' ) {
		$errors[] = '对不起，删除文章功能未启用';
	}
	$curpost = get_post( $post_id ); //根据ID获取文章
	if ( !$curpost ) {
		$errors[] = '无效的文章';
	}
	//判断权限
	if ( !current_user_can( 'delete_others_posts' ) && ( $userdata->ID != $curpost->post_author ) ) {
		$errors[] = '对不起，你没有编辑这篇文章的权限';
	}
	
	//输出错误信息
    if ( $errors ) {
		echo user_error_msg( $errors );
	}else{
		if(isset($_POST['are_you_sure'])){
			if ( ($curpost->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
				wp_delete_post( $_REQUEST['pid'] );
				//重定向
				$redirect = add_query_arg( array('msg' => 'deleted'), smzdm_my_account_link().'/my-posts' );
				wp_redirect( $redirect );
			} else {
				echo '<div class="error">你不是文章作者，不能删除文章</div>';
			}
		}else{
	?>
	
		<h2 class="box_title">删除文章：<?php echo $curpost->post_title; ?></h2>
		<form method="post" enctype="application/x-www-form-urlencoded">
		您确定要删除这篇文章？<br/><br/>
		<input type="submit" name="are_you_sure" value="确定删除"  />
		</form>
	<?php }
	}
	
} else {
	printf( "对不起，没有浏览权限，请 %s 再试", wp_loginout( '', false ) );
}
?>