1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
<?php if ( ! defined( 'ABSPATH' ) ) { die( '-1' ); }
/** * @param $attributes * @return bool * @throws \Exception */ function wpb_map( $attributes ) { return vc_map( $attributes ); }
/** * Lean map shortcodes * * @param $tag * @param null $settings_function * @param null $settings_file * @since 4.9 * */ function vc_lean_map( $tag, $settings_function = null, $settings_file = null ) { WPBMap::leanMap( $tag, $settings_function, $settings_file ); }
/** * @param $attributes * * @return bool * @throws \Exception * @since 4.2 */ function vc_map( $attributes ) { if ( ! isset( $attributes['base'] ) ) { throw new Exception( esc_html__( 'Wrong vc_map object. Base attribute is required', 'js_composer' ) ); }
return WPBMap::map( $attributes['base'], $attributes ); }
/** * @param $shortcode * * @since 4.2 */ function vc_remove_element( $shortcode ) { WPBMap::dropShortcode( $shortcode ); }
/** * Add new shortcode param. * * @param $shortcode - tag for shortcode * @param $attributes - attribute settings * @throws \Exception * @since 4.2 * */ function vc_add_param( $shortcode, $attributes ) { WPBMap::addParam( $shortcode, $attributes ); }
/** * Mass shortcode params adding function * * @param $shortcode - tag for shortcode * @param $attributes - list of attributes arrays * @throws \Exception * @since 4.3 * */ function vc_add_params( $shortcode, $attributes ) { if ( is_array( $attributes ) ) { foreach ( $attributes as $attr ) { vc_add_param( $shortcode, $attr ); } } }
/** * Shorthand function for WPBMap::modify * * @param string $name * @param string $setting * @param string $value * * @return array|bool * @throws \Exception * @since 4.2 */ function vc_map_update( $name = '', $setting = '', $value = '' ) { return WPBMap::modify( $name, $setting, $value ); }
/** * Shorthand function for WPBMap::mutateParam * * @param $name * @param array $attribute * * @return bool * @throws \Exception * @since 4.2 */ function vc_update_shortcode_param( $name, $attribute = array() ) { return WPBMap::mutateParam( $name, $attribute ); }
/** * Shorthand function for WPBMap::dropParam * * @param $name * @param $attribute_name * * @return bool * @since 4.2 */ function vc_remove_param( $name = '', $attribute_name = '' ) { return WPBMap::dropParam( $name, $attribute_name ); }
if ( ! function_exists( 'vc_set_as_theme' ) ) { /** * Sets plugin as theme plugin. * * @internal param bool $disable_updater - If value is true disables auto updater options. * * @since 4.2 */ function vc_set_as_theme() { vc_manager()->setIsAsTheme( true ); } } if ( ! function_exists( 'vc_is_as_theme' ) ) { /** * Is VC as-theme-plugin. * @return bool * @since 4.2 */ function vc_is_as_theme() { return vc_manager()->isAsTheme(); } } if ( ! function_exists( 'vc_is_updater_disabled' ) ) { /** * @return bool * @since 4.2 */ function vc_is_updater_disabled() { return vc_manager()->isUpdaterDisabled();
} } if ( ! function_exists( 'vc_default_editor_post_types' ) ) { /** * Returns list of default post type. * @return array * @since 4.2 */ function vc_default_editor_post_types() { return vc_manager()->editorDefaultPostTypes(); } } if ( ! function_exists( 'vc_set_default_editor_post_types' ) ) { /** * Set post types for VC editor. * @param array $list - list of valid post types to set * @since 4.2 * */ function vc_set_default_editor_post_types( array $list ) { vc_manager()->setEditorDefaultPostTypes( $list ); } } if ( ! function_exists( ( 'vc_editor_post_types' ) ) ) { /** * Returns list of post types where VC editor is enabled. * @return array * @since 4.2 */ function vc_editor_post_types() { return vc_manager()->editorPostTypes(); } } if ( ! function_exists( ( 'vc_editor_set_post_types' ) ) ) { /** * Set list of post types where VC editor is enabled. * @param array $post_types * @throws \Exception * @since 4.4 * */ function vc_editor_set_post_types( array $post_types ) { vc_manager()->setEditorPostTypes( $post_types ); } } if ( ! function_exists( 'vc_mode' ) ) { /** * Return current VC mode. * @return string * @see Vc_Mapper::$mode * @since 4.2 */ function vc_mode() { return vc_manager()->mode(); } } if ( ! function_exists( 'vc_set_shortcodes_templates_dir' ) ) { /** * Sets directory where WPBakery Page Builder should look for template files for content elements. * @param string - full directory path to new template directory with trailing slash * @since 4.2 * */ function vc_set_shortcodes_templates_dir( $dir ) { vc_manager()->setCustomUserShortcodesTemplateDir( $dir ); } } if ( ! function_exists( 'vc_shortcodes_theme_templates_dir' ) ) { /** * Get custom theme template path * @param $template - filename for template * * @return string * @since 4.2 * */ function vc_shortcodes_theme_templates_dir( $template ) { return vc_manager()->getShortcodesTemplateDir( $template ); } }
/** * @param bool $value * * @todo check usage. * * @since 4.3 */ function set_vc_is_inline( $value = true ) { _deprecated_function( 'set_vc_is_inline', '5.2 (will be removed in 5.3)' ); global $vc_is_inline; $vc_is_inline = $value; }
/** * Disable frontend editor for VC * @param bool $disable * @since 4.3 * */ function vc_disable_frontend( $disable = true ) { vc_frontend_editor()->disableInline( $disable ); }
/** * Check is front end enabled. * @return bool * @throws \Exception * @since 4.3 */ function vc_enabled_frontend() { return vc_frontend_editor()->frontendEditorEnabled(); }
if ( ! function_exists( 'vc_add_default_templates' ) ) { /** * Add custom template in default templates list * * @param array $data | template data (name, content, custom_class, image_path) * * @return bool * @since 4.3 */ function vc_add_default_templates( $data ) { return visual_composer()->templatesPanelEditor()->addDefaultTemplates( $data ); } }
/** * @param $shortcode * @param string $field_prefix * @param string $group_prefix * @param null $change_fields * @param null $dependency * @return array * @throws \Exception */ function vc_map_integrate_shortcode( $shortcode, $field_prefix = '', $group_prefix = '', $change_fields = null, $dependency = null ) { if ( is_string( $shortcode ) ) { $shortcode_data = WPBMap::getShortCode( $shortcode ); } else { $shortcode_data = $shortcode; } if ( is_array( $shortcode_data ) && ! empty( $shortcode_data ) ) { /** * @var WPBakeryShortCodeFishBones $shortcode */ $params = isset( $shortcode_data['params'] ) && ! empty( $shortcode_data['params'] ) ? $shortcode_data['params'] : false; if ( is_array( $params ) && ! empty( $params ) ) { $keys = array_keys( $params ); $count = count( $keys ); for ( $i = 0; $i < $count; $i ++ ) { $param = &$params[ $keys[ $i ] ]; // Note! passed by reference to automatically update data if ( isset( $change_fields ) ) { $param = vc_map_integrate_include_exclude_fields( $param, $change_fields ); if ( empty( $param ) ) { continue; } } if ( ! empty( $group_prefix ) ) { if ( isset( $param['group'] ) ) { $param['group'] = $group_prefix . ': ' . $param['group']; } else { $param['group'] = $group_prefix; } } if ( ! empty( $field_prefix ) && isset( $param['param_name'] ) ) { $param['param_name'] = $field_prefix . $param['param_name']; if ( isset( $param['dependency'] ) && is_array( $param['dependency'] ) && isset( $param['dependency']['element'] ) ) { $param['dependency']['element'] = $field_prefix . $param['dependency']['element']; } $param = vc_map_integrate_add_dependency( $param, $dependency );
} elseif ( ! empty( $dependency ) ) { $param = vc_map_integrate_add_dependency( $param, $dependency ); } $param['integrated_shortcode'] = is_array( $shortcode ) ? $shortcode['base'] : $shortcode; $param['integrated_shortcode_field'] = $field_prefix; } }
return is_array( $params ) ? array_filter( $params ) : array(); }
return array(); }
/** * Used to filter params (include/exclude) * * @param $param * @param $change_fields * * @return array|null * @internal * */ function vc_map_integrate_include_exclude_fields( $param, $change_fields ) { if ( is_array( $change_fields ) ) { if ( isset( $change_fields['exclude'] ) && in_array( $param['param_name'], $change_fields['exclude'], true ) ) { $param = null;
return $param; // to prevent group adding to $param } elseif ( isset( $change_fields['exclude_regex'] ) ) { if ( is_array( $change_fields['exclude_regex'] ) && ! empty( $change_fields['exclude_regex'] ) ) { $break_foreach = false; foreach ( $change_fields['exclude_regex'] as $regex ) { /** @noinspection PhpUsageOfSilenceOperatorInspection */ // @codingStandardsIgnoreLine if ( @preg_match( $regex, null ) ) { if ( preg_match( $regex, $param['param_name'] ) ) { $param = null; $break_foreach = true; } } if ( $break_foreach ) { break; } } if ( $break_foreach ) { return $param; // to prevent group adding to $param } } elseif ( is_string( $change_fields['exclude_regex'] ) && strlen( $change_fields['exclude_regex'] ) > 0 ) { /** @noinspection PhpUsageOfSilenceOperatorInspection */ // @codingStandardsIgnoreLine if ( @preg_match( $change_fields['exclude_regex'], null ) ) { if ( preg_match( $change_fields['exclude_regex'], $param['param_name'] ) ) { $param = null;
return $param; // to prevent group adding to $param } } } }
if ( isset( $change_fields['include_only'] ) && ! in_array( $param['param_name'], $change_fields['include_only'], true ) ) { // if we want to enclude only some fields $param = null;
return $param; // to prevent group adding to $param } elseif ( isset( $change_fields['include_only_regex'] ) ) { if ( is_array( $change_fields['include_only_regex'] ) && ! empty( $change_fields['include_only_regex'] ) ) { $break_foreach = false; foreach ( $change_fields['include_only_regex'] as $regex ) { /** @noinspection PhpUsageOfSilenceOperatorInspection */ // @codingStandardsIgnoreLine if ( false === @preg_match( $regex, null ) ) { // Regular expression is invalid, (don't remove @). } else { if ( ! preg_match( $regex, $param['param_name'] ) ) { $param = null; $break_foreach = true; } } if ( $break_foreach ) { break; } } if ( $break_foreach ) { return $param; // to prevent group adding to $param } } elseif ( is_string( $change_fields['include_only_regex'] ) && strlen( $change_fields['include_only_regex'] ) > 0 ) { /** @noinspection PhpUsageOfSilenceOperatorInspection */ // @codingStandardsIgnoreLine if ( false === @preg_match( $change_fields['include_only_regex'], null ) ) { // Regular expression is invalid, (don't remove @). } else { if ( ! preg_match( $change_fields['include_only_regex'], $param['param_name'] ) ) { $param = null;
return $param; // to prevent group adding to $param } } } } }
return $param; }
/** * @param $param * @param $dependency * * @return array * @internal used to add dependency to existed param * */ function vc_map_integrate_add_dependency( $param, $dependency ) { // activator must be used for all elements who doesn't have 'dependency' if ( ! empty( $dependency ) && ( ! isset( $param['dependency'] ) || empty( $param['dependency'] ) ) ) { if ( is_array( $dependency ) ) { $param['dependency'] = $dependency; } }
return $param; }
/** * @param $base_shortcode * @param $integrated_shortcode * @param string $field_prefix * @return array * @throws \Exception */ function vc_map_integrate_get_params( $base_shortcode, $integrated_shortcode, $field_prefix = '' ) { $shortcode_data = WPBMap::getShortCode( $base_shortcode ); $params = array(); if ( is_array( $shortcode_data ) && is_array( $shortcode_data['params'] ) && ! empty( $shortcode_data['params'] ) ) { foreach ( $shortcode_data['params'] as $param ) { if ( is_array( $param ) && isset( $param['integrated_shortcode'] ) && $integrated_shortcode === $param['integrated_shortcode'] ) { if ( ! empty( $field_prefix ) ) { if ( isset( $param['integrated_shortcode_field'] ) && $field_prefix === $param['integrated_shortcode_field'] ) { $params[] = $param; } } else { $params[] = $param; } } } }
return $params; }
/** * @param $base_shortcode * @param $integrated_shortcode * @param string $field_prefix * @return array * @throws \Exception */ function vc_map_integrate_get_atts( $base_shortcode, $integrated_shortcode, $field_prefix = '' ) { $params = vc_map_integrate_get_params( $base_shortcode, $integrated_shortcode, $field_prefix ); $atts = array(); if ( is_array( $params ) && ! empty( $params ) ) { foreach ( $params as $param ) { $value = ''; if ( isset( $param['value'] ) ) { if ( isset( $param['std'] ) ) { $value = $param['std']; } elseif ( is_array( $param['value'] ) ) { reset( $param['value'] ); $value = current( $param['value'] ); } else { $value = $param['value']; } } $atts[ $param['param_name'] ] = $value; } }
return $atts; }
/** * @param $base_shortcode * @param $integrated_shortcode * @param $atts * @param string $field_prefix * @return array * @throws \Exception */ function vc_map_integrate_parse_atts( $base_shortcode, $integrated_shortcode, $atts, $field_prefix = '' ) { $params = vc_map_integrate_get_params( $base_shortcode, $integrated_shortcode, $field_prefix ); $data = array(); if ( is_array( $params ) && ! empty( $params ) ) { foreach ( $params as $param ) { if ( isset( $atts[ $param['param_name'] ] ) ) { $value = $atts[ $param['param_name'] ]; } if ( isset( $value ) ) { $key = $param['param_name']; if ( strlen( $field_prefix ) > 0 ) { $key = substr( $key, strlen( $field_prefix ) ); } $data[ $key ] = $value; } } }
return $data; }
/** * @param bool $label * @return mixed|void */ function vc_map_add_css_animation( $label = true ) { $data = array( 'type' => 'animation_style', 'heading' => esc_html__( 'CSS Animation', 'js_composer' ), 'param_name' => 'css_animation', 'admin_label' => $label, 'value' => '', 'settings' => array( 'type' => 'in', 'custom' => array( array( 'label' => esc_html__( 'Default', 'js_composer' ), 'values' => array( esc_html__( 'Top to bottom', 'js_composer' ) => 'top-to-bottom', esc_html__( 'Bottom to top', 'js_composer' ) => 'bottom-to-top', esc_html__( 'Left to right', 'js_composer' ) => 'left-to-right', esc_html__( 'Right to left', 'js_composer' ) => 'right-to-left', esc_html__( 'Appear from center', 'js_composer' ) => 'appear', ), ), ), ), 'description' => esc_html__( 'Select type of animation for element to be animated when it "enters" the browsers viewport (Note: works only in modern browsers).', 'js_composer' ), );
return apply_filters( 'vc_map_add_css_animation', $data, $label ); }
/** * Get settings of the mapped shortcode. * * @param $tag * * @return array|null - settings or null if shortcode not mapped * @throws \Exception * @since 4.4.3 */ function vc_get_shortcode( $tag ) { return WPBMap::getShortCode( $tag ); }
/** * Remove all mapped shortcodes and the moment when function is called. * * @since 4.5 */ function vc_remove_all_elements() { WPBMap::dropAllShortcodes(); }
/** * Function to get defaults values for shortcode. * @param $tag - shortcode tag * * @return array - list of param=>default_value * @throws \Exception * @since 4.6 * */ function vc_map_get_defaults( $tag ) { $shortcode = vc_get_shortcode( $tag ); $params = array(); if ( is_array( $shortcode ) && isset( $shortcode['params'] ) && ! empty( $shortcode['params'] ) ) { $params = vc_map_get_params_defaults( $shortcode['params'] ); }
return $params; }
/** * @param $params * * @return array * @since 4.12 */ function vc_map_get_params_defaults( $params ) { $resultParams = array(); foreach ( $params as $param ) { if ( isset( $param['param_name'] ) && 'content' !== $param['param_name'] ) { $value = ''; if ( isset( $param['std'] ) ) { $value = $param['std']; } elseif ( isset( $param['value'] ) ) { if ( is_array( $param['value'] ) ) { $value = current( $param['value'] ); if ( is_array( $value ) ) { // in case if two-dimensional array provided (vc_basic_grid) $value = current( $value ); } // return first value from array (by default) } else { $value = $param['value']; } } $resultParams[ $param['param_name'] ] = apply_filters( 'vc_map_get_param_defaults', $value, $param ); } }
return $resultParams; }
/** * @param $tag - shortcode tag3 * @param array $atts - shortcode attributes * * @return array - return merged values with provided attributes ( * 'a'=>1,'b'=>2 + 'b'=>3,'c'=>4 --> 'a'=>1,'b'=>3 ) * * @throws \Exception * @see vc_shortcode_attribute_parse - return union of provided attributes ( * 'a'=>1,'b'=>2 + 'b'=>3,'c'=>4 --> 'a'=>1, * 'b'=>3, 'c'=>4 ) */ function vc_map_get_attributes( $tag, $atts = array() ) { $atts = shortcode_atts( vc_map_get_defaults( $tag ), $atts, $tag );
return apply_filters( 'vc_map_get_attributes', $atts, $tag ); }
/** * @param $name * @return mixed|string */ function vc_convert_vc_color( $name ) { $colors = array( 'blue' => '#5472d2', 'turquoise' => '#00c1cf', 'pink' => '#fe6c61', 'violet' => '#8d6dc4', 'peacoc' => '#4cadc9', 'chino' => '#cec2ab', 'mulled-wine' => '#50485b', 'vista-blue' => '#75d69c', 'orange' => '#f7be68', 'sky' => '#5aa1e3', 'green' => '#6dab3c', 'juicy-pink' => '#f4524d', 'sandy-brown' => '#f79468', 'purple' => '#b97ebb', 'black' => '#2a2a2a', 'grey' => '#ebebeb', 'white' => '#ffffff', ); $name = str_replace( '_', '-', $name ); if ( isset( $colors[ $name ] ) ) { return $colors[ $name ]; }
return ''; }
/** * Extract width/height from string * * @param string $dimensions WxH * * @return mixed array(width, height) or false * @since 4.7 * */ function vc_extract_dimensions( $dimensions ) { $dimensions = str_replace( ' ', '', $dimensions ); $matches = null;
if ( preg_match( '/(\d+)x(\d+)/', $dimensions, $matches ) ) { return array( $matches[1], $matches[2], ); }
return false; }
/** * @param string $asset * * @return array|string */ function vc_get_shared( $asset = '' ) { switch ( $asset ) { case 'colors': $asset = VcSharedLibrary::getColors(); break;
case 'colors-dashed': $asset = VcSharedLibrary::getColorsDashed(); break;
case 'icons': $asset = VcSharedLibrary::getIcons(); break;
case 'sizes': $asset = VcSharedLibrary::getSizes(); break;
case 'button styles': case 'alert styles': $asset = VcSharedLibrary::getButtonStyles(); break; case 'message_box_styles': $asset = VcSharedLibrary::getMessageBoxStyles(); break; case 'cta styles': $asset = VcSharedLibrary::getCtaStyles(); break;
case 'text align': $asset = VcSharedLibrary::getTextAlign(); break;
case 'cta widths': case 'separator widths': $asset = VcSharedLibrary::getElementWidths(); break;
case 'separator styles': $asset = VcSharedLibrary::getSeparatorStyles(); break;
case 'separator border widths': $asset = VcSharedLibrary::getBorderWidths(); break;
case 'single image styles': $asset = VcSharedLibrary::getBoxStyles(); break;
case 'single image external styles': $asset = VcSharedLibrary::getBoxStyles( array( 'default', 'round', ) ); break;
case 'toggle styles': $asset = VcSharedLibrary::getToggleStyles(); break;
case 'animation styles': $asset = VcSharedLibrary::getAnimationStyles(); break; }
return $asset; }
/** * Helper function to register new shortcode attribute hook. * * @param $name - attribute name * @param $form_field_callback - hook, will be called when settings form is shown and attribute added to shortcode * param list * @param $script_url - javascript file url which will be attached at the end of settings form. * * @return bool * @since 4.4 */ function vc_add_shortcode_param( $name, $form_field_callback, $script_url = null ) { return WpbakeryShortcodeParams::addField( $name, $form_field_callback, $script_url ); }
/** * Call hook for attribute. * * @param $name - attribute name * @param $param_settings - attribute settings from shortcode * @param $param_value - attribute value * @param $tag - attribute tag * * @return mixed|string - returns html which will be render in hook * @since 4.4 */ function vc_do_shortcode_param_settings_field( $name, $param_settings, $param_value, $tag ) { return WpbakeryShortcodeParams::renderSettingsField( $name, $param_settings, $param_value, $tag ); }
|