Im trying to understand Wordpress plugins, i made a nice little plugin that lets you upload an image to media.
However, this only works on localhost, after i moved the files to my host it stopped working.
The button of my plugin still works, when i click it it redirects me to an empty page.
How should i resolve this issue?
Heres my index: Heres the button:
Tips would be really appreciated.
Im trying to understand Wordpress plugins, i made a nice little plugin that lets you upload an image to media.
However, this only works on localhost, after i moved the files to my host it stopped working.
The button of my plugin still works, when i click it it redirects me to an empty page.
How should i resolve this issue?
Heres my index: https://pastebin/CU7AeGWD Heres the button: https://pastebin/bLG50tJp
Tips would be really appreciated.
Please check the following
Edit: This little amount of information gives us little space to work with. Also, please check that you have WP Debug set to true as it might provide you with information that you would normally not get.
First of all, you don't need to include WordPress files from wp-admin
folder because you are using media_handle_upload
in admin side. They are necessary only when you want to upload from front-end.
So you can remove these lines of codes:
$path = get_home_path();
require_once( $path . 'wp-admin/includes/image.php' );
require_once( $path . 'wp-admin/includes/file.php' );
require_once( $path . 'wp-admin/includes/media.php' );
Then, please try to fill the action
attribute of your form
using #
because the empty value is not valid and it could make issues while submitting form.
Also non of your debug log is related to your codes.
Check media_handle_upload
documentation for sample codes.
Edit: In order to debug your code and see what is result of upload, you can use error_log
function after activating WP_DEBUG_LOG
.
$attachment_id = media_handle_upload( 'fileToUpload', 0);
// Log results.
ob_start();
var_dump( $attachment_id );
error_log( ob_get_clean() );
Then you can check wp-content/debug.log
file to see what is happening.
Thanks everyone for helping me and making my code better! This is the solution: function _custom_menu_page(){ include_once DIR . '/index.php'; } It finally works!