ddev / ddev-browsersync

Auto-refresh HTTPS page on changes with DDEV
Apache License 2.0
27 stars 8 forks source link

Improving WordPress support? #51

Open graham73may opened 7 months ago

graham73may commented 7 months ago

Thanks for the add on, I've been replacing Livereload with this and it's been great.

I work on Drupal and WordPress websites, the Drupal projects are quite URL agnostic but the WordPress websites are constantly trying to redirect me to a URL without the :3000 port number.

I'm not sure what functionality is available to add ons, would modifying the wp-config-ddev.php file be an option?

My current work around is to add the below code snippet to the auto generated wp-config-ddev.php file.

 /** WP_HOME URL */
  //  defined('WP_HOME') || define('WP_HOME', 'https://wbg.org.uk.ddev.site');

  /** WP_SITEURL location */
  //  defined('WP_SITEURL') || define('WP_SITEURL', WP_HOME . '/');

  /** Allow any domain/port. (For browsersync) */
  $domain = sprintf('%s://%s', $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https', $_SERVER['SERVER_NAME']);

  define('WP_SITEURL', $domain);
  define('WP_HOME', $domain);

Maybe it would be better to only allow the project URL(s) in their original form and with :3000 so it's not too loose?

Thanks,

tyler36 commented 7 months ago

Hi @graham73may

Thanks for the report. I don't use WP so I'm not sure the best solution. It would be nice if we did have something though.

graham73may commented 7 months ago

Is it possible for an addon to modify the ddev-generated wp-config-ddev.php file?

Failing that, is it possible for the addon to detect the DDEV project type === "wordpress" and then echo some tips into the console?

rfay commented 7 months ago

It is in fact possible, see how ddev/ddev-redis does it for Drupal config. And absolutely possible to output help when detecting project type as well.

graham73may commented 7 months ago

Ah nice! Thanks for the clues @rfay. Will see if I can put a PR together.

https://github.com/ddev/ddev-redis/blob/main/redis/scripts/setup-drupal-settings.sh

tyler36 commented 1 month ago

@graham73may Any progress on the PR? Did you hit a problem? There's usually some friendly folks over on Discord if you need help. 😄

graham73may commented 1 month ago

Hey @tyler36, sorry project work has been taking priority. With the code snippet above working it's been making me lazy. Right now is actually not a bad time, taking a look at what ddev-redis is doing. Will report back shortly.