Making WordPress.org

Changeset 698


Ignore:
Timestamp:
06/12/2014 06:55:47 PM (12 years ago)
Author:
iandunn
Message:

WordCamp Forms to Drafts: Add Call for Sponsors handler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-forms-to-drafts/wordcamp-forms-to-drafts.php

    r642 r698  
    1212}
    1313
     14/*
     15 * @todo
     16 * - Refactor the update_post_meta() loop in each method into a DRY function.
     17 */
     18
    1419class WordCamp_Forms_To_Drafts {
    1520        /**
     
    1924                add_action( 'grunion_pre_message_sent', array( $this, 'returning_organizer_application' ), 10, 3 );
    2025                add_action( 'grunion_pre_message_sent', array( $this, 'new_organizer_application' ), 10, 3 );
     26                add_action( 'grunion_pre_message_sent', array( $this, 'call_for_sponsors' ), 10, 3 );
    2127        }
    2228
     
    174180                restore_current_blog();
    175181        }
     182
     183        /**
     184         * Create a draft Sponsor post from a Call for Sponsors form submission.
     185         *
     186         * @todo
     187         * - Add jetpack form field for Sponsor Level, where options are automatically pulled from wcb_sponsor_level
     188         *   taxonomy and the selected term is applied to the drafted post. Maybe need to send PR to add filter to
     189         *   insert custom fields programmatically.
     190         * - Sideload the logo from submitted URL and set it as the featured image.
     191         *
     192         * @param int   $submission_id
     193         * @param array $all_values
     194         * @param array $extra_values
     195         */
     196        public function call_for_sponsors( $submission_id, $all_values, $extra_values ) {
     197                if ( 'call-for-sponsors' != $this->get_form_key( $submission_id ) ) {
     198                        return;
     199                }
     200
     201                $sponsor_to_form_key_map = array(
     202                        '_wcpt_sponsor_website' => 'Website',
     203                );
     204
     205                $this->simulate_post_type( 'wordcamp' );
     206
     207                // Create the post
     208                $draft_id = wp_insert_post( array(
     209                        'post_type'    => 'wcb_sponsor',
     210                        'post_title'   => $all_values['Company name'],
     211                        'post_content' => $all_values['Company description'],
     212                        'post_status'  => 'draft',
     213                        'post_author'  => $this->get_user_id_from_username( 'wordcamp' ),
     214                ) );
     215
     216                // Create the post meta
     217                if ( $draft_id ) {
     218                        foreach ( $sponsor_to_form_key_map as $sponsor_key => $form_key ) {
     219                                if ( ! empty( $all_values[ $form_key ] ) ) {
     220                                        update_post_meta( $draft_id, $sponsor_key, $all_values[ $form_key ] );
     221                                }
     222                        }
     223                }
     224        }
    176225} // end WordCamp_Forms_To_Drafts
    177226
Note: See TracChangeset for help on using the changeset viewer.