/*Write here your own functions */
if ( function_exists( 'get_avatar' ) ) {
function brw_get_avatar_shortcode ( $attributes ) {
$current_user = wp_get_current_user();
extract(shortcode_atts(array(
'id' => $current_user->ID,
'size' => 32,
'default' => 'mystery',
'alt' => '',
'class' => '',
'rating' => '',
'extra_attr' => '',
'width' => '',
'height' => '',
'force_display' => ''
), $attributes, 'get_avatar' ));
$args = array(
'class' => $class,
'rating' => $rating,
'extra_attr' => $extra_attr,
'width' => $width,
'height' => $height,
'force_display' => $force_display
);
return get_avatar( $id, $size, $default, $alt, $args );
}
add_shortcode ('get_avatar', 'brw_get_avatar_shortcode');
}
function my_courses( $attributes ) {
extract(shortcode_atts(array(
'btn_color' => 'red',
), $attributes));
$user_id = get_current_user_id();
$user_meta = get_user_meta($user_id);
$course_progress = unserialize($user_meta["_sfwd-course_progress"][0]);
if (!empty($course_progress)):
return '<hr style="background:#BABABA;height:1px;margin-top:10px;margin-bottom:40px;"><div class="courses">'.
do_shortcode('[ld_course_list mycourses="true" progress_bar="true" num="3"]').
'</div>';
else:
return '
<div class="my_courses">
<div class="no_courses">
<h3>No Courses!</h3>
<div>Choose a course from the Course Library<br> or use the button below to start</div>
<a class="btn" href="/courses" style="background:'.$btn_color.'">+</a>
</div>
</div>';
endif;
}
add_shortcode('pbd_my_courses', 'my_courses');
function count_badges() {
$achievements = gamipress_get_achievements(["post_type"=>"badges", 'orderby' => 'data', 'order' => 'asc']);
$user_achievements = gamipress_get_user_earned_achievement_ids();
$count = 0;
foreach ($achievements as $achievement)
{
if ( in_array($achievement->ID, $user_achievements ))
{
$count++;
}
}
return $count;
}
add_shortcode('pbd_count_badges', 'count_badges');
function profile_tab_subscription_tag() {
global $bp;
$parent_slug = 'settings';
//Add subnav item
bp_core_new_subnav_item( array(
'name' => 'Subscriptions',
'slug' => 'subscriptions',
'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/',
'parent_slug' => $parent_slug,
'screen_function' => 'subscription_screen',
'position' => 15 ) );
bp_core_new_nav_item( array(
'name' => 'Goodies',
'slug' => 'goodies',
'parent_url' => bp_loggedin_user_domain() . '/goodies/',
'parent_slug' => $bp->profile->slug,
'screen_function' => 'goodies_screen',
'position' => 90 ) );
}
add_action( 'bp_setup_nav', 'profile_tab_subscription_tag' );
function subscription_screen() {
// Add title and content here - last is to call the members plugin.php template.
add_action( 'bp_template_content', 'subscription_tab_content' );
bp_core_load_template( 'buddypress/members/single/plugins' );
}
function subscription_tab_content() {
$library_items = get_posts( array(
'post_type' => 'library',
'numberposts' => -1,
'orderby' => 'post_title',
'order' => 'ASC',
));
?>
<div class="" style="flex-direction: column">
<?php
if (isset($_GET['action']) && $_GET['action'] == 'Cancel'){
?>
<script>
alert('Your cancellation request has been successfully processed.\n\nYour subscription will be cancelled on <?=$_GET['end_date'];?>');
</script>
<?php
}
?>
<?php echo do_shortcode('[memb_list_subscriptions status="active"]
<h3>%%subscription.name%%</h3>
<div style=" border-bottom: solid; border-width: 1px; border-color: #eaeaea; margin-bottom: 20px; ">Subscription Details</div>
<div>$%%subscription.price%%</div>
<div style="display:flex;justify-content: space-between;margin-top: 20px;">
<div style=" display: flex; flex-direction: column; ">
%%subscription.nextbilling%%
<span style="font-size:12px">Next payment date
</div>
<div>%%cancel.button%%</div>
</div>
<div style=" border-bottom: solid; border-width: 1px; border-color: #eaeaea; margin-top:30px; margin-bottom: 20px; ">Payment Method</div>
<div style="display:flex;justify-content: space-between;margin-top: 20px;">
<div>%%creditcard.last4%%</div>
<div><a href="" class="add_card_btn" style="font-size:14px">Change payment info</a></div>
</div>
[else_memb_list_subscriptions]
Sorry, we didn\'t find any active subscriptions associated with your account.
[/memb_list_subscriptions]');?>
<?php echo do_shortcode('<div class="memberium-form">
<div style="display:none" class="add_card">
<h3>Change payment info</h3>
[memb_add_creditcard successurl="/thank-you-for-updating-your-info/" failureurl="/payment-details-failure/" addonly="yes"]
</div>
</div>
');?>
<style>
input, select {
width: 100%;
margin-bottom: 20px;
}
</style>
<script>
jQuery(document).ready(function($){
$('.add_card_btn').click(function(e){
e.preventDefault();
$(".add_card").slideDown();
});
});
</script>
</div>
<?php
}
function goodies_screen() {
// Add title and content here - last is to call the members plugin.php template.
add_action( 'bp_template_content', 'goodies_tab_content' );
bp_core_load_template( 'buddypress/members/single/plugins' );
}
function goodies_tab_content() {
?>
<style>
.gamipress-achievement-image {
padding-right: 0 !important;
width: 100% !important;
text-align: center;
}
.gamipress-achievement-image img {
width: 120px
}
.gamipress-achievement-title {
text-align: center;
padding-top: 10px;
}
.user-has-not-earned {
position: relative;
}
.user-has-not-earned:before {
content: "\e90d";
font-family: "bb-icons";
position: absolute;
right: 20px;
font-size:18px;
}
</style>
<?php
echo do_shortcode('[gamipress_achievements type="goodies" filter="no" search="no" limit="100" columns="3" orderby="menu_order" order="ASC"]');
}
function pbd_gamipress_update_user_points($user_id,$new_points ){
$_SESSION["pbd_points_updated"] = true;
//$_SESSION["pbd_points"] = $new_points;
}
add_action('gamipress_update_user_points', 'pbd_gamipress_update_user_points',10,2);
function pbd_points_updated() {
if (isset($_SESSION["pbd_points_updated"]) && $_SESSION["pbd_points_updated"]){
?>
<style>
.progress_bar{
animation: expandWidth 2s;
}
@keyframes expandWidth {
0% { width: 0; }
}
</style>
<script>
jQuery(document).ready(function($){
$('#points').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 2000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
});
</script>
<?php
unset($_SESSION['pbd_points_updated']);
}
}
add_action('wp_footer','pbd_points_updated');
// Add Shortcode
function pbd_restrict_content( $atts , $content = null ) {
// Attributes
$atts = shortcode_atts(
array(
'rank_id' => get_the_ID(),
),
$atts
);
$user_id = get_current_user_id();
//return $atts['rank_id'];
//return $content;
$achievement = gamipress_get_user_achievements(array('user_id'=>$user_id,'achievement_id'=>$atts['rank_id']));
if (!empty($achievement)){
return $content;
}
}
add_shortcode( 'pbd_restrict_content', 'pbd_restrict_content' );
function pbd_courses_completed() {
$courses = 0;
$user_id = get_current_user_id();
$user_meta = get_user_meta($user_id);
$course_progress = unserialize($user_meta["_sfwd-course_progress"][0]);
$defaults = array(
'post_type' => 'sfwd-courses',
'fields' => 'ids',
'nopaging' => true,
);
$course_query_args = wp_parse_args( $course_query_args, $defaults );
$course_query = new WP_Query( $course_query_args );
if ( ( isset( $course_query->posts ) ) && ( ! empty( $course_query->posts ) ) ) {
$course_ids = $course_query->posts;
}
if (!empty ($course_ids)){
foreach ($course_ids as $course_id){
$courses = $courses + learndash_course_completed( $user_id ,$course_id );
}
}
return ($courses);
}
add_shortcode( 'pbd_courses_completed', 'pbd_courses_completed' );
if( !function_exists('custom_user_login_redirect') ) {
function custom_user_login_redirect() {
$redirect_to = 'https://www.yourdomain.ltd/yourcustomlink';
return $redirect_to;
}
add_filter('login_redirect','custom_user_login_redirect',10,3);
}
?>