main.php
290 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | |
| 4 | $settings = $this->getSetting(); |
| 5 | |
| 6 | // Tab persistence via URL: ?tab=advanced. Falls back to General. |
| 7 | $requested_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : ''; |
| 8 | $active_tab = $requested_tab; // validated against $tabs after the array is built below. |
| 9 | |
| 10 | $tabs = [ |
| 11 | 'general' => [ |
| 12 | 'label' => __( 'General', 'email-encoder-bundle' ), |
| 13 | 'icon' => 'dashicons-shield', |
| 14 | 'description' => __( 'Configure how email addresses are protected on your site.', 'email-encoder-bundle' ), |
| 15 | 'settings' => [ 'protect', 'protect_using' ], |
| 16 | ], |
| 17 | 'filters' => [ |
| 18 | 'label' => __( 'Filters', 'email-encoder-bundle' ), |
| 19 | 'icon' => 'dashicons-filter', |
| 20 | 'description' => __( 'Choose what content types and contexts to apply protection to.', 'email-encoder-bundle' ), |
| 21 | 'settings' => [ 'filter_body' ], |
| 22 | ], |
| 23 | 'images' => [ |
| 24 | 'label' => __( 'Images', 'email-encoder-bundle' ), |
| 25 | 'icon' => 'dashicons-format-image', |
| 26 | 'description' => __( 'Customize the appearance of email addresses converted to PNG images.', 'email-encoder-bundle' ), |
| 27 | 'settings' => [ 'image_settings' ], |
| 28 | ], |
| 29 | 'exclusions' => [ |
| 30 | 'label' => __( 'Exclusions', 'email-encoder-bundle' ), |
| 31 | 'icon' => 'dashicons-hidden', |
| 32 | 'description' => __( 'Choose what content to leave untouched by the encoder.', 'email-encoder-bundle' ), |
| 33 | 'settings' => [ 'skip_posts', 'skip_query_parameters' ], |
| 34 | ], |
| 35 | 'advanced' => [ |
| 36 | 'label' => __( 'Advanced', 'email-encoder-bundle' ), |
| 37 | 'icon' => 'dashicons-admin-tools', |
| 38 | 'description' => __( 'Fine-tune plugin behavior and display options.', 'email-encoder-bundle' ), |
| 39 | 'settings' => [ 'show_encoded_check', 'protection_text', 'class_name', 'custom_href_attr', 'footer_scripts', 'own_admin_menu' ], |
| 40 | ], |
| 41 | 'tools' => [ |
| 42 | 'label' => __( 'Tools', 'email-encoder-bundle' ), |
| 43 | 'icon' => 'dashicons-editor-code', |
| 44 | 'description' => __( 'Encoder form and developer tools.', 'email-encoder-bundle' ), |
| 45 | 'settings' => [], |
| 46 | ], |
| 47 | 'help' => [ |
| 48 | 'label' => __( 'Help', 'email-encoder-bundle' ), |
| 49 | 'icon' => 'dashicons-editor-help', |
| 50 | 'description' => __( 'Plugin reference, shortcodes, and template tags.', 'email-encoder-bundle' ), |
| 51 | 'settings' => [], |
| 52 | ], |
| 53 | ]; |
| 54 | |
| 55 | if ( ! isset( $tabs[ $active_tab ] ) ) { |
| 56 | $active_tab = 'general'; |
| 57 | } |
| 58 | |
| 59 | ?> |
| 60 | |
| 61 | <div class="eeb-settings-shell"> |
| 62 | |
| 63 | <nav class="eeb-settings-nav"> |
| 64 | <?php foreach ( $tabs as $tab_key => $tab ) : ?> |
| 65 | <a href="#eeb-tab-<?php echo esc_attr( $tab_key ); ?>" |
| 66 | class="eeb-tab<?php echo ( $tab_key === $active_tab ) ? ' eeb-tab-active' : ''; ?>" |
| 67 | data-tab="<?php echo esc_attr( $tab_key ); ?>"> |
| 68 | <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span> |
| 69 | <span class="eeb-nav-label"><?php echo esc_html( $tab['label'] ); ?></span> |
| 70 | </a> |
| 71 | <?php endforeach; ?> |
| 72 | </nav> |
| 73 | |
| 74 | <div class="eeb-settings-content"> |
| 75 | |
| 76 | <?php foreach ( $tabs as $tab_key => $tab ) : ?> |
| 77 | <div id="eeb-tab-<?php echo esc_attr( $tab_key ); ?>" |
| 78 | class="eeb-panel" |
| 79 | <?php echo ( $tab_key !== $active_tab ) ? 'style="display:none;"' : ''; ?>> |
| 80 | |
| 81 | <?php if ( $tab_key === 'tools' ) : |
| 82 | $encoder_form = $this->getEncoderForm(); |
| 83 | ?> |
| 84 | <?php if ( ! empty( $encoder_form ) ) : ?> |
| 85 | <div class="eeb-encoder-tool"> |
| 86 | <h3><?php esc_html_e( 'Manual Email Encoder', 'email-encoder-bundle' ); ?></h3> |
| 87 | <p class="eeb-setting-sublabel"><?php esc_html_e( 'Create protected email links manually. Enter an email address, choose an encoding method, and copy the generated code into your post, page, or template.', 'email-encoder-bundle' ); ?></p> |
| 88 | <?php |
| 89 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $encoder_form contains intentional HTML form fields. |
| 90 | echo $encoder_form; |
| 91 | ?> |
| 92 | <div class="eeb-embed-callout"> |
| 93 | <span class="dashicons dashicons-info-outline"></span> |
| 94 | <div class="eeb-embed-callout-body"> |
| 95 | <strong><?php esc_html_e( 'Embed this form on your site', 'email-encoder-bundle' ); ?></strong> |
| 96 | <div class="eeb-embed-snippets"> |
| 97 | <span><?php esc_html_e( 'Shortcode:', 'email-encoder-bundle' ); ?> <code>[eeb_form]</code></span> |
| 98 | <span><?php esc_html_e( 'Template tag:', 'email-encoder-bundle' ); ?> <code><?php eeb_form(); ?></code></span> |
| 99 | </div> |
| 100 | </div> |
| 101 | </div> |
| 102 | </div> |
| 103 | <?php endif; ?> |
| 104 | <?php endif; ?> |
| 105 | |
| 106 | <div class="eeb-settings-list"> |
| 107 | <?php foreach ( $tab['settings'] as $setting_name ) : |
| 108 | if ( ! isset( $settings[ $setting_name ] ) ) { |
| 109 | continue; |
| 110 | } |
| 111 | $setting = $settings[ $setting_name ]; |
| 112 | |
| 113 | $main_settings_value = ''; |
| 114 | if ( isset( $setting['value'] ) ) { |
| 115 | $main_settings_value = $setting['value']; |
| 116 | } |
| 117 | |
| 118 | $is_checked = ( $setting['type'] == 'checkbox' && ( $main_settings_value === 1 || $main_settings_value === '1' ) ) ? 'checked' : ''; |
| 119 | $value = ( $setting['type'] != 'checkbox' && $setting['type'] != 'multi-input' ) ? $main_settings_value : '1'; |
| 120 | |
| 121 | $setting_modifier = 'eeb-setting--' . ( $setting['type'] === 'multi-input' ? 'multi' : ( $setting['type'] === 'text' ? 'text' : 'bool' ) ); |
| 122 | ?> |
| 123 | <div class="eeb-setting <?php echo esc_attr( $setting_modifier ); ?>" data-setting="<?php echo esc_attr( $setting_name ); ?>"> |
| 124 | <div class="eeb-setting-header"> |
| 125 | <h4> |
| 126 | <?php echo esc_html( $setting['title'] ); ?> |
| 127 | <?php |
| 128 | $tooltip = ''; |
| 129 | if ( isset( $setting['description'] ) && $setting['type'] !== 'multi-input' ) { |
| 130 | $tooltip = $setting['description']; |
| 131 | } elseif ( isset( $setting['label'] ) && $setting['type'] === 'multi-input' ) { |
| 132 | $tooltip = $setting['label']; |
| 133 | } |
| 134 | ?> |
| 135 | <?php if ( ! empty( $tooltip ) ) : ?> |
| 136 | <span class="eeb-tooltip" tabindex="0"> |
| 137 | <span class="dashicons dashicons-info-outline"></span> |
| 138 | <span class="eeb-tooltip-text"><?php echo esc_html( wp_strip_all_tags( $tooltip ) ); ?></span> |
| 139 | </span> |
| 140 | <?php endif; ?> |
| 141 | </h4> |
| 142 | <?php if ( $setting['type'] !== 'multi-input' && isset( $setting['label'] ) ) : ?> |
| 143 | <p class="eeb-setting-sublabel"><?php echo wp_kses_post( $setting['label'] ); ?></p> |
| 144 | <?php endif; ?> |
| 145 | </div> |
| 146 | <div class="eeb-setting-body"> |
| 147 | <?php if ( $setting['type'] === 'multi-input' ) : ?> |
| 148 | |
| 149 | <?php foreach ( $setting['inputs'] as $si_key => $data ) : |
| 150 | |
| 151 | if ( $setting['input-type'] === 'radio' ) { |
| 152 | $data['value'] = $si_key; |
| 153 | } |
| 154 | |
| 155 | $mi_is_checked = ( $setting['input-type'] == 'checkbox' && ( isset( $data['value'] ) && ( $data['value'] === 1 || $data['value'] === '1' ) ) ) ? 'checked' : ''; |
| 156 | $mi_value = ( $setting['input-type'] != 'checkbox' ) ? $data['value'] : '1'; |
| 157 | $si_name = $si_key; |
| 158 | |
| 159 | if ( $setting['input-type'] == 'radio' ) { |
| 160 | $si_name = $setting_name; |
| 161 | if ( (string) $main_settings_value === (string) $data['value'] ) { |
| 162 | $mi_is_checked = 'checked'; |
| 163 | } |
| 164 | } |
| 165 | ?> |
| 166 | <?php if ( $setting['input-type'] === 'text' ) : |
| 167 | $text_id = esc_attr( $si_name . '_' . $si_key ); |
| 168 | ?> |
| 169 | <div class="eeb-setting eeb-setting--text"> |
| 170 | <div class="eeb-setting-header"> |
| 171 | <h4><label for="<?php echo $text_id; ?>"><?php echo wp_kses_post( $data['label'] ); ?></label></h4> |
| 172 | <?php if ( isset( $data['description'] ) ) : ?> |
| 173 | <p class="eeb-setting-sublabel"><?php echo wp_kses_post( $data['description'] ); ?></p> |
| 174 | <?php endif; ?> |
| 175 | </div> |
| 176 | <div class="eeb-setting-body"> |
| 177 | <input id="<?php echo $text_id; ?>" |
| 178 | name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $si_name ); ?>]" |
| 179 | type="text" |
| 180 | class="eeb-input" |
| 181 | value="<?php echo esc_attr( $mi_value ); ?>" |
| 182 | <?php if ( ! empty( $data['placeholder'] ) ) : ?>placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>"<?php endif; ?> /> |
| 183 | </div> |
| 184 | </div> |
| 185 | <?php elseif ( $setting['input-type'] === 'radio' ) : |
| 186 | $option_id = esc_attr( $si_name . '_' . $si_key ); |
| 187 | $icon = ! empty( $data['icon'] ) ? $data['icon'] : 'marker'; |
| 188 | ?> |
| 189 | <label class="eeb-radio-card" for="<?php echo $option_id; ?>"> |
| 190 | <input id="<?php echo $option_id; ?>" |
| 191 | class="eeb-radio-card-input" |
| 192 | name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $si_name ); ?>]" |
| 193 | type="radio" |
| 194 | value="<?php echo esc_attr( $mi_value ); ?>" |
| 195 | <?php echo esc_attr( $mi_is_checked ); ?> /> |
| 196 | <span class="eeb-radio-card-icon"> |
| 197 | <?php if ( $icon === 'shield-off' ) : ?> |
| 198 | <svg class="eeb-radio-card-svg" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> |
| 199 | <path fill-rule="evenodd" d="M10 1.944A11.954 11.954 0 012.166 5C2.056 5.649 2 6.319 2 7c0 5.225 3.34 9.67 8 11.317C14.66 16.67 18 12.225 18 7c0-.682-.057-1.35-.166-2.001A11.954 11.954 0 0110 1.944zM11 14a1 1 0 11-2 0 1 1 0 012 0zm0-7a1 1 0 10-2 0v3a1 1 0 102 0V7z" clip-rule="evenodd" /> |
| 200 | </svg> |
| 201 | <?php else : ?> |
| 202 | <span class="dashicons dashicons-<?php echo esc_attr( $icon ); ?>"></span> |
| 203 | <?php endif; ?> |
| 204 | </span> |
| 205 | <span class="eeb-radio-card-body"> |
| 206 | <strong class="eeb-radio-card-title"><?php echo wp_kses_post( $data['label'] ); ?></strong> |
| 207 | <?php if ( ! empty( $data['description'] ) ) : ?> |
| 208 | <span class="eeb-radio-card-desc"><?php echo wp_kses_post( $data['description'] ); ?></span> |
| 209 | <?php endif; ?> |
| 210 | </span> |
| 211 | </label> |
| 212 | <?php else : |
| 213 | $option_id = esc_attr( $si_name . '_' . $si_key ); |
| 214 | ?> |
| 215 | <div class="eeb-option-row"> |
| 216 | <label for="<?php echo $option_id; ?>" class="eeb-option-label"> |
| 217 | <?php echo wp_kses_post( $data['label'] ); ?> |
| 218 | </label> |
| 219 | <?php if ( isset( $data['description'] ) ) : ?> |
| 220 | <span class="eeb-tooltip" tabindex="0"> |
| 221 | <span class="dashicons dashicons-info-outline"></span> |
| 222 | <span class="eeb-tooltip-text"><?php echo esc_html( wp_strip_all_tags( $data['description'] ) ); ?></span> |
| 223 | </span> |
| 224 | <?php endif; ?> |
| 225 | <label class="eeb-option" for="<?php echo $option_id; ?>"> |
| 226 | <?php // Hidden zero submits when checkbox is unchecked, so the saved option always reflects the toggle state. ?> |
| 227 | <input type="hidden" name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $si_name ); ?>]" value="0" /> |
| 228 | <input id="<?php echo $option_id; ?>" |
| 229 | name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $si_name ); ?>]" |
| 230 | type="checkbox" |
| 231 | value="<?php echo esc_attr( $mi_value ); ?>" |
| 232 | <?php echo esc_attr( $mi_is_checked ); ?> /> |
| 233 | </label> |
| 234 | </div> |
| 235 | <?php endif; ?> |
| 236 | <?php endforeach; ?> |
| 237 | |
| 238 | <?php elseif ( $setting['type'] === 'text' ) : ?> |
| 239 | |
| 240 | <input id="<?php echo esc_attr( $setting['id'] ); ?>" |
| 241 | name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $setting_name ); ?>]" |
| 242 | type="text" |
| 243 | class="eeb-input" |
| 244 | value="<?php echo esc_attr( $value ); ?>" |
| 245 | <?php if ( ! empty( $setting['placeholder'] ) ) : ?>placeholder="<?php echo esc_attr( $setting['placeholder'] ); ?>"<?php endif; ?> /> |
| 246 | |
| 247 | <?php else : ?> |
| 248 | |
| 249 | <label class="eeb-option" for="<?php echo esc_attr( $setting['id'] ); ?>"> |
| 250 | <?php // Hidden zero submits when checkbox is unchecked, so the saved option always reflects the toggle state. ?> |
| 251 | <?php if ( $setting['type'] === 'checkbox' ) : ?> |
| 252 | <input type="hidden" name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $setting_name ); ?>]" value="0" /> |
| 253 | <?php endif; ?> |
| 254 | <input id="<?php echo esc_attr( $setting['id'] ); ?>" |
| 255 | name="<?php echo esc_attr( $this->getSettingsKey() ); ?>[<?php echo esc_attr( $setting_name ); ?>]" |
| 256 | type="<?php echo esc_attr( $setting['type'] ); ?>" |
| 257 | value="<?php echo esc_attr( $value ); ?>" |
| 258 | <?php echo esc_attr( $is_checked ); ?> /> |
| 259 | </label> |
| 260 | |
| 261 | <?php endif; ?> |
| 262 | </div> |
| 263 | </div> |
| 264 | <?php endforeach; ?> |
| 265 | </div> |
| 266 | |
| 267 | <?php if ( $tab_key === 'help' ) : ?> |
| 268 | <div class="eeb-help-content"> |
| 269 | <?php $allowed_attr_html = $this->getSafeHtmlAttr(); ?> |
| 270 | <?php include EEB_PLUGIN_DIR . 'templates/help-tabs/general.php'; ?> |
| 271 | <hr class="eeb-help-divider" /> |
| 272 | <?php include EEB_PLUGIN_DIR . 'templates/help-tabs/shortcodes.php'; ?> |
| 273 | <hr class="eeb-help-divider" /> |
| 274 | <?php include EEB_PLUGIN_DIR . 'templates/help-tabs/template-tags.php'; ?> |
| 275 | </div> |
| 276 | <?php endif; ?> |
| 277 | |
| 278 | <?php if ( ! in_array( $tab_key, [ 'help', 'tools' ], true ) ) : ?> |
| 279 | <div class="eeb-panel-footer"> |
| 280 | <?php submit_button( __( 'Save Settings', 'email-encoder-bundle' ), 'primary eeb-save-btn', 'submit', false ); ?> |
| 281 | </div> |
| 282 | <?php endif; ?> |
| 283 | |
| 284 | </div> |
| 285 | <?php endforeach; ?> |
| 286 | |
| 287 | </div> |
| 288 | |
| 289 | </div> |
| 290 |