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
763 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 radio buttons field as sub-field of a toggle/switcher checkbox |
| 96 | * |
| 97 | * @since 1.3.0 |
| 98 | */ |
| 99 | function render_radio_buttons_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_label = $args['field_label']; |
| 106 | $field_radios = $args['field_radios']; |
| 107 | if ( ! empty( $args['field_default'] ) ) { |
| 108 | $default_value = $args['field_default']; |
| 109 | } else { |
| 110 | $default_value = false; |
| 111 | } |
| 112 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : $default_value; |
| 113 | |
| 114 | foreach ( $field_radios as $radio_label => $radio_value ) { |
| 115 | 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 ) . '>'; |
| 116 | echo '<label for="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button-label">' . wp_kses_post( $radio_label ) . '</label>'; |
| 117 | } |
| 118 | |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Render text field as sub-field of a toggle/switcher checkbox |
| 123 | * |
| 124 | * @since 1.4.0 |
| 125 | */ |
| 126 | function render_text_subfield( $args ) { |
| 127 | |
| 128 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 129 | |
| 130 | $field_id = $args['field_id']; |
| 131 | $field_name = $args['field_name']; |
| 132 | $field_type = $args['field_type']; |
| 133 | $field_prefix = $args['field_prefix']; |
| 134 | $field_suffix = $args['field_suffix']; |
| 135 | $field_description = $args['field_description']; |
| 136 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 137 | |
| 138 | if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 139 | $field_classname = ' with-prefix with-suffix'; |
| 140 | } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) { |
| 141 | $field_classname = ' with-prefix'; |
| 142 | } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 143 | $field_classname = ' with-suffix'; |
| 144 | } else { |
| 145 | $field_classname = ''; |
| 146 | } |
| 147 | |
| 148 | if ( $field_id == 'custom_login_slug' ) { |
| 149 | $placeholder = 'e.g. backend'; |
| 150 | } elseif ( $field_id == 'redirect_after_login_to_slug' ) { |
| 151 | $placeholder = 'e.g. my-account'; |
| 152 | } elseif ( $field_id == 'redirect_after_logout_to_slug' ) { |
| 153 | $placeholder = 'e.g. come-visit-again'; |
| 154 | } elseif ( $field_id == 'login_fails_allowed' ) { |
| 155 | $placeholder = '3'; |
| 156 | } elseif ( $field_id == 'login_lockout_maxcount' ) { |
| 157 | $placeholder = '3'; |
| 158 | } else { |
| 159 | $placeholder = ''; |
| 160 | } |
| 161 | |
| 162 | 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; |
| 163 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>'; |
| 164 | |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Render password field as sub-field of a toggle/switcher checkbox |
| 169 | * |
| 170 | * @since 4.1.0 |
| 171 | */ |
| 172 | function render_password_subfield( $args ) { |
| 173 | |
| 174 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 175 | |
| 176 | $field_id = $args['field_id']; |
| 177 | $field_name = $args['field_name']; |
| 178 | $field_type = $args['field_type']; |
| 179 | $field_prefix = $args['field_prefix']; |
| 180 | $field_suffix = $args['field_suffix']; |
| 181 | $field_description = $args['field_description']; |
| 182 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 183 | |
| 184 | if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 185 | $field_classname = ' with-prefix with-suffix'; |
| 186 | } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) { |
| 187 | $field_classname = ' with-prefix'; |
| 188 | } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 189 | $field_classname = ' with-suffix'; |
| 190 | } else { |
| 191 | $field_classname = ''; |
| 192 | } |
| 193 | |
| 194 | $placeholder = ''; |
| 195 | |
| 196 | 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="' . base64_decode( $field_option_value ) . '">' . $field_suffix; |
| 197 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>'; |
| 198 | |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Render number field as sub-field of a toggle/switcher checkbox |
| 203 | * |
| 204 | * @since 1.4.0 |
| 205 | */ |
| 206 | function render_number_subfield( $args ) { |
| 207 | |
| 208 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 209 | |
| 210 | $field_id = $args['field_id']; |
| 211 | $field_name = $args['field_name']; |
| 212 | $field_type = $args['field_type']; |
| 213 | $field_prefix = $args['field_prefix']; |
| 214 | $field_suffix = $args['field_suffix']; |
| 215 | $field_intro = $args['field_intro']; |
| 216 | $field_description = $args['field_description']; |
| 217 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 218 | |
| 219 | if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 220 | $field_classname = ' with-prefix with-suffix'; |
| 221 | } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) { |
| 222 | $field_classname = ' with-prefix'; |
| 223 | } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 224 | $field_classname = ' with-suffix'; |
| 225 | } else { |
| 226 | $field_classname = ''; |
| 227 | } |
| 228 | |
| 229 | if ( ( $field_id == 'revisions_max_number' ) || ( $field_id == 'head_code_priority' ) || ( $field_id == 'body_code_priority' ) || ( $field_id == 'footer_code_priority' ) ) { |
| 230 | $placeholder = '10'; |
| 231 | } else { |
| 232 | $placeholder = ''; |
| 233 | } |
| 234 | |
| 235 | echo '<div class="asenha-subfield-number-wrapper">'; |
| 236 | |
| 237 | if ( ! empty( $field_intro ) ) { |
| 238 | echo '<div class="asenha-subfield-number-intro">' . wp_kses_post( $field_intro ) . '</div>'; |
| 239 | } |
| 240 | |
| 241 | 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>'; |
| 242 | |
| 243 | if ( ! empty( $field_description ) ) { |
| 244 | echo '<div class="asenha-subfield-number-description">' . wp_kses_post( $field_description ) . '</div>'; |
| 245 | } |
| 246 | |
| 247 | echo '</div>'; |
| 248 | |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Render select field as sub-field of a toggle/switcher checkbox |
| 253 | * |
| 254 | * @since 1.4.0 |
| 255 | */ |
| 256 | function render_select_subfield( $args ) { |
| 257 | |
| 258 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 259 | |
| 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 | if ( ! empty( $args['field_select_default'] ) ) { |
| 270 | $default_value = $args['field_select_default']; |
| 271 | } else { |
| 272 | $default_value = false; |
| 273 | } |
| 274 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : $default_value; |
| 275 | |
| 276 | if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 277 | $field_classname = ' with-prefix with-suffix'; |
| 278 | } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) { |
| 279 | $field_classname = ' with-prefix'; |
| 280 | } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) { |
| 281 | $field_classname = ' with-suffix'; |
| 282 | } else { |
| 283 | $field_classname = ''; |
| 284 | } |
| 285 | |
| 286 | if ( $args['display_none_on_load'] ) { |
| 287 | $inline_style = ' style="display:none;"'; |
| 288 | } else { |
| 289 | $inline_style = ''; |
| 290 | } |
| 291 | |
| 292 | echo '<div class="asenha-subfield-select-wrapper">'; |
| 293 | |
| 294 | if ( ! empty( $field_intro ) ) { |
| 295 | echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>'; |
| 296 | } |
| 297 | |
| 298 | echo '<div' . $inline_style . ' class="asenha-subfield-select-inner">' . $field_prefix; |
| 299 | echo '<select name="' . $field_name . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">'; |
| 300 | |
| 301 | foreach ( $field_select_options as $label => $value ) { |
| 302 | echo '<option value="' . $value . '" ' . selected( $value, $field_option_value, false ) . '>' . $label . '</option>'; |
| 303 | } |
| 304 | |
| 305 | echo '</select>'; |
| 306 | echo $field_suffix . '</div>'; |
| 307 | |
| 308 | if ( ! empty( $field_description ) ) { |
| 309 | echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>'; |
| 310 | } |
| 311 | |
| 312 | echo '</div>'; |
| 313 | |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Render textarea field as sub-field of a toggle/switcher checkbox |
| 318 | * |
| 319 | * @since 2.3.0 |
| 320 | */ |
| 321 | function render_textarea_subfield( $args ) { |
| 322 | |
| 323 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 324 | |
| 325 | $field_id = $args['field_id']; |
| 326 | $field_slug = $args['field_slug']; |
| 327 | $field_name = $args['field_name']; |
| 328 | $field_type = $args['field_type']; |
| 329 | $field_intro = $args['field_intro']; |
| 330 | $field_description = $args['field_description']; |
| 331 | |
| 332 | // 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 |
| 333 | if ( 'robots_txt_content' == $field_id ) { |
| 334 | if ( array_key_exists( 'manage_robots_txt', $options ) ) { |
| 335 | if ( ! $options['manage_robots_txt'] ) { // Manage robots.txt feature is NOT enabled |
| 336 | if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) { |
| 337 | $field_option_value = $options['robots_txt_content']; |
| 338 | } else { |
| 339 | $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' ); |
| 340 | $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) ); |
| 341 | $field_option_value = $robots_txt_content; |
| 342 | } |
| 343 | } else { // Manage robots.txt feature is enabled |
| 344 | if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) { |
| 345 | $field_option_value = $options['robots_txt_content']; |
| 346 | } else { |
| 347 | $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' ); |
| 348 | $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) ); |
| 349 | $field_option_value = $robots_txt_content; |
| 350 | } |
| 351 | } |
| 352 | } else { // Manage robots.txt feature has never been enabled yet |
| 353 | $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' ); |
| 354 | $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) ); |
| 355 | $field_option_value = $robots_txt_content; |
| 356 | } |
| 357 | } else { |
| 358 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 359 | } |
| 360 | |
| 361 | echo '<div class="asenha-subfield-textarea-wrapper">'; |
| 362 | |
| 363 | if ( ! empty( $field_intro ) ) { |
| 364 | echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>'; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | echo '<textarea rows="30" class="asenha-subfield-textarea" id="' . esc_attr( $field_name ) . '" name="' . esc_attr( $field_name ) . '">' . esc_textarea( $field_option_value ) . '</textarea>'; |
| 369 | |
| 370 | if ( ! empty( $field_description ) ) { |
| 371 | echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>'; |
| 372 | } |
| 373 | |
| 374 | echo '</div>'; |
| 375 | |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Render sortable menu field |
| 380 | * |
| 381 | * @since 2.0.0 |
| 382 | */ |
| 383 | function render_sortable_menu( $args ) { |
| 384 | |
| 385 | ?> |
| 386 | <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> |
| 387 | <ul id="custom-admin-menu" class="menu ui-sortable"> |
| 388 | <?php |
| 389 | |
| 390 | global $menu; |
| 391 | global $submenu; |
| 392 | $common_methods = new Common_Methods; |
| 393 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 394 | |
| 395 | // Set menu items to be excluded from title renaming. These are from WordPress core. |
| 396 | $renaming_not_allowed = array( 'menu-dashboard', 'menu-pages', 'menu-posts', 'menu-media', 'menu-comments', 'menu-appearance', 'menu-plugins', 'menu-users', 'menu-tools', 'menu-settings' ); |
| 397 | |
| 398 | // Get custom menu item titles |
| 399 | if ( array_key_exists( 'custom_menu_titles', $options ) ) { |
| 400 | $custom_menu_titles = $options['custom_menu_titles']; |
| 401 | $custom_menu_titles = explode( ',', $custom_menu_titles ); |
| 402 | } else { |
| 403 | $custom_menu_titles = array(); |
| 404 | } |
| 405 | |
| 406 | // Get hidden menu items |
| 407 | if ( array_key_exists( 'custom_menu_hidden', $options ) ) { |
| 408 | $hidden_menu = $options['custom_menu_hidden']; |
| 409 | $hidden_menu = explode( ',', $hidden_menu ); |
| 410 | } else { |
| 411 | $hidden_menu = array(); |
| 412 | } |
| 413 | |
| 414 | $i = 1; |
| 415 | |
| 416 | // Check if there's an existing custom menu order data stored in options |
| 417 | |
| 418 | if ( array_key_exists( 'custom_menu_order', $options ) ) { |
| 419 | |
| 420 | $custom_menu = $options['custom_menu_order']; |
| 421 | $custom_menu = explode( ',', $custom_menu ); |
| 422 | |
| 423 | $menu_key_in_use = array(); |
| 424 | |
| 425 | // Render sortables with data in custom menu order |
| 426 | |
| 427 | foreach ( $custom_menu as $custom_menu_item ) { |
| 428 | |
| 429 | foreach ( $menu as $menu_key => $menu_info ) { |
| 430 | |
| 431 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 432 | $menu_item_id = $menu_info[2]; |
| 433 | } else { |
| 434 | $menu_item_id = $menu_info[5]; |
| 435 | } |
| 436 | |
| 437 | if ( $custom_menu_item == $menu_item_id ) { |
| 438 | |
| 439 | ?> |
| 440 | <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 441 | <div class="menu-item-bar"> |
| 442 | <div class="menu-item-handle ui-sortable-handle"> |
| 443 | <div class="item-title"> |
| 444 | <span class="menu-item-title"> |
| 445 | <?php |
| 446 | |
| 447 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 448 | $separator_name = $menu_info[2]; |
| 449 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name ); |
| 450 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 451 | echo '~~ ' . esc_html( $separator_name ) . ' ~~'; |
| 452 | } else { |
| 453 | if ( in_array( $menu_item_id, $renaming_not_allowed ) ) { |
| 454 | // echo wp_kses_post( $menu_info[0] ); |
| 455 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ); |
| 456 | } else { |
| 457 | |
| 458 | // Get defaul/custom menu item title |
| 459 | foreach ( $custom_menu_titles as $custom_menu_title ) { |
| 460 | |
| 461 | // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets |
| 462 | |
| 463 | $custom_menu_title = explode( '__', $custom_menu_title ); |
| 464 | |
| 465 | if ( $custom_menu_title[0] == $menu_item_id ) { |
| 466 | $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] ); // e.g. Code Snippets |
| 467 | break; // stop foreach loop so $menu_item_title is not overwritten in the next iteration |
| 468 | } else { |
| 469 | $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] ); |
| 470 | } |
| 471 | |
| 472 | } |
| 473 | |
| 474 | ?> |
| 475 | <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 ); ?>"> |
| 476 | <?php |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | ?> |
| 481 | </span> |
| 482 | <label class="menu-item-checkbox-label"> |
| 483 | <?php |
| 484 | if ( in_array( $custom_menu_item, $hidden_menu ) ) { |
| 485 | ?> |
| 486 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>" checked> |
| 487 | <span>Hide</span> |
| 488 | <?php |
| 489 | } else { |
| 490 | ?> |
| 491 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 492 | <span>Hide</span> |
| 493 | <?php |
| 494 | } |
| 495 | ?> |
| 496 | </label> |
| 497 | </div> |
| 498 | </div> |
| 499 | </div> |
| 500 | <?php |
| 501 | |
| 502 | $i = 1; |
| 503 | |
| 504 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 505 | ?> |
| 506 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 507 | <?php |
| 508 | |
| 509 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 510 | |
| 511 | $i++; |
| 512 | |
| 513 | // echo $submenu_item[0]; |
| 514 | |
| 515 | } |
| 516 | ?> |
| 517 | </div> |
| 518 | <?php |
| 519 | |
| 520 | } |
| 521 | ?> |
| 522 | </li> |
| 523 | |
| 524 | <?php |
| 525 | |
| 526 | $menu_key_in_use[] = $menu_key; |
| 527 | |
| 528 | } |
| 529 | |
| 530 | } |
| 531 | |
| 532 | } |
| 533 | |
| 534 | // Render the rest of the current menu towards the end of the sortables |
| 535 | |
| 536 | foreach ( $menu as $menu_key => $menu_info ) { |
| 537 | |
| 538 | if ( ! in_array( $menu_key, $menu_key_in_use ) ) { |
| 539 | |
| 540 | $menu_item_id = $menu_info[5]; |
| 541 | $menu_item_title = $menu_info[0]; |
| 542 | |
| 543 | // Exclude Show All/Less toggles |
| 544 | |
| 545 | if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) { |
| 546 | |
| 547 | ?> |
| 548 | <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 549 | <div class="menu-item-bar"> |
| 550 | <div class="menu-item-handle ui-sortable-handle"> |
| 551 | <div class="item-title"> |
| 552 | <span class="menu-item-title"> |
| 553 | <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 ); ?>"> |
| 554 | </span> |
| 555 | <label class="menu-item-checkbox-label"> |
| 556 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 557 | <span>Hide</span> |
| 558 | </label> |
| 559 | </div> |
| 560 | </div> |
| 561 | </div> |
| 562 | <?php |
| 563 | |
| 564 | } |
| 565 | |
| 566 | $i = 1; |
| 567 | |
| 568 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 569 | ?> |
| 570 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 571 | <?php |
| 572 | |
| 573 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 574 | |
| 575 | $i++; |
| 576 | |
| 577 | // echo $submenu_item[0]; |
| 578 | |
| 579 | } |
| 580 | ?> |
| 581 | </div> |
| 582 | <?php |
| 583 | |
| 584 | } |
| 585 | ?> |
| 586 | </li> |
| 587 | |
| 588 | <?php |
| 589 | |
| 590 | } |
| 591 | |
| 592 | } |
| 593 | |
| 594 | } else { |
| 595 | |
| 596 | // Render sortables with existing items in the admin menu |
| 597 | |
| 598 | foreach ( $menu as $menu_key => $menu_info ) { |
| 599 | |
| 600 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 601 | $menu_item_id = $menu_info[2]; |
| 602 | } else { |
| 603 | $menu_item_id = $menu_info[5]; |
| 604 | } |
| 605 | |
| 606 | ?> |
| 607 | <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 608 | <div class="menu-item-bar"> |
| 609 | <div class="menu-item-handle ui-sortable-handle"> |
| 610 | <div class="item-title"> |
| 611 | <span class="menu-item-title"> |
| 612 | <?php |
| 613 | |
| 614 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 615 | $separator_name = $menu_info[2]; |
| 616 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name ); |
| 617 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 618 | echo '~~ ' . esc_html( $separator_name ) . ' ~~'; |
| 619 | } else { |
| 620 | if ( in_array( $menu_item_id, $renaming_not_allowed ) ) { |
| 621 | echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ); |
| 622 | } else { |
| 623 | ?> |
| 624 | <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 ); ?>"> |
| 625 | <?php |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | ?> |
| 630 | </span> |
| 631 | <label class="menu-item-checkbox-label"> |
| 632 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>"> |
| 633 | <span>Hide</span> |
| 634 | </label> |
| 635 | </div> |
| 636 | </div> |
| 637 | </div> |
| 638 | <?php |
| 639 | |
| 640 | $i = 1; |
| 641 | |
| 642 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 643 | ?> |
| 644 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 645 | <?php |
| 646 | |
| 647 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 648 | |
| 649 | $i++; |
| 650 | |
| 651 | // echo $submenu_item[0]; |
| 652 | |
| 653 | } |
| 654 | ?> |
| 655 | </div> |
| 656 | <?php |
| 657 | |
| 658 | } |
| 659 | ?> |
| 660 | </li> |
| 661 | |
| 662 | <?php |
| 663 | |
| 664 | } |
| 665 | |
| 666 | |
| 667 | } |
| 668 | |
| 669 | |
| 670 | ?> |
| 671 | </ul> |
| 672 | <?php |
| 673 | |
| 674 | $field_id = $args['field_id']; |
| 675 | $field_name = $args['field_name']; |
| 676 | $field_description = $args['field_description']; |
| 677 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 678 | |
| 679 | // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes. |
| 680 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 681 | |
| 682 | $field_id = 'custom_menu_titles'; |
| 683 | $field_name = ASENHA_SLUG_U . '['. $field_id .']'; |
| 684 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : ''; |
| 685 | |
| 686 | // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items. |
| 687 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 688 | |
| 689 | $field_id = 'custom_menu_hidden'; |
| 690 | $field_name = ASENHA_SLUG_U . '['. $field_id .']'; |
| 691 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : ''; |
| 692 | |
| 693 | // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes. |
| 694 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 695 | |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Render textarea field as sub-field of a toggle/switcher checkbox |
| 700 | * |
| 701 | * @since 2.3.0 |
| 702 | */ |
| 703 | function render_datatable( $args ) { |
| 704 | |
| 705 | global $wpdb; |
| 706 | |
| 707 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 708 | |
| 709 | $field_id = $args['field_id']; |
| 710 | $field_slug = $args['field_slug']; |
| 711 | $field_name = $args['field_name']; |
| 712 | $field_type = $args['field_type']; |
| 713 | $field_description = $args['field_description']; |
| 714 | $table_title = $args['table_title']; |
| 715 | $table_name = $args['table_name']; |
| 716 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 717 | |
| 718 | ?> |
| 719 | <table id="login-attempts-log" class="wp-list-table widefat striped datatable"> |
| 720 | <thead> |
| 721 | <tr class="datatable-tr"> |
| 722 | <th class="datatable-th">IP Address<br />Last Username</th> |
| 723 | <th class="datatable-th">Attempts<br />Lockouts</th> |
| 724 | <th class="datatable-th">Last Attempt On</th> |
| 725 | </tr> |
| 726 | </thead> |
| 727 | <tbody> |
| 728 | <?php |
| 729 | |
| 730 | $limit = 1000; |
| 731 | |
| 732 | $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) ); |
| 733 | |
| 734 | $entries = $wpdb->get_results( $sql, ARRAY_A ); |
| 735 | |
| 736 | foreach( $entries as $entry ) { |
| 737 | |
| 738 | $unixtime = $entry['unixtime']; |
| 739 | if ( function_exists( 'wp_date' ) ) { |
| 740 | $date = wp_date( 'F j, Y', $unixtime ); |
| 741 | $time = wp_date( 'H:i:s', $unixtime ); |
| 742 | } else { |
| 743 | $date = date_i18n( 'F j, Y', $unixtime ); |
| 744 | $time = date_i18n( 'H:i:s', $unixtime ); |
| 745 | } |
| 746 | ?> |
| 747 | <tr class="datatable-tr"> |
| 748 | <td class="datatable-td"><?php echo esc_html( $entry['ip_address'] ); ?><br /><?php echo esc_html( $entry['username'] ); ?></td> |
| 749 | <td class="datatable-td"><?php echo esc_html( $entry['fail_count'] ); ?><br /><?php echo esc_html( $entry['lockout_count'] ); ?></td> |
| 750 | <td class="datatable-td"><?php echo esc_html( $date ); ?><br /><?php echo esc_html( $time ); ?></td> |
| 751 | </tr> |
| 752 | <?php |
| 753 | } |
| 754 | |
| 755 | ?> |
| 756 | </tbody> |
| 757 | </table> |
| 758 | <?php |
| 759 | |
| 760 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 761 | } |
| 762 | |
| 763 | } |