GravityView  2.10.1
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-admin-metaboxes.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Register and render the admin metaboxes for GravityView
5  */
7 
8  static $metaboxes_dir;
9 
10  /**
11  * @var int The post ID of the current View
12  */
13  var $post_id = 0;
14 
15  /**
16  *
17  */
18  function __construct() {
19 
21  return;
22  }
23 
24  self::$metaboxes_dir = GRAVITYVIEW_DIR . 'includes/admin/metaboxes/';
25 
26  include_once self::$metaboxes_dir . 'class-gravityview-metabox-tab.php';
27 
28  include_once self::$metaboxes_dir . 'class-gravityview-metabox-tabs.php';
29 
30  $this->initialize();
31 
32  }
33 
34  /**
35  * Add WordPress hooks
36  * @since 1.7.2
37  */
38  function initialize() {
39 
40  add_action( 'add_meta_boxes', array( $this, 'register_metaboxes' ) );
41 
42  add_action( 'add_meta_boxes_gravityview', array( $this, 'update_priority' ) );
43 
44  // information box
45  add_action( 'post_submitbox_misc_actions', array( $this, 'render_shortcode_hint' ) );
46  }
47 
48  /**
49  * GravityView wants to have the top (`normal`) metaboxes all to itself, so we move all plugin/theme metaboxes down to `advanced`
50  * @since 1.15.2
51  */
52  function update_priority() {
53  global $wp_meta_boxes;
54 
55  if ( ! empty( $wp_meta_boxes['gravityview'] ) ) {
56  foreach ( array( 'high', 'core', 'low' ) as $position ) {
57  if ( isset( $wp_meta_boxes['gravityview']['normal'][ $position ] ) ) {
58  foreach ( $wp_meta_boxes['gravityview']['normal'][ $position ] as $key => $meta_box ) {
59  if ( ! preg_match( '/^gravityview_/ism', $key ) ) {
60  $wp_meta_boxes['gravityview']['advanced'][ $position ][ $key ] = $meta_box;
61  unset( $wp_meta_boxes['gravityview']['normal'][ $position ][ $key ] );
62  }
63  }
64  }
65  }
66  }
67  }
68 
69  function register_metaboxes() {
70  global $post;
71 
72  // On Comment Edit, for example, $post isn't set.
73  if ( empty( $post ) || ! is_object( $post ) || ! isset( $post->ID ) ) {
74  return;
75  }
76 
77  // select data source for this view
78  add_meta_box( 'gravityview_select_form', $this->get_data_source_header( $post->ID ), array( $this, 'render_data_source_metabox' ), 'gravityview', 'normal', 'high' );
79 
80  // select view type/template
81  add_meta_box( 'gravityview_select_template', __( 'Choose a View Type', 'gravityview' ), array( $this, 'render_select_template_metabox' ), 'gravityview', 'normal', 'high' );
82 
83  // View Configuration box
84  add_meta_box( 'gravityview_view_config', __( 'Layout', 'gravityview' ), array( $this, 'render_view_configuration_metabox' ), 'gravityview', 'normal', 'high' );
85 
87 
88  // Other Settings box
89  add_meta_box( 'gravityview_settings', __( 'Settings', 'gravityview' ), array( $this, 'settings_metabox_render' ), 'gravityview', 'normal', 'core' );
90 
91  }
92 
93  /**
94  * Render the View Settings metabox
95  * @since 1.8
96  * @param WP_Post $post
97  */
99 
100  /**
101  * @action `gravityview/metaboxes/before_render` Before rendering GravityView metaboxes
102  * @since 1.8
103  * @param WP_Post $post
104  */
105  do_action( 'gravityview/metaboxes/before_render', $post );
106 
107  $metaboxes = GravityView_Metabox_Tabs::get_all();
108 
109  include self::$metaboxes_dir . 'views/gravityview-navigation.php';
110  include self::$metaboxes_dir . 'views/gravityview-content.php';
111 
112  /**
113  * @action `gravityview/metaboxes/after_render` After rendering GravityView metaboxes
114  * @since 1.8
115  * @param WP_Post $post
116  */
117  do_action( 'gravityview/metaboxes/after_render', $post );
118  }
119 
120  /**
121  * Add default tabs to the Settings metabox
122  * @since 1.8
123  */
124  private function add_settings_metabox_tabs() {
125 
126  $metaboxes = array(
127  array(
128  'id' => 'template_settings',
129  'title' => __( 'View Settings', 'gravityview' ),
130  'file' => 'view-settings.php',
131  'icon-class' => 'dashicons-admin-generic',
132  'callback' => '',
133  'callback_args' => '',
134  ),
135  array(
136  'id' => 'multiple_entries',
137  'title' => __( 'Multiple Entries', 'gravityview' ),
138  'file' => 'multiple-entries.php',
139  'icon-class' => 'dashicons-admin-page',
140  'callback' => '',
141  'callback_args' => '',
142  ),
143  array(
144  'id' => 'single_entry', // Use the same ID as View Settings for backward compatibility
145  'title' => __( 'Single Entry', 'gravityview' ),
146  'file' => 'single-entry.php',
147  'icon-class' => 'dashicons-media-default',
148  'callback' => '',
149  'callback_args' => '',
150  ),
151  array(
152  'id' => 'edit_entry', // Use the same ID as View Settings for backward compatibility
153  'title' => __( 'Edit Entry', 'gravityview' ),
154  'file' => 'edit-entry.php',
155  'icon-class' => 'dashicons-welcome-write-blog',
156  'callback' => '',
157  'callback_args' => '',
158  ),
159  array(
160  'id' => 'delete_entry',
161  'title' => __( 'Delete Entry', 'gravityview' ),
162  'file' => 'delete-entry.php',
163  'icon-class' => 'dashicons-trash',
164  'callback' => '',
165  'callback_args' => '',
166  ),
167  array(
168  'id' => 'sort_filter',
169  'title' => __( 'Filter &amp; Sort', 'gravityview' ),
170  'file' => 'sort-filter.php',
171  'icon-class' => 'dashicons-sort',
172  'callback' => '',
173  'callback_args' => '',
174  ),
175  array(
176  'id' => 'permissions', // Use the same ID as View Settings for backward compatibility
177  'title' => __( 'Permissions', 'gravityview' ),
178  'file' => 'permissions.php',
179  'icon-class' => 'dashicons-lock',
180  'callback' => '',
181  'callback_args' => '',
182  ),
183  );
184 
185  /**
186  * @filter `gravityview/metaboxes/default` Modify the default settings metabox tabs
187  * @param array $metaboxes
188  * @since 1.8
189  */
190  $metaboxes = apply_filters( 'gravityview/metaboxes/default', $metaboxes );
191 
192  foreach ( $metaboxes as $m ) {
193 
194  $tab = new GravityView_Metabox_Tab( $m['id'], $m['title'], $m['file'], $m['icon-class'], $m['callback'], $m['callback_args'] );
195 
197 
198  }
199 
200  unset( $tab );
201 
202  }
203 
204  /**
205  * Generate the title for Data Source, which includes the Action Links once configured.
206  *
207  * @since 1.8
208  *
209  * @param int $post_id ID of the current post
210  *
211  * @return string "Data Source", plus links if any
212  */
213  private function get_data_source_header( $post_id ) {
214 
215  //current value
217 
219 
220  if ( ! empty( $links ) ) {
221  $links = '<span class="alignright gv-form-links">' . $links . '</span>';
222  }
223 
224  return __( 'Data Source', 'gravityview' ) . $links;
225  }
226 
227  /**
228  * Render html for 'select form' metabox
229  *
230  * @param object $post
231  * @return void
232  */
233  public function render_data_source_metabox( $post ) {
234 
235  include self::$metaboxes_dir . 'views/data-source.php';
236 
237  }
238 
239  /**
240  * Render html for 'select template' metabox
241  *
242  * @param object $post
243  * @return void
244  */
246 
247  include self::$metaboxes_dir . 'views/select-template.php';
248  }
249 
250  /**
251  * Generate the script tags necessary for the Gravity Forms Merge Tag picker to work.
252  *
253  * @param int $curr_form Form ID
254  * @return null|string Merge tags html; NULL if $curr_form isn't defined.
255  */
256  public static function render_merge_tags_scripts( $curr_form ) {
257 
258  if ( empty( $curr_form ) ) {
259  return null;
260  }
261 
263 
264  $get_id_backup = isset( $_GET['id'] ) ? $_GET['id'] : null;
265 
266  if ( isset( $form['id'] ) ) {
267  $form_script = 'var form = ' . GFCommon::json_encode( $form ) . ';';
268 
269  // The `gf_vars()` method needs a $_GET[id] variable set with the form ID.
270  $_GET['id'] = $form['id'];
271 
272  } else {
273  $form_script = 'var form = new Form();';
274  }
275 
276  $output = '<script type="text/javascript" data-gv-merge-tags="1">' . $form_script . "\n" . GFCommon::gf_vars( false ) . '</script>';
277 
278  // Restore previous $_GET setting
279  $_GET['id'] = $get_id_backup;
280 
281  return $output;
282  }
283 
284  /**
285  * Render html for 'View Configuration' metabox
286  *
287  * @param mixed $post
288  * @return void
289  */
291 
292  // Use nonce for verification
293  wp_nonce_field( 'gravityview_view_configuration', 'gravityview_view_configuration_nonce' );
294 
295  // Selected Form
297 
298  $view = \GV\View::from_post( $post );
299 
300  // Selected template
301  $curr_template = gravityview_get_template_id( $post->ID );
302 
303  echo self::render_merge_tags_scripts( $curr_form );
304 
305  include self::$metaboxes_dir . 'views/view-configuration.php';
306  }
307 
308  /**
309  * Render html View General Settings
310  *
311  * @param object $post
312  * @return void
313  */
315 
316  // View template settings
318 
319  include self::$metaboxes_dir . 'views/view-settings.php';
320 
321  }
322 
323 
324 
325  /**
326  * Render shortcode hint in the Publish metabox
327  *
328  * @return void
329  */
331  global $post;
332 
333  // Only show this on GravityView post types.
334  if ( false === gravityview()->request->is_admin( '', null ) ) {
335  return;
336  }
337 
338  // If the View hasn't been configured yet, don't show embed shortcode
339  if ( ! gravityview_get_directory_fields( $post->ID ) && ! gravityview_get_directory_widgets( $post->ID ) ) {
340  return;
341  }
342 
343  include self::$metaboxes_dir . 'views/shortcode-hint.php';
344  }
345 
346 }
347 
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:40
static get_all()
Get array of all registered metaboxes.
static render_merge_tags_scripts( $curr_form)
Generate the script tags necessary for the Gravity Forms Merge Tag picker to work.
gravityview_get_directory_fields( $post_id, $apply_filter=true)
Get the field configuration for the View.
render_view_settings_metabox( $post)
Render html View General Settings.
render_view_configuration_metabox( $post)
Render html for &#39;View Configuration&#39; metabox.
static get_connected_form_links( $form, $include_form_link=true)
Get HTML links relating to a connected form, like Edit, Entries, Settings, Preview.
gravityview_get_form( $form_id)
Returns the form object for a given Form ID.
gravityview_get_directory_widgets( $post_id)
Get the widgets, as configured for a View.
gravityview_get_template_settings( $post_id)
Get all the settings for a View.
$curr_form
get_data_source_header( $post_id)
Generate the title for Data Source, which includes the Action Links once configured.
static is_valid()
Is everything compatible with this version of GravityView?
gravityview()
Definition: _stubs.php:26
render_select_template_metabox( $post)
Render html for &#39;select template&#39; metabox.
global $post
Definition: delete-entry.php:7
update_priority()
GravityView wants to have the top (normal) metaboxes all to itself, so we move all plugin/theme metab...
if(gravityview() ->plugin->is_GF_25()) $form
$current_settings
gravityview_get_form_id( $view_id)
Get the connected form ID from a View ID.
The class for a metabox tab in the GravityView View Settings metabox.
settings_metabox_render( $post)
Render the View Settings metabox.
Register and render the admin metaboxes for GravityView.
render_data_source_metabox( $post)
Render html for &#39;select form&#39; metabox.
gravityview_get_template_id( $post_id)
Get the template ID (list, table, datatables, map) for a View.
add_settings_metabox_tabs()
Add default tabs to the Settings metabox.
render_shortcode_hint()
Render shortcode hint in the Publish metabox.
$current_form
Definition: data-source.php:13
static add(GravityView_Metabox_Tab $meta_box)
Add a tab.
static from_post( $post)
Construct a instance from a .