| @@ -62,9 +62,9 @@ | ||
| 62 | 62 | * @return \WP_Error|\WP_REST_Response |
| 63 | 63 | */ |
| 64 | 64 | public function save_settings( $request ) { |
| 65 | 65 | |
| 66 | - if ( ! $this->current_user_can_access( true ) ) { | |
| 66 | + if ( ! $this->current_user_can_access() ) { | |
| 67 | 67 | return $this->unauthorized(); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if ( ! $this->current_user_token_valid( $request ) ) { |
| @@ -93,10 +93,9 @@ | ||
| 93 | 93 | return $this->save_column_settings( $dbs, $tbl, $settings ); |
| 94 | 94 | case 'rest_api': |
| 95 | 95 | return $this->save_rest_api_settings( $dbs, $tbl, $settings ); |
| 96 | 96 | case 'admin_settings': |
| 97 | - $theme = $request->get_param( 'theme' ); | |
| 98 | - return $this->save_admin_settings( $dbs, $tbl, $settings, $theme ); | |
| 97 | + return $this->save_admin_settings( $dbs, $tbl, $settings ); | |
| 99 | 98 | case 'explorer_settings': |
| 100 | 99 | return $this->save_explorer_settings( $dbs, $tbl, $settings ); |
| 101 | 100 | } |
| 102 | 101 | |
| @@ -173,13 +172,15 @@ | ||
| 173 | 172 | return $this->WPDA_Rest_Response( __( 'Changes successfully saved', 'wp-data-access' ) ); |
| 174 | 173 | } else { |
| 175 | 174 | if ( '' === $wpdb->last_error ) { |
| 176 | 175 | return new \WP_Error( |
| 176 | + /* translators: %s = last dbs error */ | |
| 177 | 177 | sprintf( __( 'Failed to save changes [%s]', 'wp-data-access' ), $wpdb->last_error ), |
| 178 | 178 | array( 'status' => 420 ) |
| 179 | 179 | ); |
| 180 | 180 | } else { |
| 181 | 181 | return new \WP_Error( |
| 182 | + /* translators: %s = last dbs error */ | |
| 182 | 183 | sprintf( __( 'Failed to save changes [%s]', 'wp-data-access' ), $wpdb->last_error ), |
| 183 | 184 | array( 'status' => 420 ) |
| 184 | 185 | ); |
| 185 | 186 | } |
| @@ -226,8 +227,9 @@ | ||
| 226 | 227 | ) { |
| 227 | 228 | return $this->WPDA_Rest_Response( __( 'Changes successfully saved', 'wp-data-access' ) ); |
| 228 | 229 | } else { |
| 229 | 230 | return new \WP_Error( |
| 231 | + /* translators: %s = last dbs error */ | |
| 230 | 232 | sprintf( __( 'Failed to save changes [%s]', 'wp-data-access' ), $wpdb->last_error ), |
| 231 | 233 | array( 'status' => 420 ) |
| 232 | 234 | ); |
| 233 | 235 | } |
| @@ -235,8 +237,9 @@ | ||
| 235 | 237 | if ( WPDA_Table_Settings_Model::insert( $table_name, json_encode( $settings ), $schema_name ) ) { |
| 236 | 238 | return $this->WPDA_Rest_Response( __( 'Changes successfully saved', 'wp-data-access' ) ); |
| 237 | 239 | } else { |
| 238 | 240 | return new \WP_Error( |
| 241 | + /* translators: %s = last dbs error */ | |
| 239 | 242 | sprintf( __( 'Failed to save changes [%s]', 'wp-data-access' ), $wpdb->last_error ), |
| 240 | 243 | array( 'status' => 420 ) |
| 241 | 244 | ); |
| 242 | 245 | } |
| @@ -297,12 +300,15 @@ | ||
| 297 | 300 | $sql_dml = $settings_unused['sql_dml']; |
| 298 | 301 | } |
| 299 | 302 | unset( $settings['unused'] ); |
| 300 | 303 | } |
| 304 | + WPDA::wpda_log_wp_error($settings); | |
| 305 | + WPDA::wpda_log_wp_error($settings_unused); | |
| 301 | 306 | |
| 302 | 307 | if ( null === $sql_dml ) { |
| 303 | 308 | return new \WP_Error( |
| 304 | 309 | sprintf( |
| 310 | + /* translators: %s = contact message */ | |
| 305 | 311 | __( 'Failed to save changes [%s]', 'wp-data-access' ), |
| 306 | 312 | 'please contact the plugin development team' |
| 307 | 313 | ), |
| 308 | 314 | array( 'status' => 420 ) |
| @@ -341,8 +347,9 @@ | ||
| 341 | 347 | global $wpdb; |
| 342 | 348 | $msg = '' !== $wpdb->last_error ? " [{$wpdb->last_error}]" : ''; |
| 343 | 349 | |
| 344 | 350 | return new \WP_Error( |
| 351 | + /* translators: %s = error message */ | |
| 345 | 352 | sprintf( __( 'Failed to save changes [%s]', 'wp-data-access' ), $msg ), |
| 346 | 353 | array( 'status' => 420 ) |
| 347 | 354 | ); |
| 348 | 355 | } |
| @@ -428,8 +435,9 @@ | ||
| 428 | 435 | } |
| 429 | 436 | |
| 430 | 437 | if ( $dml_succeeded >= 0 && $dml_failed === 0 ) { |
| 431 | 438 | return $this->WPDA_Rest_Response( |
| 439 | + /* translators: %s = table name */ | |
| 432 | 440 | sprintf( __( 'Saved dashboard menus for table `%s`', 'wp-data-access' ), $table_name ), |
| 433 | 441 | $new_menus |
| 434 | 442 | ); |
| 435 | 443 | } else { |
| @@ -436,9 +444,10 @@ | ||
| 436 | 444 | global $wpdb; |
| 437 | 445 | $msg = '' !== $wpdb->last_error ? " [{$wpdb->last_error}]" : ''; |
| 438 | 446 | |
| 439 | 447 | return new \WP_Error( |
| 440 | - sprintf( __( 'Cannot save dashboard menus for table `%s`%s', 'wp-data-access' ), $table_name, $msg ), | |
| 448 | + /* translators: 1: table name; 2: error message */ | |
| 449 | + sprintf( __( 'Cannot save dashboard menus for table `%1$s`%2$s', 'wp-data-access' ), $table_name, $msg ), | |
| 441 | 450 | array( 'status' => 420 ) |
| 442 | 451 | ); |
| 443 | 452 | } |
| 444 | 453 | } |
| @@ -489,14 +498,14 @@ | ||
| 489 | 498 | if ( isset( $settings['select'] ) ) { |
| 490 | 499 | unset( $rest_api_settings[ $schema_name ][ $table_name ]['select'] ); |
| 491 | 500 | if ( |
| 492 | 501 | isset( $rest_api_settings[ $schema_name ][ $table_name ] ) && |
| 493 | - 0 === count( $rest_api_settings[ $schema_name ][ $table_name ] )//phpcs:ignore - 8.1 proof | |
| 502 | + 0 === count( $rest_api_settings[ $schema_name ][ $table_name ] ) // phpcs:ignore -- 8.1 proof | |
| 494 | 503 | ) { |
| 495 | 504 | unset( $rest_api_settings[ $schema_name ][ $table_name ] ); |
| 496 | 505 | if ( |
| 497 | 506 | isset( $rest_api_settings[ $schema_name ] ) && |
| 498 | - 0 === count( $rest_api_settings[ $schema_name ] )//phpcs:ignore - 8.1 proof | |
| 507 | + 0 === count( $rest_api_settings[ $schema_name ] ) // phpcs:ignore -- 8.1 proof | |
| 499 | 508 | ) { |
| 500 | 509 | unset( $rest_api_settings[ $schema_name ] ); |
| 501 | 510 | } |
| 502 | 511 | } |
| @@ -509,13 +518,14 @@ | ||
| 509 | 518 | |
| 510 | 519 | update_option( WPDA_API::WPDA_REST_API_TABLE_ACCESS, $rest_api_settings ); |
| 511 | 520 | |
| 512 | 521 | return $this->WPDA_Rest_Response( |
| 522 | + /* translators: %s = table name */ | |
| 513 | 523 | sprintf( __( 'Saved REST API settings for table `%s`', 'wp-data-access' ), $table_name ) |
| 514 | 524 | ); |
| 515 | 525 | } |
| 516 | 526 | |
| 517 | - private function save_admin_settings( $schema_name, $table_name, $settings, $theme ) { | |
| 527 | + private function save_admin_settings( $schema_name, $table_name, $settings ) { | |
| 518 | 528 | if ( |
| 519 | 529 | ! |
| 520 | 530 | ( |
| 521 | 531 | isset( |
| @@ -533,10 +543,9 @@ | ||
| 533 | 543 | 'user' === $settings['scope'] |
| 534 | 544 | ) && |
| 535 | 545 | ( |
| 536 | 546 | 'table' === $settings['target'] || |
| 537 | - 'form' === $settings['target'] || | |
| 538 | - 'theme' === $settings['target'] | |
| 547 | + 'form' === $settings['target'] | |
| 539 | 548 | ) |
| 540 | 549 | |
| 541 | 550 | ) |
| 542 | 551 | ) { |
| @@ -552,17 +561,8 @@ | ||
| 552 | 561 | if ( 'global' === $settings['scope'] ) { |
| 553 | 562 | // Store settings globally. |
| 554 | 563 | if ( null !== $settings['data'] ) { |
| 555 | 564 | update_option( $admin_settings, $settings['data'] ); |
| 556 | - | |
| 557 | - if ( null !== $theme ) { | |
| 558 | - $theme_settings = WPDA_Settings::get_admin_settings_key( | |
| 559 | - 'theme', | |
| 560 | - $schema_name , | |
| 561 | - $table_name | |
| 562 | - ); | |
| 563 | - update_option( $theme_settings, $theme ); | |
| 564 | - } | |
| 565 | 565 | } else { |
| 566 | 566 | delete_option( $admin_settings ); |
| 567 | 567 | } |
| 568 | 568 | } else { |
| @@ -568,17 +568,8 @@ | ||
| 568 | 568 | } else { |
| 569 | 569 | // Store settings for login user. |
| 570 | 570 | if ( null !== $settings['data'] ) { |
| 571 | 571 | update_user_option( $admin_settings, $settings['data'] ); |
| 572 | - | |
| 573 | - if ( null !== $theme ) { | |
| 574 | - $theme_settings = WPDA_Settings::get_admin_settings_key( | |
| 575 | - 'theme', | |
| 576 | - $schema_name , | |
| 577 | - $table_name | |
| 578 | - ); | |
| 579 | - update_user_option( $theme_settings, $theme ); | |
| 580 | - } | |
| 581 | 572 | } else { |
| 582 | 573 | delete_user_option( $admin_settings ); |
| 583 | 574 | } |
| 584 | 575 | } |
| @@ -602,15 +593,8 @@ | ||
| 602 | 593 | $schema_name, |
| 603 | 594 | $table_name |
| 604 | 595 | ) |
| 605 | 596 | ), |
| 606 | - 'theme' => get_option( | |
| 607 | - WPDA_Settings::get_admin_settings_key( | |
| 608 | - 'theme', | |
| 609 | - $schema_name, | |
| 610 | - $table_name | |
| 611 | - ) | |
| 612 | - ), | |
| 613 | 597 | ), |
| 614 | 598 | 'local' => array( |
| 615 | 599 | 'table' => get_user_option( |
| 616 | 600 | WPDA_Settings::get_admin_settings_key( |
| @@ -621,15 +605,8 @@ | ||
| 621 | 605 | ), |
| 622 | 606 | 'form' => get_user_option( |
| 623 | 607 | WPDA_Settings::get_admin_settings_key( |
| 624 | 608 | 'form', |
| 625 | - $schema_name, | |
| 626 | - $table_name | |
| 627 | - ) | |
| 628 | - ), | |
| 629 | - 'theme' => get_user_option( | |
| 630 | - WPDA_Settings::get_admin_settings_key( | |
| 631 | - 'theme', | |
| 632 | 609 | $schema_name, |
| 633 | 610 | $table_name |
| 634 | 611 | ) |
| 635 | 612 | ), |