| Conditions | 27 |
| Paths | 192 |
| Total Lines | 82 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 57 | |||
| 58 | function wpinv_admin_messages() { |
||
| 59 | global $wpinv_options, $pagenow, $post; |
||
| 60 | |||
| 61 | if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 62 | add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 66 | add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 70 | add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 74 | add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 78 | add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 82 | add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 86 | add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 90 | add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 94 | add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 98 | add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 102 | add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 106 | add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
||
| 107 | } |
||
| 108 | |||
| 109 | if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
||
| 110 | add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
||
| 111 | } |
||
| 112 | |||
| 113 | if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
||
| 114 | $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
||
| 115 | |||
| 116 | if ( !empty( $message ) ) { |
||
| 117 | add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | settings_errors( 'wpinv-notices' ); |
||
| 122 | } |
||
| 123 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
||
| 124 | |||
| 125 | add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
||
| 126 | function wpinv_show_test_payment_gateway_notice(){ |
||
| 127 | add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
||
| 128 | } |
||
| 129 | |||
| 130 | function wpinv_test_payment_gateway_messages(){ |
||
| 131 | $gateways = wpinv_get_enabled_payment_gateways(); |
||
| 132 | $name = array(); $test_gateways = ''; |
||
| 133 | if ($gateways) { |
||
| 134 | foreach ($gateways as $id => $gateway) { |
||
| 135 | if (wpinv_is_test_mode($id)) { |
||
| 136 | $name[] = $gateway['checkout_label']; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | $test_gateways = implode(', ', $name); |
||
| 222 |