GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-request-admin.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * The default Dashboard Request class.
11  */
12 class Admin_Request extends Request {
13  /**
14  * Check if WordPress is_admin(), and whether we have a GravityView page.
15  *
16  * @return bool If is in an admin context or not.
17  *
18  * Accepts optional $hook and $context arguments.
19  * @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`)
20  */
21  public static function is_admin() {
22  if ( ! parent::is_admin() ) {
23  return false;
24  }
25 
26  /**
27  * Regular check.
28  */
29  if ( ! ( $args = func_get_args() ) ) {
30  return true;
31  }
32 
33  $hook = \GV\Utils::get( $args, 0, '' );
34  $context = \GV\Utils::get( $args, 1, null );
35 
36  /**
37  * Assume false by default.
38  */
39  $is_page = false;
40 
41  if( function_exists( '\get_current_screen' ) || function_exists( 'get_current_screen' ) ) {
42  $current_screen = \get_current_screen();
43  } else {
44  $current_screen = false;
45  }
46 
47  if ( $current_screen && $current_screen->post_type == 'gravityview' ) {
48  if ( 'edit' === $current_screen->base ) {
49  $is_page = 'views';
50  } elseif ( 'post' === $current_screen->base ) {
51  $is_page = 'single';
52  } elseif( 'gravityview_page_gv-changelog' === $current_screen->id ) {
53  $is_page = 'changelog';
54  } elseif( 'gravityview_page_gv-getting-started' === $current_screen->id ) {
55  $is_page = 'getting-started';
56  } elseif( 'gravityview_page_gv-credits' === $current_screen->id ) {
57  $is_page = 'credits';
58  }
59  }
60 
61  /**
62  * @filter `gravityview_is_admin_page` Is the current admin page a GravityView-related page?
63  * @param string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`)
64  * @param string $hook The name of the page to check against. Is passed to the method.
65  */
66  $is_page = apply_filters( 'gravityview_is_admin_page', $is_page, $hook );
67 
68  // If the current page is the same as the compared page
69  if ( ! empty( $context ) ) {
70  return $is_page === $context;
71  }
72 
73  return $is_page;
74  }
75 }
If this file is called directly, abort.
If this file is called directly, abort.
static is_admin()
Check if WordPress is_admin(), and whether we have a GravityView page.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.