garantii.php 4.52 KB
<?php 
function fenix_garantii ($atts)
    {
        $atts = shortcode_atts(
            array(
                'post'  => '',
                'id'    => ''
            ),
            $atts,
            'fenix_garantii'
        );

        $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)
                    {   
                        $args_form = array(
                            'id_form' => 'form_consult',
                            'fields'=>array(
                                'author'    =>  '<div class="mb-3">'.
                                                    '<label for="autor" class="form-label mb-3">Имя</label>'.
                                                    '<input type="text" class="form-control rounded-pill p-2 px-4" id="author" name="author" required="required" value="" size="30" />'.
                                                '</div>',
                                'phone'     =>  '<div class="mb-5">'.
                                                    '<label for="phone" class="form-label mb-3">Телефон</label>'.
                                                    '<input type="text" class="form-control rounded-pill p-2 px-4" id="phone" name="phone" required="required" value="" />'.
                                                '</div>',
                                'email'     =>  '<input type="hidden" name="email" id="email" value="email@'.$_SERVER['HTTP_HOST'].'" />',
                                'cookies'   =>  '<input type="hidden" name="accept" id="accept" value="accept" />'
                            ),
                            'comment_field'         => '<input type="hidden" id="comment" name="comment" value="" />',
                            
                            'label_submit'          => 'Получить консультацию',
                            'submit_button'         => '<button name="%1$s" type="submit" class="btn btn-lg btn-style-0 rounded-pill %3$s" role="submit" id="%2$s">%4$s</button>',
                            'comment_notes_before'  => '',
                            '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>',
                            'class_form'            => 'needs-validation needs-validation',
                            'title_reply_before'    => '',
                            'title_reply_after'     => ''
                        );
                        $out = ''.
                            '<!--Мы на 100% гарантируем-->'.
                            '<div id="'.$atts['id'].'" class="fenix_garantii shadow-sm">'.
                                '<div class="container">'.
                                    '<div class="row">'.
                                        '<div class="col-12 pt-3 pt-md-5">'.
                                            '<h1>'.$post->post_title.'</h1>'.
                                            $post->post_content.
                                            '<div class="position-relative">';
                                                ob_start();
                                                comment_form($args_form);
                                                $out.=ob_get_clean();
                        $out.= ''. 
                                            '</div>'. 
                                        '</div>'.
                                    '</div>'.
                                '</div>'.
                            '</div>';
                        unset($args_form);    
                    }
                wp_reset_postdata();
                unset($key, $post, $posts, $args);
            }
        return $out;
    }
add_shortcode('fenix_garantii', 'fenix_garantii');