page-design-options.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * Used to check for current less version during page open
  7. *
  8. * @since 4.5
  9. */
  10. add_action( 'vc_before_init', 'vc_check_for_custom_css_build' );
  11. /**
  12. * Function check is system has custom build of css
  13. * and check it version in comparison with current VC version
  14. *
  15. * @since 4.5
  16. */
  17. function vc_check_for_custom_css_build() {
  18. $version = vc_settings()->getCustomCssVersion();
  19. if ( vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-color-tab' )
  20. ->get() && vc_settings()->useCustomCss() && ( ! $version || version_compare( WPB_VC_VERSION, $version, '<>' ) ) ) {
  21. add_action( 'admin_notices', 'vc_custom_css_admin_notice' );
  22. }
  23. }
  24. /**
  25. * Display admin notice depending on current page
  26. *
  27. * @since 4.5
  28. */
  29. function vc_custom_css_admin_notice() {
  30. global $current_screen;
  31. vc_settings()->set( 'compiled_js_composer_less', '' );
  32. $class = 'notice notice-warning vc_settings-custom-design-notice';
  33. $message_important = esc_html__( 'Important notice', 'js_composer' );
  34. if ( is_object( $current_screen ) && isset( $current_screen->id ) && 'visual-composer_page_vc-color' === $current_screen->id ) {
  35. $message = esc_html__( 'You have an outdated version of WPBakery Page Builder Design Options. It is required to review and save it.', 'js_composer' );
  36. echo '<div class="' . esc_attr( $class ) . '"><p><strong>' . esc_html( $message_important ) . '</strong>: ' . esc_html( $message ) . '</p></div>';
  37. } else {
  38. $message = esc_html__( 'You have an outdated version of WPBakery Page Builder Design Options. It is required to review and save it.', 'js_composer' );
  39. $btnClass = 'button button-primary button-large vc_button-settings-less';
  40. echo '<div class="' . esc_attr( $class ) . '"><p><strong>' . esc_html( $message_important ) . '</strong>: ' . esc_html( $message ) . '</p>' . '<p>';
  41. echo '<a ' . implode( ' ', array(
  42. 'href="' . esc_url( admin_url( 'admin.php?page=vc-color' ) ) . '"',
  43. 'class="' . esc_attr( $btnClass ) . '"',
  44. 'id="vc_less-save-button"',
  45. 'style="vertical-align: baseline;"',
  46. // needed to fix ":active bug"
  47. ) ) . '>';
  48. echo esc_html__( 'Open Design Options', 'js_composer' ) . '</a>';
  49. echo '</p></div>';
  50. }
  51. }
  52. /**
  53. * @param $submitButtonAttributes
  54. * @return mixed
  55. */
  56. function vc_page_settings_tab_color_submit_attributes( $submitButtonAttributes ) {
  57. $submitButtonAttributes['data-vc-less-path'] = vc_str_remove_protocol( vc_asset_url( 'less/js_composer.less' ) );
  58. $submitButtonAttributes['data-vc-less-root'] = vc_str_remove_protocol( vc_asset_url( 'less' ) );
  59. $submitButtonAttributes['data-vc-less-variables'] = wp_json_encode( apply_filters( 'vc_settings-less-variables', array(
  60. // Main accent color:
  61. 'vc_grey' => array(
  62. 'key' => 'wpb_js_vc_color',
  63. 'default' => vc_settings()->getDefault( 'vc_color' ),
  64. ),
  65. // Hover color
  66. 'vc_grey_hover' => array(
  67. 'key' => 'wpb_js_vc_color_hover',
  68. 'default' => vc_settings()->getDefault( 'vc_color_hover' ),
  69. ),
  70. 'vc_image_slider_link_active' => 'wpb_js_vc_color_hover',
  71. // Call to action background color
  72. 'vc_call_to_action_bg' => 'wpb_js_vc_color_call_to_action_bg',
  73. 'vc_call_to_action_2_bg' => 'wpb_js_vc_color_call_to_action_bg',
  74. 'vc_call_to_action_border' => array(
  75. 'key' => 'wpb_js_vc_color_call_to_action_border',
  76. // darken 5%
  77. 'default_key' => 'wpb_js_vc_color',
  78. 'modify_output' => array(
  79. array(
  80. 'plain' => array(
  81. 'darken({{ value }}, 5%)',
  82. ),
  83. ),
  84. ),
  85. ),
  86. // Google maps background color
  87. 'vc_google_maps_bg' => 'wpb_js_vc_color_google_maps_bg',
  88. // Post slider caption background color
  89. 'vc_post_slider_caption_bg' => 'wpb_js_vc_color_post_slider_caption_bg',
  90. // Progress bar background color
  91. 'vc_progress_bar_bg' => 'wpb_js_vc_color_progress_bar_bg',
  92. // Separator border color
  93. 'vc_separator_border' => 'wpb_js_vc_color_separator_border',
  94. // Tabs navigation background color
  95. 'vc_tab_bg' => 'wpb_js_vc_color_tab_bg',
  96. // Active tab background color
  97. 'vc_tab_bg_active' => 'wpb_js_vc_color_tab_bg_active',
  98. // Elements bottom margin
  99. 'vc_element_margin_bottom' => array(
  100. 'key' => 'wpb_js_margin',
  101. 'default' => vc_settings()->getDefault( 'margin' ),
  102. ),
  103. // Grid gutter width
  104. 'grid-gutter-width' => array(
  105. 'key' => 'wpb_js_gutter',
  106. 'default' => vc_settings()->getDefault( 'gutter' ),
  107. 'modify_output' => array(
  108. array(
  109. 'plain' => array(
  110. '{{ value }}px',
  111. ),
  112. ),
  113. ),
  114. ),
  115. 'screen-sm-min' => array(
  116. 'key' => 'wpb_js_responsive_max',
  117. 'default' => vc_settings()->getDefault( 'responsive_max' ),
  118. 'modify_output' => array(
  119. array(
  120. 'plain' => array(
  121. '{{ value }}px',
  122. ),
  123. ),
  124. ),
  125. ),
  126. ) ) );
  127. return $submitButtonAttributes;
  128. }
  129. function vc_page_settings_desing_options_load() {
  130. add_filter( 'vc_settings-tab-submit-button-attributes-color', 'vc_page_settings_tab_color_submit_attributes' );
  131. wp_enqueue_script( 'vc_less_js', vc_asset_url( 'lib/bower/lessjs/dist/less.min.js' ), array(), WPB_VC_VERSION, true );
  132. }
  133. add_action( 'vc-settings-render-tab-vc-color', 'vc_page_settings_desing_options_load' );