Completed
Push — issues/611 ( d123e1...0564a6 )
by Ravinder
20:29
created

Give_New_Offline_Donation_Email::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * New Offline Donation Email
4
 *
5
 * This class handles all email notification settings.
6
 *
7
 * @package     Give
8
 * @subpackage  Classes/Emails
9
 * @copyright   Copyright (c) 2016, WordImpress
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 * @since       1.9
12
 */
13
14
// Exit if access directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
if ( ! class_exists( 'Give_New_Offline_Donation_Email' ) ) :
20
21
	/**
22
	 * Give_New_Offline_Donation_Email
23
	 *
24
	 * @abstract
25
	 * @since       1.9
26
	 */
27
	class Give_New_Offline_Donation_Email extends Give_Email_Notification {
28
		/* @var Give_Payment $payment */
29
		public $payment;
30
31
		/**
32
		 * Create a class instance.
33
		 *
34
		 * @access  public
35
		 * @since   1.9
36
		 */
37
		public function init() {
38
			$this->id          = 'new-offline-donation';
39
			$this->label       = __( 'New Offline Donation', 'give' );
40
			$this->description = __( 'Donation Notification will be sent to admin when new offline donation received.', 'give' );
41
42
			$this->has_recipient_field       = true;
43
			$this->notification_status       = 'enabled';
44
			$this->preview_email_tags_values = array(
45
				'payment_method' => esc_html__( 'Offline', 'give' ),
46
			);
47
48
			// Initialize empty payment.
49
			$this->payment = new Give_Payment(0);
50
51
			parent::load();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (load() instead of init()). Are you sure this is correct? If so, you might want to change this to $this->load().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
52
53
			add_action( 'give_insert_payment', array( $this, 'setup_email_notification' ) );
54
		}
55
56
		/**
57
		 * Get default email subject.
58
		 *
59
		 * @since  1.9
60
		 * @access public
61
		 * @return string
62
		 */
63
		public function get_default_email_subject() {
64
			/**
65
			 * Filter the default subject.
66
			 * Note: This filter will deprecate soon.
67
			 *
68
			 * @since 1.0
69
			 */
70
			$subject = apply_filters(
71
				'give_offline_admin_donation_notification_subject',
72
				__( 'New Pending Donation', 'give' )
73
			);
74
75
			/**
76
			 * Filter the default subject
77
			 *
78
			 * @since 1.9
79
			 */
80
			return apply_filters( "give_{$this->id}_get_default_email_subject", $subject, $this );
81
		}
82
83
84
		/**
85
		 * Get default email message.
86
		 *
87
		 * @since  1.9
88
		 * @access public
89
		 *
90
		 * @return string
91
		 */
92
		public function get_default_email_message() {
93
			$message = __( 'Dear Admin,', 'give' ) . "\n\n";
94
			$message .= __( 'An offline donation has been made on your website:', 'give' ) . ' ' . get_bloginfo( 'name' ) . ' ';
95
			$message .= __( 'Hooray! The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n";
96
97
98
			$message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
99
			$message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
100
101
			$message .= sprintf(
102
				'<a href="%1$s">%2$s</a>',
103
				admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $this->payment->ID ),
104
				__( 'Click Here to View and/or Update Donation Details', 'give' )
105
			) . "\n\n";
106
107
108
			/**
109
			 * Filter the donation receipt email message
110
			 * Note: This filter will deprecate soon.
111
			 *
112
			 * @since 1.0
113
			 *
114
			 * @param string $message
115
			 */
116
			$message =  apply_filters(
117
				'give_default_new_offline_donation_email',
118
				$message,
119
				$this->payment->ID
120
			);
121
122
			/**
123
			 * Filter the default message
124
			 *
125
			 * @since 1.9
126
			 */
127
			return apply_filters( "give_{$this->id}_get_default_email_message", $message, $this );
128
		}
129
130
131
		/**
132
		 * Get message
133
		 *
134
		 * @since 1.9
135
		 * @return string
136
		 */
137
		public function get_email_message() {
138
			$message = give_get_option( "{$this->id}_email_message", $this->get_default_email_message() );
139
140
141
			/**
142
			 * Filter the email message.
143
			 * Note: This filter will deprecate soon.
144
			 *
145
			 * @since 1.0
146
			 */
147
			$message = apply_filters( 'give_offline_admin_donation_notification', $message, $this->payment->ID );
148
149
			/**
150
			 * Filter the email message
151
			 *
152
			 * @since 1.9
153
			 */
154
			return apply_filters( "give_{$this->id}_get_email_message", $message, $this );
155
		}
156
157
158
		/**
159
		 * Get attachments.
160
		 *
161
		 * @since 1.9
162
		 * @return array
163
		 */
164
		public function get_email_attachments() {
165
			/**
166
			 * Filter the attachments.
167
			 * Note: This filter will deprecate soon.
168
			 *
169
			 * @since 1.0
170
			 */
171
			$attachment = apply_filters(
172
				'give_offline_admin_donation_notification_attachments',
173
				array(),
174
				$this->payment->ID
175
			);
176
177
			/**
178
			 * Filter the attachments.
179
			 *
180
			 * @since 1.9
181
			 */
182
			return apply_filters( "give_{$this->id}_get_email_attachments", $attachment, $this );
183
		}
184
185
186
		/**
187
		 * Set email data.
188
		 *
189
		 * @since 1.9
190
		 */
191
		public function setup_email_data() {
192
			// Set recipient email.
193
			$this->recipient_email = $this->payment->email;
194
195
196
			// Set header.
197
			Give()->emails->__set(
198
				'headers',
199
				apply_filters(
200
					'give_offline_admin_donation_notification_headers',
201
					Give()->emails->get_headers(),
202
					$this->payment->ID
203
				)
204
			);
205
		}
206
207
		/**
208
		 * Setup email notification.
209
		 *
210
		 * @since  1.9
211
		 * @access public
212
		 *
213
		 * @param int $payment_id
214
		 */
215
		public function setup_email_notification( $payment_id ) {
216
			$this->payment = new Give_Payment( $payment_id );
217
218
219
			// Exit if not donation was not with offline donation.
220
			if ( 'offline' !== $this->payment->gateway ) {
221
				return;
222
			}
223
224
			// Set email data.
225
			$this->setup_email_data();
226
227
			// Send email.
228
			$this->send_email_notification( array( 'payment_id' => $this->payment->ID ) );
229
		}
230
	}
231
232
endif; // End class_exists check
233
234
return Give_New_Offline_Donation_Email::get_instance();