-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
60 lines (60 loc) · 2.07 KB
/
index.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
<?php
/**
Plugin Name: VCWB API example plugin
Plugin URI: http://visualcomposer.com
Description: Visual Composer Website Builder API example plugin
Version: 1.0
Author: Visual Composer
Author URI: http://visualcomposer.com
*/
function myExamplePlugin_registerEditorScrips()
{
wp_register_script(
'vcv:myExamplePlugin:addon:editor:settingsPanel',
plugin_dir_url(__FILE__) . 'dist/index.js',
[],
'1.0',
true
);
}
add_action('init', 'myExamplePlugin_registerEditorScrips');
add_action(
'vcv:api',
function () {
$filters = vchelper('Filters');
$events = vchelper('Events');
// listen for editor loading data request action:
$filters->listen(
'vcv:dataAjax:getData',
function ($response, $payload) {
// receive saved value
$exampleInsights = get_post_meta($payload['sourceId'], '_vcv-exampleInsights', true);
if (!empty($exampleInsights)) {
// pass the value to the editor with a specific key
$response['exampleInsights'] = $exampleInsights;
}
return $response; // must return response
}
);
// listen for editor saving request action:
$filters->listen(
'vcv:dataAjax:setData',
function ($response, $payload) {
$requestHelper = vchelper('Request');
// get our passed value from the editor
$exampleInsights = $requestHelper->input('exampleInsights');
$sourceId = $payload['sourceId'];
// save the value for the current page
update_post_meta($sourceId, '_vcv-exampleInsights', $exampleInsights);
return $response; // must return response
}
);
// listen for editor render action:
$events->listen(
'vcv:frontend:render',
function ($sourceId) {
wp_enqueue_script('vcv:myExamplePlugin:addon:editor:settingsPanel');
}
);
}
);