-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-makepot-custom.sh
executable file
·101 lines (88 loc) · 2.77 KB
/
wp-makepot-custom.sh
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
#!/usr/bin/env bash
# Created by Hugo Ferreira <[email protected]> on 2014-02-09.
# Copyright (c) 2014 Mindclick. All Rights Reserved.
# Licensed under the MIT License: https://opensource.org/licenses/MIT
readonly BASEDIR=$(cd "$(dirname "$0")" && pwd) # where the script is located
readonly CALLDIR=$(pwd) # where it was called from
readonly STATUS_SUCCESS=0 # exit status for commands
# Script configuration
readonly CMD_MAKE_POT="php ${HOME}/Work/Sandbox/wordpress/i18n-tools.svn/makepot.php"
# Script functions
usage() {
echo "
Usage: $(basename $0) slug folder
-h this usage help text
slug the base name to use for the plugins and theme
folder location of the wordpress installation
Regenerates the .pot file of custom plugins and theme with a common slug.
Example:
$(basename $0) clientname ./wordpress/"
exit ${1:-0}
}
ask_if_empty() {
local value="$1"
local default="$2"
local message="$3"
local options="$4" # pass "-s" for passwords
if [[ -z "$value" ]]; then
read $options -p "$message [$default] " value
fi
value=$(echo ${value:-$default})
echo "$value"
}
make_pot() {
local kind="$1"
local slug="$2"
local folder="$3"
local prepare=: # noop
local cleanup=: # noop
case "$kind" in
themes)
kind_type='wp-theme'
;;
plugins)
kind_type='wp-plugin'
;;
mu-plugins)
prepare=mu_plugin_setup
slug="$slug-mu"
kind_type='wp-plugin'
cleanup=mu_plugin_cleanup
;;
esac
$prepare $slug $folder
$CMD_MAKE_POT "$kind_type" "$folder/wp-content/$kind/$slug/" "$folder/wp-content/$kind/$slug/$slug.pot"
$cleanup $slug $folder
}
mu_plugin_setup() {
local slug="$1"
local folder="$2"
mkdir -p "$folder/wp-content/mu-plugins/$slug"
ln -nfs "../$slug.php" "$folder/wp-content/mu-plugins/$slug/$slug.php"
}
mu_plugin_cleanup() {
local slug="$1"
local folder="$2"
mv "$folder/wp-content/mu-plugins/$slug/$slug.pot" "$folder/wp-content/mu-plugins/"
rm -rf "$folder/wp-content/mu-plugins/$slug"
}
# Parse command line options
while getopts h option; do
case $option in
h) usage ;;
\?) usage 1 ;;
esac
done
shift $(($OPTIND - 1)); # take out the option flags
# Validate input parameters
slug=$(ask_if_empty "$1" "clientname" "Enter the slug to use:")
folder=$(ask_if_empty "$2" "." "Enter the WordPress folder:")
if [[ ! -a "$folder/wp-config.php" ]]; then
echo;
echo "Folder '$folder' doesn't seem to be a WordPress installation";
exit 1;
fi
# Do the work
make_pot 'themes' $slug $folder
make_pot 'plugins' $slug $folder
make_pot 'mu-plugins' $slug $folder