Skip to content

Commit

Permalink
Coming Soon: Use contact form attached to page instead of arbitrary o…
Browse files Browse the repository at this point in the history
…ne created in template.

There's a Grunion bug that prevents using arbitrary do_shortcode() calls: Automattic/jetpack#102


git-svn-id: https://meta.svn.wordpress.org/sites/trunk/wordcamp.org@386 74240141-8908-4e6f-9713-ba540dce6ec7


git-svn-id: https://github.com/WordPress/wordcamp.org.git@53 a64dc54a-4538-25e2-d9ce-ce57b7db7bff
  • Loading branch information
iandunn committed Feb 6, 2014
1 parent f3c4347 commit 522782b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
High priority:
wccsp_image_id
contact form bug
confirmation that contact form was sent
display dates
make work consistently with any theme
warn user that image preview won't update until they save settings
refactor get_contact_form_shortcode() once https://github.com/Automattic/jetpack/issues/102 is fixed


Medium priority:
add color pickers
update image preview after they pick new but before they save/refresh
customize image size in template
add admin notice if missing page w/ contact form or it's not published
contact form shortcode - lookup email from wordcamp cpt instead of admin email?
internationalize
any other TODOs in code
customize image size in template



Low priority:
styles
make responsive & mobile-first
make contact box align w/ right edge of intro text properly instead of workaround
contact form submitted to latest post url instead of current page (if on home page)
make dashes/underscores consistent in html element ids/names
make dashes/underscores consistent in html element ids/names

Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,45 @@ public function get_dates() {
}

/**
* Generate the contact form shortcode string
*
* @return string
* Retrieve the contact form shortcode string
*
* We can't just create an arbitrary shortcode because of https://github.com/Automattic/jetpack/issues/102. Instead we have to use a form that's tied to a page.
* This is somewhat fragile, though. It should work in most cases because the first $page that contains [contact-form] will be the one we automatically create
* when the site is created, but if the organizers delete that and then add multiple forms, the wrong form could be displayed. The alternative approaches also
* have problems, though, and #102 should be fixed relatively soon, so hopefully this will be good enough until it can be refactored.
* todo Refactor this once #102-jetpack is fixed.
*
* @return string|false
*/
public function get_contact_form_shortcode() {
$shortcode = sprintf(
"[contact-form to='%s' subject='%s contact request']
[contact-field label='Name' type='name' required='1' /]
[contact-field label='Email' type='email' required='1' /]
[contact-field label='Comment' type='textarea' required='1' /]
[/contact-form]",
get_bloginfo( 'name' ),
get_option( 'admin_email' )
);
$contact_form_shortcode = false;
$shortcode_regex = get_shortcode_regex();

$all_pages = get_posts( array(
'post_type' => 'page',
'post_status' => 'any',
'posts_per_page' => -1,
) );

foreach ( $all_pages as $page ) {
preg_match_all( '/' . $shortcode_regex . '/s', $page->post_content, $matches, PREG_SET_ORDER );

foreach ( $matches as $shortcode ) {
if ( 'contact-form' === $shortcode[2] ) {
global $post;
$post = $page;
setup_postdata( $post );

ob_start();
echo do_shortcode( $shortcode[0] );
$contact_form_shortcode = ob_get_clean();

wp_reset_postdata();
break;
}
}
}

return $shortcode;
return $contact_form_shortcode;
}
} // end WordCamp_Coming_Soon_Page
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="wccsp-box">
<h2>Contact the Organizers</h2>

<?php echo do_shortcode( $contact_form_shortcode ); ?>
<?php echo $contact_form_shortcode; ?>
</div>
<?php endif; ?>

Expand Down

0 comments on commit 522782b

Please sign in to comment.