| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDataAccess\Settings { |
| 4 |
|
| 5 |
use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist; |
| 6 |
use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists; |
| 7 |
use WPDataAccess\Utilities\WPDA_Message_Box; |
| 8 |
use WPDataAccess\WPDA; |
| 9 |
|
| 10 |
class WPDA_Settings_BackEnd extends WPDA_Settings { |
| 11 |
|
| 12 |
const WPNONCE_BACKEND_SETTING = 'WPDA_BACKEND_SETTINGS'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Add back-end tab content |
| 16 |
* |
| 17 |
* See class documentation for flow explanation. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
*/ |
| 21 |
protected function add_content() { |
| 22 |
global $wpdb; |
| 23 |
|
| 24 |
if ( isset( $_REQUEST['database'] ) ) { |
| 25 |
$database = sanitize_text_field( wp_unslash( $_REQUEST['database'] ) ); // input var okay. |
| 26 |
} else { |
| 27 |
$database = $wpdb->dbname; |
| 28 |
} |
| 29 |
$is_wp_database = $database === $wpdb->dbname; |
| 30 |
|
| 31 |
if ( isset( $_REQUEST['action'] ) ) { |
| 32 |
$action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // input var okay. |
| 33 |
|
| 34 |
// Security check. |
| 35 |
$wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. |
| 36 |
if ( ! wp_verify_nonce( $wp_nonce, 'wpda-back-end-settings' ) ) { |
| 37 |
wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); |
| 38 |
} |
| 39 |
|
| 40 |
if ( 'save' === $action ) { |
| 41 |
// Save options. |
| 42 |
if ( $is_wp_database ) { |
| 43 |
WPDA::set_option( |
| 44 |
WPDA::OPTION_BE_TABLE_ACCESS, |
| 45 |
isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay. |
| 46 |
); |
| 47 |
} else { |
| 48 |
update_option( |
| 49 |
WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $database, |
| 50 |
isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay. |
| 51 |
);} |
| 52 |
|
| 53 |
$wpda_hide_manage_link = array(); |
| 54 |
if ( isset( $_REQUEST['wpda_hide_manage_link'] ) ) { |
| 55 |
foreach ( $_REQUEST['wpda_hide_manage_link'] as $userid ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
| 56 |
if ( is_numeric( $userid ) ) { |
| 57 |
$wpda_hide_manage_link[] = sanitize_text_field( wp_unslash( $userid ) ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
update_option( 'wpda_hide_manage_link', $wpda_hide_manage_link ); |
| 62 |
|
| 63 |
$table_access_selected_new_value = isset( $_REQUEST['table_access_selected'] ) ? |
| 64 |
WPDA::sanitize_text_field_array( $_REQUEST['table_access_selected'] ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
| 65 |
if ( is_array( $table_access_selected_new_value ) ) { |
| 66 |
// Check the requested table names for sql injection. This is simply done by checking if the table |
| 67 |
// name exists in our WordPress database. |
| 68 |
$table_access_selected_new_value_checked = array(); |
| 69 |
foreach ( $table_access_selected_new_value as $key => $value ) { |
| 70 |
$wpda_dictionary_checks = new WPDA_Dictionary_Exist( $database, $value ); |
| 71 |
if ( $wpda_dictionary_checks->table_exists( false ) ) { |
| 72 |
// Add existing table to list. |
| 73 |
$table_access_selected_new_value_checked[ $key ] = $value; |
| 74 |
} else { |
| 75 |
// An invalid table name was provided. Might be an sql injection attack or an invalid state. |
| 76 |
wp_die( __( 'ERROR: Invalid table name', 'wp-data-access' ) ); |
| 77 |
} |
| 78 |
} |
| 79 |
} else { |
| 80 |
$table_access_selected_new_value_checked = ''; |
| 81 |
} |
| 82 |
if ( $is_wp_database ) { |
| 83 |
WPDA::set_option( |
| 84 |
WPDA::OPTION_BE_TABLE_ACCESS_SELECTED, |
| 85 |
$table_access_selected_new_value_checked |
| 86 |
); |
| 87 |
} else { |
| 88 |
update_option( |
| 89 |
WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $database, |
| 90 |
$table_access_selected_new_value_checked |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
WPDA::set_option( |
| 95 |
WPDA::OPTION_BE_VIEW_LINK, |
| 96 |
isset( $_REQUEST['view_link'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['view_link'] ) ) : 'off' // input var okay. |
| 97 |
); |
| 98 |
|
| 99 |
WPDA::set_option( |
| 100 |
WPDA::OPTION_BE_ALLOW_INSERT, |
| 101 |
isset( $_REQUEST['allow_insert'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_insert'] ) ) : 'off' // input var okay. |
| 102 |
); |
| 103 |
WPDA::set_option( |
| 104 |
WPDA::OPTION_BE_ALLOW_UPDATE, |
| 105 |
isset( $_REQUEST['allow_update'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_update'] ) ) : 'off' // input var okay. |
| 106 |
); |
| 107 |
WPDA::set_option( |
| 108 |
WPDA::OPTION_BE_ALLOW_DELETE, |
| 109 |
isset( $_REQUEST['allow_delete'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_delete'] ) ) : 'off' // input var okay. |
| 110 |
); |
| 111 |
|
| 112 |
WPDA::set_option( |
| 113 |
WPDA::OPTION_BE_EXPORT_ROWS, |
| 114 |
isset( $_REQUEST['export_rows'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['export_rows'] ) ) : 'off' // input var okay. |
| 115 |
); |
| 116 |
WPDA::set_option( |
| 117 |
WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX, |
| 118 |
isset( $_REQUEST['export_variable_rows'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['export_variable_rows'] ) ) : 'off' // input var okay. |
| 119 |
); |
| 120 |
|
| 121 |
WPDA::set_option( |
| 122 |
WPDA::OPTION_BE_ALLOW_IMPORTS, |
| 123 |
isset( $_REQUEST['allow_imports'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_imports'] ) ) : 'off' // input var okay. |
| 124 |
); |
| 125 |
|
| 126 |
WPDA::set_option( |
| 127 |
WPDA::OPTION_BE_CONFIRM_EXPORT, |
| 128 |
isset( $_REQUEST['confirm_export'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['confirm_export'] ) ) : 'off' // input var okay. |
| 129 |
); |
| 130 |
WPDA::set_option( |
| 131 |
WPDA::OPTION_BE_CONFIRM_VIEW, |
| 132 |
isset( $_REQUEST['confirm_view'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['confirm_view'] ) ) : 'off' // input var okay. |
| 133 |
); |
| 134 |
|
| 135 |
WPDA::set_option( |
| 136 |
WPDA::OPTION_BE_PAGINATION, |
| 137 |
isset( $_REQUEST['pagination'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pagination'] ) ) : null // input var okay. |
| 138 |
); |
| 139 |
|
| 140 |
WPDA::set_option( |
| 141 |
WPDA::OPTION_BE_REMEMBER_SEARCH, |
| 142 |
isset( $_REQUEST['remember_search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remember_search'] ) ) : 'off' // input var okay. |
| 143 |
); |
| 144 |
|
| 145 |
WPDA::set_option( |
| 146 |
WPDA::OPTION_BE_INNODB_COUNT, |
| 147 |
isset( $_REQUEST['innodb_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['innodb_count'] ) ) : 100000 // input var okay. |
| 148 |
); |
| 149 |
|
| 150 |
WPDA::set_option( |
| 151 |
WPDA::OPTION_BE_DESIGN_MODE, |
| 152 |
isset( $_REQUEST['design_mode'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['design_mode'] ) ) : 'basic' // input var okay. |
| 153 |
); |
| 154 |
|
| 155 |
WPDA::set_option( |
| 156 |
WPDA::OPTION_BE_TEXT_WRAP_SWITCH, |
| 157 |
isset( $_REQUEST['text_wrap_switch'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['text_wrap_switch'] ) ) : 'off' // input var okay. |
| 158 |
); |
| 159 |
|
| 160 |
WPDA::set_option( |
| 161 |
WPDA::OPTION_BE_TEXT_WRAP, |
| 162 |
isset( $_REQUEST['text_wrap'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['text_wrap'] ) ) : 400 // input var okay. |
| 163 |
); |
| 164 |
|
| 165 |
if ( |
| 166 |
isset( $_REQUEST['wpda_default_user'] ) && |
| 167 |
isset( $_REQUEST['wpda_default_database'] ) && |
| 168 |
'' !== $_REQUEST['wpda_default_user'] && |
| 169 |
'' !== $_REQUEST['wpda_default_database'] |
| 170 |
) { |
| 171 |
$default_databases = get_option( 'wpda_default_database' ); |
| 172 |
if ( false === $default_databases ) { |
| 173 |
$default_databases = array(); |
| 174 |
} |
| 175 |
$wpda_default_user = sanitize_text_field( wp_unslash( $_REQUEST['wpda_default_user'] ) ); // input var okay. |
| 176 |
$wpda_default_database = sanitize_text_field( wp_unslash( $_REQUEST['wpda_default_database'] ) ); // input var okay. |
| 177 |
|
| 178 |
$default_databases[ $wpda_default_user ] = $wpda_default_database; |
| 179 |
update_option( 'wpda_default_database', $default_databases ); |
| 180 |
} |
| 181 |
|
| 182 |
WPDA::set_option( |
| 183 |
WPDA::OPTION_BE_HIDE_BUTTON_ICONS, |
| 184 |
isset( $_REQUEST['hide_button_icons'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['hide_button_icons'] ) ) : 'off' // input var okay. |
| 185 |
); |
| 186 |
} elseif ( 'setdefaults' === $action ) { |
| 187 |
// Set all back-end settings back to default. |
| 188 |
if ( $is_wp_database ) { |
| 189 |
WPDA::set_option( WPDA::OPTION_BE_TABLE_ACCESS ); |
| 190 |
WPDA::set_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED ); |
| 191 |
} else { |
| 192 |
update_option( |
| 193 |
WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $database, |
| 194 |
'show' |
| 195 |
); |
| 196 |
update_option( |
| 197 |
WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $database, |
| 198 |
'' |
| 199 |
); |
| 200 |
} |
| 201 |
update_option( 'wpda_hide_manage_link', array() ); |
| 202 |
WPDA::set_option( WPDA::OPTION_BE_VIEW_LINK ); |
| 203 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_INSERT ); |
| 204 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_UPDATE ); |
| 205 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_DELETE ); |
| 206 |
WPDA::set_option( WPDA::OPTION_BE_EXPORT_ROWS ); |
| 207 |
WPDA::set_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX ); |
| 208 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_IMPORTS ); |
| 209 |
WPDA::set_option( WPDA::OPTION_BE_CONFIRM_EXPORT ); |
| 210 |
WPDA::set_option( WPDA::OPTION_BE_CONFIRM_VIEW ); |
| 211 |
WPDA::set_option( WPDA::OPTION_BE_PAGINATION ); |
| 212 |
WPDA::set_option( WPDA::OPTION_BE_REMEMBER_SEARCH ); |
| 213 |
WPDA::set_option( WPDA::OPTION_BE_INNODB_COUNT ); |
| 214 |
WPDA::set_option( WPDA::OPTION_BE_DESIGN_MODE ); |
| 215 |
WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH ); |
| 216 |
WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP ); |
| 217 |
update_option( 'wpda_default_database', array() ); |
| 218 |
WPDA::set_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); |
| 219 |
} elseif ( 'delete_default_user_database' === $action ) { |
| 220 |
if ( isset( $_REQUEST['wpda_default_database_delete'] ) ) { |
| 221 |
$delete_user_id = sanitize_text_field( wp_unslash( $_REQUEST['wpda_default_database_delete'] ) ); // input var okay. |
| 222 |
|
| 223 |
$default_databases = get_option( 'wpda_default_database' ); |
| 224 |
if ( false !== $default_databases && isset( $default_databases[ $delete_user_id ] ) ) { |
| 225 |
unset( $default_databases[ $delete_user_id ] ); |
| 226 |
update_option( 'wpda_default_database', $default_databases ); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
$msg = new WPDA_Message_Box( |
| 232 |
array( |
| 233 |
'message_text' => __( 'Settings saved', 'wp-data-access' ), |
| 234 |
) |
| 235 |
); |
| 236 |
$msg->box(); |
| 237 |
} |
| 238 |
|
| 239 |
// Get options. |
| 240 |
if ( $is_wp_database ) { |
| 241 |
$table_access = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS ); |
| 242 |
$table_access_selected = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED ); |
| 243 |
} else { |
| 244 |
$table_access = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $database ); |
| 245 |
if ( false === $table_access ) { |
| 246 |
$table_access = 'show'; |
| 247 |
} |
| 248 |
$table_access_selected = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $database ); |
| 249 |
if ( false === $table_access_selected ) { |
| 250 |
$table_access_selected = ''; |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
if ( is_array( $table_access_selected ) ) { |
| 255 |
// Convert table for simple access. |
| 256 |
$table_access_selected_by_name = array(); |
| 257 |
foreach ( $table_access_selected as $key => $value ) { |
| 258 |
$table_access_selected_by_name[ $value ] = true; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
$wpda_hide_manage_link = get_option( 'wpda_hide_manage_link' ); |
| 263 |
if ( is_array( $wpda_hide_manage_link ) ) { |
| 264 |
$wpda_hide_manage_list = array_flip( $wpda_hide_manage_link ); //phpcs:ignore - 8.1 proof |
| 265 |
} else { |
| 266 |
$wpda_hide_manage_list = array(); |
| 267 |
} |
| 268 |
|
| 269 |
$view_link = WPDA::get_option( WPDA::OPTION_BE_VIEW_LINK ); |
| 270 |
|
| 271 |
$allow_insert = WPDA::get_option( WPDA::OPTION_BE_ALLOW_INSERT ); |
| 272 |
$allow_update = WPDA::get_option( WPDA::OPTION_BE_ALLOW_UPDATE ); |
| 273 |
$allow_delete = WPDA::get_option( WPDA::OPTION_BE_ALLOW_DELETE ); |
| 274 |
|
| 275 |
$export_rows = WPDA::get_option( WPDA::OPTION_BE_EXPORT_ROWS ); |
| 276 |
$export_variable_rows = WPDA::get_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX ); |
| 277 |
|
| 278 |
$allow_imports = WPDA::get_option( WPDA::OPTION_BE_ALLOW_IMPORTS ); |
| 279 |
|
| 280 |
$confirm_export = WPDA::get_option( WPDA::OPTION_BE_CONFIRM_EXPORT ); |
| 281 |
$confirm_view = WPDA::get_option( WPDA::OPTION_BE_CONFIRM_VIEW ); |
| 282 |
|
| 283 |
$pagination = WPDA::get_option( WPDA::OPTION_BE_PAGINATION ); |
| 284 |
|
| 285 |
$remember_search = WPDA::get_option( WPDA::OPTION_BE_REMEMBER_SEARCH ); |
| 286 |
|
| 287 |
$innodb_count = WPDA::get_option( WPDA::OPTION_BE_INNODB_COUNT ); |
| 288 |
|
| 289 |
$design_mode = WPDA::get_option( WPDA::OPTION_BE_DESIGN_MODE ); |
| 290 |
|
| 291 |
$text_wrap_switch = WPDA::get_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH ); |
| 292 |
$text_wrap = WPDA::get_option( WPDA::OPTION_BE_TEXT_WRAP ); |
| 293 |
|
| 294 |
$hide_button_icons = WPDA::get_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); |
| 295 |
?> |
| 296 |
<form id="wpda_settings_backend" method="post" |
| 297 |
action="?page=<?php echo esc_attr( $this->page ); ?>&tab=backend"> |
| 298 |
<table class="wpda-table-settings"> |
| 299 |
<tr> |
| 300 |
<th><?php echo __( 'Table access', 'wp-data-access' ); ?></th> |
| 301 |
<td> |
| 302 |
<select name="database" id="schema_name"> |
| 303 |
<?php |
| 304 |
$schema_names = WPDA_Dictionary_Lists::get_db_schemas(); |
| 305 |
foreach ( $schema_names as $schema_name ) { |
| 306 |
$selected = $database === $schema_name['schema_name'] ? ' selected' : ''; |
| 307 |
echo "<option value='{$schema_name['schema_name']}'$selected>{$schema_name['schema_name']}</option>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 308 |
} |
| 309 |
?> |
| 310 |
</select> |
| 311 |
<br/><br/> |
| 312 |
<label> |
| 313 |
<input |
| 314 |
type="radio" |
| 315 |
name="table_access" |
| 316 |
value="show" |
| 317 |
<?php echo 'show' === $table_access ? 'checked' : ''; ?> |
| 318 |
><?php echo $is_wp_database ? __( 'Show WordPress tables', 'wp-data-access' ) : __( 'Show all tables', 'wp-data-access' ); ?> |
| 319 |
</label> |
| 320 |
<br/> |
| 321 |
<?php |
| 322 |
if ( $is_wp_database ) { |
| 323 |
?> |
| 324 |
<label> |
| 325 |
<input |
| 326 |
type="radio" |
| 327 |
name="table_access" |
| 328 |
value="hide" |
| 329 |
<?php echo 'hide' === $table_access ? 'checked' : ''; ?> |
| 330 |
><?php echo __( 'Hide WordPress tables', 'wp-data-access' ); ?> |
| 331 |
</label> |
| 332 |
<br/> |
| 333 |
<?php |
| 334 |
} |
| 335 |
?> |
| 336 |
<label> |
| 337 |
<input |
| 338 |
type="radio" |
| 339 |
name="table_access" |
| 340 |
value="select" |
| 341 |
<?php echo 'select' === $table_access ? 'checked' : ''; ?> |
| 342 |
><?php echo __( 'Show only selected tables', 'wp-data-access' ); ?> |
| 343 |
</label> |
| 344 |
<div id="tables_selected" <?php echo 'select' === $table_access ? '' : 'style="display:none"'; ?>> |
| 345 |
<br/> |
| 346 |
<select name="table_access_selected[]" multiple size="10"> |
| 347 |
<?php |
| 348 |
$tables = WPDA_Dictionary_Lists::get_tables( true, $database ); |
| 349 |
foreach ( $tables as $table ) { |
| 350 |
$table_name = $table['table_name']; |
| 351 |
?> |
| 352 |
<option value="<?php echo esc_attr( $table_name ); ?>" <?php echo isset( $table_access_selected_by_name[ $table_name ] ) ? 'selected' : ''; ?>><?php echo esc_attr( $table_name ); ?></option> |
| 353 |
<?php |
| 354 |
} |
| 355 |
?> |
| 356 |
</select> |
| 357 |
</div> |
| 358 |
<script type='text/javascript'> |
| 359 |
jQuery(function () { |
| 360 |
jQuery("input[name='table_access']").on("click", function () { |
| 361 |
if (this.value == 'select') { |
| 362 |
jQuery("#tables_selected").show(); |
| 363 |
} else { |
| 364 |
jQuery("#tables_selected").hide(); |
| 365 |
} |
| 366 |
}); |
| 367 |
jQuery('#schema_name').on('change', function() { |
| 368 |
window.location = '?page=<?php echo esc_attr( $this->page ); ?>&tab=backend&database=' + jQuery(this).val(); |
| 369 |
}); |
| 370 |
}); |
| 371 |
</script> |
| 372 |
</td> |
| 373 |
</tr> |
| 374 |
<tr> |
| 375 |
<th><?php echo __( 'Restrict table management', 'wp-data-access' ); ?></th> |
| 376 |
<td> |
| 377 |
<select name="wpda_hide_manage_link[]" multiple="true"> |
| 378 |
<?php |
| 379 |
foreach ( get_users( array( 'role' => 'administrator' ) ) as $user ) { |
| 380 |
$selected = isset( $wpda_hide_manage_list[ $user->ID ] ) ? 'selected' : ''; |
| 381 |
echo "<option value='{$user->ID}' {$selected}>{$user->user_login} ({$user->user_email})</option>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 382 |
} |
| 383 |
?> |
| 384 |
</select> |
| 385 |
<div style="margin-top:5px;margin-left:-5px"> |
| 386 |
<span class="dashicons dashicons-yes"></span> |
| 387 |
Removes the manage link in the Data Explorer for selected admin users |
| 388 |
</div> |
| 389 |
<div style="margin-left:-5px"> |
| 390 |
<span class="dashicons dashicons-yes"></span> |
| 391 |
Hold control key to deselect or select multiple users |
| 392 |
</div> |
| 393 |
<div style="margin-left:-5px"> |
| 394 |
<span class="dashicons dashicons-yes"></span> |
| 395 |
Non admin users have no access by default |
| 396 |
</div> |
| 397 |
<div style="margin-left:-5px"> |
| 398 |
<span class="dashicons dashicons-yes"></span> |
| 399 |
Every administrator can change this option |
| 400 |
</div> |
| 401 |
</td> |
| 402 |
</tr> |
| 403 |
<tr> |
| 404 |
<th><?php echo __( 'Row access', 'wp-data-access' ); ?></th> |
| 405 |
<td> |
| 406 |
<label> |
| 407 |
<input |
| 408 |
type="checkbox" |
| 409 |
name="view_link" |
| 410 |
<?php echo 'on' === $view_link ? 'checked' : ''; ?> |
| 411 |
><?php echo __( 'Add view link to list table', 'wp-data-access' ); ?> |
| 412 |
</label> |
| 413 |
</td> |
| 414 |
</tr> |
| 415 |
<tr> |
| 416 |
<th scope="row"><?php echo __( 'Allow transactions?', 'wp-data-access' ); ?></th> |
| 417 |
<td> |
| 418 |
<label> |
| 419 |
<input type="checkbox" name="allow_insert" |
| 420 |
<?php echo 'on' === $allow_insert ? 'checked' : ''; ?> /><?php echo __( 'Allow insert', 'wp-data-access' ); ?> |
| 421 |
</label> |
| 422 |
<br/> |
| 423 |
<label> |
| 424 |
<input type="checkbox" name="allow_update" |
| 425 |
<?php echo 'on' === $allow_update ? 'checked' : ''; ?> /><?php echo __( 'Allow update', 'wp-data-access' ); ?> |
| 426 |
</label> |
| 427 |
<br/> |
| 428 |
<label> |
| 429 |
<input type="checkbox" name="allow_delete" |
| 430 |
<?php echo 'on' === $allow_delete ? 'checked' : ''; ?> /><?php echo __( 'Allow delete', 'wp-data-access' ); ?> |
| 431 |
</label> |
| 432 |
</td> |
| 433 |
</tr> |
| 434 |
<tr> |
| 435 |
<th scope="row"><?php echo __( 'Allow exports?', 'wp-data-access' ); ?></th> |
| 436 |
<td> |
| 437 |
<label> |
| 438 |
<input type="checkbox" name="export_rows" |
| 439 |
<?php echo 'on' === $export_rows ? 'checked' : ''; ?> /><?php echo __( 'Allow row export', 'wp-data-access' ); ?> |
| 440 |
</label> |
| 441 |
<br/> |
| 442 |
<label> |
| 443 |
<input type="checkbox" name="export_variable_rows" |
| 444 |
<?php echo 'on' === $export_variable_rows ? 'checked' : ''; ?> /><?php echo __( 'Export with variable WP prefix', 'wp-data-access' ); ?> |
| 445 |
</label> |
| 446 |
</td> |
| 447 |
</tr> |
| 448 |
<tr> |
| 449 |
<th scope="row"><?php echo __( 'Allow imports?', 'wp-data-access' ); ?></th> |
| 450 |
<td> |
| 451 |
<label> |
| 452 |
<input type="checkbox" name="allow_imports" |
| 453 |
<?php echo 'on' === $allow_imports ? 'checked' : ''; ?> /><?php echo __( 'Allow to import scripts from Data Explorer table pages', 'wp-data-access' ); ?> |
| 454 |
</label> |
| 455 |
</td> |
| 456 |
</tr> |
| 457 |
<tr> |
| 458 |
<th><?php echo __( 'Ask for confirmation?', 'wp-data-access' ); ?></th> |
| 459 |
<td> |
| 460 |
<label> |
| 461 |
<input type="checkbox" name="confirm_export" |
| 462 |
<?php echo 'on' === $confirm_export ? 'checked' : ''; ?> /><?php echo __( 'When starting export', 'wp-data-access' ); ?> |
| 463 |
</label> |
| 464 |
<br/> |
| 465 |
<label> |
| 466 |
<input type="checkbox" name="confirm_view" |
| 467 |
<?php echo 'on' === $confirm_view ? 'checked' : ''; ?> /><?php echo __( 'When viewing non WPDA table', 'wp-data-access' ); ?> |
| 468 |
</label> |
| 469 |
</td> |
| 470 |
</tr> |
| 471 |
<tr> |
| 472 |
<th><?php echo __( 'Default pagination value', 'wp-data-access' ); ?></th> |
| 473 |
<td> |
| 474 |
<input |
| 475 |
type="number" step="1" min="1" max="999" name="pagination" maxlength="3" |
| 476 |
value="<?php echo esc_attr( $pagination ); ?>"> |
| 477 |
</td> |
| 478 |
</tr> |
| 479 |
<tr> |
| 480 |
<th><?php echo __( 'Search box', 'wp-data-access' ); ?></th> |
| 481 |
<td> |
| 482 |
<label> |
| 483 |
<input |
| 484 |
type="checkbox" |
| 485 |
name="remember_search" <?php echo 'on' === $remember_search ? 'checked' : ''; ?> |
| 486 |
><?php echo __( 'Remember last search', 'wp-data-access' ); ?> |
| 487 |
</label> |
| 488 |
</td> |
| 489 |
</tr> |
| 490 |
<tr> |
| 491 |
<th><?php echo __( 'Max row count', 'wp-data-access' ); ?></th> |
| 492 |
<td> |
| 493 |
<input |
| 494 |
type="number" step="1" min="1" max="999999" name="innodb_count" maxlength="3" |
| 495 |
value="<?php echo esc_attr( $innodb_count ); ?>"> |
| 496 |
<p> |
| 497 |
<strong>This works for InnoDB tables and views only!</strong> |
| 498 |
</p> |
| 499 |
<p> |
| 500 |
The real row count is shown for other table types. |
| 501 |
</p> |
| 502 |
<p> |
| 503 |
<strong>BEHAVIOUR</strong><br/> |
| 504 |
IF estimated row count > max row count:<br/> |
| 505 |
use estimated row count<br/> |
| 506 |
ELSE<br/> |
| 507 |
user real row count |
| 508 |
</p> |
| 509 |
<p> |
| 510 |
Showing the estimated row count instead of the real row count <strong>improves performance</strong> |
| 511 |
for <strong>large tables and views</strong>. |
| 512 |
An estimated row count is <strong>less accurate</strong> than a real row count. |
| 513 |
</p> |
| 514 |
<p> |
| 515 |
This option can be changed for InnoDB tables and views in the Data Explorer:<br/> |
| 516 |
WP Data Access > Data Explorer > YOUR TABLE > Manage > Settings > Table Settings > Row count |
| 517 |
</p> |
| 518 |
</td> |
| 519 |
</tr> |
| 520 |
<tr> |
| 521 |
<th><?php echo __( 'Default designer mode', 'wp-data-access' ); ?></th> |
| 522 |
<td> |
| 523 |
<select name="design_mode"> |
| 524 |
<option value="basic" <?php echo 'basic' === $design_mode ? 'selected' : ''; ?>>Basic |
| 525 |
</option> |
| 526 |
<option value="advanced" <?php echo 'advanced' === $design_mode ? 'selected' : ''; ?>> |
| 527 |
Advanced |
| 528 |
</option> |
| 529 |
</select> |
| 530 |
</td> |
| 531 |
</tr> |
| 532 |
<tr> |
| 533 |
<th><?php echo __( 'Content wrap', 'wp-data-access' ); ?></th> |
| 534 |
<td> |
| 535 |
<label> |
| 536 |
<input |
| 537 |
type="checkbox" |
| 538 |
name="text_wrap_switch" <?php echo 'on' === $text_wrap_switch ? 'checked' : ''; ?> |
| 539 |
><?php echo __( 'No content wrap', 'wp-data-access' ); ?> |
| 540 |
</label> |
| 541 |
<br/> |
| 542 |
<input |
| 543 |
type="number" step="1" min="1" max="999999" name="text_wrap" maxlength="3" |
| 544 |
value="<?php echo esc_attr( $text_wrap ); ?>"> |
| 545 |
</td> |
| 546 |
</tr> |
| 547 |
<tr> |
| 548 |
<th><?php echo __( 'Default database', 'wp-data-access' ); ?></th> |
| 549 |
<td> |
| 550 |
<div> |
| 551 |
<?php |
| 552 |
$users = array(); |
| 553 |
foreach ( get_users() as $user ) { |
| 554 |
$users[ $user->data->ID ] = $user->data->user_login; |
| 555 |
} |
| 556 |
|
| 557 |
$databases = array(); |
| 558 |
$db_databases = WPDA_Dictionary_Lists::get_db_schemas(); |
| 559 |
foreach ( $db_databases as $db_database ) { |
| 560 |
$databases[ $db_database['schema_name'] ] = true; |
| 561 |
} |
| 562 |
|
| 563 |
$default_databases = get_option( 'wpda_default_database' ); |
| 564 |
if ( false === $default_databases ) { |
| 565 |
$default_databases = array(); |
| 566 |
} |
| 567 |
if ( is_array( $default_databases ) ) { |
| 568 |
foreach ( $default_databases as $user_id => $database ) { |
| 569 |
?> |
| 570 |
<div id="wpda_default_database_<?php echo esc_attr( $user_id ); ?>"> |
| 571 |
<span class="dashicons dashicons-trash" |
| 572 |
style="font-size: 14px; vertical-align: text-top; cursor: pointer;" |
| 573 |
onclick="if (confirm('Remove default database for this user?')) { jQuery('#wpda_default_database_delete').val('<?php echo esc_attr( $user_id ); ?>'); jQuery('#delete_default_user_database_form').submit(); } " |
| 574 |
></span> |
| 575 |
<span> |
| 576 |
<?php echo esc_attr( $users[ $user_id ] ); ?> > <?php echo esc_attr( $database ); ?> |
| 577 |
</span> |
| 578 |
</div> |
| 579 |
<?php |
| 580 |
} |
| 581 |
} |
| 582 |
?> |
| 583 |
</div> |
| 584 |
<?php |
| 585 |
if ( count( $default_databases ) > 0 ) {//phpcs:ignore - 8.1 proof |
| 586 |
echo '<br/>'; |
| 587 |
} |
| 588 |
?> |
| 589 |
<div> |
| 590 |
<a href="javascript:void(0)" onclick="jQuery('#list_default_databases').show()" class="button">Define default database for user in Data Explorer</a> |
| 591 |
</div> |
| 592 |
<div id="list_default_databases" style="display:none"> |
| 593 |
<br/> |
| 594 |
<div> |
| 595 |
<label for="wpda_default_user">User: </label> |
| 596 |
<select name="wpda_default_user" id="wpda_default_user"> |
| 597 |
<option value="">Select user</option> |
| 598 |
<?php |
| 599 |
foreach ( get_users() as $user ) { |
| 600 |
echo '<option value="' . esc_attr( $user->data->ID ) . '">' . esc_attr( $user->data->user_login ) . '</option>'; |
| 601 |
} |
| 602 |
?> |
| 603 |
</select> |
| 604 |
<label for="wpda_default_database">Database: </label> |
| 605 |
<select name="wpda_default_database" id="wpda_default_database"> |
| 606 |
<option value="">Select database</option> |
| 607 |
<?php |
| 608 |
foreach ( $databases as $database => $value ) { |
| 609 |
echo '<option value="' . esc_attr( $database ) . '">' . esc_attr( $database ) . '</option>'; |
| 610 |
} |
| 611 |
?> |
| 612 |
</select> |
| 613 |
<span class="dashicons dashicons-trash" |
| 614 |
style="font-size: 14px; vertical-align: text-top; cursor: pointer;" |
| 615 |
onclick="jQuery('#list_default_databases').hide(); jQuery('#wpda_default_user').val(''); jQuery('#wpda_default_database').val('');" |
| 616 |
></span> |
| 617 |
</div> |
| 618 |
</div> |
| 619 |
</td> |
| 620 |
</tr> |
| 621 |
<tr> |
| 622 |
<th><?php echo __( 'Hide button icons', 'wp-data-access' ); ?></th> |
| 623 |
<td> |
| 624 |
<label> |
| 625 |
<input |
| 626 |
type="checkbox" |
| 627 |
name="hide_button_icons" <?php echo 'on' === $hide_button_icons ? 'checked' : ''; ?> |
| 628 |
><?php echo __( 'Hide icons on admin buttons', 'wp-data-access' ); ?> |
| 629 |
</label> |
| 630 |
</td> |
| 631 |
</tr> |
| 632 |
</table> |
| 633 |
<div class="wpda-table-settings-button"> |
| 634 |
<input type="hidden" name="action" value="save"/> |
| 635 |
<button type="submit" class="button button-primary"> |
| 636 |
<i class="fas fa-check wpda_icon_on_button"></i> |
| 637 |
<?php echo __( 'Save Back-end Settings', 'wp-data-access' ); ?> |
| 638 |
</button> |
| 639 |
<a href="javascript:void(0)" |
| 640 |
onclick="if (confirm('<?php echo __( 'Reset to defaults?', 'wp-data-access' ); ?>')) { |
| 641 |
jQuery('input[name="action"]').val('setdefaults'); |
| 642 |
jQuery('#wpda_settings_backend').trigger('submit') |
| 643 |
}" |
| 644 |
class="button"> |
| 645 |
<i class="fas fa-times-circle wpda_icon_on_button"></i> |
| 646 |
<?php echo __( 'Reset Back-end Settings To Defaults', 'wp-data-access' ); ?> |
| 647 |
</a> |
| 648 |
</div> |
| 649 |
<?php wp_nonce_field( 'wpda-back-end-settings', '_wpnonce', false ); ?> |
| 650 |
</form> |
| 651 |
<form id="delete_default_user_database_form" |
| 652 |
method="post" |
| 653 |
action="?page=<?php echo esc_attr( $this->page ); ?>&tab=backend" |
| 654 |
style="display:none"> |
| 655 |
<input type="hidden" name="wpda_default_database_delete" id="wpda_default_database_delete" value=""/> |
| 656 |
<input type="hidden" name="action" value="delete_default_user_database"/> |
| 657 |
<?php wp_nonce_field( 'wpda-back-end-settings', '_wpnonce', false ); ?> |
| 658 |
</form> |
| 659 |
<?php |
| 660 |
} |
| 661 |
|
| 662 |
} |
| 663 |
|
| 664 |
} |
| 665 |
|