css
2 years ago
images
2 years ago
img
2 years ago
js
2 years ago
archiveorg-book.php
5 years ago
archiveorg.php
5 years ago
archives.php
5 years ago
bandcamp.php
3 years ago
brightcove.php
5 years ago
cartodb.php
5 years ago
class.filter-embedded-html-objects.php
2 years ago
codepen.php
5 years ago
crowdsignal.php
2 years ago
dailymotion.php
3 years ago
descript.php
4 years ago
facebook.php
2 years ago
flatio.php
5 years ago
flickr.php
2 years ago
getty.php
2 years ago
gist.php
3 years ago
googleapps.php
2 years ago
googlemaps.php
2 years ago
googleplus.php
5 years ago
gravatar.php
2 years ago
houzz.php
5 years ago
inline-pdfs.php
4 years ago
instagram.php
3 years ago
kickstarter.php
3 years ago
mailchimp.php
3 years ago
medium.php
3 years ago
mixcloud.php
2 years ago
others.php
2 years ago
pinterest.php
2 years ago
presentations.php
2 years ago
quiz.php
4 years ago
recipe.php
2 years ago
scribd.php
5 years ago
sitemap.php
5 years ago
slideshare.php
5 years ago
slideshow.php
2 years ago
smartframe.php
3 years ago
soundcloud.php
3 years ago
spotify.php
2 years ago
ted.php
5 years ago
tweet.php
2 years ago
twitchtv.php
5 years ago
twitter-timeline.php
5 years ago
unavailable.php
3 years ago
untappd-menu.php
3 years ago
upcoming-events.php
3 years ago
ustream.php
5 years ago
videopress.php
4 years ago
vimeo.php
2 years ago
vine.php
5 years ago
vr.php
2 years ago
wordads.php
5 years ago
wufoo.php
3 years ago
youtube.php
1 year ago
wufoo.php
124 lines
| 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 |