Passed
Push — master ( 7d9b6d...4cdb09 )
by
unknown
07:12 queued 03:23
created

enqueueWpcf7Scripts()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 34
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 19
nc 8
nop 0
dl 0
loc 34
rs 9.3222
c 0
b 0
f 0
1
<?php
2
3
namespace Flynt\Components\FormContactForm7;
4
5
use Flynt\Api;
6
7
add_filter('wpcf7_load_js', '__return_false');
8
add_filter('wpcf7_load_css', '__return_false');
9
10
add_filter('Flynt/addComponentData?name=FormContactForm7', function ($data) {
11
    function_exists('wpcf7_enqueue_scripts') && enqueueWpcf7Scripts();
12
    function_exists('wpcf7_enqueue_styles') && wpcf7_enqueue_styles();
13
14
    return $data;
15
});
16
17
function enqueueWpcf7Scripts()
18
{
19
    $inFooter = true;
20
21
    if ('header' === wpcf7_load_js()) {
22
        $inFooter = false;
23
    }
24
25
    wp_enqueue_script(
26
        'contact-form-7',
27
        wpcf7_plugin_url('includes/js/scripts.js'),
28
        ['Flynt/assets'],
29
        WPCF7_VERSION,
0 ignored issues
show
Bug introduced by
The constant Flynt\Components\FormContactForm7\WPCF7_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
        $inFooter
31
    );
32
33
    $wpcf7 = [
34
        'apiSettings' => [
35
            'root' => esc_url_raw(rest_url('contact-form-7/v1')),
36
            'namespace' => 'contact-form-7/v1',
37
        ],
38
    ];
39
40
    if (defined('WP_CACHE') and WP_CACHE) {
41
        $wpcf7['cached'] = 1;
42
    }
43
44
    if (wpcf7_support_html5_fallback()) {
0 ignored issues
show
Bug introduced by
The function wpcf7_support_html5_fallback was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
    if (/** @scrutinizer ignore-call */ wpcf7_support_html5_fallback()) {
Loading history...
45
        $wpcf7['jqueryUi'] = 1;
46
    }
47
48
    wp_localize_script('contact-form-7', 'wpcf7', $wpcf7);
49
50
    do_action('wpcf7_enqueue_scripts');
51
}
52
53
remove_action('wpcf7_init', 'wpcf7_add_form_tag_submit', 10, 0);
0 ignored issues
show
Unused Code introduced by
The call to remove_action() has too many arguments starting with 0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
/** @scrutinizer ignore-call */ 
54
remove_action('wpcf7_init', 'wpcf7_add_form_tag_submit', 10, 0);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
54
55
add_action('wpcf7_init', function () {
56
    wpcf7_add_form_tag('submit', function ($tag) {
0 ignored issues
show
Bug introduced by
The function wpcf7_add_form_tag was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
    /** @scrutinizer ignore-call */ 
57
    wpcf7_add_form_tag('submit', function ($tag) {
Loading history...
57
        $class = wpcf7_form_controls_class($tag->type, 'button');
0 ignored issues
show
Bug introduced by
The function wpcf7_form_controls_class was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $class = /** @scrutinizer ignore-call */ wpcf7_form_controls_class($tag->type, 'button');
Loading history...
58
59
        $atts = [];
60
61
        $atts['class'] = $tag->get_class_option($class);
62
        $atts['id'] = $tag->get_id_option();
63
        $atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true);
64
65
        $value = isset($tag->values[0]) ? $tag->values[0] : '';
66
67
        if (empty($value)) {
68
            $value = __('Send', 'contact-form-7');
69
        }
70
71
        $atts['type'] = 'submit';
72
        $atts['value'] = $value;
73
74
        $atts = wpcf7_format_atts($atts);
0 ignored issues
show
Bug introduced by
The function wpcf7_format_atts was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        $atts = /** @scrutinizer ignore-call */ wpcf7_format_atts($atts);
Loading history...
75
76
        $html = sprintf('<button %1$s>%2$s</button>', $atts, $value);
77
        return $html;
78
    });
79
}, 10, 0);
80
81
Api::registerFields('FormContactForm7', [
82
    'layout' => [
83
        'name' => 'FormContactForm7',
84
        'label' => 'Form: Contact Form 7',
85
        'sub_fields' => [
86
            [
87
                'label' => 'General',
88
                'name' => 'Tab',
89
                'type' => 'tab',
90
                'placement' => 'top',
91
                'endpoint' => 0
92
            ],
93
            [
94
                'name' => 'preContentHtml',
95
                'label' => 'Pre-Content',
96
                'type' => 'wysiwyg',
97
                'delay' => 1,
98
                'media_upload' => 0,
99
                'toolbar' => 'full',
100
                'wrapper' => [
101
                    'class' => 'autosize',
102
                ]
103
            ],
104
            [
105
                'label' => 'Contact Form 7 Form',
106
                'name' => 'formId',
107
                'type' => 'post_object',
108
                'post_type' => [
109
                    'wpcf7_contact_form'
110
                ],
111
                'allow_null' => 0,
112
                'multiple' => 0,
113
                'return_format' => 'id',
114
                'ui' => 1,
115
                'required' => 1,
116
                'instructions' => 'If there is no form available, please first create a suitable one in the <a href="' . admin_url('admin.php?page=wpcf7') . '" target="_blank">Contact Form 7 admin page</a>.',
117
            ],
118
            [
119
                'name' => 'contentFooterHtml',
120
                'label' => 'Content Footer',
121
                'type' => 'wysiwyg',
122
                'delay' => 1,
123
                'media_upload' => 0,
124
                'toolbar' => 'full',
125
                'required' => 0,
126
                'wrapper' => [
127
                    'class' => 'autosize',
128
                ]
129
            ],
130
            [
131
                'label' => 'Options',
132
                'name' => 'optionsTab',
133
                'type' => 'tab',
134
                'placement' => 'top',
135
                'endpoint' => 0
136
            ],
137
            [
138
                'label' => '',
139
                'name' => 'options',
140
                'type' => 'group',
141
                'layout' => 'row',
142
                'sub_fields' => [
143
                    array_merge(Api::loadFields('FieldVariables', 'theme'), array(
144
                        'default_value' => 'themeDark'
145
                    )),
146
                    [
147
                        'label' => 'Show as Card',
148
                        'name' => 'card',
149
                        'type' => 'true_false',
150
                        'default_value' => 1,
151
                        'ui' => 1
152
                    ]
153
                ]
154
            ],
155
            [
156
                'label' => 'Form Examples',
157
                'name' => 'templateTab',
158
                'type' => 'tab',
159
                'placement' => 'top',
160
                'endpoint' => 0
161
            ],
162
            [
163
                'label' => '',
164
                'name' => 'template',
165
                'type' => 'message',
166
                'message' => '
167
<pre>
168
<h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Form Newsletter</h4> '.htmlspecialchars('
169
<div class="form-flex">
170
  <div class="form-flex-col">
171
    [email* your-email placeholder "Enter your email"]
172
  </div>
173
  <div class="form-flex-col">
174
    [submit "Submit"]
175
  </div>
176
</div>
177
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Simple field</h4> '.htmlspecialchars('
178
<div class="form-group">
179
    <label for="yourCompany">Company</label>
180
    [text* your-company id:yourCompany placeholder "bleech"]
181
</div>
182
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Two columns row</h4> '.htmlspecialchars('
183
<div class="form-row-2">
184
    <div class="form-group">
185
        <label for="firstName">First Name</label>
186
        [text* first-name id:firstName placeholder "Dean"]
187
    </div>
188
    <div class="form-group">
189
        <label for="lastName">Last Name</label>
190
        [text* last-name id:lastName placeholder "Winchester"]
191
    </div>
192
</div>
193
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Three columns row</h4> '.htmlspecialchars('
194
<div class="form-row-3">
195
    <div class="form-group">
196
        <label for="firstName">First Name</label>
197
        [text* first-name id:firstName placeholder "Dean"]
198
    </div>
199
    <div class="form-group">
200
        <label for="lastName">Last Name</label>
201
        [text* last-name id:lastName placeholder "Winchester"]
202
    </div>
203
    <div class="form-group">
204
        <label for="yourEmail">Email</label>
205
        [email* your-email id:yourEmail placeholder "[email protected]"]
206
    </div>
207
</div>
208
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Two columns row (left column bigger than right)</h4> '.htmlspecialchars('
209
<div class="form-row-2-lg-left">
210
    <div class="form-group">
211
        <label for="yourAddress">Address</label>
212
        [text address id:yourAddress placeholder "Panoramastraße 1A"]
213
    </div>
214
    <div class="form-group">
215
        <label for="zipCode">Zip Code</label>
216
        [number zipcode id:zipCode placeholder "10178"]
217
    </div>
218
</div>
219
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Two columns row (right column bigger than left)</h4> '.htmlspecialchars('
220
<div class="form-row-2-lg-right">
221
    <div class="form-group">
222
        <label for="phoneCode">Code</label>
223
        [select menu-phone-code id:phoneCode "+345" "+44" "+7" "+49"]
224
    </div>
225
    <div class="form-group">
226
        <label for="mobilePhone">Phone Number</label>
227
        [tel mobile-phone id:mobilePhone placeholder "767-3842"]
228
    </div>
229
</div>
230
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Textarea</h4> '.htmlspecialchars('
231
<div class="form-group">
232
    <label for="yourMessage">Your Message</label>
233
    [textarea your-message id:yourMessage placeholder "Message here"]
234
</div>
235
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">URL field</h4> '.htmlspecialchars('
236
<div class="form-group">
237
    <label for="yourWebsite">Website</label>
238
    [url website id:yourWebsite placeholder "http://"]
239
</div>
240
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Date field</h4> '.htmlspecialchars('
241
<div class="form-group">
242
    <label for="yourDate">Date</label>
243
    [date date id:yourDate]
244
</div>
245
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Checkbox</h4> '.htmlspecialchars('
246
<div class="form-group">
247
    [checkbox checkbox-555 use_label_element "some " "another" "else"]
248
</div>
249
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Radio</h4> '.htmlspecialchars('
250
<div class="form-group">
251
    [radio radio-647 default:1 use_label_element "some " "else" "another"]
252
</div>
253
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Acceptance</h4> '.htmlspecialchars('
254
<div class="form-group">
255
    [acceptance acceptance-782 use_label_element optional]
256
        By default, an acceptance checkbox is a different mechanism than
257
        general input validation, and it runs after all validation succeeds.
258
    [/acceptance]
259
</div>
260
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Quiz field</h4> '.htmlspecialchars('
261
<div class="form-group label-wrap">
262
    [quiz quiz-413 "1+1=?|1" "1+2=?|3" "1+3=?|4"]
263
</div>
264
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">File field</h4> '.htmlspecialchars('
265
<div class="form-group">
266
    [file file-838]
267
</div>
268
').' <h4 style="color: #ca4a1f;margin-bottom:0;font-size: 14px;">Submit button</h4> '.htmlspecialchars('
269
<div class="form-button">
270
    [submit "Send Message"]
271
</div>
272
').'
273
</pre>
274
                ',
275
                'new_lines' => 'wpautop',
276
                'esc_html' => 0
277
            ],
278
        ]
279
    ]
280
]);
281