add_action('wpcf7_before_send_mail', 'send_mail');
function send_mail($form){
global $wpdb;
$submission = WPCF7_Submission::get_instance();
if ( $submission && 138 == $form->id() ) {
$form->skip_mail = true;
$submited = array();
$submited['title'] = $form->title();
$submited['posted_data'] = $submission->get_posted_data();
$uploadedFiles = $submission->uploaded_files();
$data_name = $submited['posted_data']['nm'];
$data_tel = $submited['posted_data']['tel'];
$data_mail = $submited['posted_data']['mail'];
$data_msg = $submited['posted_data']['msg'];
}
$new_post = array(
'post_title' => 'Отзыв о леcтнице',
'post_type'=>'review',
'post_status'=>'draft',
'post_content'=>$data_msg
);
$post_id = wp_insert_post($new_post);
if ($post_id) {
if ($data_name) update_field('reviews_name',$data_name,$post_id);
if ($data_tel) update_field('reviews_tel',$data_tel,$post_id);
if ($data_mail) update_field('reviews_email',$data_mail,$post_id);
$arrImg = array();
foreach ($uploadedFiles as $value) {
$file = $value;
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $post_id,
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $post_id );
if (!is_wp_error($attachment_id)) {
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
wp_update_attachment_metadata( $attachment_id, $attach_data );
$arrImg[] = $attachment_id;
}
}
}
if (count($arrImg) > 0) {
update_field('reviews_img', $arrImg, $post_id );
}
}
}
function get_contact_form_func( $atts ){
$out = 'Text';
return $out;
}
add_shortcode('get_contact_form', 'get_contact_form_func');
function custom_post_type() {
$labels = array(
'name' => _x( 'Портфолио', 'Post Type General Name', 'mytheme' ),
'singular_name' => _x( 'Портфолио', 'Post Type Singular Name', 'mytheme' ),
'menu_name' => __( 'Портфолио', 'mytheme' ),
'parent_item_colon' => __( 'Родит. Портфолио', 'mytheme' ),
'all_items' => __( 'Все Портфолио', 'mytheme' ),
'view_item' => __( 'Смотреть Портфолио', 'mytheme' ),
'add_new_item' => __( 'Добавить новою Портфолио', 'mytheme' ),
'add_new' => __( 'Добавить новою', 'mytheme' ),
'edit_item' => __( 'Редактировать Портфолио', 'mytheme' ),
'update_item' => __( 'Обновить Портфолио', 'mytheme' ),
'search_items' => __( 'Искать Портфолио', 'mytheme' ),
'not_found' => __( 'Не найдено', 'mytheme' ),
'not_found_in_trash' => __( 'Не найдено в корзине', 'mytheme' ),
);
$args = array(
'label' => __( 'Портфолио', 'mytheme' ),
'description' => __( '', 'mytheme' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', ),
'taxonomies' => array(),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'portfolio', $args );
}
add_action( 'init', 'custom_post_type', 0 );