class-activation.php
3 years ago
class-admin-interface.php
3 years ago
class-common-methods.php
3 years ago
class-content-management.php
3 years ago
class-custom-code.php
3 years ago
class-deactivation.php
3 years ago
class-disable-components.php
3 years ago
class-login-logout.php
3 years ago
class-optimizations.php
3 years ago
class-security.php
3 years ago
class-settings-fields-render.php
3 years ago
class-settings-sanitization.php
3 years ago
class-settings-sections-fields.php
3 years ago
class-utilities.php
3 years ago
class-settings-fields-render.php
832 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class related to rendering of settings fields on the admin page |
| 7 | * |
| 8 | * @since 2.2.0 |
| 9 | */ |
| 10 | class Settings_Fields_Render |
| 11 | { |
| 12 | /** |
| 13 | * Render checkbox field as a toggle/switcher |
| 14 | * |
| 15 | * @since 1.0.0 |
| 16 | */ |
| 17 | function render_checkbox_toggle( $args ) |
| 18 | { |
| 19 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 20 | $field_name = $args['field_name']; |
| 21 | $field_description = $args['field_description']; |
| 22 | $field_option_value = ( array_key_exists( $args['field_id'], $options ) ? $options[$args['field_id']] : false ); |
| 23 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>' ; |
| 24 | echo '<label for="' . esc_attr( $field_name ) . '"></label>' ; |
| 25 | // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions |
| 26 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 27 | // For when the options / sub-fields occupy lengthy vertical space, we add show all / less toggler |
| 28 | |
| 29 | if ( array_key_exists( 'field_options_moreless', $args ) && $args['field_options_moreless'] ) { |
| 30 | echo '<div class="asenha-field-with-options field-show-more">' ; |
| 31 | echo '<a id="' . $args['field_slug'] . '-show-moreless" class="show-more-less show-more" href="#">Expand ▼</a>' ; |
| 32 | echo '<div class="asenha-field-options-wrapper wrapper-show-more">' ; |
| 33 | } else { |
| 34 | echo '<div class="asenha-field-with-options">' ; |
| 35 | echo '<div class="asenha-field-options-wrapper">' ; |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>' ; |
| 40 | // For field with additional options / sub-fields, we add wrapper for them |
| 41 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 42 | echo '<div class="asenha-subfields" style="display:none"></div>' ; |
| 43 | } |
| 44 | // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions |
| 45 | |
| 46 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 47 | echo '</div>' ; |
| 48 | echo '</div>' ; |
| 49 | } |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Render checkbox field as sub-field of a toggle/switcher checkbox |
| 55 | * |
| 56 | * @since 1.9.0 |
| 57 | */ |
| 58 | function render_checkbox_plain( $args ) |
| 59 | { |
| 60 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 61 | $field_name = $args['field_name']; |
| 62 | $field_label = $args['field_label']; |
| 63 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : false ); |
| 64 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>' ; |
| 65 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>' ; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Render checkbox field as sub-field of a toggle/switcher checkbox |
| 70 | * |
| 71 | * @since 1.3.0 |
| 72 | */ |
| 73 | function render_checkbox_subfield( $args ) |
| 74 | { |
| 75 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 76 | $field_name = $args['field_name']; |
| 77 | $field_label = $args['field_label']; |
| 78 | $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ? $options[$args['parent_field_id']][$args['field_id']] : false ); |
| 79 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>' ; |
| 80 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>' ; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Render radio buttons field as sub-field of a toggle/switcher checkbox |
| 85 | * |
| 86 | * @since 1.3.0 |
| 87 | */ |
| 88 | function render_radio_buttons_subfield( $args ) |
| 89 | { |
| 90 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 91 | $field_id = $args['field_id']; |
| 92 | $field_name = $args['field_name']; |
| 93 | // $field_label = $args['field_label']; |
| 94 | $field_radios = $args['field_radios']; |
| 95 | |
| 96 | if ( !empty($args['field_default']) ) { |
| 97 | $default_value = $args['field_default']; |
| 98 | } else { |
| 99 | $default_value = false; |
| 100 | } |
| 101 | |
| 102 | $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value ); |
| 103 | foreach ( $field_radios as $radio_label => $radio_value ) { |
| 104 | echo '<input type="radio" id="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button" name="' . esc_attr( $field_name ) . '" value="' . $radio_value . '" ' . checked( $radio_value, $field_option_value, false ) . '>' ; |
| 105 | echo '<label for="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button-label">' . wp_kses_post( $radio_label ) . '</label>' ; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Render text field as sub-field of a toggle/switcher checkbox |
| 111 | * |
| 112 | * @since 1.4.0 |
| 113 | */ |
| 114 | function render_text_subfield( $args ) |
| 115 | { |
| 116 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 117 | $field_id = $args['field_id']; |
| 118 | $field_name = $args['field_name']; |
| 119 | $field_type = $args['field_type']; |
| 120 | $field_prefix = $args['field_prefix']; |
| 121 | $field_suffix = $args['field_suffix']; |
| 122 | $field_description = $args['field_description']; |
| 123 | $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' ); |
| 124 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' ); |
| 125 | |
| 126 | if ( !empty($field_prefix) && !empty($field_suffix) ) { |
| 127 | $field_classname = ' with-prefix with-suffix'; |
| 128 | } elseif ( !empty($field_prefix) && empty($field_suffix) ) { |
| 129 | $field_classname = ' with-prefix'; |
| 130 | } elseif ( empty($field_prefix) && !empty($field_suffix) ) { |
| 131 | $field_classname = ' with-suffix'; |
| 132 | } else { |
| 133 | $field_classname = ''; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | if ( $field_id == 'custom_login_slug' ) { |
| 138 | $field_placeholder = 'e.g. backend'; |
| 139 | } elseif ( $field_id == 'redirect_after_login_to_slug' ) { |
| 140 | $field_placeholder = 'e.g. my-account'; |
| 141 | } elseif ( $field_id == 'redirect_after_logout_to_slug' ) { |
| 142 | $field_placeholder = 'e.g. come-visit-again'; |
| 143 | } elseif ( $field_id == 'login_fails_allowed' ) { |
| 144 | $field_placeholder = '3'; |
| 145 | } elseif ( $field_id == 'login_lockout_maxcount' ) { |
| 146 | $field_placeholder = '3'; |
| 147 | } else { |
| 148 | } |
| 149 | |
| 150 | echo $field_prefix . '<input type="text" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text' . esc_attr( $field_classname ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $field_placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix ; |
| 151 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>' ; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Render description field as sub-field of a toggle/switcher checkbox |
| 156 | * |
| 157 | * @since 4.6.0 |
| 158 | */ |
| 159 | function render_description_subfield( $args ) |
| 160 | { |
| 161 | $field_description = $args['field_description']; |
| 162 | echo '<div class="asenha-subfield-description">' . $field_description . '</div>' ; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Render heading for sub-fields of a toggle/switcher checkbox |
| 167 | * |
| 168 | * @since 5.0.0 |
| 169 | */ |
| 170 | function render_subfields_heading( $args ) |
| 171 | { |
| 172 | $subfields_heading = $args['subfields_heading']; |
| 173 | echo '<div class="asenha-subfields-heading">' . $subfields_heading . '</div>' ; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Render password field as sub-field of a toggle/switcher checkbox |
| 178 | * |
| 179 | * @since 4.1.0 |
| 180 | */ |
| 181 | function render_password_subfield( $args ) |
| 182 | { |
| 183 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 184 | $field_id = $args['field_id']; |
| 185 | $field_name = $args['field_name']; |
| 186 | $field_type = $args['field_type']; |
| 187 | $field_prefix = $args['field_prefix']; |
| 188 | $field_suffix = $args['field_suffix']; |
| 189 | $field_description = $args['field_description']; |
| 190 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' ); |
| 191 | |
| 192 | if ( !empty($field_prefix) && !empty($field_suffix) ) { |
| 193 | $field_classname = ' with-prefix with-suffix'; |
| 194 | } elseif ( !empty($field_prefix) && empty($field_suffix) ) { |
| 195 | $field_classname = ' with-prefix'; |
| 196 | } elseif ( empty($field_prefix) && !empty($field_suffix) ) { |
| 197 | $field_classname = ' with-suffix'; |
| 198 | } else { |
| 199 | $field_classname = ''; |
| 200 | } |
| 201 | |
| 202 | $placeholder = ''; |
| 203 | echo $field_prefix . '<input type="password" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-password' . esc_attr( $field_classname ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $placeholder ) . '" size="24" autocomplete="off" value="' . $field_option_value . '">' . $field_suffix ; |
| 204 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>' ; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Render number field as sub-field of a toggle/switcher checkbox |
| 209 | * |
| 210 | * @since 1.4.0 |
| 211 | */ |
| 212 | function render_number_subfield( $args ) |
| 213 | { |
| 214 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 215 | $field_id = $args['field_id']; |
| 216 | $field_name = $args['field_name']; |
| 217 | $field_type = $args['field_type']; |
| 218 | $field_prefix = $args['field_prefix']; |
| 219 | $field_suffix = $args['field_suffix']; |
| 220 | $field_intro = $args['field_intro']; |
| 221 | $field_description = $args['field_description']; |
| 222 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' ); |
| 223 | |
| 224 | if ( !empty($field_prefix) && !empty($field_suffix) ) { |
| 225 | $field_classname = ' with-prefix with-suffix'; |
| 226 | } elseif ( !empty($field_prefix) && empty($field_suffix) ) { |
| 227 | $field_classname = ' with-prefix'; |
| 228 | } elseif ( empty($field_prefix) && !empty($field_suffix) ) { |
| 229 | $field_classname = ' with-suffix'; |
| 230 | } else { |
| 231 | $field_classname = ''; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | if ( $field_id == 'revisions_max_number' || $field_id == 'head_code_priority' || $field_id == 'body_code_priority' || $field_id == 'footer_code_priority' ) { |
| 236 | $placeholder = '10'; |
| 237 | } else { |
| 238 | $placeholder = ''; |
| 239 | } |
| 240 | |
| 241 | echo '<div class="asenha-subfield-number-wrapper">' ; |
| 242 | if ( !empty($field_intro) ) { |
| 243 | echo '<div class="asenha-subfield-number-intro">' . wp_kses_post( $field_intro ) . '</div>' ; |
| 244 | } |
| 245 | echo '<div>' . $field_prefix . '<input type="number" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-number' . esc_attr( $field_classname ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix . '</div>' ; |
| 246 | if ( !empty($field_description) ) { |
| 247 | echo '<div class="asenha-subfield-number-description">' . wp_kses_post( $field_description ) . '</div>' ; |
| 248 | } |
| 249 | echo '</div>' ; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Render select field as sub-field of a toggle/switcher checkbox |
| 254 | * |
| 255 | * @since 1.4.0 |
| 256 | */ |
| 257 | function render_select_subfield( $args ) |
| 258 | { |
| 259 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 260 | $field_id = $args['field_id']; |
| 261 | $field_name = $args['field_name']; |
| 262 | $field_type = $args['field_type']; |
| 263 | $field_prefix = $args['field_prefix']; |
| 264 | $field_suffix = $args['field_suffix']; |
| 265 | $field_select_options = $args['field_select_options']; |
| 266 | $field_select_default = $args['field_select_default']; |
| 267 | $field_intro = $args['field_intro']; |
| 268 | $field_description = $args['field_description']; |
| 269 | |
| 270 | if ( !empty($args['field_select_default']) ) { |
| 271 | $default_value = $args['field_select_default']; |
| 272 | } else { |
| 273 | $default_value = false; |
| 274 | } |
| 275 | |
| 276 | $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value ); |
| 277 | |
| 278 | if ( !empty($field_prefix) && !empty($field_suffix) ) { |
| 279 | $field_classname = ' with-prefix with-suffix'; |
| 280 | } elseif ( !empty($field_prefix) && empty($field_suffix) ) { |
| 281 | $field_classname = ' with-prefix'; |
| 282 | } elseif ( empty($field_prefix) && !empty($field_suffix) ) { |
| 283 | $field_classname = ' with-suffix'; |
| 284 | } else { |
| 285 | $field_classname = ''; |
| 286 | } |
| 287 | |
| 288 | |
| 289 | if ( $args['display_none_on_load'] ) { |
| 290 | $inline_style = ' style="display:none;"'; |
| 291 | } else { |
| 292 | $inline_style = ''; |
| 293 | } |
| 294 | |
| 295 | echo '<div class="asenha-subfield-select-wrapper">' ; |
| 296 | if ( !empty($field_intro) ) { |
| 297 | echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>' ; |
| 298 | } |
| 299 | echo '<div' . $inline_style . ' class="asenha-subfield-select-inner">' . $field_prefix ; |
| 300 | echo '<select name="' . $field_name . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">' ; |
| 301 | foreach ( $field_select_options as $label => $value ) { |
| 302 | echo '<option value="' . $value . '" ' . selected( $value, $field_option_value, false ) . '>' . $label . '</option>' ; |
| 303 | } |
| 304 | echo '</select>' ; |
| 305 | echo $field_suffix . '</div>' ; |
| 306 | if ( !empty($field_description) ) { |
| 307 | echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>' ; |
| 308 | } |
| 309 | echo '</div>' ; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Render textarea field as sub-field of a toggle/switcher checkbox |
| 314 | * |
| 315 | * @since 2.3.0 |
| 316 | */ |
| 317 | function render_textarea_subfield( $args ) |
| 318 | { |
| 319 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 320 | $field_id = $args['field_id']; |
| 321 | $field_slug = $args['field_slug']; |
| 322 | $field_name = $args['field_name']; |
| 323 | $field_type = $args['field_type']; |
| 324 | $field_rows = $args['field_rows']; |
| 325 | $field_intro = $args['field_intro']; |
| 326 | $field_description = $args['field_description']; |
| 327 | $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' ); |
| 328 | // Always load textarea content from robots.txt URL, whether it's a real, custom-made robots.txt file or a virtual one generated by WordPress |
| 329 | |
| 330 | if ( 'robots_txt_content' == $field_id ) { |
| 331 | |
| 332 | if ( array_key_exists( 'manage_robots_txt', $options ) ) { |
| 333 | |
| 334 | if ( !$options['manage_robots_txt'] ) { |
| 335 | // Manage robots.txt feature is NOT enabled |
| 336 | |
| 337 | if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) { |
| 338 | $field_option_value = $options['robots_txt_content']; |
| 339 | } else { |
| 340 | $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' ); |
| 341 | $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) ); |
| 342 | $field_option_value = $robots_txt_content; |
| 343 | } |
| 344 | |
| 345 | } else { |
| 346 | // Manage robots.txt feature is enabled |
| 347 | |
| 348 | if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) { |
| 349 | $field_option_value = $options['robots_txt_content']; |
| 350 | } else { |
| 351 | $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' ); |
| 352 | $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) ); |
| 353 | $field_option_value = $robots_txt_content; |
| 354 | } |
| 355 | |
| 356 | } |
| 357 | |
| 358 | } else { |
| 359 | // Manage robots.txt feature has never been enabled yet |
| 360 | $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' ); |
| 361 | $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) ); |
| 362 | $field_option_value = $robots_txt_content; |
| 363 | } |
| 364 | |
| 365 | } else { |
| 366 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' ); |
| 367 | } |
| 368 | |
| 369 | echo '<div class="asenha-subfield-textarea-wrapper">' ; |
| 370 | if ( !empty($field_intro) ) { |
| 371 | echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>' ; |
| 372 | } |
| 373 | echo '<textarea rows="' . $field_rows . '" class="asenha-subfield-textarea" id="' . esc_attr( $field_name ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $field_placeholder ) . '">' . esc_textarea( $field_option_value ) . '</textarea>' ; |
| 374 | if ( !empty($field_description) ) { |
| 375 | echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>' ; |
| 376 | } |
| 377 | echo '</div>' ; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Render sortable menu field |
| 382 | * |
| 383 | * @since 2.0.0 |
| 384 | */ |
| 385 | function render_sortable_menu( $args ) |
| 386 | { |
| 387 | ?> |
| 388 | <div class="subfield-description">Drag and drop menu items to the desired position. Optionally change 3rd party plugin/theme's menu item titles or hide some items until toggled by clicking "Show All" at the bottom of the admin menu.</div> |
| 389 | <?php |
| 390 | ?> |
| 391 | <ul id="custom-admin-menu" class="menu ui-sortable"> |
| 392 | <?php |
| 393 | global $menu, $submenu ; |
| 394 | $common_methods = new Common_Methods(); |
| 395 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 396 | // Set menu items to be excluded from title renaming. These are from WordPress core. |
| 397 | $renaming_not_allowed = array( |
| 398 | 'menu-dashboard', |
| 399 | 'menu-pages', |
| 400 | 'menu-posts', |
| 401 | 'menu-media', |
| 402 | 'menu-comments', |
| 403 | 'menu-appearance', |
| 404 | 'menu-plugins', |
| 405 | 'menu-users', |
| 406 | 'menu-tools', |
| 407 | 'menu-settings' |
| 408 | ); |
| 409 | // Get custom menu item titles |
| 410 | |
| 411 | if ( array_key_exists( 'custom_menu_titles', $options ) ) { |
| 412 | $custom_menu_titles = $options['custom_menu_titles']; |
| 413 | $custom_menu_titles = explode( ',', $custom_menu_titles ); |
| 414 | } else { |
| 415 | $custom_menu_titles = array(); |
| 416 | } |
| 417 | |
| 418 | // Get menu items hidden by toggle |
| 419 | $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle(); |
| 420 | $i = 1; |
| 421 | // Check if there's an existing custom menu order data stored in options |
| 422 | |
| 423 | if ( array_key_exists( 'custom_menu_order', $options ) ) { |
| 424 | $custom_menu = $options['custom_menu_order']; |
| 425 | $custom_menu = explode( ',', $custom_menu ); |
| 426 | $menu_key_in_use = array(); |
| 427 | // Render sortables with data in custom menu order |
| 428 | foreach ( $custom_menu as $custom_menu_item ) { |
| 429 | foreach ( $menu as $menu_key => $menu_info ) { |
| 430 | |
| 431 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 432 | $menu_item_title = $menu_info[2]; |
| 433 | $menu_item_id = $menu_info[2]; |
| 434 | } else { |
| 435 | $menu_item_title = $menu_info[0]; |
| 436 | $menu_item_id = $menu_info[5]; |
| 437 | } |
| 438 | |
| 439 | $menu_url_fragment = ''; |
| 440 | |
| 441 | if ( $custom_menu_item == $menu_item_id ) { |
| 442 | $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id ); |
| 443 | ?> |
| 444 | <li id="<?php |
| 445 | echo esc_attr( $menu_item_id ) ; |
| 446 | ?>" class="menu-item parent-menu-item menu-item-depth-0"> |
| 447 | <div class="menu-item-bar"> |
| 448 | <div class="menu-item-handle"> |
| 449 | <span class="dashicons dashicons-menu"></span> |
| 450 | <div class="item-title"> |
| 451 | <div class="title-wrapper"> |
| 452 | <span class="menu-item-title"> |
| 453 | <?php |
| 454 | |
| 455 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 456 | $separator_name_ori = $menu_info[2]; |
| 457 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori ); |
| 458 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 459 | echo '~~ ' . esc_html( $separator_name ) . ' ~~' ; |
| 460 | } else { |
| 461 | |
| 462 | if ( in_array( $menu_item_id, $renaming_not_allowed ) ) { |
| 463 | $menu_item_title = $menu_info[0]; |
| 464 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ; |
| 465 | } else { |
| 466 | // Get defaul/custom menu item title |
| 467 | foreach ( $custom_menu_titles as $custom_menu_title ) { |
| 468 | // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets |
| 469 | $custom_menu_title = explode( '__', $custom_menu_title ); |
| 470 | |
| 471 | if ( $custom_menu_title[0] == $menu_item_id ) { |
| 472 | $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] ); |
| 473 | // e.g. Code Snippets |
| 474 | break; |
| 475 | // stop foreach loop so $menu_item_title is not overwritten in the next iteration |
| 476 | } else { |
| 477 | $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] ); |
| 478 | } |
| 479 | |
| 480 | } |
| 481 | ?> |
| 482 | <input type="text" value="<?php |
| 483 | echo wp_kses_post( $menu_item_title ) ; |
| 484 | ?>" class="menu-item-custom-title" data-menu-item-id="<?php |
| 485 | echo esc_attr( $menu_item_id ) ; |
| 486 | ?>"> |
| 487 | <?php |
| 488 | } |
| 489 | |
| 490 | } |
| 491 | |
| 492 | ?> |
| 493 | </span><!-- end of .menu-item-title --> |
| 494 | <?php |
| 495 | ?> |
| 496 | </div><!-- end of .title-wrapper --> |
| 497 | <div class="options-for-hiding"> |
| 498 | <?php |
| 499 | $hide_text = 'Hide until toggled'; |
| 500 | $checkbox_class = 'parent-menu-hide-checkbox'; |
| 501 | ?> |
| 502 | <label class="menu-item-checkbox-label"> |
| 503 | <?php |
| 504 | |
| 505 | if ( in_array( $custom_menu_item, $menu_hidden_by_toggle ) ) { |
| 506 | ?> |
| 507 | <input type="checkbox" id="hide-status-for-<?php |
| 508 | echo esc_attr( $menu_item_id_transformed ) ; |
| 509 | ?>" class="<?php |
| 510 | echo esc_attr( $checkbox_class ) ; |
| 511 | ?>" data-menu-item-title="<?php |
| 512 | echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ; |
| 513 | ?>" data-menu-item-id="<?php |
| 514 | echo esc_attr( $menu_item_id_transformed ) ; |
| 515 | ?>" data-menu-item-id-ori="<?php |
| 516 | echo esc_attr( $menu_item_id ) ; |
| 517 | ?>" data-menu-url-fragment="<?php |
| 518 | echo esc_attr( $menu_url_fragment ) ; |
| 519 | ?>" checked> |
| 520 | <span><?php |
| 521 | echo esc_html( $hide_text ) ; |
| 522 | ?></span> |
| 523 | <?php |
| 524 | } else { |
| 525 | ?> |
| 526 | <input type="checkbox" id="hide-status-for-<?php |
| 527 | echo esc_attr( $menu_item_id_transformed ) ; |
| 528 | ?>" class="<?php |
| 529 | echo esc_attr( $checkbox_class ) ; |
| 530 | ?>" data-menu-item-title="<?php |
| 531 | echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ; |
| 532 | ?>" data-menu-item-id="<?php |
| 533 | echo esc_attr( $menu_item_id_transformed ) ; |
| 534 | ?>" data-menu-item-id-ori="<?php |
| 535 | echo esc_attr( $menu_item_id ) ; |
| 536 | ?>" data-menu-url-fragment="<?php |
| 537 | echo esc_attr( $menu_url_fragment ) ; |
| 538 | ?>"> |
| 539 | <span><?php |
| 540 | echo esc_html( $hide_text ) ; |
| 541 | ?></span> |
| 542 | <?php |
| 543 | } |
| 544 | |
| 545 | ?> |
| 546 | </label> |
| 547 | <?php |
| 548 | ?> |
| 549 | </div><!-- end of .options-for-hiding --> |
| 550 | </div><!-- end of .item-title --> |
| 551 | </div><!-- end of .menu-item-handle --> |
| 552 | </div><!-- end of .menu-item-bar --> |
| 553 | <?php |
| 554 | ?> |
| 555 | <?php |
| 556 | $i = 1; |
| 557 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 558 | } |
| 559 | ?> |
| 560 | </li> |
| 561 | <?php |
| 562 | $menu_key_in_use[] = $menu_key; |
| 563 | } |
| 564 | |
| 565 | } |
| 566 | } |
| 567 | // Render the rest of the current menu towards the end of the sortables |
| 568 | foreach ( $menu as $menu_key => $menu_info ) { |
| 569 | |
| 570 | if ( !in_array( $menu_key, $menu_key_in_use ) ) { |
| 571 | |
| 572 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 573 | $menu_item_id = $menu_info[2]; |
| 574 | } else { |
| 575 | $menu_item_id = $menu_info[5]; |
| 576 | } |
| 577 | |
| 578 | $menu_item_title = $menu_info[0]; |
| 579 | $menu_url_fragment = ''; |
| 580 | // Exclude Show All/Less toggles |
| 581 | |
| 582 | if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) { |
| 583 | $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id ); |
| 584 | ?> |
| 585 | <li id="<?php |
| 586 | echo esc_attr( $menu_item_id ) ; |
| 587 | ?>" class="menu-item parent-menu-item menu-item-depth-0"> |
| 588 | <div class="menu-item-bar"> |
| 589 | <div class="menu-item-handle"> |
| 590 | <span class="dashicons dashicons-menu"></span> |
| 591 | <div class="item-title"> |
| 592 | <div class="title-wrapper"> |
| 593 | <span class="menu-item-title"> |
| 594 | <?php |
| 595 | |
| 596 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 597 | $separator_name_ori = $menu_info[2]; |
| 598 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori ); |
| 599 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 600 | echo '~~ ' . esc_html( $separator_name ) . ' ~~' ; |
| 601 | } else { |
| 602 | ?> |
| 603 | <input type="text" value="<?php |
| 604 | echo wp_kses_post( $menu_item_title ) ; |
| 605 | ?>" class="menu-item-custom-title" data-menu-item-id="<?php |
| 606 | echo esc_attr( $menu_item_id ) ; |
| 607 | ?>"> |
| 608 | <?php |
| 609 | } |
| 610 | |
| 611 | ?> |
| 612 | </span> |
| 613 | <?php |
| 614 | ?> |
| 615 | </div> |
| 616 | <div class="options-for-hiding"> |
| 617 | <?php |
| 618 | $hide_text = 'Hide until toggled'; |
| 619 | $checkbox_class = 'parent-menu-hide-checkbox'; |
| 620 | ?> |
| 621 | <label class="menu-item-checkbox-label"> |
| 622 | <input type="checkbox" id="hide-status-for-<?php |
| 623 | echo esc_attr( $menu_item_id_transformed ) ; |
| 624 | ?>" class="<?php |
| 625 | echo esc_attr( $checkbox_class ) ; |
| 626 | ?>" data-menu-item-id="<?php |
| 627 | echo esc_attr( $menu_item_id ) ; |
| 628 | ?>"> |
| 629 | <span><?php |
| 630 | echo esc_html( $hide_text ) ; |
| 631 | ?></span> |
| 632 | </label> |
| 633 | <?php |
| 634 | ?> |
| 635 | </div><!-- end of .options-for-hiding --> |
| 636 | </div><!-- end of .item-title --> |
| 637 | </div><!-- end of .menu-item-handle --> |
| 638 | </div><!-- end of .menu-item-bar --> |
| 639 | <div class="menu-item-settings parent-menu-item-settings wp-clearfix" style="display:none;"> |
| 640 | </div><!-- end of .menu-item-settings --> |
| 641 | <?php |
| 642 | $i = 1; |
| 643 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 644 | ?> |
| 645 | <?php |
| 646 | } |
| 647 | ?> |
| 648 | </li><!-- end of .menu-item --> |
| 649 | <?php |
| 650 | } |
| 651 | |
| 652 | } |
| 653 | |
| 654 | } |
| 655 | } else { |
| 656 | // No custom menu order has been saved yet |
| 657 | // Render sortables with existing items in the admin menu |
| 658 | foreach ( $menu as $menu_key => $menu_info ) { |
| 659 | |
| 660 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 661 | $menu_item_id = $menu_info[2]; |
| 662 | } else { |
| 663 | $menu_item_id = $menu_info[5]; |
| 664 | } |
| 665 | |
| 666 | $menu_url_fragment = ''; |
| 667 | $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id ); |
| 668 | ?> |
| 669 | <li id="<?php |
| 670 | echo esc_attr( $menu_item_id ) ; |
| 671 | ?>" class="menu-item parent-menu-item menu-item-depth-0"> |
| 672 | <div class="menu-item-bar"> |
| 673 | <div class="menu-item-handle"> |
| 674 | <span class="dashicons dashicons-menu"></span> |
| 675 | <div class="item-title"> |
| 676 | <div class="title-wrapper"> |
| 677 | <span class="menu-item-title"> |
| 678 | <?php |
| 679 | |
| 680 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 681 | $separator_name_ori = $menu_info[2]; |
| 682 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori ); |
| 683 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 684 | echo '~~ ' . esc_html( $separator_name ) . ' ~~' ; |
| 685 | } else { |
| 686 | |
| 687 | if ( in_array( $menu_item_id, $renaming_not_allowed ) ) { |
| 688 | $menu_item_title = $menu_info[0]; |
| 689 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ; |
| 690 | } else { |
| 691 | ?> |
| 692 | <input type="text" value="<?php |
| 693 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ) ; |
| 694 | ?>" class="menu-item-custom-title" data-menu-item-id="<?php |
| 695 | echo esc_attr( $menu_item_id ) ; |
| 696 | ?>"> |
| 697 | <?php |
| 698 | } |
| 699 | |
| 700 | } |
| 701 | |
| 702 | ?> |
| 703 | </span> |
| 704 | <?php |
| 705 | ?> |
| 706 | </div><!-- end of .title-wrapper --> |
| 707 | <div class="options-for-hiding"> |
| 708 | <?php |
| 709 | $hide_text = 'Hide until toggled'; |
| 710 | $checkbox_class = 'parent-menu-hide-checkbox'; |
| 711 | ?> |
| 712 | <label class="menu-item-checkbox-label"> |
| 713 | <input type="checkbox" id="hide-status-for-<?php |
| 714 | echo esc_attr( $menu_item_id_transformed ) ; |
| 715 | ?>" class="<?php |
| 716 | echo esc_attr( $checkbox_class ) ; |
| 717 | ?>" data-menu-item-id="<?php |
| 718 | echo esc_attr( $menu_item_id ) ; |
| 719 | ?>"> |
| 720 | <span><?php |
| 721 | echo esc_html( $hide_text ) ; |
| 722 | ?></span> |
| 723 | </label> |
| 724 | <?php |
| 725 | ?> |
| 726 | </div><!-- end of .options-for-hiding --> |
| 727 | </div><!-- end of .item-title --> |
| 728 | </div><!-- end of .menu-item-handle --> |
| 729 | </div><!-- end of .menu-item-bar --> |
| 730 | <?php |
| 731 | $i = 1; |
| 732 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 733 | ?> |
| 734 | <?php |
| 735 | } |
| 736 | ?> |
| 737 | </li> |
| 738 | <?php |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | ?> |
| 743 | </ul> |
| 744 | <?php |
| 745 | // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes. |
| 746 | $field_id = $args['field_id']; |
| 747 | $field_name = $args['field_name']; |
| 748 | $field_description = $args['field_description']; |
| 749 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' ); |
| 750 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ; |
| 751 | // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items. |
| 752 | $field_id = 'custom_menu_titles'; |
| 753 | $field_name = ASENHA_SLUG_U . '[' . $field_id . ']'; |
| 754 | $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' ); |
| 755 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ; |
| 756 | // Hidden input field to store hidden menu items (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes. |
| 757 | $field_id = 'custom_menu_hidden'; |
| 758 | $field_name = ASENHA_SLUG_U . '[' . $field_id . ']'; |
| 759 | $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' ); |
| 760 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ; |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Render textarea field as sub-field of a toggle/switcher checkbox |
| 765 | * |
| 766 | * @since 2.3.0 |
| 767 | */ |
| 768 | function render_datatable( $args ) |
| 769 | { |
| 770 | global $wpdb ; |
| 771 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 772 | $field_id = $args['field_id']; |
| 773 | $field_slug = $args['field_slug']; |
| 774 | $field_name = $args['field_name']; |
| 775 | $field_type = $args['field_type']; |
| 776 | $field_description = $args['field_description']; |
| 777 | $table_title = $args['table_title']; |
| 778 | $table_name = $args['table_name']; |
| 779 | $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' ); |
| 780 | ?> |
| 781 | <table id="login-attempts-log" class="wp-list-table widefat striped datatable"> |
| 782 | <thead> |
| 783 | <tr class="datatable-tr"> |
| 784 | <th class="datatable-th">IP Address<br />Last Username</th> |
| 785 | <th class="datatable-th">Attempts<br />Lockouts</th> |
| 786 | <th class="datatable-th">Last Attempt On</th> |
| 787 | </tr> |
| 788 | </thead> |
| 789 | <tbody> |
| 790 | <?php |
| 791 | $limit = 1000; |
| 792 | $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) ); |
| 793 | $entries = $wpdb->get_results( $sql, ARRAY_A ); |
| 794 | foreach ( $entries as $entry ) { |
| 795 | $unixtime = $entry['unixtime']; |
| 796 | |
| 797 | if ( function_exists( 'wp_date' ) ) { |
| 798 | $date = wp_date( 'F j, Y', $unixtime ); |
| 799 | $time = wp_date( 'H:i:s', $unixtime ); |
| 800 | } else { |
| 801 | $date = date_i18n( 'F j, Y', $unixtime ); |
| 802 | $time = date_i18n( 'H:i:s', $unixtime ); |
| 803 | } |
| 804 | |
| 805 | ?> |
| 806 | <tr class="datatable-tr"> |
| 807 | <td class="datatable-td"><?php |
| 808 | echo esc_html( $entry['ip_address'] ) ; |
| 809 | ?><br /><?php |
| 810 | echo esc_html( $entry['username'] ) ; |
| 811 | ?></td> |
| 812 | <td class="datatable-td"><?php |
| 813 | echo esc_html( $entry['fail_count'] ) ; |
| 814 | ?><br /><?php |
| 815 | echo esc_html( $entry['lockout_count'] ) ; |
| 816 | ?></td> |
| 817 | <td class="datatable-td"><?php |
| 818 | echo esc_html( $date ) ; |
| 819 | ?><br /><?php |
| 820 | echo esc_html( $time ) ; |
| 821 | ?></td> |
| 822 | </tr> |
| 823 | <?php |
| 824 | } |
| 825 | ?> |
| 826 | </tbody> |
| 827 | </table> |
| 828 | <?php |
| 829 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ; |
| 830 | } |
| 831 | |
| 832 | } |