Skip to content
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

QTS: Incorporated settings in qtranslate and cleanup #1115

Merged
merged 4 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 0 additions & 23 deletions admin/qtx_admin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ private function add_sections( $nonce_action ) {
$this->add_general_section();
$this->add_advanced_section();
$this->add_integration_section();

if ( $q_config['slugs_enabled'] ) {
$this->add_slugs_section();
}

$this->add_troubleshooting_section();
// Allow to load additional services
do_action( 'qtranslate_configuration', $this->options_uri );
Expand Down Expand Up @@ -852,24 +847,6 @@ class="qtranxs_explanation"><?php
<?php $this->close_section( 'integration' );
}

private function add_slugs_section() {
global $q_config;
$this->open_section( 'slugs' ); ?>

<table class="form-table qtranxs-form-table" id="qtranxs_slugs_config">
<tr>
<th scope="row"><?php _e( 'Slugs translation', 'qtranslate' ) ?></th>
<td>
<p class="qtranxs_explanation"><?php printf( __( 'Placeholder, settings for slugs translation are still available <a href="%s">here</a>.', 'qtranslate' ), get_admin_url() . 'options-general.php?page=qtranslate-slug-settings' ) ?></p>
</td>
</tr>
</table>


<?php
$this->close_section( 'slugs', false );
}

private function add_troubleshooting_section() {
$this->open_section( 'troubleshooting' ); ?>
<table class="form-table qtranxs-form-table" id="qtranxs_troubleshooting_config">
Expand Down
59 changes: 0 additions & 59 deletions modules/slugs/assets/css/qts-settings.css

This file was deleted.

18 changes: 0 additions & 18 deletions modules/slugs/assets/js/qts-settings.js

This file was deleted.

6 changes: 4 additions & 2 deletions modules/slugs/includes/class-qtranslate-slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ public function save_options( $new_options = false ) {
if ( ! $new_options || empty( $new_options ) ) {
return;
}
if ( count( $this->options ) != count( $new_options ) ) {
if ( $this->options == $new_options ) {
return;
}
update_option( QTS_OPTIONS_NAME, $new_options );
flush_rewrite_rules();
$this->options = $new_options;
}

Expand Down Expand Up @@ -258,7 +259,7 @@ public function qtranslate_slug_header_extended() {
if ( is_404() ) {
return;
}
//taken from qtx but see our #341 ticket for clarification
// taken from qtx but see our #341 ticket for clarification
echo '<link hreflang="x-default" href="' . esc_url( $this->get_current_url( $this->default_language ) ) . '" rel="alternate" />' . PHP_EOL;
foreach ( $this->get_enabled_languages() as $language ) {

Expand Down Expand Up @@ -306,6 +307,7 @@ public function qts_quickuse( $text, $lang = '' ) {
if ( ! empty( $parsed_text[ $lang ] ) ) {
return $parsed_text[ $lang ];
}

// TODO: check what to do if lang not found in ML values
return $text;
}
Expand Down
90 changes: 22 additions & 68 deletions modules/slugs/includes/qtranslate-slug-settings-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ function qts_options_page_sections() {
*
* @return array
*/
function get_multi_txt_choices( $name = false ) {
function get_multi_txt_choices() {
global $q_config;

if ( ! $name ) {
return array();
}
$choices = array();
foreach ( $q_config['enabled_languages'] as $lang ) {
$label = sprintf( __( 'Slug (%s)', 'qts' ), $q_config['language_name'][ $lang ] );
$choices[] = "$label|$lang"; // prints: 'Slug (English)|en' ( $name = books )
$label = sprintf( __( 'Slug', 'qts' ) . ' (%s)', $q_config['language_name'][ $lang ] );
$choices[] = "$label|$lang"; // prints: 'Slug (English)|en'
}

return $choices;
Expand All @@ -40,71 +37,28 @@ function get_multi_txt_choices( $name = false ) {
function qts_options_page_fields() {
$post_types = get_post_types( array( '_builtin' => false, 'public' => true ), 'objects' );

// each post type
foreach ( $post_types as $post_type ):
$options[] = array(
"section" => "post_types",
"id" => QTS_PREFIX . "post_type_" . $post_type->name,
"title" => $post_type->labels->singular_name,
"desc" => sprintf( __( '<code>https://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $post_type->name, $post_type->name ),
'class' => 'qts-slug',
"type" => "multi-text",
"choices" => get_multi_txt_choices( $post_type->name ),
"std" => ""
);
endforeach;
// end each post type

$options[] = array(
"section" => "taxonomies",
"id" => QTS_PREFIX . "taxonomy_category",
"title" => __( 'Categories', 'qts' ),
"desc" => __( '<code>https://example.org/<u>category</u>/some-category/</code>', 'qts' ),
"type" => "multi-text",
'class' => 'qts-slug',
"choices" => get_multi_txt_choices( 'category' ),
"std" => ""
);

$options[] = array(
"section" => "taxonomies",
"id" => QTS_PREFIX . "taxonomy_post_tag",
"title" => __( 'Tags', 'qts' ),
"desc" => __( '<code>https://example.org/<u>tag</u>/some-tag/</code>', 'qts' ),
"type" => "multi-text",
'class' => 'qts-slug',
"choices" => get_multi_txt_choices( 'post_tag' ),
"std" => ""
);

$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );

// each extra taxonomy
foreach ( $taxonomies as $taxonomy ):
$options[] = array(
"section" => "taxonomies",
"id" => QTS_PREFIX . "taxonomy_" . $taxonomy->name,
"title" => $taxonomy->labels->singular_name,
"desc" => sprintf( __( '<code>https://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $taxonomy->name, $taxonomy->name ),
"type" => "multi-text",
'class' => 'qts-slug',
"choices" => get_multi_txt_choices( $taxonomy->name ),
"std" => ""
);
endforeach;

// end each extra taxonomy
$options = array();
foreach ( $post_types as $post_type ) {
$options[] = qts_options_page_build_slug_fields( $post_type, "post_types", "post_type_" );
}

$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true ), 'object' );
foreach ( $taxonomies as $taxonomy ) {
$options[] = qts_options_page_build_slug_fields( $taxonomy, "taxonomies", "taxonomy_" );
}

return $options;
}

/**
* Contextual Help.
*/
function qts_options_page_contextual_help() {
$text = "<h3>" . __( 'Qtranslate Settings - Contextual Help', 'qts' ) . "</h3>";
$text .= "<p>" . __( 'Contextual help goes here. You may want to use different html elements to format your text as you want.', 'qts' ) . "</p>";

return $text;
function qts_options_page_build_slug_fields( $object, $target_section, $id_prefix ) {
return array(
"section" => $target_section,
"id" => QTS_PREFIX . $id_prefix . $object->name,
"title" => qtranxf_use( qtranxf_getLanguage(), $object->label ),
"desc" => sprintf( '<code>https://example.org/<u>%s</u>/some-%s/</code>', array_key_exists( 'slug', $object->rewrite ) ? ltrim( $object->rewrite['slug'], "/" ) : $object->name, $object->name ),
'class' => 'qts-slug', // used in qts_validate_options. TODO: cleaner way to be considered...
"type" => "multi-text",
"choices" => get_multi_txt_choices(),
"std" => ""
);
}
Loading