GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-post-types.php
Go to the documentation of this file.
1 <?php
2 /**
3  * GravityView Defining Post Types and Rewrite rules
4  *
5  * @package GravityView
6  * @license GPL2+
7  * @author Katz Web Services, Inc.
8  * @link http://gravityview.co
9  * @copyright Copyright 2014, Katz Web Services, Inc.
10  * @deprecated
11  *
12  * @since 1.0.9
13  */
14 
16 
17  function __construct() {
18  /** Deprecated. Handled by \GV\Core from here on after. */
19  if ( function_exists( 'gravityview' ) ) {
20  return;
21  }
22 
23  // Load custom post types. It's a static method.
24  // Load even when invalid to allow for export
25  add_action( 'init', array( 'GravityView_Post_Types', 'init_post_types' ) );
26 
28  add_action( 'init', array( 'GravityView_Post_Types', 'init_rewrite' ) );
29  }
30  }
31 
32  /**
33  * Init plugin components such as register own custom post types
34  *
35  * @access public
36  * @deprecated
37  * @see \GV\View::register_post_type
38  * @return void
39  */
40  public static function init_post_types() {
41 
42  if ( function_exists( 'gravityview' ) ) {
43  return \GV\View::register_post_type();
44  }
45 
46  /**
47  * @filter `gravityview_is_hierarchical` Make GravityView Views hierarchical by returning TRUE
48  * This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox
49  * @since 1.13
50  * @param boolean $is_hierarchical Default: false
51  */
52  $is_hierarchical = (bool)apply_filters( 'gravityview_is_hierarchical', false );
53 
54  $supports = array( 'title', 'revisions' );
55 
56  if( $is_hierarchical ) {
57  $supports[] = 'page-attributes';
58  }
59 
60  /**
61  * @filter `gravityview_post_type_supports` Modify post type support values for `gravityview` post type
62  * @see add_post_type_support()
63  * @since 1.15.2
64  * @param array $supports Array of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes'
65  * @param[in] boolean $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter.
66  */
67  $supports = apply_filters( 'gravityview_post_type_support', $supports, $is_hierarchical );
68 
69  //Register Custom Post Type - gravityview
70  $labels = array(
71  'name' => _x( 'Views', 'Post Type General Name', 'gravityview' ),
72  'singular_name' => _x( 'View', 'Post Type Singular Name', 'gravityview' ),
73  'menu_name' => _x( 'Views', 'Menu name', 'gravityview' ),
74  'parent_item_colon' => __( 'Parent View:', 'gravityview' ),
75  'all_items' => __( 'All Views', 'gravityview' ),
76  'view_item' => _x( 'View', 'View Item', 'gravityview' ),
77  'add_new_item' => __( 'Add New View', 'gravityview' ),
78  'add_new' => __( 'New View', 'gravityview' ),
79  'edit_item' => __( 'Edit View', 'gravityview' ),
80  'update_item' => __( 'Update View', 'gravityview' ),
81  'search_items' => __( 'Search Views', 'gravityview' ),
82  'not_found' => GravityView_Admin::no_views_text(),
83  'not_found_in_trash' => __( 'No Views found in Trash', 'gravityview' ),
84  'filter_items_list' => __( 'Filter Views list', 'gravityview' ),
85  'items_list_navigation' => __( 'Views list navigation', 'gravityview' ),
86  'items_list' => __( 'Views list', 'gravityview' ),
87  'view_items' => __( 'See Views', 'gravityview' ),
88  'attributes' => __( 'View Attributes', 'gravityview' ),
89  );
90  $args = array(
91  'label' => __( 'view', 'gravityview' ),
92  'description' => __( 'Create views based on a Gravity Forms form', 'gravityview' ),
93  'labels' => $labels,
94  'supports' => $supports,
95  'hierarchical' => $is_hierarchical,
96  /**
97  * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode?
98  * @see https://codex.wordpress.org/Function_Reference/register_post_type#public
99  * @since 1.15.2
100  * @param[in,out] boolean `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded via shortcode. Default: `true`
101  * @param int $view_id The ID of the View currently being requested. `0` for general setting
102  */
103  'public' => apply_filters( 'gravityview_direct_access', GravityView_Compatibility::is_valid(), 0 ),
105  'show_in_menu' => GravityView_Compatibility::is_valid(),
106  'show_in_nav_menus' => true,
107  'show_in_admin_bar' => true,
108  'menu_position' => 17,
109  'menu_icon' => '',
110  'can_export' => true,
111  /**
112  * @filter `gravityview_has_archive` Enable Custom Post Type archive?
113  * @since 1.7.3
114  * @param boolean False: don't have frontend archive; True: yes, have archive. Default: false
115  */
116  'has_archive' => apply_filters( 'gravityview_has_archive', false ),
117  'exclude_from_search' => true,
118  'rewrite' => array(
119  /**
120  * @filter `gravityview_slug` Modify the url part for a View.
121  * @see http://docs.gravityview.co/article/62-changing-the-view-slug
122  * @param string $slug The slug shown in the URL
123  */
124  'slug' => apply_filters( 'gravityview_slug', 'view' )
125  ),
126  'capability_type' => 'gravityview',
127  'map_meta_cap' => true,
128  );
129 
130  register_post_type( 'gravityview', $args );
131 
132  }
133 
134  /**
135  * Register rewrite rules to capture the single entry view
136  *
137  * @access public
138  * @deprecated
139  * @see \GV\Entry::add_rewrite_endpoint
140  * @return void
141  */
142  public static function init_rewrite() {
143 
144  if ( function_exists( 'gravityview' ) ) {
145  return \GV\Entry::add_rewrite_endpoint();
146  }
147 
148  $endpoint = self::get_entry_var_name();
149 
150  //add_permastruct( "{$endpoint}", $endpoint.'/%'.$endpoint.'%/?', true);
151  add_rewrite_endpoint( "{$endpoint}", EP_ALL );
152  }
153 
154  /**
155  * Return the query var / end point name for the entry
156  *
157  * @access public
158  * @deprecated
159  * @see \GV\Entry::get_endpoint_name
160  * @return string Default: "entry"
161  */
162  public static function get_entry_var_name() {
163  if ( function_exists( 'gravityview' ) ) {
164  return \GV\Entry::get_endpoint_name();
165  }
166 
167  /**
168  * @filter `gravityview_directory_endpoint` Change the slug used for single entries
169  * @param[in,out] string $endpoint Slug to use when accessing single entry. Default: `entry`
170  */
171  $endpoint = apply_filters( 'gravityview_directory_endpoint', 'entry' );
172 
173  return sanitize_title( $endpoint );
174  }
175 
176 }
177 
new GravityView_Post_Types
$labels
static get_entry_var_name()
Return the query var / end point name for the entry.
__construct()
static is_valid()
Is everything compatible with this version of GravityView?
static init_post_types()
Init plugin components such as register own custom post types.
static no_views_text()
Get text for no views found.
Definition: class-admin.php:69
static init_rewrite()
Register rewrite rules to capture the single entry view.