Making WordPress.org

Changeset 11943


Ignore:
Timestamp:
07/06/2022 05:47:25 PM (4 years ago)
Author:
iandunn
Message:

GP Profiles: Ignore updates that aren't initiated by a user.

Functions like WordPressdotorg\GlotPress\Plugin_Directory\Sync\Translation_Sync::sync_translations() can trigger a create() or save(), but only actions initiated by a contributor should trigger a notification.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/profiles.php

    r11942 r11943  
    2323}
    2424
    25 add_action( 'gp_translation_created', __NAMESPACE__ . '\add_single_translation_activity' );
    26 add_action( 'gp_translation_saved', __NAMESPACE__ . '\add_single_translation_activity', 10, 2 );
    27 add_action( 'gp_translation_set_bulk_action_post', __NAMESPACE__ . '\add_bulk_translation_activity', 10, 4 );
     25add_action( 'plugins_loaded', __NAMESPACE__ . '\register_callbacks' );
     26
     27function register_callbacks() : void {
     28        // Ignore programmatic actions, only notify for user-initiated actions.
     29        if ( empty( $_POST ) || ! is_user_logged_in() ) {
     30                return;
     31        }
     32
     33        add_action( 'gp_translation_created', __NAMESPACE__ . '\add_single_translation_activity' );
     34        add_action( 'gp_translation_saved', __NAMESPACE__ . '\add_single_translation_activity', 10, 2 );
     35        add_action( 'gp_translation_set_bulk_action_post', __NAMESPACE__ . '\add_bulk_translation_activity', 10, 4 );
     36}
    2837
    2938/**
    … …  
    5160
    5261        /*
     62         * Regular user is suggesting a string.
     63         *
    5364         * `GP_Route_Translation::translations_post` saves the translation as `waiting` for all users. Then, if the
    54          * user is an editor, it saves it second time to update the status to `current`. We can ignore the first save
    55          * since two avoid two bumps for a single action.
     65         * user is an editor, it saves it a second time to update the status to `current`. We can ignore the first save,
     66         * to avoid two notifications for a single action.
    5667         */
    5768        if ( 'waiting' === $new_translation->status && ! $current_user_is_editor ) {
    5869                $type = 'glotpress_translation_suggested';
    59         } elseif ( 'current' === $new_translation->status && 'current' !== $previous_translation->status ) {
     70
     71        // Editor is approving a suggested string.
     72        // Avoid sending a notification when a `current` post is re-saved, like when dismissing warnings.
     73        } elseif ( 'current' === $new_translation->status && isset( $previous_translation->status ) && 'current' !== $previous_translation->status ) {
    6074                $type = 'glotpress_translation_approved';
     75
    6176        } else {
    6277                return;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/tests/e2e.php

    r11938 r11943  
    4747        GlotPress_Profiles\add_single_translation_activity( $translation );
    4848
     49        $previous_translation = new GP_Translation( array(
     50                'user_id' => $user->ID,
     51                'status'  => 'waiting',
     52        ) );
    4953        $translation = new GP_Translation( array(
    5054                'user_id' => $user->ID,
    5155                'status'  => 'current',
    5256        ) );
    53         GlotPress_Profiles\add_single_translation_activity( $translation );
     57        GlotPress_Profiles\add_single_translation_activity( $translation, $previous_translation );
    5458
    5559        echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$user->user_nicename/ \n";
Note: See TracChangeset for help on using the changeset viewer.