Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavior with composer install and composer update regarding wordpress themes and plugins #49

Open
trolologuy opened this issue Aug 6, 2020 · 3 comments

Comments

@trolologuy
Copy link

Hello,

I'm encountering different behaviors with composer install and composer update regarding wordpress themes and plugins.
I want to import custom themes and plugins into wordpress, so I added them through the composer path directive.

I'm not fully sure if this is a composer issue, an issue with your great project, or just me not doing things properly.

Here's the folder structure:

.
└── custom
    ├── plugins
    │   └── my_custom_plugin
    └── themes
        └── my_custom_theme

Both my custom theme and plugin use a composer.json that has the following structure:

{
    "name": "me/my_custom_plugin",
    "description": "Custom Plugin",
    "version": "1.0",
    "type": "wordpress-plugin",
    "require": {
        "composer/installers": "~1.0"
    }
}

However the files are only copied into wordpress/wp-content/themes (or /plugins) when I run composer update or composer install with no composer.lock file present.
This behavior can be reproduced locally.

Here's what I noticed:

  1. When I delete the composer.lock file + wordpress folder + vendor folder and run composer install, it works as expected, my plugin and theme are installed.
  2. If I now keep the composer.lock file that I’ve got in step 1., delete wordpress folder and vendor folder and run composer install again, my plugins and themes are NOT installed (despite the logs saying otherwise).
    If I do a diff of the composer.lock files of the lock files generated in step 1 and in step 2 there is absolutely no difference between them (besides the hash).

What brings me to the conclusion that somehow the

"extra": {
    "installer-paths": {

**commands seem to be ignored.

Is this a known issue? Or expected behavior?**

Here's my main composer.json file

{
  "name": "johnpbloch/wordpress",
  "description": "WordPress is open source software you can use to create a beautiful website, blog, or app.",
  "keywords": [
    "wordpress",
    "blog",
    "cms"
  ],
  "type": "package",
  "homepage": "http://wordpress.org/",
  "license": "GPL-2.0+",
  "authors": [
    {
      "name": "WordPress Community",
      "homepage": "http://wordpress.org/about/"
    }
  ],
  "support": {
    "issues": "http://core.trac.wordpress.org/",
    "forum": "http://wordpress.org/support/",
    "wiki": "http://codex.wordpress.org/",
    "irc": "irc://irc.freenode.net/wordpress",
    "source": "http://core.trac.wordpress.org/browser"
  },
  "require": {
    "php": ">=5.6.20",
    "johnpbloch/wordpress-core-installer": "^1.0 || ^2.0",
    "johnpbloch/wordpress-core": "5.4.2",
    "wpackagist-plugin/bootstrap-shortcodes": "^3.4",
    "wpackagist-plugin/akismet": "^4.1",
    "me/my_custom_plugin": "^1.0",
    "me/my_custom_theme": "^1.0"
  },
  "repositories":[
        {
            "type":"composer",
            "url":"https://wpackagist.org"
        },
        {
          "type": "path",
          "url": "custom/themes/*",
          "options": {
            "symlink": false
          }
        },
        {
          "type": "path",
          "url": "custom/plugins/*",
          "options": {
            "symlink": false
          }
        }
  ],
  "scripts": {
    "copywpconfig": [
      "cp wp-config.php wordpress/"
    ],
    "post-install-cmd": "@copywpconfig"
  },
  "extra": {
    "installer-paths": {
      "wordpress/wp-content/plugins/{$name}": [
        "type:wordpress-plugin"
      ],
      "wordpress/wp-content/themes/{$name}": [
        "type:wordpress-theme"
      ],
      "wordpress/wp-content/mu-plugins/{$name}": [
        "type:wordpress-muplugin"
      ]
    }
  }
}

Here's an example (with a present lock file):

➜ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 25 installs, 0 updates, 0 removals
  - Installing composer/installers (v1.9.0): Loading from cache
  - Installing johnpbloch/wordpress-core-installer (2.0.0): Loading from cache
  - Installing me/my_custom_plugin (1.0): Mirroring from custom/plugins/my_custom_plugin
  - Installing me/my_custom_theme (1.0): Mirroring from custom/themes/my_custom_theme
...
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
> cp wp-config.php wordpress/

But when I check if the theme is present:

ls -la wordpress/wp-content/themes
.rw-r--r-- 28 trolologuy 11 Jun  0:05 index.php
drwxr-xr-x  - trolologuy 11 Jun  0:05 twentynineteen
drwxr-xr-x  - trolologuy 11 Jun  0:05 twentyseventeen
drwxr-xr-x  - trolologuy 11 Jun  0:05 twentytwenty
@trolologuy
Copy link
Author

Okey finally after coming across this issue, I noticed that indeed the install order in composer was different between the tests when the composer.lock was present or not.

What ultimately fixed it was to change the composer.json files in my templates and plugins to add the johnpbloch/wordpress-core package as required, to force installation AFTER wordpress is installed.

{
    "name": "me/my_custom_plugin",
    "description": "Custom Plugin",
    "version": "1.0",
    "type": "wordpress-plugin",
    "require": {
        "composer/installers": "~1.0",
        "johnpbloch/wordpress-core": "5.4.2"
    }
}

@johnpbloch
Copy link
Owner

Hi @trolologuy,

Thanks for stopping by! I'm glad to hear that you've got it working for now. I personally would be worried about what happens when core updates, though. As I explained in the thread you found in the wordpress-core repository, these packages are not meant to support the standard WordPress installation of keeping wp-content inside ABSPATH.

The only way I know of to reliably use these packages in a standard WP installation setup is to base the install off of johnpbloch/wordpress-core at the beginning using composer create-project and then using wp-cli instead of composer to keep WordPress core updated.

@lkraav
Copy link

lkraav commented Aug 7, 2020

@trolologuy you might be interested in looking at https://github.com/wecodemore/wpstarter

And as always, keep it trololol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants