Making WordPress.org

Changeset 11154


Ignore:
Timestamp:
07/28/2021 08:01:26 AM (3 years ago)
Author:
dd32
Message:

Translate: Allow searching for translations by "user 0" / "user anonymous" in order to find any translations which do not have a defined author.

Translations when imported will lack an author if the original author is unknown, this allows translators to actually filter views to them.

See https://wordpress.slack.com/archives/C02RP50LK/p1627457805200500

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r11122 r11154  
    5454        add_action( 'gp_translation_created', array( $this, 'auto_reject_replaced_suggestions' ) );
    5555
     56        add_filter( 'gp_for_translation_clauses', array( $this, 'allow_searching_for_no_author_translations' ), 10, 3 );
     57
    5658        // Cron.
    5759        add_filter( 'cron_schedules', [ $this, 'register_cron_schedules' ] );
     
    308310
    309311    /**
     312     * Allow searching for translations by user_id 0, by setting the user_login field to `0` or `anonymous`.
     313     */
     314    function allow_searching_for_no_author_translations( $clauses, $set, $filters ) {
     315        $user_login = gp_array_get( $filters, 'user_login' );
     316   
     317        if ( '0' === $user_login ) {
     318            $clauses['where'] .= ( $clauses['where'] ? ' AND' : '' ) . ' t.user_id = 0';
     319        } elseif ( 'anonymous' === $user_login ) {
     320            // 'Anonymous' user exists, but has no translations.
     321            $clauses['where'] = preg_replace( '/(user_id\s*=\s*\d+)/', 'user_id = 0', $clauses['where'] );
     322        }
     323   
     324        return $clauses;
     325    }
     326
     327    /**
    310328     * Adds a link to view originals in consistency tool.
    311329     *
Note: See TracChangeset for help on using the changeset viewer.