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-deactivation.php
3 years ago
class-disable-components.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
546 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 | |
| 21 | $field_name = $args['field_name']; |
| 22 | $field_description = $args['field_description']; |
| 23 | $field_option_value = ( array_key_exists( $args['field_id'], $options ) ) ? $options[$args['field_id']] : false; |
| 24 | |
| 25 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>'; |
| 26 | echo '<label for="' . esc_attr( $field_name ) . '"></label>'; |
| 27 | |
| 28 | // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions |
| 29 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 30 | // For when the options / sub-fields occupy lengthy vertical space, we add show all / less toggler |
| 31 | if ( array_key_exists( 'field_options_moreless', $args ) && $args['field_options_moreless'] ) { |
| 32 | echo '<div class="asenha-field-with-options field-show-more">'; |
| 33 | echo '<a id="' . $args['field_slug'] . '-show-moreless" class="show-more-less show-more" href="#">Expand ▼</a>'; |
| 34 | echo '<div class="asenha-field-options-wrapper wrapper-show-more">'; |
| 35 | } else { |
| 36 | echo '<div class="asenha-field-with-options">'; |
| 37 | echo '<div class="asenha-field-options-wrapper">'; |
| 38 | } |
| 39 | |
| 40 | } |
| 41 | |
| 42 | echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>'; |
| 43 | |
| 44 | // For field with additional options / sub-fields, we add wrapper for them |
| 45 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 46 | echo '<div class="asenha-subfields" style="display:none"></div>'; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions |
| 51 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 52 | echo '</div>'; |
| 53 | echo '</div>'; |
| 54 | } |
| 55 | |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Render checkbox field as sub-field of a toggle/switcher checkbox |
| 60 | * |
| 61 | * @since 1.9.0 |
| 62 | */ |
| 63 | function render_checkbox_plain( $args ) { |
| 64 | |
| 65 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 66 | |
| 67 | $field_name = $args['field_name']; |
| 68 | $field_label = $args['field_label']; |
| 69 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : false; |
| 70 | |
| 71 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>'; |
| 72 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>'; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Render checkbox field as sub-field of a toggle/switcher checkbox |
| 78 | * |
| 79 | * @since 1.3.0 |
| 80 | */ |
| 81 | function render_checkbox_subfield( $args ) { |
| 82 | |
| 83 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 84 | |
| 85 | $field_name = $args['field_name']; |
| 86 | $field_label = $args['field_label']; |
| 87 | $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ) ? $options[$args['parent_field_id']][$args['field_id']] : false; |
| 88 | |
| 89 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>'; |
| 90 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>'; |
| 91 | |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Render text field as sub-field of a toggle/switcher checkbox |
| 96 | * |
| 97 | * @since 1.4.0 |
| 98 | */ |
| 99 | function render_text_subfield( $args ) { |
| 100 | |
| 101 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 102 | |
| 103 | $field_id = $args['field_id']; |
| 104 | $field_name = $args['field_name']; |
| 105 | $field_type = $args['field_type']; |
| 106 | $field_prefix = $args['field_prefix']; |
| 107 | $field_suffix = $args['field_suffix']; |
| 108 | $field_description = $args['field_description']; |
| 109 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 110 | |
| 111 | if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 112 | $field_classname = ' with-prefix with-suffix'; |
| 113 | } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) { |
| 114 | $field_classname = ' with-prefix'; |
| 115 | } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 116 | $field_classname = ' with-suffix'; |
| 117 | } else { |
| 118 | $field_classname = ''; |
| 119 | } |
| 120 | |
| 121 | if ( $field_id == 'custom_login_slug' ) { |
| 122 | $placeholder = 'e.g. backend'; |
| 123 | } elseif ( $field_id == 'redirect_after_login_to_slug' ) { |
| 124 | $placeholder = 'e.g. my-account'; |
| 125 | } elseif ( $field_id == 'redirect_after_logout_to_slug' ) { |
| 126 | $placeholder = 'e.g. come-visit-again'; |
| 127 | } elseif ( $field_id == 'login_fails_allowed' ) { |
| 128 | $placeholder = '3'; |
| 129 | } elseif ( $field_id == 'login_lockout_maxcount' ) { |
| 130 | $placeholder = '3'; |
| 131 | } else { |
| 132 | $placeholder = ''; |
| 133 | } |
| 134 | |
| 135 | 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( $placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix; |
| 136 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>'; |
| 137 | |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Render textarea field as sub-field of a toggle/switcher checkbox |
| 142 | * |
| 143 | * @since 2.3.0 |
| 144 | */ |
| 145 | function render_textarea_subfield( $args ) { |
| 146 | |
| 147 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 148 | |
| 149 | $field_id = $args['field_id']; |
| 150 | $field_slug = $args['field_slug']; |
| 151 | $field_name = $args['field_name']; |
| 152 | $field_type = $args['field_type']; |
| 153 | $field_prefix = $args['field_prefix']; |
| 154 | $field_suffix = $args['field_suffix']; |
| 155 | $field_description = $args['field_description']; |
| 156 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 157 | |
| 158 | echo '<textarea rows="30" class="asenha-subfield-textarea" id="' . esc_attr( $field_name ) . '" name="' . esc_attr( $field_name ) . '">' . esc_textarea( $field_option_value ) . '</textarea>'; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Render sortable menu field |
| 163 | * |
| 164 | * @since 2.0.0 |
| 165 | */ |
| 166 | function render_sortable_menu( $args ) { |
| 167 | |
| 168 | ?> |
| 169 | <div class="subfield-description">Drag and drop menu items to the desired position. Optionally change item titles or hide some items until "Show All" at the bottom of the admin menu is clicked.</div> |
| 170 | <ul id="custom-admin-menu" class="menu ui-sortable"> |
| 171 | <?php |
| 172 | |
| 173 | global $menu; |
| 174 | global $submenu; |
| 175 | $common_methods = new Common_Methods; |
| 176 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 177 | |
| 178 | // Set menu items to be excluded from title renaming. These are from WordPress core. |
| 179 | $renaming_not_allowed = array( 'menu-dashboard', 'menu-pages', 'menu-posts', 'menu-media', 'menu-comments', 'menu-appearance', 'menu-plugins', 'menu-users', 'menu-tools', 'menu-settings' ); |
| 180 | |
| 181 | // Get custom menu item titles |
| 182 | if ( array_key_exists( 'custom_menu_titles', $options ) ) { |
| 183 | $custom_menu_titles = $options['custom_menu_titles']; |
| 184 | $custom_menu_titles = explode( ',', $custom_menu_titles ); |
| 185 | } else { |
| 186 | $custom_menu_titles = array(); |
| 187 | } |
| 188 | |
| 189 | // Get hidden menu items |
| 190 | if ( array_key_exists( 'custom_menu_hidden', $options ) ) { |
| 191 | $hidden_menu = $options['custom_menu_hidden']; |
| 192 | $hidden_menu = explode( ',', $hidden_menu ); |
| 193 | } else { |
| 194 | $hidden_menu = array(); |
| 195 | } |
| 196 | |
| 197 | $i = 1; |
| 198 | |
| 199 | // Check if there's an existing custom menu order data stored in options |
| 200 | |
| 201 | if ( array_key_exists( 'custom_menu_order', $options ) ) { |
| 202 | |
| 203 | $custom_menu = $options['custom_menu_order']; |
| 204 | $custom_menu = explode( ',', $custom_menu ); |
| 205 | |
| 206 | $menu_key_in_use = array(); |
| 207 | |
| 208 | // Render sortables with data in custom menu order |
| 209 | |
| 210 | foreach ( $custom_menu as $custom_menu_item ) { |
| 211 | |
| 212 | foreach ( $menu as $menu_key => $menu_info ) { |
| 213 | |
| 214 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 215 | $menu_item_id = $menu_info[2]; |
| 216 | } else { |
| 217 | $menu_item_id = $menu_info[5]; |
| 218 | } |
| 219 | |
| 220 | if ( $custom_menu_item == $menu_item_id ) { |
| 221 | |
| 222 | ?> |
| 223 | <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 224 | <div class="menu-item-bar"> |
| 225 | <div class="menu-item-handle ui-sortable-handle"> |
| 226 | <div class="item-title"> |
| 227 | <span class="menu-item-title"> |
| 228 | <?php |
| 229 | |
| 230 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 231 | $separator_name = $menu_info[2]; |
| 232 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name ); |
| 233 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 234 | echo '~~ ' . esc_html( $separator_name ) . ' ~~'; |
| 235 | } else { |
| 236 | if ( in_array( $menu_item_id, $renaming_not_allowed ) ) { |
| 237 | // echo wp_kses_post( $menu_info[0] ); |
| 238 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ); |
| 239 | } else { |
| 240 | |
| 241 | // Get defaul/custom menu item title |
| 242 | foreach ( $custom_menu_titles as $custom_menu_title ) { |
| 243 | |
| 244 | // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets |
| 245 | |
| 246 | $custom_menu_title = explode( '__', $custom_menu_title ); |
| 247 | |
| 248 | if ( $custom_menu_title[0] == $menu_item_id ) { |
| 249 | $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] ); // e.g. Code Snippets |
| 250 | break; // stop foreach loop so $menu_item_title is not overwritten in the next iteration |
| 251 | } else { |
| 252 | $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] ); |
| 253 | } |
| 254 | |
| 255 | } |
| 256 | |
| 257 | ?> |
| 258 | <input type="text" value="<?php echo wp_kses_post( $menu_item_title ); ?>" class="menu-item-custom-title" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 259 | <?php |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | ?> |
| 264 | </span> |
| 265 | <label class="menu-item-checkbox-label"> |
| 266 | <?php |
| 267 | if ( in_array( $custom_menu_item, $hidden_menu ) ) { |
| 268 | ?> |
| 269 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>" checked> |
| 270 | <span>Hide</span> |
| 271 | <?php |
| 272 | } else { |
| 273 | ?> |
| 274 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 275 | <span>Hide</span> |
| 276 | <?php |
| 277 | } |
| 278 | ?> |
| 279 | </label> |
| 280 | </div> |
| 281 | </div> |
| 282 | </div> |
| 283 | <?php |
| 284 | |
| 285 | $i = 1; |
| 286 | |
| 287 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 288 | ?> |
| 289 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 290 | <?php |
| 291 | |
| 292 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 293 | |
| 294 | $i++; |
| 295 | |
| 296 | // echo $submenu_item[0]; |
| 297 | |
| 298 | } |
| 299 | ?> |
| 300 | </div> |
| 301 | <?php |
| 302 | |
| 303 | } |
| 304 | ?> |
| 305 | </li> |
| 306 | |
| 307 | <?php |
| 308 | |
| 309 | $menu_key_in_use[] = $menu_key; |
| 310 | |
| 311 | } |
| 312 | |
| 313 | } |
| 314 | |
| 315 | } |
| 316 | |
| 317 | // Render the rest of the current menu towards the end of the sortables |
| 318 | |
| 319 | foreach ( $menu as $menu_key => $menu_info ) { |
| 320 | |
| 321 | if ( ! in_array( $menu_key, $menu_key_in_use ) ) { |
| 322 | |
| 323 | $menu_item_id = $menu_info[5]; |
| 324 | $menu_item_title = $menu_info[0]; |
| 325 | |
| 326 | // Exclude Show All/Less toggles |
| 327 | |
| 328 | if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) { |
| 329 | |
| 330 | ?> |
| 331 | <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 332 | <div class="menu-item-bar"> |
| 333 | <div class="menu-item-handle ui-sortable-handle"> |
| 334 | <div class="item-title"> |
| 335 | <span class="menu-item-title"> |
| 336 | <input type="text" value="<?php echo wp_kses_post( $menu_item_title ); ?>" class="menu-item-custom-title" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 337 | </span> |
| 338 | <label class="menu-item-checkbox-label"> |
| 339 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 340 | <span>Hide</span> |
| 341 | </label> |
| 342 | </div> |
| 343 | </div> |
| 344 | </div> |
| 345 | <?php |
| 346 | |
| 347 | } |
| 348 | |
| 349 | $i = 1; |
| 350 | |
| 351 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 352 | ?> |
| 353 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 354 | <?php |
| 355 | |
| 356 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 357 | |
| 358 | $i++; |
| 359 | |
| 360 | // echo $submenu_item[0]; |
| 361 | |
| 362 | } |
| 363 | ?> |
| 364 | </div> |
| 365 | <?php |
| 366 | |
| 367 | } |
| 368 | ?> |
| 369 | </li> |
| 370 | |
| 371 | <?php |
| 372 | |
| 373 | } |
| 374 | |
| 375 | } |
| 376 | |
| 377 | } else { |
| 378 | |
| 379 | // Render sortables with existing items in the admin menu |
| 380 | |
| 381 | foreach ( $menu as $menu_key => $menu_info ) { |
| 382 | |
| 383 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 384 | $menu_item_id = $menu_info[2]; |
| 385 | } else { |
| 386 | $menu_item_id = $menu_info[5]; |
| 387 | } |
| 388 | |
| 389 | ?> |
| 390 | <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 391 | <div class="menu-item-bar"> |
| 392 | <div class="menu-item-handle ui-sortable-handle"> |
| 393 | <div class="item-title"> |
| 394 | <span class="menu-item-title"> |
| 395 | <?php |
| 396 | |
| 397 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 398 | $separator_name = $menu_info[2]; |
| 399 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name ); |
| 400 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 401 | echo '~~ ' . esc_html( $separator_name ) . ' ~~'; |
| 402 | } else { |
| 403 | if ( in_array( $menu_item_id, $renaming_not_allowed ) ) { |
| 404 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ); |
| 405 | } else { |
| 406 | ?> |
| 407 | <input type="text" value="<?php echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ); ?>" class="menu-item-custom-title" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 408 | <?php |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | ?> |
| 413 | </span> |
| 414 | <label class="menu-item-checkbox-label"> |
| 415 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 416 | <span>Hide</span> |
| 417 | </label> |
| 418 | </div> |
| 419 | </div> |
| 420 | </div> |
| 421 | <?php |
| 422 | |
| 423 | $i = 1; |
| 424 | |
| 425 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 426 | ?> |
| 427 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 428 | <?php |
| 429 | |
| 430 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 431 | |
| 432 | $i++; |
| 433 | |
| 434 | // echo $submenu_item[0]; |
| 435 | |
| 436 | } |
| 437 | ?> |
| 438 | </div> |
| 439 | <?php |
| 440 | |
| 441 | } |
| 442 | ?> |
| 443 | </li> |
| 444 | |
| 445 | <?php |
| 446 | |
| 447 | } |
| 448 | |
| 449 | |
| 450 | } |
| 451 | |
| 452 | |
| 453 | ?> |
| 454 | </ul> |
| 455 | <?php |
| 456 | |
| 457 | $field_id = $args['field_id']; |
| 458 | $field_name = $args['field_name']; |
| 459 | $field_description = $args['field_description']; |
| 460 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 461 | |
| 462 | // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes. |
| 463 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 464 | |
| 465 | $field_id = 'custom_menu_titles'; |
| 466 | $field_name = ASENHA_SLUG_U . '['. $field_id .']'; |
| 467 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : ''; |
| 468 | |
| 469 | // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items. |
| 470 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 471 | |
| 472 | $field_id = 'custom_menu_hidden'; |
| 473 | $field_name = ASENHA_SLUG_U . '['. $field_id .']'; |
| 474 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : ''; |
| 475 | |
| 476 | // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes. |
| 477 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 478 | |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Render textarea field as sub-field of a toggle/switcher checkbox |
| 483 | * |
| 484 | * @since 2.3.0 |
| 485 | */ |
| 486 | function render_datatable( $args ) { |
| 487 | |
| 488 | global $wpdb; |
| 489 | |
| 490 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 491 | |
| 492 | $field_id = $args['field_id']; |
| 493 | $field_slug = $args['field_slug']; |
| 494 | $field_name = $args['field_name']; |
| 495 | $field_type = $args['field_type']; |
| 496 | $field_description = $args['field_description']; |
| 497 | $table_title = $args['table_title']; |
| 498 | $table_name = $args['table_name']; |
| 499 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 500 | |
| 501 | ?> |
| 502 | <table id="login-attempts-log" class="wp-list-table widefat striped datatable"> |
| 503 | <thead> |
| 504 | <tr class="datatable-tr"> |
| 505 | <th class="datatable-th">IP Address<br />Last Username</th> |
| 506 | <th class="datatable-th">Attempts<br />Lockouts</th> |
| 507 | <th class="datatable-th">Last Attempt On</th> |
| 508 | </tr> |
| 509 | </thead> |
| 510 | <tbody> |
| 511 | <?php |
| 512 | |
| 513 | $limit = 1000; |
| 514 | |
| 515 | $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) ); |
| 516 | |
| 517 | $entries = $wpdb->get_results( $sql, ARRAY_A ); |
| 518 | |
| 519 | foreach( $entries as $entry ) { |
| 520 | |
| 521 | $unixtime = $entry['unixtime']; |
| 522 | if ( function_exists( 'wp_date' ) ) { |
| 523 | $date = wp_date( 'F j, Y', $unixtime ); |
| 524 | $time = wp_date( 'H:i:s', $unixtime ); |
| 525 | } else { |
| 526 | $date = date_i18n( 'F j, Y', $unixtime ); |
| 527 | $time = date_i18n( 'H:i:s', $unixtime ); |
| 528 | } |
| 529 | ?> |
| 530 | <tr class="datatable-tr"> |
| 531 | <td class="datatable-td"><?php echo esc_html( $entry['ip_address'] ); ?><br /><?php echo esc_html( $entry['username'] ); ?></td> |
| 532 | <td class="datatable-td"><?php echo esc_html( $entry['fail_count'] ); ?><br /><?php echo esc_html( $entry['lockout_count'] ); ?></td> |
| 533 | <td class="datatable-td"><?php echo esc_html( $date ); ?><br /><?php echo esc_html( $time ); ?></td> |
| 534 | </tr> |
| 535 | <?php |
| 536 | } |
| 537 | |
| 538 | ?> |
| 539 | </tbody> |
| 540 | </table> |
| 541 | <?php |
| 542 | |
| 543 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 544 | } |
| 545 | |
| 546 | } |