| @@ -47,12 +47,20 @@ | ||
| 47 | 47 | * HTML for popup items to select. |
| 48 | 48 | * |
| 49 | 49 | * @param array $tabs [ [ key => label ] ]. |
| 50 | 50 | * @param string $html_items |
| 51 | - * | |
| 51 | + * @param string $html_filter_fields @since LP v4.4.6 | |
| 52 | + * @param array $extra_data @since LP v4.4.6 { 'classes' => '' } | |
| 52 | 53 | * @return string |
| 54 | + * @since 4.2.8.7.1 | |
| 55 | + * @version 1.0.1 | |
| 53 | 56 | */ |
| 54 | - public static function html_popup_items_to_select_clone( array $tabs, string $html_items ): string { | |
| 57 | + public static function html_popup_items_to_select_clone( | |
| 58 | + array $tabs, | |
| 59 | + string $html_items, | |
| 60 | + string $html_filter_fields = '', | |
| 61 | + array $extra_data = [] | |
| 62 | + ): string { | |
| 55 | 63 | $html_tabs = ''; |
| 56 | 64 | $i = 0; |
| 57 | 65 | foreach ( $tabs as $key => $label ) { |
| 58 | 66 | $tab_active = ''; |
| @@ -81,9 +89,9 @@ | ||
| 81 | 89 | |
| 82 | 90 | $section_main = [ |
| 83 | 91 | 'wrap' => '<div class="main">', |
| 84 | 92 | 'wrap_items' => '<div class="list-items-wrap">', |
| 85 | - 'search' => sprintf( | |
| 93 | + 'search' => ! empty( $html_filter_fields ) ? $html_filter_fields : sprintf( | |
| 86 | 94 | '<input class="%1$s" name="%1$s" type="text" placeholder="%2$s">', |
| 87 | 95 | 'lp-search-title-item', |
| 88 | 96 | __( 'Type here to search for an item', 'learnpress' ) |
| 89 | 97 | ), |
| @@ -101,10 +109,13 @@ | ||
| 101 | 109 | |
| 102 | 110 | $section_footer = [ |
| 103 | 111 | 'wrap' => '<div class="footer">', |
| 104 | 112 | 'btn-add' => sprintf( |
| 105 | - '<button type="button" disabled="disabled" class="button lp-btn-add-items-selected lp-btn-edit-primary">%s</button>', | |
| 106 | - __( 'Add', 'learnpress' ) | |
| 113 | + '<button type="button" disabled="disabled" | |
| 114 | + class="button lp-btn-add-items-selected lp-btn-edit-primary %s" %s>%s</button>', | |
| 115 | + esc_attr( $extra_data['btn-add-classes'] ?? '' ), | |
| 116 | + $extra_data['btn-add-attrs'] ?? '', // No esc_attr here | |
| 117 | + $extra_data['btn-add-label'] ?? __( 'Add', 'learnpress' ) | |
| 107 | 118 | ), |
| 108 | 119 | 'count-items-selected' => sprintf( |
| 109 | 120 | '<button type="button" disabled="disabled" class="button lp-btn-count-items-selected">%s %s</button>', |
| 110 | 121 | sprintf( __( 'Selected items', 'learnpress' ), 0 ), |
| @@ -113,13 +124,17 @@ | ||
| 113 | 124 | 'btn-back' => sprintf( |
| 114 | 125 | '<button type="button" class="button lp-btn-back-to-select-items lp-hidden">%s</button>', |
| 115 | 126 | __( 'Back', 'learnpress' ) |
| 116 | 127 | ), |
| 128 | + 'btn-custom' => $extra_data['btn-custom'] ?? '', | |
| 117 | 129 | 'wrap_end' => '</div>', |
| 118 | 130 | ]; |
| 119 | 131 | |
| 120 | 132 | $section = [ |
| 121 | - 'wrap' => '<div class="lp-popup-items-to-select">', | |
| 133 | + 'wrap' => sprintf( | |
| 134 | + '<div class="lp-popup-items-to-select %s">', | |
| 135 | + esc_attr( $extra_data['classes'] ?? '' ) | |
| 136 | + ), | |
| 122 | 137 | 'header' => Template::combine_components( $section_header ), |
| 123 | 138 | 'main' => Template::combine_components( $section_main ), |
| 124 | 139 | 'footer' => Template::combine_components( $section_footer ), |
| 125 | 140 | 'wrap_end' => '</div>', |
| @@ -140,9 +155,9 @@ | ||
| 140 | 155 | * } |
| 141 | 156 | * |
| 142 | 157 | * @return string |
| 143 | 158 | * @since 4.3.0 |
| 144 | - * @version 1.0.0 | |
| 159 | + * @version 1.0.1 | |
| 145 | 160 | */ |
| 146 | 161 | public static function html_tom_select( array $args = [] ): string { |
| 147 | 162 | $html_options = ''; |
| 148 | 163 | |
| @@ -151,8 +166,10 @@ | ||
| 151 | 166 | $class_name = $args['class_name'] ?? ''; |
| 152 | 167 | $default_value = $args['default_value'] ?? ''; |
| 153 | 168 | $multiple = $args['multiple'] ?? false; |
| 154 | 169 | $multiple = $multiple ? 'multiple' : ''; |
| 170 | + $struct = $args['struct'] ?? []; | |
| 171 | + $saved = $args['saved'] ?? ''; | |
| 155 | 172 | foreach ( $options as $key => $value ) { |
| 156 | 173 | if ( is_array( $default_value ) ) { |
| 157 | 174 | $selected = in_array( $key, $default_value, true ) ? 'selected' : ''; |
| 158 | 175 | } else { |
| @@ -163,12 +180,14 @@ | ||
| 163 | 180 | } |
| 164 | 181 | |
| 165 | 182 | $section = [ |
| 166 | 183 | 'select' => sprintf( |
| 167 | - '<select name="%s" class="%s lp-tom-select" %s>', | |
| 184 | + '<select name="%s" class="%s lp-tom-select" %s data-struct="%s" data-save="%s">', | |
| 168 | 185 | esc_attr( $name ), |
| 169 | 186 | esc_attr( $class_name ), |
| 170 | - $multiple | |
| 187 | + esc_attr( $multiple ), | |
| 188 | + esc_attr( htmlentities2( json_encode( $struct ) ) ), | |
| 189 | + esc_attr( htmlentities2( json_encode( $saved ) ) ), | |
| 171 | 190 | ), |
| 172 | 191 | 'options' => $html_options, |
| 173 | 192 | 'select-end' => '</select>', |
| 174 | 193 | ]; |
| @@ -226,9 +245,9 @@ | ||
| 226 | 245 | * @since 4.4.5 |
| 227 | 246 | * @version 1.0.0 |
| 228 | 247 | */ |
| 229 | 248 | public static function html_form_filter( array $data = [] ): string { |
| 230 | - $classes = $data['classes'] ?? ''; | |
| 249 | + $form_classes = $data['form_classes'] ?? ''; | |
| 231 | 250 | $id = $data['id'] ?? ''; |
| 232 | 251 | $html_fields = $data['fields'] ?? ''; |
| 233 | 252 | $html_btn_actions = $data['btn_actions'] ?? ''; |
| 234 | 253 | |
| @@ -234,9 +253,9 @@ | ||
| 234 | 253 | |
| 235 | 254 | $sections = array( |
| 236 | 255 | 'wrap' => sprintf( |
| 237 | 256 | '<form class="lp-form-filter %s"%s>', |
| 238 | - esc_attr( $classes ), | |
| 257 | + esc_attr( $form_classes ), | |
| 239 | 258 | $id ? sprintf( ' id="%s"', esc_attr( $id ) ) : '' |
| 240 | 259 | ), |
| 241 | 260 | 'fields' => sprintf( |
| 242 | 261 | '<div class="lp-form-filter__fields">%s</div>', |