gutenberg.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * @param $post
  7. * @return bool
  8. */
  9. function vcv_disable_gutenberg_for_classic_editor( $post ) {
  10. return false;
  11. }
  12. /**
  13. * @param \Vc_Settings $settings
  14. */
  15. function vc_gutenberg_add_settings( $settings ) {
  16. global $wp_version;
  17. if ( function_exists( 'the_gutenberg_project' ) || version_compare( $wp_version, '4.9.8', '>' ) ) {
  18. $settings->addField( 'general', esc_html__( 'Disable Gutenberg Editor', 'js_composer' ), 'gutenberg_disable', 'vc_gutenberg_sanitize_disable_callback', 'vc_gutenberg_disable_render_callback' );
  19. }
  20. }
  21. /**
  22. * @param $rules
  23. *
  24. * @return mixed
  25. */
  26. function vc_gutenberg_sanitize_disable_callback( $rules ) {
  27. return (bool) $rules;
  28. }
  29. /**
  30. * Not responsive checkbox callback function
  31. */
  32. function vc_gutenberg_disable_render_callback() {
  33. $checked = ( $checked = get_option( 'wpb_js_gutenberg_disable' ) ) ? $checked : false;
  34. ?>
  35. <label>
  36. <input type="checkbox"<?php echo esc_attr( $checked ) ? ' checked' : ''; ?> value="1"
  37. name="<?php echo 'wpb_js_gutenberg_disable' ?>">
  38. <?php esc_html_e( 'Disable', 'js_composer' ) ?>
  39. </label><br/>
  40. <p
  41. class="description indicator-hint"><?php esc_html_e( 'Disable Gutenberg Editor.', 'js_composer' ); ?></p>
  42. <?php
  43. }
  44. /**
  45. * @param $result
  46. * @param $postType
  47. * @return bool
  48. */
  49. function vc_gutenberg_check_disabled( $result, $postType ) {
  50. if ( 'wpb_gutenberg_param' === $postType ) {
  51. return true;
  52. }
  53. if ( ! isset( $_GET['vcv-gutenberg-editor'] ) && ( get_option( 'wpb_js_gutenberg_disable' ) || vc_is_wpb_content() || isset( $_GET['classic-editor'] ) ) ) {
  54. return false;
  55. }
  56. return $result;
  57. }
  58. /**
  59. * @return bool
  60. */
  61. function vc_is_wpb_content() {
  62. $post = get_post();
  63. if ( ! empty( $post ) && isset( $post->post_content ) && preg_match( '/\[vc_row/', $post->post_content ) ) {
  64. return true;
  65. }
  66. return false;
  67. }
  68. function vc_gutenberg_map() {
  69. global $wp_version;
  70. if ( function_exists( 'the_gutenberg_project' ) || version_compare( $wp_version, '4.9.8', '>' ) ) {
  71. vc_lean_map( 'vc_gutenberg', null, dirname( __FILE__ ) . '/shortcode-vc-gutenberg.php' );
  72. }
  73. }
  74. add_filter( 'use_block_editor_for_post_type', 'vc_gutenberg_check_disabled', 10, 2 );
  75. add_action( 'vc_settings_tab-general', 'vc_gutenberg_add_settings' );
  76. add_action( 'init', 'vc_gutenberg_map' );
  77. /** @see include/params/gutenberg/class-vc-gutenberg-param.php */
  78. require_once vc_path_dir( 'PARAMS_DIR', 'gutenberg/class-vc-gutenberg-param.php' );
  79. new Vc_Gutenberg_Param();