forked from resir014/headless-wordpress-gutenberg-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
140 lines (117 loc) · 5.16 KB
/
RoboFile.php
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
define( 'PROJECT_DIR', dirname( __FILE__ ) );
define( 'TMP_DIR', PROJECT_DIR . '/tmp' );
define( 'WP_DIR', PROJECT_DIR . '/wordpress' );
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks {
public function wordpressSetup(
$opts = array(
'mysql-host' => '127.0.0.1',
'mysql-root-password' => null,
'wp-user' => 'nedstark',
'wp-pw' => 'winteriscoming',
'wp-theme-dir' => 'postlight-headless-wp',
'wp-theme-name' => 'Postlight Headless WP Starter',
'wp-email' => '[email protected]',
'wp-db-name' => 'wp_headless',
'wp-description' => 'Just another (headless) WordPress site',
'wp-plugins' => array(),
)
) {
$confirm = $this->io()->confirm( 'This will replace your current ' .
'WordPress install. Are you sure you want to do this?', false);
if (!$confirm) {
return;
}
$this->_exec(
'mysql -uroot --password="' . $opts['mysql-root-password'] . '" -h ' . $opts['mysql-host'] .
' -e "create user if not exists ' . $opts['wp-db-name'] . '"'
);
$this->_exec(
'mysql -uroot --password="' . $opts['mysql-root-password'] . '" -h ' . $opts['mysql-host'] .
" -e 'create database if not exists " . $opts['wp-db-name'] . "'"
);
$this->_exec(
'mysql -uroot --password="' . $opts['mysql-root-password'] . '" -h ' . $opts['mysql-host'] .
' -e "grant all privileges on ' . $opts['wp-db-name'] .
' . * to ' . $opts['wp-db-name'] . "@localhost identified by '" . $opts['wp-db-name'] . "'\""
);
$this->_exec(
'mysql -uroot --password="' . $opts['mysql-root-password'] . '" -h ' . $opts['mysql-host'] .
' -e "flush privileges"'
);
$this->wp( 'core download --version=4.9.8 --locale=en_US --force' );
$this->wp( 'core config --dbname=' . $opts['wp-db-name'] . ' --dbuser=' . $opts['wp-db-name'] . ' --dbpass=' . $opts['wp-db-name'] . ' --dbhost=0.0.0.0' );
$this->wp( 'db drop --yes' );
$this->wp( 'db create' );
$install_command = implode( ' ', array(
'core install',
'--url=localhost:8080',
'--title="' . $opts['wp-theme-name'] . '"',
'--admin_user="' . $opts['wp-user'] . '"',
'--admin_password="' . $opts['wp-pw'] . '"',
'--admin_email="' . $opts['wp-email'] . '"',
'--skip-email',
) );
$this->wp( $install_command );
$this->wp( 'theme activate ' . $opts['wp-theme-dir'] );
$this->wp( 'theme delete twentyfourteen' );
$this->wp( 'theme delete twentyfifteen' );
$this->wp( 'theme delete twentysixteen' );
$this->wp( 'theme delete twentyseventeen' );
$this->wp( 'plugin delete akismet' );
$this->wp( 'plugin delete hello' );
if ( is_array( $opts['wp-plugins'] ) && sizeof( $opts['wp-plugins'] ) > 0 ) {
$installed_plugin_directories = $opts['wp-plugins'];
} else {
$installed_plugins = array_filter( glob( WP_DIR . '/wp-content/plugins/*' ), 'is_dir' );
$installed_plugin_directories = array_filter( str_replace( WP_DIR . '/wp-content/plugins/', '', $installed_plugins ) );
}
if ( sizeof( $installed_plugin_directories ) > 0 ) {
$plugins_command = 'plugin activate ' . ( implode( ' ', $installed_plugin_directories ) );
$this->wp( $plugins_command );
}
// Sync ACF
$this->wp( 'acf sync' );
// Pretty URL structure required for wp-json path to work correctly
$this->wp( 'rewrite structure "/%year%/%monthnum%/%day%/%postname%/"' );
// Set the site description
$this->wp( 'option update blogdescription "' . $opts['wp-description'] . '"' );
// Update the Hello World post
$this->wp( 'post update 1 wp-content/themes/postlight-headless-wp/post-content/sample-post.txt '.
'--post_title="Sample Post" --post_name=sample-post' );
// Create homepage content
$this->wp( 'post create wp-content/themes/postlight-headless-wp/post-content/welcome.txt '.
'--post_type=page --post_status=publish --post_name=welcome '.
'--post_title="Congratulations!"' );
$this->wp( 'post create wp-content/themes/postlight-headless-wp/post-content/sample-gutenberg.txt '.
'--post_status=publish --post_name=welcome-to-the-gutenberg-editor '.
'--post_title="Welcome to the Gutenberg Editor" ' );
// Set the above page as our front page.
$this->wp( 'option update page_on_front 5' );
$this->wp( 'option update show_on_front page' );
// Update the default 'Uncategorized' category name to make it more menu-friendly
$this->wp( 'term update category 1 --name="Sample Category"' );
// Set up example menu
$this->wp( 'menu create "Header Menu"' );
$this->wp( 'menu item add-post header-menu 1' );
$this->wp( 'menu item add-post header-menu 2' );
$this->wp( 'menu item add-term header-menu category 1' );
$this->wp( 'menu item add-custom header-menu "Read about the Starter Kit on Medium" https://trackchanges.postlight.com/introducing-postlights-wordpress-react-starter-kit-a61e2633c48c' );
$this->wp( 'menu location assign header-menu header-menu' );
$this->io()->success( 'Great. You can now log into WordPress at: http://localhost:8080/wp-admin (' . $opts['wp-user'] . '/' . $opts['wp-pw'] . ')' );
}
public function server() {
$this->wp( 'server' );
}
public function wp( $arg ) {
$this->taskExec( 'wp' )
->dir( WP_DIR )
->rawArg( $arg )
->run();
}
}