chriszarate / docker-compose-wordpress

An example Docker Compose setup for WordPress plugin or theme development.
162 stars 54 forks source link

Install and activate other plugins #6

Closed cstromquist closed 7 years ago

cstromquist commented 7 years ago

One thing I haven't been able to figure out is the best way to get other WP plugins installed and activated. The plugin I'm developing actually has a dependency on another WP plugin. Is there an easy way to add plugin dependencies to have them installed and activated?

chriszarate commented 7 years ago

This is relatively straightforward using WP-CLI:

docker-compose exec wordpress wp plugin install mailchimp-for-wp
docker-compose exec wordpress wp plugin activate mailchimp-for-wp

Automating this on startup (docker-compose up), though, isn't currently possible. I'll work on an environment variable that works similarly to WORDPRESS_ACTIVATE_PLUGINS that will auto-install plugins on startup.

cstromquist commented 7 years ago

That's what I was trying to do before - add a list of space delimited plugins to the WORDPRESS_ACTIVATE_PLUGINS - but it just threw an error.

The commands will work for now. Thanks for that!

chriszarate commented 7 years ago

Noting here the latest version will attempt to install any plugins in WORDPRESS_ACTIVATE_PLUGINS or theme in WORDPRESS_ACTIVATE_THEME with WP-CLI if it is not found locally in wp-content/plugins or wp-content/themes.

cstromquist commented 7 years ago

Sweet! Thanks Chris!

cstromquist commented 7 years ago

On another note, is there some documentation where all the available commands for docker-compose exec wordpress <command> available like the ones for wp plugin install <plugin> you had above?

cstromquist commented 7 years ago

Also, when I run the wp plugin install command, it works great and can access it from project.dev/wp-admin, however, it doesn't look like PHPUnit is able to access any methods from the plugin I've added. Is there a way to make it so that I can access the installed plugins from PHPUnit?

chriszarate commented 7 years ago

On documentation, any command starting wp is using WP-CLI. Documentation and examples can be found here:

http://wp-cli.org

For PHPUnit, use the PHPUNIT_WP_CONTENT_LINKS environment variable. From the docs of docker-wordpress: A space-separated list of paths, relative to /var/www/html/wp-content/, that should be symlinked into the WordPress unit test suite directory so that they are available during testing.

MikeiLL commented 7 years ago

I updated my wordpress container volumes mapping to this: ".:/var/www/html/wp-content/plugins/" so now I can have other non-public plugins in my local directory and they are being loaded in the plugins directory.

chriszarate commented 7 years ago

Yes, that's the basic approach. You could also map plugin directories individually, e.g.:

- "./plugin1:/var/www/html/wp-content/plugins/plugin1"
- "./plugin2:/var/www/html/wp-content/plugins/plugin2"
MikeiLL commented 7 years ago

I LOVE this repo!

cstromquist commented 7 years ago

Works, thank you!

cstromquist commented 7 years ago

So I was able to get my other plugin dependency symlinked into the Wordpress unit test suite directory, however, it doesn't appear the plugin is getting activated for my tests.

Is there something else I need to do to activate a plugin in the test environment?

cstromquist commented 7 years ago

Still haven't solved the PHPUnit plugin issue. Here's my wordpress docker setup:

    image: "chriszarate/wordpress:4.7.5"
    environment:
      PHPUNIT_TEST_DIR: "/var/www/html/wp-content/plugins/my-plugin"
      PHPUNIT_WP_CONTENT_LINKS: "plugins/advanced-custom-fields-pro"
      VIRTUAL_HOST: "${DOCKER_DEV_DOMAIN}"
      WORDPRESS_ACTIVATE_PLUGINS: "component-manager advanced-custom-fields-pro" # plugin folder relative to /wp-content/plugins/
      WORDPRESS_ACTIVATE_THEME: ""   # theme folder relative to /wp-content/themes/
      WORDPRESS_SITE_TITLE: "My Plugin"
      WORDPRESS_SITE_URL: "project.dev"
      WORDPRESS_CONFIG_EXTRA: ""
      WORDPRESS_PERMALINK_STRUCTURE: "/%postname%/"
      XDEBUG_CONFIG: "remote_host=${DOCKER_LOCAL_IP} idekey=xdebug"
    depends_on:
      - "mysql"
    networks:
      - "front"
      - "back"
    volumes:
      - ".:/var/www/html/wp-content/plugins/my-plugin"
      - "../../:/var/www/html/wp-content

Could you tell me why my advanced-custom-fields-pro does not activate properly for PHPUnit even though it's set there? More specifically, I'm using methods from advanced-custom-fields-pro in my-plugin but they are not accessible when I run the tests. However, the plugin is properly installed and activated at project.dev/wp-admin.

Also, in the logs it says it's symlinking the plugin/advanced-custom-fields-pro directory properly.

chriszarate commented 7 years ago

Folders included in PHPUNIT_WP_CONTENT_LINKS will be symlinked into the copy of WordPress used for testing (at /tmp/wordpress/latest/src/wp-content/). It's up to you to require any code that you need to run your tests. I'm guessing that's the step you're missing.

cstromquist commented 7 years ago

Indeed, that's what I was missing. Thank you!