wp-cli / server-command

Launches PHP's built-in web server for a specific WordPress installation.
MIT License
67 stars 19 forks source link

Server on `http://` returns `https://` links #51

Open alexander-akait opened 5 years ago

alexander-akait commented 5 years ago

If you have site on https and run php server on http the function get_site_icon_url return a link with https.

I think the problem here https://github.com/WordPress/WordPress/blob/master/wp-includes/general-template.php#L810, because WordPress should use here get_site_url() instead get_option( 'site_icon' ).

Maybe we can add filter on get_site_icon_url to fix it problem or we should fix it in WordPress?

alexander-akait commented 5 years ago

Same problem for wp_upload_dir so all images have https, maybe we can add more filters here https://github.com/wp-cli/server-command/blob/master/router.php?

swissspidy commented 5 years ago

Worth noting that get_option( 'site_icon' ) just holds the ID of the site icon, not its URL. The actual URL is generated by wp_get_attachment_image_url() and then wp_get_attachment_url(), which uses the image URL stored in the attachment metadata in the database.

So the right filter in that case would probably be wp_get_attachment_url.

alexander-akait commented 5 years ago

@swissspidy yep, i find what wp_get_attachment_url use wp_upload_dir for getting host, so i think filter should in wp_upload_dir, it is fix all images urls

schlessera commented 5 years ago

I'm not sure this can be easily solved. You still have all the links that are stored throughout post content fields that point to https://.

Maybe a better approach would be to add a flag --adapt-scheme that filters the actual output to replace all https:// links pointing to the local server with http:// links?

alexander-akait commented 5 years ago

@schlessera we rewrite url in production, but for development mode will be great have valid url