2016-04-28 111 views

回答

0

您可以使用下面的鉤子來修改任何職位類型這樣

function change_post_status($post_id) { 
    if (is_user_logged_in()) { 

     remove_action('save_post', array($this, 'change_post_status'), 99, 2); 

     if (in_array($_POST['post_type'], array('project', 'event'))) { 

      $user   = wp_get_current_user(); 
      $allowed_roles = array('editor', 'administrator', 'author'); 
      if (array_intersect($allowed_roles, $user->roles)) { 
       wp_update_post(array(
        'ID'   => $post_id, 
        'post_status' => 'publish' 
       )); 
      } 
     } 

     add_action('save_post', array($this, 'change_post_status'), 99, 2); 
    } 
} 
相關問題