-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-clic.sh
943 lines (842 loc) · 20.8 KB
/
wp-clic.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
#!/bin/bash
aboutMenu() {
clear
echo ""
echo "+------------- About -------------+"
echo "| WP-CLI Companion v.1.0 |"
echo "+---------------------------------+"
echo ""
echo "Author: Nathan Baker"
echo "Email: theNathanBaker@gmail.com"
echo "Websites: https://theNathanBaker.com"
echo ""
echo ""
echo "Description:"
echo ""
echo "Thank you for using WP-CLI Companion!"
echo ""
echo "WP-CLIC provides a text based menu system for"
echo "WP-CLI while maintaining the speed of CLI."
echo ""
echo "If you have any bug reports, feature requests, or general comments"
echo "I would love to hear them! Email me at 'theNathanBaker@gmail.com'"
echo ""
echo "If you would like to support development of this project then"
echo "contact me or send a donation to 'theNathanBaker@gmail.com' via Paypal"
echo ""
echo ""
echo ""
echo ""
echo "------ Back to Main Menu ------"
OPTIONS="Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
mainMenu;
else
echo "Invalid Option";
fi
done
}
# Settings Menu
settingsMenu() {
############# General Settings #############
generalSettings () {
echo ""
echo "------ General Settings ------"
OPTIONS="Site_Title Tagline Wordpress_URL Site_Address Membership Default_User_Role Back"
select opt in $OPTIONS
do
###### Back ######
if [ "$opt" = "Back" ]
then
break;
###### Site Title ######
elif [ "$opt" = "Site_Title" ]
then
echo ""
echo -n "Site title: " ; wp option get blogname;
echo "Change site title?"
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
break;
elif [ "$opt" = "Yes" ]
then
read -p "New site title: " newTitle;
wp option update blogname "$newTitle";
break;
else
echo "Invalid Option";
fi
done
generalSettings;
###### Tagline ######
elif [ "$opt" = "Tagline" ]
then
echo ""
echo -n "Tagline: " ; wp option get blogdescription;
echo "Change site tagline?"
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
break;
elif [ "$opt" = "Yes" ]
then
read -p "New site tagline: " newTagline;
wp option update blogdescription "$newTagline";
break;
else
echo "Invalid Option";
fi
done
generalSettings;
###### Wordpress URL ######
elif [ "$opt" = "Wordpress_URL" ]
then
echo ""
echo -n "Wordpress URL: " ; wp option get siteurl;
echo "Change Wordpress URL?"
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
break;
elif [ "$opt" = "Yes" ]
then
read -p "New Wordpress URL: " siteURL;
wp option update siteurl "$siteURL";
break;
else
echo "Invalid Option";
fi
done
generalSettings;
###### Site Address ######
elif [ "$opt" = "Site_Address" ]
then
echo ""
echo -n "Site Address: " ; wp option get home;
echo "Change Site Address?"
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
break;
elif [ "$opt" = "Yes" ]
then
read -p "New Site Address: " siteURL;
wp option update home "$siteURL";
break;
else
echo "Invalid Option";
fi
done
generalSettings;
###### Membership ######
elif [ "$opt" = "Membership" ]
then
echo ""
echo "Allow anyone to register?"
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
wp option update users_can_register 0;
break;
elif [ "$opt" = "Yes" ]
then
wp option update users_can_register 1;
break;
else
echo "Invalid Option";
fi
done
generalSettings;
###### Default User Role ######
elif [ "$opt" = "Default_User_Role" ]
then
echo ""
echo -n "Current default user role: " ; wp option get default_role;
echo "Change?"
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
break;
elif [ "$opt" = "Yes" ]
then
wp role list;
read -p "New default user role: " defaultRole;
wp option update default_role "$defaultRole";
break;
else
echo "Invalid Option";
fi
done
generalSettings;
###### Invalid Option ######
else
echo "Invalid Option";
fi
done
settingsMenu;
}
############# End General Settings #############
readingSettings () {
echo ""
echo "------ Reading Settings ------"
OPTIONS="Search_Engine_Visibility Back"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Back" ]
then
break;
elif [ "$opt" = "Search_Engine_Visibility" ]
then
echo ""
echo "Discourage Search Engines?";
OPTIONS="Yes No"
select opt in $OPTIONS
do
if [ "$opt" = "No" ]
then
wp option update blog_public 1;
break;
elif [ "$opt" = "Yes" ]
then
wp option update blog_public 0;
break;
else
echo "Invalid Option";
fi
done
readingSettings;
else
echo "Invalid Option";
fi
done
settingsMenu;
}
############# Settings Menu #############
echo ""
echo "------------- SETTINGS MENU -------------"
echo ""
OPTIONS="General Reading Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
break;
elif [ "$opt" = "General" ]
then
generalSettings;
elif [ "$opt" = "Reading" ]
then
readingSettings;
else
echo "Invalid Option";
fi
done
mainMenu;
############# End Settings Menu #############
}
# Users Menu
usersMenu() {
createUser () {
read -p "User Login: " userLogin;
read -p "User Password: " userPass;
read -p "User Email: " userEmail;
wp role list;
read -p "User Role: " userRole;
echo ""
echo "Are these settings correct?";
echo "User Login:" $userLogin;
echo "User Password:" $userPass;
echo "User Email:" $userEmail;
echo "User Role:" $userRole;
echo ""
OPTIONS="Yes No Cancel"
select opt in $OPTIONS
do
if [ "$opt" = "Cancel" ]
then
break;
elif [ "$opt" = "Yes" ]
then
wp user create "$userLogin" "$userEmail" --user_pass="$userPass" --role="$userRole";
break;
elif [ "$opt" = "No" ]
then
createUser;
else
echo "Invalid Option";
fi
done
usersMenu;
}
userInfo () {
wp user list;
read -p "Enter user ID, login, or email: " userID;
wp user get "$userID";
usersMenu;
}
deleteUser () {
read -p "Enter user ID, login, or email: " userID;
OPTIONS="Reassign_Content_to_New_User Delete_Associated_Content Cancel"
select opt in $OPTIONS
do
if [ "$opt" = "Cancel" ]
then
break;
elif [ "$opt" = "Reassign_Content_to_New_User" ]
then
wp user list;
read -p "User to assign content to: " reassignID;
wp user delete "$userID" --reassign="$reassignID";
break;
elif [ "$opt" = "Delete_Associated_Content" ]
then
wp user delete "$userID" --yes;
break;
else
echo "Invalid Option";
fi
done
usersMenu;
}
setRole () {
wp user list;
read -p "Select User: " userID;
wp role list;
read -p "Select Role: " roleID;
wp user set-role "$userID" "$roleID";
usersMenu;
}
echo ""
echo "------------- USERS MENU -------------"
echo ""
OPTIONS="List Create Info Delete Set_Role Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
break;
elif [ "$opt" = "List" ]
then
wp user list;
elif [ "$opt" = "Create" ]
then
createUser;
elif [ "$opt" = "Info" ]
then
userInfo;
elif [ "$opt" = "Delete" ]
then
deleteUser;
elif [ "$opt" = "Set_Role" ]
then
setRole;
else
echo "Invalid Option";
fi
done
mainMenu;
}
# Plugin Menu
pluginMenu() {
echo ""
echo "------------- PLUGIN MENU -------------"
echo ""
OPTIONS="List Activate Deactivate Info Search Install Uninstall Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
break;
elif [ "$opt" = "List" ]
then
wp plugin list;
elif [ "$opt" = "Activate" ]
then
read -p "Name of plugin: " pluginName;
wp plugin activate "$pluginName";
elif [ "$opt" = "Deactivate" ]
then
read -p "Name of plugin: " pluginName;
wp plugin deactivate "$pluginName";
elif [ "$opt" = "Info" ]
then
read -p "Name of plugin: " pluginName;
wp plugin get "$pluginName";
elif [ "$opt" = "Search" ]
then
read -p "Search terms: " searchTerms;
wp plugin search "$searchTerms";
elif [ "$opt" = "Install" ]
then
read -p "Name or slug of plugin: " pluginID;
wp plugin install "$pluginID";
elif [ "$opt" = "Uninstall" ]
then
read -p "Plugin: " pluginName;
wp plugin uninstall "$pluginName";
else
echo "Invalid Option";
fi
done
mainMenu;
}
# Appearance Menu
appearanceMenu() {
manageTheme () {
echo ""
echo "------ Theme Menu ------"
OPTIONS="List Activate Get_Info Delete Search_for_themes Install Back"
select opt in $OPTIONS
do
if [ "$opt" = "Back" ]
then
break;
elif [ "$opt" = "List" ]
then
wp theme list;
manageTheme;
elif [ "$opt" = "Activate" ]
then
read -p "Name of theme: " themeID;
wp theme activate $themeID;
elif [ "$opt" = "Get_Info" ]
then
read -p "Name of theme: " themeID;
wp theme get $themeID;
elif [ "$opt" = "Delete" ]
then
read -p "Name of theme: " themeID;
wp theme delete $themeID;
elif [ "$opt" = "Search_for_themes" ]
then
read -p "Search terms: " searchTerms;
wp theme search "$searchTerms";
elif [ "$opt" = "Install" ]
then
read -p "Name of theme: " themeID;
wp theme install $themeID;
else
echo "Invalid Option";
fi
done
appearanceMenu;
}
manageMenu () {
editMenu () {
read -p "Menu name: " menuName;
OPTIONS="List_menu_items Add_page_to_menu Add_custom_link_to_menu Delete_item_from_menu Back"
select opt in $OPTIONS
do
if [ "$opt" = "Back" ]
then
break;
elif [ "$opt" = "List_menu_items" ]
then
wp menu item list "$menuName";
elif [ "$opt" = "Add_page_to_menu" ]
then
wp post list --post_type=page;
read -p "Enter page ID: " pageID;
read -p "Item title: " itemTitle;
wp menu item add-post --title="$itemTitle" "$menuName" $pageID;
elif [ "$opt" = "Add_custom_link_to_menu" ]
then
read -p "Menu item title: " itemTitle;
read -p "URL: " url;
wp menu item add-custom "$menuName" "$itemTitle" "$url";
elif [ "$opt" = "Delete_item_from_menu" ]
then
wp menu item list "$menuName";
read -p "Enter db_id of menu item: " dbID;
wp menu item delete $dbID;
else
echo "Invalid Option";
fi
done
manageMenu;
}
echo ""
echo "------ Manage Menus ------"
OPTIONS="List Create Edit Delete Back"
select opt in $OPTIONS
do
if [ "$opt" = "Back" ]
then
break;
elif [ "$opt" = "List" ]
then
wp menu list;
manageMenu;
elif [ "$opt" = "Create" ]
then
read -p "Menu name: " menuName;
wp menu create "$menuName";
elif [ "$opt" = "Edit" ]
then
wp menu list;
editMenu;
elif [ "$opt" = "Delete" ]
then
read -p "Menu name: " menuName;
wp menu delete "$menuName";
else
echo "Invalid Option";
fi
done
appearanceMenu;
}
###### Appearance Menu ######
echo ""
echo "------------- APPEARANCE MENU -------------"
echo ""
OPTIONS="Theme Menu Widgets Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
mainMenu;
elif [ "$opt" = "Theme" ]
then
manageTheme;
elif [ "$opt" = "Menu" ]
then
manageMenu;
elif [ "$opt" = "Widgets" ]
then
echo "This Feature Is Still Under Development";
else
echo "Invalid Option";
fi
done
###### End Appearance Menu ######
}
# Comments Menu
commentsMenu() {
listComment () {
wp comment list;
}
manageComment () {
read -p "Enter comment ID: " commentID;
OPTIONS="View_Comment Approve Delete Spam Unapprove Unspam Untrash Back"
select opt in $OPTIONS
do
if [ "$opt" = "Back" ]
then
break;
elif [ "$opt" = "View_Comment" ]
then
wp comment get $commentID;
elif [ "$opt" = "Approve" ]
then
wp comment approve $commentID;
elif [ "$opt" = "Delete" ]
then
wp comment delete $commentID;
elif [ "$opt" = "Spam" ]
then
wp comment spam $commentID;
elif [ "$opt" = "Unapprove" ]
then
wp comment unapprove $commentID;
elif [ "$opt" = "Unspam" ]
then
wp comment unspam $commentID;
elif [ "$opt" = "Untrash" ]
then
wp comment untrash $commentID;
else
echo "Invalid Option";
fi
done
commentsMenu
}
echo ""
echo "------------- COMMENTS MENU -------------"
echo ""
wp comment count
echo ""
OPTIONS="List_Comments Manage_Comment Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
mainMenu;
elif [ "$opt" = "List_Comments" ]
then
listComment;
elif [ "$opt" = "Manage_Comment" ]
then
manageComment;
else
echo "Invalid Option";
fi
done
}
# Pages Menu
pagesMenu() {
echo ""
echo "------------- PAGES MENU -------------"
echo ""
getPageInfo () {
wp post list --post_type=page;
read -p "Enter page ID: " pageID;
wp post get $pageID;
}
createPage () {
read -p "Page title: " pageTitle;
wp post create --post_title="$pageTitle" --post_type=page --post_status=publish --edit;
}
editPage () {
wp post list --post_type=page;
read -p "Enter page ID: " pageID;
wp post edit $pageID;
}
deletePage () {
wp post list --post_type=page;
read -p "Enter page ID: " pageID;
wp post delete $pageID;
}
updatePage () {
wp post list --post_type=page;
read -p "Enter page ID of the page you wish to update: " pageID;
wp user list;
read -p "Enter ID of author: " authorID;
echo "Select status of page:";
OPTIONS="Publish Draft"
select opt in $OPTIONS
do
if [ "$opt" = "Publish" ]
then
postStatus=publish;
break;
elif [ "$opt" = "Draft" ]
then
postStatus=draft;
break;
else
echo "Invalid Option";
fi
done
wp post update $pageID --post_author=$authorID --post_status=$postStatus;
}
OPTIONS="List_Pages Get_Page_Info Create_Page Edit_Page Delete_Page Update_Page Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
mainMenu
elif [ "$opt" = "List_Pages" ]
then
wp post list --post_type=page;
elif [ "$opt" = "Get_Page_Info" ]
then
getPageInfo;
elif [ "$opt" = "Create_Page" ]
then
createPage;
elif [ "$opt" = "Edit_Page" ]
then
editPage;
elif [ "$opt" = "Delete_Page" ]
then
deletePage;
elif [ "$opt" = "Update_Page" ]
then
updatePage;
else
echo "Invalid Option";
fi
done
}
# Posts Menu
postMenu() {
echo ""
echo "------------- POSTS MENU -------------"
echo ""
getPostInfo () {
wp post list;
read -p "Enter post ID: " postID;
wp post get $postID;
}
createPost () {
read -p "Post title: " postTitle;
wp post create --post_title="$postTitle" --post_type=post --post_status=publish --edit;
}
editPost () {
wp post list;
read -p "Enter post ID: " postID;
wp post edit $postID;
}
deletePost () {
wp post list;
read -p "Enter post ID: " postID;
wp post delete $postID;
}
updatePost () {
wp post list;
read -p "Enter post ID of the post you wish to update: " postID;
wp user list;
read -p "Enter ID of author: " authorID;
echo "Select status of post:"
OPTIONS="Publish Draft"
select opt in $OPTIONS
do
if [ "$opt" = "Publish" ]
then
postStatus=publish;
break;
elif [ "$opt" = "Draft" ]
then
postStatus=draft;
break;
else
echo "Invalid Option";
fi
done
wp post update $postID --post_author=$authorID --post_status=$postStatus;
}
OPTIONS="List_Posts Get_Post_Info Create_Post Edit_Post Delete_Post Update_Post Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
mainMenu
elif [ "$opt" = "List_Posts" ]
then
wp post list;
elif [ "$opt" = "Get_Post_Info" ]
then
getPostInfo;
elif [ "$opt" = "Create_Post" ]
then
createPost;
elif [ "$opt" = "Edit_Post" ]
then
editPost;
elif [ "$opt" = "Delete_Post" ]
then
deletePost;
elif [ "$opt" = "Update_Post" ]
then
updatePost;
else
echo "Invalid Option"
fi
done
}
# Update Menu
updateMenu() {
echo ""
echo "------------- UPDATE MENU -------------"
echo ""
OPTIONS="Check_Status Update_Wordpress Update_Plugins Update_Themes Main_Menu"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Main_Menu" ]
then
mainMenu;
elif [ "$opt" = "Check_Status" ]
then
wp core check-update;
wp plugin list;
wp theme list;
elif [ "$opt" = "Update_Wordpress" ]
then
wp core update;
elif [ "$opt" = "Update_Plugins" ]
then
wp plugin update --all;
elif [ "$opt" = "Update_Themes" ]
then
wp theme update --all;
else
echo "Invalid Option"
fi
done
}
# Main Menu
start() {
clear
echo ""
echo "+---------------------------------------+"
echo "| WP-CLI Companion v.1.0 |"
echo "+---------------------------------------+"
echo ""
mainMenu;
}
# Main Menu
mainMenu() {
echo ""
echo "------------- MAIN MENU -------------"
echo ""
OPTIONS="Home Updates Posts Pages Comments Appearance Plugins Users Settings About Quit"
PS3="Option: "
select opt in $OPTIONS
do
if [ "$opt" = "Quit" ]
then
echo Done;
exit
elif [ "$opt" = "Home" ]
then
mainMenu;
elif [ "$opt" = "Updates" ]
then
updateMenu;
elif [ "$opt" = "Posts" ]
then
postMenu;
elif [ "$opt" = "Pages" ]
then
pagesMenu;
elif [ "$opt" = "Comments" ]
then
commentsMenu;
elif [ "$opt" = "Appearance" ]
then
appearanceMenu;
elif [ "$opt" = "Plugins" ]
then
pluginMenu;
elif [ "$opt" = "Users" ]
then
usersMenu;
elif [ "$opt" = "Settings" ]
then
settingsMenu;
elif [ "$opt" = "About" ]
then
aboutMenu;
else
echo "Invalid Option"
fi
done
}
# Start Program
start;