-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypeform-actions.php
39 lines (31 loc) · 1.19 KB
/
typeform-actions.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
<?php
function typeformAddEmbedScripts()
{
wp_register_script('typeform/embed', 'https://embed.typeform.com/embed.js', [], false, true);
wp_register_style('typeform/embed/button', 'https://embed.typeform.com/share-button.css', [], false);
}
add_action('wp_enqueue_scripts', 'typeformAddEmbedScripts');
function typeformLoadWidget()
{
register_widget('typeform_embed_widget');
}
add_action('widgets_init', 'typeformLoadWidget');
function typeformAddQueryUrl($url)
{
if (!isset($_GET) || empty($_GET)) {
return $url;
}
$ignore = array("preview_id", "preview_nonce", "post_format", "_thumbnail_id", "preview");
$params = array_filter($_GET, function ($k) use ($ignore) {
return !in_array($k, $ignore, true);
}, ARRAY_FILTER_USE_KEY);
$query = http_build_query($params);
$separator = strlen($query) ? strpos($url, '?') === false ? '?' : '&' : '';
return sprintf("%s%s%s", $url, $separator, $query);
}
add_filter('typeform_embed_url', 'typeformAddQueryUrl');
function typeformBuilderTemplate($url, $builder)
{
return ($builder !== '') ? TYPEFORM_TEMPLATE_URL . '?' . $builder : $url;
}
add_filter('typeform_embed_url', 'typeformBuilderTemplate', 5, 2);