0

I want to import a external image with media_sideload_image, but I get the HTTP-Code 500.

What is wrong with my code?

function test() {
    media_sideload_image("https://s.w.org/style/images/wp-header-logo.png?1", 1261, null, "id");
}
add_action("init", "test");

I want to import a external Image and generate the image sizes

0

The media_sideload_image() function is only available in the admin by default, and init runs on all page loads.

See the Codex article:

If you want to use this function outside of the context of /wp-admin/ (typically if you are writing a more advanced custom importer script) you need to include media.php and depending includes:

require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');

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.