Ticket #567: meta-567.patch
File meta-567.patch, 8.7 KB (added by , 9 years ago) |
---|
-
public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-new-site.php
8 8 */ 9 9 public function __construct() { 10 10 $this->new_site_id = false; 11 11 12 12 add_action( 'wcpt_metabox_value', array( $this, 'render_site_url_field' ), 10, 3 ); 13 13 add_action( 'wcpt_metabox_save', array( $this, 'save_site_url_field' ), 10, 3 ); 14 14 } … … 367 367 368 368 array( 369 369 'title' => 'Call for Speakers', 370 'content' => "<p><em>Organizers note:</em> Make sure you update the 'to' address and other fields before publishing this page!</p> <p>Blurb with information for potential speakers.</p> <p>[contact-form to='enter-your-address-here@example.net' subject='WordCamp Speaker Request'] [contact-field label='Name' type='text' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Topic(s) You%26#039;d Like to Present On' type='textarea' required='1'/][contact-field label='Intended Audience' type='text' required='1'/][contact-field label='Past Speaking Experience (not necessary to apply)' type='textarea'/][/contact-form]</p>",370 'content' => "<p><em>Organizers note:</em> Make sure you update the 'to' address and other fields before publishing this page!</p> <p>Blurb with information for potential speakers.</p> <p>[contact-form to='enter-your-address-here@example.net' subject='WordCamp Speaker Request']<h3>Speaker Information</h3>[contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='WordPress.org UserName' id='wporg_username' type='text' required='1'/][contact-field label='Your Bio' type='textarea' required='1'/]<h3>Session Information</h3>[contact-field label='Topic Title' type='text' required='1'/][contact-field label='Topic(s) You%26#039;d Like to Present On' type='textarea' required='1'/][contact-field label='Intended Audience' type='text' required='1'/][contact-field label='Past Speaking Experience (not necessary to apply)' type='textarea'/][/contact-form]</p>", 371 371 'status' => 'draft', 372 372 'type' => 'post', 373 373 ), -
public_html/wp-content/plugins/wordcamp-forms-to-drafts/wordcamp-forms-to-drafts.php
24 24 add_action( 'grunion_pre_message_sent', array( $this, 'returning_organizer_application' ), 10, 3 ); 25 25 add_action( 'grunion_pre_message_sent', array( $this, 'new_organizer_application' ), 10, 3 ); 26 26 add_action( 'grunion_pre_message_sent', array( $this, 'call_for_sponsors' ), 10, 3 ); 27 add_action( 'grunion_pre_message_sent', array( $this, 'call_for_speakers' ), 10, 3 ); 28 add_filter( 'the_content', array( $this, 'check_call_for_speakers_for_login' ), 9 ); 27 29 } 28 30 29 31 /** 32 * if user is not logged in, replace form with login request message 33 * if user is logged in, stick usernsme in _POST for form utilization 34 * 35 * @uses is_user_logged_in 36 * 37 */ 38 public function check_call_for_speakers_for_login( $content ) { 39 $form_pattern = '/\[contact-form[\D\S]+\[\/contact-form\]/'; 40 if ( ! is_user_logged_in() ) { 41 $title = get_the_title(); 42 switch ( $title ) { 43 case 'Call for Speakers': 44 $please_login_message = sprintf( __( 'Before submitting your speaker proposal, please <a href="%s">log into you WordPress.org account</a>*.', 'wordcamporg' ), wp_login_url( get_permalink() ) ); 45 break; 46 47 default: 48 break; 49 } 50 51 if ( ! empty( $please_login_message ) ) { 52 $content = preg_replace( $form_pattern, $please_login_message, $content ); 53 } 54 55 } else { 56 global $current_user; 57 get_currentuserinfo(); 58 59 $_POST['wporg_username'] = $current_user->user_login; 60 } 61 62 return $content; 63 } 64 65 /** 30 66 * Identify the form that the submission is associated with. 31 67 * 32 68 * This requires that the post containing the [contact-form] shortcode has a meta field named 'wcfd-key' added … … 38 74 protected function get_form_key( $submission_id ) { 39 75 $key = false; 40 76 $submission = get_post( $submission_id ); 41 42 77 if ( ! empty( $submission->post_parent ) ) { 43 78 $key = get_post_meta( $submission->post_parent, 'wcfd-key', true ); 44 79 } … … 58 93 } 59 94 60 95 /** 96 * Get speaker post ID based on WP.org user name 97 * 98 * @param int $user_id 99 * @return obj | 0 100 */ 101 protected function get_speaker_from_userid( $user_id ) { 102 103 $speaker_check_args = array( 104 'post_type' => 'wcb_speaker', 105 'posts_per_page' => 1, 106 'post_status' => 'all', 107 'meta_query' => array( 108 array( 109 'key' => '_wcpt_user_id', 110 'value' => $user_id, 111 'compare' => '=', 112 ), 113 ), 114 ); 115 116 $speaker_query = new WP_Query( $speaker_check_args ); 117 wp_reset_postdata(); 118 return empty( $speaker_query->post ) ? 0 : $speaker_query->post; 119 120 } 121 122 /** 61 123 * Simulate the existence of a post type. 62 124 * 63 125 * This plugin may need to insert a form into a different site, and the targeted post type may not be active … … 222 284 } 223 285 } 224 286 } 287 288 /** 289 * Create draft Speaker and Session posts from a Call for Speakers form submission. 290 * 291 * @todo 292 * - For this to intercept the form the post meta 'wcfd-key' has to have a value of 'call-for-speakers' 293 * - Add jetpack form field for Track, where options are automatically pulled from wcb_track 294 * taxonomy and the selected term(s) is applied to the drafted post. 295 * - Put form behind required login and pre-populate the username field - works but hacky 296 * - Make the speaker the author of their session. May have to add the speaker as an author 297 * if their session is approved. 298 * 299 * @param int $submission_id 300 * @param array $all_values 301 * @param array $extra_values 302 */ 303 public function call_for_speakers( $submission_id, $all_values, $extra_values ) { 304 305 global $current_user; 306 get_currentuserinfo(); 307 308 if ( 'call-for-speakers' != $this->get_form_key( $submission_id ) ) { 309 return; 310 } 311 312 // process the speaker part of the form 313 314 // check for existing speaker entry 315 $all_values['UserID'] = $this->get_user_id_from_username( $current_user->user_login ); 316 $speaker_obj = $this->get_speaker_from_userid( $all_values['UserID'] ); 317 318 $this->simulate_post_type( 'wordcamp' ); 319 320 if ( empty( $speaker_obj ) ) { 321 322 $speaker_to_form_key_map = array( 323 '_wcpt_speaker_website' => 'Website', 324 '_wcpt_speaker_twitter_handle' => 'Twitter Handle', 325 '_wcb_speaker_email' => 'Email', 326 '_wcpt_user_id' => 'UserID', 327 ); 328 329 // Create the speaker draft post 330 $speaker_draft_id = wp_insert_post( array( 331 'post_type' => 'wcb_speaker', 332 'post_title' => $all_values['Name'], 333 'post_content' => $all_values['Your Bio'], 334 'post_status' => 'draft', 335 'post_author' => $this->get_user_id_from_username( 'wordcamp' ), 336 ) ); 337 338 // Create the speaker post meta 339 if ( $speaker_draft_id ) { 340 foreach ( $speaker_to_form_key_map as $speaker_key => $form_key ) { 341 if ( ! empty( $all_values[ $form_key ] ) ) { 342 update_post_meta( $speaker_draft_id, $speaker_key, $all_values[ $form_key ] ); 343 } 344 } 345 } 346 $speaker_draft_title = $all_values['Name']; 347 348 } else { 349 $speaker_draft_id = $speaker_obj->ID; 350 $speaker_draft_title = $speaker_obj->post_title; 351 } 352 353 354 // process the session part of the form 355 356 // put the speaker draft id in all_values to allow saving to meta 357 $all_values['session_speaker_id'] = empty( $speaker_draft_id ) ? 0 : $speaker_draft_id; 358 $all_values['session_speaker_name'] = $speaker_draft_title . ','; 359 $session_to_form_key_map = array( 360 '_wcpt_speaker_id' => 'session_speaker_id', 361 '_wcb_session_speakers' => 'session_speaker_name', 362 ); 363 364 // Create the session draft post 365 $session_draft_id = wp_insert_post( array( 366 'post_type' => 'wcb_session', 367 'post_title' => $all_values['Topic Title'], 368 'post_content' => $all_values["Topic(s) You'd Like to Present On"], 369 'post_status' => 'draft', 370 'post_author' => $this->get_user_id_from_username( 'wordcamp' ), 371 ) ); 372 373 // Create the session post meta 374 if ( $session_draft_id ) { 375 foreach ( $session_to_form_key_map as $session_key => $form_key ) { 376 if ( ! empty( $all_values[ $form_key ] ) ) { 377 update_post_meta( $session_draft_id, $session_key, $all_values[ $form_key ] ); 378 } 379 } 380 } 381 382 } 383 225 384 } // end WordCamp_Forms_To_Drafts 226 385 227 386 $GLOBALS['wordcamp_forms_to_drafts'] = new WordCamp_Forms_To_Drafts();