Skip to content

Second issue #2505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eaa8006
coding exercise answers
Mar 23, 2024
112a299
coding exercise remove linting
Mar 27, 2024
8903193
remove lodash comments
corsacca Mar 28, 2024
4a72a59
initial push for first issue
Apr 1, 2024
e0f9d52
Merge branch 'develop' of https://github.com/CptHappyHands/disciple-t…
Apr 1, 2024
6af1b82
markdown sans images working
Apr 14, 2024
258cb80
pushing changes for troubleshooting
May 15, 2024
6488e33
Merge branch 'refs/heads/develop' into second-issue
corsacca May 17, 2024
2ae67b1
Add todos, simplify and find solution for getting translations
corsacca May 17, 2024
bf2d043
make it easier to get values from the langs table
corsacca May 17, 2024
6841470
changes for second issue
May 21, 2024
3446d39
Get options with defaults
corsacca May 22, 2024
25755ca
changes to update_language
May 28, 2024
a2417cb
Merge branch 'DiscipleTools:develop' into second-issue
CptHappyHands May 30, 2024
effa994
Merge branch 'second-issue' of https://github.com/CptHappyHands/disci…
May 30, 2024
ccaa507
Update dt-options.js
CptHappyHands May 30, 2024
b19b192
Update tab-custom-lists.php
CptHappyHands May 30, 2024
02e5302
Update tab-custom-lists.php
CptHappyHands May 30, 2024
9e6264a
Update dt-options.js
CptHappyHands May 30, 2024
d3aac69
Update admin-settings-endpoints.php
CptHappyHands May 30, 2024
ef6d4ef
Update admin-settings-endpoints.php
CptHappyHands May 31, 2024
292a4c9
Update tab-custom-lists.php
CptHappyHands May 31, 2024
5083731
Update admin-settings-endpoints.php
CptHappyHands May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions dt-core/admin/admin-settings-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,64 @@ public function add_api_routes() {
'permission_callback' => [ $this, 'default_permission_check' ],
]
);

register_rest_route(
$this->namespace, '/languages', [
'methods' => 'POST',
'callback' => [ $this, 'update_languages' ],
'permission_callback' => [ $this, 'default_permission_check' ],
]
);
}

public function update_languages( WP_REST_REQUEST $request ) {
/**
* @todo:
* only save user provided customizations to the dt_working_languages options
* this includes labels, the iso code, the enabled status and translations
* does not include: the key, default labels etc
*/
$params = $request->get_params();
$languages = dt_get_option( 'dt_working_languages' );

$langs = dt_get_available_languages();
foreach ( $languages as $language_key => $language_options ){

if ( isset( $params[$language_key]['label'] ) ){
$label = sanitize_text_field( wp_unslash( $params[$language_key]['label'] ) );
if ( ( $language_options['label'] ?? '' ) != $label ){
$languages[$language_key]['label'] = $label;
}
}
if ( isset( $params[$language_key]['iso_639-3'] ) ){
$code = sanitize_text_field( wp_unslash( $params[$language_key]['iso_639-3'] ) );
if ( ( $language_options['iso_639-3'] ?? '' ) != $code ) {
$languages[$language_key]['iso_639-3'] = $code;
}
}
if ( isset( $params[$language_key]['enabled'] ) ){
$enabled = sanitize_text_field( wp_unslash( $params[$language_key]['enabled'] ) );
if ( ( $language_options['enabled'] ?? '' ) != $enabled ) {
$languages[$language_key]['enabled'] = $enabled;
}
}
if ( isset( $params[$language_key]['translations'] ) ) {
foreach ( $langs as $lang => $val ){
$langcode = $val['language'];
$translations = sanitize_text_field( wp_unslash( $params[$language_key]['translations'][$langcode] ) );
if ( isset( $params[$language_key]['translations'][$langcode] ) ) {
$translated_label = sanitize_text_field( wp_unslash( $params[$language_key]['translations'][$langcode] ) );
if ( ( empty( $translated_label ) && !empty( $languages[$language_key]['translations'][$langcode] ) ) || !empty( $translated_label ) ){
$languages[$language_key]['translations'][$langcode] = $translated_label;
}
}
}
}
$languages[$language_key]['deleted'] = !isset( $params[$language_key]['deleted'] );
}

update_option( 'dt_working_languages', $languages, false );
return true;
}

public static function get_post_fields() {
Expand Down
Loading
Loading