├── .editorconfig ├── .travis.yml ├── README.md ├── composer.json ├── ruleset.xml └── theme-activation-command.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: php 3 | php: 4 | - '5.6' 5 | - '5.5' 6 | - '5.4' 7 | 8 | before_install: 9 | - pyrus install pear/PHP_CodeSniffer 10 | - phpenv rehash 11 | 12 | script: 13 | - phpcs --standard=ruleset.xml --extensions=php -n -s . 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/roots/wp-cli-theme-activation.svg)](https://travis-ci.org/roots/wp-cli-theme-activation) 2 | 3 | ## Installation 4 | 5 | The quick and dirty method is to drop [theme-activation-command.php](https://raw.githubusercontent.com/roots/wp-cli-theme-activation/master/theme-activation-command.php) into your `/mu-plugins/` directory. 6 | 7 | For other methods, please refer to WP-CLI's [Community Packages](https://github.com/wp-cli/wp-cli/wiki/Community-Packages) wiki. 8 | 9 | ## Usage 10 | 11 | Running the command without any options will activate [Sage](https://github.com/roots/sage) with all of the default options. 12 | 13 | 14 | ### `wp theme activation` 15 | 16 | 1. Activates Sage 17 | 2. Creates page called Home and sets as [static front page](http://codex.wordpress.org/Creating_a_Static_Front_Page) 18 | 3. Creates a new menu called Primary Navigation and adds newly created home page to it 19 | 20 | 21 | ### Options 22 | 23 | #### `[]` 24 | The theme name to activate. **Default: 'sage'** 25 | 26 | #### `[--show-on-front=]` 27 | What to show on the front page. Options are: 'posts', 'page'. **Default: 'page'** 28 | 29 | #### `[--permalink-structure=]` 30 | Permalink structure. **Default: '/%postname%/'** 31 | 32 | #### `[--skip-navigation]` 33 | Skips creating default Primary Navigation. 34 | 35 | ### Examples 36 | ``` 37 | wp theme activation 38 | wp theme activation --show-on-front=page --permalink-structure='/%year%/%postname%/' --skip-navigation 39 | ``` 40 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "roots/wp-cli-theme-activation", 3 | "description": "WP-CLI command for activating a theme and setting default options", 4 | "type": "command", 5 | "keywords": ["wp-cli", "wordpress"], 6 | "homepage": "https://github.com/roots/wp-cli-theme-activation", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Ben Word", 11 | "email": "ben@benword.com", 12 | "homepage": "https://github.com/retlehs" 13 | }, 14 | { 15 | "name": "Scott Walkinshaw", 16 | "email": "scott.walkinshaw@gmail.com", 17 | "homepage": "https://github.com/swalkinshaw" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=5.4" 22 | }, 23 | "autoload": { 24 | "files": ["theme-activation-command.php"] 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Roots Coding Standards 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /theme-activation-command.php: -------------------------------------------------------------------------------- 1 | ] 14 | * : The theme name to activate. Defaults to 'sage'. 15 | * 16 | * [--show-on-front=] 17 | * : What to show on the front page. Options are: 'posts', 'page'. Default is 'page'. 18 | * 19 | * [--permalink-structure=] 20 | * : Permalink structure. Default is '/%postname%/'. 21 | * 22 | * [--skip-navigation] 23 | * : Skip creating default Primary Navigation. 24 | * 25 | * ## EXAMPLES 26 | * 27 | * wp theme activation 28 | * wp theme activation --show-on-front=page --permalink-structure='/%year%/%postname%/' --skip-navigation 29 | * 30 | * @subcommand activation 31 | * @alias roots-activate 32 | */ 33 | public function activation($args = [], $options = []) { 34 | list($theme) = $args + ['sage']; 35 | 36 | $defaults = [ 37 | 'permalink-structure' => '/%postname%/', 38 | 'show-on-front' => 'page', 39 | 'skip-navigation' => false 40 | ]; 41 | 42 | $options = wp_parse_args($options, $defaults); 43 | 44 | $options['skip-navigation'] = ($options['skip-navigation'] || !!wp_get_nav_menu_object('Primary Navigation')); 45 | 46 | \WP_CLI::log('Activating theme and setting options'); 47 | 48 | $home_page_options = [ 49 | 'post_content' => 'Lorem Ipsum', 50 | 'post_status' => 'publish', 51 | 'post_title' => 'Home', 52 | 'post_type' => 'page' 53 | ]; 54 | 55 | parent::activate([$theme]); 56 | 57 | if ($home_page_id = wp_insert_post($home_page_options, false)) { 58 | \WP_CLI::run_command(['option', 'update', 'show_on_front', $options['show-on-front']]); 59 | \WP_CLI::run_command(['option', 'update', 'page_on_front', $home_page_id]); 60 | } 61 | 62 | if (!$options['skip-navigation'] && $menu_id = wp_create_nav_menu('Primary Navigation')) { 63 | $home_page_id && wp_update_nav_menu_item($menu_id, 0, [ 64 | 'menu-item-title' => $home_page_options['post_title'], 65 | 'menu-item-object' => $home_page_options['post_type'], 66 | 'menu-item-object-id' => $home_page_id, 67 | 'menu-item-type' => 'post_type', 68 | 'menu-item-status' => 'publish' 69 | ]); 70 | 71 | set_theme_mod('nav_menu_locations', ['primary_navigation' => $menu_id]); 72 | 73 | \WP_CLI::success('Primary Navigation created.'); 74 | } 75 | 76 | \WP_CLI::run_command(['rewrite', 'structure', $options['permalink-structure']]); 77 | \WP_CLI::run_command(['rewrite', 'flush']); 78 | 79 | \WP_CLI::success('Theme activated'); 80 | } 81 | } 82 | 83 | \WP_CLI::add_command('theme', __NAMESPACE__ . '\\Theme'); 84 | --------------------------------------------------------------------------------