/** * 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 ); } }
function wpuf_add_user() { global $wp_error; //get admin template file. wp_dropdown_role is there :( require_once ABSPATH . '/wp-admin/includes/template.php'; ?> <?php if (current_user_can('create_users')) { ?> <h3><?php _e('Creer un compte', 'wpuf'); ?> </h3> <?php if (isset($_POST['wpuf_new_user_submit'])) { $errors = array(); $username = sanitize_user($_POST['user_login']); $email = trim($_POST['user_email']); $last_name = trim($_POST['last_name']); $first_name = trim($_POST['first_name']); $role = $_POST['role']; $error = null; $error = wpuf_register_new_user($username, $email, $role, $first_name, $last_name); if (!is_wp_error($error)) { echo '<div class="success">' . __(utf8_encode('Compte crée. Un mail a été envoyé à l\\email indiqué'), 'wpuf') . '</div>'; } else { echo '<div class="error">' . $error->get_error_message() . '</div>'; } } ?> <form action="" method="post"> <ul class="wpuf-post-form"> <li> <label for="user_login"> <?php _e('Username', 'wpuf'); ?> <span class="required">*</span> </label> <input type="text" name="user_login" id="user_login" minlength="2" value="<?php if (isset($_POST['user_login'])) { echo wpuf_clean_tags($_POST['user_login']); } ?> "> <div class="clear"></div> </li> <li> <label for="user_email"> <?php _e('Email', 'wpuf'); ?> <span class="required">*</span> </label> <input type="text" name="user_email" id="user_email" minlength="2" value="<?php if (isset($_POST['user_email'])) { echo wpuf_clean_tags($_POST['user_email']); } ?> "> <div class="clear"></div> </li> <li> <label for="first_name"> <?php _e('Prenom', 'wpuf'); ?> <span class="required">*</span> </label> <input type="text" name="first_name" id="first_name" minlength="2" value="<?php if (isset($_POST['first_name'])) { echo wpuf_clean_tags($_POST['user_email']); } ?> "> <div class="clear"></div> </li> <li> <label for="last_name"> <?php _e('Nom', 'wpuf'); ?> <span class="required">*</span> </label> <input type="text" name="last_name" id="last_name" minlength="2" value="<?php if (isset($_POST['last_name'])) { echo wpuf_clean_tags($_POST['user_email']); } ?> "> <div class="clear"></div> </li> <li> <label for="role"> <?php _e('Role', 'wpuf'); ?> </label> <select name="role" id="role"> <?php if (!$new_user_role) { $new_user_role = !empty($current_role) ? $current_role : get_option('default_role'); } wp_dropdown_roles($new_user_role); ?> </select> <div class="clear"></div> </li> <li> <label> </label> <input class="wpuf_submit" type="submit" name="wpuf_new_user_submit" value="<?php echo esc_attr(__('Creer un compte', 'wpuf')); ?> "> </li> </ul> </form> <?php } ?> <?php }
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); } }
/** * Handles admin options settings submission with ajax * */ function wpuf_admin_ajax() { foreach ($_POST as $key => $val) { $_POST[$key] = esc_attr($val); } foreach ($_POST as $key => $value) { //update the input fields, whose names starts with symple_ if (wpuf_starts_with($key, 'wpuf_')) { //echo "$key => $value <br>"; update_option($key, wpuf_clean_tags($value)); //echo "$key => $value \n"; } //starts with } //foreach echo __('Settings Saved', 'wpuf'); //print_r($_POST); exit; }
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); } }
/** * Insert payment info to database * * @global object $wpdb * @param array $data payment data to insert * @param int $transaction_id the transaction id in case of update */ public static function insert_payment($data, $transaction_id = 0) { global $wpdb; //check if it's already there $sql = "SELECT transaction_id\n FROM " . $wpdb->prefix . "wpuf_transaction\n WHERE transaction_id = '" . $wpdb->escape(wpuf_clean_tags($transaction_id)) . "' LIMIT 1"; $result = $wpdb->get_row($sql); if (!$result) { $wpdb->insert($wpdb->prefix . 'wpuf_transaction', $data); do_action('wpuf_payment_received', $data); } else { $wpdb->update($wpdb->prefix . 'wpuf_transaction', $data, array('transaction_id' => $transaction_id)); WPUF_Main::log('info', 'updating existing transaction: ' . $transaction_id); } }
/** * Insert the payment details in databse * * @global type $wpdb * @global type $userdata * @param type $post_id * @param type $pack_id */ function insert_payment($post_id = 0, $pack_id = 0) { global $wpdb, $userdata; // check and make sure this transaction hasn't already been added $sql = "SELECT transaction_id\n FROM " . $wpdb->prefix . "wpuf_transaction\n WHERE txn_id = '" . $wpdb->escape(wpuf_clean_tags($_POST['txn_id'])) . "' LIMIT 1"; $results = $wpdb->get_row($sql); if (!$results) { $data = array('user_id' => $userdata->ID, 'status' => 'completed', 'cost' => $_POST['mc_gross'], 'post_id' => $post_id, 'pack_id' => $pack_id, 'payer_first_name' => $_POST['first_name'], 'payer_last_name' => $_POST['last_name'], 'payer_email' => $_POST['payer_email'], 'payment_type' => 'Paypal', 'payer_address' => $_POST['address_country_code'], 'transaction_id' => $_POST['txn_id'], 'created' => current_time('mysql')); $wpdb->insert($wpdb->prefix . 'wpuf_transaction', $data); do_action('wpuf_payment_received', $data); } wp_redirect(home_url(), 301); exit; }
/** * 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; } } }