Advertisement
Guest User

Contact Form 7 Extender

a guest
Feb 22nd, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.87 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Contact Form 7 Extender
  4.  * Description: This plugin saves input data from a form to the database.
  5.  * Version: 1.1
  6.  * Author: Marcus Thienert, Marco Gajardo
  7.  */
  8.  
  9. add_action('wpcf7_before_send_mail', 'createPostData' );
  10.  
  11. function createPostData() {
  12.          //get user id
  13.          //$user = get_userdatabylogin('myusername');
  14.          //$user = get_user_by('login', $user_login);
  15.          //$udi = $user->ID;
  16.  
  17.          get_currentuserinfo();
  18.  
  19.          if ($_POST['aut'] == '') {
  20.                  // Create post object
  21.                  $my_post = array(
  22.                          'post_title' => $_POST['title'],
  23.                          'post_content' => $_POST['Description'],
  24.                          'post_status' => 'pending',
  25.                          'post_author' => 3,
  26.                          'post_category' => array($_POST['postcategory'])
  27.                  );
  28.          } else {
  29.                  $my_post = array(
  30.                          'post_title' => $_POST['title'],
  31.                          'post_content' => $_POST['Description'],
  32.                          'post_status' => 'publish',
  33.                          //'post_author' => $user,
  34.                          'post_author' => $user_ID,
  35.                          'post_category' => array($_POST['postcategory'])
  36.                  );
  37.          }
  38.  
  39.          //Insert the post into the database
  40.          $post_id = wp_insert_post( $my_post );
  41.  
  42.          //Delete Date-Conf not Req.
  43.          if ($_POST['Earlydate'] == date('Y-m-d')) {
  44.                  $_POST['Earlydate'] = "";
  45.          }
  46.          if ($_POST['Abstractdate'] == date('Y-m-d')) {
  47.                  $_POST['Abstractdate'] = "";
  48.          }
  49.          if ($_POST['Regdate'] == date('Y-m-d')) {
  50.                  $_POST['Regdate'] = "";
  51.          }
  52.  
  53.          //insert postmeta:
  54.          update_post_meta($post_id, 'location', $_POST['location']);
  55.          update_post_meta($post_id, 'date_start', $_POST['Startdate']);
  56.          update_post_meta($post_id, 'date_end', $_POST['Enddate']);
  57.          update_post_meta($post_id, 'email', $_POST['email-Contact']);
  58.          update_post_meta($post_id, 'url', $_POST['URL']);
  59.          update_post_meta($post_id, 'date_registration', $_POST['Regdate']);
  60.          update_post_meta($post_id, 'date_early_registration', $_POST['Earlydate']);
  61.          update_post_meta($post_id, 'date_abstract_deadline', $_POST['Abstractdate']);
  62.          update_post_meta($post_id, 'date_deadline', $_POST['JobDate']);
  63.  
  64.          //insert tags to database
  65.          $tagarray = explode(",",trim($_POST['Tagsconference']));
  66.          wp_set_post_tags($post_id, $tagarray);
  67.  
  68.          //insert categories
  69.          $post_categories = array ();
  70.          $post_categories[4] = 'conferences';
  71.          $postid = (int)$post_ID;
  72.          wp_set_post_categories( $postID, $post_categories[4]);
  73.  
  74.         return;
  75. }
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement