johnpbloch / wordpress

A fork of WordPress with Composer support added. Branches, tags, and trunk synced from upstream every 15 minutes.
https://packagist.org/packages/johnpbloch/wordpress
602 stars 102 forks source link

Installing wp-core to project root as dependency #53

Open acalvino4 opened 2 years ago

acalvino4 commented 2 years ago

First of all, thanks so much for maintaining this project! it's always refreshing to see that there are in fact php developers who take time to make development best practices work in their projects, even if the framework out of the box doesn't support it.

Anyway, I know you say somewhere that if you want to install wp-core to root, this project is not for you. However, to me maintaining that third-party code (which wp is) is a dependency is a must for me, and unfortunately having wp-core installed to root is also a must because of the my client's hosting provider. I just thought I would publish my workaround here in case anyone else finds themself in a similar place, as well as for consideration for this method to be implemented into the core installer.

Basically, all I did was add the following to my composer.json:

{
...
  "extra": {
    "wordpress-install-dir": "wp"
  },
  "scripts": {
    "post-install-cmd": ["@moveWPtoRoot"],
    "post-update-cmd": ["@moveWPtoRoot"],
    "moveWPtoRoot": [
      "rsync -a wp/ .; rm -rf wp"
    ]
  }
...
}

Effectively all it does is install the core to a subfolder, then rsync it to root and delete the subfolder. This solves the issue where specifying "." as your "wordpress-install-dir" erases all your files.

johnpbloch commented 2 years ago

Thanks for putting this together! I think this is not something I'll be adding to the installer, just to keep the scope of the installer within where I want to maintain it. That being said, a separate installer and package that used it and required johnpbloch/wordpress-core directly which has this behavior would certainly be worth advertising here too.

Potential features aside, I'm going to lock and pin this issue so that future readers can get a good sense of how to do this with the least friction possible.