Skip to content

Commit 0507f2f

Browse files
authored
Merge pull request #146 from JohnEricson/master
Add support for 'wp option patch' to be able to add, update and remove nested values in options too
2 parents 6d7ab07 + 5d39d55 commit 0507f2f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

manifests/option/patch.pp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# A class for WordPress option patch subcommand.
2+
define wp::option::patch (
3+
$location,
4+
$key = $title,
5+
$key_path = undef,
6+
$value = undef,
7+
$ensure = present,
8+
$format = 'plaintext',
9+
$user = $::wp::user,
10+
) {
11+
include wp::cli
12+
13+
case $ensure {
14+
present: {
15+
$command = "insert ${key} ${key_path} ${value} --format=${format}"
16+
}
17+
equal: {
18+
if $value == undef {
19+
fail('Option value must be specified')
20+
}
21+
$command = "update ${key} ${key_path} ${value}"
22+
}
23+
absent: {
24+
$command = "delete ${key} ${key_path}"
25+
}
26+
default: {
27+
fail('Invalid option operation')
28+
}
29+
}
30+
31+
wp::command { "${location} option patch ${command}":
32+
location => $location,
33+
command => "option patch ${command}",
34+
user => $user,
35+
}
36+
}

0 commit comments

Comments
 (0)