wp plugin not working after website live

admin2025-06-05  2

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.

Share Improve this question asked Dec 12, 2018 at 8:09 NlsNls 12 bronze badges 2
  • Welcome to this site and plugin development in general! "stopped working" isn't really telling much, have you tried debugging this further? – kero Commented Dec 12, 2018 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 Commented Dec 12, 2018 at 11:03
Add a comment  | 

3 Answers 3

Reset to default 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.

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!

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749105642a316408.html

最新回复(0)