helpers.php 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder helpers functions
  7. *
  8. * @package WPBakeryPageBuilder
  9. *
  10. */
  11. // Check if this file is loaded in js_composer
  12. if ( ! defined( 'WPB_VC_VERSION' ) ) {
  13. die( '-1' );
  14. }
  15. /**
  16. * @param array $params
  17. *
  18. * @return array|bool
  19. * @since 4.2
  20. * vc_filter: vc_wpb_getimagesize - to override output of this function
  21. */
  22. function wpb_getImageBySize( $params = array() ) {
  23. $params = array_merge( array(
  24. 'post_id' => null,
  25. 'attach_id' => null,
  26. 'thumb_size' => 'thumbnail',
  27. 'class' => '',
  28. ), $params );
  29. if ( ! $params['thumb_size'] ) {
  30. $params['thumb_size'] = 'thumbnail';
  31. }
  32. if ( ! $params['attach_id'] && ! $params['post_id'] ) {
  33. return false;
  34. }
  35. $post_id = $params['post_id'];
  36. $attach_id = $post_id ? get_post_thumbnail_id( $post_id ) : $params['attach_id'];
  37. $attach_id = apply_filters( 'vc_object_id', $attach_id );
  38. $thumb_size = $params['thumb_size'];
  39. $thumb_class = ( isset( $params['class'] ) && '' !== $params['class'] ) ? $params['class'] . ' ' : '';
  40. global $_wp_additional_image_sizes;
  41. $thumbnail = '';
  42. $sizes = array(
  43. 'thumbnail',
  44. 'thumb',
  45. 'medium',
  46. 'large',
  47. 'full',
  48. );
  49. if ( is_string( $thumb_size ) && ( ( ! empty( $_wp_additional_image_sizes[ $thumb_size ] ) && is_array( $_wp_additional_image_sizes[ $thumb_size ] ) ) || in_array( $thumb_size, $sizes, true ) ) ) {
  50. $attributes = array( 'class' => $thumb_class . 'attachment-' . $thumb_size );
  51. $thumbnail = wp_get_attachment_image( $attach_id, $thumb_size, false, $attributes );
  52. } elseif ( $attach_id ) {
  53. if ( is_string( $thumb_size ) ) {
  54. preg_match_all( '/\d+/', $thumb_size, $thumb_matches );
  55. if ( isset( $thumb_matches[0] ) ) {
  56. $thumb_size = array();
  57. $count = count( $thumb_matches[0] );
  58. if ( $count > 1 ) {
  59. $thumb_size[] = $thumb_matches[0][0]; // width
  60. $thumb_size[] = $thumb_matches[0][1]; // height
  61. } elseif ( 1 === $count ) {
  62. $thumb_size[] = $thumb_matches[0][0]; // width
  63. $thumb_size[] = $thumb_matches[0][0]; // height
  64. } else {
  65. $thumb_size = false;
  66. }
  67. }
  68. }
  69. if ( is_array( $thumb_size ) ) {
  70. // Resize image to custom size
  71. $p_img = wpb_resize( $attach_id, null, $thumb_size[0], $thumb_size[1], true );
  72. $alt = trim( wp_strip_all_tags( get_post_meta( $attach_id, '_wp_attachment_image_alt', true ) ) );
  73. $attachment = get_post( $attach_id );
  74. if ( ! empty( $attachment ) ) {
  75. $title = trim( wp_strip_all_tags( $attachment->post_title ) );
  76. if ( empty( $alt ) ) {
  77. $alt = trim( wp_strip_all_tags( $attachment->post_excerpt ) ); // If not, Use the Caption
  78. }
  79. if ( empty( $alt ) ) {
  80. $alt = $title;
  81. }
  82. if ( $p_img ) {
  83. $attributes = vc_stringify_attributes( array(
  84. 'class' => $thumb_class,
  85. 'src' => $p_img['url'],
  86. 'width' => $p_img['width'],
  87. 'height' => $p_img['height'],
  88. 'alt' => $alt,
  89. 'title' => $title,
  90. ) );
  91. $thumbnail = '<img ' . $attributes . ' />';
  92. }
  93. }
  94. }
  95. }
  96. $p_img_large = wp_get_attachment_image_src( $attach_id, 'large' );
  97. return apply_filters( 'vc_wpb_getimagesize', array(
  98. 'thumbnail' => $thumbnail,
  99. 'p_img_large' => $p_img_large,
  100. ), $attach_id, $params );
  101. }
  102. /**
  103. * @param $id
  104. * @param $size
  105. * @return array|false|mixed|string
  106. */
  107. function vc_get_image_by_size( $id, $size ) {
  108. global $_wp_additional_image_sizes;
  109. $sizes = array(
  110. 'thumbnail',
  111. 'thumb',
  112. 'medium',
  113. 'large',
  114. 'full',
  115. );
  116. if ( is_string( $size ) && ( ( ! empty( $_wp_additional_image_sizes[ $size ] ) && is_array( $_wp_additional_image_sizes[ $size ] ) ) || in_array( $size, $sizes, true ) ) ) {
  117. return wp_get_attachment_image_src( $id, $size );
  118. } else {
  119. if ( is_string( $size ) ) {
  120. preg_match_all( '/\d+/', $size, $thumb_matches );
  121. if ( isset( $thumb_matches[0] ) ) {
  122. $size = array();
  123. $count = count( $thumb_matches[0] );
  124. if ( $count > 1 ) {
  125. $size[] = $thumb_matches[0][0]; // width
  126. $size[] = $thumb_matches[0][1]; // height
  127. } elseif ( 1 === $count ) {
  128. $size[] = $thumb_matches[0][0]; // width
  129. $size[] = $thumb_matches[0][0]; // height
  130. } else {
  131. $size = false;
  132. }
  133. }
  134. }
  135. if ( is_array( $size ) ) {
  136. // Resize image to custom size
  137. $p_img = wpb_resize( $id, null, $size[0], $size[1], true );
  138. return $p_img['url'];
  139. }
  140. }
  141. return '';
  142. }
  143. /**
  144. * Convert vc_col-sm-3 to 1/4
  145. * @param $width
  146. *
  147. * @return string
  148. * @since 4.2
  149. */
  150. function wpb_translateColumnWidthToFractional( $width ) {
  151. switch ( $width ) {
  152. case 'vc_col-sm-2':
  153. $w = '1/6';
  154. break;
  155. case 'vc_col-sm-3':
  156. $w = '1/4';
  157. break;
  158. case 'vc_col-sm-4':
  159. $w = '1/3';
  160. break;
  161. case 'vc_col-sm-6':
  162. $w = '1/2';
  163. break;
  164. case 'vc_col-sm-8':
  165. $w = '2/3';
  166. break;
  167. case 'vc_col-sm-9':
  168. $w = '3/4';
  169. break;
  170. case 'vc_col-sm-12':
  171. $w = '1/1';
  172. break;
  173. default:
  174. $w = is_string( $width ) ? $width : '1/1';
  175. }
  176. return $w;
  177. }
  178. /**
  179. * @param $width
  180. *
  181. * @return bool|string
  182. * @since 4.2
  183. */
  184. function wpb_translateColumnWidthToSpan( $width ) {
  185. $output = $width;
  186. preg_match( '/(\d+)\/(\d+)/', $width, $matches );
  187. if ( ! empty( $matches ) ) {
  188. $part_x = (int) $matches[1];
  189. $part_y = (int) $matches[2];
  190. if ( $part_x > 0 && $part_y > 0 ) {
  191. $value = ceil( $part_x / $part_y * 12 );
  192. if ( $value > 0 && $value <= 12 ) {
  193. $output = 'vc_col-sm-' . $value;
  194. }
  195. }
  196. }
  197. if ( preg_match( '/\d+\/5$/', $width ) ) {
  198. $output = 'vc_col-sm-' . $width;
  199. }
  200. return apply_filters( 'vc_translate_column_width_class', $output, $width );
  201. }
  202. /**
  203. * @param $content
  204. * @param bool $autop
  205. *
  206. * @return string
  207. * @since 4.2
  208. */
  209. function wpb_js_remove_wpautop( $content, $autop = false ) {
  210. if ( $autop ) {
  211. $content = wpautop( preg_replace( '/<\/?p\>/', "\n", $content ) . "\n" );
  212. }
  213. return do_shortcode( shortcode_unautop( $content ) );
  214. }
  215. if ( ! function_exists( 'shortcode_exists' ) ) {
  216. /**
  217. * Check if a shortcode is registered in WordPress.
  218. *
  219. * Examples: shortcode_exists( 'caption' ) - will return true.
  220. * shortcode_exists( 'blah' ) - will return false.
  221. *
  222. * @param bool $shortcode
  223. *
  224. * @return bool
  225. * @since 4.2
  226. */
  227. function shortcode_exists( $shortcode = false ) {
  228. global $shortcode_tags;
  229. if ( ! $shortcode ) {
  230. return false;
  231. }
  232. if ( array_key_exists( $shortcode, $shortcode_tags ) ) {
  233. return true;
  234. }
  235. return false;
  236. }
  237. }
  238. if ( ! function_exists( 'vc_siteAttachedImages' ) ) {
  239. /**
  240. * Helper function which returns list of site attached images, and if image is attached to the current post it adds class 'added'
  241. * @param array $att_ids
  242. *
  243. * @return string
  244. * @since 4.11
  245. */
  246. function vc_siteAttachedImages( $att_ids = array() ) {
  247. $output = '';
  248. $limit = (int) apply_filters( 'vc_site_attached_images_query_limit', - 1 );
  249. $media_images = get_posts( 'post_type=attachment&orderby=ID&numberposts=' . $limit );
  250. foreach ( $media_images as $image_post ) {
  251. $thumb_src = wp_get_attachment_image_src( $image_post->ID, 'thumbnail' );
  252. $thumb_src = $thumb_src[0];
  253. $class = ( in_array( $image_post->ID, $att_ids, true ) ) ? ' class="added"' : '';
  254. $output .= '<li' . $class . '>
  255. <img rel="' . esc_attr( $image_post->ID ) . '" src="' . esc_url( $thumb_src ) . '" />
  256. <span class="img-added">' . esc_html__( 'Added', 'js_composer' ) . '</span>
  257. </li>';
  258. }
  259. if ( '' !== $output ) {
  260. $output = '<ul class="gallery_widget_img_select">' . $output . '</ul>';
  261. }
  262. return $output;
  263. }
  264. }
  265. /**
  266. * @param array $images IDs or srcs of images
  267. *
  268. * @return string
  269. * @since 5.8
  270. */
  271. function vc_field_attached_images( $images = array() ) {
  272. $output = '';
  273. foreach ( $images as $image ) {
  274. if ( is_numeric( $image ) ) {
  275. $thumb_src = wp_get_attachment_image_src( $image, 'thumbnail' );
  276. $thumb_src = isset( $thumb_src[0] ) ? $thumb_src[0] : '';
  277. } else {
  278. $thumb_src = $image;
  279. }
  280. if ( $thumb_src ) {
  281. $output .= '
  282. <li class="added">
  283. <img rel="' . esc_attr( $image ) . '" src="' . esc_url( $thumb_src ) . '" />
  284. <a href="javascript:;" class="vc_icon-remove"><i class="vc-composer-icon vc-c-icon-close"></i></a>
  285. </li>';
  286. }
  287. }
  288. return $output;
  289. }
  290. /**
  291. * @param $param_value
  292. *
  293. * @return array
  294. * @since 4.2
  295. */
  296. function wpb_removeNotExistingImgIDs( $param_value ) {
  297. $tmp = explode( ',', $param_value );
  298. $return_ar = array();
  299. foreach ( $tmp as $id ) {
  300. if ( wp_get_attachment_image( $id ) ) {
  301. $return_ar[] = $id;
  302. }
  303. }
  304. $tmp = implode( ',', $return_ar );
  305. return $tmp;
  306. }
  307. /*
  308. * Resize images dynamically using wp built in functions
  309. * Victor Teixeira
  310. */
  311. if ( ! function_exists( 'wpb_resize' ) ) {
  312. /**
  313. * @param int $attach_id
  314. * @param string $img_url
  315. * @param int $width
  316. * @param int $height
  317. * @param bool $crop
  318. *
  319. * @return array
  320. * @since 4.2
  321. */
  322. function wpb_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
  323. // this is an attachment, so we have the ID
  324. $image_src = array();
  325. if ( $attach_id ) {
  326. $image_src = wp_get_attachment_image_src( $attach_id, 'full' );
  327. $actual_file_path = get_attached_file( $attach_id );
  328. // this is not an attachment, let's use the image url
  329. } elseif ( $img_url ) {
  330. $file_path = wp_parse_url( $img_url );
  331. $actual_file_path = rtrim( ABSPATH, '/' ) . $file_path['path'];
  332. $orig_size = getimagesize( $actual_file_path );
  333. $image_src[0] = $img_url;
  334. $image_src[1] = $orig_size[0];
  335. $image_src[2] = $orig_size[1];
  336. }
  337. if ( ! empty( $actual_file_path ) ) {
  338. $file_info = pathinfo( $actual_file_path );
  339. $extension = '.' . $file_info['extension'];
  340. // the image path without the extension
  341. $no_ext_path = $file_info['dirname'] . '/' . $file_info['filename'];
  342. $cropped_img_path = $no_ext_path . '-' . $width . 'x' . $height . $extension;
  343. // checking if the file size is larger than the target size
  344. // if it is smaller or the same size, stop right here and return
  345. if ( $image_src[1] > $width || $image_src[2] > $height ) {
  346. // the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
  347. if ( file_exists( $cropped_img_path ) ) {
  348. $cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
  349. $vt_image = array(
  350. 'url' => $cropped_img_url,
  351. 'width' => $width,
  352. 'height' => $height,
  353. );
  354. return $vt_image;
  355. }
  356. if ( ! $crop ) {
  357. // calculate the size proportionaly
  358. $proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
  359. $resized_img_path = $no_ext_path . '-' . $proportional_size[0] . 'x' . $proportional_size[1] . $extension;
  360. // checking if the file already exists
  361. if ( file_exists( $resized_img_path ) ) {
  362. $resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
  363. $vt_image = array(
  364. 'url' => $resized_img_url,
  365. 'width' => $proportional_size[0],
  366. 'height' => $proportional_size[1],
  367. );
  368. return $vt_image;
  369. }
  370. }
  371. // no cache files - let's finally resize it
  372. $img_editor = wp_get_image_editor( $actual_file_path );
  373. if ( is_wp_error( $img_editor ) || is_wp_error( $img_editor->resize( $width, $height, $crop ) ) ) {
  374. return array(
  375. 'url' => '',
  376. 'width' => '',
  377. 'height' => '',
  378. );
  379. }
  380. $new_img_path = $img_editor->generate_filename();
  381. if ( is_wp_error( $img_editor->save( $new_img_path ) ) ) {
  382. return array(
  383. 'url' => '',
  384. 'width' => '',
  385. 'height' => '',
  386. );
  387. }
  388. if ( ! is_string( $new_img_path ) ) {
  389. return array(
  390. 'url' => '',
  391. 'width' => '',
  392. 'height' => '',
  393. );
  394. }
  395. $new_img_size = getimagesize( $new_img_path );
  396. $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
  397. // resized output
  398. $vt_image = array(
  399. 'url' => $new_img,
  400. 'width' => $new_img_size[0],
  401. 'height' => $new_img_size[1],
  402. );
  403. return $vt_image;
  404. }
  405. // default output - without resizing
  406. $vt_image = array(
  407. 'url' => $image_src[0],
  408. 'width' => $image_src[1],
  409. 'height' => $image_src[2],
  410. );
  411. return $vt_image;
  412. }
  413. return false;
  414. }
  415. }
  416. /**
  417. * Method adds css class to body tag.
  418. *
  419. * Hooked class method by body_class WP filter. Method adds custom css class to body tag of the page to help
  420. * identify and build design specially for VC shortcodes.
  421. * Used in wp-content/plugins/js_composer/include/classes/core/class-vc-base.php\Vc_Base\bodyClass
  422. *
  423. * @param $classes
  424. *
  425. * @return array
  426. * @since 4.2
  427. */
  428. function js_composer_body_class( $classes ) {
  429. $classes[] = 'wpb-js-composer js-comp-ver-' . WPB_VC_VERSION;
  430. $disable_responsive = vc_settings()->get( 'not_responsive_css' );
  431. if ( '1' !== $disable_responsive ) {
  432. $classes[] = 'vc_responsive';
  433. } else {
  434. $classes[] = 'vc_non_responsive';
  435. }
  436. return $classes;
  437. }
  438. /**
  439. * @param $m
  440. *
  441. * @return string
  442. * @since 4.2
  443. */
  444. function vc_convert_shortcode( $m ) {
  445. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  446. if ( 'vc_row' === $tag || 'vc_section' === $tag ) {
  447. return $output;
  448. }
  449. $result = '';
  450. $el_position = '';
  451. $width = '1/1';
  452. $shortcode_attr = shortcode_parse_atts( $attr_string );
  453. extract( shortcode_atts( array(
  454. 'width' => '1/1',
  455. 'el_class' => '',
  456. 'el_position' => '',
  457. ), $shortcode_attr ) );
  458. // Start
  459. if ( preg_match( '/first/', $el_position ) || empty( $shortcode_attr['width'] ) || '1/1' === $shortcode_attr['width'] ) {
  460. $result = '[vc_row]';
  461. }
  462. if ( 'vc_column' !== $tag ) {
  463. $result .= '[vc_column width="' . $width . '"]';
  464. }
  465. // Tag
  466. $pattern = get_shortcode_regex();
  467. if ( 'vc_column' === $tag ) {
  468. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  469. } elseif ( 'vc_tabs' === $tag || 'vc_accordion' === $tag || 'vc_tour' === $tag ) {
  470. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_tab_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  471. } else {
  472. $result .= preg_replace( '/(\"\d\/\d\")/', '"1/1"', $output );
  473. }
  474. // End
  475. if ( 'vc_column' !== $tag ) {
  476. $result .= '[/vc_column]';
  477. }
  478. if ( preg_match( '/last/', $el_position ) || empty( $shortcode_attr['width'] ) || '1/1' === $shortcode_attr['width'] ) {
  479. $result .= '[/vc_row]' . "\n";
  480. }
  481. return trim( $result );
  482. }
  483. /**
  484. * @param $m
  485. *
  486. * @return string
  487. * @since 4.2
  488. */
  489. function vc_convert_tab_inner_shortcode( $m ) {
  490. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  491. $result = '';
  492. extract( shortcode_atts( array(
  493. 'width' => '1/1',
  494. 'el_class' => '',
  495. 'el_position' => '',
  496. ), shortcode_parse_atts( $attr_string ) ) );
  497. $pattern = get_shortcode_regex();
  498. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  499. return $result;
  500. }
  501. /**
  502. * @param $m
  503. *
  504. * @return string
  505. * @since 4.2
  506. */
  507. function vc_convert_inner_shortcode( $m ) {
  508. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  509. $result = '';
  510. $width = '';
  511. $el_position = '';
  512. extract( shortcode_atts( array(
  513. 'width' => '1/1',
  514. 'el_class' => '',
  515. 'el_position' => '',
  516. ), shortcode_parse_atts( $attr_string ) ) );
  517. if ( '1/1' !== $width ) {
  518. if ( preg_match( '/first/', $el_position ) ) {
  519. $result .= '[vc_row_inner]';
  520. }
  521. $result .= "\n" . '[vc_column_inner width="' . esc_attr( $width ) . '" el_position="' . esc_attr( $el_position ) . '"]';
  522. $attr = '';
  523. foreach ( shortcode_parse_atts( $attr_string ) as $key => $value ) {
  524. if ( 'width' === $key ) {
  525. $value = '1/1';
  526. } elseif ( 'el_position' === $key ) {
  527. $value = 'first last';
  528. }
  529. $attr .= ' ' . $key . '="' . $value . '"';
  530. }
  531. $result .= "[{$m_one}{$tag} {$attr}]" . $content . "[/{$tag}{$m_four}]";
  532. $result .= '[/vc_column_inner]';
  533. if ( preg_match( '/last/', $el_position ) ) {
  534. $result .= '[/vc_row_inner]' . "\n";
  535. }
  536. } else {
  537. $result = $output;
  538. }
  539. return $result;
  540. }
  541. global $vc_row_layouts;
  542. $vc_row_layouts = array(
  543. array(
  544. 'cells' => '11',
  545. 'mask' => '12',
  546. 'title' => '1/1',
  547. 'icon_class' => '1-1',
  548. ),
  549. array(
  550. 'cells' => '12_12',
  551. 'mask' => '26',
  552. 'title' => '1/2 + 1/2',
  553. 'icon_class' => '1-2_1-2',
  554. ),
  555. array(
  556. 'cells' => '23_13',
  557. 'mask' => '29',
  558. 'title' => '2/3 + 1/3',
  559. 'icon_class' => '2-3_1-3',
  560. ),
  561. array(
  562. 'cells' => '13_13_13',
  563. 'mask' => '312',
  564. 'title' => '1/3 + 1/3 + 1/3',
  565. 'icon_class' => '1-3_1-3_1-3',
  566. ),
  567. array(
  568. 'cells' => '14_14_14_14',
  569. 'mask' => '420',
  570. 'title' => '1/4 + 1/4 + 1/4 + 1/4',
  571. 'icon_class' => '1-4_1-4_1-4_1-4',
  572. ),
  573. array(
  574. 'cells' => '14_34',
  575. 'mask' => '212',
  576. 'title' => '1/4 + 3/4',
  577. 'icon_class' => '1-4_3-4',
  578. ),
  579. array(
  580. 'cells' => '14_12_14',
  581. 'mask' => '313',
  582. 'title' => '1/4 + 1/2 + 1/4',
  583. 'icon_class' => '1-4_1-2_1-4',
  584. ),
  585. array(
  586. 'cells' => '56_16',
  587. 'mask' => '218',
  588. 'title' => '5/6 + 1/6',
  589. 'icon_class' => '5-6_1-6',
  590. ),
  591. array(
  592. 'cells' => '16_16_16_16_16_16',
  593. 'mask' => '642',
  594. 'title' => '1/6 + 1/6 + 1/6 + 1/6 + 1/6 + 1/6',
  595. 'icon_class' => '1-6_1-6_1-6_1-6_1-6_1-6',
  596. ),
  597. array(
  598. 'cells' => '16_23_16',
  599. 'mask' => '319',
  600. 'title' => '1/6 + 4/6 + 1/6',
  601. 'icon_class' => '1-6_2-3_1-6',
  602. ),
  603. array(
  604. 'cells' => '16_16_16_12',
  605. 'mask' => '424',
  606. 'title' => '1/6 + 1/6 + 1/6 + 1/2',
  607. 'icon_class' => '1-6_1-6_1-6_1-2',
  608. ),
  609. array(
  610. 'cells' => '15_15_15_15_15',
  611. 'mask' => '530',
  612. 'title' => '1/5 + 1/5 + 1/5 + 1/5 + 1/5',
  613. 'icon_class' => 'l_15_15_15_15_15',
  614. ),
  615. );
  616. /**
  617. * @param $width
  618. *
  619. * @return string
  620. * @since 4.2
  621. */
  622. function wpb_vc_get_column_width_indent( $width ) {
  623. $identy = '11';
  624. if ( 'vc_col-sm-6' === $width ) {
  625. $identy = '12';
  626. } elseif ( 'vc_col-sm-3' === $width ) {
  627. $identy = '14';
  628. } elseif ( 'vc_col-sm-4' === $width ) {
  629. $identy = '13';
  630. } elseif ( 'vc_col-sm-8' === $width ) {
  631. $identy = '23';
  632. } elseif ( 'vc_col-sm-9' === $width ) {
  633. $identy = '34';
  634. } elseif ( 'vc_col-sm-2' === $width ) {
  635. $identy = '16'; // TODO: check why there is no "vc_col-sm-1, -5, -6, -7, -11, -12.
  636. } elseif ( 'vc_col-sm-10' === $width ) {
  637. $identy = '56';
  638. }
  639. return $identy;
  640. }
  641. /**
  642. * Make any HEX color lighter or darker
  643. * @param $colour
  644. * @param $per
  645. *
  646. * @return string
  647. * @since 4.2
  648. */
  649. function vc_colorCreator( $colour, $per = 10 ) {
  650. require_once 'class-vc-color-helper.php';
  651. $color = $colour;
  652. if ( stripos( $colour, 'rgba(' ) !== false ) {
  653. $rgb = str_replace( array(
  654. 'rgba',
  655. 'rgb',
  656. '(',
  657. ')',
  658. ), '', $colour );
  659. $rgb = explode( ',', $rgb );
  660. $rgb_array = array(
  661. 'R' => $rgb[0],
  662. 'G' => $rgb[1],
  663. 'B' => $rgb[2],
  664. );
  665. $alpha = $rgb[3];
  666. try {
  667. $color = Vc_Color_Helper::rgbToHex( $rgb_array );
  668. $color_obj = new Vc_Color_Helper( $color );
  669. if ( $per >= 0 ) {
  670. $color = $color_obj->lighten( $per );
  671. } else {
  672. $color = $color_obj->darken( abs( $per ) );
  673. }
  674. $rgba = $color_obj->hexToRgb( $color );
  675. $rgba[] = $alpha;
  676. $css_rgba_color = 'rgba(' . implode( ', ', $rgba ) . ')';
  677. return $css_rgba_color;
  678. } catch ( Exception $e ) {
  679. // In case of error return same as given
  680. return $colour;
  681. }
  682. } elseif ( stripos( $colour, 'rgb(' ) !== false ) {
  683. $rgb = str_replace( array(
  684. 'rgba',
  685. 'rgb',
  686. '(',
  687. ')',
  688. ), '', $colour );
  689. $rgb = explode( ',', $rgb );
  690. $rgb_array = array(
  691. 'R' => $rgb[0],
  692. 'G' => $rgb[1],
  693. 'B' => $rgb[2],
  694. );
  695. try {
  696. $color = Vc_Color_Helper::rgbToHex( $rgb_array );
  697. } catch ( Exception $e ) {
  698. // In case of error return same as given
  699. return $colour;
  700. }
  701. }
  702. try {
  703. $color_obj = new Vc_Color_Helper( $color );
  704. if ( $per >= 0 ) {
  705. $color = $color_obj->lighten( $per );
  706. } else {
  707. $color = $color_obj->darken( abs( $per ) );
  708. }
  709. return '#' . $color;
  710. } catch ( Exception $e ) {
  711. return $colour;
  712. }
  713. }
  714. /**
  715. * HEX to RGB converter
  716. * @param $color
  717. *
  718. * @return array|bool
  719. * @since 4.2
  720. */
  721. function vc_hex2rgb( $color ) {
  722. $color = str_replace( '#', '', $color );
  723. if ( strlen( $color ) === 6 ) {
  724. list( $r, $g, $b ) = array(
  725. $color[0] . $color[1],
  726. $color[2] . $color[3],
  727. $color[4] . $color[5],
  728. );
  729. } elseif ( strlen( $color ) === 3 ) {
  730. list( $r, $g, $b ) = array(
  731. $color[0] . $color[0],
  732. $color[1] . $color[1],
  733. $color[2] . $color[2],
  734. );
  735. } else {
  736. return false;
  737. }
  738. $r = hexdec( $r );
  739. $g = hexdec( $g );
  740. $b = hexdec( $b );
  741. return array(
  742. $r,
  743. $g,
  744. $b,
  745. );
  746. }
  747. /**
  748. * Parse string like "title:Hello world|weekday:Monday" to array('title' => 'Hello World', 'weekday' => 'Monday')
  749. *
  750. * @param $value
  751. * @param array $default
  752. *
  753. * @return array
  754. * @since 4.2
  755. */
  756. function vc_parse_multi_attribute( $value, $default = array() ) {
  757. $result = $default;
  758. $params_pairs = explode( '|', $value );
  759. if ( ! empty( $params_pairs ) ) {
  760. foreach ( $params_pairs as $pair ) {
  761. $param = preg_split( '/\:/', $pair );
  762. if ( ! empty( $param[0] ) && isset( $param[1] ) ) {
  763. $result[ $param[0] ] = rawurldecode( $param[1] );
  764. }
  765. }
  766. }
  767. return $result;
  768. }
  769. /**
  770. * @param $v
  771. *
  772. * @return string
  773. * @since 4.2
  774. */
  775. function vc_param_options_parse_values( $v ) {
  776. return rawurldecode( $v );
  777. }
  778. /**
  779. * @param $name
  780. * @param $settings
  781. *
  782. * @return bool
  783. * @since 4.2
  784. */
  785. function vc_param_options_get_settings( $name, $settings ) {
  786. if ( is_array( $settings ) ) {
  787. foreach ( $settings as $params ) {
  788. if ( isset( $params['name'] ) && $params['name'] === $name && isset( $params['type'] ) ) {
  789. return $params;
  790. }
  791. }
  792. }
  793. return false;
  794. }
  795. /**
  796. * @param $atts
  797. *
  798. * @return string
  799. * @since 4.2
  800. */
  801. function vc_convert_atts_to_string( $atts ) {
  802. $output = '';
  803. foreach ( $atts as $key => $value ) {
  804. $output .= ' ' . $key . '="' . $value . '"';
  805. }
  806. return $output;
  807. }
  808. /**
  809. * @param $string
  810. * @param $tag
  811. * @param $param
  812. *
  813. * @return array
  814. * @throws \Exception
  815. * @since 4.2
  816. */
  817. function vc_parse_options_string( $string, $tag, $param ) {
  818. $options = array();
  819. $option_settings_list = array();
  820. $settings = WPBMap::getParam( $tag, $param );
  821. foreach ( preg_split( '/\|/', $string ) as $value ) {
  822. if ( preg_match( '/\:/', $value ) ) {
  823. $split = preg_split( '/\:/', $value );
  824. $option_name = $split[0];
  825. $option_settings = vc_param_options_get_settings( $option_name, $settings['options'] );
  826. $option_settings_list[ $option_name ] = $option_settings;
  827. if ( isset( $option_settings['type'] ) && 'checkbox' === $option_settings['type'] ) {
  828. $option_value = array_map( 'vc_param_options_parse_values', preg_split( '/\,/', $split[1] ) );
  829. } else {
  830. $option_value = rawurldecode( $split[1] );
  831. }
  832. $options[ $option_name ] = $option_value;
  833. }
  834. }
  835. if ( isset( $settings['options'] ) ) {
  836. foreach ( $settings['options'] as $setting_option ) {
  837. if ( 'separator' !== $setting_option['type'] && isset( $setting_option['value'] ) && empty( $options[ $setting_option['name'] ] ) ) {
  838. $options[ $setting_option['name'] ] = 'checkbox' === $setting_option['type'] ? preg_split( '/\,/', $setting_option['value'] ) : $setting_option['value'];
  839. }
  840. if ( isset( $setting_option['name'] ) && isset( $options[ $setting_option['name'] ] ) && isset( $setting_option['value_type'] ) ) {
  841. if ( 'integer' === $setting_option['value_type'] ) {
  842. $options[ $setting_option['name'] ] = (int) $options[ $setting_option['name'] ];
  843. } elseif ( 'float' === $setting_option['value_type'] ) {
  844. $options[ $setting_option['name'] ] = (float) $options[ $setting_option['name'] ];
  845. } elseif ( 'boolean' === $setting_option['value_type'] ) {
  846. $options[ $setting_option['name'] ] = (bool) $options[ $setting_option['name'] ];
  847. }
  848. }
  849. }
  850. }
  851. return $options;
  852. }
  853. /**
  854. * Convert string to a valid css class name.
  855. *
  856. * @param string $class
  857. *
  858. * @return string
  859. * @since 4.3
  860. *
  861. */
  862. function vc_build_safe_css_class( $class ) {
  863. return preg_replace( '/\W+/', '', strtolower( str_replace( ' ', '_', wp_strip_all_tags( $class ) ) ) );
  864. }
  865. /**
  866. * Include template from templates dir.
  867. *
  868. * @param $template
  869. * @param array $variables - passed variables to the template.
  870. *
  871. * @param bool $once
  872. *
  873. * @return mixed
  874. * @since 4.3
  875. *
  876. */
  877. function vc_include_template( $template, $variables = array(), $once = false ) {
  878. is_array( $variables ) && extract( $variables );
  879. if ( $once ) {
  880. return require_once vc_template( $template );
  881. } else {
  882. return require vc_template( $template );
  883. }
  884. }
  885. /**
  886. * Output template from templates dir.
  887. *
  888. * @param $template
  889. * @param array $variables - passed variables to the template.
  890. *
  891. * @param bool $once
  892. *
  893. * @return string
  894. * @since 4.4
  895. *
  896. */
  897. function vc_get_template( $template, $variables = array(), $once = false ) {
  898. ob_start();
  899. vc_include_template( $template, $variables, $once );
  900. return ob_get_clean();
  901. }
  902. /**
  903. * if php version < 5.3 this function is required.
  904. */
  905. if ( ! function_exists( 'lcfirst' ) ) {
  906. /**
  907. * @param $str
  908. *
  909. * @return mixed
  910. * @since 4.3, fix #1093
  911. */
  912. function lcfirst( $str ) {
  913. $str[0] = function_exists( 'mb_strtolower' ) ? mb_strtolower( $str[0] ) : strtolower( $str[0] );
  914. return $str;
  915. }
  916. }
  917. /**
  918. * VC Convert a value to studly caps case.
  919. *
  920. * @param string $value
  921. *
  922. * @return string
  923. * @since 4.3
  924. *
  925. */
  926. function vc_studly( $value ) {
  927. $value = ucwords( str_replace( array(
  928. '-',
  929. '_',
  930. ), ' ', $value ) );
  931. return str_replace( ' ', '', $value );
  932. }
  933. /**
  934. * VC Convert a value to camel case.
  935. *
  936. * @param string $value
  937. *
  938. * @return string
  939. * @since 4.3
  940. *
  941. */
  942. function vc_camel_case( $value ) {
  943. return lcfirst( vc_studly( $value ) );
  944. }
  945. /**
  946. * Enqueue icon element font
  947. * @param $font
  948. * @since 4.4
  949. *
  950. * @todo move to separate folder
  951. */
  952. function vc_icon_element_fonts_enqueue( $font ) {
  953. switch ( $font ) {
  954. case 'fontawesome':
  955. wp_enqueue_style( 'font-awesome' );
  956. break;
  957. case 'openiconic':
  958. wp_enqueue_style( 'vc_openiconic' );
  959. break;
  960. case 'typicons':
  961. wp_enqueue_style( 'vc_typicons' );
  962. break;
  963. case 'entypo':
  964. wp_enqueue_style( 'vc_entypo' );
  965. break;
  966. case 'linecons':
  967. wp_enqueue_style( 'vc_linecons' );
  968. break;
  969. case 'monosocial':
  970. wp_enqueue_style( 'vc_monosocialiconsfont' );
  971. break;
  972. case 'material':
  973. wp_enqueue_style( 'vc_material' );
  974. break;
  975. default:
  976. do_action( 'vc_enqueue_font_icon_element', $font ); // hook to custom do enqueue style
  977. }
  978. }
  979. /**
  980. * Function merges defaults attributes in attributes by keeping it values
  981. *
  982. * Example
  983. * array defaults | array attributes | result array
  984. * 'color'=>'black', - 'color'=>'black',
  985. * 'target'=>'_self', 'target'=>'_blank', 'target'=>'_blank',
  986. * - 'link'=>'google.com' 'link'=>'google.com'
  987. *
  988. * @param array $defaults
  989. * @param array $attributes
  990. *
  991. * @return array - merged attributes
  992. *
  993. * @since 4.4
  994. *
  995. * @see vc_map_get_attributes
  996. */
  997. function vc_shortcode_attribute_parse( $defaults = array(), $attributes = array() ) {
  998. $atts = $attributes + shortcode_atts( $defaults, $attributes );
  999. return $atts;
  1000. }
  1001. /**
  1002. * @param string $tagregexp
  1003. * @return string
  1004. */
  1005. function vc_get_shortcode_regex( $tagregexp = '' ) {
  1006. if ( 0 === strlen( $tagregexp ) ) {
  1007. return get_shortcode_regex();
  1008. }
  1009. return '\\[' // Opening bracket
  1010. . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
  1011. . "($tagregexp)" // 2: Shortcode name
  1012. . '(?![\\w\-])' // Not followed by word character or hyphen
  1013. . '(' // 3: Unroll the loop: Inside the opening shortcode tag
  1014. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  1015. . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket
  1016. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  1017. . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ...
  1018. . '\\]' // ... and closing bracket
  1019. . '|' . '\\]' // Closing bracket
  1020. . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
  1021. . '[^\\[]*+' // Not an opening bracket
  1022. . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
  1023. . '[^\\[]*+' // Not an opening bracket
  1024. . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag
  1025. . ')?' . ')' . '(\\]?)';
  1026. }
  1027. /**
  1028. * Used to send warning message
  1029. *
  1030. * @param $message
  1031. *
  1032. * @return string
  1033. * @since 4.5
  1034. *
  1035. */
  1036. function vc_message_warning( $message ) {
  1037. return '<div class="wpb_element_wrapper"><div class="vc_message_box vc_message_box-standard vc_message_box-rounded vc_color-warning">
  1038. <div class="vc_message_box-icon"><i class="fa fa-exclamation-triangle"></i>
  1039. </div><p class="messagebox_text">' . $message . '</p>
  1040. </div></div>';
  1041. }
  1042. /**
  1043. * Extract video ID from youtube url
  1044. *
  1045. * @param string $url Youtube url
  1046. *
  1047. * @return string
  1048. */
  1049. function vc_extract_youtube_id( $url ) {
  1050. parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $vars );
  1051. if ( ! isset( $vars['v'] ) ) {
  1052. return '';
  1053. }
  1054. return $vars['v'];
  1055. }
  1056. /**
  1057. * @return string[]|\WP_Taxonomy[]
  1058. */
  1059. /**
  1060. * @return string[]|\WP_Taxonomy[]
  1061. */
  1062. /**
  1063. * @return string[]|\WP_Taxonomy[]
  1064. */
  1065. /**
  1066. * @return string[]|\WP_Taxonomy[]
  1067. */
  1068. /**
  1069. * @return string[]|\WP_Taxonomy[]
  1070. */
  1071. function vc_taxonomies_types( $post_type = null ) {
  1072. global $vc_taxonomies_types;
  1073. if ( is_null( $vc_taxonomies_types ) || $post_type ) {
  1074. $query = array( 'public' => true );
  1075. if ( $post_type ) {
  1076. $query['object_type'] = array( $post_type );
  1077. }
  1078. $vc_taxonomies_types = get_taxonomies( $query, 'objects' );
  1079. }
  1080. return $vc_taxonomies_types;
  1081. }
  1082. /**
  1083. * Since
  1084. *
  1085. * @param $term
  1086. *
  1087. * @return array
  1088. * @since 4.5.3
  1089. *
  1090. */
  1091. function vc_get_term_object( $term ) {
  1092. $vc_taxonomies_types = vc_taxonomies_types();
  1093. return array(
  1094. 'label' => $term->name,
  1095. 'value' => $term->term_id,
  1096. 'group_id' => $term->taxonomy,
  1097. 'group' => isset( $vc_taxonomies_types[ $term->taxonomy ], $vc_taxonomies_types[ $term->taxonomy ]->labels, $vc_taxonomies_types[ $term->taxonomy ]->labels->name ) ? $vc_taxonomies_types[ $term->taxonomy ]->labels->name : esc_html__( 'Taxonomies', 'js_composer' ),
  1098. );
  1099. }
  1100. /**
  1101. * Check if element has specific class
  1102. *
  1103. * E.g. f('foo', 'foo bar baz') -> true
  1104. *
  1105. * @param string $class Class to check for
  1106. * @param string $classes Classes separated by space(s)
  1107. *
  1108. * @return bool
  1109. */
  1110. function vc_has_class( $class, $classes ) {
  1111. return in_array( $class, explode( ' ', strtolower( $classes ), true ), true );
  1112. }
  1113. /**
  1114. * Remove specific class from classes string
  1115. *
  1116. * E.g. f('foo', 'foo bar baz') -> 'bar baz'
  1117. *
  1118. * @param string $class Class to remove
  1119. * @param string $classes Classes separated by space(s)
  1120. *
  1121. * @return string
  1122. */
  1123. function vc_remove_class( $class, $classes ) {
  1124. $list_classes = explode( ' ', strtolower( $classes ) );
  1125. $key = array_search( $class, $list_classes, true );
  1126. if ( false === $key ) {
  1127. return $classes;
  1128. }
  1129. unset( $list_classes[ $key ] );
  1130. return implode( ' ', $list_classes );
  1131. }
  1132. /**
  1133. * Convert array of named params to string version
  1134. * All values will be escaped
  1135. *
  1136. * E.g. f(array('name' => 'foo', 'id' => 'bar')) -> 'name="foo" id="bar"'
  1137. *
  1138. * @param $attributes
  1139. *
  1140. * @return string
  1141. */
  1142. function vc_stringify_attributes( $attributes ) {
  1143. $atts = array();
  1144. foreach ( $attributes as $name => $value ) {
  1145. $atts[] = $name . '="' . esc_attr( $value ) . '"';
  1146. }
  1147. return implode( ' ', $atts );
  1148. }
  1149. /**
  1150. * @return bool
  1151. */
  1152. /**
  1153. * @return bool
  1154. */
  1155. /**
  1156. * @return bool
  1157. */
  1158. /**
  1159. * @return bool
  1160. */
  1161. /**
  1162. * @return bool
  1163. */
  1164. function vc_is_responsive_disabled() {
  1165. $disable_responsive = vc_settings()->get( 'not_responsive_css' );
  1166. return '1' === $disable_responsive;
  1167. }
  1168. /**
  1169. * Do shortcode single render point
  1170. *
  1171. * @param $atts
  1172. * @param null $content
  1173. * @param null $tag
  1174. *
  1175. * @return string
  1176. * @throws \Exception
  1177. */
  1178. function vc_do_shortcode( $atts, $content = null, $tag = null ) {
  1179. return Vc_Shortcodes_Manager::getInstance()->getElementClass( $tag )->output( $atts, $content );
  1180. }
  1181. /**
  1182. * Return random string
  1183. *
  1184. * @param int $length
  1185. *
  1186. * @return string
  1187. */
  1188. function vc_random_string( $length = 10 ) {
  1189. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1190. $len = strlen( $characters );
  1191. $str = '';
  1192. for ( $i = 0; $i < $length; $i ++ ) {
  1193. $str .= $characters[ wp_rand( 0, $len - 1 ) ];
  1194. }
  1195. return $str;
  1196. }
  1197. /**
  1198. * @param $str
  1199. * @return string|string[]|null
  1200. */
  1201. /**
  1202. * @param $str
  1203. * @return string|string[]|null
  1204. */
  1205. /**
  1206. * @param $str
  1207. * @return string|string[]|null
  1208. */
  1209. /**
  1210. * @param $str
  1211. * @return string|string[]|null
  1212. */
  1213. /**
  1214. * @param $str
  1215. * @return string|string[]|null
  1216. */
  1217. function vc_slugify( $str ) {
  1218. $str = strtolower( $str );
  1219. $str = html_entity_decode( $str );
  1220. $str = preg_replace( '/[^\w ]+/', '', $str );
  1221. $str = preg_replace( '/ +/', '-', $str );
  1222. return $str;
  1223. }
  1224. /**
  1225. * WPBakery WPBakery Page Builder filter functions
  1226. *
  1227. * @package WPBakeryPageBuilder
  1228. */
  1229. /**
  1230. * This filter should be applied to all content elements titles
  1231. *
  1232. * $params['extraclass'] Extra class name will be added
  1233. *
  1234. *
  1235. * To override content element title default html markup, paste this code in your theme's functions.php file
  1236. * vc_filter: wpb_widget_title
  1237. * add_filter('wpb_widget_title', 'override_widget_title', 10, 2);
  1238. * function override_widget_title($output = '', $params = array('')) {
  1239. * $extraclass = (isset($params['extraclass'])) ? " ".$params['extraclass'] : "";
  1240. * return '<h1 class="entry-title'.$extraclass.'">'.$params['title'].'</h1>';
  1241. * }
  1242. *
  1243. * @param array $params
  1244. *
  1245. * @return mixed|string
  1246. */
  1247. function wpb_widget_title( $params = array( 'title' => '' ) ) {
  1248. if ( '' === $params['title'] ) {
  1249. return '';
  1250. }
  1251. $extraclass = ( isset( $params['extraclass'] ) ) ? ' ' . $params['extraclass'] : '';
  1252. $output = '<h2 class="wpb_heading' . esc_attr( $extraclass ) . '">' . esc_html( $params['title'] ) . '</h2>';
  1253. return apply_filters( 'wpb_widget_title', $output, $params );
  1254. }