Making WordPress.org

Changeset 386


Ignore:
Timestamp:
02/06/2014 11:26:14 PM (13 years ago)
Author:
iandunn
Message:

Coming Soon: Use contact form attached to page instead of arbitrary one created in template.

There's a Grunion bug that prevents using arbitrary do_shortcode() calls: ​https://github.com/Automattic/jetpack/issues/102

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/TODO.txt

    r383 r386  
    11High priority:
    2         wccsp_image_id
    32        contact form bug
    43                confirmation that contact form was sent
    … …  
    65        make work consistently with any theme
    76        warn user that image preview won't update until they save settings
     7        refactor get_contact_form_shortcode() once https://github.com/Automattic/jetpack/issues/102 is fixed
    88       
    99       
    … …  
    1111        add color pickers
    1212        update image preview after they pick new but before they save/refresh
    13         customize image size in template
     13        add admin notice if missing page w/ contact form or it's not published
    1414        contact form shortcode - lookup email from wordcamp cpt instead of admin email?
    1515        internationalize
    1616        any other TODOs in code
     17        customize image size in template
    1718       
    18                        
     19       
    1920Low priority:
    2021        styles
    … …  
    2324        contact form submitted to latest post url instead of current page (if on home page)
    2425        make dashes/underscores consistent in html element ids/names
     26       
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/classes/wordcamp-coming-soon-page.php

    r381 r386  
    137137
    138138        /**
    139          * Generate the contact form shortcode string
    140          *
    141          * @return string
     139         * Retrieve the contact form shortcode string
     140         *
     141         * 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.
     142         * 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
     143         * 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
     144         * have problems, though, and #102 should be fixed relatively soon, so hopefully this will be good enough until it can be refactored.
     145         * todo Refactor this once #102-jetpack is fixed.
     146         *       
     147         * @return string|false
    142148         */
    143149        public function get_contact_form_shortcode() {
    144                 $shortcode = sprintf(
    145                         "[contact-form to='%s' subject='%s contact request']
    146                                 [contact-field label='Name' type='name' required='1' /]
    147                                 [contact-field label='Email' type='email' required='1' /]
    148                                 [contact-field label='Comment' type='textarea' required='1' /]
    149                         [/contact-form]",
    150                         get_bloginfo( 'name' ),
    151                         get_option( 'admin_email' )
    152                 );
     150                $contact_form_shortcode = false;
     151                $shortcode_regex        = get_shortcode_regex();
    153152               
    154                 return $shortcode;
     153                $all_pages = get_posts( array(
     154                        'post_type'      => 'page',
     155                        'post_status'    => 'any',
     156                        'posts_per_page' => -1,
     157                ) );
     158               
     159                foreach ( $all_pages as $page ) {
     160                        preg_match_all( '/' . $shortcode_regex . '/s', $page->post_content, $matches, PREG_SET_ORDER );
     161
     162                        foreach ( $matches as $shortcode ) {
     163                                if ( 'contact-form' === $shortcode[2] ) {
     164                                        global $post;
     165                                        $post = $page;
     166                                        setup_postdata( $post );
     167                                       
     168                                        ob_start();
     169                                        echo do_shortcode( $shortcode[0] );
     170                                        $contact_form_shortcode = ob_get_clean();
     171                                       
     172                                        wp_reset_postdata();
     173                                        break;
     174                                }
     175                        }
     176                }
     177               
     178                return $contact_form_shortcode;
    155179        }
    156180} // end WordCamp_Coming_Soon_Page
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-coming-soon-page/views/template-coming-soon.php

    r383 r386  
    3737                                <h2>Contact the Organizers</h2>
    3838                               
    39                                 <?php echo do_shortcode( $contact_form_shortcode ); ?> 
     39                                <?php echo $contact_form_shortcode; ?>
    4040                        </div>
    4141                <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.