| | 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 | /** |
| | 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 | |