GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-admin.php
Go to the documentation of this file.
1 <?php
2 
4 
5  function __construct() {
6 
7  if( ! is_admin() ) { return; }
8 
9  // If Gravity Forms isn't active or compatibile, stop loading
10  if( false === gravityview()->plugin->is_compatible() ) {
11  return;
12  }
13 
14  $this->include_required_files();
15  $this->add_hooks();
16  }
17 
18  /**
19  * @since 1.15
20  * @return void
21  */
22  private function include_required_files() {
23  require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-migrate.php' );
24  require_once( GRAVITYVIEW_DIR . 'includes/admin/metaboxes/class-gravityview-admin-metaboxes.php' );
25  require_once( GRAVITYVIEW_DIR . 'includes/admin/entry-list.php' );
26  require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
27  require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-support-port.php' );
28  require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-duplicate-view.php' );
29  require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-admin-no-conflict.php' );
30  require_once( GRAVITYVIEW_DIR . 'includes/class-admin-welcome.php' );
31  }
32 
33  /**
34  * @since 1.7.5
35  * @return void
36  */
37  private function add_hooks() {
38 
39  // Filter Admin messages
40  add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
41  add_filter( 'bulk_post_updated_messages', array( $this, 'post_updated_messages' ) );
42 
43  add_action( 'plugins_loaded', array( $this, 'backend_actions' ), 100 );
44 
45  add_action( 'gravityview/metaboxes/data-source/before', array( 'GravityView_Admin', 'connected_form_warning' ) );
46  }
47 
48  /**
49  * Get text for no views found.
50  *
51  * @since 1.18 Moved to GravityView_Admin
52  *
53  * @return string HTML message with no container tags.
54  */
55  public static function no_views_text() {
56 
57  if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
58  return esc_html__( 'No Views found in Trash', 'gk-gravityview' );
59  } elseif( ! empty( $_GET['s'] ) ) {
60  return esc_html__( 'No Views found.', 'gk-gravityview' );
61  }
62 
63  // Floaty the Astronaut says "oi"
64  $image = self::get_floaty();
65 
66  if ( GVCommon::has_cap( 'edit_gravityviews' ) ) {
67  $output = sprintf( esc_attr__( "%sYou don't have any active views. Let&rsquo;s go %screate one%s!%s\n\nIf you feel like you're lost in space and need help getting started, check out the %sGetting Started%s page.", 'gk-gravityview' ), '<h3>', '<a href="' . admin_url( 'post-new.php?post_type=gravityview' ) . '">', '</a>', '</h3>', '<a href="' . admin_url( 'edit.php?post_type=gravityview&page=gv-getting-started' ) . '">', '</a>' );
68  } else {
69  $output = esc_attr__( 'There are no active Views', 'gk-gravityview' );
70  }
71 
72  return $image . wpautop( $output );
73  }
74 
75  /**
76  * Display error HTML in Edit View when the form is in the trash or no longer exists in Gravity Forms
77  *
78  * @since 1.19
79  *
80  * @param int $form_id Gravity Forms
81  *
82  * @return void
83  */
84  public static function connected_form_warning( $form_id = 0 ) {
85  global $pagenow;
86 
87  if ( empty( $form_id ) || $pagenow === 'post-new.php' ) {
88  return;
89  }
90 
91  $form_info = GFFormsModel::get_form( $form_id, true );
92 
93  $error = '';
94  if ( empty( $form_info ) ) {
95  $error = esc_html__( 'The form connected to this View no longer exists.', 'gk-gravityview' );
96  $error .= ' ' . esc_html__( 'Select another form as the data source for this View.', 'gk-gravityview' );
97  } elseif ( $form_info->is_trash ) {
98  $error = esc_html__( 'The connected form is in the trash.', 'gk-gravityview' );
99  $error .= ' ' . gravityview_get_link( admin_url( 'admin.php?page=gf_edit_forms&filter=trash&s=' . $form_info->title ), esc_html__( 'Restore the form from the trash', 'gk-gravityview' ) );
100  $error .= ' ' . esc_html__( 'or select another form.', 'gk-gravityview' );
101  }
102 
103  if( $error ) {
104  ?>
105  <div class="wp-dialog notice-warning inline error wp-clearfix">
106  <?php echo gravityview_get_floaty(); ?>
107  <h3><?php echo $error; ?></h3>
108  </div>
109  <?php
110  }
111 
112  remove_action( 'gravityview/metaboxes/data-source/before', array( 'GravityView_Admin', 'connected_form_warning' ) );
113  }
114 
115  /**
116  * Function to launch admin objects
117  *
118  * @return void
119  */
120  public function backend_actions() {
121 
122  /** @define "GRAVITYVIEW_DIR" "../" */
123  include_once( GRAVITYVIEW_DIR .'includes/admin/class.field.type.php' );
124  include_once( GRAVITYVIEW_DIR .'includes/admin/class.render.settings.php' );
125  include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-item.php' );
126  include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-field.php' );
127  include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-widget.php' );
128  include_once( GRAVITYVIEW_DIR .'includes/class-admin-views.php' );
129  include_once( GRAVITYVIEW_DIR .'includes/class-admin-welcome.php' );
130  include_once( GRAVITYVIEW_DIR .'includes/class-admin-add-shortcode.php' );
131  include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
132  include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-bulk-actions.php' );
133 
134  /**
135  * @action `gravityview_include_backend_actions` Triggered after all GravityView admin files are loaded
136  *
137  * Nice place to insert extensions' backend stuff
138  */
139  do_action('gravityview_include_backend_actions');
140  }
141 
142  /**
143  * Get an image of our intrepid explorer friend
144  * @return string HTML image tag with floaty's cute mug on it
145  */
146  public static function get_floaty() {
147  return gravityview_get_floaty();
148  }
149 
150  /**
151  * Filter Admin messages
152  *
153  * @param array $messages Existing messages
154  * @return array Messages with GravityView views!
155  */
156  function post_updated_messages( $messages, $bulk_counts = NULL ) {
157  global $post;
158 
159  $post_id = get_the_ID();
160 
161  // By default, there will only be one item being modified.
162  // When in the `bulk_post_updated_messages` filter, there will be passed a number
163  // of modified items that will override this array.
164  $bulk_counts = is_null( $bulk_counts ) ? array( 'updated' => 1 , 'locked' => 1 , 'deleted' => 1 , 'trashed' => 1, 'untrashed' => 1 ) : $bulk_counts;
165 
166  // If we're starting fresh, a new form was created.
167  // We should let the user know this is the case.
168  $start_fresh = get_post_meta( $post_id, '_gravityview_start_fresh', true );
169 
170  $new_form_text = '';
171 
172  if( !empty( $start_fresh ) ) {
173 
174  // Get the form that was created
175  $connected_form = gravityview_get_form_id( $post_id );
176 
177  if( !empty( $connected_form ) ) {
178  $form = gravityview_get_form( $connected_form );
179  $form_name = esc_attr( $form['title'] );
180  $image = self::get_floaty();
181  $new_form_text .= '<h3>'.$image.sprintf( __( 'A new form was created for this View: "%s"', 'gk-gravityview' ), $form_name ).'</h3>';
182  $new_form_text .= sprintf( __( '%sThere are no entries for the new form, so the View will also be empty.%s To start collecting entries, you can add submissions through %sthe preview form%s and also embed the form on a post or page using this code: %s
183 
184  You can %sedit the form%s in Gravity Forms and the updated fields will be available here. Don&rsquo;t forget to %scustomize the form settings%s.
185  ', 'gk-gravityview' ), '<strong>', '</strong>', '<a href="'.site_url( '?gf_page=preview&amp;id='.$connected_form ).'">', '</a>', '<code>[gravityform id="'.$connected_form.'" name="'.$form_name.'"]</code>', '<a href="'.admin_url( 'admin.php?page=gf_edit_forms&amp;id='.$connected_form ).'">', '</a>', '<a href="'.admin_url( 'admin.php?page=gf_edit_forms&amp;view=settings&amp;id='.$connected_form ).'">', '</a>');
186  $new_form_text = wpautop( $new_form_text );
187 
188  delete_post_meta( $post_id, '_gravityview_start_fresh' );
189  }
190  }
191 
192  $messages['gravityview'] = array(
193  0 => '', // Unused. Messages start at index 1.
194  /* translators: %s and %s are HTML tags linking to the View on the website */
195  1 => sprintf(__( 'View updated. %sView on website.%s', 'gk-gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
196  /* translators: %s and %s are HTML tags linking to the View on the website */
197  2 => sprintf(__( 'View updated. %sView on website.%s', 'gk-gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
198  3 => __( 'View deleted.', 'gk-gravityview' ),
199  /* translators: %s and %s are HTML tags linking to the View on the website */
200  4 => sprintf(__( 'View updated. %sView on website.%s', 'gk-gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
201  /* translators: %s: date and time of the revision */
202  5 => isset( $_GET['revision'] ) ? sprintf( __( 'View restored to revision from %s', 'gk-gravityview' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
203  /* translators: %s and %s are HTML tags linking to the View on the website */
204  6 => sprintf(__( 'View published. %sView on website.%s', 'gk-gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text,
205  /* translators: %s and %s are HTML tags linking to the View on the website */
206  7 => sprintf(__( 'View saved. %sView on website.%s', 'gk-gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text,
207  8 => __( 'View submitted.', 'gk-gravityview' ),
208  9 => sprintf(
209  /* translators: Date and time the View is scheduled to be published */
210  __( 'View scheduled for: %1$s.', 'gk-gravityview' ),
211  // translators: Publish box date format, see http://php.net/date
212  date_i18n( __( 'M j, Y @ G:i', 'gk-gravityview' ), strtotime( ( isset( $post->post_date ) ? $post->post_date : NULL ) ) )
213  ) . $new_form_text,
214  /* translators: %s and %s are HTML tags linking to the View on the website */
215  10 => sprintf(__( 'View draft updated. %sView on website.%s', 'gk-gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text,
216 
217  /**
218  * These apply to `bulk_post_updated_messages`
219  * @file wp-admin/edit.php
220  */
221  'updated' => _n( '%s View updated.', '%s Views updated.', $bulk_counts['updated'], 'gk-gravityview' ),
222  'locked' => _n( '%s View not updated, somebody is editing it.', '%s Views not updated, somebody is editing them.', $bulk_counts['locked'], 'gk-gravityview' ),
223  'deleted' => _n( '%s View permanently deleted.', '%s Views permanently deleted.', $bulk_counts['deleted'], 'gk-gravityview' ),
224  'trashed' => _n( '%s View moved to the Trash.', '%s Views moved to the Trash.', $bulk_counts['trashed'], 'gk-gravityview' ),
225  'untrashed' => _n( '%s View restored from the Trash.', '%s Views restored from the Trash.', $bulk_counts['untrashed'], 'gk-gravityview' ),
226  );
227 
228  return $messages;
229  }
230 
231 
232  /**
233  * Get admin notices
234  * @deprecated since 1.12
235  * @return array
236  */
237  public static function get_notices() {
239  }
240 
241  /**
242  * Add a notice to be displayed in the admin.
243  * @deprecated since 1.12
244  * @param array $notice Array with `class` and `message` keys. The message is not escaped.
245  */
246  public static function add_notice( $notice = array() ) {
248  }
249 
250  /**
251  * Check if Gravity Forms plugin is active and show notice if not.
252  *
253  * @deprecated since 1.12
254  * @see GravityView_Compatibility::get_plugin_status()
255  * @return boolean True: checks have been passed; GV is fine to run; False: checks have failed, don't continue loading
256  */
257  public static function check_gravityforms() {
259  }
260 
261  /**
262  * Check if specified plugin is active, inactive or not installed
263  *
264  * @deprecated since 1.12
265  * @see GravityView_Compatibility::get_plugin_status()
266 
267  * @return boolean|string True: plugin is active; False: plugin file doesn't exist at path; 'inactive' it's inactive
268  */
269  static function get_plugin_status( $location = '' ) {
271  }
272 
273  /**
274  * Is the current admin page a GravityView-related page?
275  *
276  * @deprecated See `gravityview()->request->is_admin` or `\GV\Request::is_admin`
277  * @param string $hook
278  * @param null|string $page Optional. String return value of page to compare against.
279  *
280  * @return bool|string If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`)
281  */
282  static function is_admin_page( $hook = '', $page = NULL ) {
283  gravityview()->log->warning( 'The \GravityView_Admin::is_admin_page() method is deprecated. Use gravityview()->request->is_admin' );
284  return gravityview()->request->is_admin( $hook, $page );
285  }
286 }
287 
289 
290 /**
291  * Former alias for GravityView_Admin::is_admin_page()
292  *
293  * @param string $hook
294  * @param null|string $page Optional. String return value of page to compare against.
295  *
296  * @deprecated See `gravityview()->request->is_admin` or `\GV\Request::is_admin`
297  *
298  * @return bool|string If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`)
299  */
300 function gravityview_is_admin_page( $hook = '', $page = NULL ) {
301  gravityview()->log->warning( 'The gravityview_is_admin_page() function is deprecated. Use gravityview()->request->is_admin' );
302  return gravityview()->request->is_admin( $hook, $page );
303 }
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:49
$image
Definition: post_image.php:98
gravityview_get_floaty( $height=87, $css_class=null)
Get an image of our intrepid explorer friend.
static get_notices()
Get admin notices.
gravityview_get_form( $form_id)
Returns the form object for a given Form ID.
gravityview_is_admin_page( $hook='', $page=NULL)
Former alias for GravityView_Admin::is_admin_page()
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
new GravityView_Admin
static check_gravityforms()
Check if Gravity Forms plugin is active and show notice if not.
backend_actions()
Function to launch admin objects.
global $post
Definition: delete-entry.php:7
if(gravityview() ->plugin->is_GF_25()) $form
static get_plugin_status( $location='')
Check if specified plugin is active, inactive or not installed.
static no_views_text()
Get text for no views found.
Definition: class-admin.php:55
static is_admin_page( $hook='', $page=NULL)
Is the current admin page a GravityView-related page?
gravityview_get_form_id( $view_id)
Get the connected form ID from a View ID.
static get_plugin_status( $location='')
Check if specified plugin is active, inactive or not installed.
static check_gravityforms()
Check if Gravity Forms plugin is active and show notice if not.
static connected_form_warning( $form_id=0)
Display error HTML in Edit View when the form is in the trash or no longer exists in Gravity Forms...
Definition: class-admin.php:84
static add_notice( $notice=array())
Add a notice to be displayed in the admin.
if(empty( $created_by)) $form_id
static add_notice( $notice=array())
Add a notice to be displayed in the admin.
static get_floaty()
Get an image of our intrepid explorer friend.
gravityview()
The main GravityView wrapper function.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
static get_notices()
Get admin notices.