| Conditions | 36 |
| Paths | > 20000 |
| Total Lines | 256 |
| Code Lines | 193 |
| Lines | 184 |
| Ratio | 71.88 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 124 | function _give_register_admin_notices() { |
||
| 125 | // Bailout. |
||
| 126 | if( ! is_admin() ) { |
||
| 127 | return; |
||
| 128 | } |
||
| 129 | |||
| 130 | // Add PHP version update notice |
||
| 131 | if ( function_exists( 'phpversion' ) && version_compare( GIVE_REQUIRED_PHP_VERSION, phpversion(), '>' ) ) { |
||
| 132 | |||
| 133 | $notice_desc = '<p><strong>' . __( 'Your site could be faster and more secure with a newer PHP version.', 'give' ) . '</strong></p>'; |
||
| 134 | $notice_desc .= '<p>' . __( 'Hey, we\'ve noticed that you\'re running an outdated version of PHP. PHP is the programming language that WordPress and Give are built on. The version that is currently used for your site is no longer supported. Newer versions of PHP are both faster and more secure. In fact, your version of PHP no longer receives security updates, which is why we\'re sending you this notice.', 'give' ) . '</p>'; |
||
| 135 | $notice_desc .= '<p>' . __( 'Hosts have the ability to update your PHP version, but sometimes they don\'t dare to do that because they\'re afraid they\'ll break your site.', 'give' ) . '</p>'; |
||
| 136 | $notice_desc .= '<p><strong>' . __( 'To which version should I update?', 'give' ) . '</strong></p>'; |
||
| 137 | $notice_desc .= '<p>' . __( 'You should update your PHP version to either 5.6 or to 7.0 or 7.1. On a normal WordPress site, switching to PHP 5.6 should never cause issues. We would however actually recommend you switch to PHP7. There are some plugins that are not ready for PHP7 though, so do some testing first. PHP7 is much faster than PHP 5.6. It\'s also the only PHP version still in active development and therefore the better option for your site in the long run.', 'give' ) . '</p>'; |
||
| 138 | $notice_desc .= '<p><strong>' . __( 'Can\'t update? Ask your host!', 'give' ) . '</strong></p>'; |
||
| 139 | $notice_desc .= '<p>' . sprintf( __( 'If you cannot upgrade your PHP version yourself, you can send an email to your host. If they don\'t want to upgrade your PHP version, we would suggest you switch hosts. Have a look at one of the recommended %1$sWordPress hosting partners%2$s.', 'give' ), sprintf( '<a href="%1$s" target="_blank">', esc_url( 'https://wordpress.org/hosting/' ) ), '</a>' ) . '</p>'; |
||
| 140 | |||
| 141 | Give()->notices->register_notice( array( |
||
| 142 | 'id' => 'give-invalid-php-version', |
||
| 143 | 'type' => 'error', |
||
| 144 | 'description' => $notice_desc, |
||
| 145 | 'dismissible_type' => 'user', |
||
| 146 | 'dismiss_interval' => 'shortly', |
||
| 147 | ) ); |
||
| 148 | } |
||
| 149 | |||
| 150 | // Add payment bulk notice. |
||
| 151 | if ( |
||
| 152 | current_user_can( 'edit_give_payments' ) |
||
| 153 | && isset( $_GET['action'] ) |
||
| 154 | && ! empty( $_GET['action'] ) |
||
| 155 | && isset( $_GET['payment'] ) |
||
| 156 | && ! empty( $_GET['payment'] ) |
||
| 157 | ) { |
||
| 158 | $payment_count = isset( $_GET['payment'] ) ? count( $_GET['payment'] ) : 0; |
||
| 159 | |||
| 160 | switch ( $_GET['action'] ) { |
||
| 161 | View Code Duplication | case 'delete': |
|
| 162 | Give()->notices->register_notice( array( |
||
| 163 | 'id' => 'bulk_action_delete', |
||
| 164 | 'type' => 'updated', |
||
| 165 | 'description' => sprintf( |
||
| 166 | _n( |
||
| 167 | 'Successfully deleted one transaction.', |
||
| 168 | 'Successfully deleted %d transactions.', |
||
| 169 | $payment_count, |
||
| 170 | 'give' |
||
| 171 | ), |
||
| 172 | $payment_count ), |
||
| 173 | 'show' => true, |
||
| 174 | ) ); |
||
| 175 | |||
| 176 | break; |
||
| 177 | |||
| 178 | View Code Duplication | case 'resend-receipt': |
|
| 179 | Give()->notices->register_notice( array( |
||
| 180 | 'id' => 'bulk_action_resend_receipt', |
||
| 181 | 'type' => 'updated', |
||
| 182 | 'description' => sprintf( |
||
| 183 | _n( |
||
| 184 | 'Successfully sent email receipt to one recipient.', |
||
| 185 | 'Successfully sent email receipts to %d recipients.', |
||
| 186 | $payment_count, |
||
| 187 | 'give' |
||
| 188 | ), |
||
| 189 | $payment_count |
||
| 190 | ), |
||
| 191 | 'show' => true, |
||
| 192 | ) ); |
||
| 193 | break; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | // Add give message notices. |
||
| 198 | if ( ! empty( $_GET['give-message'] ) ) { |
||
| 199 | // Donation reports errors. |
||
| 200 | if ( current_user_can( 'view_give_reports' ) ) { |
||
| 201 | switch ( $_GET['give-message'] ) { |
||
| 202 | View Code Duplication | case 'donation_deleted' : |
|
| 203 | Give()->notices->register_notice( array( |
||
| 204 | 'id' => 'give-donation-deleted', |
||
| 205 | 'type' => 'updated', |
||
| 206 | 'description' => __( 'The donation has been deleted.', 'give' ), |
||
| 207 | 'show' => true, |
||
| 208 | ) ); |
||
| 209 | break; |
||
| 210 | View Code Duplication | case 'email_sent' : |
|
| 211 | Give()->notices->register_notice( array( |
||
| 212 | 'id' => 'give-payment-sent', |
||
| 213 | 'type' => 'updated', |
||
| 214 | 'description' => __( 'The donation receipt has been resent.', 'give' ), |
||
| 215 | 'show' => true, |
||
| 216 | ) ); |
||
| 217 | break; |
||
| 218 | View Code Duplication | case 'refreshed-reports' : |
|
| 219 | Give()->notices->register_notice( array( |
||
| 220 | 'id' => 'give-refreshed-reports', |
||
| 221 | 'type' => 'updated', |
||
| 222 | 'description' => __( 'The reports cache has been cleared.', 'give' ), |
||
| 223 | 'show' => true, |
||
| 224 | ) ); |
||
| 225 | break; |
||
| 226 | View Code Duplication | case 'donation-note-deleted' : |
|
| 227 | Give()->notices->register_notice( array( |
||
| 228 | 'id' => 'give-donation-note-deleted', |
||
| 229 | 'type' => 'updated', |
||
| 230 | 'description' => __( 'The donation note has been deleted.', 'give' ), |
||
| 231 | 'show' => true, |
||
| 232 | ) ); |
||
| 233 | break; |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | // Give settings notices and errors. |
||
| 238 | if ( current_user_can( 'manage_give_settings' ) ) { |
||
| 239 | switch ( $_GET['give-message'] ) { |
||
| 240 | View Code Duplication | case 'settings-imported' : |
|
| 241 | Give()->notices->register_notice( array( |
||
| 242 | 'id' => 'give-settings-imported', |
||
| 243 | 'type' => 'updated', |
||
| 244 | 'description' => __( 'The settings have been imported.', 'give' ), |
||
| 245 | 'show' => true, |
||
| 246 | ) ); |
||
| 247 | break; |
||
| 248 | View Code Duplication | case 'api-key-generated' : |
|
| 249 | Give()->notices->register_notice( array( |
||
| 250 | 'id' => 'give-api-key-generated', |
||
| 251 | 'type' => 'updated', |
||
| 252 | 'description' => __( 'API keys have been generated.', 'give' ), |
||
| 253 | 'show' => true, |
||
| 254 | ) ); |
||
| 255 | break; |
||
| 256 | View Code Duplication | case 'api-key-exists' : |
|
| 257 | Give()->notices->register_notice( array( |
||
| 258 | 'id' => 'give-api-key-exists', |
||
| 259 | 'type' => 'updated', |
||
| 260 | 'description' => __( 'The specified user already has API keys.', 'give' ), |
||
| 261 | 'show' => true, |
||
| 262 | ) ); |
||
| 263 | break; |
||
| 264 | View Code Duplication | case 'api-key-regenerated' : |
|
| 265 | Give()->notices->register_notice( array( |
||
| 266 | 'id' => 'give-api-key-regenerated', |
||
| 267 | 'type' => 'updated', |
||
| 268 | 'description' => __( 'API keys have been regenerated.', 'give' ), |
||
| 269 | 'show' => true, |
||
| 270 | ) ); |
||
| 271 | break; |
||
| 272 | View Code Duplication | case 'api-key-revoked' : |
|
| 273 | Give()->notices->register_notice( array( |
||
| 274 | 'id' => 'give-api-key-revoked', |
||
| 275 | 'type' => 'updated', |
||
| 276 | 'description' => __( 'API keys have been revoked.', 'give' ), |
||
| 277 | 'show' => true, |
||
| 278 | ) ); |
||
| 279 | break; |
||
| 280 | View Code Duplication | case 'sent-test-email' : |
|
| 281 | Give()->notices->register_notice( array( |
||
| 282 | 'id' => 'give-sent-test-email', |
||
| 283 | 'type' => 'updated', |
||
| 284 | 'description' => __( 'The test email has been sent.', 'give' ), |
||
| 285 | 'show' => true, |
||
| 286 | ) ); |
||
| 287 | break; |
||
| 288 | View Code Duplication | case 'matched-success-failure-page': |
|
| 289 | Give()->notices->register_notice( array( |
||
| 290 | 'id' => 'give-matched-success-failure-page', |
||
| 291 | 'type' => 'updated', |
||
| 292 | 'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ), |
||
| 293 | 'show' => true, |
||
| 294 | ) ); |
||
| 295 | break; |
||
| 296 | } |
||
| 297 | } |
||
| 298 | // Payments errors. |
||
| 299 | if ( current_user_can( 'edit_give_payments' ) ) { |
||
| 300 | switch ( $_GET['give-message'] ) { |
||
| 301 | View Code Duplication | case 'note-added' : |
|
| 302 | Give()->notices->register_notice( array( |
||
| 303 | 'id' => 'give-note-added', |
||
| 304 | 'type' => 'updated', |
||
| 305 | 'description' => __( 'The donation note has been added.', 'give' ), |
||
| 306 | 'show' => true, |
||
| 307 | ) ); |
||
| 308 | break; |
||
| 309 | View Code Duplication | case 'payment-updated' : |
|
| 310 | Give()->notices->register_notice( array( |
||
| 311 | 'id' => 'give-payment-updated', |
||
| 312 | 'type' => 'updated', |
||
| 313 | 'description' => __( 'The donation has been updated.', 'give' ), |
||
| 314 | 'show' => true, |
||
| 315 | ) ); |
||
| 316 | break; |
||
| 317 | } |
||
| 318 | } |
||
| 319 | |||
| 320 | // Donor Notices. |
||
| 321 | if ( current_user_can( 'edit_give_payments' ) ) { |
||
| 322 | switch ( $_GET['give-message'] ) { |
||
| 323 | View Code Duplication | case 'donor-deleted' : |
|
| 324 | Give()->notices->register_notice( array( |
||
| 325 | 'id' => 'give-donor-deleted', |
||
| 326 | 'type' => 'updated', |
||
| 327 | 'description' => __( 'The donor has been deleted.', 'give' ), |
||
| 328 | 'show' => true, |
||
| 329 | ) ); |
||
| 330 | break; |
||
| 331 | |||
| 332 | View Code Duplication | case 'email-added' : |
|
| 333 | Give()->notices->register_notice( array( |
||
| 334 | 'id' => 'give-donor-email-added', |
||
| 335 | 'type' => 'updated', |
||
| 336 | 'description' => __( 'Donor email added.', 'give' ), |
||
| 337 | 'show' => true, |
||
| 338 | ) ); |
||
| 339 | break; |
||
| 340 | |||
| 341 | View Code Duplication | case 'email-removed' : |
|
| 342 | Give()->notices->register_notice( array( |
||
| 343 | 'id' => 'give-donor-email-removed', |
||
| 344 | 'type' => 'updated', |
||
| 345 | 'description' => __( 'Donor email removed.', 'give' ), |
||
| 346 | 'show' => true, |
||
| 347 | ) ); |
||
| 348 | break; |
||
| 349 | |||
| 350 | View Code Duplication | case 'email-remove-failed' : |
|
| 351 | Give()->notices->register_notice( array( |
||
| 352 | 'id' => 'give-donor-email-remove-failed', |
||
| 353 | 'type' => 'updated', |
||
| 354 | 'description' => __( 'Failed to remove donor email.', 'give' ), |
||
| 355 | 'show' => true, |
||
| 356 | ) ); |
||
| 357 | break; |
||
| 358 | |||
| 359 | View Code Duplication | case 'primary-email-updated' : |
|
| 360 | Give()->notices->register_notice( array( |
||
| 361 | 'id' => 'give-donor-primary-email-updated', |
||
| 362 | 'type' => 'updated', |
||
| 363 | 'description' => __( 'Primary email updated for donor.', 'give' ), |
||
| 364 | 'show' => true, |
||
| 365 | ) ); |
||
| 366 | break; |
||
| 367 | |||
| 368 | View Code Duplication | case 'primary-email-failed' : |
|
| 369 | Give()->notices->register_notice( array( |
||
| 370 | 'id' => 'give-donor-primary-email-failed', |
||
| 371 | 'type' => 'updated', |
||
| 372 | 'description' => __( 'Failed to set primary email.', 'give' ), |
||
| 373 | 'show' => true, |
||
| 374 | ) ); |
||
| 375 | break; |
||
| 376 | } |
||
| 377 | } |
||
| 378 | } |
||
| 379 | } |
||
| 380 | |||
| 414 | add_action( 'admin_bar_menu', '_give_show_test_mode_notice_in_admin_bar', 1000, 1 ); |