0

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.com/CU7AeGWD Heres the button: https://pastebin.com/bLG50tJp

Tips would be really appreciated.

  • Welcome to this site and plugin development in general! "stopped working" isn't really telling much, have you tried debugging this further? – kero Dec 12 '18 at 11:00
  • thank you, yes ive done something and now the only error im getting has to do with this: function _custom_menu_page(), so i think i didnt link it correctly , i might be wrong though – Nls Dec 12 '18 at 11:03
0

Please check the following

  • You have checked the URL of your Wordpress installation
  • You have checked that your webhosting is compatible with uploading (file permissions, user rights)
  • You re-saved the permalinks (to make sure that URLs are used correctly)

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.

  • I got this after setting it to true: pastebin.com/wNgfwrx9 – Nls Dec 12 '18 at 9:09
  • Is this a plugin that you're using to upload with? If not, try disabling to check if it might change the functionality of your own plugin. – Jim Dec 12 '18 at 9:21
0

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, so if none of my debug log is related to my code, could it be the host blocking the file uploader? – Nls Dec 12 '18 at 9:41
  • I think not. You can try upload a simple image in media and see if it works or not. Did you tried changing action from empty value to #? – Hector Dec 12 '18 at 10:09
  • I uploaded an image to media , so that worked and yes i changed the action to '#' – Nls Dec 12 '18 at 10:25
-1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.