PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.3
Jetpack – WP Security, Backup, Speed, & Growth v12.3
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 12.3, at modules/shortcodes/wufoo.php

124 lines 3.4 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 automattic/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 return;
56 }
57
58 /**
59 * Placeholder which will tell Wufoo where to render the form.
60 */
61 $js_embed_placeholder = sprintf(
62 '<div id="wufoo-%s"></div>',
63 esc_attr( $attr['formhash'] )
64 );
65
66 /**
67 * Required parameters are present.
68 * An error will be returned inside the form if they are invalid.
69 */
70 $js_embed = sprintf(
71 '(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){}})();',
72 esc_attr( $attr['formhash'] ),
73 esc_attr( $attr['username'] ),
74 'true' == $attr['autoresize'] ? 'true' : 'false', // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
75 absint( $attr['height'] ),
76 'show' === $attr['header'] ? 'show' : 'hide'
77 );
78
79 // Embed URL.
80 $embed_url = sprintf(
81 'https://%1$s.wufoo.com/embed/%2$s/',
82 $attr['username'],
83 $attr['formhash']
84 );
85
86 // Form URL.
87 $form_url = sprintf(
88 'https://%1$s.wufoo.com/forms/%2$s/',
89 $attr['username'],
90 $attr['formhash']
91 );
92
93 /*
94 * iframe embed, loaded inside <noscript> tags.
95 */
96 $iframe_embed = sprintf(
97 '<iframe height="%1$d" src="%2$s" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%%;border:none;">
98 <a href="%3$s" target="_blank" rel="noopener noreferrer">%4$s</a>
99 </iframe>',
100 absint( $attr['height'] ),
101 esc_url( $embed_url ),
102 esc_url( $form_url ),
103 esc_html__( 'Fill out my Wufoo form!', 'jetpack' )
104 );
105
106 wp_enqueue_script(
107 'wufoo-form',
108 'https://www.wufoo.com/scripts/embed/form.js',
109 array(),
110 JETPACK__VERSION,
111 true
112 );
113 wp_add_inline_script( 'wufoo-form', $js_embed );
114
115 /** This action is already documented in modules/widgets/gravatar-profile.php */
116 do_action( 'jetpack_stats_extra', 'embeds', 'wufoo' );
117
118 /**
119 * Return embed in JS and iframe.
120 */
121 return "$js_embed_placeholder<noscript>$iframe_embed</noscript>";
122 }
123 add_shortcode( 'wufoo', 'wufoo_shortcode' );
124