|
| 1 | +<?php |
| 2 | +if (!defined('ABSPATH')) { |
| 3 | + exit; |
| 4 | +} |
| 5 | + |
| 6 | +/** |
| 7 | + * Integrations settings page |
| 8 | + * |
| 9 | + * @package RM_PagBank/Admin/Settings |
| 10 | + */ |
| 11 | + |
| 12 | +// Enqueue integrations CSS |
| 13 | +wp_enqueue_style( |
| 14 | + 'pagbank-connect-integrations', |
| 15 | + plugins_url('public/css/integrations.css', WC_PAGSEGURO_CONNECT_PLUGIN_FILE), |
| 16 | + [], |
| 17 | + WC_PAGSEGURO_CONNECT_VERSION |
| 18 | +); |
| 19 | + |
| 20 | +// Load integrations settings fields |
| 21 | +$integrations_fields = include WC_PAGSEGURO_CONNECT_BASE_DIR.'/admin/views/settings/dokan-split-fields.php'; |
| 22 | + |
| 23 | +// Get saved options |
| 24 | +$integrations_options = get_option('woocommerce_rm-pagbank-integrations_settings', []); |
| 25 | + |
| 26 | +// Check if Dokan is active |
| 27 | +$dokan_is_active = function_exists('dokan'); |
| 28 | + |
| 29 | +// Display the settings form |
| 30 | +?> |
| 31 | +<input type="hidden" name="section" value="rm-pagbank-integrations" /> |
| 32 | +<?php if (!$dokan_is_active): ?> |
| 33 | + <div class="notice notice-warning inline" style="margin: 20px 0;"> |
| 34 | + <p> |
| 35 | + <strong><?php esc_html_e('Atenção:', 'pagbank-connect'); ?></strong> |
| 36 | + <?php esc_html_e('O plugin Dokan não está instalado ou não está ativo. As configurações de Split Dokan serão ignoradas até que o Dokan seja instalado e ativado.', 'pagbank-connect'); ?> |
| 37 | + </p> |
| 38 | + </div> |
| 39 | +<?php endif; ?> |
| 40 | +<table class="form-table"> |
| 41 | + <?php |
| 42 | + foreach ($integrations_fields as $key => $field) { |
| 43 | + // Use field ID if available, otherwise use key |
| 44 | + if (!isset($field['id'])) { |
| 45 | + $field['id'] = $key; |
| 46 | + } |
| 47 | + $field_id = $field['id']; // Use the field ID for HTML attributes |
| 48 | + $field_value = isset($integrations_options[$key]) ? $integrations_options[$key] : (isset($field['default']) ? $field['default'] : ''); |
| 49 | + |
| 50 | + switch ($field['type']) { |
| 51 | + case 'title': |
| 52 | + ?> |
| 53 | + <tr> |
| 54 | + <td colspan="2"> |
| 55 | + <h2><?php echo esc_html($field['title']); ?></h2> |
| 56 | + <?php if (!empty($field['desc'])): ?> |
| 57 | + <p><?php echo wp_kses_post($field['desc']); ?></p> |
| 58 | + <?php endif; ?> |
| 59 | + </td> |
| 60 | + </tr> |
| 61 | + <?php |
| 62 | + break; |
| 63 | + |
| 64 | + case 'checkbox': |
| 65 | + ?> |
| 66 | + <tr valign="top" <?php echo !$dokan_is_active ? 'style="opacity: 0.6;"' : ''; ?>> |
| 67 | + <th scope="row" class="titledesc"> |
| 68 | + <label for="<?php echo esc_attr($field_id); ?>"><?php echo esc_html($field['title']); ?></label> |
| 69 | + </th> |
| 70 | + <td class="forminp forminp-<?php echo esc_attr($field['type']); ?>"> |
| 71 | + <fieldset> |
| 72 | + <legend class="screen-reader-text"><span><?php echo esc_html($field['title']); ?></span></legend> |
| 73 | + <label for="<?php echo esc_attr($field_id); ?>"> |
| 74 | + <input |
| 75 | + type="checkbox" |
| 76 | + class="<?php echo esc_attr(isset($field['class']) ? $field['class'] : ''); ?>" |
| 77 | + name="<?php echo esc_attr($key); ?>" |
| 78 | + id="<?php echo esc_attr($field_id); ?>" |
| 79 | + value="1" |
| 80 | + <?php checked($field_value, 'yes'); ?> |
| 81 | + <?php disabled(!$dokan_is_active); ?> |
| 82 | + /> |
| 83 | + <?php echo wp_kses_post(isset($field['description']) ? $field['description'] : ''); ?> |
| 84 | + <?php if (!$dokan_is_active && $key === 'dokan_split_enabled'): ?> |
| 85 | + <p class="description" style="color: #d63638; margin-top: 5px;"> |
| 86 | + <strong><?php esc_html_e('⚠', 'pagbank-connect'); ?></strong> |
| 87 | + <?php esc_html_e('Esta configuração será ignorada porque o Dokan não está ativo ou instalado.', 'pagbank-connect'); ?> |
| 88 | + </p> |
| 89 | + <?php endif; ?> |
| 90 | + </label> |
| 91 | + </fieldset> |
| 92 | + </td> |
| 93 | + </tr> |
| 94 | + <?php |
| 95 | + break; |
| 96 | + |
| 97 | + case 'text': |
| 98 | + case 'number': |
| 99 | + ?> |
| 100 | + <tr valign="top" <?php echo !$dokan_is_active ? 'style="opacity: 0.6;"' : ''; ?>> |
| 101 | + <th scope="row" class="titledesc"> |
| 102 | + <label for="<?php echo esc_attr($field_id); ?>"><?php echo esc_html($field['title']); ?></label> |
| 103 | + </th> |
| 104 | + <td class="forminp forminp-<?php echo esc_attr($field['type']); ?>"> |
| 105 | + <input |
| 106 | + type="<?php echo esc_attr($field['type']); ?>" |
| 107 | + name="<?php echo esc_attr($key); ?>" |
| 108 | + id="<?php echo esc_attr($field_id); ?>" |
| 109 | + value="<?php echo esc_attr($field_value); ?>" |
| 110 | + class="<?php echo esc_attr(isset($field['class']) ? $field['class'] : ''); ?>" |
| 111 | + <?php disabled(!$dokan_is_active); ?> |
| 112 | + <?php if (isset($field['custom_attributes']) && is_array($field['custom_attributes'])) { |
| 113 | + foreach ($field['custom_attributes'] as $attr => $attr_value) { |
| 114 | + echo esc_attr($attr) . '="' . esc_attr($attr_value) . '" '; |
| 115 | + } |
| 116 | + } ?> |
| 117 | + /> |
| 118 | + <?php if (!empty($field['description'])): ?> |
| 119 | + <p class="description"><?php echo wp_kses_post($field['description']); ?></p> |
| 120 | + <?php endif; ?> |
| 121 | + </td> |
| 122 | + </tr> |
| 123 | + <?php |
| 124 | + break; |
| 125 | + |
| 126 | + case 'select': |
| 127 | + ?> |
| 128 | + <tr valign="top" <?php echo !$dokan_is_active ? 'style="opacity: 0.6;"' : ''; ?>> |
| 129 | + <th scope="row" class="titledesc"> |
| 130 | + <label for="<?php echo esc_attr($field_id); ?>"><?php echo esc_html($field['title']); ?></label> |
| 131 | + </th> |
| 132 | + <td class="forminp forminp-<?php echo esc_attr($field['type']); ?>"> |
| 133 | + <select |
| 134 | + name="<?php echo esc_attr($key); ?>" |
| 135 | + id="<?php echo esc_attr($field_id); ?>" |
| 136 | + class="<?php echo esc_attr(isset($field['class']) ? $field['class'] : ''); ?>" |
| 137 | + <?php disabled(!$dokan_is_active); ?> |
| 138 | + > |
| 139 | + <?php foreach ($field['options'] as $option_key => $option_value): ?> |
| 140 | + <option value="<?php echo esc_attr($option_key); ?>" <?php selected($field_value, $option_key); ?>> |
| 141 | + <?php echo esc_html($option_value); ?> |
| 142 | + </option> |
| 143 | + <?php endforeach; ?> |
| 144 | + </select> |
| 145 | + <?php if (!empty($field['description'])): ?> |
| 146 | + <p class="description"><?php echo wp_kses_post($field['description']); ?></p> |
| 147 | + <?php endif; ?> |
| 148 | + </td> |
| 149 | + </tr> |
| 150 | + <?php |
| 151 | + break; |
| 152 | + } |
| 153 | + } |
| 154 | + ?> |
| 155 | + </table> |
0 commit comments