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