• Resolved emiliengerbois

    (@emiliengerbois)


    Hi Michael,
    I hope you’re well,

    I just bought the Activity code add-on and I would need your help regarding the associated shortcode, designed to submit an activity code from anywhere on the website.

    I’d need to restrict the use of this shortcode, to use it in association with a defined badge of a specific type.

    Something like this: [badgeos_activity_code_input badge_type=”my_specific_badge_type” badge_ID=”my_specific_badge_ID” input_text=”Enter Activity Code” submit_text=”Submit”]

    Is it possible? How could we achieve this?

    My problem is I will have a huge amount of badges and I will have the same activity code for various badges…

    Thank you so much in advance for your help, have a great day,
    Emilien

    https://www.ads-software.com/plugins/badgeos/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    Trying to work out your flow here.

    It sounds like you’re going to re-use the same activity code for all of the achievements, but you want to conditionally show the form and possibly associate the form to a specific achievement?

    Essentially making the people have to earn their way to the forms so that they can put in the code, even though the code is “universal” ?

    Thread Starter emiliengerbois

    (@emiliengerbois)

    well the code isn’t universal but I will have some codes that will be used for multiple badges indeed, even though the context will be different each time…

    thank you for your help ??

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Regardless of how often 1 activity code gets used, is the rest of the flow correct? Meaning the form and awarded achievement is what’s conditionally shown?

    I don’t believe this add-on is built in that way, if yes. It’s meant to have the unique codes associated with the achievements.

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Actually I think I don’t explain my problem the right way: sorry for that.
    I use a visual composer to build my badges pages. so what I would need would be to specify the ID of the current badge in the shortcode I place on its page.

    Then I’d need to restrict the use of this form shown by shortcode, so that it would only check if the submitted code is correct for this specific first current badge on this specific page. So even if this same code is used for a second badge, entering it on the first badge page will validate only this first badge as earned.

    :-s

    thank you again ??

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not quite following still, but it’s making at least a bit more sense. I know we have the badgeos_activity_render_input_form filter that has the form output passed through. You could do your own output modified and based on that. Not quite sure what all would be left for what you’re envisioning though.

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Hi Michael,

    I had a look into the files (though I’m not a dev).
    I’m not sure I understand the following piece of code in the activity-input.php.
    Does this mean the submit activity code form is filtered when called on a badge page?
    Meaning it will check if the submitted code is valid only for the current badge being viewed?

    If yes, is the form grabbed by the [badgeos_activity_code_input] shortcode filtered too when displayed on a single badge page? Or is there a way to call the filtered form that shows on a badge page through shortcode also? (I ask because I use a page builder for badge pages and I’d need to display the filtered activity form through shortcode…)

    Thank you again for your help,
    Emilien

    /**
     * Append activity code input to single achievement view
     *
     * @since  1.0.0
     * @param  string $content The current content
     * @return string          The updated content
     */
    function badgeos_activity_input_content_filter( $content ) {
    
    	// Grab our achievement ID
    	$achievement_id = get_the_ID();
    
    	// If we're on the main achievment view,
    	// and it's earned by activity code...
    	if (
    		badgeos_is_main_loop( $achievement_id )
    		&& 'activity_code' == get_post_meta( $achievement_id, '_badgeos_earned_by', true )
    	) {
    		// Append the input form
    		$content .= badgeos_activity_render_input_form( array( 'context' => 'content_filter' ) );
    	}
    
    	// Return our (potentially filtered) content
    	return $content;
    
    }
    add_filter( 'the_content', 'badgeos_activity_input_content_filter' );
    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like this snippet checks if we’re in the main loop of the page, and the achievement is earned via activity code. If yes, append the form to submit to. I’m not seeing anything that limits it to earning just that specific achievement that the form is on so from what I can tell, it’d be useful for any of the created activity codes. The PHP behind the scenes would fetch the appropriate achievement ID based on the submitted code.

    Thread Starter emiliengerbois

    (@emiliengerbois)

    OK I get it better, thank you!!!

    So there is no way to make the form grabbed by the [badgeos_activity_code_input] shortcode to check only if the submitted code is valid for the current Badge being seen ?
    Would it be feasible with some custom code? Would you have any idea how to begin?

    Thank you again, have a great day,
    Emilien

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Best I can tell, you’d need to tap into the following filter and return false if the achievement ID passed into the filter doesn’t match the ID from the $post variable.

    return apply_filters( 'user_has_access_to_achievement', $return, $user_id, $achievement_id, $this_trigger, $site_id, $args );

    The $return variable will hold either true or false boolean.

    Thread Starter emiliengerbois

    (@emiliengerbois)

    OK thank you again, I’ll try to find a dev to work on it

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Activity code add-on – restrict activity shortcode to a single badge’ is closed to new replies.