brint / wordpress-cookbook

Development repository for Opscode Cookbook wordpress
https://supermarket.chef.io/cookbooks/wordpress
Apache License 2.0
80 stars 176 forks source link

Adding LWRPs for Themes and Plugins #53

Closed EdHurtig closed 9 years ago

EdHurtig commented 9 years ago

It would be really awesome if Plugins and Themes could be installed and activated using a LWRP. Has anyone put some thought into this?

Thoughts

Plugins

wordpress_plugin 'Plugin Name' do 
  action :install | :activate | :deactivate | :delete | :network_activate | :network_deactivate
  sites [ 1 ] # an array of site IDs to activate the plugin on in an MU install
  repository 'https://wordpress.org' # The WordPress Repository (Theoretical I have to look into if this is possible)
  source 'https://internal.company.com/plugin-name.(zip|tar|tar.gz)' # Just Ark that
end

Themes

very similar setup for themes but also the possibility of adding theme mod support

Examples

# Install but don't activate
wordpress_plugin 'jetpack' do 
  action :install
end
# Install if missing and activate for the entire network
wordpress_plugin 'buddypress' do 
  action :activate_network
end
# Delete Plugin
wordpress_plugin 'hello-dolly' do 
  action :delete
end
# Disable Plugin
wordpress_plugin 'akismet' do 
  action :disable
end
jokimaki commented 9 years ago

LWRPs would indeed be a good feature. In my wrapper cookbook I have automated plugin and theme installation/deletion by using wp-cli:

remote_file "/usr/local/bin/wp" do
    action :create_if_missing
    source "https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"
    owner "root"
    group "root"  
    mode 0755
end

# Install and activate plugins
if node['wordpress']['plugins'] then
  node['wordpress']['plugins'].each do |name, version|
    execute "wp plugin #{name}" do
      command "wp plugin install #{name} --version=#{version} --activate"
      cwd  node['wordpress']['dir']
      user node['wordpress']['install']['user']
      action :run
      not_if "wp plugin is-installed #{name}"
    end
  end
end

# Delete some of the default themes
%w{twentythirteen twentytwelve}.each do |name|
  execute "wp theme delete #{name}" do
    command "wp theme delete #{name}"
    cwd  node['wordpress']['dir']
    user node['wordpress']['install']['user']
    action :run
  end
end

I hope this helps.

brint commented 9 years ago

:+1: on wp-cli, it's a fantastic tool for this type of thing. We use wp-cli as well.

There is a community wp-cli cookbook that provides a library for doing anything you'd like to do with wp-cli, which can include installing plugins to an existing WordPress installation.

It would probably be best to keep wp-cli as it's own cookbook.

EdHurtig commented 9 years ago

That works for me, Thanks!