我有以下一段代码,只要用户购买了订阅包,就会发布其帖子,并在其包过期后将帖子的状态更改为草稿。我只是想知道如何编辑它,以便用户可以创建一篇帖子,并且帖子会自动设置为草稿,然后在用户完成包付款后,帖子的状态会更新为发布?任何帮助都将不胜感激。
if ( ! in_array( $new_status, array( \'active\', \'trial\' ) ) ) {
$user_limits = stm_get_post_limits( $user_id );
$posts_args = array(
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'post_type\' => \'listings\',
\'post_status\' => \'publish\',
\'posts_per_page\' => - 1,
\'meta_query\' => array(
array(
\'key\' => \'stm_car_user\',
\'value\' => $user_id,
\'compare\' => \'\'
)
),
\'fields\' => \'ids\'
);
$user_posts = get_posts( $posts_args );
if ( count( $user_posts ) > $user_limits[\'posts_allowed\'] ) {
array_splice( $user_posts, 0, $user_limits[\'posts_allowed\'] );
foreach ( $user_posts as $user_post ) {
$draft_post = array(
\'ID\' => $user_post,
\'post_status\' => \'draft\'
);
wp_update_post( $draft_post );
}
}
/*Change user back to private if not admin*/
if(!user_can($user_id, \'manage_options\')) {
wp_update_user( array(
\'ID\' => $user_id,
\'role\' => \'privateseller\'
) );
}
} else {
/*If plan includes dealeship, change user role to dealer*/
if ( $role == \'dealer\' ) {
wp_update_user( array(
\'ID\' => $user_id,
\'role\' => \'stm_dealer\'
) );
}
}