| Conditions | 11 |
| Paths | 320 |
| Total Lines | 295 |
| Code Lines | 199 |
| 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 |
||
| 24 | public static function output( $post ) { |
||
| 25 | |||
| 26 | // Prepare the item. |
||
| 27 | $item = new WPInv_Item( $post ); |
||
| 28 | |||
| 29 | // Nonce field. |
||
| 30 | wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
||
| 31 | |||
| 32 | // Set the currency position. |
||
| 33 | $position = wpinv_currency_position(); |
||
| 34 | |||
| 35 | if ( $position == 'left_space' ) { |
||
| 36 | $position = 'left'; |
||
| 37 | } |
||
| 38 | |||
| 39 | if ( $position == 'right_space' ) { |
||
| 40 | $position = 'right'; |
||
| 41 | } |
||
| 42 | |||
| 43 | ?> |
||
| 44 | <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" /> |
||
| 45 | <style> |
||
| 46 | #poststuff .input-group-text, |
||
| 47 | #poststuff .form-control { |
||
| 48 | border-color: #7e8993; |
||
| 49 | } |
||
| 50 | |||
| 51 | .bsui label.col-sm-3.col-form-label { |
||
| 52 | font-weight: 600; |
||
| 53 | } |
||
| 54 | |||
| 55 | </style> |
||
| 56 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
||
| 57 | |||
| 58 | <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?> |
||
| 59 | <div class="form-group row"> |
||
| 60 | <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e( 'Item Price', 'invoicing' )?></span></label> |
||
| 61 | <div class="col-sm-8"> |
||
| 62 | <div class="row"> |
||
| 63 | <div class="col-sm-4 getpaid-price-input"> |
||
| 64 | <div class="input-group input-group-sm"> |
||
| 65 | <?php if( 'left' == $position ) : ?> |
||
| 66 | <div class="input-group-prepend"> |
||
| 67 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
||
|
|
|||
| 68 | </div> |
||
| 69 | <?php endif; ?> |
||
| 70 | <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( $item->get_price( 'edit' ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
||
| 71 | |||
| 72 | <?php if( 'left' != $position ) : ?> |
||
| 73 | <div class="input-group-append"> |
||
| 74 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
||
| 75 | </div> |
||
| 76 | <?php endif; ?> |
||
| 77 | </div> |
||
| 78 | |||
| 79 | </div> |
||
| 80 | <div class="col-sm-4 wpinv_show_if_recurring"> |
||
| 81 | <?php |
||
| 82 | echo aui()->select( |
||
| 83 | array( |
||
| 84 | 'id' => 'wpinv_recurring_interval', |
||
| 85 | 'name' => 'wpinv_recurring_interval', |
||
| 86 | 'label' => __( 'Interval', 'invoicing' ), |
||
| 87 | 'placeholder' => __( 'Select Interval', 'invoicing' ), |
||
| 88 | 'value' => $item->get_recurring_interval( 'edit' ), |
||
| 89 | 'select2' => true, |
||
| 90 | 'data-allow-clear' => 'false', |
||
| 91 | 'options' => array( |
||
| 92 | '1' => __( 'every', 'invoicing' ), |
||
| 93 | '2' => __( 'every 2nd', 'invoicing' ), |
||
| 94 | '3' => __( 'every 3rd', 'invoicing' ), |
||
| 95 | '4' => __( 'every 4th', 'invoicing' ), |
||
| 96 | '5' => __( 'every 5th', 'invoicing' ), |
||
| 97 | '6' => __( 'every 6th', 'invoicing' ), |
||
| 98 | '8' => __( 'every 8th', 'invoicing' ), |
||
| 99 | '9' => __( 'every 9th', 'invoicing' ), |
||
| 100 | '10' => __( 'every 10th', 'invoicing' ), |
||
| 101 | '11' => __( 'every 11th', 'invoicing' ), |
||
| 102 | '12' => __( 'every 12th', 'invoicing' ), |
||
| 103 | '13' => __( 'every 13th', 'invoicing' ), |
||
| 104 | '14' => __( 'every 14th', 'invoicing' ), |
||
| 105 | ) |
||
| 106 | ) |
||
| 107 | ); |
||
| 108 | ?> |
||
| 109 | </div> |
||
| 110 | <div class="col-sm-4 wpinv_show_if_recurring"> |
||
| 111 | <?php |
||
| 112 | echo aui()->select( |
||
| 113 | array( |
||
| 114 | 'id' => 'wpinv_recurring_period', |
||
| 115 | 'name' => 'wpinv_recurring_period', |
||
| 116 | 'label' => __( 'Period', 'invoicing' ), |
||
| 117 | 'placeholder' => __( 'Select Period', 'invoicing' ), |
||
| 118 | 'value' => $item->get_recurring_period( 'edit' ), |
||
| 119 | 'select2' => true, |
||
| 120 | 'data-allow-clear' => 'false', |
||
| 121 | 'options' => array( |
||
| 122 | 'D' => __( 'day', 'invoicing' ), |
||
| 123 | 'W' => __( 'week', 'invoicing' ), |
||
| 124 | 'M' => __( 'month', 'invoicing' ), |
||
| 125 | 'Y' => __( 'year', 'invoicing' ), |
||
| 126 | ) |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | ?> |
||
| 130 | </div> |
||
| 131 | </div> |
||
| 132 | <div class="row"> |
||
| 133 | <div class="col-sm-12"> |
||
| 134 | <?php |
||
| 135 | |||
| 136 | // Dynamic pricing. |
||
| 137 | if( $item->supports_dynamic_pricing() ) { |
||
| 138 | |||
| 139 | do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
||
| 140 | |||
| 141 | // NYP toggle. |
||
| 142 | echo aui()->input( |
||
| 143 | array( |
||
| 144 | 'id' => 'wpinv_name_your_price', |
||
| 145 | 'name' => 'wpinv_name_your_price', |
||
| 146 | 'type' => 'checkbox', |
||
| 147 | 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
||
| 148 | 'value' => '1', |
||
| 149 | 'checked' => $item->user_can_set_their_price(), |
||
| 150 | 'no_wrap' => true, |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | |||
| 154 | do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
||
| 155 | |||
| 156 | } |
||
| 157 | |||
| 158 | // Subscriptions. |
||
| 159 | do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item ); |
||
| 160 | echo aui()->input( |
||
| 161 | array( |
||
| 162 | 'id' => 'wpinv_is_recurring', |
||
| 163 | 'name' => 'wpinv_is_recurring', |
||
| 164 | 'type' => 'checkbox', |
||
| 165 | 'label' => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ), |
||
| 166 | 'value' => '1', |
||
| 167 | 'checked' => $item->is_recurring(), |
||
| 168 | 'no_wrap' => true, |
||
| 169 | ) |
||
| 170 | ); |
||
| 171 | do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item ); |
||
| 172 | |||
| 173 | ?> |
||
| 174 | <div class="wpinv_show_if_recurring"> |
||
| 175 | <em><?php echo wpinv_get_recurring_gateways_text(); ?></em> |
||
| 176 | </div> |
||
| 177 | </div> |
||
| 178 | </div> |
||
| 179 | </div> |
||
| 180 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 181 | <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span> |
||
| 182 | </div> |
||
| 183 | </div> |
||
| 184 | <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?> |
||
| 185 | |||
| 186 | <?php if( $item->supports_dynamic_pricing() ) : ?> |
||
| 187 | <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?> |
||
| 188 | <div class="wpinv_show_if_dynamic wpinv_minimum_price"> |
||
| 189 | |||
| 190 | <div class="form-group row"> |
||
| 191 | <label for="wpinv_minimum_price" class="col-sm-3 col-form-label"> |
||
| 192 | <?php _e( 'Minimum Price', 'invoicing' );?> |
||
| 193 | </label> |
||
| 194 | <div class="col-sm-8"> |
||
| 195 | <div class="input-group input-group-sm"> |
||
| 196 | <?php if( 'left' == $position ) : ?> |
||
| 197 | <div class="input-group-prepend"> |
||
| 198 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
||
| 199 | </div> |
||
| 200 | <?php endif; ?> |
||
| 201 | |||
| 202 | <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( $item->get_minimum_price( 'edit' ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
||
| 203 | |||
| 204 | <?php if( 'left' != $position ) : ?> |
||
| 205 | <div class="input-group-append"> |
||
| 206 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
||
| 207 | </div> |
||
| 208 | <?php endif; ?> |
||
| 209 | </div> |
||
| 210 | </div> |
||
| 211 | |||
| 212 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 213 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span> |
||
| 214 | </div> |
||
| 215 | </div> |
||
| 216 | |||
| 217 | </div> |
||
| 218 | <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?> |
||
| 219 | <?php endif; ?> |
||
| 220 | |||
| 221 | <?php |
||
| 222 | // one time Subscriptions. |
||
| 223 | do_action( 'wpinv_item_details_metabox_before_one_time_subscription_checkbox', $item ); |
||
| 224 | ?> |
||
| 225 | <div class="wpinv_show_if_recurring wpinv_one_time_recurring"> |
||
| 226 | <div class="form-group row"> |
||
| 227 | <label for="wpinv_is_one_time_recurring" class="col-sm-3 col-form-label"> |
||
| 228 | <?php _e( 'One time only (non-recurring)?', 'invoicing' );?> |
||
| 229 | </label> |
||
| 230 | |||
| 231 | <div class="col-sm-8"> |
||
| 232 | <div class="row"> |
||
| 233 | <div class="col-sm-12"> |
||
| 234 | <div class="custom-control custom-checkbox"> |
||
| 235 | <input type="checkbox" value="1" <?php echo ($item->is_one_time_recurring()) ? 'checked' : ''; ?> class="form-control custom-control-input" name="wpinv_is_one_time_recurring" id="wpinv_is_one_time_recurring" /><label for="wpinv_is_one_time_recurring" class=" custom-control-label">Change customers a recurring amount for one time only.</label> |
||
| 236 | </div> |
||
| 237 | <div class="wpinv_show_if_recurring"> |
||
| 238 | <em><span class="form-text text-muted"><?php echo apply_filters( 'wpinv_is_one_time_recurring_toggle_help_text', __( 'It will appear as a recurring payment, at the next renewal date it will complete the subscription without any deductions.', 'invoicing' ) ) ?></span></em> |
||
| 239 | </div> |
||
| 240 | </div> |
||
| 241 | </div> |
||
| 242 | </div> |
||
| 243 | </div> |
||
| 244 | </div> |
||
| 245 | <?php |
||
| 246 | do_action( 'wpinv_item_details_metabox_one_time_subscription_checkbox', $item ); |
||
| 247 | ?> |
||
| 248 | |||
| 249 | <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?> |
||
| 250 | <div class="wpinv_show_if_recurring wpinv_maximum_renewals"> |
||
| 251 | |||
| 252 | <div class="form-group row"> |
||
| 253 | <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label"> |
||
| 254 | <?php _e( 'Maximum Renewals', 'invoicing' );?> |
||
| 255 | </label> |
||
| 256 | <div class="col-sm-8"> |
||
| 257 | <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
||
| 258 | </div> |
||
| 259 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 260 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span> |
||
| 261 | </div> |
||
| 262 | </div> |
||
| 263 | |||
| 264 | </div> |
||
| 265 | <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?> |
||
| 266 | |||
| 267 | <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?> |
||
| 268 | <div class="wpinv_show_if_recurring wpinv_free_trial"> |
||
| 269 | |||
| 270 | <div class="form-group row"> |
||
| 271 | <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e( 'Free Trial', 'invoicing' )?></label> |
||
| 272 | |||
| 273 | <div class="col-sm-8"> |
||
| 274 | <div class="row"> |
||
| 275 | <div class="col-sm-6"> |
||
| 276 | <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0;?> |
||
| 277 | |||
| 278 | <div> |
||
| 279 | <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" > |
||
| 280 | </div> |
||
| 281 | </div> |
||
| 282 | <div class="col-sm-6"> |
||
| 283 | <?php |
||
| 284 | echo aui()->select( |
||
| 285 | array( |
||
| 286 | 'id' => 'wpinv_trial_period', |
||
| 287 | 'name' => 'wpinv_trial_period', |
||
| 288 | 'label' => __( 'Trial Period', 'invoicing' ), |
||
| 289 | 'placeholder' => __( 'Trial Period', 'invoicing' ), |
||
| 290 | 'value' => $item->get_trial_period( 'edit' ), |
||
| 291 | 'select2' => true, |
||
| 292 | 'data-allow-clear' => 'false', |
||
| 293 | 'no_wrap' => true, |
||
| 294 | 'options' => array( |
||
| 295 | 'D' => __( 'day(s)', 'invoicing' ), |
||
| 296 | 'W' => __( 'week(s)', 'invoicing' ), |
||
| 297 | 'M' => __( 'month(s)', 'invoicing' ), |
||
| 298 | 'Y' => __( 'year(s)', 'invoicing' ), |
||
| 299 | ) |
||
| 300 | ) |
||
| 301 | ); |
||
| 302 | ?> |
||
| 303 | |||
| 304 | </div> |
||
| 305 | </div> |
||
| 306 | </div> |
||
| 307 | |||
| 308 | <div class="col-sm-1 pt-2 pl-0"> |
||
| 309 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span> |
||
| 310 | </div> |
||
| 311 | |||
| 312 | </div> |
||
| 313 | |||
| 314 | </div> |
||
| 315 | <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?> |
||
| 316 | |||
| 317 | <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?> |
||
| 318 | </div> |
||
| 319 | <?php |
||
| 360 |