agent

Please log in to use this feature.

‘; get_footer(); exit; } get_header(); // Handle form submission $message = ”; if (isset($_POST[‘submit_agent_form’]) && check_admin_referer(‘agent_upload_nonce’, ‘agent_nonce’)) { // 1. Create new post $post_title = sanitize_text_field($_POST[‘title’] ?? ‘User Upload – ‘ . date(‘Y-m-d H:i’)); $post_content = wp_kses_post($_POST[‘description’] ?? ”); $new_post = array( ‘post_title’ => $post_title, ‘post_content’ => $post_content, ‘post_status’ => ‘draft’, // change to ‘publish’ if you want it live immediately ‘post_type’ => ‘post’, ‘post_author’ => get_current_user_id(), ); $post_id = wp_insert_post($new_post); if (is_wp_error($post_id)) { $message = ‘

Error creating post: ‘ . esc_html($post_id->get_error_message()) . ‘

‘; } else { // 2. Handle image upload if (!empty($_FILES[‘user_image’][‘name’]) && $_FILES[‘user_image’][‘error’] === 0) { require_once(ABSPATH . ‘wp-admin/includes/image.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/media.php’); $file = $_FILES[‘user_image’]; // Basic validation – only images $allowed = array(‘jpg|jpeg|jpe’ => ‘image/jpeg’, ‘png’ => ‘image/png’, ‘gif’ => ‘image/gif’); $file_type = wp_check_filetype(basename($file[‘name’]), $allowed); if (!empty($file_type[‘ext’])) { $upload_overrides = array(‘test_form’ => false); $movefile = wp_handle_upload($file, $upload_overrides); if ($movefile && !isset($movefile[‘error’])) { // Insert attachment $attachment = array( ‘post_mime_type’ => $file_type[‘type’], ‘post_title’ => sanitize_file_name(basename($file[‘name’])), ‘post_content’ => ”, ‘post_status’ => ‘inherit’, ‘post_author’ => get_current_user_id(), ); $attach_id = wp_insert_attachment($attachment, $movefile[‘file’], $post_id); if (!is_wp_error($attach_id)) { $attach_data = wp_generate_attachment_metadata($attach_id, $movefile[‘file’]); wp_update_attachment_metadata($attach_id, $attach_data); // Set as featured image set_post_thumbnail($post_id, $attach_id); $message = ‘

Success! New post created (ID: ‘ . $post_id . ‘).
View your post (currently in draft)

‘; } else { $message = ‘

Could not create attachment.

‘; } } else { $message = ‘

Upload error: ‘ . esc_html($movefile[‘error’]) . ‘

‘; } } else { $message = ‘

Please upload a valid image (jpg, png, gif only).

‘; } } else { $message = ‘

Please upload an image.

‘; } } } ?>

Upload Your Picture & Text → Create Post




Note: New posts are created as draft. You (or admin) can publish them later from wp-admin.