GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-plugin-hooks-elegant-themes.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Add Elegant Themes compatibility to GravityView (Divi theme)
4  *
5  * @file class-gravityview-theme-hooks-elegant-themes.php
6  * @package GravityView
7  * @license GPL2+
8  * @author Katz Web Services, Inc.
9  * @link http://gravityview.co
10  * @copyright Copyright 2016', Katz Web Services, Inc.
11  *
12  * @since 1.17.2
13  */
14 
15 /**
16  * @inheritDoc
17  * @since 1.17.2
18  */
20 
21  /**
22  * @inheritDoc
23  * @since 1.17.2
24  */
25  protected $function_name = 'et_setup_theme';
26 
27  function add_hooks() {
28  parent::add_hooks();
29 
30  add_action( 'admin_init', array( $this, 'add_hooks_admin_init' ), 1 );
31  }
32 
33  /**
34  * Prevent Divi from adding their stuff to GV pages
35  */
36  public function add_hooks_admin_init() {
37  if ( gravityview()->request->is_admin( '', null ) ) {
38  // Prevent Divi from adding import/export modal dialog
39  remove_action( 'admin_init', 'et_pb_register_builder_portabilities' );
40 
41  // Divi theme adds their quicktag shortcode buttons on a View CPT. This causes JS errors.
42  remove_action( 'admin_head', 'et_add_simple_buttons' );
43  }
44 
45  // Prevent Divi from rendering the sidebar with one of our Widgets in Page Builder.
46  // See: https://github.com/gravityview/GravityView/issues/914
47  add_action( 'et_pb_admin_excluded_shortcodes', array( $this, 'maybe_admin_excluded_shortcodes' ) );
48  }
49 
50  /**
51  * Maybe prevent Divi (and others) from rendering our Widgets in the Page Builders Sidebar widget.
52  *
53  * Divi (among others) tries to render all the widgets in the sidebar.
54  * Our Widgets are not designed to be rendered in the administration panel.
55  *
56  * Try to find the sidebar it wants to render, see if it contains our Widgets
57  * and prevent it from being rendered if it does. Allow everything else through.
58  *
59  * @see https://github.com/gravityview/GravityView/issues/914
60  *
61  * @param array $shortcodes The shortcodes that should not be rendered in the Page Builder.
62  *
63  * @return array The shortcodes that should not be rendered in the Page Builder.
64  */
65  public function maybe_admin_excluded_shortcodes( $shortcodes ) {
66  global $post;
67 
68  if ( ! $post || ! $post->post_content ) {
69  return $shortcodes;
70  }
71 
72  /**
73  * Find the et_pb_sidebar shortcode and the area it's assigned to.
74  */
75  preg_match( '#\[et_pb_sidebar .*area="(.*?)"#', $post->post_content, $matches );
76 
77  if ( count( $matches ) != 2 ) {
78  return $shortcodes;
79  }
80 
81  $sidebars_widgets = wp_get_sidebars_widgets();
82  if ( empty( $sidebars_widgets[ $matches[1] ] ) ) {
83  return $shortcodes;
84  }
85 
86  foreach ( $sidebars_widgets[ $matches[1] ] as $widgets ) {
87  if (
88  /**
89  * Blacklisted widgets.
90  */
91  strpos( $widgets, 'gravityview_search' ) === 0 ||
92  strpos( $widgets, 'gv_recent_entries' ) === 0
93  ) {
94 
95  $shortcodes []= 'et_pb_sidebar';
96  break;
97  }
98  }
99 
100  return $shortcodes;
101  }
102 }
103 
gravityview()
Definition: _stubs.php:26
add_hooks_admin_init()
Prevent Divi from adding their stuff to GV pages.
global $post
maybe_admin_excluded_shortcodes( $shortcodes)
Maybe prevent Divi (and others) from rendering our Widgets in the Page Builders Sidebar widget...
Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles...