@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | $args = wp_parse_args( |
| 58 | 58 | $args, |
| 59 | 59 | array( |
| 60 | - 'status' => array( 'publish' ), |
|
| 61 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | - 'page' => 1, |
|
| 63 | - 'exclude' => array(), |
|
| 64 | - 'orderby' => 'date', |
|
| 65 | - 'order' => 'DESC', |
|
| 66 | - 'type' => wpinv_item_types(), |
|
| 67 | - 'meta_query' => array( |
|
| 60 | + 'status' => array( 'publish' ), |
|
| 61 | + 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | + 'page' => 1, |
|
| 63 | + 'exclude' => array(), |
|
| 64 | + 'orderby' => 'date', |
|
| 65 | + 'order' => 'DESC', |
|
| 66 | + 'type' => wpinv_item_types(), |
|
| 67 | + 'meta_query' => array( |
|
| 68 | 68 | array( |
| 69 | 69 | 'key' => '_wpinv_one_time', |
| 70 | 70 | 'compare' => 'NOT EXISTS', |
| 71 | 71 | ), |
| 72 | 72 | ), |
| 73 | - 'return' => 'objects', |
|
| 74 | - 'paginate' => false, |
|
| 73 | + 'return' => 'objects', |
|
| 74 | + 'paginate' => false, |
|
| 75 | 75 | ) |
| 76 | 76 | ); |
| 77 | 77 | |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | function wpinv_get_item_types() { |
| 213 | 213 | $item_types = array( |
| 214 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 215 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 216 | - ); |
|
| 214 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
| 215 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
| 216 | + ); |
|
| 217 | 217 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -255,16 +255,16 @@ discard block |
||
| 255 | 255 | $args = array(); |
| 256 | 256 | if ( $post_ids ) { |
| 257 | 257 | $args = array( |
| 258 | - 'fields' => 'ids', |
|
| 259 | - ); |
|
| 258 | + 'fields' => 'ids', |
|
| 259 | + ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $args = array_merge( |
| 263 | 263 | $args, |
| 264 | 264 | array( |
| 265 | 265 | 'post_type' => 'wpi_item', |
| 266 | - 'orderby' => 'rand', |
|
| 267 | - 'post_count' => $num, |
|
| 266 | + 'orderby' => 'rand', |
|
| 267 | + 'post_count' => $num, |
|
| 268 | 268 | 'meta_query' => array( |
| 269 | 269 | array( |
| 270 | 270 | 'key' => '_wpinv_one_time', |
@@ -439,10 +439,10 @@ discard block |
||
| 439 | 439 | $bill_times_less = $bill_times - 1; |
| 440 | 440 | |
| 441 | 441 | if ( ! empty( $bill_times ) ) { |
| 442 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 442 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 443 | 443 | $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
| 444 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 445 | - } |
|
| 444 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | 447 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
| 448 | 448 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -587,19 +587,19 @@ discard block |
||
| 587 | 587 | * @return bool Whether the item type supports the given feature. |
| 588 | 588 | */ |
| 589 | 589 | function getpaid_item_type_supports( $item_type, $feature, $item_ID = 0 ) { |
| 590 | - $supports = false; |
|
| 590 | + $supports = false; |
|
| 591 | 591 | |
| 592 | - if ( ! is_scalar( $item_type ) ) { |
|
| 593 | - return $supports; |
|
| 594 | - } |
|
| 592 | + if ( ! is_scalar( $item_type ) ) { |
|
| 593 | + return $supports; |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - switch ( $feature ) { |
|
| 597 | - case 'buy_now': |
|
| 598 | - if ( '' === $item_type || 'fee' === $item_type || 'custom' === $item_type ) { |
|
| 599 | - $supports = true; |
|
| 600 | - } |
|
| 601 | - break; |
|
| 602 | - } |
|
| 596 | + switch ( $feature ) { |
|
| 597 | + case 'buy_now': |
|
| 598 | + if ( '' === $item_type || 'fee' === $item_type || 'custom' === $item_type ) { |
|
| 599 | + $supports = true; |
|
| 600 | + } |
|
| 601 | + break; |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - return apply_filters( 'getpaid_item_type_supports', $supports, $item_type, $feature, $item_ID ); |
|
| 604 | + return apply_filters( 'getpaid_item_type_supports', $supports, $item_type, $feature, $item_ID ); |
|
| 605 | 605 | } |
| 606 | 606 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,1291 +11,1291 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Input { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Build the component. |
|
| 16 | - * |
|
| 17 | - * @param array $args |
|
| 18 | - * |
|
| 19 | - * @return string The rendered component. |
|
| 20 | - */ |
|
| 21 | - public static function input( $args = array() ) { |
|
| 22 | - global $aui_bs5; |
|
| 23 | - |
|
| 24 | - $defaults = array( |
|
| 25 | - 'type' => 'text', |
|
| 26 | - 'name' => '', |
|
| 27 | - 'class' => '', |
|
| 28 | - 'wrap_class' => '', |
|
| 29 | - 'id' => '', |
|
| 30 | - 'placeholder' => '', |
|
| 31 | - 'title' => '', |
|
| 32 | - 'value' => '', |
|
| 33 | - 'required' => false, |
|
| 34 | - 'size' => '', // sm, lg, small, large |
|
| 35 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
| 36 | - 'with_hidden' => false, // Append hidden field for single checkbox. |
|
| 37 | - 'label' => '', |
|
| 38 | - 'label_after' => false, |
|
| 39 | - 'label_class' => '', |
|
| 40 | - 'label_col' => '2', |
|
| 41 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
| 42 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
| 43 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 44 | - 'help_text' => '', |
|
| 45 | - 'validation_text' => '', |
|
| 46 | - 'validation_pattern' => '', |
|
| 47 | - 'no_wrap' => false, |
|
| 48 | - 'input_group_right' => '', |
|
| 49 | - 'input_group_left' => '', |
|
| 50 | - 'input_group_right_inside' => false, |
|
| 51 | - // forces the input group inside the input |
|
| 52 | - 'input_group_left_inside' => false, |
|
| 53 | - // forces the input group inside the input |
|
| 54 | - 'form_group_class' => '', |
|
| 55 | - 'step' => '', |
|
| 56 | - 'switch' => false, |
|
| 57 | - // to show checkbox as a switch |
|
| 58 | - 'checked' => false, |
|
| 59 | - // set a checkbox or radio as selected |
|
| 60 | - 'password_toggle' => true, |
|
| 61 | - // toggle view/hide password |
|
| 62 | - 'element_require' => '', |
|
| 63 | - // [%element_id%] == "1" |
|
| 64 | - 'extra_attributes' => array(), |
|
| 65 | - // an array of extra attributes |
|
| 66 | - 'wrap_attributes' => array() |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 71 | - */ |
|
| 72 | - $args = wp_parse_args( $args, $defaults ); |
|
| 73 | - $output = ''; |
|
| 74 | - if ( ! empty( $args['type'] ) ) { |
|
| 75 | - // hidden label option needs to be empty |
|
| 76 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 77 | - |
|
| 78 | - $type = sanitize_html_class( $args['type'] ); |
|
| 79 | - |
|
| 80 | - $help_text = ''; |
|
| 81 | - $label = ''; |
|
| 82 | - $label_after = $args['label_after']; |
|
| 83 | - $label_args = array( |
|
| 84 | - 'title' => $args['label'], |
|
| 85 | - 'for' => $args['id'], |
|
| 86 | - 'class' => $args['label_class'] . " ", |
|
| 87 | - 'label_type' => $args['label_type'], |
|
| 88 | - 'label_col' => $args['label_col'] |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - // floating labels need label after |
|
| 92 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
| 93 | - $label_after = true; |
|
| 94 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // size |
|
| 98 | - $size = ''; |
|
| 99 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
| 100 | - $size = 'lg'; |
|
| 101 | - $args['class'] .= ' form-control-lg'; |
|
| 102 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
| 103 | - $size = 'sm'; |
|
| 104 | - $args['class'] .= ' form-control-sm'; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // clear function |
|
| 108 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
| 109 | - |
|
| 110 | - // Some special sauce for files |
|
| 111 | - if ( $type == 'file' ) { |
|
| 112 | - $label_after = true; // if type file we need the label after |
|
| 113 | - $args['class'] .= ' custom-file-input '; |
|
| 114 | - } elseif ( $type == 'checkbox' ) { |
|
| 115 | - $label_after = true; // if type file we need the label after |
|
| 116 | - $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer '; |
|
| 117 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
| 118 | - $orig_type = $type; |
|
| 119 | - $type = 'text'; |
|
| 120 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
| 121 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
| 122 | - |
|
| 123 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 124 | - |
|
| 125 | - // Disable native datetime inputs. |
|
| 126 | - $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true'; |
|
| 127 | - $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args ); |
|
| 128 | - |
|
| 129 | - $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr; |
|
| 130 | - |
|
| 131 | - // set a way to clear field if empty |
|
| 132 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
| 133 | - $args['input_group_right_inside'] = true; |
|
| 134 | - $args['clear_icon'] = true; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // enqueue the script |
|
| 138 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 139 | - $aui_settings->enqueue_flatpickr(); |
|
| 140 | - } elseif ( $type == 'iconpicker' ) { |
|
| 141 | - $type = 'text'; |
|
| 142 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 14 | + /** |
|
| 15 | + * Build the component. |
|
| 16 | + * |
|
| 17 | + * @param array $args |
|
| 18 | + * |
|
| 19 | + * @return string The rendered component. |
|
| 20 | + */ |
|
| 21 | + public static function input( $args = array() ) { |
|
| 22 | + global $aui_bs5; |
|
| 23 | + |
|
| 24 | + $defaults = array( |
|
| 25 | + 'type' => 'text', |
|
| 26 | + 'name' => '', |
|
| 27 | + 'class' => '', |
|
| 28 | + 'wrap_class' => '', |
|
| 29 | + 'id' => '', |
|
| 30 | + 'placeholder' => '', |
|
| 31 | + 'title' => '', |
|
| 32 | + 'value' => '', |
|
| 33 | + 'required' => false, |
|
| 34 | + 'size' => '', // sm, lg, small, large |
|
| 35 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
| 36 | + 'with_hidden' => false, // Append hidden field for single checkbox. |
|
| 37 | + 'label' => '', |
|
| 38 | + 'label_after' => false, |
|
| 39 | + 'label_class' => '', |
|
| 40 | + 'label_col' => '2', |
|
| 41 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
| 42 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
| 43 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 44 | + 'help_text' => '', |
|
| 45 | + 'validation_text' => '', |
|
| 46 | + 'validation_pattern' => '', |
|
| 47 | + 'no_wrap' => false, |
|
| 48 | + 'input_group_right' => '', |
|
| 49 | + 'input_group_left' => '', |
|
| 50 | + 'input_group_right_inside' => false, |
|
| 51 | + // forces the input group inside the input |
|
| 52 | + 'input_group_left_inside' => false, |
|
| 53 | + // forces the input group inside the input |
|
| 54 | + 'form_group_class' => '', |
|
| 55 | + 'step' => '', |
|
| 56 | + 'switch' => false, |
|
| 57 | + // to show checkbox as a switch |
|
| 58 | + 'checked' => false, |
|
| 59 | + // set a checkbox or radio as selected |
|
| 60 | + 'password_toggle' => true, |
|
| 61 | + // toggle view/hide password |
|
| 62 | + 'element_require' => '', |
|
| 63 | + // [%element_id%] == "1" |
|
| 64 | + 'extra_attributes' => array(), |
|
| 65 | + // an array of extra attributes |
|
| 66 | + 'wrap_attributes' => array() |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 71 | + */ |
|
| 72 | + $args = wp_parse_args( $args, $defaults ); |
|
| 73 | + $output = ''; |
|
| 74 | + if ( ! empty( $args['type'] ) ) { |
|
| 75 | + // hidden label option needs to be empty |
|
| 76 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 77 | + |
|
| 78 | + $type = sanitize_html_class( $args['type'] ); |
|
| 79 | + |
|
| 80 | + $help_text = ''; |
|
| 81 | + $label = ''; |
|
| 82 | + $label_after = $args['label_after']; |
|
| 83 | + $label_args = array( |
|
| 84 | + 'title' => $args['label'], |
|
| 85 | + 'for' => $args['id'], |
|
| 86 | + 'class' => $args['label_class'] . " ", |
|
| 87 | + 'label_type' => $args['label_type'], |
|
| 88 | + 'label_col' => $args['label_col'] |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + // floating labels need label after |
|
| 92 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
| 93 | + $label_after = true; |
|
| 94 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // size |
|
| 98 | + $size = ''; |
|
| 99 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
| 100 | + $size = 'lg'; |
|
| 101 | + $args['class'] .= ' form-control-lg'; |
|
| 102 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
| 103 | + $size = 'sm'; |
|
| 104 | + $args['class'] .= ' form-control-sm'; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // clear function |
|
| 108 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
| 109 | + |
|
| 110 | + // Some special sauce for files |
|
| 111 | + if ( $type == 'file' ) { |
|
| 112 | + $label_after = true; // if type file we need the label after |
|
| 113 | + $args['class'] .= ' custom-file-input '; |
|
| 114 | + } elseif ( $type == 'checkbox' ) { |
|
| 115 | + $label_after = true; // if type file we need the label after |
|
| 116 | + $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer '; |
|
| 117 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
| 118 | + $orig_type = $type; |
|
| 119 | + $type = 'text'; |
|
| 120 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
| 121 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
| 122 | + |
|
| 123 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 124 | + |
|
| 125 | + // Disable native datetime inputs. |
|
| 126 | + $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true'; |
|
| 127 | + $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args ); |
|
| 128 | + |
|
| 129 | + $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr; |
|
| 130 | + |
|
| 131 | + // set a way to clear field if empty |
|
| 132 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
| 133 | + $args['input_group_right_inside'] = true; |
|
| 134 | + $args['clear_icon'] = true; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // enqueue the script |
|
| 138 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 139 | + $aui_settings->enqueue_flatpickr(); |
|
| 140 | + } elseif ( $type == 'iconpicker' ) { |
|
| 141 | + $type = 'text'; |
|
| 142 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 143 | 143 | // $args['class'] .= ' bg-initial '; |
| 144 | 144 | |
| 145 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
| 146 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
| 145 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
| 146 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
| 147 | 147 | |
| 148 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
| 148 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
| 149 | 149 | // $args['input_group_right_inside'] = true; |
| 150 | - // enqueue the script |
|
| 151 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 152 | - $aui_settings->enqueue_iconpicker(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
| 156 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // allow clear icon |
|
| 160 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
| 161 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
| 162 | - $args['input_group_right_inside'] = true; |
|
| 163 | - $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
| 164 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // open/type |
|
| 168 | - $output .= '<input type="' . $type . '" '; |
|
| 169 | - |
|
| 170 | - // name |
|
| 171 | - if ( ! empty( $args['name'] ) ) { |
|
| 172 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // id |
|
| 176 | - if ( ! empty( $args['id'] ) ) { |
|
| 177 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // placeholder |
|
| 181 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 182 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // title |
|
| 186 | - if ( ! empty( $args['title'] ) ) { |
|
| 187 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // value |
|
| 191 | - if ( ! empty( $args['value'] ) ) { |
|
| 192 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // checked, for radio and checkboxes |
|
| 196 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
| 197 | - $output .= ' checked '; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // validation text |
|
| 201 | - if ( ! empty( $args['validation_text'] ) ) { |
|
| 202 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
| 203 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // validation_pattern |
|
| 207 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 208 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // step (for numbers) |
|
| 212 | - if ( ! empty( $args['step'] ) ) { |
|
| 213 | - $output .= ' step="' . $args['step'] . '" '; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // required |
|
| 217 | - if ( ! empty( $args['required'] ) ) { |
|
| 218 | - $output .= ' required '; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // class |
|
| 222 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 223 | - $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
| 224 | - |
|
| 225 | - // data-attributes |
|
| 226 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 227 | - |
|
| 228 | - // extra attributes |
|
| 229 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 230 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // close |
|
| 234 | - $output .= ' >'; |
|
| 235 | - |
|
| 236 | - // help text |
|
| 237 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 238 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // label |
|
| 242 | - if ( ! empty( $args['label'] ) ) { |
|
| 243 | - $label_base_class = ''; |
|
| 244 | - if ( $type == 'file' ) { |
|
| 245 | - $label_base_class = ' custom-file-label'; |
|
| 246 | - } elseif ( $type == 'checkbox' ) { |
|
| 247 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
| 248 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
| 249 | - $help_text = ''; |
|
| 250 | - //$label_args['class'] .= ' d-inline '; |
|
| 251 | - $args['wrap_class'] .= ' align-items-center '; |
|
| 252 | - }else{ |
|
| 253 | - |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
| 257 | - } |
|
| 258 | - $label_args['class'] .= $label_base_class; |
|
| 259 | - $temp_label_args = $label_args; |
|
| 260 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
| 261 | - $label = self::label( $temp_label_args, $type ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - // set help text in the correct position |
|
| 268 | - if ( $label_after ) { |
|
| 269 | - $output .= $label . $help_text; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // some input types need a separate wrap |
|
| 273 | - if ( $type == 'file' ) { |
|
| 274 | - $output = self::wrap( array( |
|
| 275 | - 'content' => $output, |
|
| 276 | - 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
| 277 | - ) ); |
|
| 278 | - } elseif ( $type == 'checkbox' ) { |
|
| 279 | - |
|
| 280 | - $label_args['title'] = $args['label']; |
|
| 281 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
| 282 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
| 283 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
| 284 | - if ( $aui_bs5 ) { |
|
| 285 | - $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
| 286 | - }else{ |
|
| 287 | - $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
| 288 | - } |
|
| 289 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
| 290 | - $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
| 291 | - $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
| 292 | - } |
|
| 293 | - $output = self::wrap( array( |
|
| 294 | - 'content' => $output, |
|
| 295 | - 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
| 296 | - ) ); |
|
| 297 | - |
|
| 298 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 299 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 300 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
| 301 | - } |
|
| 302 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - // allow password field to toggle view |
|
| 306 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 150 | + // enqueue the script |
|
| 151 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 152 | + $aui_settings->enqueue_iconpicker(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
| 156 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // allow clear icon |
|
| 160 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
| 161 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
| 162 | + $args['input_group_right_inside'] = true; |
|
| 163 | + $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
| 164 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // open/type |
|
| 168 | + $output .= '<input type="' . $type . '" '; |
|
| 169 | + |
|
| 170 | + // name |
|
| 171 | + if ( ! empty( $args['name'] ) ) { |
|
| 172 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // id |
|
| 176 | + if ( ! empty( $args['id'] ) ) { |
|
| 177 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // placeholder |
|
| 181 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 182 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // title |
|
| 186 | + if ( ! empty( $args['title'] ) ) { |
|
| 187 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // value |
|
| 191 | + if ( ! empty( $args['value'] ) ) { |
|
| 192 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // checked, for radio and checkboxes |
|
| 196 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
| 197 | + $output .= ' checked '; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // validation text |
|
| 201 | + if ( ! empty( $args['validation_text'] ) ) { |
|
| 202 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
| 203 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // validation_pattern |
|
| 207 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 208 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // step (for numbers) |
|
| 212 | + if ( ! empty( $args['step'] ) ) { |
|
| 213 | + $output .= ' step="' . $args['step'] . '" '; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // required |
|
| 217 | + if ( ! empty( $args['required'] ) ) { |
|
| 218 | + $output .= ' required '; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // class |
|
| 222 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 223 | + $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
| 224 | + |
|
| 225 | + // data-attributes |
|
| 226 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 227 | + |
|
| 228 | + // extra attributes |
|
| 229 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 230 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // close |
|
| 234 | + $output .= ' >'; |
|
| 235 | + |
|
| 236 | + // help text |
|
| 237 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 238 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // label |
|
| 242 | + if ( ! empty( $args['label'] ) ) { |
|
| 243 | + $label_base_class = ''; |
|
| 244 | + if ( $type == 'file' ) { |
|
| 245 | + $label_base_class = ' custom-file-label'; |
|
| 246 | + } elseif ( $type == 'checkbox' ) { |
|
| 247 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
| 248 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
| 249 | + $help_text = ''; |
|
| 250 | + //$label_args['class'] .= ' d-inline '; |
|
| 251 | + $args['wrap_class'] .= ' align-items-center '; |
|
| 252 | + }else{ |
|
| 253 | + |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
| 257 | + } |
|
| 258 | + $label_args['class'] .= $label_base_class; |
|
| 259 | + $temp_label_args = $label_args; |
|
| 260 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
| 261 | + $label = self::label( $temp_label_args, $type ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + // set help text in the correct position |
|
| 268 | + if ( $label_after ) { |
|
| 269 | + $output .= $label . $help_text; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // some input types need a separate wrap |
|
| 273 | + if ( $type == 'file' ) { |
|
| 274 | + $output = self::wrap( array( |
|
| 275 | + 'content' => $output, |
|
| 276 | + 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
| 277 | + ) ); |
|
| 278 | + } elseif ( $type == 'checkbox' ) { |
|
| 279 | + |
|
| 280 | + $label_args['title'] = $args['label']; |
|
| 281 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
| 282 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
| 283 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
| 284 | + if ( $aui_bs5 ) { |
|
| 285 | + $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
| 286 | + }else{ |
|
| 287 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
| 288 | + } |
|
| 289 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
| 290 | + $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
| 291 | + $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
| 292 | + } |
|
| 293 | + $output = self::wrap( array( |
|
| 294 | + 'content' => $output, |
|
| 295 | + 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
| 296 | + ) ); |
|
| 297 | + |
|
| 298 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 299 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 300 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
| 301 | + } |
|
| 302 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + // allow password field to toggle view |
|
| 306 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 307 | 307 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
| 308 | 308 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
| 309 | 309 | if($el.hasClass(\'fa-eye\')) |
| 310 | 310 | {$eli.attr(\'type\',\'text\');} |
| 311 | 311 | else{$eli.attr(\'type\',\'password\');}" |
| 312 | 312 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
| 313 | - } |
|
| 314 | - |
|
| 315 | - // input group wraps |
|
| 316 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 317 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 318 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
| 319 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
| 320 | - |
|
| 321 | - if ( $args['input_group_left'] ) { |
|
| 322 | - $output = self::wrap( array( |
|
| 323 | - 'content' => $output, |
|
| 324 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 325 | - 'input_group_left' => $args['input_group_left'], |
|
| 326 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 327 | - ) ); |
|
| 328 | - } |
|
| 329 | - if ( $args['input_group_right'] ) { |
|
| 330 | - $output = self::wrap( array( |
|
| 331 | - 'content' => $output, |
|
| 332 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 333 | - 'input_group_right' => $args['input_group_right'], |
|
| 334 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 335 | - ) ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - if ( ! $label_after ) { |
|
| 341 | - $output .= $help_text; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 346 | - $output = self::wrap( array( |
|
| 347 | - 'content' => $output, |
|
| 348 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 349 | - ) ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if ( ! $label_after ) { |
|
| 353 | - $output = $label . $output; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // wrap |
|
| 357 | - if ( ! $args['no_wrap'] ) { |
|
| 358 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
| 359 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 360 | - }else{ |
|
| 361 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 362 | - } |
|
| 363 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
| 364 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 365 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 366 | - $output = self::wrap( array( |
|
| 367 | - 'content' => $output, |
|
| 368 | - 'class' => $wrap_class, |
|
| 369 | - 'element_require' => $args['element_require'], |
|
| 370 | - 'argument_id' => $args['id'], |
|
| 371 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 372 | - ) ); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - return $output; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - public static function label( $args = array(), $type = '' ) { |
|
| 380 | - global $aui_bs5; |
|
| 381 | - //<label for="exampleInputEmail1">Email address</label> |
|
| 382 | - $defaults = array( |
|
| 383 | - 'title' => 'div', |
|
| 384 | - 'for' => '', |
|
| 385 | - 'class' => '', |
|
| 386 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
| 387 | - 'label_col' => '', |
|
| 388 | - ); |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 392 | - */ |
|
| 393 | - $args = wp_parse_args( $args, $defaults ); |
|
| 394 | - $output = ''; |
|
| 395 | - |
|
| 396 | - if ( $args['title'] ) { |
|
| 397 | - |
|
| 398 | - // maybe hide labels //@todo set a global option for visibility class |
|
| 399 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
| 400 | - $class = $args['class']; |
|
| 401 | - } else { |
|
| 402 | - $class = 'sr-only ' . $args['class']; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - // maybe horizontal |
|
| 406 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 407 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if( $aui_bs5 ){ $class .= ' form-label'; } |
|
| 411 | - |
|
| 412 | - // open |
|
| 413 | - $output .= '<label '; |
|
| 414 | - |
|
| 415 | - // for |
|
| 416 | - if ( ! empty( $args['for'] ) ) { |
|
| 417 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - // class |
|
| 421 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 422 | - $output .= ' class="' . $class . '" '; |
|
| 423 | - |
|
| 424 | - // close |
|
| 425 | - $output .= '>'; |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - // title, don't escape fully as can contain html |
|
| 429 | - if ( ! empty( $args['title'] ) ) { |
|
| 430 | - $output .= wp_kses_post( $args['title'] ); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // close wrap |
|
| 434 | - $output .= '</label>'; |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - return $output; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Wrap some content in a HTML wrapper. |
|
| 445 | - * |
|
| 446 | - * @param array $args |
|
| 447 | - * |
|
| 448 | - * @return string |
|
| 449 | - */ |
|
| 450 | - public static function wrap( $args = array() ) { |
|
| 451 | - global $aui_bs5; |
|
| 452 | - $defaults = array( |
|
| 453 | - 'type' => 'div', |
|
| 454 | - 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
| 455 | - 'content' => '', |
|
| 456 | - 'input_group_left' => '', |
|
| 457 | - 'input_group_right' => '', |
|
| 458 | - 'input_group_left_inside' => false, |
|
| 459 | - 'input_group_right_inside' => false, |
|
| 460 | - 'element_require' => '', |
|
| 461 | - 'argument_id' => '', |
|
| 462 | - 'wrap_attributes' => array() |
|
| 463 | - ); |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 467 | - */ |
|
| 468 | - $args = wp_parse_args( $args, $defaults ); |
|
| 469 | - $output = ''; |
|
| 470 | - if ( $args['type'] ) { |
|
| 471 | - |
|
| 472 | - // open |
|
| 473 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
| 474 | - |
|
| 475 | - // element require |
|
| 476 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 477 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 478 | - $args['class'] .= " aui-conditional-field"; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - // argument_id |
|
| 482 | - if ( ! empty( $args['argument_id'] ) ) { |
|
| 483 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // class |
|
| 487 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 488 | - $output .= ' class="' . $class . '" '; |
|
| 489 | - |
|
| 490 | - // Attributes |
|
| 491 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
| 492 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // close wrap |
|
| 496 | - $output .= ' >'; |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - // Input group left |
|
| 500 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
| 501 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 502 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 503 | - $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // input group wraps |
|
| 316 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 317 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 318 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
| 319 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
| 320 | + |
|
| 321 | + if ( $args['input_group_left'] ) { |
|
| 322 | + $output = self::wrap( array( |
|
| 323 | + 'content' => $output, |
|
| 324 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 325 | + 'input_group_left' => $args['input_group_left'], |
|
| 326 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 327 | + ) ); |
|
| 328 | + } |
|
| 329 | + if ( $args['input_group_right'] ) { |
|
| 330 | + $output = self::wrap( array( |
|
| 331 | + 'content' => $output, |
|
| 332 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 333 | + 'input_group_right' => $args['input_group_right'], |
|
| 334 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 335 | + ) ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + if ( ! $label_after ) { |
|
| 341 | + $output .= $help_text; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 346 | + $output = self::wrap( array( |
|
| 347 | + 'content' => $output, |
|
| 348 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 349 | + ) ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if ( ! $label_after ) { |
|
| 353 | + $output = $label . $output; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // wrap |
|
| 357 | + if ( ! $args['no_wrap'] ) { |
|
| 358 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
| 359 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 360 | + }else{ |
|
| 361 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 362 | + } |
|
| 363 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
| 364 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 365 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 366 | + $output = self::wrap( array( |
|
| 367 | + 'content' => $output, |
|
| 368 | + 'class' => $wrap_class, |
|
| 369 | + 'element_require' => $args['element_require'], |
|
| 370 | + 'argument_id' => $args['id'], |
|
| 371 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 372 | + ) ); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + return $output; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + public static function label( $args = array(), $type = '' ) { |
|
| 380 | + global $aui_bs5; |
|
| 381 | + //<label for="exampleInputEmail1">Email address</label> |
|
| 382 | + $defaults = array( |
|
| 383 | + 'title' => 'div', |
|
| 384 | + 'for' => '', |
|
| 385 | + 'class' => '', |
|
| 386 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
| 387 | + 'label_col' => '', |
|
| 388 | + ); |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 392 | + */ |
|
| 393 | + $args = wp_parse_args( $args, $defaults ); |
|
| 394 | + $output = ''; |
|
| 395 | + |
|
| 396 | + if ( $args['title'] ) { |
|
| 397 | + |
|
| 398 | + // maybe hide labels //@todo set a global option for visibility class |
|
| 399 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
| 400 | + $class = $args['class']; |
|
| 401 | + } else { |
|
| 402 | + $class = 'sr-only ' . $args['class']; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + // maybe horizontal |
|
| 406 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 407 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if( $aui_bs5 ){ $class .= ' form-label'; } |
|
| 411 | + |
|
| 412 | + // open |
|
| 413 | + $output .= '<label '; |
|
| 414 | + |
|
| 415 | + // for |
|
| 416 | + if ( ! empty( $args['for'] ) ) { |
|
| 417 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + // class |
|
| 421 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 422 | + $output .= ' class="' . $class . '" '; |
|
| 423 | + |
|
| 424 | + // close |
|
| 425 | + $output .= '>'; |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + // title, don't escape fully as can contain html |
|
| 429 | + if ( ! empty( $args['title'] ) ) { |
|
| 430 | + $output .= wp_kses_post( $args['title'] ); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // close wrap |
|
| 434 | + $output .= '</label>'; |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + return $output; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Wrap some content in a HTML wrapper. |
|
| 445 | + * |
|
| 446 | + * @param array $args |
|
| 447 | + * |
|
| 448 | + * @return string |
|
| 449 | + */ |
|
| 450 | + public static function wrap( $args = array() ) { |
|
| 451 | + global $aui_bs5; |
|
| 452 | + $defaults = array( |
|
| 453 | + 'type' => 'div', |
|
| 454 | + 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
| 455 | + 'content' => '', |
|
| 456 | + 'input_group_left' => '', |
|
| 457 | + 'input_group_right' => '', |
|
| 458 | + 'input_group_left_inside' => false, |
|
| 459 | + 'input_group_right_inside' => false, |
|
| 460 | + 'element_require' => '', |
|
| 461 | + 'argument_id' => '', |
|
| 462 | + 'wrap_attributes' => array() |
|
| 463 | + ); |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 467 | + */ |
|
| 468 | + $args = wp_parse_args( $args, $defaults ); |
|
| 469 | + $output = ''; |
|
| 470 | + if ( $args['type'] ) { |
|
| 471 | + |
|
| 472 | + // open |
|
| 473 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
| 474 | + |
|
| 475 | + // element require |
|
| 476 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 477 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 478 | + $args['class'] .= " aui-conditional-field"; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + // argument_id |
|
| 482 | + if ( ! empty( $args['argument_id'] ) ) { |
|
| 483 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // class |
|
| 487 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 488 | + $output .= ' class="' . $class . '" '; |
|
| 489 | + |
|
| 490 | + // Attributes |
|
| 491 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
| 492 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // close wrap |
|
| 496 | + $output .= ' >'; |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + // Input group left |
|
| 500 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
| 501 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 502 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 503 | + $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 504 | 504 | // $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
| 505 | - } |
|
| 505 | + } |
|
| 506 | 506 | |
| 507 | - // content |
|
| 508 | - $output .= $args['content']; |
|
| 507 | + // content |
|
| 508 | + $output .= $args['content']; |
|
| 509 | 509 | |
| 510 | - // Input group right |
|
| 511 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
| 512 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 513 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 514 | - $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
| 510 | + // Input group right |
|
| 511 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
| 512 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 513 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 514 | + $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
| 515 | 515 | // $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - // close wrap |
|
| 520 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - } else { |
|
| 524 | - $output = $args['content']; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - return $output; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Build the component. |
|
| 532 | - * |
|
| 533 | - * @param array $args |
|
| 534 | - * |
|
| 535 | - * @return string The rendered component. |
|
| 536 | - */ |
|
| 537 | - public static function textarea( $args = array() ) { |
|
| 538 | - global $aui_bs5; |
|
| 539 | - |
|
| 540 | - $defaults = array( |
|
| 541 | - 'name' => '', |
|
| 542 | - 'class' => '', |
|
| 543 | - 'wrap_class' => '', |
|
| 544 | - 'id' => '', |
|
| 545 | - 'placeholder' => '', |
|
| 546 | - 'title' => '', |
|
| 547 | - 'value' => '', |
|
| 548 | - 'required' => false, |
|
| 549 | - 'label' => '', |
|
| 550 | - 'label_after' => false, |
|
| 551 | - 'label_class' => '', |
|
| 552 | - 'label_type' => '', |
|
| 553 | - 'label_col' => '', |
|
| 554 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 555 | - 'input_group_right' => '', |
|
| 556 | - 'input_group_left' => '', |
|
| 557 | - 'input_group_right_inside' => false, |
|
| 558 | - 'form_group_class' => '', |
|
| 559 | - 'help_text' => '', |
|
| 560 | - 'validation_text' => '', |
|
| 561 | - 'validation_pattern' => '', |
|
| 562 | - 'no_wrap' => false, |
|
| 563 | - 'rows' => '', |
|
| 564 | - 'wysiwyg' => false, |
|
| 565 | - 'allow_tags' => false, |
|
| 566 | - // Allow HTML tags |
|
| 567 | - 'element_require' => '', |
|
| 568 | - // [%element_id%] == "1" |
|
| 569 | - 'extra_attributes' => array(), |
|
| 570 | - // an array of extra attributes |
|
| 571 | - 'wrap_attributes' => array(), |
|
| 572 | - ); |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 576 | - */ |
|
| 577 | - $args = wp_parse_args( $args, $defaults ); |
|
| 578 | - $output = ''; |
|
| 579 | - $label = ''; |
|
| 580 | - |
|
| 581 | - // hidden label option needs to be empty |
|
| 582 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 583 | - |
|
| 584 | - // floating labels don't work with wysiwyg so set it as top |
|
| 585 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
| 586 | - $args['label_type'] = 'top'; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - $label_after = $args['label_after']; |
|
| 590 | - |
|
| 591 | - // floating labels need label after |
|
| 592 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
| 593 | - $label_after = true; |
|
| 594 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - // label |
|
| 598 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 599 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 600 | - $label_args = array( |
|
| 601 | - 'title' => $args['label'], |
|
| 602 | - 'for' => $args['id'], |
|
| 603 | - 'class' => $args['label_class'] . " ", |
|
| 604 | - 'label_type' => $args['label_type'], |
|
| 605 | - 'label_col' => $args['label_col'] |
|
| 606 | - ); |
|
| 607 | - $label .= self::label( $label_args ); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - // maybe horizontal label |
|
| 611 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 612 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 613 | - $label .= '<div class="' . $input_col . '">'; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
| 617 | - ob_start(); |
|
| 618 | - $content = $args['value']; |
|
| 619 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
| 620 | - $settings = array( |
|
| 621 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
| 622 | - 'quicktags' => false, |
|
| 623 | - 'media_buttons' => false, |
|
| 624 | - 'editor_class' => 'form-control', |
|
| 625 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
| 626 | - 'teeny' => true, |
|
| 627 | - ); |
|
| 628 | - |
|
| 629 | - // maybe set settings if array |
|
| 630 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
| 631 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - wp_editor( $content, $editor_id, $settings ); |
|
| 635 | - $output .= ob_get_clean(); |
|
| 636 | - } else { |
|
| 637 | - |
|
| 638 | - // open |
|
| 639 | - $output .= '<textarea '; |
|
| 640 | - |
|
| 641 | - // name |
|
| 642 | - if ( ! empty( $args['name'] ) ) { |
|
| 643 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // id |
|
| 647 | - if ( ! empty( $args['id'] ) ) { |
|
| 648 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // placeholder |
|
| 652 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 653 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - // title |
|
| 657 | - if ( ! empty( $args['title'] ) ) { |
|
| 658 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - // validation text |
|
| 662 | - if ( ! empty( $args['validation_text'] ) ) { |
|
| 663 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
| 664 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - // validation_pattern |
|
| 668 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 669 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - // required |
|
| 673 | - if ( ! empty( $args['required'] ) ) { |
|
| 674 | - $output .= ' required '; |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - // rows |
|
| 678 | - if ( ! empty( $args['rows'] ) ) { |
|
| 679 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - // class |
|
| 684 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 685 | - $output .= ' class="form-control ' . $class . '" '; |
|
| 686 | - |
|
| 687 | - // extra attributes |
|
| 688 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 689 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - // close tag |
|
| 693 | - $output .= ' >'; |
|
| 694 | - |
|
| 695 | - // value |
|
| 696 | - if ( ! empty( $args['value'] ) ) { |
|
| 697 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
| 698 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 699 | - } else { |
|
| 700 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - // closing tag |
|
| 705 | - $output .= '</textarea>'; |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - // input group wraps |
|
| 709 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 710 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 711 | - if ( $args['input_group_left'] ) { |
|
| 712 | - $output = self::wrap( array( |
|
| 713 | - 'content' => $output, |
|
| 714 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 715 | - 'input_group_left' => $args['input_group_left'], |
|
| 716 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 717 | - ) ); |
|
| 718 | - } |
|
| 719 | - if ( $args['input_group_right'] ) { |
|
| 720 | - $output = self::wrap( array( |
|
| 721 | - 'content' => $output, |
|
| 722 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 723 | - 'input_group_right' => $args['input_group_right'], |
|
| 724 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 725 | - ) ); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
| 734 | - $label_args = array( |
|
| 735 | - 'title' => $args['label'], |
|
| 736 | - 'for' => $args['id'], |
|
| 737 | - 'class' => $args['label_class'] . " ", |
|
| 738 | - 'label_type' => $args['label_type'], |
|
| 739 | - 'label_col' => $args['label_col'] |
|
| 740 | - ); |
|
| 741 | - $output .= self::label( $label_args ); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // help text |
|
| 745 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 746 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - if ( ! $label_after ) { |
|
| 750 | - $output = $label . $output; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // maybe horizontal label |
|
| 754 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 755 | - $output .= '</div>'; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - // wrap |
|
| 760 | - if ( ! $args['no_wrap'] ) { |
|
| 761 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
| 762 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 763 | - }else{ |
|
| 764 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 765 | - } |
|
| 766 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
| 767 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 768 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 769 | - $output = self::wrap( array( |
|
| 770 | - 'content' => $output, |
|
| 771 | - 'class' => $wrap_class, |
|
| 772 | - 'element_require' => $args['element_require'], |
|
| 773 | - 'argument_id' => $args['id'], |
|
| 774 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 775 | - ) ); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - return $output; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * Build the component. |
|
| 784 | - * |
|
| 785 | - * @param array $args |
|
| 786 | - * |
|
| 787 | - * @return string The rendered component. |
|
| 788 | - */ |
|
| 789 | - public static function select( $args = array() ) { |
|
| 790 | - global $aui_bs5; |
|
| 791 | - $defaults = array( |
|
| 792 | - 'class' => '', |
|
| 793 | - 'wrap_class' => '', |
|
| 794 | - 'id' => '', |
|
| 795 | - 'title' => '', |
|
| 796 | - 'value' => '', |
|
| 797 | - // can be an array or a string |
|
| 798 | - 'required' => false, |
|
| 799 | - 'label' => '', |
|
| 800 | - 'label_after' => false, |
|
| 801 | - 'label_type' => '', |
|
| 802 | - 'label_col' => '', |
|
| 803 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 804 | - 'label_class' => '', |
|
| 805 | - 'help_text' => '', |
|
| 806 | - 'placeholder' => '', |
|
| 807 | - 'options' => array(), |
|
| 808 | - // array or string |
|
| 809 | - 'icon' => '', |
|
| 810 | - 'multiple' => false, |
|
| 811 | - 'select2' => false, |
|
| 812 | - 'no_wrap' => false, |
|
| 813 | - 'input_group_right' => '', |
|
| 814 | - 'input_group_left' => '', |
|
| 815 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 816 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 817 | - 'form_group_class' => '', |
|
| 818 | - 'element_require' => '', |
|
| 819 | - // [%element_id%] == "1" |
|
| 820 | - 'extra_attributes' => array(), |
|
| 821 | - // an array of extra attributes |
|
| 822 | - 'wrap_attributes' => array(), |
|
| 823 | - ); |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 827 | - */ |
|
| 828 | - $args = wp_parse_args( $args, $defaults ); |
|
| 829 | - $output = ''; |
|
| 830 | - |
|
| 831 | - // for now lets hide floating labels |
|
| 832 | - if ( $args['label_type'] == 'floating' ) { |
|
| 833 | - $args['label_type'] = 'hidden'; |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - // hidden label option needs to be empty |
|
| 837 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - $label_after = $args['label_after']; |
|
| 841 | - |
|
| 842 | - // floating labels need label after |
|
| 843 | - if ( $args['label_type'] == 'floating' ) { |
|
| 844 | - $label_after = true; |
|
| 845 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - // Maybe setup select2 |
|
| 849 | - $is_select2 = false; |
|
| 850 | - if ( ! empty( $args['select2'] ) ) { |
|
| 851 | - $args['class'] .= ' aui-select2'; |
|
| 852 | - $is_select2 = true; |
|
| 853 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
| 854 | - $is_select2 = true; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - // select2 tags |
|
| 858 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
| 859 | - $args['data-tags'] = 'true'; |
|
| 860 | - $args['data-token-separators'] = "[',']"; |
|
| 861 | - $args['multiple'] = true; |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - // select2 placeholder |
|
| 865 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
| 866 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
| 867 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - // Set hidden input to save empty value for multiselect. |
|
| 871 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
| 872 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - // open/type |
|
| 876 | - $output .= '<select '; |
|
| 877 | - |
|
| 878 | - // style |
|
| 879 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
| 880 | - $output .= " style='width:100%;' "; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - // element require |
|
| 884 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 885 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 886 | - $args['class'] .= " aui-conditional-field"; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - // class |
|
| 890 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 891 | - $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
| 892 | - $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
| 893 | - |
|
| 894 | - // name |
|
| 895 | - if ( ! empty( $args['name'] ) ) { |
|
| 896 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - // id |
|
| 900 | - if ( ! empty( $args['id'] ) ) { |
|
| 901 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - // title |
|
| 905 | - if ( ! empty( $args['title'] ) ) { |
|
| 906 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - // data-attributes |
|
| 910 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 911 | - |
|
| 912 | - // aria-attributes |
|
| 913 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 914 | - |
|
| 915 | - // extra attributes |
|
| 916 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 917 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - // required |
|
| 921 | - if ( ! empty( $args['required'] ) ) { |
|
| 922 | - $output .= ' required '; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - // multiple |
|
| 926 | - if ( ! empty( $args['multiple'] ) ) { |
|
| 927 | - $output .= ' multiple '; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - // close opening tag |
|
| 931 | - $output .= ' >'; |
|
| 932 | - |
|
| 933 | - // placeholder |
|
| 934 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
| 935 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
| 936 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
| 937 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - // Options |
|
| 941 | - if ( ! empty( $args['options'] ) ) { |
|
| 942 | - |
|
| 943 | - if ( ! is_array( $args['options'] ) ) { |
|
| 944 | - $output .= $args['options']; // not the preferred way but an option |
|
| 945 | - } else { |
|
| 946 | - foreach ( $args['options'] as $val => $name ) { |
|
| 947 | - $selected = ''; |
|
| 948 | - if ( is_array( $name ) ) { |
|
| 949 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
| 950 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 951 | - |
|
| 952 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
| 953 | - } else { |
|
| 954 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 955 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
| 956 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
| 957 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
| 958 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
| 959 | - } elseif ( ! empty( $args['value'] ) ) { |
|
| 960 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
| 961 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
| 962 | - $selected = selected( $option_value, $args['value'], false ); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
| 966 | - } |
|
| 967 | - } else { |
|
| 968 | - if ( ! empty( $args['value'] ) ) { |
|
| 969 | - if ( is_array( $args['value'] ) ) { |
|
| 970 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
| 971 | - } elseif ( ! empty( $args['value'] ) ) { |
|
| 972 | - $selected = selected( $args['value'], $val, false ); |
|
| 973 | - } |
|
| 974 | - } elseif ( $args['value'] === $val ) { |
|
| 975 | - $selected = selected( $args['value'], $val, false ); |
|
| 976 | - } |
|
| 977 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - // closing tag |
|
| 985 | - $output .= '</select>'; |
|
| 986 | - |
|
| 987 | - $label = ''; |
|
| 988 | - $help_text = ''; |
|
| 989 | - // label |
|
| 990 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 991 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 992 | - $label_args = array( |
|
| 993 | - 'title' => $args['label'], |
|
| 994 | - 'for' => $args['id'], |
|
| 995 | - 'class' => $args['label_class'] . " ", |
|
| 996 | - 'label_type' => $args['label_type'], |
|
| 997 | - 'label_col' => $args['label_col'] |
|
| 998 | - ); |
|
| 999 | - $label = self::label( $label_args ); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - // help text |
|
| 1003 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 1004 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - // input group wraps |
|
| 1008 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 1009 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 1010 | - if ( $args['input_group_left'] ) { |
|
| 1011 | - $output = self::wrap( array( |
|
| 1012 | - 'content' => $output, |
|
| 1013 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1014 | - 'input_group_left' => $args['input_group_left'], |
|
| 1015 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 1016 | - ) ); |
|
| 1017 | - } |
|
| 1018 | - if ( $args['input_group_right'] ) { |
|
| 1019 | - $output = self::wrap( array( |
|
| 1020 | - 'content' => $output, |
|
| 1021 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1022 | - 'input_group_right' => $args['input_group_right'], |
|
| 1023 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 1024 | - ) ); |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - if ( ! $label_after ) { |
|
| 1030 | - $output .= $help_text; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - |
|
| 1034 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1035 | - $output = self::wrap( array( |
|
| 1036 | - 'content' => $output, |
|
| 1037 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 1038 | - ) ); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - if ( ! $label_after ) { |
|
| 1042 | - $output = $label . $output; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - // maybe horizontal label |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + // close wrap |
|
| 520 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + } else { |
|
| 524 | + $output = $args['content']; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + return $output; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Build the component. |
|
| 532 | + * |
|
| 533 | + * @param array $args |
|
| 534 | + * |
|
| 535 | + * @return string The rendered component. |
|
| 536 | + */ |
|
| 537 | + public static function textarea( $args = array() ) { |
|
| 538 | + global $aui_bs5; |
|
| 539 | + |
|
| 540 | + $defaults = array( |
|
| 541 | + 'name' => '', |
|
| 542 | + 'class' => '', |
|
| 543 | + 'wrap_class' => '', |
|
| 544 | + 'id' => '', |
|
| 545 | + 'placeholder' => '', |
|
| 546 | + 'title' => '', |
|
| 547 | + 'value' => '', |
|
| 548 | + 'required' => false, |
|
| 549 | + 'label' => '', |
|
| 550 | + 'label_after' => false, |
|
| 551 | + 'label_class' => '', |
|
| 552 | + 'label_type' => '', |
|
| 553 | + 'label_col' => '', |
|
| 554 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 555 | + 'input_group_right' => '', |
|
| 556 | + 'input_group_left' => '', |
|
| 557 | + 'input_group_right_inside' => false, |
|
| 558 | + 'form_group_class' => '', |
|
| 559 | + 'help_text' => '', |
|
| 560 | + 'validation_text' => '', |
|
| 561 | + 'validation_pattern' => '', |
|
| 562 | + 'no_wrap' => false, |
|
| 563 | + 'rows' => '', |
|
| 564 | + 'wysiwyg' => false, |
|
| 565 | + 'allow_tags' => false, |
|
| 566 | + // Allow HTML tags |
|
| 567 | + 'element_require' => '', |
|
| 568 | + // [%element_id%] == "1" |
|
| 569 | + 'extra_attributes' => array(), |
|
| 570 | + // an array of extra attributes |
|
| 571 | + 'wrap_attributes' => array(), |
|
| 572 | + ); |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 576 | + */ |
|
| 577 | + $args = wp_parse_args( $args, $defaults ); |
|
| 578 | + $output = ''; |
|
| 579 | + $label = ''; |
|
| 580 | + |
|
| 581 | + // hidden label option needs to be empty |
|
| 582 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 583 | + |
|
| 584 | + // floating labels don't work with wysiwyg so set it as top |
|
| 585 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
| 586 | + $args['label_type'] = 'top'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + $label_after = $args['label_after']; |
|
| 590 | + |
|
| 591 | + // floating labels need label after |
|
| 592 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
| 593 | + $label_after = true; |
|
| 594 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + // label |
|
| 598 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 599 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 600 | + $label_args = array( |
|
| 601 | + 'title' => $args['label'], |
|
| 602 | + 'for' => $args['id'], |
|
| 603 | + 'class' => $args['label_class'] . " ", |
|
| 604 | + 'label_type' => $args['label_type'], |
|
| 605 | + 'label_col' => $args['label_col'] |
|
| 606 | + ); |
|
| 607 | + $label .= self::label( $label_args ); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + // maybe horizontal label |
|
| 611 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 612 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 613 | + $label .= '<div class="' . $input_col . '">'; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
| 617 | + ob_start(); |
|
| 618 | + $content = $args['value']; |
|
| 619 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
| 620 | + $settings = array( |
|
| 621 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
| 622 | + 'quicktags' => false, |
|
| 623 | + 'media_buttons' => false, |
|
| 624 | + 'editor_class' => 'form-control', |
|
| 625 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
| 626 | + 'teeny' => true, |
|
| 627 | + ); |
|
| 628 | + |
|
| 629 | + // maybe set settings if array |
|
| 630 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
| 631 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + wp_editor( $content, $editor_id, $settings ); |
|
| 635 | + $output .= ob_get_clean(); |
|
| 636 | + } else { |
|
| 637 | + |
|
| 638 | + // open |
|
| 639 | + $output .= '<textarea '; |
|
| 640 | + |
|
| 641 | + // name |
|
| 642 | + if ( ! empty( $args['name'] ) ) { |
|
| 643 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // id |
|
| 647 | + if ( ! empty( $args['id'] ) ) { |
|
| 648 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // placeholder |
|
| 652 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 653 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + // title |
|
| 657 | + if ( ! empty( $args['title'] ) ) { |
|
| 658 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + // validation text |
|
| 662 | + if ( ! empty( $args['validation_text'] ) ) { |
|
| 663 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
| 664 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + // validation_pattern |
|
| 668 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 669 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + // required |
|
| 673 | + if ( ! empty( $args['required'] ) ) { |
|
| 674 | + $output .= ' required '; |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + // rows |
|
| 678 | + if ( ! empty( $args['rows'] ) ) { |
|
| 679 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + // class |
|
| 684 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 685 | + $output .= ' class="form-control ' . $class . '" '; |
|
| 686 | + |
|
| 687 | + // extra attributes |
|
| 688 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 689 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + // close tag |
|
| 693 | + $output .= ' >'; |
|
| 694 | + |
|
| 695 | + // value |
|
| 696 | + if ( ! empty( $args['value'] ) ) { |
|
| 697 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
| 698 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 699 | + } else { |
|
| 700 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + // closing tag |
|
| 705 | + $output .= '</textarea>'; |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + // input group wraps |
|
| 709 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 710 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 711 | + if ( $args['input_group_left'] ) { |
|
| 712 | + $output = self::wrap( array( |
|
| 713 | + 'content' => $output, |
|
| 714 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 715 | + 'input_group_left' => $args['input_group_left'], |
|
| 716 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 717 | + ) ); |
|
| 718 | + } |
|
| 719 | + if ( $args['input_group_right'] ) { |
|
| 720 | + $output = self::wrap( array( |
|
| 721 | + 'content' => $output, |
|
| 722 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 723 | + 'input_group_right' => $args['input_group_right'], |
|
| 724 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 725 | + ) ); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
| 734 | + $label_args = array( |
|
| 735 | + 'title' => $args['label'], |
|
| 736 | + 'for' => $args['id'], |
|
| 737 | + 'class' => $args['label_class'] . " ", |
|
| 738 | + 'label_type' => $args['label_type'], |
|
| 739 | + 'label_col' => $args['label_col'] |
|
| 740 | + ); |
|
| 741 | + $output .= self::label( $label_args ); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + // help text |
|
| 745 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 746 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + if ( ! $label_after ) { |
|
| 750 | + $output = $label . $output; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // maybe horizontal label |
|
| 754 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 755 | + $output .= '</div>'; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + // wrap |
|
| 760 | + if ( ! $args['no_wrap'] ) { |
|
| 761 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
| 762 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 763 | + }else{ |
|
| 764 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 765 | + } |
|
| 766 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
| 767 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 768 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 769 | + $output = self::wrap( array( |
|
| 770 | + 'content' => $output, |
|
| 771 | + 'class' => $wrap_class, |
|
| 772 | + 'element_require' => $args['element_require'], |
|
| 773 | + 'argument_id' => $args['id'], |
|
| 774 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 775 | + ) ); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + return $output; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * Build the component. |
|
| 784 | + * |
|
| 785 | + * @param array $args |
|
| 786 | + * |
|
| 787 | + * @return string The rendered component. |
|
| 788 | + */ |
|
| 789 | + public static function select( $args = array() ) { |
|
| 790 | + global $aui_bs5; |
|
| 791 | + $defaults = array( |
|
| 792 | + 'class' => '', |
|
| 793 | + 'wrap_class' => '', |
|
| 794 | + 'id' => '', |
|
| 795 | + 'title' => '', |
|
| 796 | + 'value' => '', |
|
| 797 | + // can be an array or a string |
|
| 798 | + 'required' => false, |
|
| 799 | + 'label' => '', |
|
| 800 | + 'label_after' => false, |
|
| 801 | + 'label_type' => '', |
|
| 802 | + 'label_col' => '', |
|
| 803 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 804 | + 'label_class' => '', |
|
| 805 | + 'help_text' => '', |
|
| 806 | + 'placeholder' => '', |
|
| 807 | + 'options' => array(), |
|
| 808 | + // array or string |
|
| 809 | + 'icon' => '', |
|
| 810 | + 'multiple' => false, |
|
| 811 | + 'select2' => false, |
|
| 812 | + 'no_wrap' => false, |
|
| 813 | + 'input_group_right' => '', |
|
| 814 | + 'input_group_left' => '', |
|
| 815 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 816 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 817 | + 'form_group_class' => '', |
|
| 818 | + 'element_require' => '', |
|
| 819 | + // [%element_id%] == "1" |
|
| 820 | + 'extra_attributes' => array(), |
|
| 821 | + // an array of extra attributes |
|
| 822 | + 'wrap_attributes' => array(), |
|
| 823 | + ); |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 827 | + */ |
|
| 828 | + $args = wp_parse_args( $args, $defaults ); |
|
| 829 | + $output = ''; |
|
| 830 | + |
|
| 831 | + // for now lets hide floating labels |
|
| 832 | + if ( $args['label_type'] == 'floating' ) { |
|
| 833 | + $args['label_type'] = 'hidden'; |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + // hidden label option needs to be empty |
|
| 837 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + $label_after = $args['label_after']; |
|
| 841 | + |
|
| 842 | + // floating labels need label after |
|
| 843 | + if ( $args['label_type'] == 'floating' ) { |
|
| 844 | + $label_after = true; |
|
| 845 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + // Maybe setup select2 |
|
| 849 | + $is_select2 = false; |
|
| 850 | + if ( ! empty( $args['select2'] ) ) { |
|
| 851 | + $args['class'] .= ' aui-select2'; |
|
| 852 | + $is_select2 = true; |
|
| 853 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
| 854 | + $is_select2 = true; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + // select2 tags |
|
| 858 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
| 859 | + $args['data-tags'] = 'true'; |
|
| 860 | + $args['data-token-separators'] = "[',']"; |
|
| 861 | + $args['multiple'] = true; |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + // select2 placeholder |
|
| 865 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
| 866 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
| 867 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + // Set hidden input to save empty value for multiselect. |
|
| 871 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
| 872 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + // open/type |
|
| 876 | + $output .= '<select '; |
|
| 877 | + |
|
| 878 | + // style |
|
| 879 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
| 880 | + $output .= " style='width:100%;' "; |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + // element require |
|
| 884 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 885 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 886 | + $args['class'] .= " aui-conditional-field"; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + // class |
|
| 890 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 891 | + $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
| 892 | + $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
| 893 | + |
|
| 894 | + // name |
|
| 895 | + if ( ! empty( $args['name'] ) ) { |
|
| 896 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + // id |
|
| 900 | + if ( ! empty( $args['id'] ) ) { |
|
| 901 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + // title |
|
| 905 | + if ( ! empty( $args['title'] ) ) { |
|
| 906 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + // data-attributes |
|
| 910 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 911 | + |
|
| 912 | + // aria-attributes |
|
| 913 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 914 | + |
|
| 915 | + // extra attributes |
|
| 916 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 917 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + // required |
|
| 921 | + if ( ! empty( $args['required'] ) ) { |
|
| 922 | + $output .= ' required '; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + // multiple |
|
| 926 | + if ( ! empty( $args['multiple'] ) ) { |
|
| 927 | + $output .= ' multiple '; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + // close opening tag |
|
| 931 | + $output .= ' >'; |
|
| 932 | + |
|
| 933 | + // placeholder |
|
| 934 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
| 935 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
| 936 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
| 937 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + // Options |
|
| 941 | + if ( ! empty( $args['options'] ) ) { |
|
| 942 | + |
|
| 943 | + if ( ! is_array( $args['options'] ) ) { |
|
| 944 | + $output .= $args['options']; // not the preferred way but an option |
|
| 945 | + } else { |
|
| 946 | + foreach ( $args['options'] as $val => $name ) { |
|
| 947 | + $selected = ''; |
|
| 948 | + if ( is_array( $name ) ) { |
|
| 949 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
| 950 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 951 | + |
|
| 952 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
| 953 | + } else { |
|
| 954 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 955 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
| 956 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
| 957 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
| 958 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
| 959 | + } elseif ( ! empty( $args['value'] ) ) { |
|
| 960 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
| 961 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
| 962 | + $selected = selected( $option_value, $args['value'], false ); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
| 966 | + } |
|
| 967 | + } else { |
|
| 968 | + if ( ! empty( $args['value'] ) ) { |
|
| 969 | + if ( is_array( $args['value'] ) ) { |
|
| 970 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
| 971 | + } elseif ( ! empty( $args['value'] ) ) { |
|
| 972 | + $selected = selected( $args['value'], $val, false ); |
|
| 973 | + } |
|
| 974 | + } elseif ( $args['value'] === $val ) { |
|
| 975 | + $selected = selected( $args['value'], $val, false ); |
|
| 976 | + } |
|
| 977 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + // closing tag |
|
| 985 | + $output .= '</select>'; |
|
| 986 | + |
|
| 987 | + $label = ''; |
|
| 988 | + $help_text = ''; |
|
| 989 | + // label |
|
| 990 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 991 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 992 | + $label_args = array( |
|
| 993 | + 'title' => $args['label'], |
|
| 994 | + 'for' => $args['id'], |
|
| 995 | + 'class' => $args['label_class'] . " ", |
|
| 996 | + 'label_type' => $args['label_type'], |
|
| 997 | + 'label_col' => $args['label_col'] |
|
| 998 | + ); |
|
| 999 | + $label = self::label( $label_args ); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + // help text |
|
| 1003 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 1004 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + // input group wraps |
|
| 1008 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 1009 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 1010 | + if ( $args['input_group_left'] ) { |
|
| 1011 | + $output = self::wrap( array( |
|
| 1012 | + 'content' => $output, |
|
| 1013 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1014 | + 'input_group_left' => $args['input_group_left'], |
|
| 1015 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 1016 | + ) ); |
|
| 1017 | + } |
|
| 1018 | + if ( $args['input_group_right'] ) { |
|
| 1019 | + $output = self::wrap( array( |
|
| 1020 | + 'content' => $output, |
|
| 1021 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1022 | + 'input_group_right' => $args['input_group_right'], |
|
| 1023 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 1024 | + ) ); |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + if ( ! $label_after ) { |
|
| 1030 | + $output .= $help_text; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + |
|
| 1034 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1035 | + $output = self::wrap( array( |
|
| 1036 | + 'content' => $output, |
|
| 1037 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 1038 | + ) ); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + if ( ! $label_after ) { |
|
| 1042 | + $output = $label . $output; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + // maybe horizontal label |
|
| 1046 | 1046 | // if ( $args['label_type'] == 'horizontal' ) { |
| 1047 | 1047 | // $output .= '</div>'; |
| 1048 | 1048 | // } |
| 1049 | 1049 | |
| 1050 | 1050 | |
| 1051 | - // wrap |
|
| 1052 | - if ( ! $args['no_wrap'] ) { |
|
| 1053 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
| 1054 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 1055 | - }else{ |
|
| 1056 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1057 | - } |
|
| 1058 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1059 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1060 | - $output = self::wrap( array( |
|
| 1061 | - 'content' => $output, |
|
| 1062 | - 'class' => $wrap_class, |
|
| 1063 | - 'element_require' => $args['element_require'], |
|
| 1064 | - 'argument_id' => $args['id'], |
|
| 1065 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1066 | - ) ); |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - |
|
| 1070 | - return $output; |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - /** |
|
| 1074 | - * Build the component. |
|
| 1075 | - * |
|
| 1076 | - * @param array $args |
|
| 1077 | - * |
|
| 1078 | - * @return string The rendered component. |
|
| 1079 | - */ |
|
| 1080 | - public static function radio( $args = array() ) { |
|
| 1081 | - global $aui_bs5; |
|
| 1082 | - |
|
| 1083 | - $defaults = array( |
|
| 1084 | - 'class' => '', |
|
| 1085 | - 'wrap_class' => '', |
|
| 1086 | - 'id' => '', |
|
| 1087 | - 'title' => '', |
|
| 1088 | - 'horizontal' => false, |
|
| 1089 | - // sets the lable horizontal |
|
| 1090 | - 'value' => '', |
|
| 1091 | - 'label' => '', |
|
| 1092 | - 'label_class' => '', |
|
| 1093 | - 'label_type' => '', |
|
| 1094 | - 'label_col' => '', |
|
| 1095 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 1096 | - 'help_text' => '', |
|
| 1097 | - 'inline' => true, |
|
| 1098 | - 'required' => false, |
|
| 1099 | - 'options' => array(), |
|
| 1100 | - 'icon' => '', |
|
| 1101 | - 'no_wrap' => false, |
|
| 1102 | - 'element_require' => '', |
|
| 1103 | - // [%element_id%] == "1" |
|
| 1104 | - 'extra_attributes' => array(), |
|
| 1105 | - // an array of extra attributes |
|
| 1106 | - 'wrap_attributes' => array() |
|
| 1107 | - ); |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 1111 | - */ |
|
| 1112 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1113 | - |
|
| 1114 | - // for now lets use horizontal for floating |
|
| 1115 | - if ( $args['label_type'] == 'floating' ) { |
|
| 1116 | - $args['label_type'] = 'horizontal'; |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - $label_args = array( |
|
| 1120 | - 'title' => $args['label'], |
|
| 1121 | - 'class' => $args['label_class'] . " pt-0 ", |
|
| 1122 | - 'label_type' => $args['label_type'], |
|
| 1123 | - 'label_col' => $args['label_col'] |
|
| 1124 | - ); |
|
| 1125 | - |
|
| 1126 | - if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) { |
|
| 1127 | - $label_args['class'] .= 'd-block '; |
|
| 1128 | - |
|
| 1129 | - if ( $args['label_type'] == 'hidden' ) { |
|
| 1130 | - $label_args['class'] .= 'sr-only '; |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - $output = ''; |
|
| 1135 | - |
|
| 1136 | - // label before |
|
| 1137 | - if ( ! empty( $args['label'] ) ) { |
|
| 1138 | - $output .= self::label( $label_args, 'radio' ); |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - // maybe horizontal label |
|
| 1142 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1143 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 1144 | - $output .= '<div class="' . $input_col . '">'; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - if ( ! empty( $args['options'] ) ) { |
|
| 1148 | - $count = 0; |
|
| 1149 | - foreach ( $args['options'] as $value => $label ) { |
|
| 1150 | - $option_args = $args; |
|
| 1151 | - $option_args['value'] = $value; |
|
| 1152 | - $option_args['label'] = $label; |
|
| 1153 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 1154 | - $output .= self::radio_option( $option_args, $count ); |
|
| 1155 | - $count ++; |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - // help text |
|
| 1160 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
| 1161 | - $output .= $help_text; |
|
| 1162 | - |
|
| 1163 | - // maybe horizontal label |
|
| 1164 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1165 | - $output .= '</div>'; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - // wrap |
|
| 1169 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1170 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1171 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1172 | - $output = self::wrap( array( |
|
| 1173 | - 'content' => $output, |
|
| 1174 | - 'class' => $wrap_class, |
|
| 1175 | - 'element_require' => $args['element_require'], |
|
| 1176 | - 'argument_id' => $args['id'], |
|
| 1177 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1178 | - ) ); |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - return $output; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * Build the component. |
|
| 1186 | - * |
|
| 1187 | - * @param array $args |
|
| 1188 | - * |
|
| 1189 | - * @return string The rendered component. |
|
| 1190 | - */ |
|
| 1191 | - public static function radio_option( $args = array(), $count = '' ) { |
|
| 1192 | - $defaults = array( |
|
| 1193 | - 'class' => '', |
|
| 1194 | - 'id' => '', |
|
| 1195 | - 'title' => '', |
|
| 1196 | - 'value' => '', |
|
| 1197 | - 'required' => false, |
|
| 1198 | - 'inline' => true, |
|
| 1199 | - 'label' => '', |
|
| 1200 | - 'options' => array(), |
|
| 1201 | - 'icon' => '', |
|
| 1202 | - 'no_wrap' => false, |
|
| 1203 | - 'extra_attributes' => array() // an array of extra attributes |
|
| 1204 | - ); |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 1208 | - */ |
|
| 1209 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1210 | - |
|
| 1211 | - $output = ''; |
|
| 1212 | - |
|
| 1213 | - // open/type |
|
| 1214 | - $output .= '<input type="radio"'; |
|
| 1215 | - |
|
| 1216 | - // class |
|
| 1217 | - $output .= ' class="form-check-input" '; |
|
| 1218 | - |
|
| 1219 | - // name |
|
| 1220 | - if ( ! empty( $args['name'] ) ) { |
|
| 1221 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - // id |
|
| 1225 | - if ( ! empty( $args['id'] ) ) { |
|
| 1226 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - // title |
|
| 1230 | - if ( ! empty( $args['title'] ) ) { |
|
| 1231 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - // value |
|
| 1235 | - if ( isset( $args['value'] ) ) { |
|
| 1236 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - // checked, for radio and checkboxes |
|
| 1240 | - if ( $args['checked'] ) { |
|
| 1241 | - $output .= ' checked '; |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - // data-attributes |
|
| 1245 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 1246 | - |
|
| 1247 | - // aria-attributes |
|
| 1248 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 1249 | - |
|
| 1250 | - // extra attributes |
|
| 1251 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 1252 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - // required |
|
| 1256 | - if ( ! empty( $args['required'] ) ) { |
|
| 1257 | - $output .= ' required '; |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - // close opening tag |
|
| 1261 | - $output .= ' >'; |
|
| 1262 | - |
|
| 1263 | - // label |
|
| 1264 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 1265 | - } elseif ( ! empty( $args['label'] ) ) { |
|
| 1266 | - $output .= self::label( array( |
|
| 1267 | - 'title' => $args['label'], |
|
| 1268 | - 'for' => $args['id'] . $count, |
|
| 1269 | - 'class' => 'form-check-label' |
|
| 1270 | - ), 'radio' ); |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - // wrap |
|
| 1274 | - if ( ! $args['no_wrap'] ) { |
|
| 1275 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1276 | - |
|
| 1277 | - // Unique wrap class |
|
| 1278 | - $uniq_class = 'fwrap'; |
|
| 1279 | - if ( ! empty( $args['name'] ) ) { |
|
| 1280 | - $uniq_class .= '-' . $args['name']; |
|
| 1281 | - } else if ( ! empty( $args['id'] ) ) { |
|
| 1282 | - $uniq_class .= '-' . $args['id']; |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
| 1286 | - $uniq_class .= '-' . $args['value']; |
|
| 1287 | - } else { |
|
| 1288 | - $uniq_class .= '-' . $count; |
|
| 1289 | - } |
|
| 1290 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
| 1291 | - |
|
| 1292 | - $output = self::wrap( array( |
|
| 1293 | - 'content' => $output, |
|
| 1294 | - 'class' => $wrap_class |
|
| 1295 | - ) ); |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - return $output; |
|
| 1299 | - } |
|
| 1051 | + // wrap |
|
| 1052 | + if ( ! $args['no_wrap'] ) { |
|
| 1053 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
| 1054 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 1055 | + }else{ |
|
| 1056 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1057 | + } |
|
| 1058 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1059 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1060 | + $output = self::wrap( array( |
|
| 1061 | + 'content' => $output, |
|
| 1062 | + 'class' => $wrap_class, |
|
| 1063 | + 'element_require' => $args['element_require'], |
|
| 1064 | + 'argument_id' => $args['id'], |
|
| 1065 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1066 | + ) ); |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + |
|
| 1070 | + return $output; |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + /** |
|
| 1074 | + * Build the component. |
|
| 1075 | + * |
|
| 1076 | + * @param array $args |
|
| 1077 | + * |
|
| 1078 | + * @return string The rendered component. |
|
| 1079 | + */ |
|
| 1080 | + public static function radio( $args = array() ) { |
|
| 1081 | + global $aui_bs5; |
|
| 1082 | + |
|
| 1083 | + $defaults = array( |
|
| 1084 | + 'class' => '', |
|
| 1085 | + 'wrap_class' => '', |
|
| 1086 | + 'id' => '', |
|
| 1087 | + 'title' => '', |
|
| 1088 | + 'horizontal' => false, |
|
| 1089 | + // sets the lable horizontal |
|
| 1090 | + 'value' => '', |
|
| 1091 | + 'label' => '', |
|
| 1092 | + 'label_class' => '', |
|
| 1093 | + 'label_type' => '', |
|
| 1094 | + 'label_col' => '', |
|
| 1095 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 1096 | + 'help_text' => '', |
|
| 1097 | + 'inline' => true, |
|
| 1098 | + 'required' => false, |
|
| 1099 | + 'options' => array(), |
|
| 1100 | + 'icon' => '', |
|
| 1101 | + 'no_wrap' => false, |
|
| 1102 | + 'element_require' => '', |
|
| 1103 | + // [%element_id%] == "1" |
|
| 1104 | + 'extra_attributes' => array(), |
|
| 1105 | + // an array of extra attributes |
|
| 1106 | + 'wrap_attributes' => array() |
|
| 1107 | + ); |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 1111 | + */ |
|
| 1112 | + $args = wp_parse_args( $args, $defaults ); |
|
| 1113 | + |
|
| 1114 | + // for now lets use horizontal for floating |
|
| 1115 | + if ( $args['label_type'] == 'floating' ) { |
|
| 1116 | + $args['label_type'] = 'horizontal'; |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + $label_args = array( |
|
| 1120 | + 'title' => $args['label'], |
|
| 1121 | + 'class' => $args['label_class'] . " pt-0 ", |
|
| 1122 | + 'label_type' => $args['label_type'], |
|
| 1123 | + 'label_col' => $args['label_col'] |
|
| 1124 | + ); |
|
| 1125 | + |
|
| 1126 | + if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) { |
|
| 1127 | + $label_args['class'] .= 'd-block '; |
|
| 1128 | + |
|
| 1129 | + if ( $args['label_type'] == 'hidden' ) { |
|
| 1130 | + $label_args['class'] .= 'sr-only '; |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + $output = ''; |
|
| 1135 | + |
|
| 1136 | + // label before |
|
| 1137 | + if ( ! empty( $args['label'] ) ) { |
|
| 1138 | + $output .= self::label( $label_args, 'radio' ); |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + // maybe horizontal label |
|
| 1142 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1143 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 1144 | + $output .= '<div class="' . $input_col . '">'; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + if ( ! empty( $args['options'] ) ) { |
|
| 1148 | + $count = 0; |
|
| 1149 | + foreach ( $args['options'] as $value => $label ) { |
|
| 1150 | + $option_args = $args; |
|
| 1151 | + $option_args['value'] = $value; |
|
| 1152 | + $option_args['label'] = $label; |
|
| 1153 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 1154 | + $output .= self::radio_option( $option_args, $count ); |
|
| 1155 | + $count ++; |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + // help text |
|
| 1160 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
| 1161 | + $output .= $help_text; |
|
| 1162 | + |
|
| 1163 | + // maybe horizontal label |
|
| 1164 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1165 | + $output .= '</div>'; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + // wrap |
|
| 1169 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1170 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1171 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1172 | + $output = self::wrap( array( |
|
| 1173 | + 'content' => $output, |
|
| 1174 | + 'class' => $wrap_class, |
|
| 1175 | + 'element_require' => $args['element_require'], |
|
| 1176 | + 'argument_id' => $args['id'], |
|
| 1177 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1178 | + ) ); |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + return $output; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * Build the component. |
|
| 1186 | + * |
|
| 1187 | + * @param array $args |
|
| 1188 | + * |
|
| 1189 | + * @return string The rendered component. |
|
| 1190 | + */ |
|
| 1191 | + public static function radio_option( $args = array(), $count = '' ) { |
|
| 1192 | + $defaults = array( |
|
| 1193 | + 'class' => '', |
|
| 1194 | + 'id' => '', |
|
| 1195 | + 'title' => '', |
|
| 1196 | + 'value' => '', |
|
| 1197 | + 'required' => false, |
|
| 1198 | + 'inline' => true, |
|
| 1199 | + 'label' => '', |
|
| 1200 | + 'options' => array(), |
|
| 1201 | + 'icon' => '', |
|
| 1202 | + 'no_wrap' => false, |
|
| 1203 | + 'extra_attributes' => array() // an array of extra attributes |
|
| 1204 | + ); |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 1208 | + */ |
|
| 1209 | + $args = wp_parse_args( $args, $defaults ); |
|
| 1210 | + |
|
| 1211 | + $output = ''; |
|
| 1212 | + |
|
| 1213 | + // open/type |
|
| 1214 | + $output .= '<input type="radio"'; |
|
| 1215 | + |
|
| 1216 | + // class |
|
| 1217 | + $output .= ' class="form-check-input" '; |
|
| 1218 | + |
|
| 1219 | + // name |
|
| 1220 | + if ( ! empty( $args['name'] ) ) { |
|
| 1221 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + // id |
|
| 1225 | + if ( ! empty( $args['id'] ) ) { |
|
| 1226 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + // title |
|
| 1230 | + if ( ! empty( $args['title'] ) ) { |
|
| 1231 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + // value |
|
| 1235 | + if ( isset( $args['value'] ) ) { |
|
| 1236 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + // checked, for radio and checkboxes |
|
| 1240 | + if ( $args['checked'] ) { |
|
| 1241 | + $output .= ' checked '; |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + // data-attributes |
|
| 1245 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 1246 | + |
|
| 1247 | + // aria-attributes |
|
| 1248 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 1249 | + |
|
| 1250 | + // extra attributes |
|
| 1251 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 1252 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + // required |
|
| 1256 | + if ( ! empty( $args['required'] ) ) { |
|
| 1257 | + $output .= ' required '; |
|
| 1258 | + } |
|
| 1259 | + |
|
| 1260 | + // close opening tag |
|
| 1261 | + $output .= ' >'; |
|
| 1262 | + |
|
| 1263 | + // label |
|
| 1264 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 1265 | + } elseif ( ! empty( $args['label'] ) ) { |
|
| 1266 | + $output .= self::label( array( |
|
| 1267 | + 'title' => $args['label'], |
|
| 1268 | + 'for' => $args['id'] . $count, |
|
| 1269 | + 'class' => 'form-check-label' |
|
| 1270 | + ), 'radio' ); |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + // wrap |
|
| 1274 | + if ( ! $args['no_wrap'] ) { |
|
| 1275 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1276 | + |
|
| 1277 | + // Unique wrap class |
|
| 1278 | + $uniq_class = 'fwrap'; |
|
| 1279 | + if ( ! empty( $args['name'] ) ) { |
|
| 1280 | + $uniq_class .= '-' . $args['name']; |
|
| 1281 | + } else if ( ! empty( $args['id'] ) ) { |
|
| 1282 | + $uniq_class .= '-' . $args['id']; |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
| 1286 | + $uniq_class .= '-' . $args['value']; |
|
| 1287 | + } else { |
|
| 1288 | + $uniq_class .= '-' . $count; |
|
| 1289 | + } |
|
| 1290 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
| 1291 | + |
|
| 1292 | + $output = self::wrap( array( |
|
| 1293 | + 'content' => $output, |
|
| 1294 | + 'class' => $wrap_class |
|
| 1295 | + ) ); |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + return $output; |
|
| 1299 | + } |
|
| 1300 | 1300 | |
| 1301 | 1301 | } |
| 1302 | 1302 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,28 +22,28 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - aui()->alert( |
|
| 28 | + aui()->alert( |
|
| 29 | 29 | array( |
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ), |
|
| 33 | - true |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ), |
|
| 33 | + true |
|
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | + } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 37 | 37 | |
| 38 | - // Display a single subscription. |
|
| 39 | - wpinv_recurring_subscription_details(); |
|
| 40 | - } else { |
|
| 38 | + // Display a single subscription. |
|
| 39 | + wpinv_recurring_subscription_details(); |
|
| 40 | + } else { |
|
| 41 | 41 | |
| 42 | - // Display a list of available subscriptions. |
|
| 43 | - getpaid_print_subscriptions_list(); |
|
| 44 | - } |
|
| 42 | + // Display a list of available subscriptions. |
|
| 43 | + getpaid_print_subscriptions_list(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - ?> |
|
| 46 | + ?> |
|
| 47 | 47 | |
| 48 | 48 | </div> |
| 49 | 49 | </div> |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function getpaid_print_subscriptions_list() { |
| 62 | 62 | |
| 63 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 64 | - $subscribers_table->prepare_items(); |
|
| 63 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 64 | + $subscribers_table->prepare_items(); |
|
| 65 | 65 | |
| 66 | - ?> |
|
| 66 | + ?> |
|
| 67 | 67 | <?php $subscribers_table->views(); ?> |
| 68 | 68 | <form id="subscribers-filter" class="bsui" method="get"> |
| 69 | 69 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
@@ -82,42 +82,42 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function wpinv_recurring_subscription_details() { |
| 84 | 84 | |
| 85 | - // Fetch the subscription. |
|
| 86 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 87 | - if ( ! $sub->exists() ) { |
|
| 85 | + // Fetch the subscription. |
|
| 86 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 87 | + if ( ! $sub->exists() ) { |
|
| 88 | 88 | |
| 89 | - aui()->alert( |
|
| 90 | - array( |
|
| 91 | - 'type' => 'danger', |
|
| 92 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 93 | - ), |
|
| 94 | - true |
|
| 95 | - ); |
|
| 89 | + aui()->alert( |
|
| 90 | + array( |
|
| 91 | + 'type' => 'danger', |
|
| 92 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 93 | + ), |
|
| 94 | + true |
|
| 95 | + ); |
|
| 96 | 96 | |
| 97 | - return; |
|
| 98 | - } |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - // Use metaboxes to display the subscription details. |
|
| 101 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 102 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | + // Use metaboxes to display the subscription details. |
|
| 101 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 102 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 103 | 103 | |
| 104 | - $subscription_id = $sub->get_id(); |
|
| 105 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 106 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 104 | + $subscription_id = $sub->get_id(); |
|
| 105 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 106 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 107 | 107 | |
| 108 | - if ( 1 < count( $subscription_groups ) ) { |
|
| 109 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 110 | - } |
|
| 108 | + if ( 1 < count( $subscription_groups ) ) { |
|
| 109 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - if ( ! empty( $subscription_group ) ) { |
|
| 113 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 114 | - } |
|
| 112 | + if ( ! empty( $subscription_group ) ) { |
|
| 113 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 116 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 117 | 117 | |
| 118 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 118 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 119 | 119 | |
| 120 | - ?> |
|
| 120 | + ?> |
|
| 121 | 121 | |
| 122 | 122 | <form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ) ); ?>"> |
| 123 | 123 | |
@@ -157,49 +157,49 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 159 | 159 | |
| 160 | - // Subscription items. |
|
| 161 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 162 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 163 | - |
|
| 164 | - // Prepare subscription detail columns. |
|
| 165 | - $fields = apply_filters( |
|
| 166 | - 'getpaid_subscription_admin_page_fields', |
|
| 167 | - array( |
|
| 168 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 169 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 170 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 171 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 172 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 173 | - 'renewals' => __( 'Collected Payments', 'invoicing' ), |
|
| 174 | - 'item' => $items_count > 1 ? __( 'Items', 'invoicing' ) : __( 'Item', 'invoicing' ), |
|
| 175 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 176 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 177 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 178 | - ) |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - if ( ! $sub->is_active() ) { |
|
| 182 | - |
|
| 183 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 184 | - unset( $fields['renews_on'] ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if ( isset( $fields['gateway'] ) ) { |
|
| 188 | - unset( $fields['gateway'] ); |
|
| 189 | - } |
|
| 190 | - } elseif ( $sub->is_last_renewal() ) { |
|
| 191 | - |
|
| 192 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 193 | - $fields['renews_on'] = __( 'End Date', 'invoicing' ); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $profile_id = $sub->get_profile_id(); |
|
| 198 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 199 | - unset( $fields['profile_id'] ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - ?> |
|
| 160 | + // Subscription items. |
|
| 161 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 162 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 163 | + |
|
| 164 | + // Prepare subscription detail columns. |
|
| 165 | + $fields = apply_filters( |
|
| 166 | + 'getpaid_subscription_admin_page_fields', |
|
| 167 | + array( |
|
| 168 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 169 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 170 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 171 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 172 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 173 | + 'renewals' => __( 'Collected Payments', 'invoicing' ), |
|
| 174 | + 'item' => $items_count > 1 ? __( 'Items', 'invoicing' ) : __( 'Item', 'invoicing' ), |
|
| 175 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 176 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 177 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 178 | + ) |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + if ( ! $sub->is_active() ) { |
|
| 182 | + |
|
| 183 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 184 | + unset( $fields['renews_on'] ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if ( isset( $fields['gateway'] ) ) { |
|
| 188 | + unset( $fields['gateway'] ); |
|
| 189 | + } |
|
| 190 | + } elseif ( $sub->is_last_renewal() ) { |
|
| 191 | + |
|
| 192 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 193 | + $fields['renews_on'] = __( 'End Date', 'invoicing' ); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $profile_id = $sub->get_profile_id(); |
|
| 198 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 199 | + unset( $fields['profile_id'] ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + ?> |
|
| 203 | 203 | |
| 204 | 204 | <table class="table table-borderless" style="font-size: 14px;"> |
| 205 | 205 | <tbody> |
@@ -233,20 +233,20 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 235 | 235 | |
| 236 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 236 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 237 | 237 | |
| 238 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 239 | - if ( $user ) { |
|
| 238 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 239 | + if ( $user ) { |
|
| 240 | 240 | |
| 241 | - $username = sprintf( |
|
| 242 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 243 | - absint( $user->ID ), |
|
| 244 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 245 | - ); |
|
| 241 | + $username = sprintf( |
|
| 242 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 243 | + absint( $user->ID ), |
|
| 244 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 245 | + ); |
|
| 246 | 246 | |
| 247 | - } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - echo wp_kses_post( $username ); |
|
| 249 | + echo wp_kses_post( $username ); |
|
| 250 | 250 | } |
| 251 | 251 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 252 | 252 | |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | * @param WPInv_Subscription $subscription |
| 257 | 257 | */ |
| 258 | 258 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 259 | - $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
| 260 | - echo wp_kses_post( "<span>$amount</span>" ); |
|
| 259 | + $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
| 260 | + echo wp_kses_post( "<span>$amount</span>" ); |
|
| 261 | 261 | } |
| 262 | 262 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 263 | 263 | |
@@ -268,11 +268,11 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 270 | 270 | |
| 271 | - printf( |
|
| 272 | - '<a href="%s">#%s</a>', |
|
| 273 | - esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
| 274 | - absint( $subscription->get_id() ) |
|
| 275 | - ); |
|
| 271 | + printf( |
|
| 272 | + '<a href="%s">#%s</a>', |
|
| 273 | + esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
| 274 | + absint( $subscription->get_id() ) |
|
| 275 | + ); |
|
| 276 | 276 | |
| 277 | 277 | } |
| 278 | 278 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
@@ -284,24 +284,24 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 286 | 286 | |
| 287 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 288 | - aui()->input( |
|
| 289 | - array( |
|
| 290 | - 'type' => 'text', |
|
| 291 | - 'id' => 'wpinv_subscription_date_created', |
|
| 292 | - 'name' => 'wpinv_subscription_date_created', |
|
| 293 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
| 294 | - 'label_type' => 'hidden', |
|
| 295 | - 'placeholder' => 'YYYY-MM-DD', |
|
| 296 | - 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
| 297 | - 'no_wrap' => true, |
|
| 298 | - 'size' => 'sm', |
|
| 299 | - ), |
|
| 300 | - true |
|
| 301 | - ); |
|
| 302 | - } else { |
|
| 303 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 304 | - } |
|
| 287 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 288 | + aui()->input( |
|
| 289 | + array( |
|
| 290 | + 'type' => 'text', |
|
| 291 | + 'id' => 'wpinv_subscription_date_created', |
|
| 292 | + 'name' => 'wpinv_subscription_date_created', |
|
| 293 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
| 294 | + 'label_type' => 'hidden', |
|
| 295 | + 'placeholder' => 'YYYY-MM-DD', |
|
| 296 | + 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
| 297 | + 'no_wrap' => true, |
|
| 298 | + 'size' => 'sm', |
|
| 299 | + ), |
|
| 300 | + true |
|
| 301 | + ); |
|
| 302 | + } else { |
|
| 303 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | 306 | } |
| 307 | 307 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
@@ -313,24 +313,24 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 315 | 315 | |
| 316 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 317 | - aui()->input( |
|
| 318 | - array( |
|
| 319 | - 'type' => 'text', |
|
| 320 | - 'id' => 'wpinv_subscription_expiration', |
|
| 321 | - 'name' => 'wpinv_subscription_expiration', |
|
| 322 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
| 323 | - 'label_type' => 'hidden', |
|
| 324 | - 'placeholder' => 'YYYY-MM-DD', |
|
| 325 | - 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
| 326 | - 'no_wrap' => true, |
|
| 327 | - 'size' => 'sm', |
|
| 328 | - ), |
|
| 329 | - true |
|
| 330 | - ); |
|
| 331 | - } else { |
|
| 332 | - echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
| 333 | - } |
|
| 316 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 317 | + aui()->input( |
|
| 318 | + array( |
|
| 319 | + 'type' => 'text', |
|
| 320 | + 'id' => 'wpinv_subscription_expiration', |
|
| 321 | + 'name' => 'wpinv_subscription_expiration', |
|
| 322 | + 'label' => __( 'Renews On', 'invoicing' ), |
|
| 323 | + 'label_type' => 'hidden', |
|
| 324 | + 'placeholder' => 'YYYY-MM-DD', |
|
| 325 | + 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
| 326 | + 'no_wrap' => true, |
|
| 327 | + 'size' => 'sm', |
|
| 328 | + ), |
|
| 329 | + true |
|
| 330 | + ); |
|
| 331 | + } else { |
|
| 332 | + echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
| 333 | + } |
|
| 334 | 334 | } |
| 335 | 335 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 336 | 336 | |
@@ -341,32 +341,32 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 343 | 343 | |
| 344 | - $max_bills = $subscription->get_bill_times(); |
|
| 345 | - $times_billed = (int) $subscription->get_times_billed(); |
|
| 346 | - |
|
| 347 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_bill_times_change' ) ) { |
|
| 348 | - aui()->input( |
|
| 349 | - array( |
|
| 350 | - 'type' => 'number', |
|
| 351 | - 'id' => 'wpinv_subscription_max_bill_times', |
|
| 352 | - 'name' => 'wpinv_subscription_max_bill_times', |
|
| 353 | - 'label' => __( 'Maximum bill times', 'invoicing' ), |
|
| 354 | - 'label_type' => 'hidden', |
|
| 355 | - 'placeholder' => __( 'Unlimited', 'invoicing' ), |
|
| 356 | - 'value' => empty( $max_bills ) ? '' : (int) $max_bills, |
|
| 357 | - 'no_wrap' => true, |
|
| 358 | - 'size' => 'sm', |
|
| 359 | - 'input_group_left' => sprintf( |
|
| 360 | - // translators: %d: Number of times billed |
|
| 361 | - __( '%d of', 'invoicing' ), |
|
| 362 | - $times_billed |
|
| 363 | - ), |
|
| 364 | - ), |
|
| 365 | - true |
|
| 366 | - ); |
|
| 367 | - } else { |
|
| 368 | - echo esc_html( $times_billed ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 369 | - } |
|
| 344 | + $max_bills = $subscription->get_bill_times(); |
|
| 345 | + $times_billed = (int) $subscription->get_times_billed(); |
|
| 346 | + |
|
| 347 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_bill_times_change' ) ) { |
|
| 348 | + aui()->input( |
|
| 349 | + array( |
|
| 350 | + 'type' => 'number', |
|
| 351 | + 'id' => 'wpinv_subscription_max_bill_times', |
|
| 352 | + 'name' => 'wpinv_subscription_max_bill_times', |
|
| 353 | + 'label' => __( 'Maximum bill times', 'invoicing' ), |
|
| 354 | + 'label_type' => 'hidden', |
|
| 355 | + 'placeholder' => __( 'Unlimited', 'invoicing' ), |
|
| 356 | + 'value' => empty( $max_bills ) ? '' : (int) $max_bills, |
|
| 357 | + 'no_wrap' => true, |
|
| 358 | + 'size' => 'sm', |
|
| 359 | + 'input_group_left' => sprintf( |
|
| 360 | + // translators: %d: Number of times billed |
|
| 361 | + __( '%d of', 'invoicing' ), |
|
| 362 | + $times_billed |
|
| 363 | + ), |
|
| 364 | + ), |
|
| 365 | + true |
|
| 366 | + ); |
|
| 367 | + } else { |
|
| 368 | + echo esc_html( $times_billed ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 369 | + } |
|
| 370 | 370 | } |
| 371 | 371 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 372 | 372 | |
@@ -378,13 +378,13 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
| 380 | 380 | |
| 381 | - if ( empty( $subscription_group ) ) { |
|
| 382 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
| 383 | - return; |
|
| 384 | - } |
|
| 381 | + if ( empty( $subscription_group ) ) { |
|
| 382 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
| 383 | + return; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 387 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 386 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 387 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 388 | 388 | |
| 389 | 389 | } |
| 390 | 390 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -396,13 +396,13 @@ discard block |
||
| 396 | 396 | */ |
| 397 | 397 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 398 | 398 | |
| 399 | - $gateway = $subscription->get_gateway(); |
|
| 399 | + $gateway = $subscription->get_gateway(); |
|
| 400 | 400 | |
| 401 | - if ( ! empty( $gateway ) ) { |
|
| 402 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 403 | - } else { |
|
| 404 | - echo '—'; |
|
| 405 | - } |
|
| 401 | + if ( ! empty( $gateway ) ) { |
|
| 402 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 403 | + } else { |
|
| 404 | + echo '—'; |
|
| 405 | + } |
|
| 406 | 406 | |
| 407 | 407 | } |
| 408 | 408 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * @param WPInv_Subscription $subscription |
| 414 | 414 | */ |
| 415 | 415 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 416 | - echo wp_kses_post( $subscription->get_status_label_html() ); |
|
| 416 | + echo wp_kses_post( $subscription->get_status_label_html() ); |
|
| 417 | 417 | } |
| 418 | 418 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 419 | 419 | |
@@ -424,28 +424,28 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 426 | 426 | |
| 427 | - $profile_id = $subscription->get_profile_id(); |
|
| 428 | - |
|
| 429 | - aui()->input( |
|
| 430 | - array( |
|
| 431 | - 'type' => 'text', |
|
| 432 | - 'id' => 'wpinv_subscription_profile_id', |
|
| 433 | - 'name' => 'wpinv_subscription_profile_id', |
|
| 434 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 435 | - 'label_type' => 'hidden', |
|
| 436 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 437 | - 'value' => esc_attr( $profile_id ), |
|
| 438 | - 'input_group_right' => '', |
|
| 439 | - 'no_wrap' => true, |
|
| 440 | - 'size' => 'sm', |
|
| 441 | - ), |
|
| 442 | - true |
|
| 443 | - ); |
|
| 444 | - |
|
| 445 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 446 | - if ( ! empty( $url ) ) { |
|
| 447 | - echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 448 | - } |
|
| 427 | + $profile_id = $subscription->get_profile_id(); |
|
| 428 | + |
|
| 429 | + aui()->input( |
|
| 430 | + array( |
|
| 431 | + 'type' => 'text', |
|
| 432 | + 'id' => 'wpinv_subscription_profile_id', |
|
| 433 | + 'name' => 'wpinv_subscription_profile_id', |
|
| 434 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 435 | + 'label_type' => 'hidden', |
|
| 436 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 437 | + 'value' => esc_attr( $profile_id ), |
|
| 438 | + 'input_group_right' => '', |
|
| 439 | + 'no_wrap' => true, |
|
| 440 | + 'size' => 'sm', |
|
| 441 | + ), |
|
| 442 | + true |
|
| 443 | + ); |
|
| 444 | + |
|
| 445 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 446 | + if ( ! empty( $url ) ) { |
|
| 447 | + echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | 450 | } |
| 451 | 451 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -457,40 +457,40 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 459 | 459 | |
| 460 | - ?> |
|
| 460 | + ?> |
|
| 461 | 461 | <div class="mt-3"> |
| 462 | 462 | |
| 463 | 463 | <?php |
| 464 | - aui()->select( |
|
| 465 | - array( |
|
| 466 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 467 | - 'name' => 'subscription_status', |
|
| 468 | - 'id' => 'subscription_status_update_select', |
|
| 469 | - 'required' => true, |
|
| 470 | - 'no_wrap' => false, |
|
| 471 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 472 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 473 | - 'select2' => true, |
|
| 474 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 475 | - ), |
|
| 476 | - true |
|
| 477 | - ); |
|
| 478 | - ?> |
|
| 464 | + aui()->select( |
|
| 465 | + array( |
|
| 466 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 467 | + 'name' => 'subscription_status', |
|
| 468 | + 'id' => 'subscription_status_update_select', |
|
| 469 | + 'required' => true, |
|
| 470 | + 'no_wrap' => false, |
|
| 471 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 472 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 473 | + 'select2' => true, |
|
| 474 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 475 | + ), |
|
| 476 | + true |
|
| 477 | + ); |
|
| 478 | + ?> |
|
| 479 | 479 | |
| 480 | 480 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 481 | 481 | |
| 482 | 482 | <?php |
| 483 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 483 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 484 | 484 | |
| 485 | - $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 486 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 487 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 485 | + $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 486 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 487 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 488 | 488 | |
| 489 | - if ( $subscription->is_active() ) { |
|
| 490 | - echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
| 491 | - } |
|
| 489 | + if ( $subscription->is_active() ) { |
|
| 490 | + echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | - echo '</div></div>'; |
|
| 493 | + echo '</div></div>'; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -501,33 +501,33 @@ discard block |
||
| 501 | 501 | */ |
| 502 | 502 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
| 503 | 503 | |
| 504 | - $columns = apply_filters( |
|
| 505 | - 'getpaid_subscription_related_invoices_columns', |
|
| 506 | - array( |
|
| 507 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 508 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 509 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 510 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 511 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 512 | - ), |
|
| 513 | - $subscription |
|
| 514 | - ); |
|
| 515 | - |
|
| 516 | - // Prepare the invoices. |
|
| 517 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 518 | - $parent = $subscription->get_parent_invoice(); |
|
| 519 | - |
|
| 520 | - if ( $parent->exists() ) { |
|
| 521 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $table_class = 'w-100 bg-white'; |
|
| 525 | - |
|
| 526 | - if ( ! is_admin() ) { |
|
| 527 | - $table_class = 'table table-bordered'; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - ?> |
|
| 504 | + $columns = apply_filters( |
|
| 505 | + 'getpaid_subscription_related_invoices_columns', |
|
| 506 | + array( |
|
| 507 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 508 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 509 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 510 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 511 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 512 | + ), |
|
| 513 | + $subscription |
|
| 514 | + ); |
|
| 515 | + |
|
| 516 | + // Prepare the invoices. |
|
| 517 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 518 | + $parent = $subscription->get_parent_invoice(); |
|
| 519 | + |
|
| 520 | + if ( $parent->exists() ) { |
|
| 521 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $table_class = 'w-100 bg-white'; |
|
| 525 | + |
|
| 526 | + if ( ! is_admin() ) { |
|
| 527 | + $table_class = 'table table-bordered'; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + ?> |
|
| 531 | 531 | <div class="m-0" style="overflow: auto;"> |
| 532 | 532 | |
| 533 | 533 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -535,10 +535,10 @@ discard block |
||
| 535 | 535 | <thead> |
| 536 | 536 | <tr> |
| 537 | 537 | <?php |
| 538 | - foreach ( $columns as $key => $label ) { |
|
| 539 | - echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 540 | - } |
|
| 541 | - ?> |
|
| 538 | + foreach ( $columns as $key => $label ) { |
|
| 539 | + echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 540 | + } |
|
| 541 | + ?> |
|
| 542 | 542 | </tr> |
| 543 | 543 | </thead> |
| 544 | 544 | |
@@ -554,72 +554,72 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | <?php |
| 556 | 556 | |
| 557 | - foreach ( $payments as $payment ) : |
|
| 557 | + foreach ( $payments as $payment ) : |
|
| 558 | 558 | |
| 559 | - // Ensure that we have an invoice. |
|
| 560 | - $payment = new WPInv_Invoice( $payment ); |
|
| 559 | + // Ensure that we have an invoice. |
|
| 560 | + $payment = new WPInv_Invoice( $payment ); |
|
| 561 | 561 | |
| 562 | - // Abort if the invoice is invalid... |
|
| 563 | - if ( ! $payment->exists() ) { |
|
| 564 | - continue; |
|
| 565 | - } |
|
| 562 | + // Abort if the invoice is invalid... |
|
| 563 | + if ( ! $payment->exists() ) { |
|
| 564 | + continue; |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - // ... or belongs to a different subscription. |
|
| 568 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 569 | - continue; |
|
| 570 | - } |
|
| 567 | + // ... or belongs to a different subscription. |
|
| 568 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 569 | + continue; |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - echo '<tr>'; |
|
| 572 | + echo '<tr>'; |
|
| 573 | 573 | |
| 574 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 574 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 575 | 575 | |
| 576 | - echo "<td class='p-2 text-left'>"; |
|
| 576 | + echo "<td class='p-2 text-left'>"; |
|
| 577 | 577 | |
| 578 | - switch ( $key ) { |
|
| 578 | + switch ( $key ) { |
|
| 579 | 579 | |
| 580 | - case 'total': |
|
| 581 | - echo '<strong>'; |
|
| 582 | - wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
| 583 | - echo '</strong>'; |
|
| 584 | - break; |
|
| 580 | + case 'total': |
|
| 581 | + echo '<strong>'; |
|
| 582 | + wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
| 583 | + echo '</strong>'; |
|
| 584 | + break; |
|
| 585 | 585 | |
| 586 | - case 'relationship': |
|
| 587 | - echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
| 588 | - break; |
|
| 586 | + case 'relationship': |
|
| 587 | + echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
| 588 | + break; |
|
| 589 | 589 | |
| 590 | - case 'date': |
|
| 591 | - echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
| 592 | - break; |
|
| 590 | + case 'date': |
|
| 591 | + echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
| 592 | + break; |
|
| 593 | 593 | |
| 594 | - case 'status': |
|
| 595 | - $status = $payment->get_status_nicename(); |
|
| 596 | - if ( is_admin() ) { |
|
| 597 | - $status = $payment->get_status_label_html(); |
|
| 598 | - } |
|
| 594 | + case 'status': |
|
| 595 | + $status = $payment->get_status_nicename(); |
|
| 596 | + if ( is_admin() ) { |
|
| 597 | + $status = $payment->get_status_label_html(); |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - echo wp_kses_post( $status ); |
|
| 601 | - break; |
|
| 600 | + echo wp_kses_post( $status ); |
|
| 601 | + break; |
|
| 602 | 602 | |
| 603 | - case 'invoice': |
|
| 604 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 603 | + case 'invoice': |
|
| 604 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 605 | 605 | |
| 606 | - if ( ! is_admin() ) { |
|
| 607 | - $link = esc_url( $payment->get_view_url() ); |
|
| 608 | - } |
|
| 606 | + if ( ! is_admin() ) { |
|
| 607 | + $link = esc_url( $payment->get_view_url() ); |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | - $invoice = esc_html( $payment->get_number() ); |
|
| 611 | - echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
| 612 | - break; |
|
| 613 | - } |
|
| 610 | + $invoice = esc_html( $payment->get_number() ); |
|
| 611 | + echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
| 612 | + break; |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | - echo '</td>'; |
|
| 615 | + echo '</td>'; |
|
| 616 | 616 | |
| 617 | - } |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | - echo '</tr>'; |
|
| 619 | + echo '</tr>'; |
|
| 620 | 620 | |
| 621 | - endforeach; |
|
| 622 | - ?> |
|
| 621 | + endforeach; |
|
| 622 | + ?> |
|
| 623 | 623 | |
| 624 | 624 | </tbody> |
| 625 | 625 | |
@@ -637,42 +637,42 @@ discard block |
||
| 637 | 637 | */ |
| 638 | 638 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
| 639 | 639 | |
| 640 | - // Fetch the subscription group. |
|
| 641 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 640 | + // Fetch the subscription group. |
|
| 641 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 642 | 642 | |
| 643 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 644 | - return; |
|
| 645 | - } |
|
| 643 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 644 | + return; |
|
| 645 | + } |
|
| 646 | 646 | |
| 647 | - // Prepare table columns. |
|
| 648 | - $columns = apply_filters( |
|
| 649 | - 'getpaid_subscription_item_details_columns', |
|
| 650 | - array( |
|
| 651 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
| 652 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 653 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 654 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 655 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 656 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
| 657 | - ), |
|
| 658 | - $subscription |
|
| 659 | - ); |
|
| 647 | + // Prepare table columns. |
|
| 648 | + $columns = apply_filters( |
|
| 649 | + 'getpaid_subscription_item_details_columns', |
|
| 650 | + array( |
|
| 651 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
| 652 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 653 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 654 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
| 655 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 656 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
| 657 | + ), |
|
| 658 | + $subscription |
|
| 659 | + ); |
|
| 660 | 660 | |
| 661 | - // Prepare the invoices. |
|
| 661 | + // Prepare the invoices. |
|
| 662 | 662 | |
| 663 | - $invoice = $subscription->get_parent_invoice(); |
|
| 663 | + $invoice = $subscription->get_parent_invoice(); |
|
| 664 | 664 | |
| 665 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 666 | - unset( $columns['tax'] ); |
|
| 667 | - } |
|
| 665 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 666 | + unset( $columns['tax'] ); |
|
| 667 | + } |
|
| 668 | 668 | |
| 669 | - $table_class = 'w-100 bg-white'; |
|
| 669 | + $table_class = 'w-100 bg-white'; |
|
| 670 | 670 | |
| 671 | - if ( ! is_admin() ) { |
|
| 672 | - $table_class = 'table table-bordered'; |
|
| 673 | - } |
|
| 671 | + if ( ! is_admin() ) { |
|
| 672 | + $table_class = 'table table-bordered'; |
|
| 673 | + } |
|
| 674 | 674 | |
| 675 | - ?> |
|
| 675 | + ?> |
|
| 676 | 676 | <div class="m-0" style="overflow: auto;"> |
| 677 | 677 | |
| 678 | 678 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -681,10 +681,10 @@ discard block |
||
| 681 | 681 | <tr> |
| 682 | 682 | <?php |
| 683 | 683 | |
| 684 | - foreach ( $columns as $key => $label ) { |
|
| 685 | - echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 686 | - } |
|
| 687 | - ?> |
|
| 684 | + foreach ( $columns as $key => $label ) { |
|
| 685 | + echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 686 | + } |
|
| 687 | + ?> |
|
| 688 | 688 | </tr> |
| 689 | 689 | </thead> |
| 690 | 690 | |
@@ -692,106 +692,106 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | <?php |
| 694 | 694 | |
| 695 | - foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
| 695 | + foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
| 696 | 696 | |
| 697 | - echo '<tr>'; |
|
| 697 | + echo '<tr>'; |
|
| 698 | 698 | |
| 699 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 699 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 700 | 700 | |
| 701 | - $class = 'text-left'; |
|
| 701 | + $class = 'text-left'; |
|
| 702 | 702 | |
| 703 | - echo "<td class='p-2 text-left'>"; |
|
| 703 | + echo "<td class='p-2 text-left'>"; |
|
| 704 | 704 | |
| 705 | - switch ( $key ) { |
|
| 705 | + switch ( $key ) { |
|
| 706 | 706 | |
| 707 | - case 'item_name': |
|
| 708 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 709 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 707 | + case 'item_name': |
|
| 708 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 709 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 710 | 710 | |
| 711 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 712 | - echo esc_html( $item_name ); |
|
| 713 | - } else { |
|
| 714 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 715 | - } |
|
| 711 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 712 | + echo esc_html( $item_name ); |
|
| 713 | + } else { |
|
| 714 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - break; |
|
| 717 | + break; |
|
| 718 | 718 | |
| 719 | - case 'price': |
|
| 720 | - wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
| 721 | - break; |
|
| 719 | + case 'price': |
|
| 720 | + wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
| 721 | + break; |
|
| 722 | 722 | |
| 723 | - case 'tax': |
|
| 724 | - wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 725 | - break; |
|
| 723 | + case 'tax': |
|
| 724 | + wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 725 | + break; |
|
| 726 | 726 | |
| 727 | - case 'discount': |
|
| 728 | - wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 729 | - break; |
|
| 727 | + case 'discount': |
|
| 728 | + wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 729 | + break; |
|
| 730 | 730 | |
| 731 | - case 'initial': |
|
| 732 | - wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
| 733 | - break; |
|
| 731 | + case 'initial': |
|
| 732 | + wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
| 733 | + break; |
|
| 734 | 734 | |
| 735 | - case 'recurring': |
|
| 736 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
| 737 | - break; |
|
| 735 | + case 'recurring': |
|
| 736 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
| 737 | + break; |
|
| 738 | 738 | |
| 739 | - } |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | - echo '</td>'; |
|
| 741 | + echo '</td>'; |
|
| 742 | 742 | |
| 743 | - } |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - echo '</tr>'; |
|
| 745 | + echo '</tr>'; |
|
| 746 | 746 | |
| 747 | - endforeach; |
|
| 747 | + endforeach; |
|
| 748 | 748 | |
| 749 | - foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 749 | + foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 750 | 750 | |
| 751 | - echo '<tr>'; |
|
| 751 | + echo '<tr>'; |
|
| 752 | 752 | |
| 753 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 753 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 754 | 754 | |
| 755 | - $class = 'text-left'; |
|
| 755 | + $class = 'text-left'; |
|
| 756 | 756 | |
| 757 | - echo "<td class='p-2 text-left'>"; |
|
| 757 | + echo "<td class='p-2 text-left'>"; |
|
| 758 | 758 | |
| 759 | - switch ( $key ) { |
|
| 759 | + switch ( $key ) { |
|
| 760 | 760 | |
| 761 | - case 'item_name': |
|
| 762 | - echo esc_html( $subscription_group_fee['name'] ); |
|
| 763 | - break; |
|
| 761 | + case 'item_name': |
|
| 762 | + echo esc_html( $subscription_group_fee['name'] ); |
|
| 763 | + break; |
|
| 764 | 764 | |
| 765 | - case 'price': |
|
| 766 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 767 | - break; |
|
| 765 | + case 'price': |
|
| 766 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 767 | + break; |
|
| 768 | 768 | |
| 769 | - case 'tax': |
|
| 770 | - echo '—'; |
|
| 771 | - break; |
|
| 769 | + case 'tax': |
|
| 770 | + echo '—'; |
|
| 771 | + break; |
|
| 772 | 772 | |
| 773 | - case 'discount': |
|
| 774 | - echo '—'; |
|
| 775 | - break; |
|
| 773 | + case 'discount': |
|
| 774 | + echo '—'; |
|
| 775 | + break; |
|
| 776 | 776 | |
| 777 | - case 'initial': |
|
| 778 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 779 | - break; |
|
| 777 | + case 'initial': |
|
| 778 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 779 | + break; |
|
| 780 | 780 | |
| 781 | - case 'recurring': |
|
| 782 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
| 783 | - break; |
|
| 781 | + case 'recurring': |
|
| 782 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
| 783 | + break; |
|
| 784 | 784 | |
| 785 | - } |
|
| 785 | + } |
|
| 786 | 786 | |
| 787 | - echo '</td>'; |
|
| 787 | + echo '</td>'; |
|
| 788 | 788 | |
| 789 | - } |
|
| 789 | + } |
|
| 790 | 790 | |
| 791 | - echo '</tr>'; |
|
| 791 | + echo '</tr>'; |
|
| 792 | 792 | |
| 793 | - endforeach; |
|
| 794 | - ?> |
|
| 793 | + endforeach; |
|
| 794 | + ?> |
|
| 795 | 795 | |
| 796 | 796 | </tbody> |
| 797 | 797 | |
@@ -810,38 +810,38 @@ discard block |
||
| 810 | 810 | */ |
| 811 | 811 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
| 812 | 812 | |
| 813 | - // Fetch the subscription groups. |
|
| 814 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 815 | - |
|
| 816 | - if ( empty( $subscription_groups ) ) { |
|
| 817 | - return; |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - // Prepare table columns. |
|
| 821 | - $columns = apply_filters( |
|
| 822 | - 'getpaid_subscription_related_subscriptions_columns', |
|
| 823 | - array( |
|
| 824 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 825 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 826 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 827 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 828 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 829 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 830 | - ), |
|
| 831 | - $subscription |
|
| 832 | - ); |
|
| 833 | - |
|
| 834 | - if ( $subscription->get_status() == 'pending' ) { |
|
| 835 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - $table_class = 'w-100 bg-white'; |
|
| 839 | - |
|
| 840 | - if ( ! is_admin() ) { |
|
| 841 | - $table_class = 'table table-bordered'; |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - ?> |
|
| 813 | + // Fetch the subscription groups. |
|
| 814 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 815 | + |
|
| 816 | + if ( empty( $subscription_groups ) ) { |
|
| 817 | + return; |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + // Prepare table columns. |
|
| 821 | + $columns = apply_filters( |
|
| 822 | + 'getpaid_subscription_related_subscriptions_columns', |
|
| 823 | + array( |
|
| 824 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 825 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 826 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 827 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 828 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 829 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 830 | + ), |
|
| 831 | + $subscription |
|
| 832 | + ); |
|
| 833 | + |
|
| 834 | + if ( $subscription->get_status() == 'pending' ) { |
|
| 835 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + $table_class = 'w-100 bg-white'; |
|
| 839 | + |
|
| 840 | + if ( ! is_admin() ) { |
|
| 841 | + $table_class = 'table table-bordered'; |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + ?> |
|
| 845 | 845 | <div class="m-0" style="overflow: auto;"> |
| 846 | 846 | |
| 847 | 847 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -850,10 +850,10 @@ discard block |
||
| 850 | 850 | <tr> |
| 851 | 851 | <?php |
| 852 | 852 | |
| 853 | - foreach ( $columns as $key => $label ) { |
|
| 854 | - echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 855 | - } |
|
| 856 | - ?> |
|
| 853 | + foreach ( $columns as $key => $label ) { |
|
| 854 | + echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 855 | + } |
|
| 856 | + ?> |
|
| 857 | 857 | </tr> |
| 858 | 858 | </thead> |
| 859 | 859 | |
@@ -861,74 +861,74 @@ discard block |
||
| 861 | 861 | |
| 862 | 862 | <?php |
| 863 | 863 | |
| 864 | - foreach ( $subscription_groups as $subscription_group ) : |
|
| 864 | + foreach ( $subscription_groups as $subscription_group ) : |
|
| 865 | 865 | |
| 866 | - // Do not list current subscription. |
|
| 867 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 868 | - continue; |
|
| 869 | - } |
|
| 866 | + // Do not list current subscription. |
|
| 867 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 868 | + continue; |
|
| 869 | + } |
|
| 870 | 870 | |
| 871 | - // Ensure the subscription exists. |
|
| 872 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 871 | + // Ensure the subscription exists. |
|
| 872 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 873 | 873 | |
| 874 | - if ( ! $_suscription->exists() ) { |
|
| 875 | - continue; |
|
| 876 | - } |
|
| 874 | + if ( ! $_suscription->exists() ) { |
|
| 875 | + continue; |
|
| 876 | + } |
|
| 877 | 877 | |
| 878 | - echo '<tr>'; |
|
| 878 | + echo '<tr>'; |
|
| 879 | 879 | |
| 880 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 880 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 881 | 881 | |
| 882 | - $class = 'text-left'; |
|
| 882 | + $class = 'text-left'; |
|
| 883 | 883 | |
| 884 | - echo "<td class='p-2 text-left'>"; |
|
| 884 | + echo "<td class='p-2 text-left'>"; |
|
| 885 | 885 | |
| 886 | - switch ( $key ) { |
|
| 886 | + switch ( $key ) { |
|
| 887 | 887 | |
| 888 | - case 'status': |
|
| 889 | - echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
| 890 | - break; |
|
| 888 | + case 'status': |
|
| 889 | + echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
| 890 | + break; |
|
| 891 | 891 | |
| 892 | - case 'item': |
|
| 893 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 894 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 895 | - break; |
|
| 892 | + case 'item': |
|
| 893 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 894 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 895 | + break; |
|
| 896 | 896 | |
| 897 | - case 'renewals': |
|
| 898 | - $max_bills = $_suscription->get_bill_times(); |
|
| 899 | - echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 900 | - break; |
|
| 897 | + case 'renewals': |
|
| 898 | + $max_bills = $_suscription->get_bill_times(); |
|
| 899 | + echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 900 | + break; |
|
| 901 | 901 | |
| 902 | - case 'renewal_date': |
|
| 903 | - echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
| 904 | - break; |
|
| 902 | + case 'renewal_date': |
|
| 903 | + echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
| 904 | + break; |
|
| 905 | 905 | |
| 906 | - case 'start_date': |
|
| 907 | - echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
| 908 | - break; |
|
| 906 | + case 'start_date': |
|
| 907 | + echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
| 908 | + break; |
|
| 909 | 909 | |
| 910 | - case 'subscription': |
|
| 911 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 912 | - printf( |
|
| 910 | + case 'subscription': |
|
| 911 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 912 | + printf( |
|
| 913 | 913 | '%1$s#%2$s%3$s', |
| 914 | 914 | '<a href="' . esc_url( $url ) . '">', |
| 915 | 915 | '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
| 916 | - '</a>' |
|
| 916 | + '</a>' |
|
| 917 | 917 | ); |
| 918 | 918 | |
| 919 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
| 920 | - break; |
|
| 919 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
| 920 | + break; |
|
| 921 | 921 | |
| 922 | - } |
|
| 922 | + } |
|
| 923 | 923 | |
| 924 | - echo '</td>'; |
|
| 924 | + echo '</td>'; |
|
| 925 | 925 | |
| 926 | - } |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | - echo '</tr>'; |
|
| 928 | + echo '</tr>'; |
|
| 929 | 929 | |
| 930 | - endforeach; |
|
| 931 | - ?> |
|
| 930 | + endforeach; |
|
| 931 | + ?> |
|
| 932 | 932 | |
| 933 | 933 | </tbody> |
| 934 | 934 | |
@@ -5,129 +5,129 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | - exit; // Exit if accessed directly |
|
| 8 | + exit; // Exit if accessed directly |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * GetPaid_Admin_Profile Class. |
|
| 15 | - */ |
|
| 16 | - class GetPaid_Admin_Profile { |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Hook in tabs. |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 24 | - |
|
| 25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Get Address Fields for the edit user pages. |
|
| 31 | - * |
|
| 32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
| 33 | - */ |
|
| 34 | - public function get_customer_meta_fields() { |
|
| 35 | - |
|
| 36 | - $show_fields = apply_filters( |
|
| 37 | - 'getpaid_customer_meta_fields', |
|
| 38 | - array( |
|
| 39 | - 'billing' => array( |
|
| 40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 41 | - 'fields' => array( |
|
| 42 | - '_wpinv_first_name' => array( |
|
| 43 | - 'label' => __( 'First name', 'invoicing' ), |
|
| 44 | - 'description' => '', |
|
| 45 | - ), |
|
| 46 | - '_wpinv_last_name' => array( |
|
| 47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
| 48 | - 'description' => '', |
|
| 49 | - ), |
|
| 50 | - '_wpinv_company' => array( |
|
| 51 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 52 | - 'description' => '', |
|
| 53 | - ), |
|
| 54 | - '_wpinv_company_id' => array( |
|
| 55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 56 | - 'description' => '', |
|
| 57 | - ), |
|
| 58 | - '_wpinv_address' => array( |
|
| 59 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 60 | - 'description' => '', |
|
| 61 | - ), |
|
| 62 | - '_wpinv_city' => array( |
|
| 63 | - 'label' => __( 'City', 'invoicing' ), |
|
| 64 | - 'description' => '', |
|
| 65 | - ), |
|
| 66 | - '_wpinv_zip' => array( |
|
| 67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 68 | - 'description' => '', |
|
| 69 | - ), |
|
| 70 | - '_wpinv_country' => array( |
|
| 71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 72 | - 'description' => '', |
|
| 73 | - 'class' => 'getpaid_js_field-country', |
|
| 74 | - 'type' => 'select', |
|
| 75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 76 | - ), |
|
| 77 | - '_wpinv_state' => array( |
|
| 78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
| 81 | - ), |
|
| 82 | - '_wpinv_phone' => array( |
|
| 83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 84 | - 'description' => '', |
|
| 85 | - ), |
|
| 86 | - '_wpinv_vat_number' => array( |
|
| 87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 88 | - 'description' => '', |
|
| 89 | - ), |
|
| 90 | - ), |
|
| 91 | - ), |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - return $show_fields; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Show Address Fields on edit user pages. |
|
| 99 | - * |
|
| 100 | - * @param WP_User $user |
|
| 101 | - */ |
|
| 102 | - public function add_customer_meta_fields( $user ) { |
|
| 103 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $show_fields = $this->get_customer_meta_fields(); |
|
| 108 | - |
|
| 109 | - $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 110 | - |
|
| 111 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 112 | - if ( ! wpinv_use_taxes() && isset( $fieldset['fields']['_wpinv_vat_number'] ) ) { |
|
| 113 | - unset( $fieldset['fields']['_wpinv_vat_number'] ); |
|
| 114 | - } |
|
| 115 | - ?> |
|
| 13 | + /** |
|
| 14 | + * GetPaid_Admin_Profile Class. |
|
| 15 | + */ |
|
| 16 | + class GetPaid_Admin_Profile { |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Hook in tabs. |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 24 | + |
|
| 25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Get Address Fields for the edit user pages. |
|
| 31 | + * |
|
| 32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
| 33 | + */ |
|
| 34 | + public function get_customer_meta_fields() { |
|
| 35 | + |
|
| 36 | + $show_fields = apply_filters( |
|
| 37 | + 'getpaid_customer_meta_fields', |
|
| 38 | + array( |
|
| 39 | + 'billing' => array( |
|
| 40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 41 | + 'fields' => array( |
|
| 42 | + '_wpinv_first_name' => array( |
|
| 43 | + 'label' => __( 'First name', 'invoicing' ), |
|
| 44 | + 'description' => '', |
|
| 45 | + ), |
|
| 46 | + '_wpinv_last_name' => array( |
|
| 47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
| 48 | + 'description' => '', |
|
| 49 | + ), |
|
| 50 | + '_wpinv_company' => array( |
|
| 51 | + 'label' => __( 'Company', 'invoicing' ), |
|
| 52 | + 'description' => '', |
|
| 53 | + ), |
|
| 54 | + '_wpinv_company_id' => array( |
|
| 55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
| 56 | + 'description' => '', |
|
| 57 | + ), |
|
| 58 | + '_wpinv_address' => array( |
|
| 59 | + 'label' => __( 'Address', 'invoicing' ), |
|
| 60 | + 'description' => '', |
|
| 61 | + ), |
|
| 62 | + '_wpinv_city' => array( |
|
| 63 | + 'label' => __( 'City', 'invoicing' ), |
|
| 64 | + 'description' => '', |
|
| 65 | + ), |
|
| 66 | + '_wpinv_zip' => array( |
|
| 67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 68 | + 'description' => '', |
|
| 69 | + ), |
|
| 70 | + '_wpinv_country' => array( |
|
| 71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 72 | + 'description' => '', |
|
| 73 | + 'class' => 'getpaid_js_field-country', |
|
| 74 | + 'type' => 'select', |
|
| 75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 76 | + ), |
|
| 77 | + '_wpinv_state' => array( |
|
| 78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
| 81 | + ), |
|
| 82 | + '_wpinv_phone' => array( |
|
| 83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
| 84 | + 'description' => '', |
|
| 85 | + ), |
|
| 86 | + '_wpinv_vat_number' => array( |
|
| 87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 88 | + 'description' => '', |
|
| 89 | + ), |
|
| 90 | + ), |
|
| 91 | + ), |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + return $show_fields; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Show Address Fields on edit user pages. |
|
| 99 | + * |
|
| 100 | + * @param WP_User $user |
|
| 101 | + */ |
|
| 102 | + public function add_customer_meta_fields( $user ) { |
|
| 103 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $show_fields = $this->get_customer_meta_fields(); |
|
| 108 | + |
|
| 109 | + $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 110 | + |
|
| 111 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 112 | + if ( ! wpinv_use_taxes() && isset( $fieldset['fields']['_wpinv_vat_number'] ) ) { |
|
| 113 | + unset( $fieldset['fields']['_wpinv_vat_number'] ); |
|
| 114 | + } |
|
| 115 | + ?> |
|
| 116 | 116 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
| 117 | 117 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
| 118 | 118 | <?php foreach ( $fieldset['fields'] as $key => $field ) : |
| 119 | - if ( ! empty( $customer ) ) { |
|
| 120 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 121 | - $save_key = substr( $key , 7 ); |
|
| 122 | - } else { |
|
| 123 | - $save_key = $key; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $value = $customer->get( $save_key ); |
|
| 127 | - } else { |
|
| 128 | - $value = $this->get_user_meta( $user->ID, $key ); |
|
| 129 | - } |
|
| 130 | - ?> |
|
| 119 | + if ( ! empty( $customer ) ) { |
|
| 120 | + if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 121 | + $save_key = substr( $key , 7 ); |
|
| 122 | + } else { |
|
| 123 | + $save_key = $key; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $value = $customer->get( $save_key ); |
|
| 127 | + } else { |
|
| 128 | + $value = $this->get_user_meta( $user->ID, $key ); |
|
| 129 | + } |
|
| 130 | + ?> |
|
| 131 | 131 | <tr> |
| 132 | 132 | <th> |
| 133 | 133 | <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label> |
@@ -150,75 +150,75 @@ discard block |
||
| 150 | 150 | <?php endforeach; ?> |
| 151 | 151 | </table> |
| 152 | 152 | <?php |
| 153 | - endforeach; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Save Address Fields on edit user pages. |
|
| 158 | - * |
|
| 159 | - * @param int $user_id User ID of the user being saved |
|
| 160 | - */ |
|
| 161 | - public function save_customer_meta_fields( $user_id ) { |
|
| 162 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 163 | - return; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $save_fields = $this->get_customer_meta_fields(); |
|
| 167 | - $save_data = array(); |
|
| 168 | - |
|
| 169 | - foreach ( $save_fields as $fieldset ) { |
|
| 170 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 171 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 172 | - $save_key = substr( $key , 7 ); |
|
| 173 | - } else { |
|
| 174 | - $save_key = $key; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 178 | - $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 179 | - } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 180 | - $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ( empty( $save_data ) ) { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 190 | - |
|
| 191 | - if ( empty( $customer ) ) { |
|
| 192 | - $customer = new GetPaid_Customer( 0 ); |
|
| 193 | - $customer->clone_user( (int) $user_id ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - foreach ( $save_data as $key => $value ) { |
|
| 197 | - $customer->set( $key, $value ); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $customer->save(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 205 | - * |
|
| 206 | - * @since 3.1.0 |
|
| 207 | - * @param int $user_id User ID of the user being edited |
|
| 208 | - * @param string $key Key for user meta field |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - protected function get_user_meta( $user_id, $key ) { |
|
| 212 | - $value = get_user_meta( $user_id, $key, true ); |
|
| 213 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 214 | - |
|
| 215 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 216 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - return $value; |
|
| 220 | - } |
|
| 221 | - } |
|
| 153 | + endforeach; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Save Address Fields on edit user pages. |
|
| 158 | + * |
|
| 159 | + * @param int $user_id User ID of the user being saved |
|
| 160 | + */ |
|
| 161 | + public function save_customer_meta_fields( $user_id ) { |
|
| 162 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $save_fields = $this->get_customer_meta_fields(); |
|
| 167 | + $save_data = array(); |
|
| 168 | + |
|
| 169 | + foreach ( $save_fields as $fieldset ) { |
|
| 170 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 171 | + if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 172 | + $save_key = substr( $key , 7 ); |
|
| 173 | + } else { |
|
| 174 | + $save_key = $key; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 178 | + $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 179 | + } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 180 | + $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ( empty( $save_data ) ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 190 | + |
|
| 191 | + if ( empty( $customer ) ) { |
|
| 192 | + $customer = new GetPaid_Customer( 0 ); |
|
| 193 | + $customer->clone_user( (int) $user_id ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + foreach ( $save_data as $key => $value ) { |
|
| 197 | + $customer->set( $key, $value ); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $customer->save(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 205 | + * |
|
| 206 | + * @since 3.1.0 |
|
| 207 | + * @param int $user_id User ID of the user being edited |
|
| 208 | + * @param string $key Key for user meta field |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + protected function get_user_meta( $user_id, $key ) { |
|
| 212 | + $value = get_user_meta( $user_id, $key, true ); |
|
| 213 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 214 | + |
|
| 215 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 216 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + return $value; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | 223 | endif; |
| 224 | 224 | |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; |
|
| 10 | + exit; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | 16 | add_action('after_setup_theme', function () { |
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | - $this_version = "0.2.18"; |
|
| 19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | - } |
|
| 17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | + $this_version = "0.2.18"; |
|
| 19 | + if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | + $ayecode_ui_version = $this_version ; |
|
| 21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | + } |
|
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | 28 | add_action('after_setup_theme', function () { |
| 29 | - global $ayecode_ui_file_key; |
|
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | - } |
|
| 29 | + global $ayecode_ui_file_key; |
|
| 30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | + } |
|
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | 39 | if(!function_exists('aui')){ |
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - return AUI::instance(); |
|
| 45 | - } |
|
| 40 | + function aui(){ |
|
| 41 | + if(!class_exists("AUI",false)){ |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + return AUI::instance(); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -14,76 +14,76 @@ |
||
| 14 | 14 | * @return array|mixed|string|string[] |
| 15 | 15 | */ |
| 16 | 16 | function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) { |
| 17 | - global $aui_bs5; |
|
| 17 | + global $aui_bs5; |
|
| 18 | 18 | |
| 19 | - if ( $aui_bs5 ) { |
|
| 20 | - $convert = array( |
|
| 21 | - '"ml-' => '"ms-', |
|
| 22 | - '"mr-' => '"me-', |
|
| 23 | - '"pl-' => '"ps-', |
|
| 24 | - '"pr-' => '"pe-', |
|
| 25 | - "'ml-" => "'ms-", |
|
| 26 | - "'mr-" => "'me-", |
|
| 27 | - "'pl-" => "'ps-", |
|
| 28 | - "'pr-" => "'pe-", |
|
| 29 | - ' ml-' => ' ms-', |
|
| 30 | - ' mr-' => ' me-', |
|
| 31 | - ' pl-' => ' ps-', |
|
| 32 | - ' pr-' => ' pe-', |
|
| 33 | - '.ml-' => '.ms-', |
|
| 34 | - '.mr-' => '.me-', |
|
| 35 | - '.pl-' => '.ps-', |
|
| 36 | - '.pr-' => '.pe-', |
|
| 37 | - ' form-row' => ' row', |
|
| 38 | - ' embed-responsive-item' => '', |
|
| 39 | - ' embed-responsive' => ' ratio', |
|
| 40 | - '-1by1' => '-1x1', |
|
| 41 | - '-4by3' => '-4x3', |
|
| 42 | - '-16by9' => '-16x9', |
|
| 43 | - '-21by9' => '-21x9', |
|
| 44 | - 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
| 45 | - 'geodir-lightbox-iframe' => 'aui-lightbox-iframe', |
|
| 46 | - ' badge-' => ' text-bg-', |
|
| 47 | - 'form-group' => 'mb-3', |
|
| 48 | - 'custom-select' => 'form-select', |
|
| 49 | - 'float-left' => 'float-start', |
|
| 50 | - 'float-right' => 'float-end', |
|
| 51 | - 'text-left' => 'text-start', |
|
| 52 | - 'text-sm-left' => 'text-sm-start', |
|
| 53 | - 'text-md-left' => 'text-md-start', |
|
| 54 | - 'text-lg-left' => 'text-lg-start', |
|
| 55 | - 'text-right' => 'text-end', |
|
| 56 | - 'text-sm-right' => 'text-sm-end', |
|
| 57 | - 'text-md-right' => 'text-md-end', |
|
| 58 | - 'text-lg-right' => 'text-lg-end', |
|
| 59 | - 'border-right' => 'border-end', |
|
| 60 | - 'border-left' => 'border-start', |
|
| 61 | - 'font-weight-' => 'fw-', |
|
| 62 | - 'btn-block' => 'w-100', |
|
| 63 | - 'rounded-left' => 'rounded-start', |
|
| 64 | - 'rounded-right' => 'rounded-end', |
|
| 65 | - 'font-italic' => 'fst-italic', |
|
| 19 | + if ( $aui_bs5 ) { |
|
| 20 | + $convert = array( |
|
| 21 | + '"ml-' => '"ms-', |
|
| 22 | + '"mr-' => '"me-', |
|
| 23 | + '"pl-' => '"ps-', |
|
| 24 | + '"pr-' => '"pe-', |
|
| 25 | + "'ml-" => "'ms-", |
|
| 26 | + "'mr-" => "'me-", |
|
| 27 | + "'pl-" => "'ps-", |
|
| 28 | + "'pr-" => "'pe-", |
|
| 29 | + ' ml-' => ' ms-', |
|
| 30 | + ' mr-' => ' me-', |
|
| 31 | + ' pl-' => ' ps-', |
|
| 32 | + ' pr-' => ' pe-', |
|
| 33 | + '.ml-' => '.ms-', |
|
| 34 | + '.mr-' => '.me-', |
|
| 35 | + '.pl-' => '.ps-', |
|
| 36 | + '.pr-' => '.pe-', |
|
| 37 | + ' form-row' => ' row', |
|
| 38 | + ' embed-responsive-item' => '', |
|
| 39 | + ' embed-responsive' => ' ratio', |
|
| 40 | + '-1by1' => '-1x1', |
|
| 41 | + '-4by3' => '-4x3', |
|
| 42 | + '-16by9' => '-16x9', |
|
| 43 | + '-21by9' => '-21x9', |
|
| 44 | + 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
| 45 | + 'geodir-lightbox-iframe' => 'aui-lightbox-iframe', |
|
| 46 | + ' badge-' => ' text-bg-', |
|
| 47 | + 'form-group' => 'mb-3', |
|
| 48 | + 'custom-select' => 'form-select', |
|
| 49 | + 'float-left' => 'float-start', |
|
| 50 | + 'float-right' => 'float-end', |
|
| 51 | + 'text-left' => 'text-start', |
|
| 52 | + 'text-sm-left' => 'text-sm-start', |
|
| 53 | + 'text-md-left' => 'text-md-start', |
|
| 54 | + 'text-lg-left' => 'text-lg-start', |
|
| 55 | + 'text-right' => 'text-end', |
|
| 56 | + 'text-sm-right' => 'text-sm-end', |
|
| 57 | + 'text-md-right' => 'text-md-end', |
|
| 58 | + 'text-lg-right' => 'text-lg-end', |
|
| 59 | + 'border-right' => 'border-end', |
|
| 60 | + 'border-left' => 'border-start', |
|
| 61 | + 'font-weight-' => 'fw-', |
|
| 62 | + 'btn-block' => 'w-100', |
|
| 63 | + 'rounded-left' => 'rounded-start', |
|
| 64 | + 'rounded-right' => 'rounded-end', |
|
| 65 | + 'font-italic' => 'fst-italic', |
|
| 66 | 66 | |
| 67 | 67 | // 'custom-control custom-checkbox' => 'form-check', |
| 68 | - // data |
|
| 69 | - ' data-toggle=' => ' data-bs-toggle=', |
|
| 70 | - 'data-ride=' => 'data-bs-ride=', |
|
| 71 | - 'data-controlnav=' => 'data-bs-controlnav=', |
|
| 72 | - 'data-slide=' => 'data-bs-slide=', |
|
| 73 | - 'data-slide-to=' => 'data-bs-slide-to=', |
|
| 74 | - 'data-target=' => 'data-bs-target=', |
|
| 75 | - 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
| 76 | - 'class="close"' => 'class="btn-close"', |
|
| 77 | - '<span aria-hidden="true">×</span>' => '', |
|
| 78 | - ); |
|
| 79 | - $output = str_replace( |
|
| 80 | - array_keys( $convert ), |
|
| 81 | - array_values( $convert ), |
|
| 82 | - $output |
|
| 83 | - ); |
|
| 84 | - } |
|
| 68 | + // data |
|
| 69 | + ' data-toggle=' => ' data-bs-toggle=', |
|
| 70 | + 'data-ride=' => 'data-bs-ride=', |
|
| 71 | + 'data-controlnav=' => 'data-bs-controlnav=', |
|
| 72 | + 'data-slide=' => 'data-bs-slide=', |
|
| 73 | + 'data-slide-to=' => 'data-bs-slide-to=', |
|
| 74 | + 'data-target=' => 'data-bs-target=', |
|
| 75 | + 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
| 76 | + 'class="close"' => 'class="btn-close"', |
|
| 77 | + '<span aria-hidden="true">×</span>' => '', |
|
| 78 | + ); |
|
| 79 | + $output = str_replace( |
|
| 80 | + array_keys( $convert ), |
|
| 81 | + array_values( $convert ), |
|
| 82 | + $output |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $output; |
|
| 86 | + return $output; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | - exit; |
|
| 18 | + exit; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
| 22 | - // include the class if needed |
|
| 23 | - include_once( dirname( __FILE__ ) . "/wp-super-duper.php" ); |
|
| 22 | + // include the class if needed |
|
| 23 | + include_once( dirname( __FILE__ ) . "/wp-super-duper.php" ); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /* |
@@ -35,5 +35,5 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | if ( ! function_exists( 'sd_get_class_build_keys' ) ) { |
| 38 | - include_once( dirname( __FILE__ ) . "/sd-functions.php" ); |
|
| 38 | + include_once( dirname( __FILE__ ) . "/sd-functions.php" ); |
|
| 39 | 39 | } |
| 40 | 40 | \ No newline at end of file |
@@ -3,114 +3,114 @@ discard block |
||
| 3 | 3 | class SD_Hello_World extends WP_Super_Duper { |
| 4 | 4 | |
| 5 | 5 | |
| 6 | - public $arguments; |
|
| 7 | - |
|
| 8 | - /** |
|
| 9 | - * Sets up the widgets name etc |
|
| 10 | - */ |
|
| 11 | - public function __construct() { |
|
| 12 | - |
|
| 13 | - $options = array( |
|
| 14 | - 'textdomain' => 'super-duper', |
|
| 15 | - // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
| 16 | - 'block-icon' => 'fas fa-globe-americas', |
|
| 17 | - // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
| 18 | - // OR font-awesome 5 class name: fas fa-globe-americas |
|
| 19 | - 'block-category' => 'widgets', |
|
| 20 | - // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
| 21 | - 'block-keywords' => "['hello','world']", |
|
| 22 | - // used in the block search, MAX 3 |
|
| 23 | - 'block-output' => array( // the block visual output elements as an array |
|
| 6 | + public $arguments; |
|
| 7 | + |
|
| 8 | + /** |
|
| 9 | + * Sets up the widgets name etc |
|
| 10 | + */ |
|
| 11 | + public function __construct() { |
|
| 12 | + |
|
| 13 | + $options = array( |
|
| 14 | + 'textdomain' => 'super-duper', |
|
| 15 | + // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
| 16 | + 'block-icon' => 'fas fa-globe-americas', |
|
| 17 | + // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
| 18 | + // OR font-awesome 5 class name: fas fa-globe-americas |
|
| 19 | + 'block-category' => 'widgets', |
|
| 20 | + // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
| 21 | + 'block-keywords' => "['hello','world']", |
|
| 22 | + // used in the block search, MAX 3 |
|
| 23 | + 'block-output' => array( // the block visual output elements as an array |
|
| 24 | 24 | // array( |
| 25 | 25 | // 'element' => 'p', |
| 26 | 26 | // 'title' => __( 'Placeholder', 'ayecode-connect' ), |
| 27 | 27 | // 'class' => '[%className%]', |
| 28 | 28 | // 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
| 29 | 29 | // ) |
| 30 | - array( |
|
| 31 | - 'element' => 'BlocksProps', |
|
| 32 | - 'inner_element' => 'p', |
|
| 33 | - 'blockProps' => array( |
|
| 34 | - 'className' => '[%WrapClass%]', |
|
| 30 | + array( |
|
| 31 | + 'element' => 'BlocksProps', |
|
| 32 | + 'inner_element' => 'p', |
|
| 33 | + 'blockProps' => array( |
|
| 34 | + 'className' => '[%WrapClass%]', |
|
| 35 | 35 | // 'content' => 'Hello: [%after_text%]' |
| 36 | 36 | // 'if_dangerouslySetInnerHTML' => '{__html: blockstrap_build_shape(props.attributes) }', |
| 37 | - ), |
|
| 38 | - 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - ), |
|
| 42 | - ), |
|
| 43 | - 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
| 44 | - 'class_name' => __CLASS__, |
|
| 45 | - // The calling class name |
|
| 46 | - 'base_id' => 'hello_world', |
|
| 47 | - // this is used as the widget id and the shortcode id. |
|
| 48 | - 'name' => __( 'Hello World', 'ayecode-connect' ), |
|
| 49 | - // the name of the widget/block |
|
| 50 | - 'widget_ops' => array( |
|
| 51 | - 'classname' => 'hello-world-class', |
|
| 52 | - // widget class |
|
| 53 | - 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
| 54 | - // widget description |
|
| 55 | - ), |
|
| 56 | - 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
| 57 | - 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
| 58 | - 'after_text' => array( // this is the input name='' |
|
| 59 | - 'title' => __( 'Text after hello:', 'ayecode-connect' ), |
|
| 60 | - // input title |
|
| 61 | - 'desc' => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ), |
|
| 62 | - // input description |
|
| 63 | - 'type' => 'text', |
|
| 64 | - // the type of input, test, select, checkbox etc. |
|
| 65 | - 'placeholder' => 'World', |
|
| 66 | - // the input placeholder text. |
|
| 67 | - 'desc_tip' => true, |
|
| 68 | - // if the input should show the widget description text as a tooltip. |
|
| 69 | - 'default' => 'World', |
|
| 70 | - // the input default value. |
|
| 71 | - 'advanced' => false |
|
| 72 | - // not yet implemented |
|
| 73 | - ), |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - |
|
| 77 | - parent::__construct( $options ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * This is the output function for the widget, shortcode and block (front end). |
|
| 83 | - * |
|
| 84 | - * @param array $args The arguments values. |
|
| 85 | - * @param array $widget_args The widget arguments when used. |
|
| 86 | - * @param string $content The shortcode content argument |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var string $after_text |
|
| 94 | - * @var string $another_input This is added by filter below. |
|
| 95 | - */ |
|
| 96 | - extract( $args, EXTR_SKIP ); |
|
| 97 | - |
|
| 98 | - /* |
|
| 37 | + ), |
|
| 38 | + 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + ), |
|
| 42 | + ), |
|
| 43 | + 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
| 44 | + 'class_name' => __CLASS__, |
|
| 45 | + // The calling class name |
|
| 46 | + 'base_id' => 'hello_world', |
|
| 47 | + // this is used as the widget id and the shortcode id. |
|
| 48 | + 'name' => __( 'Hello World', 'ayecode-connect' ), |
|
| 49 | + // the name of the widget/block |
|
| 50 | + 'widget_ops' => array( |
|
| 51 | + 'classname' => 'hello-world-class', |
|
| 52 | + // widget class |
|
| 53 | + 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
| 54 | + // widget description |
|
| 55 | + ), |
|
| 56 | + 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
| 57 | + 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
| 58 | + 'after_text' => array( // this is the input name='' |
|
| 59 | + 'title' => __( 'Text after hello:', 'ayecode-connect' ), |
|
| 60 | + // input title |
|
| 61 | + 'desc' => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ), |
|
| 62 | + // input description |
|
| 63 | + 'type' => 'text', |
|
| 64 | + // the type of input, test, select, checkbox etc. |
|
| 65 | + 'placeholder' => 'World', |
|
| 66 | + // the input placeholder text. |
|
| 67 | + 'desc_tip' => true, |
|
| 68 | + // if the input should show the widget description text as a tooltip. |
|
| 69 | + 'default' => 'World', |
|
| 70 | + // the input default value. |
|
| 71 | + 'advanced' => false |
|
| 72 | + // not yet implemented |
|
| 73 | + ), |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + |
|
| 77 | + parent::__construct( $options ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * This is the output function for the widget, shortcode and block (front end). |
|
| 83 | + * |
|
| 84 | + * @param array $args The arguments values. |
|
| 85 | + * @param array $widget_args The widget arguments when used. |
|
| 86 | + * @param string $content The shortcode content argument |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var string $after_text |
|
| 94 | + * @var string $another_input This is added by filter below. |
|
| 95 | + */ |
|
| 96 | + extract( $args, EXTR_SKIP ); |
|
| 97 | + |
|
| 98 | + /* |
|
| 99 | 99 | * This value is added by filter so might not exist if filter is removed so we check. |
| 100 | 100 | */ |
| 101 | - if ( ! isset( $another_input ) ) { |
|
| 102 | - $another_input = ''; |
|
| 103 | - } |
|
| 101 | + if ( ! isset( $another_input ) ) { |
|
| 102 | + $another_input = ''; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return "Helllo: " . $after_text . "" . $another_input; |
|
| 105 | + return "Helllo: " . $after_text . "" . $another_input; |
|
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // register it. |
| 112 | 112 | add_action( 'widgets_init', function () { |
| 113 | - register_widget( 'SD_Hello_World' ); |
|
| 113 | + register_widget( 'SD_Hello_World' ); |
|
| 114 | 114 | } ); |
| 115 | 115 | |
| 116 | 116 | |
@@ -123,26 +123,26 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | function _my_extra_arguments( $options ) { |
| 125 | 125 | |
| 126 | - /* |
|
| 126 | + /* |
|
| 127 | 127 | * Add a new input option. |
| 128 | 128 | */ |
| 129 | - $options['arguments']['another_input'] = array( |
|
| 130 | - 'name' => 'another_input', // this is the input name='' |
|
| 131 | - 'title' => __( 'Another input:', 'ayecode-connect' ), // input title |
|
| 132 | - 'desc' => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description |
|
| 133 | - 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
| 134 | - 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
| 135 | - 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
| 136 | - 'default' => '', // the input default value. |
|
| 137 | - 'advanced' => false // not yet implemented |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - /* |
|
| 129 | + $options['arguments']['another_input'] = array( |
|
| 130 | + 'name' => 'another_input', // this is the input name='' |
|
| 131 | + 'title' => __( 'Another input:', 'ayecode-connect' ), // input title |
|
| 132 | + 'desc' => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description |
|
| 133 | + 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
| 134 | + 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
| 135 | + 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
| 136 | + 'default' => '', // the input default value. |
|
| 137 | + 'advanced' => false // not yet implemented |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + /* |
|
| 141 | 141 | * Output the new option in the block output also. |
| 142 | 142 | */ |
| 143 | - $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
| 143 | + $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
| 144 | 144 | |
| 145 | - return $options; |
|
| 145 | + return $options; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' ); |
| 149 | 149 | \ No newline at end of file |
@@ -14,620 +14,620 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | - return $this->data[ $prop ]; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Define class properties. |
|
| 79 | - */ |
|
| 80 | - public function set_properties() { |
|
| 81 | - // Sessions. |
|
| 82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | - |
|
| 86 | - // Init other objects. |
|
| 87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | - $this->set( 'api', new WPInv_API() ); |
|
| 89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Define plugin constants. |
|
| 102 | - */ |
|
| 103 | - public function define_constants() { |
|
| 104 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 106 | - $this->version = WPINV_VERSION; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Hook into actions and filters. |
|
| 111 | - * |
|
| 112 | - * @since 1.0.19 |
|
| 113 | - */ |
|
| 114 | - protected function init_hooks() { |
|
| 115 | - /* Internationalize the text strings used. */ |
|
| 116 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | - |
|
| 118 | - // Init the plugin after WordPress inits. |
|
| 119 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | - |
|
| 131 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 134 | - |
|
| 135 | - // Fires after registering actions. |
|
| 136 | - do_action( 'wpinv_actions', $this ); |
|
| 137 | - do_action( 'getpaid_actions', $this ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function plugins_loaded() { |
|
| 141 | - /* Internationalize the text strings used. */ |
|
| 142 | - $this->load_textdomain(); |
|
| 143 | - |
|
| 144 | - do_action( 'wpinv_loaded' ); |
|
| 145 | - |
|
| 146 | - // Fix oxygen page builder conflict |
|
| 147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | - wpinv_oxygen_fix_conflict(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Load Localisation files. |
|
| 154 | - * |
|
| 155 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 156 | - * |
|
| 157 | - * Locales found in: |
|
| 158 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 159 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 160 | - * |
|
| 161 | - * @since 1.0.0 |
|
| 162 | - */ |
|
| 163 | - public function load_textdomain() { |
|
| 164 | - // Determines the current locale. |
|
| 165 | - if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | - $locale = determine_locale(); |
|
| 167 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | - $locale = get_user_locale(); |
|
| 169 | - } else { |
|
| 170 | - $locale = get_locale(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Filter the locale to use for translations. |
|
| 175 | - */ |
|
| 176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | - |
|
| 178 | - unload_textdomain( 'invoicing' ); |
|
| 179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Include required core files used in admin and on the frontend. |
|
| 185 | - */ |
|
| 186 | - public function includes() { |
|
| 187 | - // Start with the settings. |
|
| 188 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 189 | - |
|
| 190 | - // Packages/libraries. |
|
| 191 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 193 | - |
|
| 194 | - // Load functions. |
|
| 195 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 208 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 209 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 210 | - |
|
| 211 | - // Register autoloader. |
|
| 212 | - try { |
|
| 213 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | - } catch ( Exception $e ) { |
|
| 215 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 235 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 236 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 237 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 238 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 240 | - |
|
| 241 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | - GetPaid_Post_Types_Admin::init(); |
|
| 243 | - |
|
| 244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 250 | - // load the user class only on the users.php page |
|
| 251 | - global $pagenow; |
|
| 252 | - if ( $pagenow == 'users.php' ) { |
|
| 253 | - new WPInv_Admin_Users(); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Register cli commands |
|
| 258 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 260 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Class autoloader |
|
| 266 | - * |
|
| 267 | - * @param string $class_name The name of the class to load. |
|
| 268 | - * @access public |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function autoload( $class_name ) { |
|
| 273 | - // Normalize the class name... |
|
| 274 | - $class_name = strtolower( $class_name ); |
|
| 275 | - |
|
| 276 | - // ... and make sure it is our class. |
|
| 277 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | - return; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Next, prepare the file name from the class. |
|
| 282 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | - |
|
| 284 | - // Base path of the classes. |
|
| 285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | - |
|
| 287 | - // And an array of possible locations in order of importance. |
|
| 288 | - $locations = array( |
|
| 289 | - "$plugin_path/includes", |
|
| 290 | - "$plugin_path/includes/data-stores", |
|
| 291 | - "$plugin_path/includes/gateways", |
|
| 292 | - "$plugin_path/includes/payments", |
|
| 293 | - "$plugin_path/includes/geolocation", |
|
| 294 | - "$plugin_path/includes/reports", |
|
| 295 | - "$plugin_path/includes/api", |
|
| 296 | - "$plugin_path/includes/admin", |
|
| 297 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | - include trailingslashit( $location ) . $file_name; |
|
| 303 | - break; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Inits hooks etc. |
|
| 310 | - */ |
|
| 311 | - public function init() { |
|
| 312 | - // Fires before getpaid inits. |
|
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | - |
|
| 315 | - // Maybe upgrade. |
|
| 316 | - $this->maybe_upgrade_database(); |
|
| 317 | - |
|
| 318 | - // Load default gateways. |
|
| 319 | - $gateways = apply_filters( |
|
| 320 | - 'getpaid_default_gateways', |
|
| 321 | - array( |
|
| 322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | - GetPaid_Installer::rename_gateways_label(); |
|
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Fires after getpaid inits. |
|
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Checks if this is an IPN request and processes it. |
|
| 345 | - */ |
|
| 346 | - public function maybe_process_ipn() { |
|
| 347 | - // Ensure that this is an IPN request. |
|
| 348 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | - |
|
| 354 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | - exit; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - public function enqueue_scripts() { |
|
| 360 | - // Fires before adding scripts. |
|
| 361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | - |
|
| 363 | - $localize = array(); |
|
| 364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 366 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 367 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 369 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 374 | - |
|
| 375 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | - |
|
| 377 | - // reCaptcha. |
|
| 378 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - public function wpinv_actions() { |
|
| 388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Fires an action after verifying that a user can fire them. |
|
| 399 | - * |
|
| 400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | - * current user owns the invoice/subscription. |
|
| 402 | - */ |
|
| 403 | - public function maybe_do_authenticated_action() { |
|
| 404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 407 | - |
|
| 408 | - if ( is_user_logged_in() ) { |
|
| 409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - public function pre_get_posts( $wp_query ) { |
|
| 417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $wp_query; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Register widgets |
|
| 426 | - * |
|
| 427 | - */ |
|
| 428 | - public function register_widgets() { |
|
| 429 | - global $pagenow; |
|
| 430 | - |
|
| 431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | - return; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | - |
|
| 439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | - // don't initiate in these conditions. |
|
| 441 | - } else { |
|
| 442 | - // Only load allowed widgets. |
|
| 443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | - $widgets = apply_filters( |
|
| 445 | - 'getpaid_widget_classes', |
|
| 446 | - array( |
|
| 447 | - 'WPInv_Checkout_Widget', |
|
| 448 | - 'WPInv_History_Widget', |
|
| 449 | - 'WPInv_Receipt_Widget', |
|
| 450 | - 'WPInv_Subscriptions_Widget', |
|
| 451 | - 'WPInv_Buy_Item_Widget', |
|
| 452 | - 'WPInv_Messages_Widget', |
|
| 453 | - 'WPInv_GetPaid_Widget', |
|
| 454 | - 'WPInv_Invoice_Widget', |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - // For each widget... |
|
| 459 | - foreach ( $widgets as $widget ) { |
|
| 460 | - // Abort early if it is excluded for this page. |
|
| 461 | - if ( in_array( $widget, $exclude ) ) { |
|
| 462 | - continue; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | - register_widget( $widget ); |
|
| 468 | - } else { |
|
| 469 | - new $widget(); |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Upgrades the database. |
|
| 477 | - * |
|
| 478 | - * @since 2.0.2 |
|
| 479 | - */ |
|
| 480 | - public function maybe_upgrade_database() { |
|
| 481 | - // Ensure the database tables are up to date. |
|
| 482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | - |
|
| 484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | - |
|
| 486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $installer = new GetPaid_Installer(); |
|
| 491 | - |
|
| 492 | - if ( empty( $wpi_version ) ) { |
|
| 493 | - return $installer->upgrade_db( 0 ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - $upgrades = array( |
|
| 497 | - '0.0.5' => '004', |
|
| 498 | - '1.0.3' => '102', |
|
| 499 | - '2.0.0' => '118', |
|
| 500 | - '2.8.0' => '279', |
|
| 501 | - ); |
|
| 502 | - |
|
| 503 | - foreach ( $upgrades as $key => $method ) { |
|
| 504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | - return $installer->upgrade_db( $method ); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Flushes the permalinks if needed. |
|
| 512 | - * |
|
| 513 | - * @since 2.0.8 |
|
| 514 | - */ |
|
| 515 | - public function maybe_flush_permalinks() { |
|
| 516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | - |
|
| 518 | - if ( ! empty( $flush ) ) { |
|
| 519 | - flush_rewrite_rules(); |
|
| 520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Remove our pages from yoast sitemaps. |
|
| 526 | - * |
|
| 527 | - * @since 1.0.19 |
|
| 528 | - * @param int[] $excluded_posts_ids |
|
| 529 | - */ |
|
| 530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | - // Ensure that we have an array. |
|
| 532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | - $excluded_posts_ids = array(); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // Prepare our pages. |
|
| 537 | - $our_pages = array(); |
|
| 538 | - |
|
| 539 | - // Checkout page. |
|
| 540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | - |
|
| 542 | - // Success page. |
|
| 543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | - |
|
| 545 | - // Failure page. |
|
| 546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | - |
|
| 548 | - // History page. |
|
| 549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | - |
|
| 551 | - // Subscriptions page. |
|
| 552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | - |
|
| 554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | - |
|
| 556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | - |
|
| 558 | - return array_unique( $excluded_posts_ids ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Remove our pages from yoast sitemaps. |
|
| 563 | - * |
|
| 564 | - * @since 1.0.19 |
|
| 565 | - * @param string[] $post_types |
|
| 566 | - */ |
|
| 567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | - // Ensure that we have an array. |
|
| 569 | - if ( ! is_array( $post_types ) ) { |
|
| 570 | - $post_types = array(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Remove our post types. |
|
| 574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Displays additional footer code. |
|
| 579 | - * |
|
| 580 | - * @since 2.0.0 |
|
| 581 | - */ |
|
| 582 | - public function wp_footer() { |
|
| 583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Displays additional header code. |
|
| 588 | - * |
|
| 589 | - * @since 2.0.0 |
|
| 590 | - */ |
|
| 591 | - public function wp_head() { |
|
| 592 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Custom query vars. |
|
| 597 | - * |
|
| 598 | - */ |
|
| 599 | - public function custom_query_vars( $vars ) { |
|
| 600 | - $vars[] = 'getpaid-ipn'; |
|
| 601 | - return $vars; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Add rewrite tags and rules. |
|
| 606 | - * |
|
| 607 | - */ |
|
| 608 | - public function add_rewrite_rule() { |
|
| 609 | - $tag = 'getpaid-ipn'; |
|
| 610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Processes non-query string ipns. |
|
| 616 | - * |
|
| 617 | - */ |
|
| 618 | - public function maybe_process_new_ipn( $query ) { |
|
| 619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | - |
|
| 625 | - if ( ! empty( $gateway ) ) { |
|
| 626 | - $gateway = sanitize_text_field( $gateway ); |
|
| 627 | - nocache_headers(); |
|
| 628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | - exit; |
|
| 631 | - } |
|
| 632 | - } |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | + return $this->data[ $prop ]; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Define class properties. |
|
| 79 | + */ |
|
| 80 | + public function set_properties() { |
|
| 81 | + // Sessions. |
|
| 82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | + |
|
| 86 | + // Init other objects. |
|
| 87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | + $this->set( 'api', new WPInv_API() ); |
|
| 89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Define plugin constants. |
|
| 102 | + */ |
|
| 103 | + public function define_constants() { |
|
| 104 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 106 | + $this->version = WPINV_VERSION; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Hook into actions and filters. |
|
| 111 | + * |
|
| 112 | + * @since 1.0.19 |
|
| 113 | + */ |
|
| 114 | + protected function init_hooks() { |
|
| 115 | + /* Internationalize the text strings used. */ |
|
| 116 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | + |
|
| 118 | + // Init the plugin after WordPress inits. |
|
| 119 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | + |
|
| 131 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 134 | + |
|
| 135 | + // Fires after registering actions. |
|
| 136 | + do_action( 'wpinv_actions', $this ); |
|
| 137 | + do_action( 'getpaid_actions', $this ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function plugins_loaded() { |
|
| 141 | + /* Internationalize the text strings used. */ |
|
| 142 | + $this->load_textdomain(); |
|
| 143 | + |
|
| 144 | + do_action( 'wpinv_loaded' ); |
|
| 145 | + |
|
| 146 | + // Fix oxygen page builder conflict |
|
| 147 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | + wpinv_oxygen_fix_conflict(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Load Localisation files. |
|
| 154 | + * |
|
| 155 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 156 | + * |
|
| 157 | + * Locales found in: |
|
| 158 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 159 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 160 | + * |
|
| 161 | + * @since 1.0.0 |
|
| 162 | + */ |
|
| 163 | + public function load_textdomain() { |
|
| 164 | + // Determines the current locale. |
|
| 165 | + if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | + $locale = determine_locale(); |
|
| 167 | + } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | + $locale = get_user_locale(); |
|
| 169 | + } else { |
|
| 170 | + $locale = get_locale(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Filter the locale to use for translations. |
|
| 175 | + */ |
|
| 176 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | + |
|
| 178 | + unload_textdomain( 'invoicing' ); |
|
| 179 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Include required core files used in admin and on the frontend. |
|
| 185 | + */ |
|
| 186 | + public function includes() { |
|
| 187 | + // Start with the settings. |
|
| 188 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 189 | + |
|
| 190 | + // Packages/libraries. |
|
| 191 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 193 | + |
|
| 194 | + // Load functions. |
|
| 195 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 208 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 209 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 210 | + |
|
| 211 | + // Register autoloader. |
|
| 212 | + try { |
|
| 213 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | + } catch ( Exception $e ) { |
|
| 215 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 235 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 236 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 237 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 238 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 240 | + |
|
| 241 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | + GetPaid_Post_Types_Admin::init(); |
|
| 243 | + |
|
| 244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 250 | + // load the user class only on the users.php page |
|
| 251 | + global $pagenow; |
|
| 252 | + if ( $pagenow == 'users.php' ) { |
|
| 253 | + new WPInv_Admin_Users(); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Register cli commands |
|
| 258 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 260 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Class autoloader |
|
| 266 | + * |
|
| 267 | + * @param string $class_name The name of the class to load. |
|
| 268 | + * @access public |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function autoload( $class_name ) { |
|
| 273 | + // Normalize the class name... |
|
| 274 | + $class_name = strtolower( $class_name ); |
|
| 275 | + |
|
| 276 | + // ... and make sure it is our class. |
|
| 277 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Next, prepare the file name from the class. |
|
| 282 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | + |
|
| 284 | + // Base path of the classes. |
|
| 285 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | + |
|
| 287 | + // And an array of possible locations in order of importance. |
|
| 288 | + $locations = array( |
|
| 289 | + "$plugin_path/includes", |
|
| 290 | + "$plugin_path/includes/data-stores", |
|
| 291 | + "$plugin_path/includes/gateways", |
|
| 292 | + "$plugin_path/includes/payments", |
|
| 293 | + "$plugin_path/includes/geolocation", |
|
| 294 | + "$plugin_path/includes/reports", |
|
| 295 | + "$plugin_path/includes/api", |
|
| 296 | + "$plugin_path/includes/admin", |
|
| 297 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | + include trailingslashit( $location ) . $file_name; |
|
| 303 | + break; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Inits hooks etc. |
|
| 310 | + */ |
|
| 311 | + public function init() { |
|
| 312 | + // Fires before getpaid inits. |
|
| 313 | + do_action( 'before_getpaid_init', $this ); |
|
| 314 | + |
|
| 315 | + // Maybe upgrade. |
|
| 316 | + $this->maybe_upgrade_database(); |
|
| 317 | + |
|
| 318 | + // Load default gateways. |
|
| 319 | + $gateways = apply_filters( |
|
| 320 | + 'getpaid_default_gateways', |
|
| 321 | + array( |
|
| 322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + foreach ( $gateways as $id => $class ) { |
|
| 331 | + $this->gateways[ $id ] = new $class(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + GetPaid_Installer::rename_gateways_label(); |
|
| 336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Fires after getpaid inits. |
|
| 340 | + do_action( 'getpaid_init', $this ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Checks if this is an IPN request and processes it. |
|
| 345 | + */ |
|
| 346 | + public function maybe_process_ipn() { |
|
| 347 | + // Ensure that this is an IPN request. |
|
| 348 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | + |
|
| 354 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | + exit; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + public function enqueue_scripts() { |
|
| 360 | + // Fires before adding scripts. |
|
| 361 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | + |
|
| 363 | + $localize = array(); |
|
| 364 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 366 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 367 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 369 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 370 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 374 | + |
|
| 375 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | + |
|
| 377 | + // reCaptcha. |
|
| 378 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + public function wpinv_actions() { |
|
| 388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Fires an action after verifying that a user can fire them. |
|
| 399 | + * |
|
| 400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | + * current user owns the invoice/subscription. |
|
| 402 | + */ |
|
| 403 | + public function maybe_do_authenticated_action() { |
|
| 404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | + $data = wp_unslash( $_REQUEST ); |
|
| 407 | + |
|
| 408 | + if ( is_user_logged_in() ) { |
|
| 409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + public function pre_get_posts( $wp_query ) { |
|
| 417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $wp_query; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Register widgets |
|
| 426 | + * |
|
| 427 | + */ |
|
| 428 | + public function register_widgets() { |
|
| 429 | + global $pagenow; |
|
| 430 | + |
|
| 431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | + return; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | + |
|
| 439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | + // don't initiate in these conditions. |
|
| 441 | + } else { |
|
| 442 | + // Only load allowed widgets. |
|
| 443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | + $widgets = apply_filters( |
|
| 445 | + 'getpaid_widget_classes', |
|
| 446 | + array( |
|
| 447 | + 'WPInv_Checkout_Widget', |
|
| 448 | + 'WPInv_History_Widget', |
|
| 449 | + 'WPInv_Receipt_Widget', |
|
| 450 | + 'WPInv_Subscriptions_Widget', |
|
| 451 | + 'WPInv_Buy_Item_Widget', |
|
| 452 | + 'WPInv_Messages_Widget', |
|
| 453 | + 'WPInv_GetPaid_Widget', |
|
| 454 | + 'WPInv_Invoice_Widget', |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + // For each widget... |
|
| 459 | + foreach ( $widgets as $widget ) { |
|
| 460 | + // Abort early if it is excluded for this page. |
|
| 461 | + if ( in_array( $widget, $exclude ) ) { |
|
| 462 | + continue; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | + register_widget( $widget ); |
|
| 468 | + } else { |
|
| 469 | + new $widget(); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Upgrades the database. |
|
| 477 | + * |
|
| 478 | + * @since 2.0.2 |
|
| 479 | + */ |
|
| 480 | + public function maybe_upgrade_database() { |
|
| 481 | + // Ensure the database tables are up to date. |
|
| 482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | + |
|
| 484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | + |
|
| 486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $installer = new GetPaid_Installer(); |
|
| 491 | + |
|
| 492 | + if ( empty( $wpi_version ) ) { |
|
| 493 | + return $installer->upgrade_db( 0 ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + $upgrades = array( |
|
| 497 | + '0.0.5' => '004', |
|
| 498 | + '1.0.3' => '102', |
|
| 499 | + '2.0.0' => '118', |
|
| 500 | + '2.8.0' => '279', |
|
| 501 | + ); |
|
| 502 | + |
|
| 503 | + foreach ( $upgrades as $key => $method ) { |
|
| 504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | + return $installer->upgrade_db( $method ); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Flushes the permalinks if needed. |
|
| 512 | + * |
|
| 513 | + * @since 2.0.8 |
|
| 514 | + */ |
|
| 515 | + public function maybe_flush_permalinks() { |
|
| 516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | + |
|
| 518 | + if ( ! empty( $flush ) ) { |
|
| 519 | + flush_rewrite_rules(); |
|
| 520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Remove our pages from yoast sitemaps. |
|
| 526 | + * |
|
| 527 | + * @since 1.0.19 |
|
| 528 | + * @param int[] $excluded_posts_ids |
|
| 529 | + */ |
|
| 530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | + // Ensure that we have an array. |
|
| 532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | + $excluded_posts_ids = array(); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // Prepare our pages. |
|
| 537 | + $our_pages = array(); |
|
| 538 | + |
|
| 539 | + // Checkout page. |
|
| 540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | + |
|
| 542 | + // Success page. |
|
| 543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | + |
|
| 545 | + // Failure page. |
|
| 546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | + |
|
| 548 | + // History page. |
|
| 549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | + |
|
| 551 | + // Subscriptions page. |
|
| 552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | + |
|
| 554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | + |
|
| 556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | + |
|
| 558 | + return array_unique( $excluded_posts_ids ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Remove our pages from yoast sitemaps. |
|
| 563 | + * |
|
| 564 | + * @since 1.0.19 |
|
| 565 | + * @param string[] $post_types |
|
| 566 | + */ |
|
| 567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | + // Ensure that we have an array. |
|
| 569 | + if ( ! is_array( $post_types ) ) { |
|
| 570 | + $post_types = array(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Remove our post types. |
|
| 574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Displays additional footer code. |
|
| 579 | + * |
|
| 580 | + * @since 2.0.0 |
|
| 581 | + */ |
|
| 582 | + public function wp_footer() { |
|
| 583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Displays additional header code. |
|
| 588 | + * |
|
| 589 | + * @since 2.0.0 |
|
| 590 | + */ |
|
| 591 | + public function wp_head() { |
|
| 592 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Custom query vars. |
|
| 597 | + * |
|
| 598 | + */ |
|
| 599 | + public function custom_query_vars( $vars ) { |
|
| 600 | + $vars[] = 'getpaid-ipn'; |
|
| 601 | + return $vars; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Add rewrite tags and rules. |
|
| 606 | + * |
|
| 607 | + */ |
|
| 608 | + public function add_rewrite_rule() { |
|
| 609 | + $tag = 'getpaid-ipn'; |
|
| 610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Processes non-query string ipns. |
|
| 616 | + * |
|
| 617 | + */ |
|
| 618 | + public function maybe_process_new_ipn( $query ) { |
|
| 619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | + |
|
| 625 | + if ( ! empty( $gateway ) ) { |
|
| 626 | + $gateway = sanitize_text_field( $gateway ); |
|
| 627 | + nocache_headers(); |
|
| 628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | + exit; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | 633 | } |