Guest User

Untitled

a guest
Oct 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. function image_up_gall(){
  2. ?>
  3. <form id="featured_upload" method="post" action="#" enctype="multipart/form-data">
  4. <input type="file" name="my_image_upload" id="my_image_upload" multiple="false" />
  5. <input type="hidden" name="post_id" id="post_id" value="1" />
  6. <?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>
  7. <input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Upload" />
  8. </form>
  9. <?php
  10. // Check that the nonce is valid, and the user can edit this post.
  11. if (
  12. isset( $_POST['my_image_upload_nonce'], $_POST['post_id'] )
  13. && wp_verify_nonce( $_POST['my_image_upload_nonce'], 'my_image_upload' )
  14. && current_user_can( 'edit_post', $_POST['post_id'] )
  15. ) {
  16. // The nonce was valid and the user has the capabilities, it is safe to continue.
  17.  
  18. // These files need to be included as dependencies when on the front end.
  19. require_once( ABSPATH . 'wp-admin/includes/image.php' );
  20. require_once( ABSPATH . 'wp-admin/includes/file.php' );
  21. require_once( ABSPATH . 'wp-admin/includes/media.php' );
  22.  
  23. // Let WordPress handle the upload.
  24. // Remember, 'my_image_upload' is the name of our file input in our form above.
  25. $attachment_id = media_handle_upload( 'my_image_upload', $_POST['post_id'] );
  26.  
  27. if ( is_wp_error( $attachment_id ) ) {
  28. // There was an error uploading the image.
  29. echo "error Uploading";
  30. } else {
  31. // The image was uploaded successfully!
  32. echo "Successfully Uploaded";
  33. }
  34.  
  35. } else {
  36.  
  37. // The security check failed, maybe show the user an error.
  38. echo "security check error";
  39. }
  40. }
  41. add_action('edit_user_profile', 'image_up_gall');
  42. add_action('show_user_profile', 'image_up_gall');
Add Comment
Please, Sign In to add comment