|
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 Katz Web Services, Inc. |
|
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
|
|
|
*/ |
|
19
|
|
|
class GravityView_Plugin_Hooks_Gravity_PDF extends GravityView_Plugin_and_Theme_Hooks { |
|
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 ( ! $shortcodes = GPDFAPI::get_mvc_class( 'Model_Shortcodes' ) ) { |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
global $wpdb; |
|
46
|
|
|
$table = GFFormsModel::get_meta_table_name(); |
|
47
|
|
|
|
|
48
|
|
|
foreach ( $shortcodes->get_shortcode_information( 'gravitypdf', $content ) as $shortcode ) { |
|
49
|
|
|
// Let's make sure this entry ID is correct for the supplied form |
|
50
|
|
|
$form_id = $wpdb->get_var( $wpdb->prepare( "SELECT form_id FROM $table WHERE display_meta LIKE %s", '%"' . $wpdb->esc_like( $shortcode['attr']['id'] ) . '"%' ) ); |
|
51
|
|
|
|
|
52
|
|
|
// Inject the needed entry ID |
|
53
|
|
|
$replace = str_replace( |
|
54
|
|
|
sprintf( 'entry="%d"', $shortcode['attr']['entry'] ), |
|
55
|
|
|
sprintf( 'entry="%d"', $context->entry[ $form_id ]['id'] ), |
|
56
|
|
|
$shortcode['shortcode'] |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$content = str_replace( $shortcode['shortcode'], $replace, $content ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $content; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
new GravityView_Plugin_Hooks_Gravity_PDF; |
|
67
|
|
|
|