Deleted posts don't decrement progress counts for "on post published" event #67

Open
paulgibbs opened this Issue Jan 24, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@paulgibbs

This comment has been minimized.

Show comment
Hide comment
@paulgibbs

paulgibbs Feb 17, 2013

Owner

Support for this would involve special-casing this event. Before doing so, think about if any other achievements have a similar problem, and see if there's a unified way of dealing with them all.

Owner

paulgibbs commented Feb 17, 2013

Support for this would involve special-casing this event. Before doing so, think about if any other achievements have a similar problem, and see if there's a unified way of dealing with them all.

@rmccue

This comment has been minimized.

Show comment
Hide comment
@rmccue

rmccue Jul 8, 2013

Contributor

Here's how I did it, but it breaks in certain circumstances:

    add_filter( 'dpa_maybe_unlock_achievement_progress_increment', array( $this, 'maybe_decrement'));
    add_action( 'sennza_likes', array( $this, 'run_sennza_likes' ), 10 );
    add_action( 'sennza_likes_unlike', array( $this, 'run_sennza_likes' ), 10 );

    public function run_sennza_likes($post_id) {
        $user = get_current_user_id();
        if ( empty( $user ) )
            return;

        if (current_filter() === 'sennza_likes_unlike')
            $this->decrement = true;

        do_action( 'ts_sennza_likes' );
    }

    public function maybe_decrement($step) {
        if ( $this->decrement === true ) {
            $step = -1;
            $this->decrement = false;
        }
        return $step;
    }

Specifically, it breaks when using recurring achievements with no limit/repeat, as the same action is used for both.

In a prospective general solution, it would use the same progress object for both actions and use the same step filter, but I didn't have time for implementing that.

Contributor

rmccue commented Jul 8, 2013

Here's how I did it, but it breaks in certain circumstances:

    add_filter( 'dpa_maybe_unlock_achievement_progress_increment', array( $this, 'maybe_decrement'));
    add_action( 'sennza_likes', array( $this, 'run_sennza_likes' ), 10 );
    add_action( 'sennza_likes_unlike', array( $this, 'run_sennza_likes' ), 10 );

    public function run_sennza_likes($post_id) {
        $user = get_current_user_id();
        if ( empty( $user ) )
            return;

        if (current_filter() === 'sennza_likes_unlike')
            $this->decrement = true;

        do_action( 'ts_sennza_likes' );
    }

    public function maybe_decrement($step) {
        if ( $this->decrement === true ) {
            $step = -1;
            $this->decrement = false;
        }
        return $step;
    }

Specifically, it breaks when using recurring achievements with no limit/repeat, as the same action is used for both.

In a prospective general solution, it would use the same progress object for both actions and use the same step filter, but I didn't have time for implementing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment