GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-plugin-hooks-gravity-pdf.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Add GravityView compatibility to Gravity PDF
4  *
5  * @file class-gravityview-plugin-hooks-gravity-pdf.php
6  * @package GravityView
7  * @license GPL2+
8  * @author GravityView <[email protected]>
9  * @link http://gravityview.co
10  * @copyright Copyright 2015, Katz Web Services, Inc.
11  *
12  * @since develop
13  */
14 
15 /**
16  * @inheritDoc
17  * @since develop
18  */
20 
21  /**
22  * @inheritDoc
23  * @since 1.15.2
24  */
25  protected $constant_name = 'PDF_EXTENDED_VERSION';
26 
27  public function add_hooks() {
28  parent::add_hooks();
29 
30  add_filter( 'gravityview/fields/custom/content_before', array( $this, 'fix_entry_id_for_custom_content_shortcode' ), 11, 2 );
31  }
32 
33  /**
34  * @see https://github.com/gravityview/Multiple-Forms/issues/41
35  */
36  public function fix_entry_id_for_custom_content_shortcode( $content, $context ) {
37  if ( ! $context->entry->is_multi() ) {
38  return $content;
39  }
40 
41  if ( ! class_exists( 'GPDFAPI' ) ) {
42  return $content;
43  }
44 
45  if ( ! $shortcodes = GPDFAPI::get_mvc_class( 'Model_Shortcodes' ) ) {
46  return $content;
47  }
48 
49  global $wpdb;
50  $table = GFFormsModel::get_meta_table_name();
51 
52  foreach ( $shortcodes->get_shortcode_information( 'gravitypdf', $content ) as $shortcode ) {
53  // Let's make sure this entry ID is correct for the supplied form
54  $form_id = $wpdb->get_var( $wpdb->prepare( "SELECT form_id FROM $table WHERE display_meta LIKE %s", '%"' . $wpdb->esc_like( $shortcode['attr']['id'] ) . '"%' ) );
55 
56  // Inject the needed entry ID
57  $replace = str_replace(
58  sprintf( 'entry="%d"', $shortcode['attr']['entry'] ),
59  sprintf( 'entry="%d"', $context->entry[ $form_id ]['id'] ),
60  $shortcode['shortcode']
61  );
62 
63  $content = str_replace( $shortcode['shortcode'], $replace, $content );
64  }
65 
66  return $content;
67  }
68 }
69 
if(empty( $field_settings['content'])) $content
Definition: custom.php:37
if(empty( $created_by)) $form_id
Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles...