'off',
'post_type' => 'post',
'category' => 'off',
'featured_image' => 'default',
'meta' => 'off',
'excerpt' => 'off',
'payment_column' => 'on',
], $atts
);
$attributes = array_merge( $attributes, $atts );
ob_start();
if ( is_user_logged_in() ) {
$this->post_listing( $attributes );
} else {
$message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
wpuf_load_template( 'unauthorized.php', [ 'message' => $message ] );
}
$content = ob_get_contents();
ob_end_clean();
return $content;
}
/**
* List's all the posts by the user
*
* @global object $wpdb
* @global object $userdata
*/
public function post_listing( $attributes ) {
global $post;
//phpcs:ignore
extract( $attributes );
$pagenum = isset( $_GET['pagenum'] ) ? intval( wp_unslash( $_GET['pagenum'] ) ) : 1;
$action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
$msg = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( $_GET['msg'] ) ) : '';
//delete post
if ( $action === 'del' ) {
$this->delete_post();
}
//show delete success message
if ( $msg === 'deleted' ) {
echo wp_kses_post( '
' . __( 'Post Deleted', 'wp-user-frontend' ) . '
' );
}
$post_type = explode( ',', $post_type );
$args = [
'author' => get_current_user_id(),
'post_status' => [ 'draft', 'future', 'pending', 'publish', 'private' ],
'post_type' => $post_type,
'posts_per_page' => wpuf_get_option( 'per_page', 'wpuf_dashboard', 10 ),
'paged' => $pagenum,
];
if ( isset( $attributes['form_id'] ) && $attributes['form_id'] !== 'off' ) {
$args['meta_query'] = [
[
'key' => '_wpuf_form_id',
'value' => $attributes['form_id'],
'compare' => 'IN',
],
];
}
if ( isset( $attributes['category__in'] ) ) {
$taxonomy = [ 'category' ];
if ( class_exists( 'WooCommerce' ) ) {
$taxonomy[] = 'product_cat';
}
$attributes['category__in'] = get_terms(
[
'name' => explode( ',', $attributes['category__in'] ),
'taxonomy' => $taxonomy,
'fields' => 'ids',
]
);
}
if ( isset( $attributes['author__in'] ) ) {
$attributes['author__in'] = get_users(
[
'nicename__in' => explode( ',', $attributes['author__in'] ),
'fields' => 'ids',
]
);
unset( $args['author'] );
}
$args = array_merge( $args, $attributes );
$original_post = $post;
$dashboard_query = new WP_Query( apply_filters( 'wpuf_dashboard_query', $args, $attributes ) );
$post_type_obj = [];
foreach ( $post_type as $key => $value ) {
$post_type_obj[ $value ] = get_post_type_object( $value );
}
wpuf_load_template(
'dashboard.php', [
'post_type' => $post_type,
'userdata' => wp_get_current_user(),
'dashboard_query' => $dashboard_query,
'post_type_obj' => $post_type_obj,
'post' => $post,
'pagenum' => $pagenum,
'category' => $category,
'featured_image' => $featured_image,
'form_id' => $form_id,
'meta' => $meta,
'excerpt' => $excerpt,
'payment_column' => $payment_column,
]
);
wp_reset_postdata();
$this->user_info();
}
/**
* Show user info on dashboard
*/
public function user_info() {
global $userdata;
if ( wpuf_get_option( 'show_user_bio', 'wpuf_dashboard', 'on' ) === 'on' ) {
?>
post_author == $userdata->ID ) || current_user_can( 'delete_others_pages' ) ) {
wp_trash_post( $pid );
//redirect
$redirect = add_query_arg( [ 'msg' => 'deleted' ], get_permalink() );
$redirect = apply_filters( 'wpuf_delete_post_redirect', $redirect );
wp_redirect( $redirect );
exit;
} else {
echo wp_kses_post( '' . __( 'You are not the post author. Cheating huh!', 'wp-user-frontend' ) . '
' );
}
}
}