PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
← All changes | includes/payments/class-give-sequential-donation-number.php +31 -31 2.3.2 → 4.17.0 View file →
@@ -1,6 +1,8 @@
1 1 <?php
2 2 // Exit if access directly.
3 +use Give\Framework\Database\DB;
4 +
3 5 if ( ! defined( 'ABSPATH' ) ) {
4 6 exit;
5 7 }
6 8
@@ -11,9 +13,9 @@
11 13 * @since 2.1.0
12 14 * @access private
13 15 * @var
14 16 */
15 - static private $instance;
17 + private static $instance;
16 18
17 19 /**
18 20 * Donation tile prefix
19 21 *
@@ -55,16 +57,18 @@
55 57 *
56 58 * @since 2.1.0
57 59 */
58 60 public function init() {
59 - add_action( 'wp_insert_post', array( $this, '__save_donation_title' ), 10, 3 );
60 - add_action( 'after_delete_post', array( $this, '__remove_serial_number' ), 10, 1 );
61 - }
61 + add_action('wp_insert_post', array($this, 'save_donation_title'), 10, 3);
62 + add_action('after_delete_post', array($this, 'remove_serial_number'), 10, 1);
63 + }
62 64
63 65 /**
64 66 * Set serialize donation number as donation title.
65 67 * Note: only for internal use
66 68 *
69 + * @since 4.9.0 rename function - PHP 8 compatibility
70 + * @since 3.0.0 replace wp_update_post with DB::update to avoid affecting the post update date and invalidating the donation model's updatedAt date
67 71 * @since 2.1.0
68 72 * @access public
69 73 *
70 74 * @param int $donation_id
@@ -72,9 +76,9 @@
72 76 * @param bool $existing_donation_updated
73 77 *
74 78 * @return void
75 79 */
76 - public function __save_donation_title( $donation_id, $post, $existing_donation_updated ) {
80 + public function save_donation_title( $donation_id, $post, $existing_donation_updated ) {
77 81 // Bailout
78 82 if (
79 83 ! give_is_setting_enabled( give_get_option( 'sequential-ordering_status', 'disabled' ) )
80 84 || $existing_donation_updated
@@ -82,9 +86,9 @@
82 86 ) {
83 87 return;
84 88 }
85 89
86 - $serial_number = $this->__set_donation_number( $donation_id );
90 + $serial_number = $this->set_donation_number( $donation_id );
87 91 $serial_code = $this->set_number_padding( $serial_number );
88 92
89 93 // Add prefix.
90 94 if ( $prefix = give_get_option( 'sequential-ordering_number_prefix', '' ) ) {
@@ -109,29 +113,24 @@
109 113 $existing_donation_updated,
110 114 array(
111 115 $serial_number,
112 116 $prefix,
113 - $suffix
117 + $suffix,
114 118 )
115 119 );
116 120
117 121 try {
118 - /* @var WP_Error $wp_error */
119 - $wp_error = wp_update_post(
120 - array(
121 - 'ID' => $donation_id,
122 - 'post_name' => "{$this->donation_title_prefix}-{$serial_number}",
123 - 'post_title' => trim( $serial_code )
124 - )
125 - );
122 + DB::table('posts')
123 + ->where('ID', $donation_id)
124 + ->update([
125 + 'post_title' => trim($serial_code),
126 + 'post_name' => "{$this->donation_title_prefix}-{$serial_number}",
127 + ]);
128 + clean_post_cache($donation_id);
126 129
127 - if ( is_wp_error( $wp_error ) ) {
128 - throw new Exception( $wp_error->get_error_message() );
129 - }
130 -
131 130 give_update_option( 'sequential-ordering_number', ( $serial_number + 1 ) );
132 131 } catch ( Exception $e ) {
133 - error_log( "Give caught exception: {$e->getMessage()}" );
132 + error_log( "GiveWP caught exception: {$e->getMessage()}" );
134 133 }
135 134 }
136 135
137 136 /**
@@ -137,8 +136,9 @@
137 136 /**
138 137 * Set donation number
139 138 * Note: only for internal use
140 139 *
140 + * @since 4.9.0 rename function - PHP 8 compatibility
141 141 * @since 2.1.0
142 142 * @access public
143 143 *
144 144 * @param int $donation_id
@@ -144,11 +144,11 @@
144 144 * @param int $donation_id
145 145 *
146 146 * @return int
147 147 */
148 - public function __set_donation_number( $donation_id ) {
148 + public function set_donation_number( $donation_id ) {
149 149 $table_data = array(
150 - 'payment_id' => $donation_id
150 + 'payment_id' => $donation_id,
151 151 );
152 152
153 153 // Customize sequential donation number starting point if needed.
154 154 if (
@@ -161,9 +161,8 @@
161 161
162 162 $table_data['id'] = $number;
163 163 }
164 164
165 -
166 165 /**
167 166 * Filter the donation number
168 167 *
169 168 * @since 2.1
@@ -179,8 +178,9 @@
179 178 /**
180 179 * Remove sequential donation data
181 180 * Note: only internal use.
182 181 *
182 + * @since 4.9.0 rename function - PHP 8 compatibility
183 183 * @since 2.1.0
184 184 * @access public
185 185 *
186 186 * @param $donation_id
@@ -186,9 +186,9 @@
186 186 * @param $donation_id
187 187 *
188 188 * @return bool
189 189 */
190 - public function __remove_serial_number( $donation_id ) {
190 + public function remove_serial_number( $donation_id ) {
191 191 return Give()->sequential_donation_db->delete( $this->get_serial_number( $donation_id ) );
192 192 }
193 193
194 194 /**
@@ -215,18 +215,18 @@
215 215 * @since 2.1.0
216 216 * @access public
217 217 *
218 218 * @param int|Give_Payment|WP_Post $donation
219 - * @param array $args
219 + * @param array $args
220 220 *
221 221 * @return string
222 222 */
223 223 public function get_serial_code( $donation, $args = array() ) {
224 224 // Get id from object.
225 - if( ! is_numeric( $donation ) ) {
226 - if( $donation instanceof Give_Payment ) {
225 + if ( ! is_numeric( $donation ) ) {
226 + if ( $donation instanceof Give_Payment ) {
227 227 $donation = $donation->ID;
228 - } elseif ( $donation instanceof WP_Post ){
228 + } elseif ( $donation instanceof WP_Post ) {
229 229 $donation = $donation->ID;
230 230 }
231 231 }
232 232
@@ -234,9 +234,9 @@
234 234 $args = wp_parse_args(
235 235 $args,
236 236 array(
237 237 'with_hash' => false,
238 - 'default' => true
238 + 'default' => true,
239 239 )
240 240 );
241 241
242 242 $serial_code = $args['default'] ? $donation : '';
@@ -328,9 +328,9 @@
328 328 $wpdb->get_var(
329 329 "
330 330 SELECT ID
331 331 FROM {$table_name}
332 - ORDER BY id DESC
332 + ORDER BY id DESC
333 333 LIMIT 1
334 334 "
335 335 )
336 336 );
@@ -354,9 +354,9 @@
354 354 SELECT ID
355 355 FROM {$wpdb->posts}
356 356 WHERE post_type=%s
357 357 AND post_status=%s
358 - ORDER BY id DESC
358 + ORDER BY id DESC
359 359 LIMIT 1
360 360 ",
361 361 'give_payment',
362 362 'publish'