|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Forms Module |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2018 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Forms |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Forms; |
|
12
|
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
|
14
|
|
|
use Pronamic\WordPress\Pay\Plugin; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Forms Module |
|
18
|
|
|
* |
|
19
|
|
|
* @author Remco Tolsma |
|
20
|
|
|
* @version 3.7.0 |
|
21
|
|
|
* @since 3.7.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class FormsModule { |
|
24
|
|
|
/** |
|
25
|
|
|
* Plugin. |
|
26
|
|
|
* |
|
27
|
|
|
* @var Plugin |
|
28
|
|
|
*/ |
|
29
|
|
|
private $plugin; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructs and initalize a forms module object. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Plugin $plugin Plugin. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( $plugin ) { |
|
37
|
|
|
$this->plugin = $plugin; |
|
38
|
|
|
|
|
39
|
|
|
// Form Post Type. |
|
40
|
|
|
$this->form_post_type = new FormPostType( $plugin ); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
// Processor. |
|
43
|
|
|
$this->processor = new FormProcessor( $plugin ); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
// Scripts. |
|
46
|
|
|
$this->scripts = new FormScripts( $plugin ); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
// Shortcode. |
|
49
|
|
|
$this->shortcode = new FormShortcode( $this ); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
// Actions. |
|
52
|
|
|
add_filter( 'the_content', array( $this, 'maybe_add_form_to_content' ) ); |
|
53
|
|
|
|
|
54
|
|
|
add_filter( 'pronamic_payment_source_text_payment_form', array( $this, 'source_text' ), 10, 2 ); |
|
55
|
|
|
add_filter( 'pronamic_payment_source_description_payment_form', array( $this, 'source_description' ), 10, 2 ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Maybe add form to content. |
|
60
|
|
|
* |
|
61
|
|
|
* @see https://developer.wordpress.org/reference/hooks/the_content/ |
|
62
|
|
|
* @param string $content Post content to maybe extend with a payment form. |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function maybe_add_form_to_content( $content ) { |
|
66
|
|
|
if ( is_singular( 'pronamic_pay_form' ) && 'pronamic_pay_form' === get_post_type() ) { |
|
67
|
|
|
$content .= $this->get_form_output( get_the_ID() ); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $content; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get form output. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $id Form ID. |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function get_form_output( $id ) { |
|
80
|
|
|
$file = plugin_dir_path( $this->plugin->get_file() ) . 'templates/form.php'; |
|
81
|
|
|
|
|
82
|
|
|
ob_start(); |
|
83
|
|
|
|
|
84
|
|
|
include $file; |
|
85
|
|
|
|
|
86
|
|
|
$output = ob_get_clean(); |
|
87
|
|
|
|
|
88
|
|
|
return $output; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Source text filter. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $text The source text to filter. |
|
95
|
|
|
* @param Payment $payment The payment for the specified source text. |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function source_text( $text, Payment $payment ) { |
|
99
|
|
|
$text = __( 'Payment Form', 'pronamic_ideal' ) . '<br />'; |
|
100
|
|
|
|
|
101
|
|
|
$text .= sprintf( |
|
102
|
|
|
'<a href="%s">%s</a>', |
|
103
|
|
|
get_edit_post_link( $payment->source_id ), |
|
|
|
|
|
|
104
|
|
|
$payment->source_id |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
return $text; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Source description filter. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $text The source text to filter. |
|
114
|
|
|
* @param Payment $payment The payment for the specified source text. |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function source_description( $text, Payment $payment ) { |
|
|
|
|
|
|
118
|
|
|
$text = __( 'Payment Form', 'pronamic_ideal' ) . '<br />'; |
|
119
|
|
|
|
|
120
|
|
|
return $text; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|