params-to-init.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. add_filter( 'vc_edit_form_fields_optional_params', 'vc_edit_for_fields_add_optional_params' );
  6. if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
  7. add_filter( 'vc_edit_form_fields_after_render', 'vc_output_required_params_to_init' );
  8. add_filter( 'vc_edit_form_fields_optional_params', 'vc_edit_for_fields_add_optional_params' );
  9. }
  10. /**
  11. * @param $params
  12. * @return array
  13. */
  14. function vc_edit_for_fields_add_optional_params( $params ) {
  15. $arr = array(
  16. 'hidden',
  17. 'textfield',
  18. 'dropdown',
  19. 'checkbox',
  20. 'posttypes',
  21. 'taxonomies',
  22. 'taxomonies',
  23. 'exploded_textarea',
  24. 'textarea_raw_html',
  25. 'textarea_safe',
  26. 'textarea',
  27. 'attach_images',
  28. 'attach_image',
  29. 'widgetised_sidebars',
  30. 'colorpicker',
  31. 'loop',
  32. 'vc_link',
  33. 'sorted_list',
  34. 'tab_id',
  35. 'href',
  36. 'custom_markup',
  37. 'animation_style',
  38. 'iconpicker',
  39. 'el_id',
  40. 'vc_grid_item',
  41. 'google_fonts',
  42. );
  43. $params = array_values( array_unique( array_merge( $params, $arr ) ) );
  44. return $params;
  45. }
  46. function vc_output_required_params_to_init( $output ) {
  47. $params = WpbakeryShortcodeParams::getRequiredInitParams();
  48. $js_array = array();
  49. foreach ( $params as $param ) {
  50. $js_array[] = '"' . $param . '"';
  51. }
  52. $data = '
  53. if ( window.vc ) {
  54. window.vc.required_params_to_init = [' . implode( ',', $js_array ) . '];
  55. }';
  56. $custom_tag = 'script';
  57. $output .= '<' . $custom_tag . '>' . $data . '</' . $custom_tag . '>';
  58. return $output;
  59. }
  60. add_action( 'wp_ajax_wpb_gallery_html', 'vc_gallery_html' );
  61. function vc_gallery_html() {
  62. vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie();
  63. $images = vc_post_param( 'content' );
  64. if ( ! empty( $images ) ) {
  65. wp_send_json_success( vc_field_attached_images( explode( ',', $images ) ) );
  66. }
  67. die();
  68. }