-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
195 lines (164 loc) · 5.19 KB
/
init.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
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
<?php
use Voting\Controller\CategoryController;
use Voting\Controller\NominationsController;
use Voting\Controller\AwardFinalistsController;
use Voting\Controller\AwardController;
use Voting\Controller\WinnersController;
use Voting\Controller\VotesController;
use Voting\Controller\AwardCategoryController;
use Voting\Infrastructure\Migrate;
use Voting\Routes;
use Voting\Infrastructure\Menu;
use Voting\Infrastructure\MenuOptions;
use Voting\Infrastructure\RouteHandler;
use Voting\Infrastructure\RequestObject;
function plugin_activate() {
Migrate::tables();
}
register_activation_hook( __DIR__ . '/voting.php', 'plugin_activate' );
/**
* WP AJAX Routes
*/
function saveNomination()
{
$nominationsController = new NominationsController();
$nominationsController->saveNomination();
}
add_action('wp_ajax_nopriv_save_nomination', 'saveNomination');
add_action('wp_ajax_save_nomination', 'saveNomination');
function patchAwardFinalist()
{
$controller = new AwardFinalistsController;
$handler = new RouteHandler([$controller, 'update'], [$_REQUEST]);
}
add_action('wp_ajax_patch_award_finalist', 'patchAwardFinalist');
function createAwardFinalist()
{
$controller = new AwardFinalistsController;
$handler = new RouteHandler([$controller, 'create'], [$_REQUEST]);
}
add_action('wp_ajax_create_award_finalist', 'createAwardFinalist');
function deleteAwardFinalist()
{
$controller = new AwardFinalistsController;
$handler = new RouteHandler([$controller, 'delete'], [$_REQUEST]);
}
add_action('wp_ajax_delete_award_finalist', 'deleteAwardFinalist');
function createWinner()
{
$controller = new WinnersController;
$handler = new RouteHandler([$controller, 'updateOrCreate'], [$_REQUEST]);
}
add_action('wp_ajax_create_winner', 'createWinner');
function deleteAwardWinners()
{
$controller = new WinnersController;
$handler = new RouteHandler([$controller, 'delete'], [$_REQUEST]);
}
add_action('wp_ajax_delete_winner', 'deleteAwardWinners');
function archiveAward()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'archive'], [$_REQUEST]);
}
add_action('wp_ajax_archive_award', 'archiveAward');
function goLiveAward()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'goLive'], [$_REQUEST]);
}
add_action('wp_ajax_go_live_with_award', 'goLiveAward');
function unpublishAward()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'unpublish'], [$_REQUEST]);
}
add_action('wp_ajax_unpublish_award', 'unpublishAward');
function publishWinners()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'publishWinners'], [$_REQUEST]);
}
add_action('wp_ajax_publish_winners', 'publishWinners');
function unpublishWinners()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'unpublishWinners'], [$_REQUEST]);
}
add_action('wp_ajax_unpublish_winners', 'unpublishWinners');
function saveVote()
{
$controller = new VotesController;
$handler = new RouteHandler([$controller, 'create'], [$_REQUEST]);
}
add_action('wp_ajax_save_vote', 'saveVote');
add_action('wp_ajax_nopriv_save_vote', 'saveVote');
function createCategory()
{
$controller = new CategoryController;
$handler = new RouteHandler([$controller, 'create'], [$_REQUEST]);
}
add_action('wp_ajax_create_category', 'createCategory');
function updateCategory()
{
$controller = new CategoryController;
$handler = new RouteHandler([$controller, 'update'], [$_REQUEST]);
}
add_action('wp_ajax_patch_category', 'updateCategory');
function deleteCategory()
{
$controller = new CategoryController;
$handler = new RouteHandler([$controller, 'delete'], [$_REQUEST]);
}
add_action('wp_ajax_delete_category', 'deleteCategory');
function createAwardCategory()
{
$controller = new AwardCategoryController;
$handler = new RouteHandler([$controller, 'create'], [$_REQUEST]);
}
add_action('wp_ajax_create_award_category', 'createAwardCategory');
function deleteAwardCategory()
{
$controller = new AwardCategoryController;
$handler = new RouteHandler([$controller, 'delete'], [$_REQUEST]);
}
add_action('wp_ajax_delete_award_category', 'deleteAwardCategory');
function createAward()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'create'], [$_REQUEST]);
}
add_action('wp_ajax_create_award', 'createAward');
function patchAward()
{
$controller = new AwardController;
$handler = new RouteHandler([$controller, 'update'], [$_REQUEST]);
}
add_action('wp_ajax_patch_award', 'patchAward');
/**
* Initialise Routes
* Only readable routes
*/
Routes::init();
/**
* Menus
*/
Menu::add(new MenuOptions([
'title' => 'Awards',
'capability' => 'edit_others_pages',
'slug' => 'voting-awards',
'templateName' => 'awards',
]));
Menu::add(new MenuOptions([
'title' => 'Categories',
'capability' => 'edit_others_pages',
'slug' => 'voting-categories',
'templateName' => 'categories',
'parentSlug' => 'voting-awards'
]));
add_action('admin_init', function() {
wp_localize_script('voting-client-js', 'wpApiSettings', array(
'root' => esc_url_raw(rest_url()),
'nonce' => wp_create_nonce('wp_rest')
));
});