I am working on a plugin .I want to upload image from front end i.e by input type="file"
.I did lot of google for it but could not upload image .Here is my code for uploading image
<form method="post" action="options.php">
<input type="file" name="my_image_upload" id="my_image_upload" multiple="false" />
<input type="hidden" name="post_id" id="post_id" value="55" />
<?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>
<input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Upload" />
</form>
<?php
if (
isset( $_POST['my_image_upload_nonce'], $_POST['post_id'] )
&& wp_verify_nonce( $_POST['my_image_upload_nonce'], 'my_image_upload' )
&& current_user_can( 'edit_post', $_POST['post_id'] )
) {
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$attachment_id = media_handle_upload( 'my_image_upload', $_POST['post_id'] );
if ( is_wp_error( $attachment_id ) ) {
// There was an error uploading the image.
} else {
// The image was uploaded successfully!
}
} else {
// The security check failed, maybe show the user an error.
}
function wp_verify_nonce_X($nonce, $action = -1) {
return true;
$user = wp_get_current_user();
$uid = (int) $user->id;
$i = wp_nonce_tick();
if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce )
return 1;
if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) == $nonce )
return 2;
// Invalid nonce
return false;
}
After implementing this code I get thiserror
Fatal error: Call to undefined function wp_verify_nonce() in /home/projectdemos/public_html/WP-Team-Showcase/wp-content/plugins/wp-team-showcase/team.php on line 435
I google this error and run all possible solution found across it but could not solved it .
Tell me how to upload image and save it ,if there is any other solution beside my this code.