2012-12-03 55 views
0

我想添加的能力,用戶將圖像附加到他們提交給wordpress帖子的形式。任何人做了這個或知道如何?添加圖像附件功能,用戶提交的WordPress的帖子

class submit_custom_forms{ 

public function __construct() { 

} 

public function processForms(){ 
    extract($_POST); 

    $postData = array(
    'post_title' => wp_strip_all_tags($full_name), 
    'post_status' => 'pending', 
    'post_type' => 'story', /*the custom post type*/ 
    'post_author' => 1, 
    'post_category' => array($catID)); 

     $pid = wp_insert_post($postData); 

    //Process Custom Fields 
     if(!empty($pid) && is_numeric($pid) && !empty($custom)){ 
      foreach($custom as $key => $value){ 
      if(!empty($value) && !is_array($value)){ 
      add_post_meta($pid, $key, $value); 
      } elseif(!empty($value) && is_array($value)){ 
       foreach($value as $k => $v){ 
        add_post_meta($pid, $key, $v, false); 
      } 
      } 

     } 
     } 

     $success = "Thank you for submitting."; 
     return (!empty($pid) && is_numeric($pid)) ? array('success' => "$success $imageUplodMsg $msgVid") : array('error' => 'An error occured. Please try again.'); 
} 

}

+0

我認爲你必須修改WP用戶角色的能力。用戶不允許默認上傳任何內容 –

回答