-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-usage.php
More file actions
427 lines (353 loc) · 13.9 KB
/
Copy pathexample-usage.php
File metadata and controls
427 lines (353 loc) · 13.9 KB
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
<?php
/**
* Resume Parser Plugin - Example Usage
*
* This file demonstrates how to use the Resume Parser plugin
* in various scenarios and integrations.
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Example 1: Basic shortcode usage in a WordPress page/post
*/
function example_basic_shortcode() {
// Add this shortcode to any page or post content
return '[resume_parser]';
}
/**
* Example 2: Advanced shortcode with custom fields and API
*/
function example_advanced_shortcode() {
// Custom fields and API endpoint
return '[resume_parser fields="name,email,phone,experience,education,skills,summary,address" api_endpoint="https://api.resumeparser.com/parse" class="job-application-form"]';
}
/**
* Example 3: Programmatic shortcode rendering
*/
function example_programmatic_usage() {
$atts = array(
'fields' => 'name,email,phone,experience',
'api_endpoint' => 'https://your-api.com/parse',
'class' => 'resume-form'
);
return do_shortcode('[resume_parser fields="' . $atts['fields'] . '" api_endpoint="' . $atts['api_endpoint'] . '" class="' . $atts['class'] . '"]');
}
/**
* Example 4: Custom form integration
*/
function example_custom_form_integration() {
ob_start();
?>
<form id="job-application-form" method="post" action="">
<h3>Job Application Form</h3>
<!-- Resume Parser Shortcode -->
<?php echo do_shortcode('[resume_parser fields="name,email,phone,experience,education,skills"]'); ?>
<!-- Additional custom fields -->
<div class="form-group">
<label for="position">Position Applied For:</label>
<select id="position" name="position" required>
<option value="">Select Position</option>
<option value="developer">Software Developer</option>
<option value="designer">UI/UX Designer</option>
<option value="manager">Project Manager</option>
</select>
</div>
<div class="form-group">
<label for="salary_expectation">Salary Expectation:</label>
<input type="text" id="salary_expectation" name="salary_expectation" placeholder="e.g., $80,000 - $100,000">
</div>
<div class="form-group">
<label for="cover_letter">Cover Letter:</label>
<textarea id="cover_letter" name="cover_letter" rows="6" placeholder="Tell us why you're perfect for this role..."></textarea>
</div>
<div class="form-group">
<input type="submit" value="Submit Application" class="submit-btn">
</div>
</form>
<style>
#job-application-form {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background: #f9f9f9;
border-radius: 8px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input,
.form-group select,
.form-group textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.submit-btn {
background: #007cba;
color: white;
border: none;
padding: 12px 30px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.submit-btn:hover {
background: #005a87;
}
</style>
<?php
return ob_get_clean();
}
/**
* Example 5: Contact Form 7 Integration
*/
function example_cf7_integration() {
// Create a Contact Form 7 form with resume parser
$form_content = '
<h3>Contact Form with Resume Parser</h3>
[resume_parser fields="name,email,phone"]
<label>Your Message
[textarea your-message placeholder "Your message here..."]
</label>
<label>Subject
[text your-subject placeholder "Subject"]
</label>
[submit "Send Message"]
';
return $form_content;
}
/**
* Example 6: Custom API endpoint handler
*/
function example_custom_api_endpoint() {
// This would be your custom API endpoint that receives resume data
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input = json_decode(file_get_contents('php://input'), true);
if (isset($input['file_data'])) {
// Decode the base64 file data
$file_content = base64_decode($input['file_data']);
// Here you would integrate with your resume parsing service
// For example, using a third-party API like HireAbility, Sovren, etc.
$parsed_data = parse_resume_with_external_service($file_content, $input['file_type']);
if ($parsed_data) {
header('Content-Type: application/json');
echo json_encode($parsed_data);
} else {
http_response_code(400);
echo json_encode(['error' => true, 'message' => 'Failed to parse resume']);
}
}
}
}
/**
* Example resume parsing function (mock implementation)
*/
function parse_resume_with_external_service($file_content, $file_type) {
// This is a mock function - replace with actual API integration
// Example using a hypothetical resume parsing API
$api_url = 'https://api.resumeparser.com/v1/parse';
$api_key = 'your-api-key';
$post_data = array(
'file_content' => base64_encode($file_content),
'file_type' => $file_type,
'output_format' => 'json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
/**
* Example 7: WordPress hook integrations
*/
// Hook into resume parsing success
add_action('resume_parser_after_success', function($parsed_data) {
// Save resume data to user meta or custom table
if (is_user_logged_in()) {
$user_id = get_current_user_id();
update_user_meta($user_id, 'parsed_resume_data', $parsed_data);
}
// Send notification email to admin
wp_mail(
get_option('admin_email'),
'New Resume Parsed',
'A new resume has been parsed with the following data: ' . print_r($parsed_data, true)
);
});
// Modify allowed file types
add_filter('resume_parser_allowed_types', function($types) {
// Add text files to allowed types
$types[] = 'text/plain';
return $types;
});
// Customize API request data
add_filter('resume_parser_api_data', function($data, $file_info) {
// Add additional metadata
$data['timestamp'] = current_time('timestamp');
$data['user_id'] = is_user_logged_in() ? get_current_user_id() : 0;
$data['ip_address'] = $_SERVER['REMOTE_ADDR'];
return $data;
}, 10, 2);
/**
* Example 8: AJAX handler for custom processing
*/
add_action('wp_ajax_custom_resume_processing', 'handle_custom_resume_processing');
add_action('wp_ajax_nopriv_custom_resume_processing', 'handle_custom_resume_processing');
function handle_custom_resume_processing() {
// Verify nonce
if (!wp_verify_nonce($_POST['nonce'], 'custom_resume_nonce')) {
wp_die('Security check failed');
}
// Get the parsed resume data
$resume_data = $_POST['resume_data'];
// Custom processing logic
$processed_data = array();
// Example: Extract skills and match with job requirements
if (isset($resume_data['skills'])) {
$skills = explode(',', $resume_data['skills']);
$required_skills = array('PHP', 'JavaScript', 'WordPress', 'MySQL');
$matched_skills = array_intersect($skills, $required_skills);
$processed_data['skill_match_percentage'] = (count($matched_skills) / count($required_skills)) * 100;
$processed_data['matched_skills'] = $matched_skills;
}
// Example: Calculate experience level
if (isset($resume_data['experience'])) {
$experience_text = strtolower($resume_data['experience']);
$years = 0;
if (preg_match('/(\d+)\s*years?/', $experience_text, $matches)) {
$years = intval($matches[1]);
}
$processed_data['experience_years'] = $years;
if ($years < 2) {
$processed_data['experience_level'] = 'Junior';
} elseif ($years < 5) {
$processed_data['experience_level'] = 'Mid-level';
} else {
$processed_data['experience_level'] = 'Senior';
}
}
wp_send_json_success($processed_data);
}
/**
* Example 9: Shortcode in widget
*/
function example_widget_integration() {
// Add this to your theme's functions.php to create a custom widget
class Resume_Parser_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'resume_parser_widget',
'Resume Parser Widget',
array('description' => 'Add a resume parser form to your sidebar')
);
}
public function widget($args, $instance) {
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
}
$fields = !empty($instance['fields']) ? $instance['fields'] : 'name,email,phone';
echo do_shortcode('[resume_parser fields="' . $fields . '"]');
echo $args['after_widget'];
}
public function form($instance) {
$title = !empty($instance['title']) ? $instance['title'] : 'Upload Resume';
$fields = !empty($instance['fields']) ? $instance['fields'] : 'name,email,phone';
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id('fields'); ?>">Fields:</label>
<input class="widefat" id="<?php echo $this->get_field_id('fields'); ?>" name="<?php echo $this->get_field_name('fields'); ?>" type="text" value="<?php echo esc_attr($fields); ?>">
</p>
<?php
}
public function update($new_instance, $old_instance) {
$instance = array();
$instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
$instance['fields'] = (!empty($new_instance['fields'])) ? strip_tags($new_instance['fields']) : '';
return $instance;
}
}
// Register the widget
add_action('widgets_init', function() {
register_widget('Resume_Parser_Widget');
});
}
/**
* Example 10: Page template integration
*/
function example_page_template() {
// Create a custom page template: page-job-application.php
$template_content = '
<?php
/*
Template Name: Job Application
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<article class="page job-application-page">
<header class="page-header">
<h1 class="page-title">Job Application</h1>
</header>
<div class="page-content">
<p>Please upload your resume to auto-fill the application form:</p>
<!-- Resume Parser Integration -->
<?php echo do_shortcode(\'[resume_parser fields="name,email,phone,experience,education,skills,summary"]\'); ?>
<!-- Additional application fields -->
<div class="additional-fields">
<h3>Additional Information</h3>
<form id="application-form" method="post">
<div class="form-row">
<label for="position">Position:</label>
<select id="position" name="position" required>
<option value="">Select Position</option>
<option value="frontend">Frontend Developer</option>
<option value="backend">Backend Developer</option>
<option value="fullstack">Full Stack Developer</option>
</select>
</div>
<div class="form-row">
<label for="availability">Start Date:</label>
<input type="date" id="availability" name="availability" required>
</div>
<div class="form-row">
<button type="submit">Submit Application</button>
</div>
</form>
</div>
</div>
</article>
</main>
</div>
<?php get_footer(); ?>
';
return $template_content;
}
// Initialize examples if called directly (for testing)
if (defined('WP_CLI') && WP_CLI) {
// WP-CLI commands for testing
WP_CLI::add_command('resume-parser test', function() {
WP_CLI::success('Resume Parser Plugin examples loaded successfully!');
});
}