shprics.php 5.06 KB
<?php 
function fenix_shprics ($atts, $content)
    {
        $atts = shortcode_atts(
            array(
                'post'  => '',
                'id'    => ''
            ),
            $atts,
            'fenix_shprics'
        );

        $out = '';
        if ($atts['post']!=='')
            {
                $args = array(
                    'numberposts'   => 1,
                    'post__in'      => array($atts['post']),
                    'order'         => 'ASC',
                    'limit'         => 1
                );
                $posts = get_posts($args);
                foreach($posts as $key=>$post)
                    {   
                        $out = ''.
                            '<!--Шприцы-->'.
                            '<div id="'.$atts['id'].'" class="fenix-shprics"'.(has_post_thumbnail($post->ID)?' style="background-image: url('.get_the_post_thumbnail_url($post->ID, 'full').');"':'').'>'.
                                '<div class="container text-color-1">'.
                                    '<div class="row">'.
                                        '<div class="col-12 col-md-6 text-md-start">'.
                                            '<div class="info">'.
                                                '<div class="caption mb-md-4">'.($post->post_excerpt===''?$post->post_title:$post->post_excerpt).'</div>'.
                                                '<div class="description">'.$post->post_content.'</div>'.
                                            '</div>'.
                                        '</div>'.
                                        '<div class="col-12 col-md-6 text-md-end">';

                                  
								$args = array(
									'id_form'=>'form_'.$atts['id'],
									'fields'=>array(
										'author' => '<div class="mb-3">'.
											'<label for="author_'.$atts['id'].'" class="form-label">Ваше имя</label>'.
                                            '<input type="text" class="form-control form-control-lg rounded-4 border-0" name="author" id="author_'.$atts['id'].'" value="" size="30" required/>'.
											'<div class="invalid-feedback">Пожалуйста, укажите Ваше имя</div>'.
										'</div>',
										'phone' => '<div class="mb-5">'.
                                            '<label for="phone_'.$atts['id'].'" class="form-label">Телефон</label>'.
											'<input type="text" class="form-control form-control-lg rounded-4 border-0" name="phone" id="phone_'.$atts['id'].'" value="" required />'.
											'<div class="invalid-feedback">Пожалуйста, укажите телефон</div>'.
										'</div>',
										'cookies' => '<div class="mb-5 form-check ps-0">'.
											'<input type="checkbox" name="accept" class="form-check-input d-none" id="accept_'.$atts['id'].'" value="accept" required="required" checked="checked"/>'.
											'<label class="form-check-label" for="accept_'.$atts['id'].'">Согласен на обработку<br/> персональных данных</label>'.
											'<div class="invalid-feedback">Вы должны принять перед отправкой</div>'.
										'</div>'
									),
									'comment_field' => '<input type="hidden" name="comment" id="comment_'.$atts['id'].'" value="'.time().'"/>',
                                    'class_submit'=>'btn btn-lg btn-style-1 rounded-pill mx-auto w-100',
                                    'submit_field'=>'%1$s %2$s',
									'submit_button'=> '<button name="%1$s" type="submit" class="%3$s" value="%4$s" id="%2$s">Отправить заявку</button>',
                                    'id_submit'=>'submit_'.$atts['id'],
									'comment_notes_before' => '<div class="text-center mb-5 caption">Обратная связь</div>',
									'title_reply'=> ''.
										'<div class="form-preloader align-items-center justify-content-center d-flex d-none text-center position-absolute top-0 bottom-0 start-0 end-0 m-auto" style="z-index:1; background-color: rgba(255,255,255,0.8)">'.
											'<div class="spinner-border" role="status">'.
												'<span class="visually-hidden">Обработка...</span>'.
											'</div>'.
										'</div>',
                                    'title_reply'=>'',
                                    'title_reply_before'=>'',
                                    'title_reply_after'=>'',    
									'class_form'=>'needs-validation text-start mx-auto me-md-0 rounded-4 text-color-1 bg-custom-9 shadow-2 ajax-submit'
								);
                                ob_start();
                                comment_form($args, url_to_postid('main'));
                                $out.=ob_get_clean();
                                $out.= ''. 
                                        '</div>'.
                                    '</div>'.
                                '</div>'.
                            '</div>';
                    }
                wp_reset_postdata();

                unset($key, $post, $posts, $args);
            }
        return $out;
    }
add_shortcode('fenix_shprics', 'fenix_shprics');