14 if ( ! defined( 
'GRAVITYVIEW_DIR' ) ) {
    49         $page = $request->get_param( 
'page' );
    50         $limit = $request->get_param( 
'limit' );
    53             'posts_per_page' => $limit,
    57         if ( empty( $items ) ) {
    58             return new \WP_Error( 
'gravityview-no-views', __( 
'No Views found.', 
'gk-gravityview' ) ); 
    63             'total' => wp_count_posts( 
'gravityview' )->publish,
    65         foreach ( $items as $item ) {
    69         return new \WP_REST_Response( $data, 200 );
    83         $url = $request->get_url_params();
    90         if ( $item && ! is_wp_error( $item ) ) {
    92             return new \WP_REST_Response( $data, 200 );
    95         return new \WP_Error( 
'code', sprintf( 
'A View with ID #%d was not found.', 
$view_id ) );
   116         foreach ( $view->fields->by_position( 
"{$context}_*" )->by_visible( $view )->all() as 
$field ) {
   128         $allowed_field_ids = apply_filters( 
'gravityview/rest/entry/fields', wp_list_pluck( $allowed, 
'ID' ), $view, 
$entry, $request, $context );
   130         $allowed = array_filter( $allowed, 
function( 
$field ) use ( $allowed_field_ids ) {
   131             return in_array( 
$field->ID, $allowed_field_ids, 
true );
   135         foreach ( array_diff( $allowed_field_ids, wp_list_pluck( $allowed, 
'ID' ) ) as 
$field_id ) {
   142         $renderer = new \GV\Field_Renderer();
   146         foreach ( $allowed as 
$field ) {
   147             $source = is_numeric( $field->ID ) ? $view->form : new \GV\Internal_Source();
   152             if ( ! isset( $used_ids[ 
$field_id ] ) ) {
   162                 $field_id = sprintf( 
'%s(%d)', $field_id, $index + 1 );
   173             $field_id = apply_filters( 
'gravityview/api/field/key', $field_id, $view, 
$entry, $request, $context );
   175             if ( ! 
$class && in_array( $field->ID, array( 
'custom' ) ) ) {
   181                 $return[ 
$field_id ] = $renderer->render( $field, $view, $source, 
$entry, $r, 
'\GV\Field_CSV_Template' );
   185                 switch ( $field->type ):
   187                         $return[ 
$field_id ] = unserialize( $field->get_value( $view, $source, 
$entry, $r ) );
   190                     case 'business_hours':
   191                         $return[ 
$field_id ] = json_decode( $field->get_value( $view, $source, 
$entry, $r ) );
   194                         $return[ 
$field_id ] = $field->get_value( $view, $source, 
$entry, $r );
   213         $url     = $request->get_url_params();
   217         if( $post_id = $request->get_param(
'post_id') ) {
   220             $post = get_post( $post_id );
   222             if ( ! $post || is_wp_error( $post ) ) {
   223                 return new \WP_Error( 
'gravityview-post-not-found', sprintf( 
'A post with ID #%d was not found.', $post_id ) );
   228             if ( ! $collection->contains( 
$view_id ) ) {
   229                 return new \WP_Error( 
'gravityview-post-not-contains', sprintf( 
'The post with ID #%d does not contain a View with ID #%d', $post_id, 
$view_id ) );
   237             $renderer = new \GV\View_Renderer();
   241             add_action( 
'gravityview/template/view/render', 
function( $context ) use ( &$count, &$total ) {
   242                 $count = $context->entries->count();
   243                 $total = $context->entries->total();
   257             $insert_meta = apply_filters( 
'gravityview/rest/entries/html/insert_meta', 
true, $count, $view, $request, $total );
   259             if ( $insert_meta ) {
   260                 $output = 
'<meta http-equiv="X-Item-Count" content="' . $count . 
'" />' . 
$output;
   261                 $output = 
'<meta http-equiv="X-Item-Total" content="' . $total . 
'" />' . 
$output;
   264             $response = new \WP_REST_Response( $output, 200 );
   265             $response->header( 
'X-Item-Count', $count );
   266             $response->header( 
'X-Item-Total', $total );
   274             return new \WP_Error( 
'gravityview-no-entries', __( 
'No Entries found.', 
'gk-gravityview' ) );
   277         if ( in_array( 
$format, array( 
'csv', 
'tsv' ), 
true ) ) {
   281             $csv_or_tsv = fopen( 
'php://output', 
'w' );
   284             if ( apply_filters( 
'gform_include_bom_export_entries', 
true, $view->form ? $view->form->form : null ) ) {
   285                 fputs( $csv_or_tsv, 
"\xef\xbb\xbf" );
   288             $headers_done = 
false;
   291             $delimiter = ( 
'tsv' === 
$format ) ? 
"\t" : 
',';
   296                 if ( ! $headers_done ) {
   297                     $headers_done = fputcsv( $csv_or_tsv, array_map( array( 
'\GV\Utils', 
'strip_excel_formulas' ), array_keys( 
$entry ) ), $delimiter );
   300                 fputcsv( $csv_or_tsv, array_map( array( 
'\GV\Utils', 
'strip_excel_formulas' ), 
$entry ), $delimiter );
   303             $response = new \WP_REST_Response( 
'', 200 );
   304             $response->header( 
'X-Item-Count', 
$entries->count() );
   305             $response->header( 
'X-Item-Total', 
$entries->total() );
   306             $response->header( 
'Content-Type', 
'text/' . 
$format );
   308             fflush( $csv_or_tsv );
   310             $data = rtrim( ob_get_clean() );
   312             add_filter( 
'rest_pre_serve_request', 
function() use ( $data ) {
   317             if ( defined( 
'DOING_GRAVITYVIEW_TESTS' ) && DOING_GRAVITYVIEW_TESTS ) {
   324         $data = array( 
'entries' => 
$entries->all(), 
'total' => 
$entries->total() );
   326         foreach ( $data[
'entries'] as &
$entry ) {
   330         return new \WP_REST_Response( $data, 200 );
   344         $url      = $request->get_url_params();
   346         $entry_id = intval( 
$url[
's_id'] );
   353             $renderer = new \GV\Entry_Renderer();
   354             return $renderer->render( 
$entry, $view, 
new Request( $request ) );
   371             return array( 
'ID' => $view_post->ID, 
'post_content' => __( 
'You are not allowed to access this content.', 
'gk-gravityview' ) );
   376         $item = $view->as_data();
   379         $view_post = $view_post->to_array();
   381         unset( $view_post[
'to_ping'], $view_post[
'ping_status'], $view_post[
'pinged'], $view_post[
'post_type'], $view_post[
'filter'], $view_post[
'post_category'], $view_post[
'tags_input'], $view_post[
'post_content'], $view_post[
'post_content_filtered'] );
   383         $return = wp_parse_args( $item, $view_post );
   385         $return[
'title'] = $return[
'post_title'];
   387         $return[
'settings'] = isset( $return[
'atts'] ) ? $return[
'atts'] : array();
   388         unset( $return[
'atts'], $return[
'view_id'] );
   390         $return[
'search_criteria'] = array(
   391             'page_size' => rgars( $return, 
'settings/page_size' ),
   392             'sort_field' => rgars( $return, 
'settings/sort_field' ),
   393             'sort_direction' => rgars( $return, 
'settings/sort_direction' ),
   394             'offset' => rgars( $return, 
'settings/offset' ),
   397         unset( $return[
'settings'][
'page_size'], $return[
'settings'][
'sort_field'], $return[
'settings'][
'sort_direction'] );
   401             unset( $return[
'settings'] );
   402             unset( $return[
'search_criteria'] );
   405         if ( ! \GFCommon::current_user_can_any( 
'gravityforms_edit_forms' ) ) {
   406             unset( $return[
'form'] );
   418         if ( func_num_args() === 2 ) {
   421             $url     = $request->get_url_params();
   426             return new \WP_Error( 
'rest_forbidden', __( 
'You are not allowed to access this content.', 
'gk-gravityview' ) );
   429         while ( $error = $view->can_render( array( 
'rest' ), $request ) ) {
   431             if ( ! is_wp_error( $error ) ) {
   435             switch ( str_replace( 
'gravityview/', 
'', $error->get_error_code() ) ) {
   436                 case 'rest_disabled':
   437                 case 'post_password_required':
   440                 case 'no_direct_access':
   441                     return new \WP_Error( 
'rest_forbidden_access_denied', __( 
'You are not allowed to access this content.', 
'gk-gravityview' ) );
   442                 case 'no_form_attached':
   443                     return new \WP_Error( 
'rest_forbidden_no_form_attached', __( 
'This View is not configured properly.', 
'gk-gravityview' ) );
   445                     return new \WP_Error( 
'rest_forbidden', __( 
'You are not allowed to access this content.', 
'gk-gravityview' ) );
   454         if ( ! apply_filters( 
'gravityview/view/output/rest', 
true, $view ) ) {
   455             return new \WP_Error( 
'rest_forbidden', __( 
'You are not allowed to access this content.', 
'gk-gravityview' ) );
   467         $url     = $request->get_url_params();
   469         $entry_id = intval( 
$url[
's_id'] );
   474             return new \WP_Error( 
'rest_forbidden', 
'You are not allowed to view this content.', 
'gravityview' );
   477         if ( 
$entry[
'form_id'] != $view->form->ID ) {
   478             return new \WP_Error( 
'rest_forbidden', 
'You are not allowed to view this content.', 
'gravityview' );
   481         if ( 
$entry[
'status'] != 
'active' ) {
   482             return new \WP_Error( 
'rest_forbidden', 
'You are not allowed to view this content.', 
'gravityview' );
   486             return new \WP_Error( 
'rest_forbidden', 
'You are not allowed to view this content.', 
'gravityview' );
   489         $is_admin_and_can_view = $view->settings->get( 
'admin_show_all_statuses' ) && 
\GVCommon::has_cap(
'gravityview_moderate_entries', $view->ID );
   491         if ( $view->settings->get( 
'show_only_approved' ) && ! $is_admin_and_can_view ) {
   493                 return new \WP_Error( 
'rest_forbidden', 
'You are not allowed to view this content.', 
'gravityview' );
 
get_sub_item_permissions_check( $request)
 
prepare_entry_for_response( $view, $entry, \WP_REST_Request $request, $context, $class=null)
Prepare the item for the REST response. 
 
If this file is called directly, abort. 
 
get_items( $request)
Get a collection of views. 
 
if(gv_empty( $field['value'], false, false)) $format
 
get_sub_items_permissions_check( $request)
 
prepare_view_for_response( $view_post, \WP_REST_Request $request)
Prepare the item for the REST response. 
 
get_items_permissions_check( $request)
 
If this file is called directly, abort. 
 
static from_post(\WP_Post $post)
Get a list of  objects inside the supplied . 
 
static by_id( $form, $field_id)
Get a  by  and Field ID. 
 
static get_endpoint_name()
Return the endpoint name for a single Entry. 
 
get_item( $request)
Get one view. 
 
If this file is called directly, abort. 
 
static by_id( $post_id)
Construct a  instance from a post ID. 
 
get_sub_item( $request)
Get one entry from view. 
 
get_sub_items( $request)
Get a collection of items. 
 
static by_id( $field_id)
Get a  from an internal Gravity Forms field ID. 
 
static get( $array, $key, $default=null)
Grab a value from an array or an object or default. 
 
static by_id( $entry_id, $form_id=0)
Construct a  instance by ID. 
 
static is_approved( $status)
 
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap() 
 
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed 
 
static get_all_views( $args=array())
Get all existing Views. 
 
get_item_permissions_check( $request)
 
static from_post( $post)
Construct a  instance from a .