Skip to content

Commit

Permalink
Add date/time option to use WP and ignore QTX formats (#1248)
Browse files Browse the repository at this point in the history
Allow to disable date/time hooks in qTranslate and use WP default behavior.
  • Loading branch information
herrvigg authored Nov 8, 2022
1 parent ae83752 commit 78a790b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions admin/qtx_admin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ private function add_advanced_section() {
<tr>
<th scope="row"><?php _e( 'Date / Time Conversion', 'qtranslate' ) ?></th>
<td>
<label>
<input type="radio" name="use_strftime"
value="<?php echo QTX_DATE_WP; ?>" <?php checked( $q_config['use_strftime'], QTX_DATE_WP ) ?>/> <?php _e( 'Use WordPress options and translation. Ignore language date / time formats.', 'qtranslate' ) ?>
</label><br/>
<label>
<input type="radio" name="use_strftime"
value="<?php echo QTX_DATE; ?>" <?php checked( $q_config['use_strftime'], QTX_DATE ) ?>/> <?php _e( 'Use emulated date function.', 'qtranslate' ) ?>
Expand Down
1 change: 1 addition & 0 deletions qtranslate_date_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function qtranxf_convert_to_strftime_format_using_config( $format, $default_form
return ( ! empty( $format ) ? qtranxf_convert_date_format_to_strftime_format( $format ) : stripslashes( $default_format ) );
case QTX_STRFTIME_OVERRIDE:
return stripslashes( $default_format );
case QTX_DATE_WP:
default:
return '';
}
Expand Down
16 changes: 10 additions & 6 deletions qtranslate_hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ function qtranxf_ngettext( $translated_text ) {
* @return void
*/
function qtranxf_add_main_filters() {
global $q_config;

// Hooks defined differently in admin and frontend
add_filter( 'wp_trim_words', 'qtranxf_trim_words', 0, 4 );

Expand All @@ -138,12 +140,14 @@ function qtranxf_add_main_filters() {
add_filter( 'the_excerpt', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0 );
add_filter( 'the_excerpt_rss', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0 );

add_filter( 'get_comment_date', 'qtranxf_dateFromCommentForCurrentLanguage', 0, 3 );
add_filter( 'get_comment_time', 'qtranxf_timeFromCommentForCurrentLanguage', 0, 5 );
add_filter( 'get_post_modified_time', 'qtranxf_timeModifiedFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_time', 'qtranxf_timeFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_date', 'qtranxf_dateFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_modified_date', 'qtranxf_dateModifiedFromPostForCurrentLanguage', 0, 2 );
if ( $q_config['use_strftime'] != QTX_DATE_WP ) {
add_filter( 'get_comment_date', 'qtranxf_dateFromCommentForCurrentLanguage', 0, 3 );
add_filter( 'get_comment_time', 'qtranxf_timeFromCommentForCurrentLanguage', 0, 5 );
add_filter( 'get_post_modified_time', 'qtranxf_timeModifiedFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_time', 'qtranxf_timeFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_date', 'qtranxf_dateFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_modified_date', 'qtranxf_dateModifiedFromPostForCurrentLanguage', 0, 2 );
}

add_filter( 'locale', 'qtranxf_localeForCurrentLanguage', 99 );
add_filter( 'core_version_check_locale', 'qtranxf_versionLocale' );
Expand Down
2 changes: 1 addition & 1 deletion qtranslate_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Date/time conversion, see "use_strftime" option.
*/
const QTX_DATE_WP = 0; // obsolete, value reserved
const QTX_DATE_WP = 0; // Use WordPress options and translation, disable all date / time hooks.
const QTX_STRFTIME_OVERRIDE = 1; // TODO: deprecate strftime format
const QTX_DATE_OVERRIDE = 2; // deprecated
const QTX_DATE = 3; // default format at first activation - not consistent with default date/time values
Expand Down

0 comments on commit 78a790b

Please sign in to comment.