I have two different plugins. My custom-post-type is on the first plugin and it has some meta boxes. Now in the second plugin, I extracted the email using IMAP and stored it in the post type of the first plugin.
In the below code the two variables ticket_username
and ticket_email
are inside a class.
for($i=1; $i<=imap_num_msg($this->conn); $i++) {
$res = imap_headerinfo($this->conn, $i);
$ticket_username = $res->fromaddress; //For username
$ticket_email = $res->from[0]->mailbox . "@" . $res->from[0]->host;// For E-mail.
}
I assigned the username and email from the email. Now I want this email and username to be inserted into my meta boxes along with the emails.
if(!function_exists('custom_meta_ticket_field_callback')){
function custom_meta_ticket_field_callback($post) {
wp_nonce_field( 'custom_ticket_metabox_nonce', 'faqpress_ticket_meta_fields_nonce' );
$ticket_username = get_post_meta( $post->ID, 'ticket_username', true );
$ticket_email = get_post_meta( $post->ID, 'ticket_email', true );
?>
<label for="custom_design"><h4><?php _e( 'Name', 'Custom' ); ?></h4></label>
<input type="text" id="" class="widefat" name="ticket_username" value="<?php echo esc_attr( $ticket_username ); ?>" size="25" readonly />
<label for="design"><h4><?php _e( 'Email', 'Custom' ); ?></h4></label>
<input type="email" id="" class="widefat" name="email" value="<?php echo esc_attr( $ticket_email ); ?>" size="25" readonly />
<?php
}
}
Note: The CPT and metabox are registered in a different plugin and the emails are extracted and stored in the CPT by another plugin.