9
9
10
10
use WP_Job_Manager \UI \Modal_Dialog ;
11
11
use WP_Job_Manager \UI \Notice ;
12
+ use WP_Job_Manager \UI \UI ;
13
+ use WP_Job_Manager \UI \UI_Elements ;
12
14
13
15
if ( ! defined ( 'ABSPATH ' ) ) {
14
16
exit ;
@@ -28,21 +30,39 @@ class Job_Overlay {
28
30
*/
29
31
public function __construct () {
30
32
add_action ( 'job_manager_ajax_job_dashboard_overlay ' , [ $ this , 'ajax_job_overlay ' ] );
33
+ add_action ( 'wp_ajax_job_dashboard_overlay ' , [ $ this , 'ajax_job_overlay ' ] );
34
+ add_action ( 'admin_footer ' , [ $ this , 'init_admin_dashboard_overlay ' ], 10 );
35
+ add_action ( 'job_manager_job_dashboard ' , [ $ this , 'init_dashboard_overlay ' ], 10 );
36
+ add_action ( 'job_manager_job_overlay_footer ' , [ $ this , 'output_footer_actions ' ], 10 );
31
37
32
38
}
33
39
34
40
/**
35
41
* Render the job dashboard overlay content for an AJAX request.
36
42
*/
37
43
public function ajax_job_overlay () {
38
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
44
+
45
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce check.
46
+ if ( ! isset ( $ _REQUEST ['_wpnonce ' ] ) || ! wp_verify_nonce ( wp_unslash ( $ _REQUEST ['_wpnonce ' ] ), 'job_dashboard_overlay ' ) ) {
47
+ wp_send_json_error (
48
+ Notice::error (
49
+ [
50
+ 'message ' => __ ( 'Invalid request. ' , 'wp-job-manager ' ),
51
+ 'classes ' => [ 'type-dialog ' ],
52
+ ]
53
+ )
54
+ );
55
+
56
+ return ;
57
+ }
58
+
39
59
$ job_id = isset ( $ _REQUEST ['job_id ' ] ) ? absint ( $ _REQUEST ['job_id ' ] ) : null ;
40
60
41
61
$ job = $ job_id ? get_post ( $ job_id ) : null ;
42
62
43
63
$ shortcode = Job_Dashboard_Shortcode::instance ();
44
64
45
- if ( empty ( $ job ) || ! $ shortcode ->is_job_available_on_dashboard ( $ job ) ) {
65
+ if ( ! $ shortcode ->can_manage_job ( $ job ) ) {
46
66
wp_send_json_error (
47
67
Notice::error (
48
68
[
@@ -55,7 +75,7 @@ public function ajax_job_overlay() {
55
75
return ;
56
76
}
57
77
58
- $ content = $ this ->get_job_overlay ( $ job );
78
+ $ content = $ this ->render_job_overlay ( $ job );
59
79
60
80
wp_send_json_success ( $ content );
61
81
@@ -65,6 +85,11 @@ public function ajax_job_overlay() {
65
85
* Output the modal element.
66
86
*/
67
87
public function output_modal_element () {
88
+
89
+ UI ::instance ()->enqueue_styles ();
90
+ wp_enqueue_style ( 'wp-job-manager-job-dashboard ' );
91
+ wp_enqueue_script ( 'wp-job-manager-job-dashboard ' );
92
+
68
93
$ overlay = new Modal_Dialog (
69
94
[
70
95
'id ' => 'jmDashboardOverlay ' ,
@@ -83,17 +108,14 @@ public function output_modal_element() {
83
108
*
84
109
* @return string
85
110
*/
86
- private function get_job_overlay ( $ job ) {
87
-
88
- $ job_actions = Job_Dashboard_Shortcode::instance ()->get_job_actions ( $ job );
111
+ private function render_job_overlay ( $ job ) {
89
112
90
113
ob_start ();
91
114
92
115
get_job_manager_template (
93
116
'job-dashboard-overlay.php ' ,
94
117
[
95
- 'job ' => $ job ,
96
- 'job_actions ' => $ job_actions ,
118
+ 'job ' => $ job ,
97
119
]
98
120
);
99
121
@@ -102,5 +124,96 @@ private function get_job_overlay( $job ) {
102
124
return $ content ;
103
125
}
104
126
127
+ /**
128
+ * Load and output overlay dependencies on the job listings screen.
129
+ *
130
+ * @output Modal HTML.
131
+ *
132
+ * @return void
133
+ */
134
+ public function init_admin_dashboard_overlay () {
135
+ $ screen = get_current_screen ();
136
+
137
+ if ( ! $ screen || 'edit-job_listing ' !== $ screen ->id ) {
138
+ return ;
139
+ }
140
+
141
+ $ this ->init_dashboard_overlay ();
142
+ }
143
+
144
+ /**
145
+ * Load scripts and output HTML skeleton for the job dashboard overlay.
146
+ *
147
+ * @output Modal HTML.
148
+ *
149
+ * @return void
150
+ */
151
+ public function init_dashboard_overlay () {
152
+
153
+ \WP_Job_Manager::register_script ( 'wp-job-manager-job-dashboard ' , 'js/job-dashboard.js ' , null , true );
154
+ \WP_Job_Manager::register_style ( 'wp-job-manager-job-dashboard ' , 'css/job-dashboard.css ' , [ 'wp-job-manager-ui ' ] );
155
+
156
+ $ endpoint = is_admin ()
157
+ ? add_query_arg ( [ 'action ' => 'job_dashboard_overlay ' ], admin_url ( 'admin-ajax.php ' ) )
158
+ : \WP_Job_Manager_Ajax::get_endpoint ( 'job_dashboard_overlay ' );
159
+ $ endpoint = wp_nonce_url ( $ endpoint , 'job_dashboard_overlay ' );
160
+
161
+ wp_localize_script (
162
+ 'wp-job-manager-job-dashboard ' ,
163
+ 'job_manager_job_dashboard ' ,
164
+ [
165
+ 'i18nConfirmDelete ' => esc_html__ ( 'Are you sure you want to delete this listing? ' , 'wp-job-manager ' ),
166
+ 'overlayEndpoint ' => $ endpoint ,
167
+ 'statsEnabled ' => \WP_Job_Manager \Stats::is_enabled (),
168
+ ]
169
+ );
170
+
171
+ $ this ->output_modal_element ();
172
+ }
173
+
174
+ /**
175
+ * Output the job actions in the overlay footer.
176
+ *
177
+ * @param \WP_Post $job
178
+ */
179
+ public function output_footer_actions ( $ job ) {
180
+
181
+ if ( is_admin () ) {
182
+ return ;
183
+ }
184
+
185
+ $ job_actions = Job_Dashboard_Shortcode::instance ()->get_job_actions ( $ job );
186
+
187
+ $ buttons = [];
188
+ $ actions = [];
189
+ if ( ! empty ( $ job_actions ) ) {
190
+ $ primary = Job_Dashboard_Shortcode::get_primary_action ( $ job , $ job_actions );
191
+
192
+ if ( $ primary ) {
193
+ $ buttons [] = [
194
+ 'label ' => $ primary ['label ' ],
195
+ 'url ' => $ primary ['url ' ],
196
+ 'class ' => 'job-dashboard-action- ' . esc_attr ( $ primary ['name ' ] ),
197
+ 'primary ' => false ,
198
+ ];
199
+ }
200
+
201
+ foreach ( $ job_actions as $ action ) {
202
+ if ( ! empty ( $ primary ) && $ primary ['name ' ] === $ action ['name ' ] ) {
203
+ continue ;
204
+ }
205
+ $ actions [] = [
206
+ 'label ' => $ action ['label ' ],
207
+ 'url ' => $ action ['url ' ],
208
+ 'class ' => 'job-dashboard-action- ' . esc_attr ( $ action ['name ' ] ),
209
+ ];
210
+ }
211
+ }
212
+
213
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in UI classes.
214
+ echo UI_Elements::actions ( $ buttons , $ actions );
215
+
216
+ }
217
+
105
218
106
219
}
0 commit comments