CouponsPage
1 year ago
CustomersPage
5 months ago
DashboardPage
1 year ago
DownloadLogsPage
1 year ago
ExportPage
5 months ago
GroupsPage
1 year ago
OrdersPage
1 year ago
PlansPage
2 months ago
SubscriptionsPage
3 months ago
TaxSettings
3 years ago
views
1 month ago
CheckListHeader.php
3 years ago
CheckoutFieldsManager.php
1 year ago
ContextualStateChangeHelper.php
3 years ago
FileDownloads.php
3 years ago
PaymentMethods.php
1 year ago
PaymentSettings.php
1 month ago
PlanIntegrationsMetabox.php
10 months ago
SettingsFieldsParser.php
1 year ago
index.php
3 years ago
PlanIntegrationsMetabox.php
338 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\Membership; |
| 4 | |
| 5 | |
| 6 | class PlanIntegrationsMetabox |
| 7 | { |
| 8 | protected $args; |
| 9 | protected $saved_values; |
| 10 | protected $plan_id; |
| 11 | |
| 12 | /** |
| 13 | * @param array $args |
| 14 | */ |
| 15 | public function __construct($args, $saved_values) |
| 16 | { |
| 17 | $this->args = $args; |
| 18 | $this->saved_values = $saved_values; |
| 19 | } |
| 20 | |
| 21 | private function saved_values_bucket($key) |
| 22 | { |
| 23 | return isset($this->saved_values[$key]) ? $this->saved_values[$key] : ''; |
| 24 | } |
| 25 | |
| 26 | public function text($name, $options) |
| 27 | { |
| 28 | $placeholder = isset($options['placeholder']) ? $options['placeholder'] : ''; |
| 29 | printf( |
| 30 | '<input type="text" class="short" name="%1$s" id="%1$s" value="%3$s" placeholder="%2$s">', |
| 31 | esc_attr($name), esc_attr($placeholder), esc_attr($this->saved_values_bucket($name)) |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | public function number($name, $options) |
| 36 | { |
| 37 | $placeholder = isset($options['placeholder']) ? $options['placeholder'] : ''; |
| 38 | printf( |
| 39 | '<input type="number" class="short" name="%1$s" id="%1$s" value="%3$s" placeholder="%2$s">', |
| 40 | esc_attr($name), esc_attr($placeholder), esc_attr($this->saved_values_bucket($name)) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | public function upload($name, $options) |
| 45 | { |
| 46 | $placeholder = isset($options['placeholder']) ? $options['placeholder'] : ''; |
| 47 | echo '<div class="pp_upload_field_container">'; |
| 48 | printf( |
| 49 | '<input type="text" class="pp_upload_field short large-text" name="%1$s" id="%1$s" value="%3$s" placeholder="%2$s">', |
| 50 | esc_attr($name), esc_attr($placeholder), esc_attr($this->saved_values_bucket($name)) |
| 51 | ); |
| 52 | printf('<span class="pp_upload_file"><a href="#" class="pp_upload_button">%s</a></span>', esc_html__('Upload Image', 'wp-user-avatar')); |
| 53 | echo '</div>'; |
| 54 | } |
| 55 | |
| 56 | private function digital_files_row($name, $file_name = '', $file_url = '') |
| 57 | { |
| 58 | ?> |
| 59 | <tr> |
| 60 | <td class="sort"></td> |
| 61 | <td class="file_name"> |
| 62 | <input type="text" class="input_text" placeholder="<?php esc_html_e('File name', 'wp-user-avatar') ?>" name="<?= esc_attr($name) ?>_names[]" value="<?= esc_attr($file_name) ?>"> |
| 63 | </td> |
| 64 | <td class="file_url"> |
| 65 | <input type="text" class="input_text" placeholder="https://" name="<?= esc_attr($name) ?>_urls[]" value="<?= esc_url($file_url) ?>"> |
| 66 | </td> |
| 67 | <td class="file_url_choose"> |
| 68 | <a href="#" class="button upload_file_button" data-choose="<?php esc_html_e('Choose file', 'wp-user-avatar') ?>" data-update="<?php esc_html_e('Insert file URL', 'wp-user-avatar') ?>"><?php esc_html_e('Choose file', 'wp-user-avatar') ?></a> |
| 69 | </td> |
| 70 | <td><a href="#" class="delete">x</a></td> |
| 71 | </tr> |
| 72 | <?php |
| 73 | } |
| 74 | |
| 75 | public function digital_files($name, $options) |
| 76 | { |
| 77 | $url_field_id = sprintf('%s_urls', $name); |
| 78 | $name_field_id = sprintf('%s_names', $name); |
| 79 | ?> |
| 80 | <table class="widefat downloadable_files"> |
| 81 | <thead> |
| 82 | <tr> |
| 83 | <th class="sort"> </th> |
| 84 | <th><?php esc_html_e('Name', 'wp-user-avatar') ?></th> |
| 85 | <th colspan="2"><?php esc_html_e('File URL', 'wp-user-avatar') ?></span></th> |
| 86 | <th style="width:20px;"> </th> |
| 87 | </tr> |
| 88 | </thead> |
| 89 | <tbody> |
| 90 | <?php if (isset($this->saved_values[$url_field_id]) && is_array($this->saved_values[$url_field_id]) && ! empty($this->saved_values[$url_field_id])) : ?> |
| 91 | <?php foreach ($this->saved_values[$url_field_id] as $index => $file_url) : ?> |
| 92 | <?php $file_name = isset($this->saved_values[$name_field_id]) && is_array($this->saved_values[$name_field_id]) ? $this->saved_values[$name_field_id][$index] : ''; ?> |
| 93 | <?php $this->digital_files_row($name, $file_name, $file_url); ?> |
| 94 | <?php endforeach; ?> |
| 95 | <?php else : ?> |
| 96 | <?php $this->digital_files_row($name); ?> |
| 97 | <?php endif; ?> |
| 98 | </tbody> |
| 99 | <tfoot> |
| 100 | <tr> |
| 101 | <th colspan="2"> |
| 102 | <a href="#" class="button insert"><?php esc_html_e('Add File', 'wp-user-avatar') ?></a> |
| 103 | </th> |
| 104 | <th colspan="3"> |
| 105 | </th> |
| 106 | </tr> |
| 107 | </tfoot> |
| 108 | </table> |
| 109 | |
| 110 | <script type="text/html" id="tmpl-ppress-add-digital-file"> |
| 111 | <?php $this->digital_files_row($name); ?> |
| 112 | </script> |
| 113 | <?php |
| 114 | } |
| 115 | |
| 116 | public function textarea($name, $options) |
| 117 | { |
| 118 | $placeholder = $options['placeholder'] ?? ''; |
| 119 | printf( |
| 120 | '<textarea class="short" name="%1$s" id="%1$s" placeholder="%2$s">%3$s</textarea>', |
| 121 | esc_attr($name), esc_attr($placeholder), esc_textarea($this->saved_values_bucket($name)) |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | public function checkbox($name, $options) |
| 126 | { |
| 127 | $checkbox_label = $options['checkbox_label'] ?? ''; |
| 128 | |
| 129 | printf('<input type="hidden" style="display: none" name="%1$s" value="false">', esc_attr($name)); |
| 130 | |
| 131 | printf( |
| 132 | '<input type="checkbox" class="checkbox" name="%1$s" id="%1$s" value="true" %2$s>', |
| 133 | esc_attr($name), checked('true', $this->saved_values_bucket($name), false) |
| 134 | ); |
| 135 | |
| 136 | printf('<span class="description">%s</span>', $checkbox_label); |
| 137 | } |
| 138 | |
| 139 | public function select($name, $options) |
| 140 | { |
| 141 | printf('<select id="%1$s" name="%1$s" class="select short">', esc_attr($name)); |
| 142 | |
| 143 | if ( |
| 144 | isset($options['options']) && |
| 145 | ($options['options'] instanceof \Generator || (is_array($options['options']) && ! empty($options['options']))) |
| 146 | ) { |
| 147 | foreach ($options['options'] as $id => $val) { |
| 148 | if (is_array($val)) { |
| 149 | echo "<optgroup label='$id'>"; |
| 150 | foreach ($val as $id2 => $val2) { |
| 151 | printf('<option value="%1$s" %3$s>%2$s</option>', $id2, $val2, selected($id2, $this->saved_values_bucket($name), false)); |
| 152 | } |
| 153 | echo "</optgroup>"; |
| 154 | } else { |
| 155 | printf('<option value="%1$s" %3$s>%2$s</option>', $id, $val, selected($id, $this->saved_values_bucket($name), false)); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | echo '</select>'; |
| 161 | } |
| 162 | |
| 163 | public function custom($name, $options) |
| 164 | { |
| 165 | echo isset($options['content']) ? wp_kses_post($options['content']) : ''; |
| 166 | } |
| 167 | |
| 168 | private function select2_selected($id, $name) |
| 169 | { |
| 170 | $bucket = $this->saved_values_bucket($name); |
| 171 | |
| 172 | return in_array($id, is_array($bucket) ? $bucket : []) ? 'selected="selected"' : ''; |
| 173 | } |
| 174 | |
| 175 | public function select2($name, $options) |
| 176 | { |
| 177 | printf('<input name="%1$s[]" type="hidden" value="">', esc_attr($name)); |
| 178 | printf('<select data-placeholder="%2$s" id="%1$s" name="%1$s[]" class="select ppselect2 short" multiple>', esc_attr($name), esc_html__('Select...', 'wp-user-avatar')); |
| 179 | |
| 180 | if ( |
| 181 | isset($options['options']) && |
| 182 | ($options['options'] instanceof \Generator || (is_array($options['options']) && ! empty($options['options']))) |
| 183 | ) { |
| 184 | foreach ($options['options'] as $id => $val) { |
| 185 | if (is_array($val)) { |
| 186 | echo "<optgroup label='$id'>"; |
| 187 | foreach ($val as $id2 => $val2) { |
| 188 | printf('<option value="%1$s" %3$s>%2$s</option>', $id2, $val2, $this->select2_selected($id2, $name)); |
| 189 | } |
| 190 | echo "</optgroup>"; |
| 191 | } else { |
| 192 | printf('<option value="%1$s" %3$s>%2$s</option>', $id, $val, $this->select2_selected($id, $name)); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | echo '</select>'; |
| 198 | } |
| 199 | |
| 200 | public function build() |
| 201 | { |
| 202 | $tabs = []; |
| 203 | $tab_settings = []; |
| 204 | foreach ($this->args as $key => $value) { |
| 205 | $tabs[$key] = $value['tab_title']; |
| 206 | unset($value['tab_title']); |
| 207 | $tab_settings[$key] = wp_list_sort($value, ['priority' => 'ASC']); |
| 208 | } |
| 209 | ob_start(); |
| 210 | ?> |
| 211 | <style> |
| 212 | #pp-form-builder-metabox .ppress-plan-integrations ul.pp-tabs li a::before { |
| 213 | font-family: none; |
| 214 | content: none; |
| 215 | } |
| 216 | |
| 217 | #pp-form-builder-metabox .pp-form-builder_options_panel label { |
| 218 | width: 140px; |
| 219 | } |
| 220 | |
| 221 | .ppview .postbox#pp-form-builder-metabox input:not([type=checkbox]) { |
| 222 | width: 100% !important; |
| 223 | max-width: 100% !important; |
| 224 | } |
| 225 | |
| 226 | .ppview .postbox#pp-form-builder-metabox .downloadable_files input { |
| 227 | width: auto !important; |
| 228 | max-width: none !important; |
| 229 | } |
| 230 | |
| 231 | .pp-form-builder_options_panel fieldset.form-field, .pp-form-builder_options_panel .form-field { |
| 232 | padding-right: 0 !important; |
| 233 | } |
| 234 | |
| 235 | .pp-form-builder_options_panel .pp-field-row-content { |
| 236 | width: 98% !important; |
| 237 | } |
| 238 | |
| 239 | .ppview .postbox#pp-form-builder-metabox .widefat th, |
| 240 | .ppview .postbox#pp-form-builder-metabox .widefat td { |
| 241 | padding-right: 0; |
| 242 | padding-left: 5px; |
| 243 | } |
| 244 | |
| 245 | .ppview .postbox#pp-form-builder-metabox .widefat td input { |
| 246 | width: 100% !important; |
| 247 | } |
| 248 | |
| 249 | .ppview .postbox#pp-form-builder-metabox .widefat th.sort { |
| 250 | width: 15px; |
| 251 | padding: 5px !important; |
| 252 | } |
| 253 | |
| 254 | .ppview .postbox#pp-form-builder-metabox .widefat td.sort { |
| 255 | width: 17px; |
| 256 | cursor: move; |
| 257 | font-size: 15px; |
| 258 | text-align: center; |
| 259 | background: #f9f9f9; |
| 260 | padding-right: 7px !important; |
| 261 | } |
| 262 | |
| 263 | .ppview .postbox#pp-form-builder-metabox .widefat td.sort::before { |
| 264 | content: "\f333"; |
| 265 | font-family: Dashicons; |
| 266 | text-align: center; |
| 267 | line-height: 1; |
| 268 | color: #999; |
| 269 | display: block; |
| 270 | width: 17px; |
| 271 | float: left; |
| 272 | height: 100%; |
| 273 | } |
| 274 | |
| 275 | .ppress-plan-integrations .pp-field-row-content .delete { |
| 276 | display: block; |
| 277 | text-indent: -9999px; |
| 278 | position: relative; |
| 279 | height: 1em; |
| 280 | width: 1em; |
| 281 | font-size: 1.2em; |
| 282 | } |
| 283 | |
| 284 | .ppress-plan-integrations .pp-field-row-content .delete::before { |
| 285 | font-family: Dashicons; |
| 286 | speak: never; |
| 287 | font-weight: 400; |
| 288 | font-variant: normal; |
| 289 | text-transform: none; |
| 290 | line-height: 1; |
| 291 | -webkit-font-smoothing: antialiased; |
| 292 | margin: 0; |
| 293 | text-indent: 0; |
| 294 | position: absolute; |
| 295 | top: 5px; |
| 296 | left: 0; |
| 297 | width: 100%; |
| 298 | height: 100%; |
| 299 | text-align: center; |
| 300 | content: "\f153"; |
| 301 | color: #999; |
| 302 | } |
| 303 | |
| 304 | </style> |
| 305 | <?php echo ppress_minify_css(ob_get_clean()); ?> |
| 306 | <div class="panel-wrap pp-form-builder-mb-data"> |
| 307 | <ul class="pp-form-builder-mb-data_tabs pp-tabs" style="width:22%"> |
| 308 | <?php foreach ($tabs as $key => $value) : $key = esc_attr($key); ?> |
| 309 | <?php if (empty($tab_settings[$key])) continue; ?> |
| 310 | <li class="<?= $key ?>_options <?= $key ?>_tab"> |
| 311 | <a href="#<?= $key ?>_data"><span><?= $value ?></span></a> |
| 312 | </li> |
| 313 | <?php endforeach; ?> |
| 314 | </ul> |
| 315 | |
| 316 | <?php foreach ($tab_settings as $key => $fields) { |
| 317 | echo '<div id="' . esc_attr($key) . '_data" class="panel pp-form-builder_options_panel hidden" style="width: 78%">'; |
| 318 | |
| 319 | foreach ($fields as $options) { |
| 320 | $field_id = $options['id'] ?? ''; |
| 321 | |
| 322 | echo sprintf('<div class="form-field %s_wrap">', $field_id); |
| 323 | echo "<label for=\"$field_id\">" . wp_kses_post($options['label'] ?? '') . '</label>'; |
| 324 | echo '<div class="pp-field-row-content">'; |
| 325 | $this->{$options['type']}($field_id, $options); |
| 326 | echo '</div>'; |
| 327 | if ( ! empty($options['description'])) { |
| 328 | printf('<p class="description">%s</p>', wp_kses_post($options['description'])); |
| 329 | } |
| 330 | echo '</div>'; |
| 331 | } |
| 332 | echo '</div>'; |
| 333 | } |
| 334 | ?> |
| 335 | </div> |
| 336 | <?php |
| 337 | } |
| 338 | } |