PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 8.2
Jetpack – WP Security, Backup, Speed, & Growth v8.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / wufoo.php

wufoo.php in Jetpack – WP Security, Backup, Speed, & Growth 8.2, at modules/shortcodes/wufoo.php

122 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Wufoo Shortcode
4 * Based on https://wordpress.org/plugins/wufoo-shortcode/
5 *
6 * Examples:
7 * [wufoo username="jeherve" formhash="z1x13ltw1m8jtrw" autoresize="true" height="338" header="show"]
8 *
9 * @package Jetpack
10 */
11
12 /**
13 * Display the Wufoo shortcode.
14 *
15 * @param array $atts Shortcode attributes.
16 */
17 function wufoo_shortcode( $atts ) {
18 $attr = shortcode_atts(
19 array(
20 'username' => '',
21 'formhash' => '',
22 'autoresize' => true,
23 'height' => '500',
24 'header' => 'show',
25 ),
26 $atts
27 );
28
29 // Check username and formhash to ensure they only have alphanumeric characters or underscores, and aren't empty.
30 if (
31 ! preg_match( '/^[a-zA-Z0-9_]+$/', $attr['username'] )
32 || ! preg_match( '/^[a-zA-Z0-9_]+$/', $attr['formhash'] )
33 ) {
34 /*
35 * Return an error to the users with instructions if one of these params is invalid
36 * They don't have default values because they are user/form-specific
37 */
38 if ( current_user_can( 'edit_posts' ) ) {
39 return sprintf(
40 wp_kses(
41 /* translators: URL to Wufoo support page. */
42 __( 'Something is wrong with your Wufoo shortcode. Try following the instructions <a href="%s" target="_blank" rel="noopener noreferrer">here</a> to embed a form on your site.', 'jetpack' ),
43 array(
44 'a' => array(
45 'href' => array(),
46 'target' => array(),
47 'rel' => array(),
48 ),
49 )
50 ),
51 'https://help.wufoo.com/articles/en_US/kb/Embed'
52 );
53 }
54 }
55
56 /**
57 * Placeholder which will tell Wufoo where to render the form.
58 */
59 $js_embed_placeholder = sprintf(
60 '<div id="wufoo-%s"></div>',
61 esc_attr( $attr['formhash'] )
62 );
63
64 /**
65 * Required parameters are present.
66 * An error will be returned inside the form if they are invalid.
67 */
68 $js_embed = sprintf(
69 '(function(){try{var wufoo_%1$s = new WufooForm();wufoo_%1$s.initialize({"userName":"%2$s","formHash":"%1$s","autoResize":"%3$s","height":"%4$d","header":"%5$s","ssl":true,"async":true});wufoo_%1$s.display();}catch(e){}})();',
70 esc_attr( $attr['formhash'] ),
71 esc_attr( $attr['username'] ),
72 esc_attr( $attr['autoresize'] ),
73 absint( $attr['height'] ),
74 esc_js( $attr['header'] )
75 );
76
77 // Embed URL.
78 $embed_url = sprintf(
79 'https://%1$s.wufoo.com/embed/%2$s/',
80 $attr['username'],
81 $attr['formhash']
82 );
83
84 // Form URL.
85 $form_url = sprintf(
86 'https://%1$s.wufoo.com/forms/%2$s/',
87 $attr['username'],
88 $attr['formhash']
89 );
90
91 /*
92 * iframe embed, loaded inside <noscript> tags.
93 */
94 $iframe_embed = sprintf(
95 '<iframe height="%1$d" src="%2$s" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none;">
96 <a href="%3$s" target="_blank" rel="noopener noreferrer">%4$s</a>
97 </iframe>',
98 absint( $attr['height'] ),
99 esc_url( $embed_url ),
100 esc_url( $form_url ),
101 esc_html__( 'Fill out my Wufoo form!', 'jetpack' )
102 );
103
104 wp_enqueue_script(
105 'wufoo-form',
106 'https://www.wufoo.com/scripts/embed/form.js',
107 array(),
108 JETPACK__VERSION,
109 true
110 );
111 wp_add_inline_script( 'wufoo-form', $js_embed );
112
113 /** This action is already documented in modules/widgets/gravatar-profile.php */
114 do_action( 'jetpack_stats_extra', 'embeds', 'wufoo' );
115
116 /**
117 * Return embed in JS and iframe.
118 */
119 return "$js_embed_placeholder<noscript>$iframe_embed</noscript>";
120 }
121 add_shortcode( 'wufoo', 'wufoo_shortcode' );
122