Skip to content

Instantly share code, notes, and snippets.

@bryanwillis
Forked from jwahlin/custom_progress_bar.php
Created October 23, 2019 21:54
Show Gist options
  • Save bryanwillis/b26e52f78b24359854917d1ba5885193 to your computer and use it in GitHub Desktop.
Save bryanwillis/b26e52f78b24359854917d1ba5885193 to your computer and use it in GitHub Desktop.
Combine Formidable stats with SKT Skillset shortcode
add_shortcode( 'custom_progress_bar', 'add_custom_progress_bar' );
function add_custom_progress_bar( $atts ) {
if (
! isset( $atts['user'] ) || ! isset( $atts['goal'] ) || ! isset( $atts['year_month'] )
|| ! isset( $atts['title'] ) || ! isset( $atts['goal_id'] )
) {
return '';
}
// Get total amount completed for the current month
$amount_complete = FrmProStatisticsController::stats_shortcode(
array(
'id' => 40206,//Replace 40206 with the ID of the field you want to total
'type' => 'total',
'user_id' => $atts['user'],
'40204_greater_than_or_equal_to' => $atts['year_month'] . '-01',// Replace 40204 with the ID of the date field in your log activity form
'40204_less_than_or_equal_to' => $atts['year_month'] . '-31',// Replace 40204 with the ID of the date field in your log activity form
'40205' => $atts['goal_id'],// Replace 40205 with the ID of the hidden field or Dynamic field that stores the goal entry ID
)
);
// Divide by goal
$percent = ( (int) $amount_complete / (int) $atts['goal'] ) * 100;
return do_shortcode( '[skill title_background="#2f97ac" bar_foreground="#21b7c4" bar_background="#eeeeee" percent="' .
$percent . '" title="' . $atts['title'] . '"]' );
}
@bryanwillis
Copy link
Author

I created a View from the "Set a goal" form. I used this shortcode in my View:

[skillwrapper type="bar"]
    [foreach 40194]
        [custom_progress_bar title="[40197]" goal="[40196]" user="[40200 show=ID]" goal_id="[id]" year_month="[40210]-[40193 show=value]"]
    [/foreach 40194]
[/skillwrapper]

40914 is the ID of my repeating section
40197 is the ID of the "activity" field
40196 is the ID of the goal number/amount
40200 is the ID of the userID field
40210 is the ID of a "Year" dropdown (outside of repeating section)
40193 is the ID of a "Month" dropdown (outside of repeating section)

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