コード例 #1
0
/**
 * Validate the post submit data
 *
 * @author Tareq Hasan
 * @package WP User Frontend
 *
 * @global type $userdata
 * @param type $post_type
 */
function wpuf_validate_pending_submit()
{
    global $userdata;
    $errors = array();
    //if there is some attachement, validate them
    if (!empty($_FILES['wpuf_post_attachments'])) {
        $errors = wpuf_check_upload();
    }
    $title = trim($_POST['wpuf_post_title']);
    $content = trim($_POST['wpuf_post_content']);
    $tags = wpuf_clean_tags($_POST['wpuf_post_tags']);
    $cat = $_POST['category'];
    //validate title
    if (empty($title)) {
        $errors[] = __('Empty post title', 'wpuf');
    } else {
        $title = trim(strip_tags($title));
    }
    //validate cat
    if ($cat == '-1') {
        $errors[] = __('Please choose a category', 'wpuf');
    }
    //validate post content
    if (empty($content)) {
        $errors[] = __('Empty post content', 'wpuf');
    } else {
        $content = trim($content);
    }
    //process tags
    if (!empty($tags)) {
        $tags = explode(',', $tags);
    }
    //post type
    $post_type = trim(strip_tags($_POST['wpuf_post_type']));
    //process the custom fields
    $custom_fields = array();
    $fields = wpuf_get_custom_fields();
    if (is_array($fields)) {
        foreach ($fields as $cf) {
            if (array_key_exists($cf['field'], $_POST)) {
                $temp = trim(strip_tags($_POST[$cf['field']]));
                //var_dump($temp, $cf);
                if ($cf['type'] == 'yes' && !$temp) {
                    $errors[] = sprintf(__('%s is missing', 'wpuf'), $cf['label']);
                } else {
                    $custom_fields[$cf['field']] = $temp;
                }
            }
            //array_key_exists
        }
        //foreach
    }
    //is_array
    $errors = apply_filters('wpuf_add_post_validation', $errors);
    //if not any errors, proceed
    if (!$errors) {
        $post_stat = get_option('wpuf_post_status') ? get_option('wpuf_post_status') : 'publish';
        $post_author = get_option('wpuf_post_author') == 'original' ? $userdata->ID : get_option('wpuf_map_author');
        //users are allowed to choose category
        if (get_option('wpuf_allow_choose_cat') == 'yes') {
            $post_category = $cat;
        } else {
            $post_category = array(get_option('wpuf_default_cat'));
        }
        $my_post = array('post_title' => $title, 'post_content' => $content, 'post_status' => 'pending', 'post_author' => $post_author, 'post_category' => $post_category, 'post_type' => $post_type, 'tags_input' => $tags);
        //plugin API to extend the functionality
        $my_post = apply_filters('wpuf_add_post_args', $my_post);
        //insert the post
        $post_id = wp_insert_post($my_post);
        if ($post_id) {
            //upload attachment to the post
            wpuf_upload_attachment($post_id);
            //send mail notification
            if (get_option('wpuf_notify') == 'yes') {
                wpuf_notify_post_mail($userdata, $post_id);
            }
            //add the custom fields
            if ($custom_fields) {
                foreach ($custom_fields as $key => $val) {
                    add_post_meta($post_id, $key, $val, true);
                }
            }
            //plugin API to extend the functionality
            do_action('wpuf_add_post_after_insert', $post_id);
            //echo '<div class="success">' . __('Post published successfully', 'wpuf') . '</div>';
            if ($post_id) {
                $redirect = get_permalink($post_id);
                $redirect = apply_filters('wpuf_after_post_redirect', $redirect, $post_id);
                wp_redirect($redirect);
            }
        }
    } else {
        //echo wpuf_error_msg( $errors );
    }
}
コード例 #2
0
function wpuf_validate_post_edit_submit()
{
    global $userdata;
    $errors = array();
    $title = trim($_POST['wpuf_post_title']);
    $content = trim($_POST['wpuf_post_content']);
    $tags = '';
    $cat = '';
    if (isset($_POST['wpuf_post_tags'])) {
        $tags = wpuf_clean_tags($_POST['wpuf_post_tags']);
    }
    if (isset($_POST['cat'])) {
        $cat = trim($_POST['cat']);
    }
    //if there is some attachement, validate them
    if (!empty($_FILES['wpuf_post_attachments'])) {
        $errors = wpuf_check_upload();
    }
    if (empty($title)) {
        $errors[] = __('Empty post title', 'wpuf');
    } else {
        $title = trim(strip_tags($title));
    }
    if (empty($content)) {
        $errors[] = __('Empty post content', 'wpuf');
    } else {
        $content = trim($content);
    }
    if (!empty($tags)) {
        $tags = explode(',', $tags);
    }
    //process the custom fields
    $custom_fields = array();
    $fields = wpuf_get_custom_fields();
    if (is_array($fields)) {
        foreach ($fields as $cf) {
            if (array_key_exists($cf['field'], $_POST)) {
                $temp = trim(strip_tags($_POST[$cf['field']]));
                //var_dump($temp, $cf);
                if ($cf['type'] == 'yes' && !$temp) {
                    $errors[] = sprintf(__('%s is missing', 'wpuf'), $cf['label']);
                } else {
                    $custom_fields[$cf['field']] = $temp;
                }
            }
            //array_key_exists
        }
        //foreach
    }
    //is_array
    $errors = apply_filters('wpuf_edit_post_validation', $errors);
    if (!$errors) {
        $post_update = array('ID' => trim($_POST['post_id']), 'post_title' => $title, 'post_content' => $content, 'post_category' => array($cat), 'tags_input' => $tags);
        //plugin API to extend the functionality
        $post_update = apply_filters('wpuf_edit_post_args', $post_update);
        $post_id = wp_update_post($post_update);
        if ($post_id) {
            echo '<div class="success">' . __(' Modification avec success', 'wpuf') . '</div>';
            //upload attachment to the post
            wpuf_upload_attachment($post_id);
            //add the custom fields
            if ($custom_fields) {
                foreach ($custom_fields as $key => $val) {
                    update_post_meta($post_id, $key, $val, false);
                }
            }
            do_action('wpuf_edit_post_after_update', $post_id);
        }
    } else {
        echo wpuf_error_msg($errors);
    }
}
コード例 #3
0
ファイル: wpuf-edit-post.php プロジェクト: alphaomegahost/FIN
 function submit_post()
 {
     global $userdata;
     $errors = array();
     $title = trim($_POST['wpuf_post_title']);
     $content = trim($_POST['wpuf_post_content']);
     $tags = '';
     $cat = '';
     if (isset($_POST['wpuf_post_tags'])) {
         $tags = wpuf_clean_tags($_POST['wpuf_post_tags']);
     }
     //if there is some attachement, validate them
     if (!empty($_FILES['wpuf_post_attachments'])) {
         $errors = wpuf_check_upload();
     }
     if (empty($title)) {
         $errors[] = __('Empty post title', 'wpuf');
     } else {
         $title = trim(strip_tags($title));
     }
     //validate cat
     $cat_type = wpuf_get_option('cat_type');
     if (!isset($_POST['category'])) {
         $errors[] = __('Please choose a category', 'wpuf');
     } else {
         if ($cat_type == 'normal' && $_POST['category'][0] == '-1') {
             $errors[] = __('Please choose a category', 'wpuf');
         } else {
             if (count($_POST['category']) < 1) {
                 $errors[] = __('Please choose a category', 'wpuf');
             }
         }
     }
     if (empty($content)) {
         $errors[] = __('Empty post content', 'wpuf');
     } else {
         $content = trim($content);
     }
     if (!empty($tags)) {
         $tags = explode(',', $tags);
     }
     //process the custom fields
     $custom_fields = array();
     $fields = wpuf_get_custom_fields();
     if (is_array($fields)) {
         foreach ($fields as $cf) {
             if (array_key_exists($cf['field'], $_POST)) {
                 $temp = trim(strip_tags($_POST[$cf['field']]));
                 //var_dump($temp, $cf);
                 if ($cf['type'] == 'yes' && !$temp) {
                     $errors[] = sprintf(__('%s is missing', 'wpuf'), $cf['label']);
                 } else {
                     $custom_fields[$cf['field']] = $temp;
                 }
             }
             //array_key_exists
         }
         //foreach
     }
     //is_array
     //post attachment
     $attach_id = isset($_POST['wpuf_featured_img']) ? intval($_POST['wpuf_featured_img']) : 0;
     $errors = apply_filters('wpuf_edit_post_validation', $errors);
     if (!$errors) {
         //users are allowed to choose category
         if (wpuf_get_option('allow_cats') == 'on') {
             $post_category = $_POST['category'];
         } else {
             $post_category = array(get_option('wpuf_default_cat'));
         }
         $post_update = array('ID' => trim($_POST['post_id']), 'post_title' => $title, 'post_content' => $content, 'post_category' => $post_category, 'tags_input' => $tags);
         //plugin API to extend the functionality
         $post_update = apply_filters('wpuf_edit_post_args', $post_update);
         $post_id = wp_update_post($post_update);
         if ($post_id) {
             echo '<div class="success">' . __('Post updated succesfully.', 'wpuf') . '</div>';
             //upload attachment to the post
             wpuf_upload_attachment($post_id);
             //set post thumbnail if has any
             if ($attach_id) {
                 set_post_thumbnail($post_id, $attach_id);
             }
             //add the custom fields
             if ($custom_fields) {
                 foreach ($custom_fields as $key => $val) {
                     update_post_meta($post_id, $key, $val, false);
                 }
             }
             do_action('wpuf_edit_post_after_update', $post_id);
         }
     } else {
         echo wpuf_error_msg($errors);
     }
 }
コード例 #4
0
 /**
  * Validate the post submit data
  *
  * @global type $userdata
  * @param type $post_type
  */
 function submit_post()
 {
     global $userdata;
     $errors = array();
     var_dump($_POST);
     //if there is some attachement, validate them
     if (!empty($_FILES['wpuf_post_attachments'])) {
         $errors = wpuf_check_upload();
     }
     $title = trim($_POST['wpuf_post_title']);
     $content = trim($_POST['wpuf_post_content']);
     $tags = '';
     if (isset($_POST['wpuf_post_tags'])) {
         $tags = wpuf_clean_tags($_POST['wpuf_post_tags']);
     }
     //validate title
     if (empty($title)) {
         $errors[] = __('Empty post title', 'wpuf');
     } else {
         $title = trim(strip_tags($title));
     }
     //validate cat
     if (wpuf_get_option('allow_cats', 'wpuf_frontend_posting', 'on') == 'on') {
         $cat_type = wpuf_get_option('cat_type', 'wpuf_frontend_posting', 'normal');
         if (!isset($_POST['category'])) {
             $errors[] = __('Please choose a category', 'wpuf');
         } else {
             if ($cat_type == 'normal' && $_POST['category'][0] == '-1') {
                 $errors[] = __('Please choose a category', 'wpuf');
             } else {
                 if (count($_POST['category']) < 1) {
                     $errors[] = __('Please choose a category', 'wpuf');
                 }
             }
         }
     }
     //validate post content
     if (empty($content)) {
         $errors[] = __('Empty post content', 'wpuf');
     } else {
         $content = trim($content);
     }
     //process tags
     if (!empty($tags)) {
         $tags = explode(',', $tags);
     }
     //post attachment
     $attach_id = isset($_POST['wpuf_featured_img']) ? intval($_POST['wpuf_featured_img']) : 0;
     //post type
     $post_type = trim(strip_tags($_POST['wpuf_post_type']));
     //process the custom fields
     $custom_fields = array();
     $fields = wpuf_get_custom_fields();
     if (is_array($fields)) {
         foreach ($fields as $cf) {
             if (array_key_exists($cf['field'], $_POST)) {
                 if (is_array($_POST[$cf['field']])) {
                     $temp = implode(',', $_POST[$cf['field']]);
                 } else {
                     $temp = trim(strip_tags($_POST[$cf['field']]));
                 }
                 //var_dump($temp, $cf);
                 if ($cf['type'] == 'yes' && !$temp) {
                     $errors[] = sprintf(__('"%s" is missing', 'wpuf'), $cf['label']);
                 } else {
                     $custom_fields[$cf['field']] = $temp;
                 }
             }
             //array_key_exists
         }
         //foreach
     }
     //is_array
     $post_date_enable = wpuf_get_option('enable_post_date', 'wpuf_frontend_posting');
     $post_expiry = wpuf_get_option('enable_post_expiry', 'wpuf_frontend_posting');
     //check post date
     if ($post_date_enable == 'on') {
         $month = $_POST['mm'];
         $day = $_POST['jj'];
         $year = $_POST['aa'];
         $hour = $_POST['hh'];
         $min = $_POST['mn'];
         if (!checkdate($month, $day, $year)) {
             $errors[] = __('Invalid date', 'wpuf');
         }
     }
     $errors = apply_filters('wpuf_add_post_validation', $errors);
     //if not any errors, proceed
     if ($errors) {
         echo wpuf_error_msg($errors);
         return;
     }
     $post_stat = wpuf_get_option('post_status', 'wpuf_frontend_posting');
     $post_author = wpuf_get_option('post_author', 'wpuf_frontend_posting') == 'original' ? $userdata->ID : wpuf_get_option('map_author', 'wpuf_frontend_posting');
     //users are allowed to choose category
     if (wpuf_get_option('allow_cats', 'wpuf_frontend_posting', 'on') == 'on') {
         $post_category = $_POST['category'];
     } else {
         $post_category = array(wpuf_get_option('default_cat', 'wpuf_frontend_posting'));
     }
     $my_post = array('post_title' => $title, 'post_content' => $content, 'post_status' => $post_stat, 'post_author' => $post_author, 'post_category' => $post_category, 'post_type' => $post_type, 'tags_input' => $tags);
     if ($post_date_enable == 'on') {
         $month = $_POST['mm'];
         $day = $_POST['jj'];
         $year = $_POST['aa'];
         $hour = $_POST['hh'];
         $min = $_POST['mn'];
         $post_date = mktime($hour, $min, 59, $month, $day, $year);
         $my_post['post_date'] = date('Y-m-d H:i:s', $post_date);
     }
     //plugin API to extend the functionality
     $my_post = apply_filters('wpuf_add_post_args', $my_post);
     //var_dump( $_POST, $my_post );die();
     //insert the post
     $post_id = wp_insert_post($my_post);
     if ($post_id) {
         //upload attachment to the post
         wpuf_upload_attachment($post_id);
         //send mail notification
         if (wpuf_get_option('post_notification', 'wpuf_others', 'yes') == 'yes') {
             wpuf_notify_post_mail($userdata, $post_id);
         }
         //add the custom fields
         if ($custom_fields) {
             foreach ($custom_fields as $key => $val) {
                 add_post_meta($post_id, $key, $val, true);
             }
         }
         //set post thumbnail if has any
         if ($attach_id) {
             set_post_thumbnail($post_id, $attach_id);
         }
         //Set Post expiration date if has any
         if (!empty($_POST['expiration-date']) && $post_expiry == 'on') {
             $post = get_post($post_id);
             $post_date = strtotime($post->post_date);
             $expiration = (int) $_POST['expiration-date'];
             $expiration = $post_date + $expiration * 60 * 60 * 24;
             add_post_meta($post_id, 'expiration-date', $expiration, true);
         }
         //plugin API to extend the functionality
         do_action('wpuf_add_post_after_insert', $post_id);
         //echo '<div class="success">' . __('Post published successfully', 'wpuf') . '</div>';
         if ($post_id) {
             $redirect = apply_filters('wpuf_after_post_redirect', get_permalink($post_id), $post_id);
             wp_redirect($redirect);
             exit;
         }
     }
 }