-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpuentitycreator.sh
executable file
·187 lines (161 loc) · 5.71 KB
/
wpuentitycreator.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
echo '####';
echo '#### WPU Entity Creator';
echo '#### v 0.42.0';
echo '####';
echo '';
###################################
## Config
###################################
SOURCEDIR="$( dirname "${BASH_SOURCE[0]}" )/";
_SOURCEDIR_BASHUTILITIES="${SOURCEDIR}tools/BashUtilities/"
###################################
## Check path
###################################
MAINDIR="${PWD}/";
if [[ -d "${MAINDIR}wp-content/mu-plugins/" ]];then
echo '-> Going to the mu-plugins directory';
MAINDIR="${MAINDIR}wp-content/mu-plugins/";
fi;
if [[ "${MAINDIR}" != *"mu-plugins"* ]]; then
echo "The script did not start in a mu-plugins directory.";
return 0;
fi
###################################
## Entity type
###################################
if [[ "${1}" == 'p' || "${1}" == 'page' ]]; then
entity_typename='page';
entity_type='p';
elif [[ "${1}" == 'c' || "${1}" == 'custom' ]]; then
entity_typename='entity';
entity_type='c';
elif [[ "${1}" == 't' || "${1}" == 'taxo' || "${1}" == 'taxonomy' ]]; then
entity_typename='taxo';
entity_type='t';
else
entity_current_dirname=$(basename "${MAINDIR}");
default_entity_type_choice='c';
default_entity_type_choice_string='p/t/b/C/e';
if [[ "${entity_current_dirname}" == 'page' || "${entity_current_dirname}" == 'pages' ]];then
default_entity_type_choice='p';
default_entity_type_choice_string='P/t/b/c/e';
fi;
if [[ "${entity_current_dirname}" == 'taxonomy' || "${entity_current_dirname}" == 'taxonomies' ]];then
default_entity_type_choice='t';
default_entity_type_choice_string='p/T/b/c/e';
fi;
if [[ "${entity_current_dirname}" == 'block' || "${entity_current_dirname}" == 'blocks' ]];then
default_entity_type_choice='b';
default_entity_type_choice_string='p/t/B/c/e';
fi;
read -p "Is this entity a [p]age, a [t]axonomy, a [b]lock, a [c]ustom post type or an [e]mpty file ? (${default_entity_type_choice_string}) " entity_type_choice;
if [[ "${entity_type_choice}" == '' ]];then
entity_type_choice="${default_entity_type_choice}";
fi;
if [[ $entity_type_choice == 'c' ]]; then
entity_typename='entity';
entity_type='c';
fi;
if [[ $entity_type_choice == 't' ]]; then
entity_typename='taxo';
entity_type='t';
fi;
if [[ $entity_type_choice == 'b' ]]; then
entity_typename='block';
entity_type='b';
fi;
if [[ $entity_type_choice == 'p' ]]; then
entity_typename='page';
entity_type='p';
fi;
if [[ $entity_type_choice == 'e' ]]; then
entity_typename='empty';
entity_type='e';
fi;
fi;
# Creating dir
MAINDIR_NAME=$(basename $MAINDIR);
if [[ "${entity_typename}" != "empty" && "${MAINDIR_NAME}" == 'mu-plugins' ]];then
if [[ "${entity_typename}" == 'page' ]];then
MAINDIR="${MAINDIR}/pages/";
elif [[ "${entity_typename}" == 'taxo' ]];then
MAINDIR="${MAINDIR}/taxonomies/";
elif [[ "${entity_typename}" == 'block' ]];then
MAINDIR="${MAINDIR}/blocks/";
else
MAINDIR="${MAINDIR}/entities/";
fi;
if [[ ! -d "${MAINDIR}" ]];then
echo "-> Creating a directory for this ${entity_typename}";
mkdir "${MAINDIR}";
fi;
fi;
_wpcontentdir=$(pwd);
wpcontent_dir=$(echo "${_wpcontentdir%/mu-plugins*}");
. "${_SOURCEDIR_BASHUTILITIES}/modules/files.sh";
. "${_SOURCEDIR_BASHUTILITIES}/modules/messages.sh";
. "${_SOURCEDIR_BASHUTILITIES}/modules/texttransform.sh";
. "${_SOURCEDIR_BASHUTILITIES}/modules/values.sh";
. "${_SOURCEDIR_BASHUTILITIES}/modules/git.sh";
. "${SOURCEDIR}bin/functions.sh";
. "${SOURCEDIR}bin/config.sh";
. "${SOURCEDIR}bin/create_file.sh";
. "${SOURCEDIR}bin/detect.sh";
theme_dir="${wpcontent_dir}/themes/${project_prefix}";
# Custom post type
if [[ $entity_type == 'c' ]]; then
. "${SOURCEDIR}bin/register_post_type.sh";
. "${SOURCEDIR}bin/add_taxometas.sh";
. "${SOURCEDIR}bin/prevent_single.sh";
. "${SOURCEDIR}bin/save_post_posttype.sh";
. "${SOURCEDIR}bin/delete_post_posttype.sh";
. "${SOURCEDIR}bin/add_strates_posttype.sh";
. "${SOURCEDIR}bin/add_fixtures.sh";
. "${SOURCEDIR}bin/add_to_blocks.sh";
. "${SOURCEDIR}bin/create_entity.sh";
. "${SOURCEDIR}bin/add_options.sh";
. "${SOURCEDIR}bin/add_post_metas.sh";
. "${SOURCEDIR}bin/add_meta_box.sh";
. "${SOURCEDIR}bin/add_wpuseo.sh";
. "${SOURCEDIR}bin/add_pll.sh";
. "${SOURCEDIR}bin/add_filters.sh";
. "${SOURCEDIR}bin/add_archive_acf_fields.sh";
. "${SOURCEDIR}bin/add_admin_columns.sh";
. "${SOURCEDIR}bin/add_thumbnails.sh";
. "${SOURCEDIR}bin/add_widget.sh";
. "${SOURCEDIR}bin/add_admin_widget.sh";
fi;
# Taxonomy
if [[ $entity_type == 't' ]]; then
. "${SOURCEDIR}bin/register_taxo.sh";
. "${SOURCEDIR}bin/create_tax.sh";
. "${SOURCEDIR}bin/add_taxometas_tax.sh";
. "${SOURCEDIR}bin/add_taxo_column.sh";
. "${SOURCEDIR}bin/add_wpuseo_taxo.sh";
fi;
# Block
if [[ $entity_type == 'b' ]]; then
. "${SOURCEDIR}bin/add_block_type.sh";
. "${SOURCEDIR}bin/add_options.sh";
. "${SOURCEDIR}bin/add_acf_options.sh";
fi;
# Page
if [[ $entity_type == 'p' ]]; then
. "${SOURCEDIR}bin/add_page.sh";
. "${SOURCEDIR}bin/hide_page.sh";
. "${SOURCEDIR}bin/add_post_metas.sh";
. "${SOURCEDIR}bin/add_contact_form.sh";
. "${SOURCEDIR}bin/add_strates_page.sh";
. "${SOURCEDIR}bin/create_page.sh";
fi;
###################################
## Open file in Visual Studio Code
###################################
if command -v ps >/dev/null 2>&1; then
if command -v code >/dev/null 2>&1 && ps aux | grep -q "[V]isual Studio"; then
code "${mainfile}";
fi
fi
. "${SOURCEDIR}bin/clean.sh";
. "${_SOURCEDIR_BASHUTILITIES}/modules/stop.sh";