MyCRED Shortcodes

Below, you’ll find a detailed guide on how to add the MyCRED Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Mycred Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Mycred Plugin and the shortcodes it provides:

Plugin Icon
myCred – Points, Rewards, Gamification, Ranks, Badges & Loyalty Plugin

"myCred – Points, Rewards, Gamification, Ranks, Badges & Loyalty Plugin is an all-in-one tool designed to boost user engagement via gamification. It offers points, rewards, ranks, badges, and loyalty programs."

★★★★☆ (440) Active Installs: 10000+ Tested with: 6.2.3 PHP Version: 7.0
Included Shortcodes:
  • [mycred_my_badges]
  • [myCRED_badges]
  • [mycred_badges_list]
  • [MYCRED_buy']
  • [MYCRED_buy_form']
  • [myCRED_Buy_Pending]
  • [mycred_cashcred]
  • [myCRED_load_coupon]
  • [mycred_email_subscriptions]
  • [mycred_my_rank]
  • [MYCRED_SLUG_my_ranks]
  • [myCRED_Users_of_Rank]
  • [mycred_users_of_all_ranks]
  • [MYCRED_SLUG_list_ranks]
  • [myCRED_sell_this]
  • [mycred_sell_this_ajax]
  • [mycred_sales_history]
  • [myCred_content_sale_count]
  • [mycred_content_buyer_count]
  • [myCRED_content_buyer_avatars]
  • [myCRED_chart_circulation]
  • [myCRED_chart_gain_loss]
  • [myCRED_chart_history]
  • [myCRED_chart_balance_history]
  • [MYCRED_SLUG_chart_instance_history]
  • [myCRED_chart_top_balances]
  • [myCRED_chart_top_instances]
  • [MYCRED_SLUG . '_chart_acquisition']
  • [mycred_transfer]
  • [myCRED_badge_evidence]
  • [mycred_affiliate_id]
  • [myCRED_Affiliate_Link]
  • [myCRED_best_user]
  • [myCRED_exchange]
  • [mycred_give]
  • [mycred_hide_if]
  • [myCRED_History]
  • [MYCRED_SLUG_hook_table]
  • [mycred_leaderboard]
  • [mycred_leaderboard_position]
  • [myCRED_link]
  • [myCRED_my_balance]
  • [mycred_my_balance_converted]
  • [myCRED_referral_stats]
  • [MYCRED_SLUG . '_send']
  • [myCRED_show_if]
  • [MYCRED_SLUG_total_balance]
  • [myCRED_total_points]
  • [myCRED_total_since]
  • [myCRED_video]

Mycred [mycred_my_badges] Shortcode

The MyCred Badges shortcode is used to display the list of badges a user has earned on their profile. It provides customization options like the display style (vertical or horizontal), badge dimensions, and choice to show badge title and excerpt. The shortcode extracts user data and checks if the user is logged in. It then retrieves all badges and the badges earned by the user. The badges are displayed according to the specified style and dimensions. If the user has earned a badge, the badge image is displayed. If the title or excerpt is enabled, it is also displayed with the badge. The output is then returned for rendering.

Shortcode: [mycred_my_badges]

Parameters

Here is a list of all possible mycred_my_badges shortcode parameters and attributes:

  • show – controls whether to display ‘earned’ badges only.
  • width – sets the width of the badge image.
  • height – sets the height of the badge image.
  • user_id – specifies the user whose badges will be displayed.
  • title – determines if the badge title will be shown (1 for yes, 0 for no).
  • excerpt – decides if the badge excerpt will be displayed (1 for yes, 0 for no).
  • display – controls the layout orientation of the badges (‘vertical’ or ‘horizontal’).

Examples and Usage

Basic example – Display the badges earned by the current logged-in user in a vertical arrangement.

[mycred_my_badges]

Advanced examples

Display the badges earned by the user with the ID of 10 in a horizontal arrangement, including the title and excerpt of each badge.

[mycred_my_badges user_id=10 display='horizontal' title=1 excerpt=1]

Display all the badges, whether earned or not, for the current logged-in user. Unearned badges will be displayed in a vertical arrangement, and earned badges will be displayed in a horizontal arrangement.

[mycred_my_badges show='all' display='vertical' earned_display='horizontal']

Display all the badges for the user with the ID of 5, with a custom width and height of 100px and 150px respectively.

[mycred_my_badges user_id=5 width=100 height=150]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_my_badges] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_my_badges', 'mycred_render_my_badges' );

Shortcode PHP function:

function mycred_render_my_badges( $atts, $content = '' ) {

        extract( shortcode_atts( array(
            'show'         => 'earned',
            'width'        => MYCRED_BADGE_WIDTH,
            'height'       => MYCRED_BADGE_HEIGHT,
            'user_id'      => 'current',
            'title'        => 0,
            'excerpt'      => 0,
            'display'      => 'vertical'
        ), $atts, MYCRED_SLUG . '_my_badges' ) );

        if ( ! is_user_logged_in() && $user_id == 'current' )
            return $content;

        $user_id      = mycred_get_user_id( $user_id );
        $all_badges   = mycred_get_badge_ids();
        $users_badges = mycred_get_users_badges( $user_id );
        $css_classes  = in_array( $display, array( 'vertical', 'horizontal' ) ) ? $display : 'vertical';

        wp_enqueue_style( 'mycred-badge-front-style' );

        ob_start();

        echo '<div class="mycred-users-badges">';

        foreach ( $all_badges as $badge_id ) {

            $user_has_earned = array_key_exists( $badge_id, $users_badges );

            if ( $show == 'earned' && ! $user_has_earned ) continue;

            $css_classes = $user_has_earned ? $display . ' earned' : $display;

            echo '<div class="the-badge '. esc_attr( $css_classes ) .'">';

            $level = $user_has_earned ? $users_badges[ $badge_id ] : NULL;
            $badge = mycred_get_badge( $badge_id, $level );
            $badge->image_width  = $width;
            $badge->image_height = $height;

            if ( $user_has_earned ) {
                    
                if ( $badge->level_image !== false )
                    echo wp_kses_post( $badge->get_image( $level ) );

            }
            else {

                if ( $badge->main_image !== false )
                    echo wp_kses_post( $badge->get_image( 'main' ) );

            }

            if ( $title == 1 || $excerpt == 1 ) {

                echo '<div class="mycred-badge-content">';

                if ( $title == 1 && ! empty( $badge->title ) ) 
                    echo '<h4 class="title">' . esc_html( $badge->title ) . '</h4>';

                if ( $excerpt == 1 ) {

                    $badge_excerpt = get_the_excerpt( $badge_id );

                    if ( ! empty( $badge_excerpt ) ) 
                        echo '<p class="excerpt">' . esc_html( $badge_excerpt ) . '</p>';

                } 

                echo '</div>';

            }

            echo '</div>';

            do_action( 'mycred_add_share_and_embed_button', $badge, $badge_id );

        }

        echo '</div>';

        $output = ob_get_contents();
        ob_end_clean();

        return apply_filters( 'mycred_my_badges', $output, $user_id );

    }

Code file location:

mycred/mycred/addons/badges/myCRED-addon-badges.php

Mycred [myCRED_badges] Shortcode

The myCRED_badges shortcode displays all badges earned by users. It extracts badge details like title, requirements, count, and images. It also checks if the current user has earned a specific badge and displays the badge’s level. It then applies filters to the output for customization.

Shortcode: [myCRED_badges]

Parameters

Here is a list of all possible myCRED_badges shortcode parameters and attributes:

  • width – determines the width of the badge image
  • height – sets the height of the badge image

Examples and Usage

Basic example – Display all badges with default width and height.

[mycred_badges]

Advanced examples

Display all badges with a custom width and height.

[mycred_badges width=100 height=100]

Display a specific badge with a custom width and height. Note that you would replace ‘badge_id’ with the actual ID of the badge you want to display.

[mycred_badges badge_id=1 width=100 height=100]

Display a specific badge with default width and height. Again, replace ‘badge_id’ with the actual ID of the badge.

[mycred_badges badge_id=1]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_badges] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_badges',    'mycred_render_badges' );

Shortcode PHP function:

function mycred_render_badges( $atts, $template = '' ) {
        extract( shortcode_atts( array(
            'width'  => MYCRED_BADGE_WIDTH,
            'height' => MYCRED_BADGE_HEIGHT
        ), $atts, MYCRED_SLUG . '_badges' ) );

        $all_badges = mycred_get_badge_ids();

        if ( $template == '' )
            $template = '<div class="the-badge row"><div class="col-xs-12"><h3 class="badge-title">%badge_title%</h3><div class="badge-requirements">%requirements%</div><div class="users-with-badge">%count%</div><div class="badge-images">%default_image% %main_image%</div></div></div>';

        $output = '<div id="mycred-all-badges">';

        if ( ! empty( $all_badges ) ) {

            foreach ( $all_badges as $badge_id ) {

                $badge               = mycred_get_badge( $badge_id, 0 );
                $badge->image_width  = $width;
                $badge->image_height = $height;

                $row = $template;
                $row = str_replace( '%badge_title%',   $badge->title,                                  $row );
                $row = str_replace( '%requirements%',  mycred_display_badge_requirements( $badge_id ), $row );
                $row = str_replace( '%count%',         $badge->earnedby,                               $row );
                $row = str_replace( '%default_image%', $badge->get_image( 'main' ),                    $row );
                
                if( mycred_user_has_badge( get_current_user_id(), $badge_id) ) {
                    $user_id = get_current_user_id();
                    $badge   = mycred_get_badge( $badge_id );
                    $level   = $badge->get_users_current_level( $user_id );
                    $row     = str_replace( '%main_image%',    $badge->get_image( $level ), $row );
                }
                else {
                    $row = str_replace( '%main_image%',    '', $row );
                }

                $output .= apply_filters( 'mycred_badges_badge', $row, $badge );

            }

        }

        $output .= '</div>';

        return apply_filters( 'mycred_badges', $output );

    }

Code file location:

mycred/mycred/addons/badges/myCRED-addon-badges.php

Mycred [mycred_badges_list] Shortcode

The myCRED Badges List shortcode is a powerful tool for displaying a list of all badges on your WordPress site. It offers search functionality and filter options for achieved and not achieved badges. This shortcode also allows for tabbed categorization of badges, making it easier for users to navigate through them. The list can be customized with CSS and JavaScript for a more personalized look and feel. Shortcode: [mycred_badges_list]

Shortcode: [mycred_badges_list]

Parameters

Here is a list of all possible mycred_badges_list shortcode parameters and attributes:

  • achievement_tabs – Determines if badges are grouped by categories or not

Examples and Usage

Basic example – Display a list of all the badges using the mycred_badges_list shortcode.

[mycred_badges_list]

Advanced example – Display a list of all the badges with the achievement tabs enabled. This will categorize the badges under different tabs based on their achievement status (achieved or not achieved).

[mycred_badges_list achievement_tabs=1]

Here, the ‘achievement_tabs’ attribute is set to 1, which enables the categorization of badges. If this attribute is not included or is set to 0, all badges will be displayed without any categorization.

Another advanced example could be to customize the mycred_badges_list shortcode further by adding custom CSS classes to the badges list. This can be achieved by using the ‘class’ attribute in the shortcode.

[mycred_badges_list class="my-custom-class"]

In this example, the ‘class’ attribute is used to add a custom CSS class to the badges list. This can be used to apply custom styles to the badges list.

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_badges_list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_badges_list',    'mycred_render_badges_list' );

Shortcode PHP function:

function mycred_render_badges_list( $atts = '' ) {

        extract( shortcode_atts( array(
                'achievement_tabs'  =>  '1'
            ),
            $atts, MYCRED_SLUG . '_badges_list'
        ) );

        ob_start();?>

        <div class="mycred-badges-list">
            <div class="mycred-search-bar">
                <form method="post">
                    <input id="mycerd-badges-search" type="text" placeholder="Search for badge">
                    <button class="mycred-achieved-badge-btn">Achieved</button>
                    <button class="mycred-not-achieved-badge-btn">Not Achieved</button>
                    <button class="mycred-clear-filter-btn">Clear All</button>
                </form>
            </div>

            <?php 
            if ( $achievement_tabs == 1 ) {

                $badges = mycred_get_categorized_badge_list();

                if ( $badges['category_count'] > 0 ) { ?>
                    <div class="mycred-badges-list-nav">
                        <ul class="mycred-badges-list-tabs">
                            <?php 
                                foreach ( $badges['tabs'] as $id => $element ) {
                                        
                                    echo wp_kses_post( $element );

                                }
                            ?>
                        </ul>
                    </div>
                    <div class="mycred-badges-list-panels">
                        <?php 
                            foreach ( $badges['panels'] as $id => $element ) {
                                    
                                echo wp_kses_post( $element );

                            }
                        ?>
                    </div>
                <?php
                }

            }
            else {

                echo '<div class="mycred-badges-list-all">';
                echo wp_kses_post( mycred_get_uncategorized_badge_list() );
                echo '</div>';
            
            }
            wp_reset_query();
            ?>
        </div>
        <script type="text/javascript">
                
            jQuery(document).ready(function(){

                jQuery('.mycred-badges-list-item').click(function(){

                    window.location.href = jQuery(this).data('url');

                });

                jQuery('.mycred-badges-list-tabs li').click(function(){

                    jQuery('.mycred-badges-list-tabs li').removeClass('active');
                    jQuery( this ).addClass('active');

                    jQuery('.mycred-badges-list-panel').removeClass('active');
                    jQuery('.mycred-badges-list-panel[data-id="'+ jQuery(this).data('id') +'"]').addClass('active');

                });

            });

        </script>

        <?php
        $content = ob_get_clean();

        return apply_filters( 'mycred_badges_list', $content, $atts );
    }

Code file location:

mycred/mycred/addons/badges/myCRED-addon-badges.php

Mycred [MYCRED_buy’] Shortcode

The myCRED_Buy shortcode is used to render a buy points button. This button allows users to purchase points using selected payment gateways. The shortcode also supports gifting points to authors or members.

Shortcode: [MYCRED_buy]

Parameters

Here is a list of all possible MYCRED_buy shortcode parameters and attributes:

  • gateway – Specifies the payment gateway to use.
  • ctype – Defines the type of points to purchase.
  • amount – Sets the amount of points to buy.
  • gift_to – Specifies the user to gift the points to.
  • class – Assigns CSS classes to the purchase button.
  • login – Sets the message for non-logged in users.

Examples and Usage

Basic Example – A simple usage of the mycred shortcode to buy points using the default settings.

[mycred_buy]

Advanced Examples

Buying points with a specified gateway, point type, and amount. This example uses the ‘paypal’ gateway, the default point type, and sets the amount to 100.

[mycred_buy gateway="paypal" ctype="mycred_default" amount="100"]

Customizing the buy points button with a custom CSS class and button label. This example sets the CSS class to ‘my-custom-class’ and the button label to ‘Buy Now’.

[mycred_buy class="my-custom-class" button_label="Buy Now"]

Buying points as a gift for another user. This example sets the ‘gift_to’ parameter to the user ID of the recipient.

[mycred_buy gift_to="2"]

Combining multiple parameters for more advanced usage. This example uses the ‘paypal’ gateway, the default point type, sets the amount to 100, adds a custom CSS class, sets the button label to ‘Buy Now’, and gifts the points to another user.

[mycred_buy gateway="paypal" ctype="mycred_default" amount="100" class="my-custom-class" button_label="Buy Now" gift_to="2"]

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG . '_buy'] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_buy',      'mycred_render_buy_points' );

Shortcode PHP function:

function mycred_render_buy_points( $atts = array(), $button_label = '' ) {

		$settings           = mycred_get_buycred_settings();

		extract( shortcode_atts( array(
			'gateway' => '',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'amount'  => '',
			'gift_to' => '',
			'class'   => 'mycred-buy-link btn btn-primary btn-lg',
			'login'   => $settings['login']
		), $atts, MYCRED_SLUG . '_buy' ) );

		$mycred = mycred( $ctype );

		// If we are not logged in
		if ( ! is_user_logged_in() ) return $mycred->template_tags_general( $login );

		global $mycred_modules, $buycred_sale, $post;

		$buycred            = $mycred_modules['solo']['buycred'];
		$installed          = mycred_get_buycred_gateways();

		// Catch errors
		if ( empty( $installed ) )                                                   return 'No gateways installed.';
		elseif ( ! empty( $gateway ) && ! array_key_exists( $gateway, $installed ) ) return 'Gateway does not exist.';
		elseif ( empty( $buycred->active ) )                                         return 'No active gateways found.';
		elseif ( ! empty( $gateway ) && ! $buycred->is_active( $gateway ) )          return 'The selected gateway is not active.';

		$buycred_sale       = true;

		// Make sure we are trying to sell a point type that is allowed to be purchased
		if ( ! in_array( $ctype, $settings['types'] ) )
			$ctype = $settings['types'][0];

		$args               = array();
		$args['mycred_buy'] = $gateway;
		$classes[]          = $gateway;

		// Prep
		$buyer_id           = get_current_user_id();
		$recipient_id       = $buyer_id;

		if ( $settings['gifting']['authors'] && $gift_to == 'author' )
			$recipient_id = $post->post_author;

		if ( $settings['gifting']['members'] && absint( $gift_to ) !== 0 )
			$recipient_id = absint( $gift_to );

		if ( $recipient_id !== $buyer_id )
			$args['gift_to'] = $recipient_id;

		// Allow user related template tags to be used in the button label
		$button_label       = $mycred->template_tags_general( $button_label );
		$button_label       = $mycred->template_tags_user( $button_label, $recipient_id );

		$args['ctype']      = $ctype;
		$args['amount']     = $amount;
		$args['token']      = wp_create_nonce( 'mycred-buy-creds' );

		// Let others add items to the arguments
		$args               = apply_filters( 'mycred_buy_args', $args, $atts, $mycred );

		// Classes
		$classes            = explode( ' ', $class );

		if ( empty( $classes ) || ! in_array( 'mycred-buy-link', $classes ) )
			$classes[] = 'mycred-buy-link';

		$current_url        = ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) ? set_url_scheme( sanitize_text_field( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) ) : '';( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) ? set_url_scheme( sanitize_text_field( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) ) : '';
		if ( is_ssl() )
			$current_url = str_replace( 'http://', 'https://', $current_url );

		// Construct anchor element to take us to the checkout page
		return '<a href="' . esc_url( add_query_arg( $args, $current_url ) ) . '" data-gateway="' . $gateway . '" class="' . implode( ' ', $classes ) . '" title="' . esc_attr( strip_tags( $button_label ) ) . '">' . do_shortcode( $button_label ) . '</a>';

	}

Code file location:

mycred/mycred/addons/buy-creds/modules/buycred-module-core.php

Mycred [MYCRED_buy_form] Shortcode

The myCRED_buy_form shortcode is used to render a form that allows users to purchase points. It includes various parameters like button label, gateway, point type, amount, and more. . This shortcode checks if the user is logged in, if a usable gateway is available, and if the point type can be purchased. It also handles gifting points to post authors or specific users.

Shortcode: [MYCRED_buy_form]

Parameters

Here is a list of all possible MYCRED_buy_form shortcode parameters and attributes:

  • button – Defines the label of the purchase button.
  • gateway – Specifies the payment gateway to use.
  • ctype – Determines the type of points to purchase.
  • amount – Sets the amount of points to purchase.
  • excluded – Defines the message if the user is excluded from purchasing.
  • maxed – Sets the message if the user has reached the purchase limit.
  • gift_to – Specifies the user ID to gift the points.
  • e_rate – Sets the exchange rate for the points.
  • gift_by – Determines how the gift is identified (i.e., by username).
  • inline – Decides if the form should be inline or not.

Examples and Usage

Basic example – Display a form for users to buy points in the default point type with the default gateway

[mycred_buy_form]

Advanced examples

Displaying a form for users to buy points in a specific point type ‘gold’ with the PayPal gateway

[mycred_buy_form ctype="gold" gateway="paypal"]

Displaying a form for users to buy points with a custom button label ‘Purchase Now’

[mycred_buy_form button="Purchase Now"]

Displaying a form for users to buy points with a specific amount ‘100’

[mycred_buy_form amount="100"]

Displaying a form for users to buy points and gift them to a specific user with the user ID ‘2’

[mycred_buy_form gift_to="2"]

Displaying a form for users to buy points with multiple parameters. In this example, the point type is ‘gold’, the gateway is ‘paypal’, the button label is ‘Purchase Now’, the amount is ‘100’, and the points are gifted to user with ID ‘2’

[mycred_buy_form ctype="gold" gateway="paypal" button="Purchase Now" amount="100" gift_to="2"]

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG . '_buy_form'] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_buy_form', 'mycred_render_buy_form_points' );

Shortcode PHP function:

function mycred_render_buy_form_points( $atts = array(), $content = '' ) {

		$settings     = mycred_get_buycred_settings();

		extract( shortcode_atts( array(
			'button'   => __( 'Buy Now', 'mycred' ),
			'gateway'  => '',
			'ctype'    => '',
			'amount'   => '',
			'excluded' => '',
			'maxed'    => '',
			'gift_to'  => '',
			'e_rate'   => '',
			'gift_by'  => __( 'Username', 'mycred' ),
			'inline'   => 0
		), $atts, MYCRED_SLUG . '_buy_form' ) );

		// If we are not logged in
		if ( ! is_user_logged_in() ) return $content;

		global $post, $buycred_instance, $buycred_sale;

		// Prepare
		$buyer_id     = get_current_user_id();
		$recipient_id = $buyer_id;
		$classes      = array( 'myCRED-buy-form' );
		$amounts      = array();
		$gifting      = false;
		$point_types  = array();

		$type_keys = $settings['types'];

		if ( ! empty( $atts['ctype'] ) ) {
			$given_types = explode( ',' , $atts['ctype'] );
			$type_keys = array_intersect( $settings['types'], $given_types );
			
		}

		if( !empty( $type_keys ) && empty( $atts['ctype'] ) ) {
			$type_keys[] = $settings['types'][0];

		}

		foreach( $type_keys as $type_key ){
			$point_types[] = array( $type_key ,mycred_get_point_type_name( $type_key, false ) );
			if( !empty( $type_keys ) && empty( $atts['ctype'] ) )
				break;
		}
			
		// Make sure we have a gateway we can use
		if ( ( ! empty( $gateway ) && ! mycred_buycred_gateway_is_usable( $gateway ) ) || ( empty( $gateway ) && empty( $buycred_instance->active ) ) )
			return 'No gateway available.';

		// Make sure we are trying to sell a point type that is allowed to be purchased
		if ( ! in_array( $ctype, $settings['types'] ) )
			$ctype = $settings['types'][0];

		$mycred       = mycred( $ctype );
		$setup        = mycred_get_buycred_sale_setup( $ctype );

		$remaining    = mycred_user_can_buycred( $buyer_id, $ctype );

		// We are excluded from this point type
		if ( $remaining === false ) return $excluded;

		// We have reached a max purchase limit
		elseif ( $remaining === 0 ) return $maxed;

		// From this moment on, we need to indicate the shortcode usage for scripts and styles.
		$buycred_sale = true;

		// Amount - This can be one single amount or a comma separated list
		$minimum      = $mycred->number( $setup['min'] );

		if ( ! empty( $amount ) ) {
			foreach ( explode( ',', $amount ) as $value ) {
				$value     = $mycred->number( abs( trim( $value ) ) );
				if ( $value < $minimum ) continue;
				$amounts[] = $value;
			}
		}

		// If we want to gift this to the post author (must be used inside the loop)
		if ( $settings['gifting']['authors'] && $gift_to == 'author' ) {
			$recipient_id = absint( $post->post_author );
			$gifting      = true;
		}

		// If we have nominated a user ID to be the recipient, use it
		elseif ( $settings['gifting']['members'] && absint( $gift_to ) !== 0 ) {
			$recipient_id = absint( $gift_to );
			$gifting      = true;
		}

		// Button Label
		$button_label = $mycred->template_tags_general( $button );

		if ( ! empty( $gateway ) ) {
			$gateway_name = explode( ' ', $buycred_instance->active[ $gateway ]['title'] );
			$button_label = str_replace( '%gateway%', $gateway_name[0], $button_label );
			$classes[]    = $gateway_name[0];
		}

		ob_start();

		if ( ! empty( $buycred_instance->gateway->errors ) ) {

			foreach ( $buycred_instance->gateway->errors as $error )
				echo '<div class="alert alert-warnng"><p>' . esc_html( $error ) . '</p></div>';

		}

?>
<div class="row">
	<div class="col-xs-12">
		<form method="post" class="form<?php if ( $inline == 1 ) echo esc_attr( '-inline' ); ?> <?php echo esc_attr( implode( ' ', $classes ) ); ?>" action="">
			<input type="hidden" name="token" value="<?php echo esc_attr( wp_create_nonce( 'mycred-buy-creds' ) ); ?>" />
				<?php
				if( count( $point_types ) > 1 ){ ?>
					<select name="ctype" class="mycred-change-pointtypes">
						<?php foreach ( $point_types as $key => $value ) :?>
							<option value="<?php echo esc_attr( $value[0] ); ?>"><?php echo esc_html( $value[1] ); ?></option><?php endforeach;?>
					</select><?php 
				}else{ ?>
					<input type="hidden" name="ctype" value="<?php echo esc_attr( $point_types[0][0] ); ?>" /><?php 
				} 

				if( ! empty( $e_rate ) ) { 
					$e_rate = mycred_encode_values( $e_rate );
				?>
			<input type="hidden" name="er_random" value="<?php echo esc_attr( $e_rate ); ?>" />
			<?php } ?>			
			<div class="form-group">
				<label class="mycred-point-type"><?php echo esc_html( $point_types[0][1] ); ?></label>
<?php

		// No amount given - user must nominate the amount
		if ( count( $amounts ) == 0 ) {

?>
				<input type="text" name="amount" class="form-control" placeholder="<?php echo esc_attr( $mycred->format_creds( $minimum ) ); ?>" min="<?php echo esc_attr( $minimum );?>" value="" />
<?php

		}

		// One amount - this is the amount a user must buy
		elseif ( count( $amounts ) == 1 ) {

?>
				<p class="form-control-static"><?php echo esc_html( $mycred->format_creds( $amounts[0] ) ); ?></p>
				<input type="hidden" name="amount" value="<?php echo esc_attr( $amounts[0] ); ?>" />
<?php

		}

		// Multiple amounts - user selects the amount from a dropdown menu
		else {

?>
				<select name="amount" class="form-control">
<?php

				foreach ( $amounts as $amount ) {

					echo '<option value="' . esc_attr( $amount ) . '"';

					// If we enforce a maximum and the nominated amount is higher than we can buy,
					// disable the option
					if ( $remaining !== true && $remaining < $amount ) echo ' disabled="disabled"';

					echo '>' . esc_html( $mycred->format_creds( $amount ) ) . '</option>';

				}

?>
				</select>
<?php

		}

		// A recipient is set
		if ( $gifting ) {

			$user = get_userdata( $recipient_id );

?>
				<div class="form-group">
					<label for="gift_to"><?php esc_html_e( 'Recipient', 'mycred' ); ?></label>
					<p class="form-control-static"><?php echo esc_html( $user->display_name ); ?></p>
					<input type="hidden" name="<?php if ( $gift_to == 'author' ) echo 'post_id'; else echo 'gift_to'; ?>" value="<?php echo absint( $recipient_id ); ?>" />
				</div>
<?php

		}

		// The payment gateway needs to be selected
		if ( empty( $gateway ) && count( $buycred_instance->active ) > 1 ) {

?>
				<div class="form-group">
					<label for="gateway"><?php esc_html_e( 'Pay Using', 'mycred' ); ?></label>
					<select name="mycred_buy" class="form-control">
<?php

			$active_gateways = apply_filters( 'mycred_buycred_sort_gateways', $buycred_instance->active, $atts );
			foreach ( $active_gateways as $gateway_id => $info )
				echo '<option value="' . esc_attr( $gateway_id ) . '">' . esc_html( $info['title'] ) . '</option>';

?>
					</select>
				</div>
<?php

		}

		// The gateway is set or we just have one gateway enabled
		else {

			// If no gateway is set, use the first active gateway
			if (  empty( $gateway ) && count( $buycred_instance->active ) > 0 )
				$gateway = array_keys( $buycred_instance->active )[0];

?>
				<input type="hidden" name="mycred_buy" value="<?php echo esc_attr( $gateway ); ?>" />
<?php

		}

?>
				</div>

				<div class="form-group">
					<button class="button btn btn-block btn-lg" ><?php echo esc_html( $button_label ); ?></button>
				</div>

		</form>
	</div>
</div>
<?php

		$content = ob_get_contents();
		ob_end_clean();

		return $content;

	}

Code file location:

mycred/mycred/addons/buy-creds/modules/buycred-module-core.php

Mycred [myCRED_Buy_Pending] Shortcode

The myCRED_Buy_Pending shortcode is designed to display a logged-in user’s pending purchases. It extracts the user’s ID and retrieves the pending payments related to that user. This shortcode then generates a table, listing each pending transaction’s ID, associated gateway, amount, cost, and the available actions (Pay Now or Cancel). If no pending payments are found, a message is displayed.

Shortcode: [myCRED_Buy_Pending]

Parameters

Here is a list of all possible myCRED_Buy_Pending shortcode parameters and attributes:

  • ctype – indicates the type of points to consider for the pending payments
  • pay_now – text for the ‘Pay Now’ button in the user’s preferred language
  • cancel – text for the ‘Cancel’ button in the user’s preferred language

Examples and Usage

Basic example – Displaying pending payments for the current user in default point type

[mycred_buy_pending]

Advanced examples

Displaying pending payments for the current user with a specific point type, and customizing the text for the “Pay Now” and “Cancel” actions.

[mycred_buy_pending ctype="gold" pay_now="Proceed to Payment" cancel="Dismiss"]

Displaying pending payments for the current user with a specific point type, and leaving the “Pay Now” and “Cancel” actions with their default text.

[mycred_buy_pending ctype="silver"]

Displaying pending payments for the current user in default point type, and customizing the text for the “Pay Now” action.

[mycred_buy_pending pay_now="Make Payment"]

Displaying pending payments for the current user in default point type, and customizing the text for the “Cancel” action.

[mycred_buy_pending cancel="Abort Transaction"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_Buy_Pending] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_buy_pending', 'mycred_render_pending_purchases' );

Shortcode PHP function:

function mycred_render_pending_purchases( $atts = array(), $content = '' ) {

		// Must be logged in
		if ( ! is_user_logged_in() ) return $content;

		extract( shortcode_atts( array(
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'pay_now' => __( 'Pay Now', 'mycred' ),
			'cancel'  => __( 'Cancel', 'mycred' )
		), $atts, MYCRED_SLUG . '_buy_pending' ) );

		$user_id = get_current_user_id();
		$pending = buycred_get_users_pending_payments( $user_id, $ctype );

		global $mycred_modules, $buycred_sale;

		$buycred = $mycred_modules['solo']['buycred-pending'];

		ob_start();

?>
<div id="pending-buycred-payments-<?php echo esc_attr( $ctype ); ?>">
	<table class="table">
		<thead>
			<tr>
				<th class="column-transaction-id"><?php esc_html_e( 'Transaction ID', 'mycred' ); ?></th>
				<th class="column-gateway"><?php esc_html_e( 'Gateway', 'mycred' ); ?></th>
				<th class="column-amount"><?php esc_html_e( 'Amount', 'mycred' ); ?></th>
				<th class="column-cost"><?php esc_html_e( 'Cost', 'mycred' ); ?></th>
				<?php if ( $ctype == '' ) : ?><th class="column-ctype"><?php esc_html_e( 'Point Type', 'mycred' ); ?></th><?php endif; ?>
				<th class="column-actions"><?php esc_html_e( 'Actions', 'mycred' ); ?></th>
			</tr>
		</thead>
		<tbody>
<?php

		if ( ! empty( $pending ) ) {

			// Showing all point types
			if ( $ctype == '' ) {

				foreach ( $pending as $point_type => $entries ) {

					if ( empty( $entries ) ) continue;

					foreach ( $entries as $entry ) {

?>
			<tr>
				<td class="column-transaction-id"><?php echo esc_html( $entry->public_id ); ?></td>
				<td class="column-gateway"><?php echo esc_html( $buycred->adjust_column_content( 'gateway', $entry->payment_id ) ); ?></td>
				<td class="column-amount"><?php echo esc_html( $buycred->adjust_column_content( 'amount', $entry->payment_id ) ); ?></td>
				<td class="column-cost"><?php echo esc_html( $buycred->adjust_column_content( 'cost', $entry->payment_id ) ); ?></td>
				<td class="column-ctype"><?php echo esc_html( mycred_get_point_type_name( $entry->point_type, false ) ); ?></td>
				<td class="column-actions">
					<?php if( $entry->gateway_id != 'bank' ):?>
						<a href="<?php echo esc_url( $entry->pay_now_url ); ?>"><?php echo esc_html( $pay_now ); ?></a> &bull; 
					<?php endif; ?>
					<a href="<?php echo esc_url( $entry->cancel_url ); ?>"><?php echo esc_html( $cancel ); ?></a>
				</td>
			</tr>
<?php
 
					}

				}

			}

			// Showing a particular point type
			else {

				foreach ( $pending as $entry ) {

?>
			<tr>
				<td class="column-transaction-id"><?php echo esc_html( $entry->public_id ); ?></td>
				<td class="column-gateway"><?php echo esc_html( $buycred->adjust_column_content( 'gateway', $entry->payment_id ) ); ?></td>
				<td class="column-amount"><?php echo esc_html( $buycred->adjust_column_content( 'amount', $entry->payment_id ) ); ?></td>
				<td class="column-cost"><?php echo esc_html( $buycred->adjust_column_content( 'cost', $entry->payment_id ) ); ?></td>
				<td class="column-actions">
					<?php if( $entry->gateway_id != 'bank' ):?>
						<a href="<?php echo esc_url( $entry->pay_now_url ); ?>"><?php echo esc_html( $pay_now ); ?></a> &bull; 
					<?php endif; ?>
					<a href="<?php echo esc_url( $entry->cancel_url ); ?>"><?php echo esc_html( $cancel ); ?></a>
				</td>
			</tr>
<?php

				}

			}

		}
		else {

?>
			<tr>
				<td colspan="<?php if ( $ctype == '' ) echo '6'; else echo '5'; ?>"><?php esc_html_e( 'No pending payments found', 'mycred' ); ?></td>
			</tr>
<?php

		}

?>
		</tbody>
	</table>
</div>
<?php

		$output = ob_get_contents();
		ob_end_clean();

		return $output;

	}

Code file location:

mycred/mycred/addons/buy-creds/modules/buycred-module-pending.php

Mycred [mycred_cashcred] Shortcode

The myCRED CashCred shortcode is a powerful tool that facilitates the withdrawal of user points in WordPress. It allows users to submit withdrawal requests, view approved requests, and track cancelled requests. The shortcode provides an interface for users to select their desired point type and payment method for withdrawal. It also displays the total withdrawal amount and a submit button to finalize the request. The shortcode also checks for user login status, available gateways, and sufficient points for withdrawal. It’s a comprehensive solution for managing point withdrawals in WordPress.

Shortcode: [mycred_cashcred]

Parameters

Here is a list of all possible mycred_cashcred shortcode parameters and attributes:

  • button – label of the submit button on the form
  • gateways – defines the payment gateways to use
  • types – specifies the point types for withdrawal
  • amount – sets the withdrawal amount
  • excluded – message displayed when the user is excluded from the point type
  • insufficient – message shown when the user has insufficient points for withdrawal

Examples and Usage

Basic example – Displaying the withdrawal form with a custom submit button text

[mycred_cashcred button="Click to Withdraw"]

Advanced examples

Displaying the withdrawal form with a custom submit button text, specific gateways, point types, and a custom message for excluded users.

[mycred_cashcred button="Submit Your Request" gateways="paypal,stripe" types="gold,silver" excluded="Sorry, you cannot access this point type."]

Displaying the withdrawal form with a custom submit button text, specific gateways, point types, and a custom message for users with insufficient points.

[mycred_cashcred button="Submit Your Request" gateways="paypal,stripe" types="gold,silver" insufficient="Sorry, you do not have enough points for withdrawal."]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_cashcred] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_cashcred', 'mycred_render_cashcred' );

Shortcode PHP function:

function mycred_render_cashcred( $atts = array(), $content = '' ) {

		extract( shortcode_atts( array(
			'button'       => __( 'Submit Request', 'mycred' ),
			'gateways'     => '',
			'types'        => '',
			'amount'       => '',
			'excluded'     => __( 'You have excluded from this point type', 'mycred' ),
			'insufficient' => __( 'Insufficient Points for Withdrawal', 'mycred' )
		), $atts, MYCRED_SLUG . '_cashcred' ) );


		// If we are not logged in
		if ( ! is_user_logged_in() ) return $content;

		global $cashcred_instance, $mycred_modules, $cashcred_withdraw;
		
		// Prepare
		$user_id = get_current_user_id();

		$gateways = cashcred_get_usable_gateways( $gateways );

		// Make sure we have a gateway we can use
		if ( empty( $gateways ) ) return __( 'No gateway available.', 'mycred' );

		$point_types = cashcred_get_point_types( $types, $user_id );

		//We are excluded
		if ( empty( $point_types ) ) return $excluded;

		$point_types = cashcred_is_user_have_balances( $point_types, $user_id );

		//Insufficient points for withdrawal.
		if ( empty( $point_types ) ) return $insufficient;

		// From this moment on, we need to indicate the shortcode usage for scripts and styles.
		$cashcred_withdraw = true;

		// Button Label
		$button_label = $point_types[ current(array_keys($point_types)) ]->template_tags_general( $button );

		$cashcred_setting = mycred_get_cashcred_settings();

		ob_start();
			
		$pending_withdrawal = cashcred_get_withdraw_requests('Pending');


	?>
<div id="cashcred">
	<ul class="cashcred-nav-tabs">
		<li id="tab1" class="active"><?php esc_html_e( 'Withdraw Request', 'mycred' ); ?></li>
		<li id="tab2"><?php esc_html_e( 'Approved Requests', 'mycred' ); ?></li>
		<li id="tab3"><?php esc_html_e( 'Cancelled Requests', 'mycred' ); ?></li>
		<li id="tab4"><?php esc_html_e( 'Payment Settings', 'mycred' ); ?></li>
	</ul>
	<div id="cashcred_tab_content">
		<!--------First tab--------->
		<div id="tab1c" class="cashcred-tab">
			<?php cashcred_display_message(); ?>

			
			<?php if( count( $pending_withdrawal ) > 0 ){ ?>
			<h4><?php esc_html_e( 'You have pending withdrawal', 'mycred' ); ?></h4>
			<table>
				<thead class="cashcred-table-heading">
					<tr>
						<th>ID</th>
						<th>Points</th>
						<?php
							if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
								if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
									<th><span class="nobr"><?php esc_html_e( 'Fee', 'mycred' ) ?></span></th><?php
								}
							}?>



						<th><?php esc_html_e( 'Amount', 'mycred' ) ?></th>
						<th><?php esc_html_e( 'Point Type', 'mycred' ) ?></th>
						<th>
							<?php 
							// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
							apply_filters( 'mycred_change_gateway_text', 'Gateway' ); 
							?>	
						</th>

						
						<th class="date-heading">Date</th>
					</tr>
				</thead>
				<tbody class="cashcred-table-content">
					<?php foreach( $pending_withdrawal as $post ):?>
					<tr class="cashcred-table-content">
						<td><?php echo esc_html( $post->post_name ); ?></td>
						<td><?php echo esc_html( get_post_meta($post->ID,'points',true) );?></td>
						<?php 

						if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
							
							if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
							
								<td><?php 
															
									$type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID,'point_type',true)];
										
									if ( $type_data['by'] == 'percent' ) {
										$fee = !empty($type_data['amount']) ? ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID,'points',true) ) : '';
									}
									else{
										$fee = $type_data['amount'];
									}

									if( $type_data['min_cap'] != 0 )
										$fee = $fee + $type_data['min_cap'];

									if( $type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] )
										$fee = $type_data['max_cap'];

									echo esc_html( $fee ); ?>
								</td><?php
							} 
						}?>
						<td>

							<?php echo esc_html( get_post_meta($post->ID,'currency',true). " " .get_post_meta($post->ID,'points',true) * get_post_meta($post->ID,'cost',true) ); ?>
						</td>
						<td><?php echo esc_html( mycred_get_types()[get_post_meta($post->ID,'point_type',true)] );?></td>
						<td>
					 		<?php 
								$gateway = get_post_meta($post->ID,'gateway',true);
								$installed = $mycred_modules['solo']['cashcred']->get();
								if ( isset( $installed[ $gateway ] ) )
									echo esc_html( $installed[ $gateway ]['title'] );
								else
									echo esc_html( $gateway );
							?>
						</td>
						<td class="date-format"><?php echo esc_html( $post->post_date ); ?>
							
						</td>
					</tr>
					<?php endforeach;?>				
				</tbody>
			</table>	
			<?php } else {
                $mycred_cashcred_gateway_notice = apply_filters( 'mycred_cashcred_gateway_notice', 'Selected gateway details are incomplete.' );
			    ?>

			<div class="cashcred_gateway_notice"><?php esc_html_e( $mycred_cashcred_gateway_notice, 'mycred' ) ?></div>

			<form method="post" class="mycred-cashcred-form" action="">

				<?php wp_nonce_field( 'cashCred-withdraw-request', 'cashcred_withdraw_wpnonce' ); ?>
				
				<?php if( count( $point_types ) > 1 ) {?>
					<div class="form-group"> 
						<label for="gateway"><?php esc_html_e( 'Withdraw Point Type', 'mycred' ); ?></label>
						<select id="cashcred_point_type" name="cashcred_point_type" class="form-control">
							<?php 
								foreach( $point_types as $point_type_id => $point_type_obj ) {
									echo '<option value="' . esc_attr( $point_type_id ) . '">' . esc_html( $point_type_obj->plural() ) . '</option>'; 
								}
							?>
						</select>
					</div>
				<?php } else {?>
					<input type="hidden" id="cashcred_point_type" name="cashcred_point_type" value="<?php echo esc_attr( current(array_keys($point_types)) ); ?>" />
				<?php } ?>

				<?php if ( count( $gateways ) > 1 ) { ?>
					<div class="form-group"> 
						<label for="gateway"><?php esc_html_e( 'Withdrawal Payment Method', 'mycred' ); ?></label>
						<select id="cashcred_pay_method" name="cashcred_pay_method" class="form-control">
							<?php 
								foreach ( $gateways as $gateway_id => $gateway_data ) {
									echo '<option value="' . esc_attr( $gateway_id ) . '">' . esc_html( $gateway_data['title'] ) . '</option>';
								}
							?>
						</select>
					</div>
				<?php } else { ?>
					<input type="hidden" id="cashcred_pay_method" name="cashcred_pay_method" value="<?php echo esc_attr( current(array_keys($gateways)) ); ?>" />
				<?php } ?>

			<div class="form-group">  
				<label><?php echo sprintf( esc_html__('Withdraw %s value', 'mycred'), esc_html( $point_types[ current(array_keys($point_types)) ]->plural() ) ); ?></label>
				<?php 
					$amount = ! empty( $amount ) ? floatval( $amount ) : 0;
					
				?> 
				<input type="number" id="withdraw_points" name="points" class="form-control" placeholder="0" step="any" value="<?php echo ! empty($amount) ? esc_attr( $amount ) : 0; ?>" required />
				<p class="cashcred-min"><?php echo esc_html__('Minimum Amount: ', 'mycred');?><span></span></p>
				
				<?php 
				
				if ( ! empty( $cashcred_setting['fees'] ) ){

				 	if( $cashcred_setting['fees']['use'] == 1 ) { ?>
					
						<p class="cashcred-fee" ><?php echo esc_html__('Fee : ', 'mycred'); ?>
							
							<span></span>
							
						</p> <?php
					}

					$format = array();	
					foreach ($point_types as $key => $value) {
						$format[$key] = $point_types[$key]->core['format'];
						
					}

					wp_localize_script( 'cashcred-withdraw', 'cashcred_data', 
						array( 
							'cashcred_setting' => $cashcred_setting['fees'],
							'format' => $format,
						)
					);
					
				}
				?>
			</div>
			<div class="mycred-cashcred-withdraw-form-footer">
				<div id="cashcred_total" class="form-group">
					<strong>
						<span class="amount_label"><?php echo esc_html__( 'Amount:', 'mycred' ); ?></span>
						<span id="cashcred_currency_symbol"></span> 
						<span id="cashcred_total_amount"></span>
					</strong>
				</div>
				<div id="submit_button" class="form-group">
					<input type="submit" class="button" value="<?php echo esc_attr( $button_label ); ?>" />
				</div>
				<div class="mycred-clearfix"></div>
			</div>
		</form>
		<?php } ?>
		</div>
		<!--------End First tab--------->

		<!--------Secound tab--------->
		<div id="tab2c" class="cashcred-tab">
			<h4>Approved Requests</h4>
			<?php	
				$posts = cashcred_get_withdraw_requests('Approved');
			?>		
			<table>
				<thead>
					<tr>
						<th>ID</th>
						<th>Points</th>
						<?php
						if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
							if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
								<th><span class="nobr">Fee</span></th><?php
							}
						}?>
						<th><?php esc_html_e( 'Amount', 'mycred' ) ?></th>
						<th><?php esc_html_e( 'Point Type', 'mycred' ) ?></th>
						<th>
							<?php 
							// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
							apply_filters( 'mycred_change_gateway_text', 'Gateway' ); 
							?>	
						</th>
						<th>Date</th>


					</tr>
				</thead>
				<tbody>
					<?php foreach($posts as $post) {
						
						?>
					<tr>
						<td><?php echo esc_html( $post->post_name ); ?></td>
						<td><?php echo esc_html( get_post_meta($post->ID,'points',true) );?></td>
						<?php 
						if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
							
							if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
							
								<td><?php 
															
									$type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID,'point_type',true)];
										
									if ( $type_data['by'] == 'percent' ) {
										$fee = !empty($type_data['amount']) ? ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID,'points',true) ) : '';
									}
									else{
										$fee = $type_data['amount'];
									}

									if( $type_data['min_cap'] != 0 )
										$fee = $fee + $type_data['min_cap'];

									if( $type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] )
										$fee = $type_data['max_cap'];

									echo esc_html( $fee ); ?>
								</td><?php
							} 
						}?>
						<td>
							<?php echo esc_html( get_post_meta($post->ID,'currency',true). " " .get_post_meta($post->ID,'points',true) * get_post_meta($post->ID,'cost',true) );?>
						</td>
						<td><?php echo esc_html( mycred_get_types()[get_post_meta($post->ID,'point_type',true)] ); ?></td>
						<td>
							<?php 
								$gateway = get_post_meta($post->ID,'gateway',true);
								$installed = $mycred_modules['solo']['cashcred']->get();
								if ( isset( $installed[ $gateway ] ) )
									echo esc_html( $installed[ $gateway ]['title'] );
								else
									echo esc_html( $gateway );
							?>
						</td>
						<td><?php echo esc_html( $post->post_date ); ?></td>
					</tr>
					<?php } ?>
		 		</tbody>
			</table>
		</div>
		<!--------End Secound tab--------->

		<!--------Third tab--------->
		<div id="tab3c" class="cashcred-tab">
			<h4>Cancelled Requests</h4>
			<?php
				$posts = cashcred_get_withdraw_requests('Cancelled');
			?>
			
			<table>
				<thead>
					<tr>
						<th><span class="nobr"><?php esc_html_e( 'ID', 'mycred' ) ?></span></th>
						<th><span class="nobr"><?php esc_html_e(  'Points', 'mycred' ) ?></span></th>
						<?php
						if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
							if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
								<th><span class="nobr">Fee</span></th><?php
							}
						}?>
						<th><?php esc_html_e(  'Amount', 'mycred' ) ?></th>
						<th><?php esc_html_e(  'Point Type', 'mycred' ) ?></th>
						<th>
							<?php 
							// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
							apply_filters( 'mycred_change_gateway_text', 'Gateway' ); 
							?>			
						</th>
						<th><?php esc_html_e( 'Date', 'mycred' ) ?></th>

					</tr>
				</thead>
				<tbody>
					<?php foreach($posts as $post) {

						?>
					<tr>
					 	<td><?php echo esc_html( $post->post_name ); ?></td>
						
						<td><?php echo esc_html( get_post_meta($post->ID,'points',true ) );?></td>
						<?php 
						if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
							
							if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
							
								<td><?php 
															
									$type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID,'point_type',true)];
										
									if ( $type_data['by'] == 'percent' ) {
										$fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID,'points',true) );
									}
									else{
										$fee = $type_data['amount'];
									}

									if( $type_data['min_cap'] != 0 )
										$fee = $fee + $type_data['min_cap'];

									if( $type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] )
										$fee = $type_data['max_cap'];

									echo esc_html( $fee ); ?>
								</td><?php
							} 
						}?>
						<td>
							<?php echo esc_html( get_post_meta($post->ID,'currency',true). " " .get_post_meta($post->ID,'points',true) * get_post_meta($post->ID,'cost',true) );?>
						</td>
						<td><?php echo esc_html( mycred_get_types()[get_post_meta($post->ID,'point_type',true)] );?></td>
						<td>
						<?php 
							$gateway = get_post_meta($post->ID,'gateway',true);
							$installed = $mycred_modules['solo']['cashcred']->get();
							if ( isset( $installed[ $gateway ] ) )
								echo esc_html( $installed[ $gateway ]['title'] );
							else
								echo esc_html( $gateway );
							?>
						</td>
						<td><?php echo esc_html( $post->post_date ); ?></td>
					</tr>
					<?php } ?>
				</tbody>
			</table>
		</div>
		<!--------End Third tab--------->

		<!--------Fourth tab--------->
		<div id="tab4c" class="cashcred-tab">
			<form action="" method="POST">
				<?php if ( count( $gateways ) > 1 ):?>
					<select class="form-control" name="cashcred_save_settings" id="cashcred_save_settings">
						<?php 
							foreach ( $gateways as $key => $active_gateways_value ) {
								echo '<option value="' . esc_attr( $key ). '"> '. esc_html( $active_gateways_value['title'] ) .' </option>';
							}
						?>
					</select>
				<?php else:?>
					<input type="hidden" name="cashcred_save_settings" id="cashcred_save_settings" value="<?php echo esc_attr( current(array_keys($gateways)) ); ?>" />
				<?php endif;?>
				<?php 
					wp_nonce_field( 'cashCred-payment-settings', 'cashcred_settings_wpnonce' );

				    foreach ( $gateways as $key => $active_gateways_value ) {
						
						$MyCred_payment_setting_call = new $active_gateways_value['callback'][0]($key);
						$MyCred_payment_setting_call->cashcred_payment_settings($key) ;
							
					}
				?>
				<div id="cashcred_save_settings" class="form-group">
					<input type="submit" class="button" value="Save" />
				</div>
			</form>	
		</div>
		<!--------End Fourth tab--------->
	</div>
</div>
<?php
		$content = ob_get_contents();
		ob_end_clean();
		return $content;
	}

Code file location:

mycred/mycred/addons/cash-creds/modules/cashcred-module-core.php

Mycred [myCRED_load_coupon] Shortcode

The myCRED_load_coupon shortcode is used to render a form that allows users to apply coupon codes. The form is only displayed to logged-in users. Upon form submission, the shortcode verifies the coupon code, checks its validity, and applies it to the user’s account. If the coupon code is invalid, an error message is displayed. Shortcode: [myCRED_load_coupon]

Shortcode: [myCRED_load_coupon]

Parameters

Here is a list of all possible myCRED_load_coupon shortcode parameters and attributes:

  • label – Text that appears as the label for the coupon input field.
  • button – Text that appears on the coupon apply button.
  • placeholder – Text that appears within the coupon input field when it’s empty.

Examples and Usage

Basic example – In this example, we are going to use the shortcode to load a coupon form with default parameters.

[mycred_load_coupon]

Advanced examples

Customizing the label, button text, and placeholder for the coupon form. This will change the default label “Coupon” to “Enter your coupon”, the default button text “Apply Coupon” to “Redeem”, and set a placeholder “Enter coupon code here”.

[mycred_load_coupon label="Enter your coupon" button="Redeem" placeholder="Enter coupon code here"]

Another example could be to only change the placeholder text, leaving the label and button text to their default values.

[mycred_load_coupon placeholder="Enter your special code"]

These examples show how the mycred_load_coupon shortcode can be used in various ways to customize the coupon form according to the specific needs of your WordPress site.

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_load_coupon] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_load_coupon', 'mycred_render_shortcode_load_coupon' );

Shortcode PHP function:

function mycred_render_shortcode_load_coupon( $atts, $content = NULL ) {

		if ( ! is_user_logged_in() )
			return $content;

		extract( shortcode_atts( array(
			'label'       => 'Coupon',
			'button'      => 'Apply Coupon',
			'placeholder' => ''
		), $atts, MYCRED_SLUG . '_load_coupon' ) );

		$mycred = mycred();
		if ( ! isset( $mycred->coupons ) )
			return '<p><strong>Coupon Add-on settings are missing! Please visit the myCRED > Settings page to save your settings before using this shortcode.</strong></p>';

		// Prep
		$user_id = get_current_user_id();

		$output  = '<div class="mycred-coupon-form">';

		// On submits
		if ( isset( $_POST['mycred_coupon_load']['token'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mycred_coupon_load']['token'] ) ), 'mycred-load-coupon' . $user_id ) ) {

			$coupon_code = isset( $_POST['mycred_coupon_load']['couponkey'] ) ? sanitize_text_field( wp_unslash( $_POST['mycred_coupon_load']['couponkey'] ) ) : '';
			$coupon_post = mycred_get_coupon_post( $coupon_code );
			if ( isset( $coupon_post->ID ) ) {

				$coupon      = mycred_get_coupon( $coupon_post->ID );

				// Attempt to use this coupon
				$load        = mycred_use_coupon( $coupon_code, $user_id );

				// Load myCRED in the type we are paying out for messages
				if ( isset( $coupon->point_type ) && $coupon->point_type != $mycred->cred_id )
					$mycred = mycred( $coupon->point_type );

				// That did not work out well, need to show an error message
				if ( ! mycred_coupon_was_successfully_used( $load ) ) {

					$message = mycred_get_coupon_error_message( $load, $coupon );
					$message = $mycred->template_tags_general( $message );
					$output .= '<div class="alert alert-danger">' . $message . '</div>';

				}

				// Success!
				else {

					//$message = $mycred->template_tags_amount( $mycred->coupons['success'], $coupon->value );
					$updated_coupon_value=$coupon->value;
					$updated_coupon_value=apply_filters('mycred_show_custom_coupon_value',$updated_coupon_value);
					$coupon_settings = mycred_get_addon_settings( 'coupons' ,  $coupon->point_type  );
					$message = $mycred->template_tags_amount( $coupon_settings['success'], $updated_coupon_value );   // without filter
					$message = str_replace( '%amount%', $mycred->format_creds( $updated_coupon_value ), $message );
					$output .= '<div class="alert alert-success">' . $message . '</div>';

				}

			}

			// Invalid coupon
			else {

				$message = mycred_get_coupon_error_message( 'invalid' );
				$message = $mycred->template_tags_general( $message );
				$output .= '<div class="alert alert-danger">' . $message . '</div>';

			}

		}

		if ( $label != '' )
			$label = '<label for="mycred-coupon-code">' . $label . '</label>';

		$output .= '
	<form action="" method="post" class="form-inline">
		<div class="form-group">
			' . $label . '
			<input type="text" name="mycred_coupon_load[couponkey]" placeholder="' . esc_attr( $placeholder ) . '" id="mycred-coupon-couponkey" class="form-control" value="" />
		</div>
		<div class="form-group">
			<input type="hidden" name="mycred_coupon_load[token]" value="' . wp_create_nonce( 'mycred-load-coupon' . $user_id ) . '" />
			<input type="submit" class="btn btn-primary" value="' . $button . '" />
		</div>
	</form>
</div>';

		return apply_filters( 'mycred_load_coupon', $output, $atts, $content );

	}

Code file location:

mycred/mycred/addons/coupons/myCRED-addon-coupons.php

Mycred [mycred_email_subscriptions] Shortcode

The myCRED Email Subscriptions shortcode allows users to manage their email notifications. It displays a form with a list of all active email notifications, where users can select which emails to unsubscribe from.

Shortcode: [mycred_email_subscriptions]

Examples and Usage

Basic example – Displaying default email subscription settings for the logged-in user.

[mycred_email_subscriptions /]

Advanced examples

Displaying email subscription settings for the logged-in user with a custom success message once settings are updated.

[mycred_email_subscriptions success="Your settings have been successfully updated!" /]

Using the shortcode to display email subscription settings for the logged-in user within a specific content.

[mycred_email_subscriptions]Here is your email subscription settings.[/mycred_email_subscriptions]

Please note that the shortcode will only work if the user is logged in. If the user is not logged in, the shortcode will return the content inside the shortcode if there is any. If there is no content, it will not display anything.

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_email_subscriptions] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_email_subscriptions', 'mycred_render_email_subscriptions' );

Shortcode PHP function:

function mycred_render_email_subscriptions( $atts = array(), $content = '' ) {

		extract( shortcode_atts( array(
			'success' => __( 'Settings Updated', 'mycred' )
		), $atts, MYCRED_SLUG . '_email_subscriptions' ) );

		if ( ! is_user_logged_in() ) return $content;

		$user_id         = get_current_user_id();
		$unsubscriptions = mycred_get_user_meta( $user_id, 'mycred_email_unsubscriptions', '', true );

		if ( $unsubscriptions == '' ) $unsubscriptions = array();

		// Save
		$saved           = false;
		if ( isset( $_REQUEST['do'] ) && $_REQUEST['do'] == 'mycred-unsubscribe' && isset( $_REQUEST['token'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['token'] ) ), 'update-mycred-email-subscriptions' ) ) {

			if ( isset( $_POST['mycred_email_unsubscribe'] ) && ! empty( $_POST['mycred_email_unsubscribe'] ) )
				$new_selection = sanitize_email( wp_unslash( $_POST['mycred_email_unsubscribe'] ) );
			else
				$new_selection = array();

			mycred_update_user_meta( $user_id, 'mycred_email_unsubscriptions', '', $new_selection );
			$unsubscriptions = $new_selection;
			$saved           = true;

		}

		global $wpdb;

		$email_notices   = $wpdb->get_results( $wpdb->prepare( "
			SELECT * 
			FROM {$wpdb->posts} notices

			LEFT JOIN {$wpdb->postmeta} prefs 
				ON ( notices.ID = prefs.post_id AND prefs.meta_key = 'mycred_email_settings' )

			WHERE notices.post_type = 'mycred_email_notice' 
				AND notices.post_status = 'publish'
				AND ( prefs.meta_value LIKE %s OR prefs.meta_value LIKE %s );", '%s:9:"recipient";s:4:"user";%', '%s:9:"recipient";s:4:"both";%' ) );

		ob_start();

		if ( $saved )
			echo '<p class="updated-email-subscriptions">' . esc_html( $success ) . '</p>';

			$url             = add_query_arg( array( 'do' => 'mycred-unsubscribe', 'user' => get_current_user_id(), 'token' => wp_create_nonce( 'update-mycred-email-subscriptions' ) ) );

?>
<form action="<?php echo esc_url( $url ); ?>" id="mycred-email-subscriptions" method="post">
	<table class="table">
		<thead>
			<tr>
				<th class="check"><?php esc_html_e( 'Unsubscribe', 'mycred' ); ?></th>
				<th class="notice-title"><?php esc_html_e( 'Email Notice', 'mycred' ); ?></th>
			</tr>
		</thead>
		<tbody>

		<?php if ( ! empty( $email_notices ) ) : ?>

			<?php foreach ( $email_notices as $notice ) : $settings = mycred_get_email_settings( $notice->ID ); ?>

			<?php if ( $settings['recipient'] == 'admin' ) continue; ?>

			<tr>
				<td class="check"><input type="checkbox" name="mycred_email_unsubscribe[]"<?php if ( in_array( $notice->ID, $unsubscriptions ) ) echo ' checked="checked"'; ?> value="<?php echo esc_attr( $notice->ID ); ?>" /></td>
				<td class="notice-title"><?php echo esc_html( $settings['label'] ); ?></td>
			</tr>

			<?php endforeach; ?>
		
		<?php else : ?>

			<tr>
				<td colspan="2"><?php esc_html_e( 'There are no email notifications yet.', 'mycred' ); ?></td>
			</tr>

		<?php endif; ?>

		</tbody>
	</table>
	<input type="submit" class="btn btn-primary button button-primary pull-right" value="<?php esc_html_e( 'Save Changes', 'mycred' ); ?>" />
</form>
<?php

		$content = ob_get_contents();
		ob_end_clean();

		return apply_filters( 'mycred_render_email_subscriptions', $content, $atts );

	}

Code file location:

mycred/mycred/addons/email-notices/myCRED-addon-email-notices.php

Mycred [mycred_my_rank] Shortcode

The MyCred Rank shortcode is a dynamic tool that displays the rank of a user based on their point balance. It’s customizable, allowing the display of the rank title, logo, and more.

Shortcode: [mycred_my_rank]

Parameters

Here is a list of all possible mycred_my_rank shortcode parameters and attributes:

  • user_id – Specifies the user, ‘current’ for the logged-in user.
  • ctype – Indicates the type of point, defaults to MYCRED_DEFAULT_TYPE_KEY.
  • show_title – Set to 1 to display the rank title, 0 to hide it.
  • show_logo – Set to 1 to display the rank logo, 0 to hide it.
  • logo_size – Defines the size of the rank logo, defaults to ‘post-thumbnail’.
  • first – Determines what to show first, ‘logo’ for rank logo.

Examples and Usage

Basic example – Show the current user’s rank title using the default point type.

[mycred_my_rank]

Advanced examples

Display the rank title and logo for a specific user (user_id=10) using the default point type.

[mycred_my_rank user_id=10 show_logo=1]

Show the rank title and logo for the current user, but use a different point type (ctype=”gold”).

[mycred_my_rank ctype="gold" show_logo=1]

Display the rank logo before the title for the current user using the default point type.

[mycred_my_rank first="logo" show_logo=1]

Use a different size for the logo (logo_size=”medium”) for the current user’s rank using the default point type.

[mycred_my_rank logo_size="medium" show_logo=1]

Note: Replace “gold” and “medium” with your actual point type and logo size respectively. Also, replace the user_id=10 with the actual user ID you want to display the rank for.

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_my_rank] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_my_rank',            'mycred_render_my_rank' );

Shortcode PHP function:

function mycred_render_my_rank( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'user_id'    => 'current',
			'ctype'      => MYCRED_DEFAULT_TYPE_KEY,
			'show_title' => 1,
			'show_logo'  => 0,
			'logo_size'  => 'post-thumbnail',
			'first'      => 'logo'
		), $atts, MYCRED_SLUG . '_my_rank' ) );

		if ( $user_id == '' && ! is_user_logged_in() ) return;

		if ( ! mycred_point_type_exists( $ctype ) )
			$ctype = MYCRED_DEFAULT_TYPE_KEY;

		$show           = array();
		$user_id        = mycred_get_user_id( $user_id );
		if ( $user_id === false ) return;

		$account_object = mycred_get_account( $user_id );
		
		if( empty( $account_object->balance[ $ctype ]->rank ) ) return;
		
		$rank_object    = $account_object->balance[ $ctype ]->rank;

		if ( $rank_object !== false ) {

			if ( $show_logo == 1 && $rank_object->has_logo )
				$show[] = mycred_get_rank_logo( $rank_object->post_id, $logo_size );

			if ( $show_title == 1 )
				$show[] = $rank_object->title;
		
			if ( $first != 'logo' )
				$show = array_reverse( $show );

		}

		if ( ! empty( $show ) )
			$content = '<div class="mycred-my-rank">' . implode( ' ', $show ) . '</div>';

		return apply_filters( 'mycred_my_rank', $content, $user_id, $rank_object );

	}

Code file location:

mycred/mycred/addons/ranks/myCRED-addon-ranks.php

Mycred [MYCRED_my_ranks] Shortcode

The myCRED_my_ranks shortcode is used to display the ranks of a current user in WordPress. It extracts the user’s ID and shows their rank title and logo based on the settings defined.

Shortcode: [MYCRED_my_ranks]

Parameters

Here is a list of all possible MYCRED_my_ranks shortcode parameters and attributes:

  • user_id – Identifies the user for which ranks are displayed.
  • show_title – Decides whether the rank title is shown (1) or not (0).
  • show_logo – Determines whether the rank logo is displayed (1) or not (0).
  • logo_size – Defines the size of the displayed rank logo.
  • first – Specifies which element, logo or title, is displayed first.

Examples and Usage

Basic example – Display the rank of the current logged-in user, including the title of the rank.

[mycred_my_ranks user_id="current" show_title="1"]

Advanced examples

Display the rank of a specific user (with user_id 2), including the title and logo of the rank. The logo will be displayed first.

[mycred_my_ranks user_id="2" show_title="1" show_logo="1" first="logo"]

Display the rank of a specific user (with user_id 3), including the title and logo of the rank. The title will be displayed first.

[mycred_my_ranks user_id="3" show_title="1" show_logo="1" first="title"]

Display the rank of the current logged-in user, including the logo of the rank. The logo size will be set to ‘medium’.

[mycred_my_ranks user_id="current" show_logo="1" logo_size="medium"]

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG_my_ranks] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_my_ranks',           'mycred_render_my_ranks' );

Shortcode PHP function:

function mycred_render_my_ranks( $atts, $content = '' ) {
		
		$ranks = new stdClass();

		extract( shortcode_atts( array(
			'user_id'    => 'current',
			'show_title' => 1,
			'show_logo'  => 0,
			'logo_size'  => 'post-thumbnail',
			'first'      => 'logo'
		), $atts, MYCRED_SLUG . '_my_ranks' ) );

		if ( $user_id == '' && ! is_user_logged_in() ) return;

		$user_id        = mycred_get_user_id( $user_id );
		if ( $user_id == false ) return;

		$account_object = mycred_get_account( $user_id );
		$show           = array();

		// Get the rank for each type
		foreach ( $account_object->balance as $type_id => $balance ) {

			$row         = array();
			$rank_object = $balance->rank;

			if ( $rank_object !== false ) {

				if ( $show_logo == 1 && $rank_object->has_logo )
					$row[] = mycred_get_rank_logo( $rank_object->post_id, $logo_size );

				if ( $show_title == 1 )
					$row[] = $rank_object->title;
		
				if ( $first != 'logo' )
					$row = array_reverse( $row );

			}

			if ( ! empty( $row ) )
				$show[] = '<div class="mycred-my-rank ' . $type_id . '">' . implode( ' ', $row ) . '</div>';

		}

		if ( ! empty( $show ) )
			$content = '<div class="mycred-all-my-ranks">' . implode( ' ', $show ) . '</div>';

		if( ! empty($rank_object) )
			$ranks = $rank_object;

		return apply_filters( 'mycred_my_ranks', $content, $user_id, $ranks );

	}

Code file location:

mycred/mycred/addons/ranks/myCRED-addon-ranks.php

Mycred [myCRED_Users_of_Rank] Shortcode

The myCRED_Users_of_Rank shortcode is used to display a list of users with a specific rank. It requires the rank_id as an attribute. It also allows customization of the output format, the number of users to display, and the order of display. If no users are found with the specified rank, a custom message is displayed.

Shortcode: [myCRED_Users_of_Rank]

Parameters

Here is a list of all possible myCRED_Users_of_Rank shortcode parameters and attributes:

  • rank_id – Required. Identifies the rank to display users from.
  • login – Optional. Text displayed if user is not logged in.
  • number – Optional. Number of users to display. Default is 10.
  • wrap – Optional. HTML element to wrap output. Default is ‘div’.
  • col – Optional. If using table, defines column span. Default is 1.
  • nothing – Optional. Text displayed if no users found. Default is ‘No users found with this rank’
  • ctype – Optional. Type of points to display. Default is MYCRED_DEFAULT_TYPE_KEY.
  • order – Optional. Determines order of users displayed. Default is ‘DESC’.

Examples and Usage

Basic example – Displaying users of a specific rank by using the rank ID

[mycred_users_of_rank rank_id=5]

With this shortcode, you can display users who have achieved a specific rank. The rank is identified by its ID, which is ‘5’ in this case.

Advanced examples

Displaying users of a specific rank, limiting the number of users shown, and specifying the order

[mycred_users_of_rank rank_id=3 number=10 order="ASC"]

This shortcode displays the users who have achieved the rank with the ID ‘3’, but only the top 10 users are shown. The users are also displayed in ascending order.

Displaying users of a specific rank and specifying the content type

[mycred_users_of_rank rank_id=2 ctype="gold_points"]

With this shortcode, you can display users who have achieved a specific rank, and specify the content type. In this example, the rank is identified by its ID, which is ‘2’, and the content type is ‘gold_points’.

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_Users_of_Rank] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_users_of_rank',      'mycred_render_users_of_rank' );

Shortcode PHP function:

function mycred_render_users_of_rank( $atts, $row_template = NULL ) {

		extract( shortcode_atts( array(
			'rank_id' => NULL,
			'login'   => '',
			'number'  => 10,
			'wrap'    => 'div',
			'col'     => 1,
			'nothing' => 'No users found with this rank',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'order'   => 'DESC'
		), $atts, MYCRED_SLUG . '_users_of_rank' ) );

		// Rank ID required
		if ( $rank_id === NULL )
			return '<strong>ERROR</strong> Rank ID is required!';

		// User is not logged in
		if ( ! is_user_logged_in() && $login != '' )
			return $mycred->template_tags_general( $login );

		if ( ! mycred_point_type_exists( $ctype ) )
			$ctype = MYCRED_DEFAULT_TYPE_KEY;

		$mycred       = mycred( $ctype );

		$output       = '';

		if ( $row_template === NULL || empty( $row_template ) )
			$row_template = '<p class="user-row">%user_profile_link% with %balance% %_plural%</p>';

		// Let others play
		$row_template = apply_filters( 'mycred_users_of_rank', $row_template, $atts, $mycred );

		// Get users of this rank if there are any
		$users        = mycred_get_users_of_rank( $rank_id, $number, $order, $ctype );
		if ( ! empty( $users ) ) {

			// Add support for table
			if ( $wrap != 'table' && ! empty( $wrap ) )
				$output .= '<' . $wrap . ' class="mycred-users-of-rank-wrapper">';

			// Loop
			foreach ( $users as $user )
				$output .= $mycred->template_tags_user( $row_template, false, $user );

			// Add support for table
			if ( $wrap != 'table' && ! empty( $wrap ) )
				$output .= '</' . $wrap . '>' . "\n";

		}

		// No users found
		else {

			// Add support for table
			if ( $wrap == 'table' ) {
				$output .= '<tr><td';
				if ( $col > 1 ) $output .= ' colspan="' . $col . '"';
				$output .= '>' . $nothing . '</td></tr>';
			}

			else {
				if ( empty( $wrap ) ) $wrap = 'p';
				$output .= '<' . $wrap . '>' . $nothing . '</' . $wrap . '>' . "\n";
			}

		}

		return do_shortcode( $output );

	}

Code file location:

mycred/mycred/addons/ranks/myCRED-addon-ranks.php

Mycred [mycred_users_of_all_ranks] Shortcode

The myCRED shortcode enables users to display all registered users of every rank in a descending order. It extracts specific attributes such as the login status, number of users, and rank logo. If a user is not logged in, it returns a general template tag. It generates an output that includes the rank title and logo, if available. If no users are found with a certain rank, it displays a custom message.

Shortcode: [mycred_users_of_all_ranks]

Parameters

Here is a list of all possible mycred_users_of_all_ranks shortcode parameters and attributes:

  • login – message to display when a user is not logged in
  • number – number of users to display per rank
  • ctype – type of myCRED points to use
  • show_logo – whether to display the rank logo (1 for yes, 0 for no)
  • logo_size – size of the rank logo to display
  • wrap – HTML tag to wrap around the output
  • nothing – message to display when no users are found with a rank

Examples and Usage

Basic example – The shortcode displays users of all ranks in a descending order, with the default number of users set to 10.

[mycred_users_of_all_ranks]

Advanced examples

Displaying a specific number of users of all ranks. In this case, we are setting the number to 20.

[mycred_users_of_all_ranks number=20]

Displaying users of all ranks without the rank logo. The ‘show_logo’ parameter is set to 0 to hide the logo.

[mycred_users_of_all_ranks show_logo=0]

Changing the message displayed when no users are found with the rank. The ‘nothing’ parameter is used to customize the message.

[mycred_users_of_all_ranks nothing="No users found with the specified rank"]

Displaying users of a specific rank by specifying the ‘ctype’ parameter. In this case, we are displaying users of the rank with the key ‘gold’.

[mycred_users_of_all_ranks ctype=gold]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_users_of_all_ranks] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_users_of_all_ranks', 'mycred_render_users_of_all_ranks' );

Shortcode PHP function:

function mycred_render_users_of_all_ranks( $atts, $row_template = NULL ) {

		extract( shortcode_atts( array(
			'login'     => '',
			'number'    => 10,
			'ctype'     => MYCRED_DEFAULT_TYPE_KEY,
			'show_logo' => 1,
			'logo_size' => 'post-thumbnail',
			'wrap'      => 'div',
			'nothing'   => 'No users found with this rank'
		), $atts, MYCRED_SLUG . '_users_of_all_ranks' ) );

		// Prep
		$mycred    = mycred();

		// User is not logged in
		if ( ! is_user_logged_in() && $login != '' )
			return $mycred->template_tags_general( $login );

		$output    = '';
		$all_ranks = mycred_get_ranks( 'publish', '-1', 'DESC', $ctype );

		// If we have ranks
		if ( ! empty( $all_ranks ) ) {

			$output .= '<div class="mycred-all-ranks-wrapper">' . "\n";

			// Loop though all ranks
			foreach ( $all_ranks as $rank ) {

				// Prep Slug
				$slug    = str_replace( ' ', '-', strtolower( $rank->title ) );

				// Rank wrapper
				$output .= '<div class="mycred-rank rank-' . $slug . ' rank-' . $rank->post_id . '"><h2>';

				// Insert Logo
				if ( $show_logo )
					$output .= mycred_get_rank_logo( $rank->post_id, $logo_size );

				// Rank title
				$output .= $rank->title . '</h2>' . "\n";

				$attr    = array(
					'rank_id' => $rank->post_id,
					'number'  => $number,
					'nothing' => $nothing,
					'wrap'    => $wrap,
					'ctype'   => $ctype
				);
				$output .= mycred_render_users_of_rank( $attr, $row_template );

				$output .= '</div>' . "\n";

			}

			$output .= '</div>';

		}

		return $output;

	}

Code file location:

mycred/mycred/addons/ranks/myCRED-addon-ranks.php

Mycred [MYCRED_SLUG_list_ranks] Shortcode

The myCRED_list_ranks shortcode is designed to render a list of all published ranks in descending order. It displays each rank with its minimum and maximum points. . The shortcode is customizable, allowing you to alter the order and type of content. It also supports wrapping the output in a specified HTML element.

Shortcode: [MYCRED_list_ranks]

Parameters

Here is a list of all possible MYCRED_list_ranks shortcode parameters and attributes:

  • order – Defines the order of ranks, “DESC” for descending, “ASC” for ascending.
  • ctype – Specifies the type of points to display ranks for.
  • wrap – HTML tag to wrap the rank list, default is ‘div’.

Examples and Usage

Basic example – Display a list of ranks in descending order.

[mycred_list_ranks]

Advanced examples

Display a list of ranks in ascending order. The ‘order’ attribute is used to specify the rank order. In this case, ‘ASC’ is used to display ranks in ascending order.

[mycred_list_ranks order='ASC']

Display a list of ranks for a specific point type. The ‘ctype’ attribute is used to specify the point type. In this example, ‘gold_points’ is the point type.

[mycred_list_ranks ctype='gold_points']

Wrap the rank list within a div. The ‘wrap’ attribute is used to specify the HTML element that will wrap around the rank list. In this case, ‘div’ is used.

[mycred_list_ranks wrap='div']

Combine multiple attributes to customize the rank list. This example displays a list of ranks for ‘gold_points’ point type in ascending order and wraps the list within a div.

[mycred_list_ranks order='ASC' ctype='gold_points' wrap='div']

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG_list_ranks] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_list_ranks',         'mycred_render_rank_list' );

Shortcode PHP function:

function mycred_render_rank_list( $atts, $row_template = NULL ) {

		$atts      = shortcode_atts( array(
			'order' => 'DESC',
			'ctype' => MYCRED_DEFAULT_TYPE_KEY,
			'wrap'  => 'div'
		), $atts, MYCRED_SLUG . '_list_ranks' );

		extract( $atts );

		$output    = '';
		$all_ranks = mycred_get_ranks( 'publish', '-1', strtoupper( $order ), $ctype );

		if ( ! empty( $all_ranks ) ) {

			if ( $wrap != '' )
				$output .= '<' . $wrap . ' class="mycred-rank-list">';

			if ( $row_template === NULL || empty( $row_template ) )
				$row_template = '<p>%rank% <span class="min">%min%</span> - <span class="max">%max%</span></p>';

			foreach ( $all_ranks as $rank ) {

				$mycred  = mycred( $rank->point_type );
				$row     = apply_filters( 'mycred_rank_list', $row_template, $atts, $mycred );

				$row     = str_replace( '%rank%',             $rank->title, $row );
				$row     = str_replace( '%rank_logo%',        mycred_get_rank_logo( $rank->post_id ), $row );
				$row     = str_replace( '%min%',              $mycred->format_creds( $rank->minimum ), $row );
				$row     = str_replace( '%max%',              $mycred->format_creds( $rank->maximum ), $row );
				$row     = str_replace( '%count%',            $rank->count, $row );

				$row     = $mycred->template_tags_general( $row );

				$output .= $row;

			}

			if ( $wrap != '' )
				$output .= '</' . $wrap . '>';

		}

		return $output;

	}

Code file location:

mycred/mycred/addons/ranks/myCRED-addon-ranks.php

Mycred [myCRED_sell_this] Shortcode

The myCRED_sell_this shortcode is used to sell specific content on a WordPress site. It checks if a user is logged in and if they have paid for the content. If not, it provides payment options. If the user can’t afford, it displays a message.

Shortcode: [myCRED_sell_this]

Examples and Usage

Basic example – Displaying the sell content option for a specific post.

[mycred_sell_this post_id=1 /]

Advanced examples

Using the shortcode to display a sell content option for a specific post only for logged in users who are not the post author or an admin.

[mycred_sell_this post_id=1 user_id=2 is_admin=false is_owner=false /]

Using the shortcode to display a sell content option for a specific post with a custom message for visitors or users who cannot afford to buy the content.

[mycred_sell_this post_id=1 user_id=2 is_admin=false is_owner=false cantafford="Sorry, you do not have enough credits to purchase this content." /]

Using the shortcode to display a sell content option for a specific post with a custom message for visitors or users who cannot afford to buy the content and a custom buy button.

[mycred_sell_this post_id=1 user_id=2 is_admin=false is_owner=false cantafford="Sorry, you do not have enough credits to purchase this content." buy_button="Buy this content for 10 credits" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_sell_this] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_sell_this',             'mycred_render_sell_this' );

Shortcode PHP function:

function mycred_render_sell_this( $atts, $content = '' ) {

		global $mycred_partial_content_sale, $mycred_modules;

		$post_id  = mycred_sell_content_post_id();
		$post     = mycred_get_post( $post_id );
		$user_id  = get_current_user_id();
		$is_admin = mycred_is_admin( $user_id );
		$is_owner = ( (int) $post->post_author === $user_id ) ? true : false;

		$mycred_partial_content_sale = true;

		// Logged in users
		if ( is_user_logged_in() ) {

			// Authors and admins do not pay
			if ( ! $is_admin && ! $is_owner ) {

				// In case we have not paid
				if ( ! mycred_user_paid_for_content( $user_id, $post_id ) ) {

					// Get Payment Options
					$payment_options = mycred_sell_content_payment_buttons( $user_id, $post_id );

					// User can buy
					if ( $payment_options !== false ) {

						$content = $mycred_modules['solo']['content']->sell_content['templates']['members'];
						$content = str_replace( '%buy_button%', $payment_options, $content );
						$content = mycred_sell_content_template( $content, $post, 'mycred-sell-partial-content', 'mycred-sell-unpaid' );

					}

					// Can not afford to buy
					else {

						$content = $mycred_modules['solo']['content']->sell_content['templates']['cantafford'];
						$content = mycred_sell_content_template( $content, $post, 'mycred-sell-partial-content', 'mycred-sell-insufficient' );

					}

				}

			}

			/**
			 * Incase the shortcode is used incorrectly
			 * Since the shortcode is only used to indicate which part of the content that is for sale, we need to make sure it can only be used
			 * on content that has been set to be purchasable. In manual mode, this means we must have clicked to enable sale in the metabox.
			 * In auto modes, the particular post types setup must be enabled and the post must fit any filter criteria we might have set.
			 * Since the content might have monetary value, we do not want to just show it, but to warn admin/post author and appologize to the user.
			 * @since 1.7.8
			 */
			elseif ( ! mycred_post_is_for_sale( $post ) ) {

				if ( $is_admin || $is_owner )
					return '<p>' . sprintf( '%s %s', __( 'This shortcode can not be used in content that has not been set for sale!', 'mycred' ), '<a href="' . get_edit_post_link( $post_id ) ) . '">' . __( 'Edit', 'mycred' ) . '</a></p>';

				return '<p>' . __( 'This content is currently unattainable. Apologies for the inconvenience.', 'mycred' ) . '</p>';

			}

		}

		// Visitors
		else {

			$content = $mycred_modules['solo']['content']->sell_content['templates']['visitors'];
			$content = mycred_sell_content_template( $content, $post, 'mycred-sell-partial-content', 'mycred-sell-visitor' );

		}

		return do_shortcode( $content );

	}

Code file location:

mycred/mycred/addons/sell-content/myCRED-addon-sell-content.php

Mycred [mycred_sell_this_ajax] Shortcode

The MyCred Sell This Ajax shortcode is a unique feature that enables users to sell content on their website. It’s used to render the ‘sell this’ function in an Ajax call. However, this shortcode is deprecated and will be removed in version 1.8.

Shortcode: [mycred_sell_this_ajax]

Examples and Usage

Basic example – Utilizes the mycred_sell_this_ajax shortcode to render the sell this function.

[mycred_sell_this_ajax /]

Advanced examples

Embedding the shortcode within a post or page to sell a specific item. The item’s ID is passed as a parameter.

[mycred_sell_this_ajax id="123" /]

Applying the shortcode with multiple parameters. Here, the shortcode is used to sell an item (ID 123) with a specific price (100 points) and a custom button label (“Buy Now”).

[mycred_sell_this_ajax id="123" price="100" button_label="Buy Now" /]

Remember that the mycred_sell_this_ajax shortcode is deprecated and will be removed in version 1.8. It’s recommended to use the mycred_render_sell_this shortcode instead.

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_sell_this_ajax] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_sell_this_ajax',        'mycred_render_sell_this_ajax' );

Shortcode PHP function:

function mycred_render_sell_this_ajax( $atts, $content = '' ) {

		_doing_it_wrong( 'mycred_render_sell_this_ajax', 'The mycred_sell_this_ajax shortcode has been depreciated and will be removed in version 1.8.', '1.7' );

		return mycred_render_sell_this( $atts, $content );

	}

Code file location:

mycred/mycred/addons/sell-content/myCRED-addon-sell-content.php

Mycred [mycred_sales_history] Shortcode

The myCRED Sales History shortcode displays a logged-in user’s purchase history. It presents data such as purchase date, title, cost, and expiration status in a table format.

Shortcode: [mycred_sales_history]

Parameters

Here is a list of all possible mycred_sales_history shortcode parameters and attributes:

  • user_id – The WordPress user ID or ‘current’ for logged-in user.
  • number – Defines the number of purchases to display.
  • nothing – Message to display when no purchases are found.
  • ctype – The myCRED point type to consider, NULL for all types.
  • order – Order of the purchases, ‘DESC’ for descending, ‘ASC’ for ascending.

Examples and Usage

Basic example – Displaying the current user’s purchase history with default settings

[mycred_sales_history]

Advanced examples

Displaying the purchase history of a specific user (user_id=2) and limiting the number of purchases shown (number=10).

[mycred_sales_history user_id=2 number=10]

Displaying the purchase history with a custom message when no purchases are found (nothing=”No transactions yet”) and ordering the purchases in ascending order (order=’ASC’).

[mycred_sales_history nothing="No transactions yet" order='ASC']

Displaying the purchase history for a specific type of credit (ctype=’gold’) and changing the default message when no purchases are found (nothing=”No gold purchases found”).

[mycred_sales_history ctype='gold' nothing="No gold purchases found"]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_sales_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_sales_history',         'mycred_render_sell_history' );

Shortcode PHP function:

function mycred_render_sell_history( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'user_id' => 'current',
			'number'  => 25,
			'nothing' => 'No purchases found',
			'ctype'   => NULL,
			'order'   => 'DESC'
		), $atts, MYCRED_SLUG . '_sales_history' ) );

		// Not logged in
		if ( ! is_user_logged_in() && $user_id == 'current' )
			return $content;

		$user_id     = mycred_get_user_id( $user_id );
		$date_format = get_option( 'date_format' );
		$expiration  = apply_filters( 'mycred_sell_exp_title', __( 'Hour(s)', 'mycred' ) );
		$purchases   = mycred_get_users_purchased_content( $user_id, $number, $order, $ctype );

		$columns     = apply_filters( 'mycred_sales_history_columns', array(
			'col-date'    => __( 'Date', 'mycred' ),
			'col-title'   => __( 'Title', 'mycred' ),
			'col-amount'  => __( 'Cost', 'mycred' ),
			'col-expires' => __( 'Expires', 'mycred' )
		), $atts );

		if ( empty( $purchases ) && $nothing == '' ) return;

		ob_start();

?>
<div class="table-responsive mycred-sell-this-history">
	<table class="table">
		<thead>
			<tr>
<?php

		foreach ( $columns as $column_id => $column_label )
			echo '<th class="mycred-sell-' . esc_attr( $column_id ) . ' ' . esc_attr( $column_id ) . '">' . esc_html( $column_label ) . '</th>';

?>
		</thead>
		<tbody>
<?php

		if ( ! empty( $purchases ) ) {
			foreach ( $purchases as $entry ) {

				$mycred = mycred( $entry->ctype );
				
				$hours  = mycred_sell_content_get_expiration_length( $entry->ref_id, $entry->ctype );
			
				$expires_in = apply_filters( 'mycred_sell_content_expires_in', $hours );
  	
				echo '<tr>';

				foreach ( $columns as $column_id => $column_label ) {
  		

					if ( $column_id == 'col-date' )
						echo '<td class="' . esc_attr( $column_id ) . '">'. esc_html( date( $date_format, $entry->time ) ).'</td>';

					elseif ( $column_id == 'col-title' )
						echo '<td class="' . esc_attr( $column_id ) . '"><a href="' . esc_attr( mycred_get_permalink( $entry->ref_id ) ) . '">' . esc_html( mycred_get_the_title( $entry->ref_id ) ) . '</a></td>';

					elseif ( $column_id == 'col-amount' )
						echo '<td class="' . esc_attr( $column_id ) . '">' . esc_attr( $mycred->format_creds( abs( $entry->creds ) ) ) . '</td>';

					elseif ( $column_id == 'col-expires' ) {

						$expires = __( 'Never', 'mycred' );

						if ( $expires_in > 0 ) {
							$days = $hours * 60 * 60;
					 		$date = time()- $entry->time;
					 		$time_change = $days - $date;
							$expires_in  = mycred_seconds_to_time( $time_change );

							if( $expires < $time_change ){
							
								$expires = sprintf( _x( 'Purchase expires in %s', 'e.g. 10 hours', 'mycred' ), $expires_in. ' ' );
							
							}
							else{
							
								$expires = 'Expired';
							
							}

						}
					
						echo '<td class="' . esc_attr( $column_id ) . '">' . esc_html( $expires ) . '</td>';

					}
					else {

						do_action( 'mycred_sales_history_column', $column_id, $entry );
						do_action( 'mycred_sales_history_column_' . $column_id, $entry );

					}

				}

				echo '</tr>';

			}
		}
		else {

			echo '<tr><td class="no-results" colspan="' . count( $columns ) . '">' . esc_html( $nothing ) . '</td></tr>';

		}

?>
		</tbody>
	</table>
</div>
<?php

		$content = ob_get_contents();
		ob_end_clean();

		return $content;

	}

Code file location:

mycred/mycred/addons/sell-content/myCRED-addon-sell-content.php

Mycred [myCred_content_sale_count] Shortcode

The myCred_content_sale_count shortcode is a part of the myCred plugin. It displays the sales count of a specific post. This shortcode accepts two attributes: ‘wrapper’ and ‘post_id’. ‘Wrapper’ specifies the HTML tag to wrap the sales count, while ‘post_id’ identifies the post. If no post_id is provided, it defaults to the current post. Shortcode: [myCred_content_sale_count wrapper=”div” post_id=”123″]

Shortcode: [myCred_content_sale_count]

Parameters

Here is a list of all possible myCred_content_sale_count shortcode parameters and attributes:

  • wrapper – specifies HTML element to wrap sales count
  • post_id – identifies the post to get sales count from

Examples and Usage

Basic example – The following shortcode displays the sales count for a specific post, using the post’s ID as a parameter.

[mycred_content_sale_count post_id=5 /]

Advanced examples

If you want to display the sales count within a specific HTML element, you can use the ‘wrapper’ attribute. This attribute accepts any valid HTML tag name. The sales count will be wrapped within this HTML element. For instance, if you want to display the sales count within a ‘span’ element, you can use the following shortcode:

[mycred_content_sale_count wrapper="span" post_id=5 /]

If you want to display the sales count without specifying a post ID, the shortcode will automatically use the ID of the current post. This can be useful when used within a post loop. The following shortcode will display the sales count for the current post within a ‘div’ element:

[mycred_content_sale_count wrapper="div" /]

Please note that the ‘post_id’ and ‘wrapper’ attributes are optional. If you don’t provide a ‘post_id’, the shortcode will use the ID of the current post. If you don’t provide a ‘wrapper’, the sales count will be returned without any HTML wrapping.

PHP Function Code

In case you have difficulties debugging what causing issues with [myCred_content_sale_count] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_content_sale_count',    'mycred_render_sell_count' );

Shortcode PHP function:

function mycred_render_sell_count( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'wrapper' => '',
			'post_id' => NULL
		), $atts, MYCRED_SLUG . '_content_sale_count' ) );

		if ( $post_id === NULL )
			$post_id = mycred_sell_content_post_id();

		$content = '';

		if ( $wrapper != '' )
			$content .= '<' . $wrapper . ' class="mycred-sell-this-sales-count">';

		$content .= mycred_get_content_sales_count( $post_id );

		if ( $wrapper != '' )
			$content .= '</' . $wrapper . '>';

		return $content;

	}

Code file location:

mycred/mycred/addons/sell-content/myCRED-addon-sell-content.php

Mycred [mycred_content_buyer_count] Shortcode

The mycred_content_buyer_count shortcode displays the total number of buyers for a specific post. It takes two parameters: ‘wrapper’, which wraps the output in HTML tags, and ‘post_id’, the ID of the post.

Shortcode: [mycred_content_buyer_count]

Parameters

Here is a list of all possible mycred_content_buyer_count shortcode parameters and attributes:

  • wrapper – Defines the HTML tag wrapping the buyer count
  • post_id – Specifies the ID of the post for which to display the buyer count

Examples and Usage

Basic example – Displays the count of content buyers for the current post.

[mycred_content_buyer_count]

Advanced examples

Displays the count of content buyers for a specific post by referencing the post ID. The count will be wrapped in a div tag with a class of “mycred-sell-this-author-count”.

[mycred_content_buyer_count post_id=123 wrapper="div"]

Displays the count of content buyers for a specific post by referencing the post ID. The count will be wrapped in a span tag with a class of “mycred-sell-this-author-count”.

[mycred_content_buyer_count post_id=456 wrapper="span"]

Displays the count of content buyers for the current post. The count will be wrapped in an h2 tag with a class of “mycred-sell-this-author-count”.

[mycred_content_buyer_count wrapper="h2"]

Please note that you need to replace the post_id in the examples with the actual ID of the post you want to target. If you don’t specify a post_id, the shortcode will target the current post.

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_content_buyer_count] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_content_buyer_count',   'mycred_render_sell_buyer_count' );

Shortcode PHP function:

function mycred_render_sell_buyer_count( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'wrapper' => '',
			'post_id' => NULL
		), $atts, MYCRED_SLUG . '_content_buyer_count' ) );

		if ( $post_id === NULL )
			$post_id = mycred_sell_content_post_id();

		$content = '';

		if ( $wrapper != '' )
			$content .= '<' . $wrapper . ' class="mycred-sell-this-author-count">';

		$content .= mycred_get_content_buyers_count( $post_id );

		if ( $wrapper != '' )
			$content .= '</' . $wrapper . '>';

		return $content;

	}

Code file location:

mycred/mycred/addons/sell-content/myCRED-addon-sell-content.php

Mycred [myCRED_content_buyer_avatars] Shortcode

The myCRED_content_buyer_avatars shortcode is used to display the avatars of users who have purchased a specific post. This shortcode accepts parameters like post_id, number of avatars, avatar size, and type of identification. It then fetches the buyers of the post and displays their avatars in a div container.

Shortcode: [myCRED_content_buyer_avatars]

Parameters

Here is a list of all possible myCRED_content_buyer_avatars shortcode parameters and attributes:

  • post_id – The identifier of the post in question.
  • number – The maximum number of buyer avatars to display.
  • size – The size, in pixels, of the buyer avatars to be displayed.
  • ctype – The myCRED point type to consider for the purchase.
  • use_email – If set to 1, use the buyer’s email for their avatar, otherwise use their user ID.
  • default – The URL of a default avatar if the buyer doesn’t have one.
  • alt – The alternative text to display if the avatar can’t be loaded.

Examples and Usage

Basic example – Displays avatars of the content buyers using the default parameters.

[mycred_content_buyer_avatars]

Advanced examples

Display avatars of the first 5 buyers of a specific post, with an avatar size of 50px.

[mycred_content_buyer_avatars post_id="123" number="5" size="50"]

Display avatars of the buyers using their email as identification, instead of their user ID.

[mycred_content_buyer_avatars use_email="1"]

Show avatars of the content buyers with a default avatar image and alternative text if the avatar is not found.

[mycred_content_buyer_avatars default="https://example.com/default-avatar.jpg" alt="Default Avatar"]

Display avatars of the buyers of a specific post, using a custom point type.

[mycred_content_buyer_avatars post_id="123" ctype="gold"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_content_buyer_avatars] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_content_buyer_avatars', 'mycred_render_sell_buyer_avatars' );

Shortcode PHP function:

function mycred_render_sell_buyer_avatars( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'post_id'   => NULL,
			'number'    => 10,
			'size'      => 42,
			'ctype'     => NULL,
			'use_email' => 0,
			'default'   => '',
			'alt'       => ''
		), $atts, MYCRED_SLUG . '_content_buyer_avatars' ) );

		if ( $post_id === NULL )
			$post_id = mycred_sell_content_post_id();

		$buyers = mycred_get_posts_buyers( $post_id, $number, $ctype );

		$content = '';
		if ( ! empty( $buyers ) ) {
			foreach ( $buyers as $buyer_id ) {

				$identification = $buyer_id;
				if ( absint( $use_email ) === 1 ) {
					$buyer_object   = get_userdata( $buyer_id );
					if ( ! isset( $buyer_object->ID ) ) continue;
					$identification = $buyer_object->user_email;
				}

				$avatar = get_avatar( $identification, $size, $default, $alt );
				$avatar = apply_filters( 'mycred_sell_content_buyer_avatar', $avatar, $buyer_id, $post_id );
				if ( $avatar !== false )
					$content .= $avatar;

			}
		}

		return '<div class="mycred-sell-this-buyers">' . $content . '</div>';

	}

Code file location:

mycred/mycred/addons/sell-content/myCRED-addon-sell-content.php

Mycred [myCRED_chart_circulation] Shortcode

The myCRED_chart_circulation shortcode generates various chart types to display data. It allows customization of chart type, title, animation, bezier curve, labels, legend, height, and width. .

Shortcode: [myCRED_chart_circulation]

Parameters

Here is a list of all possible myCRED_chart_circulation shortcode parameters and attributes:

  • type – Specifies the type of chart to display (pie, doughnut, line, bar, radar, polarArea).
  • title – Sets the title of the chart.
  • animate – Controls whether the chart animates when loading (1 for yes, 0 for no).
  • bezier – Determines if the chart should use bezier curves (1 for yes, 0 for no).
  • labels – Decides if the chart should display x-axis labels (1 for yes, 0 for no).
  • legend – Determines if the chart should display a legend (1 for yes, 0 for no).
  • height – Specifies the height of the chart.
  • width – Defines the width of the chart.

Examples and Usage

Basic example – Display a simple pie chart with the default settings using the myCRED circulation chart shortcode.

[mycred_chart_circulation]

Advanced examples

Display a bar chart with a custom title, enabling animation and bezier curves, and disabling labels and legend. Also, specify the height and width of the chart.

[mycred_chart_circulation type="bar" title="My Custom Title" animate="1" bezier="1" labels="0" legend="0" height="400" width="600"]

Display a doughnut chart with a custom title and disabling animation, bezier curves, labels, and legend. Also, specify the height and width of the chart.

[mycred_chart_circulation type="doughnut" title="My Doughnut Chart" animate="0" bezier="0" labels="0" legend="0" height="500" width="500"]

Display a line chart with a custom title, enabling animation and bezier curves, and enabling labels and legend. Also, specify the height and width of the chart.

[mycred_chart_circulation type="line" title="My Line Chart" animate="1" bezier="1" labels="1" legend="1" height="300" width="400"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_chart_circulation] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_circulation',      'mycred_render_chart_circulation' );

Shortcode PHP function:

function mycred_render_chart_circulation( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'pie',
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_circulation' ) );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'pie', 'doughnut', 'line', 'bar', 'radar', 'polarArea' ) ) ) ? 'pie' : $type;

		// Get data
		$data  = mycred_get_circulation_data();
		if ( empty( $data ) ) return $no_data;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [myCRED_chart_gain_loss] Shortcode

The myCRED_chart_gain_loss shortcode is used to render a chart that displays gains versus losses. It allows customization of chart type, labels, dimensions, and animation.

Shortcode: [myCRED_chart_gain_loss]

Parameters

Here is a list of all possible myCRED_chart_gain_loss shortcode parameters and attributes:

  • type – defines the type of the chart (pie, doughnut, line, bar, polarArea).
  • ctype – determines the type of credit used in the chart.
  • title – sets the title of the chart.
  • animate – allows the chart to have animation (1 for yes, 0 for no).
  • bezier – enables smooth curves in line charts (1 for yes, 0 for no).
  • labels – displays labels on the x-axis (1 for yes, 0 for no).
  • legend – shows the legend for the chart (1 for yes, 0 for no).
  • height – sets the height of the chart.
  • width – establishes the width of the chart.
  • gains – customizes the label for gains data.
  • losses – customizes the label for losses data.

Examples and Usage

Basic example – Show a pie chart of gains vs losses with default parameters

[mycred_chart_gain_loss]

Advanced examples

Display a doughnut chart of gains vs losses with a custom title and animation turned off

[mycred_chart_gain_loss type="doughnut" title="My Custom Title" animate="0"]

Display a line chart with custom labels for gains and losses, and a custom size

[mycred_chart_gain_loss type="line" gains="My Gains" losses="My Losses" height="400" width="600"]

Display a polar area chart with legend turned off

[mycred_chart_gain_loss type="polarArea" legend="0"]

Display a bar chart with bezier smoothing turned off

[mycred_chart_gain_loss type="bar" bezier="0"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_chart_gain_loss] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_gain_loss',        'mycred_render_chart_gain_vs_loss' );

Shortcode PHP function:

function mycred_render_chart_gain_vs_loss( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'pie',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => '',
			'gains'   => '',
			'losses'  => ''
		), $atts, MYCRED_SLUG . '_chart_gain_loss' ) );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'pie', 'doughnut', 'line', 'bar', 'polarArea' ) ) ) ? 'pie' : $type;

		// Get data
		$data  = mycred_get_gains_vs_losses_data( $ctype );
		if ( empty( $data ) ) return $no_data;

		// If we want to customize labels
		if ( ! empty( $gains ) )
			$data[0]->label = $gains;

		if ( ! empty( $losses ) )
			$data[1]->label = $losses;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [myCRED_chart_history] Shortcode

The myCRED_chart_history shortcode is a tool that generates customizable chart visualizations of user credit history on a WordPress site. The shortcode accepts various parameters like ‘type’, ‘ctype’, ‘period’, ‘number’, ‘order’, ‘title’, ‘animate’, ‘bezier’, ‘labels’, ‘legend’, ‘height’, ‘width’ to adjust the chart’s appearance and data representation. It supports two types of charts – ‘line’ and ‘bar’. The ‘ctype’ parameter specifies the type of points to consider. The ‘period’ and ‘number’ parameters define the time span and volume of data to be represented. The ‘order’ parameter sets the sorting order of the data points. The ‘title’, ‘height’, and ‘width’ parameters adjust the chart’s dimensions and title. The ‘animate’, ‘bezier’, ‘labels’, and ‘legend’ parameters control various visual aspects of the chart. Upon execution, the shortcode fetches the requisite data, creates a new chart object, and finally generates the chart canvas. If no data is found, it returns the ‘no_data’ parameter.

Shortcode: [myCRED_chart_history]

Parameters

Here is a list of all possible myCRED_chart_history shortcode parameters and attributes:

  • type – defines the type of chart, either ‘line’ or ‘bar’
  • ctype – sets the credit type to be displayed
  • period – sets the time period for the chart
  • number – specifies the number of data points in the chart
  • order – determines the order of data points, either ‘ASC’ or ‘DESC’
  • title – sets the title of the chart
  • animate – enables or disables animation for the chart
  • bezier – enables or disables bezier curves in line charts
  • labels – toggles the display of x-axis labels
  • legend – toggles the display of the chart legend
  • height – sets the height of the chart
  • width – sets the width of the chart

Examples and Usage

Basic example – Displaying a line chart of myCRED history for the default point type over the last 10 days.

[mycred_chart_history type="line" number=10 /]

Advanced examples

Displaying a bar chart of myCRED history for a custom point type (‘my_points’) over the last 30 days, ordered in ascending order, with a custom title, animation enabled, bezier curves disabled, labels enabled, legend enabled, and specific height and width.

[mycred_chart_history type="bar" ctype="my_points" period="days" number=30 order="ASC" title="My Points History" animate=1 bezier=0 labels=1 legend=1 height="400px" width="600px" /]

Showing a line chart of myCRED history for the default point type over the last 5 weeks, ordered in descending order, with a custom title, animation disabled, bezier curves enabled, labels disabled, legend disabled, and specific height and width.

[mycred_chart_history type="line" period="weeks" number=5 order="DESC" title="Weekly Points History" animate=0 bezier=1 labels=0 legend=0 height="500px" width="800px" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_chart_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_history',          'mycred_render_chart_history' );

Shortcode PHP function:

function mycred_render_chart_history( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'line',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'period'  => 'days',
			'number'  => 10,
			'order'   => 'DESC',
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_history' ) );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'line', 'bar' ) ) ) ? 'line' : $type;

		// Get data
		$data  = mycred_get_history_data( $ctype, $period, $number, $order );
		if ( empty( $data ) ) return $no_data;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [myCRED_chart_balance_history] Shortcode

The myCRED_chart_balance_history shortcode is designed to display a user’s balance history in a chart format. It can be customized to show data in line or bar style, for a specific user or the current one, over a certain period.

Shortcode: [myCRED_chart_balance_history]

Parameters

Here is a list of all possible myCRED_chart_balance_history shortcode parameters and attributes:

  • type – Defines the chart type, either ‘line’ or ‘bar’.
  • ctype – Specifies the currency type for myCRED.
  • user – Identifies the user, ‘current’ for logged-in user.
  • period – Sets the time period for data, usually in ‘days’.
  • number – Number of data points to display on the chart.
  • order – Sets the order of data, either ‘DESC’ or ‘ASC’.
  • title – Optional title for the chart.
  • animate – Enables or disables animation, 1 for yes, 0 for no.
  • bezier – Enables or disables curve smoothing, 1 for yes, 0 for no.
  • labels – Shows or hides x-axis labels, 1 for yes, 0 for no.
  • legend – Shows or hides legend, 1 for yes, 0 for no.
  • height – Sets the height of the chart.
  • ref – Reference for specific data points.
  • width – Sets the width of the chart.

Examples and Usage

Basic example – Render a line chart for the current logged-in user’s balance history over the last 10 days.

[mycred_chart_balance_history]

Advanced examples

Render a line chart for a specific user’s balance history (user ID 5) over the last 20 days.

[mycred_chart_balance_history user="5" number="20"]

Render a bar chart for the current logged-in user’s balance history over the last 10 days, with custom title, and disabling animation and legend.

[mycred_chart_balance_history type="bar" title="My Balance History" animate="0" legend="0"]

Render a line chart for a specific user’s balance history (user ID 5), for a specific point type (point type key ‘gold’), over the last 30 days, ordered in ascending order.

[mycred_chart_balance_history user="5" ctype="gold" number="30" order="ASC"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_chart_balance_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_balance_history',  'mycred_render_chart_balance_history' );

Shortcode PHP function:

function mycred_render_chart_balance_history( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'line',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'user'    => 'current',
			'period'  => 'days',
			'number'  => 10,
			'order'   => 'DESC',
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'ref'	  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_balance_history' ) );

		if ( $user == 'current' && ! is_user_logged_in() ) return $no_data;

		$user_id = mycred_get_user_id( $user );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'line', 'bar' ) ) ) ? 'line' : $type;

		// Get data
		$data  = mycred_get_users_history_data( $user_id, $ctype, $period, $number, $order, $ref );
		if ( empty( $data ) ) return $no_data;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [MYCRED_SLUG_chart_instance_history] Shortcode

The myCRED_chart_instance_history shortcode generates a customizable chart showcasing user point history. This shortcode allows you to specify chart type, point type, reference, period, number of instances, order, title, animation, bezier curve, labels, legend, height, and width. . This shortcode aids in visualizing user engagement and activity trends.

Shortcode: [MYCRED_SLUG_chart_instance_history]

Parameters

Here is a list of all possible MYCRED_SLUG_chart_instance_history shortcode parameters and attributes:

  • type – Defines the type of chart to display: line, bar, or radar.
  • ctype – Specifies the credential type to track in the chart.
  • ref – The reference point for the chart data.
  • period – Sets the time frame for the chart: days, weeks, months, etc.
  • number – Determines the number of data points to display on the chart.
  • order – Sets the data order in the chart: ascending or descending.
  • title – The text to display as the chart title.
  • animate – Enables or disables animation for the chart.
  • bezier – Decides whether to use Bezier curves in line charts.
  • labels – Toggles the display of labels on the x-axis.
  • legend – Controls the display of the chart legend.
  • height – Sets the height of the chart canvas.
  • width – Determines the width of the chart canvas.

Examples and Usage

Basic example – The following shortcode displays a line chart of a user’s credit history over the last 10 days. The chart will display in descending order.

[mycred_chart_instance_history type="line" ctype="myCRED_DEFAULT_TYPE_KEY" period="days" number="10" order="DESC" /]

Advanced examples

Displaying a bar chart of a specific reference point in a user’s credit history over the last 30 days. The chart is animated and has a title of “My Credit History”.

[mycred_chart_instance_history type="bar" ctype="myCRED_DEFAULT_TYPE_KEY" ref="specific_ref_point" period="days" number="30" order="DESC" title="My Credit History" animate="1" /]

Creating a radar chart of a user’s credit history over the last 7 days, displaying the chart in ascending order. The chart will not be animated, will not have Bezier curves, and will not display labels or a legend.

[mycred_chart_instance_history type="radar" ctype="myCRED_DEFAULT_TYPE_KEY" period="days" number="7" order="ASC" animate="0" bezier="0" labels="0" legend="0" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG_chart_instance_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_instance_history', 'mycred_render_chart_instance_history' );

Shortcode PHP function:

function mycred_render_chart_instance_history( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'line',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'ref'     => '',
			'period'  => 'days',
			'number'  => 10,
			'order'   => 'DESC',
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_instance_history' ) );

		if ( empty( $ref ) ) return $no_data;

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'line', 'bar', 'radar' ) ) ) ? 'line' : $type;

		// Get data
		$data  = mycred_get_ref_history_data( $ref, $ctype, $period, $number, $order );
		if ( empty( $data ) ) return $no_data;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [myCRED_chart_top_balances] Shortcode

The myCRED_chart_top_balances shortcode is designed to display a chart of users with the highest balances. It provides a visual representation of top balances in various chart types. This shortcode supports different chart types, including bar, pie, doughnut, line, radar, and polarArea. It also allows customization of chart parameters such as animation, bezier curves, labels, legend, height, and width.

Shortcode: [myCRED_chart_top_balances]

Parameters

Here is a list of all possible myCRED_chart_top_balances shortcode parameters and attributes:

  • type – Defines the type of chart to be displayed.
  • ctype – Specifies the type of myCRED points to be shown.
  • number – Sets the number of top balances to be shown.
  • order – Determines the order of the balances, either ascending or descending.
  • title – Sets the title of the chart.
  • animate – Decides whether the chart should be animated or not.
  • bezier – Configures the line tension for the line charts.
  • labels – Sets whether labels should be shown on the x-axis.
  • legend – Determines whether a legend should be shown or not.
  • height – Sets the height of the chart.
  • width – Sets the width of the chart.

Examples and Usage

Basic example – Display a bar chart with top 10 balances in descending order

[mycred_chart_top_balances type="bar" number="10" order="DESC" /]

Advanced examples

Display a doughnut chart with top 5 balances in ascending order, with animation and labels

[mycred_chart_top_balances type="doughnut" ctype="mycred_default" number="5" order="ASC" animate="1" labels="1" /]

Display a line chart with top 20 balances in descending order, with a custom height and width

[mycred_chart_top_balances type="line" ctype="mycred_default" number="20" order="DESC" height="400" width="600" /]

Display a polarArea chart with top 15 balances in descending order, without legend and labels

[mycred_chart_top_balances type="polarArea" ctype="mycred_default" number="15" order="DESC" legend="0" labels="0" /]

Note: In these examples, ‘type’ is the type of chart, ‘ctype’ is the type of points, ‘number’ is the number of top balances to display, ‘order’ is the order of balances (ASC for ascending, DESC for descending), ‘animate’ is whether to animate the chart (1 for yes, 0 for no), ‘labels’ is whether to display labels (1 for yes, 0 for no), ‘legend’ is whether to display the legend (1 for yes, 0 for no), ‘height’ and ‘width’ are the dimensions of the chart.

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_chart_top_balances] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_top_balances',     'mycred_render_chart_top_balances' );

Shortcode PHP function:

function mycred_render_chart_top_balances( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'bar',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'number'  => 10,
			'order'   => 'DESC',
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_top_balances' ) );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'pie', 'doughnut', 'line', 'bar', 'radar', 'polarArea' ) ) ) ? 'bar' : $type;

		// Get data
		$data  = mycred_get_top_balances_data( $ctype, $number, $order );
		if ( empty( $data ) ) return $no_data;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [myCRED_chart_top_instances] Shortcode

The myCRED_chart_top_instances shortcode generates a chart displaying top instances of a specified type. It extracts attributes like chart type, order, title, and size, then creates a chart object with these specifications.

Shortcode: [myCRED_chart_top_instances]

Parameters

Here is a list of all possible myCRED_chart_top_instances shortcode parameters and attributes:

  • type – defines the type of chart to display (bar, pie, etc.)
  • ctype – specifies the type of myCRED points to use
  • number – sets the number of top instances to display
  • order – controls the order of instances (DESC for descending, ASC for ascending)
  • title – adds a title to the chart
  • animate – determines if the chart should have animation (1 for yes, 0 for no)
  • bezier – enables or disables bezier curves in line type charts (1 for yes, 0 for no)
  • labels – decides if the chart should have labels (1 for yes, 0 for no)
  • legend – dictates if a legend should be included (1 for yes, 0 for no)
  • height – sets the height of the chart
  • width – defines the width of the chart

Examples and Usage

Basic example – A simple usage of the shortcode to display a bar chart with the top 10 instances of the default myCRED points type.

[mycred_chart_top_instances]

Advanced examples

Using the shortcode to display a pie chart with the top 5 instances of a custom points type. The chart will be animated, without bezier curves, and without labels or legend.

[mycred_chart_top_instances type="pie" ctype="custom" number="5" animate="1" bezier="0" labels="0" legend="0"]

Using the shortcode to display a doughnut chart with the top 20 instances of the default points type. The chart will be static, with bezier curves, labels, and legend. The chart will have a specified height and width.

[mycred_chart_top_instances type="doughnut" number="20" animate="0" bezier="1" labels="1" legend="1" height="400px" width="600px"]

Using the shortcode to display a line chart with the top 10 instances of the default points type, ordered in ascending order. The chart will be animated, with bezier curves, labels, and a custom title.

[mycred_chart_top_instances type="line" order="ASC" animate="1" bezier="1" labels="1" title="My Custom Title"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_chart_top_instances] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_top_instances',    'mycred_render_chart_top_instances' );

Shortcode PHP function:

function mycred_render_chart_top_instances( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'bar',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'number'  => 10,
			'order'   => 'DESC',
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_top_instances' ) );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'pie', 'doughnut', 'line', 'bar', 'radar', 'polarArea' ) ) ) ? 'pie' : $type;

		// Get data
		$data  = mycred_get_top_instances_data( $ctype, $number, $order );
		if ( empty( $data ) ) return $no_data;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [MYCRED_chart_acquisition] Shortcode

The myCRED_chart_acquisition shortcode is a versatile tool, allowing users to render various types of charts. It extracts a range of attributes, including type, period, and number, which can be customized to suit specific needs. The shortcode supports multiple chart types, including pie, doughnut, line, bar, and polarArea. It fetches data based on the specified time frame and type of points. If no data is available, it returns a ‘no data’ message. This shortcode also allows label customization and chart animation, providing a dynamic and interactive user experience.

Shortcode: [MYCRED_chart_acquisition]

Parameters

Here is a list of all possible MYCRED_chart_acquisition shortcode parameters and attributes:

  • type – defines the type of chart to display, possible values are ‘pie’, ‘doughnut’, ‘line’, ‘bar’, ‘polarArea’
  • ctype – represents the type of myCRED points to display in the chart
  • period – determines the time period for the data, default is ‘days’
  • number – sets the number of data points to display in the chart
  • title – allows you to set a title for the chart
  • animate – controls whether the chart is animated or not, 1 for yes and 0 for no
  • bezier – determines if the line chart should be curved (1) or straight (0)
  • labels – controls whether to display labels on the x-axis, 1 for yes and 0 for no
  • legend – controls whether to display a legend for the chart, 1 for yes and 0 for no
  • height – allows you to set a specific height for the chart
  • width – allows you to set a specific width for the chart

Examples and Usage

Basic example – Display a pie chart with the default settings

[mycred_chart_acquisition]

Advanced examples

Display a line chart of the last 7 days, with custom height and width

[mycred_chart_acquisition type='line' period='days' number=7 height='400' width='600']

Display a doughnut chart of the last 5 weeks, with custom animation and bezier settings

[mycred_chart_acquisition type='doughnut' period='weeks' number=5 animate=0 bezier=0]

Display a bar chart of the last 10 months, with custom labels and legend settings

[mycred_chart_acquisition type='bar' period='months' number=10 labels=0 legend=0]

Display a polarArea chart of the last 12 years, with custom title

[mycred_chart_acquisition type='polarArea' period='years' number=12 title='My Custom Title']

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG . '_chart_acquisition'] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_chart_acquisition',    	'mycred_render_chart_acquisition' );

Shortcode PHP function:

function mycred_render_chart_acquisition( $atts, $no_data = '' ) {

		extract( shortcode_atts( array(
			'type'    => 'pie',
			'ctype'   => MYCRED_DEFAULT_TYPE_KEY,
			'period'  => 'days',
			'number'  => 10,
			'title'   => '',
			'animate' => 1,
			'bezier'  => 1,
			'labels'  => 1,
			'legend'  => 1,
			'height'  => '',
			'width'   => ''
		), $atts, MYCRED_SLUG . '_chart_acquisition' ) );

		// Make sure we request a chart type that we support
		$type  = ( ! in_array( $type, array( 'pie', 'doughnut', 'line', 'bar', 'polarArea' ) ) ) ? 'pie' : $type;

		// Get data
		$data  = mycred_get_time_frame_data( $ctype, $period, $number );
		if ( empty( $data ) ) return $no_data;

		// If we want to customize labels
		if ( ! empty( $gains ) )
			$data[0]->label = $gains;

		if ( ! empty( $losses ) )
			$data[1]->label = $losses;

		// New Chart Object
		$chart = mycred_create_chart( array(
			'type'     => $type,
			'title'    => $title,
			'animate'  => (bool) $animate,
			'bezier'   => (bool) $bezier,
			'x_labels' => (bool) $labels,
			'legend'   => (bool) $legend,
			'height'   => $height,
			'width'    => $width
		) );

		return $chart->generate_canvas( $type, $data );

	}

Code file location:

mycred/mycred/addons/stats/myCRED-addon-stats.php

Mycred [mycred_transfer] Shortcode

The MyCred Transfer shortcode enables users to transfer points between accounts. It checks user login status, validates transfer conditions, and renders the transfer form or error messages.

Shortcode: [mycred_transfer]

Parameters

Here is a list of all possible mycred_transfer shortcode parameters and attributes:

  • button – defines the text on the transfer button
  • button_class – sets the CSS class for the transfer button
  • pay_to – specifies the recipient of the transfer
  • show_balance – decides if current balance should be displayed, 1 for yes, 0 for no
  • show_limit – determines if transfer limit should be shown, 1 for yes, 0 for no
  • ref – sets the reference for the transfer
  • amount – defines the amount to be transferred
  • amount_placeholder – placeholder text for the amount input field
  • min – sets the minimum amount that can be transferred
  • placeholder – placeholder text for the input fields
  • message_placeholder – placeholder text for the message input field
  • recipient_placeholder – placeholder text for the recipient input field
  • types – defines the types of points that can be transferred
  • excluded – specifies users who are excluded from transfers
  • recipient_label – label for the recipient input field
  • amount_label – label for the amount input field
  • balance_label – label for the balance display
  • message_label – label for the message input field

Examples and Usage

Basic example – A simple shortcode that displays the transfer form with default settings.

[mycred_transfer]

Advanced examples

1. Displaying the transfer form with a custom button class, and a specific recipient. This shortcode will render a form with a custom styled button and prefill the recipient field with the specified user.

[mycred_transfer button_class="btn btn-success btn-block btn-lg" pay_to="john_doe"]

2. Displaying the transfer form with balance and limit visibility, custom placeholders, and labels. This shortcode will render a form that shows the user’s balance and transfer limit, and use custom placeholders and labels for the recipient, amount, and message fields.

[mycred_transfer show_balance="1" show_limit="1" recipient_placeholder="Enter username" amount_placeholder="Enter amount" message_placeholder="Enter message" recipient_label="Send to" amount_label="Transfer amount" message_label="Transfer message"]

3. Displaying the transfer form with a minimum transfer amount and a specific point type. This shortcode will render a form that requires a minimum transfer amount and uses a specific type of points for the transfer.

[mycred_transfer min="10" types="gold_points"]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_transfer] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_transfer',  'mycred_transfer_render' );

Shortcode PHP function:

function mycred_transfer_render( $atts, $content = NULL ) {

		global $mycred_do_transfer;

		// Get Attributes
		$atts    = shortcode_atts( array(
			'button'          => '',
			'button_class'    => 'btn btn-primary btn-block btn-lg',
			'pay_to'          => '',
			'show_balance'    => 0,
			'show_limit'      => 0,
			'ref'             => 'transfer',
			'amount'          => '',
			'amount_placeholder' => '',
			'min'             => 0,
			'placeholder'     => '',
			'message_placeholder'   => '',
			'recipient_placeholder' => '',
			'types'           => '',
			'excluded'        => '',
			'recipient_label' => __( 'Recipient', 'mycred' ),
			'amount_label'    => __( 'Amount', 'mycred' ),
			'balance_label'   => __( 'Balance', 'mycred' ),
			'message_label'   => __( 'Message', 'mycred' )
		), $atts, MYCRED_SLUG . '_transfer' );

		// Prep
		$mycred_do_transfer = false;
		$transfer           = mycred_transfer();
		$output             = '';

		// Visitors can't do much
		if ( ! is_user_logged_in() ) {

			$output = do_shortcode( $transfer->settings['templates']['login'] );

		}

		// We are logged in
		else {

			// Create a new request. This will check if we meet the minimum requirements
			// and make sure we can initiate a transfer based on our setup
			// This function will also populate the transfer object to help us render the form
			if ( $transfer->new_instance( array(
				'reference'   => $atts['ref'],
				'minimum'     => $atts['min'],
				'amount'      => $atts['amount'],
				'recipient'   => $atts['pay_to'],
				'point_types' => $atts['types'],
				
			) ) ) {

				// We meet the minimum requirements! Yay, now let the get_transfer_form() function render our form
				$output = do_shortcode( $transfer->get_transfer_form( $atts ) );

			}

			// We can not make a new transfer
			else {

				// We either have no funds, exceeded limits (if used) or are excluded
				$output = do_shortcode( $transfer->get_error_message(true) );

			}

		}

		return do_shortcode( apply_filters( 'mycred_transfer_render', $output, $atts, $transfer ) );

	}

Code file location:

mycred/mycred/addons/transfer/myCRED-addon-transfer.php

Mycred [myCRED_badge_evidence] Shortcode

The myCRED_badge_evidence shortcode displays user badge evidence. It checks if user and badge IDs are present, fetches user data, and verifies the badge type. If valid, it creates a detailed badge evidence page.

Shortcode: [myCRED_badge_evidence]

Examples and Usage

Basic example – Showcases the basic usage of the myCRED badge evidence shortcode. The shortcode is used without any additional parameters and will display the badge evidence for the specified user and badge IDs.

[mycred_badge_evidence uid="1" bid="2" /]

Advanced examples

Displays the badge evidence for a user with ID of 3 and a badge with ID of 4. It also uses the ‘mycred_badge_plus’ post type, which is a more advanced version of the basic ‘mycred_badge’ post type.

[mycred_badge_evidence uid="3" bid="4" post_type="mycred_badge_plus" /]

Displays the badge evidence for a user with ID of 5 and a badge with ID of 6. It also uses the ‘mycred_badge’ post type and includes the ‘issued_on’ parameter, which displays the date and time the badge was issued.

[mycred_badge_evidence uid="5" bid="6" post_type="mycred_badge" issued_on="true" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_badge_evidence] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_badge_evidence', 'mycred_render_badge_evidence' );

Shortcode PHP function:

function mycred_render_badge_evidence( $atts = '' ) {

        $content = '<div class="mycred-evidence-page">Evidence not found</div>'; 

        if ( isset( $_GET['uid'] ) && isset( $_GET['bid'] ) ) {

            $user_id  = intval( $_GET['uid'] );
            $badge_id = intval( $_GET['bid'] );

            $user_info = get_userdata( $user_id );
            $post  = get_post( $badge_id );
            
            $issued_on = '';
            if( $post->post_type == 'mycred_badge' ){
                $badge = mycred_get_badge( $badge_id );
                $issued_on = mycred_get_user_meta( $user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true );

            }

            if ( $post->post_type == 'mycred_badge_plus' ) {
                $badge = mycred_badge_plus_object( $badge_id );
                $issued_on = end( mycred_get_user_meta( $user_id, 'mycred_badge_plus_ids', '', true )[$badge_id] );
            }

            if ( $user_info && $badge->open_badge ) {

                $content = '<div class="mycred-evidence-page">
                                <div class="mycred-left">
                                    <img src="' . $badge->get_earned_image( $user_id ) . '" alt="">
                                </div>
                                <div class="mycred-left intro">
                                    <h4 class="mycred-remove-margin">' . $badge->title . '</h4>
                                    <div class="mycred-remove-margin">
                                        <p>Name: '. $user_info->display_name .'</p>
                                        <p>Email: ' . $user_info->user_email . '</p>
                                        <p>Issued On: ' . date( 'Y-m-d\TH:i:sP', $issued_on ) . '</p>
                                        <p><span class="dashicons dashicons-yes-alt"></span> <span class="icon-txt"> Verified</span></p>
                                    </div>
                                </div>
                                <div class="mycred-clear"></div>
                            </div>';

            }
            
            
        }

        return $content;
    }

Code file location:

mycred/mycred/includes/shortcodes/mycred-badge-evidence-page.php

Mycred [mycred_affiliate_id] Shortcode

The mycred_affiliate_id shortcode is a unique identifier that links to the affiliate’s account. It’s used to track referrals and calculate commissions. This shortcode extracts the ‘type’ attribute, applies filters, and returns the affiliate ID. It’s a crucial tool in managing affiliate marketing efforts on your WordPress site.

Shortcode: [mycred_affiliate_id]

Parameters

Here is a list of all possible mycred_affiliate_id shortcode parameters and attributes:

  • type – Specifies the type of affiliate ID to be rendered

Examples and Usage

Basic example – The following shortcode demonstrates a simple usage of the mycred plugin’s affiliate ID shortcode. It uses the default type key, hence no attributes are required.

[mycred_affiliate_id]

Advanced examples

In this example, the shortcode is used with a custom type attribute. This allows for specifying a different type key for the affiliate ID, providing more flexibility in its usage.

[mycred_affiliate_id type="custom_type"]

In the next advanced example, the shortcode is used with multiple attributes. This is useful when you want to apply certain filters to the affiliate ID. Here, the shortcode is used with both ‘type’ and ‘filter’ attributes.

[mycred_affiliate_id type="custom_type" filter="custom_filter"]

Remember, the ‘type’ attribute is used to specify the type of affiliate ID and the ‘filter’ attribute is used to apply a certain filter to the affiliate ID. This helps in customizing the output of the shortcode based on your specific requirements.

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_affiliate_id] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_affiliate_id', 'mycred_render_affiliate_id' );

Shortcode PHP function:

function mycred_render_affiliate_id( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'type' => MYCRED_DEFAULT_TYPE_KEY
		), $atts, MYCRED_SLUG . '_affiliate_id' ) );

		return apply_filters( 'mycred_affiliate_id_' . $type, '', $atts, $content );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_affiliate_id.php

Mycred [myCRED_Affiliate_Link] Shortcode

The myCRED_Affiliate_Link shortcode generates an affiliate link, enabling users to earn points through referrals. It uses the ‘mycred_render_affiliate_link’ function, which extracts the type of affiliate link.

Shortcode: [myCRED_Affiliate_Link]

Parameters

Here is a list of all possible myCRED_Affiliate_Link shortcode parameters and attributes:

  • type – Specifies the type of affiliate link to be rendered.

Examples and Usage

Basic example – Using the shortcode to display the default affiliate link.

[mycred_affiliate_link]

By default, this shortcode will display the affiliate link associated with the default point type. No additional parameters are needed for this basic usage.

Advanced examples

Using the shortcode to display an affiliate link for a specific point type. The point type is defined by the ‘type’ parameter.

[mycred_affiliate_link type="gold_points"]

In this example, the shortcode will display the affiliate link associated with the ‘gold_points’ point type. If the ‘gold_points’ type does not exist, the shortcode will return an empty string.

Using the shortcode with a custom filter to modify the output of the affiliate link.

function custom_affiliate_link( $link, $atts, $content ) {
    return $link . ' - Custom Text';
}
add_filter( 'mycred_affiliate_link_gold_points', 'custom_affiliate_link', 10, 3 );

In this example, a custom filter is added to modify the output of the affiliate link. The filter is applied to the ‘gold_points’ point type and appends ‘ – Custom Text’ to the end of the link. The filter function accepts three parameters: the original link, the shortcode attributes, and the shortcode content.

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_Affiliate_Link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_affiliate_link', 'mycred_render_affiliate_link' );

Shortcode PHP function:

function mycred_render_affiliate_link( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'type' => MYCRED_DEFAULT_TYPE_KEY
		), $atts, MYCRED_SLUG . '_affiliate_link' ) );

		return apply_filters( 'mycred_affiliate_link_' . $type, '', $atts, $content );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_affiliate_link.php

Mycred [myCRED_best_user] Shortcode

The myCRED_best_user shortcode is designed to display the top user based on myCRED points. It extracts attributes like balance, date range, type of points, and avatar size. The shortcode creates a leaderboard, runs a query to populate it, and returns the top user. If no user is found, it displays a custom message. The shortcode also allows for content customization. Shortcode: [myCRED_best_user]

Shortcode: [myCRED_best_user]

Parameters

Here is a list of all possible myCRED_best_user shortcode parameters and attributes:

  • ref – Defines the reference point for the user’s balance
  • from – Sets the start date of the timeframe
  • until – Sets the end date of the timeframe
  • types – Determines the type of credit to consider
  • nothing – Sets the message displayed when no user is found
  • order – Specifies the order of the users (ASC or DESC)
  • avatar – Defines the size of the user’s avatar image

Examples and Usage

Basic Example – Displays the user with the highest balance.

[mycred_best_user]

Advanced Examples

Displays the best user in terms of the specific point type, for instance, ‘gold’

[mycred_best_user types="gold"]

Displays the best user from a specific date, for instance, ‘2021-01-01’

[mycred_best_user from="2021-01-01"]

Displays the best user until a specific date, for instance, ‘2022-01-01’

[mycred_best_user until="2022-01-01"]

Displays the best user with a specific avatar size, for instance, ‘100’

[mycred_best_user avatar="100"]

Displays the best user with a custom message when no user is found

[mycred_best_user nothing="No top user found"]

Displays the best user by ordering the users in ascending order

[mycred_best_user order="ASC"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_best_user] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_best_user', 'mycred_render_shortcode_best_user' );

Shortcode PHP function:

function mycred_render_shortcode_best_user( $attr, $content = '' ) {

		extract( shortcode_atts( array(
			'ref'     => 'balance',
			'from'    => '',
			'until'   => '',
			'types'   => MYCRED_DEFAULT_TYPE_KEY,
			'nothing' => 'No user found',
			'order'   => 'DESC',
			'avatar'  => 50
		), $attr, MYCRED_SLUG . '_best_user' ) );

		$args = array(
			'number'       => 1,
			'type'         => $types,
			'order'        => $order,
			'based_on'     => $ref,
			'timeframe'    => $from,
			'now'          => $until,
			'exclude_zero' => 0
		);

		// Construct the leaderboard class
		$leaderboard = mycred_get_leaderboard( $args );

		// Just constructing the class will not yeld any results
		// We need to run the query to populate the leaderboard
		$leaderboard->get_leaderboard_results();

		if ( empty( $leaderboard->leaderboard ) )
			return '<p class="mycred-best-user-no-results text-center">' . $nothing . '</p>';

		$best_user   = $leaderboard->leaderboard[0];
		$amount      = $best_user['cred'];
		$user        = get_userdata( $best_user['ID'] );
		if ( ! isset( $user->display_name ) )
			return '<p class="mycred-best-user-no-results text-center">' . $nothing . '</p>';

		if ( empty( $content ) )
			$content = '<div class="mycred-best-user text-center">%avatar%<h4>%display_name%</h4></div>';

		$content = apply_filters( 'mycred_best_user_content', $content, $attr );

		$content = str_replace( '%display_name%', $user->display_name, $content );
		$content = str_replace( '%first_name%',   $user->first_name,   $content );
		$content = str_replace( '%last_name%',    $user->last_name,    $content );
		$content = str_replace( '%user_email%',   $user->user_email,   $content );
		$content = str_replace( '%user_login%',   $user->user_login,   $content );

		$content = str_replace( '%avatar%',       get_avatar( $user->ID, $avatar ), $content );
		$content = str_replace( '%total%',        $amount, $content );
		$content = str_replace( '%total_abs%',    abs( $amount ), $content );
		//$content = str_replace( '%count%',        $result->count, $content );

		return apply_filters( 'mycred_render_best_user', $content, $leaderboard, $attr );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_best_user.php

Mycred [myCRED_exchange] Shortcode

The myCRED_exchange shortcode is used to create a form for users to exchange one type of point for another. The shortcode checks if the user is logged in and if the specified point types exist. It also handles user exclusion and balance checks. If all checks pass, it generates an exchange form with current balance, amount to exchange, exchange rate, and a submit button.

Shortcode: [myCRED_exchange]

Parameters

Here is a list of all possible myCRED_exchange shortcode parameters and attributes:

  • from – specifies the point type to be exchanged
  • to – specifies the point type to be received
  • rate – sets the exchange rate between the two point types
  • min – sets the minimum amount of points that can be exchanged
  • button – customizes the text displayed on the exchange button

Examples and Usage

Basic example – Allows users to exchange one type of myCRED points for another at a specified rate. The shortcode checks if the user is logged in and if the specified point types exist before rendering the exchange form.

[mycred_exchange from="gold" to="silver" rate=2]

Advanced examples

Allows users to exchange a minimum amount of one type of myCRED points for another at a specified rate. The shortcode checks if the user is logged in, if the specified point types exist, and if the user’s balance is sufficient before rendering the exchange form.

[mycred_exchange from="gold" to="silver" rate=2 min=10]

Allows users to exchange one type of myCRED points for another at a specified rate with a custom button text. The shortcode checks if the user is logged in and if the specified point types exist before rendering the exchange form.

[mycred_exchange from="gold" to="silver" rate=2 button="Convert Gold to Silver"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_exchange] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_exchange', 'mycred_render_shortcode_exchange' );

Shortcode PHP function:

function mycred_render_shortcode_exchange( $atts, $content = '' ) {

		if ( ! is_user_logged_in() ) return $content;

		extract( shortcode_atts( array(
			'from'   => '',
			'to'     => '',
			'rate'   => 1,
			'min'    => 1,
			'button' => 'Exchange'
		), $atts, MYCRED_SLUG . '_exchange' ) );

		if ( $from == '' || $to == '' ) return '';

		if ( ! mycred_point_type_exists( $from ) || ! mycred_point_type_exists( $to ) ) return __( 'Point type not found.', 'mycred' );

		$user_id     = get_current_user_id();

		$mycred_from = mycred( $from );
		if ( $mycred_from->exclude_user( $user_id ) )
			return sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_from->plural() );

		$balance     = $mycred_from->get_users_balance( $user_id, $from );
		if ( $balance < $mycred_from->number( $min ) )
			return __( 'Your balance is too low to use this feature.', 'mycred' );

		$mycred_to   = mycred( $to );
		if ( $mycred_to->exclude_user( $user_id ) )
			return sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_to->plural() );

		global $mycred_exchange;

		$rate        = apply_filters( 'mycred_exchange_rate', $rate, $mycred_from, $mycred_to );
		$token       = mycred_create_token( array( $from, $to, $user_id, $rate, $min ) );

		ob_start();

?>
<div class="mycred-exchange">

	<?php echo wp_kses_post( $content ); ?>

	<?php if ( isset( $mycred_exchange['message'] ) ) : ?>
	<div class="alert alert-<?php if ( $mycred_exchange['success'] ) echo 'success'; else echo 'warning'; ?>"><?php echo esc_html( $mycred_exchange['message'] ); ?></div>
	<?php endif; ?>

	<form action="" method="post" class="form">
		<div class="row">
			<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-balance">
				<div class="form-group">
					<label><?php printf( esc_html__( 'Your current %s balance', 'mycred' ), esc_html( $mycred_from->singular() ) ); ?></label>
					<p class="form-control-static"><?php echo esc_html( $mycred_from->format_creds( $balance ) ); ?></p>
				</div>
			</div>
			<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-amount">
				<div class="form-group">
					<label for="mycred-exchange-amount"><?php esc_html_e( 'Amount', 'mycred' ); ?></label>
					<input type="text" size="20" placeholder="<?php printf( esc_attr__( 'Minimum %s', 'mycred' ), esc_attr( $mycred_from->format_creds( $min ) ) ); ?>" value="" class="form-control" id="mycred-exchange-amount" name="mycred_exchange[amount]" />
				</div>
			</div>
			<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-rate">
				<div class="form-group">
					<label><?php esc_html_e( 'Exchange Rate', 'mycred' ); ?></label>
					<p class="form-control-static"><?php printf( wp_kses_post( '1 %s = <span class="rate">%s</span> %s', 'mycred' ), esc_html( $mycred_from->singular() ), esc_html( $rate ), ( ( $rate == 1 ) ? esc_html( $mycred_to->singular() ) : esc_html( $mycred_to->plural() ) ) ); ?></p>
				</div>
			</div>
			<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-submit">
				<div class="form-group">
					<input type="submit" class="btn btn-primary btn-lg btn-block" value="<?php echo esc_attr( $button ); ?>" />
				</div>
			</div>
		</div>
		<input type="hidden" name="mycred_exchange[token]" value="<?php echo esc_attr( $token ); ?>" />
		<input type="hidden" name="mycred_exchange[nonce]" value="<?php echo esc_attr( wp_create_nonce( 'mycred-exchange' ) ); ?>" />
	</form>

</div>
<?php

		$output = ob_get_contents();
		ob_end_clean();

		return apply_filters( 'mycred_exchange_output', $output, $atts );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_exchange.php

Mycred [mycred_give] Shortcode

The MyCred_Give shortcode is designed to allocate points to users. Its functionality checks if a user is logged in and whether the point type exists. If these conditions are met, the shortcode proceeds to check for user exclusion and limit restrictions. If the user is not excluded and hasn’t reached the limit, the shortcode adds points to the user’s account.

Shortcode: [mycred_give]

Parameters

Here is a list of all possible mycred_give shortcode parameters and attributes:

  • amount – the number of points to give to the user.
  • user_id – the ID of the user who will receive the points.
  • log – text to describe the transaction in the log.
  • ref – reference for the transaction, defaults to ‘gift’.
  • limit – the maximum number of times this shortcode can be used.
  • type – the type of points to give, defaults to the default point type.

Examples and Usage

Basic example – A shortcode to give a specific amount of points to the current user.

[mycred_give amount="10"]

Advanced examples

Giving a specific amount of points to a specific user by user ID.

[mycred_give amount="10" user_id="2"]

Limiting the number of times a user can receive points from this shortcode to once per day.

[mycred_give amount="10" limit="1"]

Assigning a custom reference and log entry for the points given with this shortcode.

[mycred_give amount="10" ref="bonus" log="Daily bonus points"]

Using a different point type with the shortcode.

[mycred_give amount="10" type="gold"]

Combining multiple attributes in the shortcode to give a specific amount of a specific point type to a specific user, with a custom reference and log entry, and a limit on how often they can receive points.

[mycred_give amount="10" user_id="2" ref="bonus" log="Daily bonus points" limit="1" type="gold"]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_give] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_give', 'mycred_render_shortcode_give' );

Shortcode PHP function:

function mycred_render_shortcode_give( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'amount'  => '',
			'user_id' => 'current',
			'log'     => '',
			'ref'     => 'gift',
			'limit'   => 0,
			'type'    => MYCRED_DEFAULT_TYPE_KEY
		), $atts, MYCRED_SLUG . '_give' ) );

		if ( ! is_user_logged_in() && $user_id == 'current' )
			return $content;

		if ( ! mycred_point_type_exists( $type ) || apply_filters( 'mycred_give_run', true, $atts ) === false ) return $content;

		$mycred  = mycred( $type );
		$user_id = mycred_get_user_id( $user_id );
		$ref     = sanitize_key( $ref );
		$limit   = absint( $limit );

		// Check for exclusion
		if ( $mycred->exclude_user( $user_id ) ) return $content;

		// Limit
		if ( $limit > 0 && mycred_count_ref_instances( $ref, $user_id, $type ) >= $limit ) return $content;

		$mycred->add_creds(
			$ref,
			$user_id,
			$amount,
			$log,
			0,
			'',
			$type
		);

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_give.php

Mycred [mycred_hide_if] Shortcode

The myCRED_Hide_If shortcode is a dynamic tool that allows content visibility control based on user-specific criteria. This shortcode evaluates user conditions such as balance, rank, reference count, and user login status. If conditions are met, the shortcode hides the content from the user. It’s useful for creating exclusive content for certain users, enhancing user experience and engagement.

Shortcode: [mycred_hide_if]

Parameters

Here is a list of all possible mycred_hide_if shortcode parameters and attributes:

  • balance – Defines the minimum balance a user must have
  • rank – Specifies the user rank requirement
  • ref – Indicates reference for specific actions or events
  • count – Sets the minimum number of reference instances
  • ctype – Determines the type of points to consider
  • visitors – Specifies content for non-logged in users
  • comp – Sets the comparison operator, either ‘AND’ or ‘OR’
  • user_id – Identifies the user to check the conditions against

Examples and Usage

Basic example – This shortcode hides content based on the user’s myCRED balance. The content will be hidden if the user’s balance is equal or greater than the specified amount.

[mycred_hide_if balance=100]Your hidden content goes here[/mycred_hide_if]

Advanced examples

Using the shortcode to hide content based on the user’s myCRED rank. The content will be hidden if the user’s rank is equal to the specified rank.

[mycred_hide_if rank="Gold"]Your hidden content goes here[/mycred_hide_if]

Using the shortcode to hide content based on multiple conditions. The content will be hidden if the user’s balance is equal or greater than 100 and their rank is equal to “Gold”.

[mycred_hide_if balance=100 rank="Gold" comp="AND"]Your hidden content goes here[/mycred_hide_if]

Using the shortcode to hide content for visitors who are not logged in. The content will be hidden and replaced with a custom message.

[mycred_hide_if visitors="Please log in to view this content."]Your hidden content goes here[/mycred_hide_if]

Using the shortcode to hide content based on the user’s myCRED reference count. The content will be hidden if the user’s reference count is equal or greater than the specified count.

[mycred_hide_if ref="comment" count=5]Your hidden content goes here[/mycred_hide_if]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_hide_if] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_hide_if', 'mycred_render_shortcode_hide_if' );

Shortcode PHP function:

function mycred_render_shortcode_hide_if( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'balance'  => -1,
			'rank'     => -1,
			'ref'      => '',
			'count'    => -1,
			'ctype'    => MYCRED_DEFAULT_TYPE_KEY,
			'visitors' => '',
			'comp'     => 'AND',
			'user_id'  => 'current'
		), $atts, MYCRED_SLUG . '_hide_if' ) );

		// Visitors
		if ( ! is_user_logged_in() ) {

			if ( $visitors != '' ) return $visitors;

			return do_shortcode( $content );

		}

		// Get the user ID
		$user_id = mycred_get_user_id( $user_id );

		// You can only use AND or OR for comparisons
		if ( ! in_array( $comp, array( 'AND', 'OR' ) ) )
			$comp = 'AND';

		// Make sure the point type we nominated exists
		if ( ! mycred_point_type_exists( $ctype ) ) return 'invalid point type';

		// Load myCRED with the requested point type
		$mycred  = mycred( $ctype );

		// Make sure user is not excluded
		if ( $mycred->exclude_user( $user_id ) ) return do_shortcode( $content );

		// Lets start determening if the content should be hidden from user
		$should_hide = false;

		// Balance related requirement
		if ( $balance >= 0 ) {

			$users_balance = $mycred->get_users_balance( $user_id, $ctype );
			$balance       = $mycred->number( $balance );

			// Zero balance requirement
			if ( $balance == $mycred->zero() && $users_balance == $mycred->zero() )
				$should_hide = true;

			// Balance must be higher or equal to the amount set
			elseif ( $users_balance >= $balance )
				$should_hide = true;

		}

		// Reference related requirement
		if ( MYCRED_ENABLE_LOGGING && strlen( $ref ) > 0 ) {

			$ref_count = mycred_count_ref_instances( $ref, $user_id, $ctype );

			// Combined with a balance requirement we must have references
			if ( $balance >= 0 && $ref_count == 0 && $comp === 'AND' )
				$should_hide = false;

			// Ref count must be higher or equal to the count set
			elseif ( $ref_count >= $count )
				$should_hide = true;

		}

		// Rank related requirement
		if ( $rank !== -1 && function_exists( 'mycred_get_users_rank' ) ) {

			$rank_id = mycred_get_rank_object_id( $rank );

			// Rank ID provided
			if ( is_numeric( $rank ) )
				$users_rank = mycred_get_users_rank( $user_id, $ctype );

			// Rank title provided
			else
				$users_rank = mycred_get_users_rank( $user_id, $ctype );

			if ( isset( $users_rank->post_id ) && $rank_id !== false ) {

				if ( $users_rank->post_id != $rank_id && $comp === 'AND' )
					$should_hide = false;

				elseif ( $users_rank->post_id == $rank_id )
					$should_hide = true;

			}

		}

		// Allow others to play
		$should_hide = apply_filters( 'mycred_hide_if', $should_hide, $user_id, $atts, $content );

		// Sorry, no show
		if ( $should_hide !== false ) return;

		$content = '<div class="mycred-hide-this-content">' . $content . '</div>';

		// Return content
		return do_shortcode( apply_filters( 'mycred_hide_if_render', $content, $user_id, $atts, $content ) );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_hide_if.php

Mycred [myCRED_History] Shortcode

The myCRED_History shortcode is designed to display the history of a user’s points. It extracts attributes like user ID, number of points, time, reference, order, and more. The shortcode checks if a user is logged in and if logging is enabled. It then retrieves the user ID and checks the existence of the point type. It sets up an array of arguments based on the attributes and displays the points history. It also allows for customization of the display, including inline navigation and front-end navigation. The shortcode ends by resetting the query and returning the content.

Shortcode: [myCRED_History]

Parameters

Here is a list of all possible myCRED_History shortcode parameters and attributes:

  • user_id – Specifies the ID of the user whose points history you want to display.
  • number – Determines the number of entries to display at one time.
  • time – Filters entries based on the time they were logged.
  • ref – Allows filtering of entries based on a specific reference.
  • order – Determines the order of the entries, ascending or descending.
  • show_user – If set to 1, it will display the user’s name with each entry.
  • show_nav – If set to 1, navigation will be displayed.
  • login – If a user is not logged in, this message will be displayed.
  • type – Defines the type of points to display, defaults to the key of the default point type.
  • pagination – Determines how many entries to display per page.
  • inlinenav – If set to 1, the navigation will be displayed inline.

Examples and Usage

Basic example – Display the history of a specific user with default settings.

[mycred_history user_id=1]

Advanced examples

Display the history of a specific user, limiting the results to the last 5 entries.

[mycred_history user_id=1 number=5]

Display the history of a specific user, showing only entries from a specific reference and in a descending order.

[mycred_history user_id=1 ref="custom_reference" order="DESC"]

Display the history of a specific user, showing only entries from a certain point type and with pagination set to 20 entries per page.

[mycred_history user_id=1 type="custom_type" pagination=20]

Display the history of a specific user, showing entries from a specific time period (e.g., last month).

[mycred_history user_id=1 time="last month"]

Display the history of a specific user, excluding navigation and displaying the pagination inline.

[mycred_history user_id=1 show_nav=0 inlinenav=1]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_History] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_history', 'mycred_render_shortcode_history' );

Shortcode PHP function:

function mycred_render_shortcode_history( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'user_id'    => '',
			'number'     => 10,
			'time'       => '',
			'ref'        => '',
			'order'      => '',
			'show_user'  => 0,
			'show_nav'   => 1,
			'login'      => '',
			'type'       => MYCRED_DEFAULT_TYPE_KEY,
			'pagination' => 10,
			'inlinenav'  => 0
		), $atts, MYCRED_SLUG . '_history' ) );

		// If we are not logged in
		if ( ! is_user_logged_in() && $login != '' )
			return $login . $content;

		if ( ! MYCRED_ENABLE_LOGGING ) return '';

		$user_id = mycred_get_user_id( $user_id );

		if ( ! mycred_point_type_exists( $type ) )
			$type = MYCRED_DEFAULT_TYPE_KEY;

		$args    = array( 'ctype' => $type );

		if ( $user_id != 0 && $user_id != '' )
			$args['user_id'] = absint( $user_id );

		if ( absint( $number ) > 0 )
			$args['number'] = absint( $number );

		if ( $time != '' )
			$args['time'] = $time;

		if ( $ref != '' )
			$args['ref'] = $ref;

		if ( $order != '' )
			$args['order'] = $order;

		$log = new myCRED_Query_Log( apply_filters( 'mycred_front_history_args', $args, $atts ) );

		ob_start();

		if ( $inlinenav ) echo '<style type="text/css">.mycred-history-wrapper ul li { list-style-type: none; display: inline; padding: 0 6px; }</style>';

		do_action( 'mycred_front_history', $user_id );

?>
<div class="mycred-history-wrapper">
<form class="form-inline" role="form" method="get" action="">

	<?php if ( $show_nav == 1 ) $log->front_navigation( 'top', $pagination ); ?>

	<?php $log->display(); ?>

	<?php if ( $show_nav == 1 ) $log->front_navigation( 'bottom', $pagination ); ?>

</form>
</div>
<?php

		$content = ob_get_contents();
		ob_end_clean();

		$log->reset_query();

		return $content;

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_history.php

Mycred [MYCRED_SLUG_hook_table] Shortcode

The myCRED_SLUG_hook_table shortcode is a dynamic tool in the myCRED plugin that displays a table of hooks that are active for a specific point type. It accepts parameters for type, gains, user, post, comment, amount, and a default message for when no instances are found. This shortcode is useful for managing and displaying various myCRED hooks in a structured table format.

Shortcode: [MYCRED_SLUG_hook_table]

Parameters

Here is a list of all possible MYCRED_SLUG_hook_table shortcode parameters and attributes:

  • type – Specifies the type of points to display.
  • gains – Determines if gains (1) or losses (0) are shown.
  • user – Defines the user related to the points.
  • post – Defines the post related to the points.
  • comment – Defines the comment related to the points.
  • amount – Specifies the amount of points to display.
  • nothing – Text to display if no instances are found for the point type.

Examples and Usage

Basic example – A simple usage of the myCRED hook table shortcode, displaying the default type of points.

[mycred_hook_table]

Advanced examples

Specifying a different type of points, for example ‘gold’, to be displayed in the hook table.

[mycred_hook_table type='gold']

Displaying only the hooks that subtract points (gains=0) for the ‘gold’ type of points.

[mycred_hook_table type='gold' gains=0]

Customizing the message displayed when no instances are found for the specified point type.

[mycred_hook_table nothing='No gold points instances found.']

Using the shortcode to display a hook table for a specific user, post, and comment.

[mycred_hook_table user='JohnDoe' post='PostTitle' comment='CommentText']

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG_hook_table] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_hook_table', 'mycred_render_shortcode_hook_table' );

Shortcode PHP function:

function mycred_render_shortcode_hook_table( $atts ) {

		extract( shortcode_atts( array(
			'type'    => MYCRED_DEFAULT_TYPE_KEY,
			'gains'   => 1,
			'user'    => '-user-',
			'post'    => '-post-',
			'comment' => '-comment-',
			'amount'  => '',
			'nothing' => __( 'No instances found for this point type', 'mycred' )
		), $atts, MYCRED_SLUG . '_hook_table' ) );

		if ( ! mycred_point_type_exists( $type ) ) return __( 'Point type not found.', 'mycred' );

		$mycred     = mycred( $type );
		$id         = str_replace( '_', '-', $type );
		$prefs_key  = apply_filters( 'mycred_option_id', 'mycred_pref_hooks' );

		if ( $type != MYCRED_DEFAULT_TYPE_KEY )
			$prefs_key .= '_' . $type;

		$applicable = array();

		$hooks      = get_option( $prefs_key, false );

		if ( isset( $hooks['active'] ) && ! empty( $hooks['active'] ) ) {

			foreach ( $hooks['active'] as $active_hook_id ) {

				$hook_prefs = $hooks['hook_prefs'][ $active_hook_id ];

				// Single Instance
				if ( isset( $hook_prefs['creds'] ) ) {

					if ( ( $gains == 1 && $hook_prefs['creds'] > 0 ) || ( $gains == 0 && $hook_prefs['creds'] < 0 ) )
						$applicable[ $active_hook_id ] = $hook_prefs;

				}

				// Multiple Instances
				else {

					foreach ( $hook_prefs as $instance_id => $instance_prefs ) {

						if ( ! isset( $instance_prefs['creds'] ) ) continue;

						if ( ( $gains == 1 && $instance_prefs['creds'] > 0 ) || ( $gains == 0 && $instance_prefs['creds'] < 0 ) ){
							if($active_hook_id==='deleted_content' || $active_hook_id==='publishing_content' || $active_hook_id==='view_contents'  ){
								$applicable[ $active_hook_id."_".$instance_id ] = $instance_prefs;
							}
							else{
									$applicable[ $instance_id ] = $instance_prefs;
							}
						}

					}

				}

			}

		}

		ob_start();

		if ( ! empty( $applicable ) ) {

?>
<div class="table-responsive">
	<table class="table mycred-hook-table hook-table-<?php echo esc_attr( $id ); ?>">
		<thead>
			<tr>
				<th class="column-instance" style="width: 60%;"><?php esc_html_e( 'Instance', 'mycred' ); ?></th>
				<th class="column-amount" style="width: 20%;"><?php esc_html_e( 'Amount', 'mycred' ); ?></th>
				<th class="column-limit" style="width: 20%;"><?php esc_html_e( 'Limit', 'mycred' ); ?></th>
			</tr>
		</thead>
		<tbody><?php

			foreach ( $applicable as $id => $prefs ) {
			
				if( is_array( $prefs['creds'] ) ){ ?>

				<tr>
					
					<?php
					foreach ( $prefs['log'] as $key => $value ) {
						
						$log = $mycred->template_tags_general( $value );
						$log = strip_tags( $log );
						$log = str_replace( array( '%user_id%', '%user_name%', '%user_name_en%', '%display_name%', '%user_profile_url%', '%user_profile_link%', '%user_nicename%', '%user_email%', '%user_url%', '%balance%', '%balance_f%' ), $user, $log );
						$log = str_replace( array( '%post_title%', '%post_url%', '%link_with_title%', '%post_type%' ), $post, $log );
						$log = str_replace( array( 'comment_id', 'c_post_id', 'c_post_title', 'c_post_url', 'c_link_with_title' ), $comment, $log );
						$log = str_replace( array( '%cred%', '%cred_f%' ), $amount, $log );

						$cred = $mycred->format_creds( $prefs['creds'][$key] );
						$limit = '';
						$limit = mycred_translate_limit_code( $limit, $id, $mycred );?>
						
						<tr>
							<td class="column-instance"><?php echo esc_html( $log ); ?></td>
							<td class="column-amount"><?php echo esc_html( $cred ); ?></td>
							<td class="column-limit"><?php echo esc_html( $limit ); ?></td>
						</tr><?php
					}
					?>
				</tr><?php

				}
				else {
					
					$log = $mycred->template_tags_general( $prefs['log'] );
					$log = strip_tags( $log );
					$log = str_replace( array( '%user_id%', '%user_name%', '%user_name_en%', '%display_name%', '%user_profile_url%', '%user_profile_link%', '%user_nicename%', '%user_email%', '%user_url%', '%balance%', '%balance_f%' ), $user, $log );
					$log = str_replace( array( '%post_title%', '%post_url%', '%link_with_title%', '%post_type%' ), $post, $log );
					$log = str_replace( array( 'comment_id', 'c_post_id', 'c_post_title', 'c_post_url', 'c_link_with_title' ), $comment, $log );
					$log = str_replace( array( '%cred%', '%cred_f%' ), $amount, $log );
					$log = apply_filters( 'mycred_hook_table_log', $log, $id, $prefs, $atts );

					$limit = '';
					if ( isset( $prefs['limit'] ) )
						$limit = $prefs['limit'];
						
					if( $id == "approved" ) {
					    if ( isset( $hooks["hook_prefs"]["comments"]["limits"] ) ) {
					        $approved_limits = $hooks["hook_prefs"]["comments"]["limits"];
					        if( (int) $approved_limits["per_post"] > 0 && (int) $approved_limits["per_day"] > 0 ) {
					        	
					            $limit = sprintf( __( 'Maximum %s times per post and Maximum %s times per day', 'mycred' ), $approved_limits["per_post"],  $approved_limits["per_day"] );
					        }
					        elseif( (int) $approved_limits["per_post"] > 0 && (int) $approved_limits["per_day"] < 1 ) {
					        	
					            $limit = sprintf( __( 'Maximum %s times per post', 'mycred' ), $approved_limits["per_post"] );
					        }
					        elseif( (int) $approved_limits["per_post"] < 1 && (int) $approved_limits["per_day"] > 0 ) {

					            $limit = sprintf( __( 'Maximum %s times per day', 'mycred' ), $approved_limits["per_day"] );
					        }
					        else {
					            $limit = __('No limit', 'mycred');
					        }
					    }   
				    }
				    else {
				        $limit = mycred_translate_limit_code( $limit, $id, $mycred );
				    } 

				    $creds = apply_filters( 'mycred_hook_table_creds', $mycred->format_creds( $prefs['creds'] ), $id, $prefs, $atts );
				    ?>
					<tr>
						<td class="column-instance"><?php echo esc_html( $log ); ?></td>
						<td class="column-amount"><?php echo esc_html( $creds ); ?></td>
						<td class="column-limit"><?php echo esc_html( $limit ); ?></td>
					</tr>
					<?php

				}

			}

?>
		</tbody>
	</table>
</div>
<?php

		}
		else {
			echo '<p>' . esc_html( $nothing ) . '</p>';
		}

		$content = ob_get_contents();
		ob_end_clean();

		return apply_filters( 'mycred_render_hook_table', $content, $atts );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_hook_table.php

Mycred [mycred_leaderboard] Shortcode

The MyCred Leaderboard shortcode is a powerful tool that dynamically generates a leaderboard based on user points. This shortcode ranks users based on their balance, with customizable features such as the number of users displayed, ordering, and offset. The leaderboard can be wrapped in a specified HTML tag, and the layout can be customized using templates. If the leaderboard is empty, a custom message can be displayed. The shortcode also allows for the exclusion of users with zero balance, and it supports specific timeframes and user exclusions. It also includes an option to display user avatars.

Shortcode: [mycred_leaderboard]

Parameters

Here is a list of all possible mycred_leaderboard shortcode parameters and attributes:

  • number – Defines the total number of users to show on the leaderboard.
  • order – Sets the order of users on the leaderboard, either ascending or descending.
  • offset – Determines the number of users to skip at the beginning.
  • type – Identifies the type of myCRED points to consider.
  • based_on – Specifies the criteria for ranking users on the leaderboard.
  • total – Sets the total number of points to distribute among users.
  • wrap – Determines the HTML tag to wrap around each user on the leaderboard.
  • template – Defines the layout of the leaderboard.
  • nothing – Message displayed when the leaderboard is empty.
  • current – Shows the current user’s position on the leaderboard.
  • exclude_zero – Excludes users with zero points from the leaderboard.
  • timeframe – Sets the time frame for the leaderboard, such as daily, weekly, or monthly.
  • to – Sets the end date for the leaderboard.
  • exclude – Excludes specific users from the leaderboard.
  • image – Determines whether to show user profile pictures on the leaderboard.

Examples and Usage

Basic example – Display a leaderboard of users with the highest balances. The leaderboard will include the top 25 users by default.

[mycred_leaderboard]

Advanced examples

Display a leaderboard of the top 10 users based on their balance and order them in ascending order.

[mycred_leaderboard number=10 order='ASC']

Display a leaderboard of users excluding those with zero balance. The leaderboard will show the top 25 users by default and will exclude users with zero balance.

[mycred_leaderboard exclude_zero=1]

Display a leaderboard of users based on a specific timeframe. The leaderboard will show the top 25 users by default and will only include balances earned within the specified timeframe.

[mycred_leaderboard timeframe='2021-01-01 00:00:00,2021-12-31 23:59:59']

Display a leaderboard of users, excluding specific users. The leaderboard will show the top 25 users by default and will exclude the specified users.

[mycred_leaderboard exclude='user1,user2,user3']

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_leaderboard] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_leaderboard', 'mycred_render_shortcode_leaderboard' );

Shortcode PHP function:

function mycred_render_shortcode_leaderboard( $atts, $content = '' ) {

		$args = shortcode_atts( array(
			'number'       	=>	25,
			'order'        	=>	'DESC',
			'offset'       	=>	0,
			'type'         	=>	MYCRED_DEFAULT_TYPE_KEY,
			'based_on'     	=>	'balance',
			'total'        	=>	0,
			'wrap'         	=>	'li',
			'template'     	=>	'#%position% %user_profile_link% %image% %cred_f%',
			'nothing'      	=>	'Leaderboard is empty',
			'current'      	=>	0,
			'exclude_zero' 	=>	1,
			'timeframe'    	=>	'',
			'to'    		=>	'',
			'exclude'		=>	'',
			'image'			=>	0
		), $atts, MYCRED_SLUG . '_leaderboard' );

		// Construct the leaderboard class
		$leaderboard = mycred_get_leaderboard( $args );

		// Just constructing the class will not yeld any results
		// We need to run the query to populate the leaderboard
		$leaderboard->get_leaderboard_results( (bool) $args['current'] );

		// Render and return
		return do_shortcode( $leaderboard->render( $args, $content ) );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_leaderboard.php

Mycred [mycred_leaderboard_position] Shortcode

The myCRED_Leaderboard_Position shortcode displays a user’s rank on a leaderboard. It uses user ID and other attributes to determine the position. . The shortcode can be customized using various attributes like user_id, ctype, type, based_on, total, missing, suffix, and timeframe. These attributes allow for a versatile use of the shortcode.

Shortcode: [mycred_leaderboard_position]

Parameters

Here is a list of all possible mycred_leaderboard_position shortcode parameters and attributes:

  • user_id – Identifier of the user for whom position is needed
  • ctype – The type of points to use for the leaderboard
  • type – The type of points to use, if ‘ctype’ is not provided
  • based_on – Determines the criteria for leaderboard ranking
  • total – The total number of users to include in the leaderboard
  • missing – The text to display if a user’s position is not available
  • suffix – If set to 1, adds an ordinal suffix to the position number
  • timeframe – The timeframe for which the leaderboard is generated

Examples and Usage

Basic Example – A shortcode that displays the current user’s leaderboard position based on their balance.

[MYCRED_SLUG_leaderboard_position user_id="current" based_on="balance"]

Advanced Examples

Displaying a specific user’s position on the leaderboard, using their user ID and the custom point type. If the user’s position is missing, it will display ‘N/A’.

[MYCRED_SLUG_leaderboard_position user_id="123" ctype="custom" missing="N/A"]

Displaying the leaderboard position of the current user, based on a custom point type, with an ordinal suffix (1st, 2nd, 3rd, etc.). If the user’s position is missing, it will display ‘0’.

[MYCRED_SLUG_leaderboard_position user_id="current" ctype="custom" missing="0" suffix="1"]

Displaying the leaderboard position of a specific user, based on total points earned within a specific timeframe (e.g., ‘this week’). If the user’s position is missing, it will display ‘-‘.

[MYCRED_SLUG_leaderboard_position user_id="123" based_on="total" timeframe="this week" missing="-"]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_leaderboard_position] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_leaderboard_position', 'mycred_render_shortcode_leaderbaord_position' );

Shortcode PHP function:

function mycred_render_shortcode_leaderbaord_position( $atts, $content = '' ) {

		$args = shortcode_atts( array(
			'user_id'   => 'current',
			'ctype'     => MYCRED_DEFAULT_TYPE_KEY,
			'type'      => '',
			'based_on'  => 'balance',
			'total'     => 0,
			'missing'   => '-',
			'suffix'    => 0,
			'timeframe' => ''
		), $atts, MYCRED_SLUG . '_leaderboard_position' );

		// Get the user ID we need a position for
		$user_id     = mycred_get_user_id( $args['user_id'] );

		// Backwards comp.
		if ( $args['type'] == '' )
			$args['type'] = $args['ctype'];

		// Construct the leaderboard class
		$leaderboard = mycred_get_leaderboard( $args );

		// Query the users position
		$position    = $leaderboard->get_users_current_position( $user_id, $args['missing'] );

		if ( $position != $args['missing'] && $args['suffix'] == 1 )
			$position = mycred_ordinal_suffix( $position, true );

		return $position;

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_leaderboard_position.php

Mycred [myCRED_link] Shortcode

The myCRED_link shortcode is a powerful tool that generates links with customizable attributes. It allows users to earn points when they click on the link. The shortcode uses global variable $mycred_link_points to ensure jQuery script is called. It checks if the user is logged in and applies point value for the link click. It also creates a unique token for each link. The shortcode returns an anchor tag with all the attributes and points value.

Shortcode: [myCRED_link]

Parameters

Here is a list of all possible myCRED_link shortcode parameters and attributes:

  • id – Unique identifier for the link.
  • rel – Relationship between the current document and the linked document.
  • class – Specifies one or more class names for the link.
  • href – The URL the link goes to.
  • title – Text to be displayed as a tooltip when hovering over the link.
  • target – Specifies where to open the linked document.
  • style – Specifies an inline CSS style for the link.
  • amount – The amount of points to be awarded.
  • ctype – The type of points to be awarded.
  • hreflang – Language of the linked document.
  • media – Specifies what media/device the linked document is optimized for.
  • type – Specifies the MIME type of the linked document.
  • onclick – Script to be run when the link is clicked.

Examples and Usage

Basic example – Display a link with a specific URL and class name.

[mycred_link href="https://example.com" class="my-custom-class" /]

Advanced examples – Using the shortcode to display a link with various attributes. The link will contain the specified ID, rel, class, href, title, target, style, amount, ctype, hreflang, media, type, onclick attributes.

[mycred_link id="my-id" rel="nofollow" class="my-custom-class" href="https://example.com" title="My Title" target="_blank" style="color: red;" amount="10" ctype="gold" hreflang="en" media="screen" type="text/html" onclick="myFunction()" /]

Using the shortcode to display a link with specific attributes for logged-in users. The link will contain the specified href, amount, and ctype attributes. The amount attribute will be used to specify the number of points to be awarded to the user for clicking the link. The ctype attribute will be used to specify the type of points to be awarded.

[mycred_link href="https://example.com" amount="10" ctype="gold" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_link', 'mycred_render_shortcode_link' );

Shortcode PHP function:

function mycred_render_shortcode_link( $atts, $link_title = '' ) {

		global $mycred_link_points;

		$atts = shortcode_atts( array(
			'id'       => '',
			'rel'      => '',
			'class'    => '',
			'href'     => '',
			'title'    => '',
			'target'   => '',
			'style'    => '',
			'amount'   => 0,
			'ctype'    => MYCRED_DEFAULT_TYPE_KEY,
			'hreflang' => '',
			'media'    => '',
			'type'     => '',
			'onclick'  => ''
		), $atts, MYCRED_SLUG . '_link' );

		// Make sure point type exists
		if ( ! mycred_point_type_exists( $atts['ctype'] ) )
			$atts['ctype'] = MYCRED_DEFAULT_TYPE_KEY;

		// HREF is required
		if ( empty( $atts['href'] ) )
			$atts['href'] = '#';

		// All links must contain the 'mycred-points-link' class
		if ( empty( $atts['class'] ) )
			$atts['class'] = 'mycred-points-link';
		else
			$atts['class'] = 'mycred-points-link ' . $atts['class'];

		// If no id exists, make one
		if ( empty( $atts['id'] ) ) {
			$id         = str_replace( array( 'http://', 'https://', 'http%3A%2F%2F', 'https%3A%2F%2F' ), 'hs', $atts['href'] );
			$id         = str_replace( array( '/', '-', '_', ':', '.', '?', '=', '+', '\\', '%2F' ), '', $id );
			$atts['id'] = $id;
		}

		// Construct anchor attributes
		$attr = array();
		foreach ( $atts as $attribute => $value ) {
			if ( ! empty( $value ) && ! in_array( $attribute, array( 'amount', 'ctype' ) ) ) {
				$attr[] = $attribute . '="' . $value . '"';
			}
		}

		// Add point type as a data attribute
		$attr[] = 'data-type="' . esc_attr( $atts['ctype'] ) . '"';

		// Only usable for members
		if ( is_user_logged_in() ) {

			// If amount is zero, use the amount we set in the hooks settings
			if ( $atts['amount'] == 0 ) {

				// Get hook settings
				$prf_hook = apply_filters( 'mycred_option_id', 'mycred_pref_hooks' );
				$hooks = mycred_get_option( $prf_hook, false );
				if ( $atts['ctype'] != MYCRED_DEFAULT_TYPE_KEY )
					$hooks = mycred_get_option( 'mycred_pref_hooks_' . sanitize_key( $atts['ctype'] ), false );

				// Apply points value
				if ( $hooks !== false && is_array( $hooks ) && array_key_exists( 'link_click', $hooks['hook_prefs'] ) ) {
					$atts['amount'] = $hooks['hook_prefs']['link_click']['creds'];
				}

			}

			// Add key
			$token  = mycred_create_token( array( $atts['amount'], $atts['ctype'], $atts['id'], urlencode( $atts['href'] ) ) );
			$attr[] = 'data-token="' . $token . '"';

			// Make sure jQuery script is called
			$mycred_link_points = true;

		}

		// Return result
		return apply_filters( 'mycred_link', '<a ' . implode( ' ', $attr ) . '>' . do_shortcode( $link_title ) . '</a>', $atts, $link_title );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_link.php

Mycred [myCRED_my_balance] Shortcode

The myCRED_my_balance shortcode displays the current user’s balance. It allows customization of the title, element types, and inclusion of an image. This shortcode uses the mycred_render_shortcode_my_balance function, which extracts the user ID, title, and other attributes. It checks whether the user is logged in and the validity of the point type. It then retrieves the user’s balance and, if not excluded, displays it with the specified formatting.

Shortcode: [myCRED_my_balance]

Parameters

Here is a list of all possible myCRED_my_balance shortcode parameters and attributes:

  • user_id – Identifier of the user, ‘current’ for logged-in user
  • title – Title text to display above the balance
  • title_el – HTML element for the title, default is ‘h1’
  • balance_el – HTML element for the balance, default is ‘div’
  • wrapper – If set to 1, a div wrapper is added around the output
  • formatted – If set to 1, balance is formatted with decimals
  • type – Type of myCRED points, default is ‘MYCRED_DEFAULT_TYPE_KEY’
  • image – If set to 1, displays an image before the balance

Examples and Usage

Basic example – Displays the current user’s balance without a title.

[mycred_my_balance]

Advanced examples

Displays the current user’s balance with a title.

[mycred_my_balance title="Your Current Balance:"]

Displays a specific user’s balance by referencing the user ID.

[mycred_my_balance user_id=2]

Displays the current user’s balance with a title and an image, and it is wrapped within a div element.

[mycred_my_balance title="Your Current Balance:" image=1 wrapper=1]

Displays the current user’s balance without formatting the number.

[mycred_my_balance formatted=0]

Displays the current user’s balance for a specific point type.

[mycred_my_balance type="gold"]

Displays the balance wrapped within a div element, and the balance is displayed within a h1 element.

[mycred_my_balance wrapper=1 balance_el="h1"]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_my_balance] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_my_balance', 'mycred_render_shortcode_my_balance' );

Shortcode PHP function:

function mycred_render_shortcode_my_balance( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'user_id'   	=>	'current',
			'title'      	=>	'',
			'title_el'   	=>	'h1',
			'balance_el' 	=>	'div',
			'wrapper'    	=>	1,
			'formatted'  	=>	1,
			'type'       	=>	MYCRED_DEFAULT_TYPE_KEY,
			'image'			=>	0
		), $atts, MYCRED_SLUG . '_my_balance' ) );

		$mycred = mycred( $type );

		$output = '';

		// Not logged in
		if ( ! is_user_logged_in() && $user_id == 'current' )
			return $content;

		// Get user ID
		$user_id = mycred_get_user_id( $user_id );

		// Make sure we have a valid point type
		if ( ! mycred_point_type_exists( $type ) )
			$type = MYCRED_DEFAULT_TYPE_KEY;

		// Get the users myCRED account object
		$account = mycred_get_account( $user_id );
		if ( $account === false ) return;

		// Check for exclusion
		if ( empty( $account->balance ) || ! array_key_exists( $type, $account->balance ) || $account->balance[ $type ] === false ) return;

		$balance = $account->balance[ $type ];

		if ( $wrapper )
			$output .= '<div class="mycred-my-balance-wrapper">';

		// Title
		if ( ! empty( $title ) ) {
			if ( ! empty( $title_el ) )
				$output .= '<' . $title_el . '>';

			$output .= $title;

			if ( ! empty( $title_el ) )
				$output .= '</' . $title_el . '>';
		}

		// Balance
		if ( ! empty( $balance_el ) )
			$output .= '<' . $balance_el . '>';

		//Image
		if( $image && $mycred->image_url)
			$output .= "<img src='{$mycred->image_url}' style='margin-right: 5px;' class='mycred-my-balance-image-{$type}' width='20px' />";

		if ( $formatted )
			$output .= $balance->point_type->format( $balance->current );
		else
			$output .= $balance->point_type->number( $balance->current );

		if ( ! empty( $balance_el ) )
			$output .= '</' . $balance_el . '>';

		if ( $wrapper )
			$output .= '</div>';

		return $output;

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_my_balance.php

Mycred [mycred_my_balance_converted] Shortcode

The myCRED Balance Converted shortcode is used to display a user’s myCRED balance in a converted format. It allows customization of the output with parameters like currency type, conversion rate, prefix, suffix, and decimal places. This shortcode is especially useful when you want to display a user’s myCRED balance in different currency types or rates. It checks if the user is logged in, validates the point type, and retrieves the user’s myCRED account balance. Finally, it outputs the converted balance enclosed in a div tag, with optional prefix and suffix.

Shortcode: [mycred_my_balance_converted]

Parameters

Here is a list of all possible mycred_my_balance_converted shortcode parameters and attributes:

  • ctype – Specifies the type of myCRED points to be converted.
  • rate – Defines the conversion rate for the points.
  • prefix – Adds a custom text before the converted balance.
  • suffix – Adds a custom text after the converted balance.
  • decimal – Determines the number of decimal places in the converted balance.
  • timeframe – Allows balance conversion within a specific timeframe.

Examples and Usage

Basic example – Displays the user’s converted myCRED balance with a default conversion rate of 1.

[mycred_my_balance_converted /]

Advanced examples

Displaying the user’s converted myCRED balance with a custom conversion rate of 0.5. The balance will be halved due to the rate specified.

[mycred_my_balance_converted rate=0.5 /]

Displaying the user’s converted myCRED balance with a custom conversion rate of 2 and a prefix of ‘$’. The balance will be doubled and prefixed with a dollar sign due to the parameters specified.

[mycred_my_balance_converted rate=2 prefix='$' /]

Displaying the user’s converted myCRED balance with a custom conversion rate of 0.75, a prefix of ‘€’, and a suffix of ‘ EUR’. The balance will be multiplied by 0.75 and prefixed with a euro sign and suffixed with ‘ EUR’ due to the parameters specified.

[mycred_my_balance_converted rate=0.75 prefix='€' suffix=' EUR' /]

Displaying the user’s converted myCRED balance with a custom conversion rate of 1.5, a prefix of ‘£’, a suffix of ‘ GBP’, and a timeframe of ‘week’. The balance will be multiplied by 1.5, prefixed with a pound sign, suffixed with ‘ GBP’, and only the balance of the last week will be considered due to the parameters specified.

[mycred_my_balance_converted rate=1.5 prefix='£' suffix=' GBP' timeframe='week' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mycred_my_balance_converted] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_my_balance_converted', 'mycred_render_shortcode_my_balance_converted' );

Shortcode PHP function:

function mycred_render_shortcode_my_balance_converted( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'ctype'   	=>	MYCRED_DEFAULT_TYPE_KEY,
			'rate'    	=>	1,
			'prefix'  	=>	'',
			'suffix' 	=>	'',
			'decimal' 	=>	1,
			'timeframe'	=>	''
		), $atts, MYCRED_SLUG . '_my_balance_converted' ) );

		$output = '';

		$timeframe_balance = '';

		// Not logged in
		if ( ! is_user_logged_in() )
			return $content;

		// Get user ID
		$user_id = mycred_get_user_id( get_current_user_id() );

		// Make sure we have a valid point type
		if ( ! mycred_point_type_exists( $ctype ) )
			$ctype = MYCRED_DEFAULT_TYPE_KEY;

		// Get the users myCRED account object
		$account = mycred_get_account( $user_id );
		if ( $account === false ) return;

		// Check for exclusion
		if ( empty( $account->balance ) || ! array_key_exists( $ctype, $account->balance ) || $account->balance[ $ctype ] === false ) return;

		if( empty( $timeframe ) )
			$balance = $account->balance[ $ctype ];
		else
			$timeframe_balance = mycred_my_bc_get_balance( $user_id, $timeframe, $ctype );

		$output = '<div class="mycred-my-balance-converted-wrapper">';

		if ( ! empty( $prefix ) )
			$output .= '<span class="mycred-my-balance-converted-prefix">'.esc_attr( $prefix ).'</span>';

		if( floatval( $rate ) == 0 ) $rate = 1;

		$converted_balance = floatval( empty( $timeframe ) ? $balance->current : $timeframe_balance ) * floatval( $rate );

		$output .= number_format( $converted_balance, intval( $decimal ), '.', '' );

		if ( ! empty( $suffix ) )
			$output .= '<span class="mycred-my-balance-converted-suffix">'.esc_attr( $suffix ).'</span>';

		$output .= '</div>';

		return $output;

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_my_balance_converted.php

Mycred [myCRED_referral_stats] Shortcode

The myCRED_referral_stats shortcode displays referral statistics for the current user in a table format. It shows the count of visitors and signups referred by the user.

Shortcode: [myCRED_referral_stats]

Examples and Usage

Basic example – Displays the referral statistics for the current user with the default point type.

[mycred_referral_stats]

Advanced examples

Displays the referral statistics for the current user with a specific point type. The point type is defined by the ‘ctype’ attribute. In this example, we are using ‘gold’ as the point type.

[mycred_referral_stats ctype='gold']

Another example of an advanced usage of the shortcode is when you want to display the referral stats for a specific user. You can do this by adding the user’s ID in the ‘user_id’ attribute. In this example, the user ID is ‘123’.

[mycred_referral_stats user_id='123']

Please note that the ‘user_id’ attribute is not defined in the given PHP code. It’s just an example of how you might extend the shortcode to accept more parameters.

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_referral_stats] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_referral_stats' , 'mycred_referral_front' );

Shortcode PHP function:

function mycred_referral_front( $atts ){

		extract( shortcode_atts( array(

			'ctype'    => MYCRED_DEFAULT_TYPE_KEY

		), $atts, MYCRED_SLUG . '_referral' ) );

		$hooks    = mycred_get_option( 'mycred_pref_hooks', false );

		if ( $ctype != MYCRED_DEFAULT_TYPE_KEY )
			$hooks = mycred_get_option( 'mycred_pref_hooks_' . sanitize_key( $ctype ), false );
			$active = $hooks['active'];
		if( is_array( $active) && in_array( 'affiliate' , $active )){

			$visit = $hooks['hook_prefs']['affiliate']['visit'];
			$signup = $hooks['hook_prefs']['affiliate']['signup'];
			
			$output = '';
			
			$user_id = get_current_user_id();

			$output .= '<table class="profile-fields">';
			
			// Show Visitor referral count
			if ( $visit['creds'] != 0 )
				$output .= sprintf( '<tr class="field_2 field_ref_count_visit"><td class="label">%s</td><td>%s</td></tr>', __( 'Visitors Referred', 'mycred' ), mycred_count_ref_instances( 'visitor_referral', $user_id, $ctype ) );

			// Show Signup referral count
			if ( $signup['creds'] != 0 )
				$output .= sprintf( '<tr class="field_3 field_ref_count_signup"><td class="label">%s</td><td>%s</td></tr>', __( 'Signups Referred', 'mycred' ), mycred_count_ref_instances( 'signup_referral', $user_id, $ctype ) );
				
			$output .= '</table>';
			return $output;
		}
	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_referral_stats.php

Mycred [MYCRED_send] Shortcode

The myCRED_send shortcode is a powerful tool allowing logged-in users to send points to other users. It checks the point type, ensures the sender has sufficient balance, and verifies neither party is excluded.

Shortcode: [MYCRED_send]

Parameters

Here is a list of all possible MYCRED_send shortcode parameters and attributes:

  • amount – Specifies the number of points to send.
  • to – Identifies the recipient of the points.
  • log – Stores a custom log entry for the transaction.
  • ref – Defines the reference for the points transaction.
  • type – Specifies the type of points being sent.
  • class – Sets the CSS class for the send points button.
  • reload – Determines if the page should reload after sending points.

Examples and Usage

Basic example – An example of a basic usage of the shortcode to send points from a logged-in user to another user. The ‘to’ parameter specifies the recipient. The ‘amount’ parameter specifies the number of points to be sent. The ‘type’ parameter specifies the type of points to be sent.

[mycred_send to="2" amount="10" type="mycred_default"]

Advanced examples

Using the shortcode to send points with a custom log entry and reference. The ‘log’ parameter specifies the log entry for the transaction. The ‘ref’ parameter specifies the reference. If the ‘reload’ parameter is set to 1, the page will reload after the transaction.

[mycred_send to="2" amount="10" log="Sending points for a job well done" ref="gift" reload="1" type="mycred_default"]

Using the shortcode to send points with a custom CSS class. The ‘class’ parameter can be used to add custom CSS classes to the button.

[mycred_send to="2" amount="10" class="my-custom-class" type="mycred_default"]

Using the shortcode to send points with a custom button label. The content enclosed within the shortcode tags will be used as the button label.

[mycred_send to="2" amount="10" type="mycred_default"]Click here to send points[/mycred_send]

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG . '_send'] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_send', 'mycred_render_shortcode_send' );

Shortcode PHP function:

function mycred_render_shortcode_send( $atts, $content = '' ) {

		if ( ! is_user_logged_in() ) return;

		extract( shortcode_atts( array(
			'amount' => 0,
			'to'     => '',
			'log'    => '',
			'ref'    => 'gift',
			'type'   => MYCRED_DEFAULT_TYPE_KEY,
			'class'  => 'button button-primary btn btn-primary',
			'reload' => 0
		), $atts, MYCRED_SLUG . '_send' ) );

		if ( ! mycred_point_type_exists( $type ) ) return 'Point type not found.';

		global $post;

		// Send points to the post author (assuming this shortcode is used inside the loop)
		$to            = mycred_get_user_id( $to );

		// We will not render for ourselves.
		$user_id       = get_current_user_id();
		$recipient     = absint( $to );
		if ( $recipient === $user_id || $recipient === 0 ) return;

		global $mycred_sending_points;

		$mycred_sending_points = false;

		$mycred        = mycred( $type );

		// Make sure current user or recipient is not excluded!
		if ( $mycred->exclude_user( $recipient ) || $mycred->exclude_user( $user_id ) ) return;

		$account_limit = $mycred->number( apply_filters( 'mycred_transfer_acc_limit', 0 ) );
		$balance       = $mycred->get_users_balance( $user_id, $type );
		$amount        = $mycred->number( $amount );

		// Insufficient Funds
		if ( $balance-$amount < $account_limit ) return;

		// We are ready!
		$mycred_sending_points = true;

		if ( $class != '' )
			$class = ' ' . sanitize_text_field( $class );

		$reload = absint( $reload );

		$render = '<button type="button" class="mycred-send-points-button btn btn-primary' . $class . '" data-reload="' . $reload . '" data-to="' . $recipient . '" data-ref="' . esc_attr( $ref ) . '" data-log="' . esc_attr( $log ) . '" data-amount="' . $amount . '" data-type="' . esc_attr( $type ) . '">' . $mycred->template_tags_general( $content ) . '</button>';

		return apply_filters( 'mycred_send', $render, $atts, $content );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_send.php

Mycred [myCRED_show_if] Shortcode

The myCRED_show_if shortcode is a conditional logic tool in the myCRED plugin that displays content based on a user’s points balance, rank, or reference count. It checks if the user is logged in and not excluded, then determines if the content should be shown based on set conditions. If all conditions are met, the content within the shortcode is displayed.

Shortcode: [myCRED_show_if]

Parameters

Here is a list of all possible myCRED_show_if shortcode parameters and attributes:

  • balance – The minimum balance required for the content to be visible.
  • rank – The rank a user must have for the content to be shown.
  • ref – The reference used to count instances for the content to be visible.
  • count – The minimum count of references required for the content to show.
  • ctype – The type of points that are being checked for the content visibility.
  • visitors – The content that is shown to visitors who are not logged in.
  • comp – The comparison operator used to check requirements (‘AND’ or ‘OR’).
  • user_id – The ID of the user whose credentials are being checked.

Examples and Usage

Basic example – A shortcode that displays content based on the user’s current balance.

[mycred_show_if balance=100]You have enough points![/mycred_show_if]

Advanced examples

Using the shortcode to display content based on the user’s rank and balance. The content will only show if the user’s rank is “Gold” and they have a balance of at least 1000 points.

[mycred_show_if balance=1000 rank="Gold"]Congratulations, you are a Gold member with over 1000 points![/mycred_show_if]

Using the shortcode to display different content to visitors and logged-in users. If the user is not logged in, they will see a message encouraging them to log in. If they are logged in, they will see a message welcoming them back.

[mycred_show_if visitors="Please log in to see your points."]Welcome back, check out your points below![/mycred_show_if]

Using the shortcode to display content based on a specific reference count. If the user has at least 5 references of a specific type, they will see the enclosed content.

[mycred_show_if ref="specific-ref" count=5]You have enough references of this type![/mycred_show_if]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_show_if] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_show_if', 'mycred_render_shortcode_show_if' );

Shortcode PHP function:

function mycred_render_shortcode_show_if( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'balance'  => -1,
			'rank'     => -1,
			'ref'      => '',
			'count'    => -1,
			'ctype'    => MYCRED_DEFAULT_TYPE_KEY,
			'visitors' => '',
			'comp'     => 'AND',
			'user_id'  => 'current'
		), $atts, MYCRED_SLUG . '_show_if' ) );

		// Visitors
		if ( ! is_user_logged_in() ) {

			if ( $visitors != '' ) return $visitors;

			return;

		}

		// Get the user ID
		$user_id = mycred_get_user_id( $user_id );

		// You can only use AND or OR for comparisons
		if ( ! in_array( $comp, array( 'AND', 'OR' ) ) )
			$comp = 'AND';

		// Make sure the point type we nominated exists
		if ( ! mycred_point_type_exists( $ctype ) ) return 'invalid point type';

		// Load myCRED with the requested point type
		$mycred = mycred( $ctype );

		// Make sure user is not excluded
		if ( $mycred->exclude_user( $user_id ) ) return;

		// Lets start determening if the user can see the content
		$should_show = false;
		$check_bal 	 = $balance == -1 ? true : false;
		$check_ref   = empty( $ref ) ? true : false;
		$check_rank  = $rank == -1 ? true : false;

		// Balance related requirement
		if ( $balance >= 0 ) {

			$users_balance = $mycred->get_users_balance( $user_id, $ctype );
			$balance       = $mycred->number( $balance );

			// Zero balance requirement
			if ( $balance == $mycred->zero() && $users_balance == $mycred->zero() )
				$check_bal = true;

			// Balance must be higher or equal to the amount set
			elseif ( $users_balance >= $balance )
				$check_bal = true;

		}

		// Reference related requirement
		if ( MYCRED_ENABLE_LOGGING && strlen( $ref ) > 0 ) {

			$ref_count = mycred_count_ref_instances( $ref, $user_id, $ctype );

			// Combined with a balance requirement we must have references
			if ( $balance >= 0 && $ref_count == 0 && $comp === 'AND' )
				$check_ref = false;

			// Ref count must be higher or equal to the count set
			elseif ( $ref_count >= $count )
				$check_ref = true;

		}

		// Rank related requirement
		if ( $rank !== -1 && function_exists( 'mycred_get_users_rank' ) ) {

			$rank_id = mycred_get_rank_object_id( $rank );

			// Rank ID provided
			if ( is_numeric( $rank ) )
				$users_rank = mycred_get_users_rank( $user_id, $ctype );

			// Rank title provided
			else
				$users_rank = mycred_get_users_rank( $user_id, $ctype );

			if ( isset( $users_rank->post_id ) && $rank_id !== false ) {

				if ( $users_rank->post_id != $rank_id && $comp === 'AND' )
					$check_rank = false;

				elseif ( $users_rank->post_id == $rank_id )
					$check_rank = true;

			}

		}

		if ( $user_id == get_current_user_id() ) {

			if ( $comp === 'AND' ) {

				if( $check_bal && $check_ref && $check_rank ) 
					$should_show = true;

			}
			else {

				if( ( $balance >= 0 && $check_bal ) || ( ! empty( $ref ) && $check_ref ) || ( $rank != -1 && $check_rank ) ) 
					$should_show = true;

			}

		}

		// Allow others to play
		$should_show = apply_filters( 'mycred_show_if', $should_show, $user_id, $atts, $content );

		// Sorry, no show
		if ( $should_show !== true ) return;

		$content = '<div class="mycred-show-this-content">' . $content . '</div>';

		// Return content
		return do_shortcode( apply_filters( 'mycred_show_if_render', $content, $user_id, $atts, $content ) );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_show_if.php

Mycred [MYCRED_total_balance] Shortcode

The myCRED_total_balance shortcode is used to display the total balance of a user’s myCRED points. It allows you to specify the user ID and the types of points to include. This shortcode retrieves the user’s account object and checks for any exclusions. If specific point types are defined, it adds up only those balances. The balance sum can be formatted based on request.

Shortcode: [MYCRED_total_balance]

Parameters

Here is a list of all possible MYCRED_SLUG_total_balance shortcode parameters and attributes:

  • user_id – The ID of the user whose balance is displayed.
  • types – The type of points to display, default is MYCRED_DEFAULT_TYPE_KEY.
  • raw – If set to 1, it will return unformatted balance, otherwise, it will return formatted balance.
  • total – If set to 1, it will return the user’s total accumulated balance, otherwise, it will return the current balance.

Examples and Usage

Basic example – Displaying the total balance of the current user in myCRED default point type.

[mycred_total_balance]

Advanced examples

Displaying the total balance of a specific user by providing the user id. Here, the user id is 123.

[mycred_total_balance user_id=123]

Displaying the total balance of the current user in a specific point type. Here, the point type key is ‘gold’.

[mycred_total_balance types=gold]

Displaying the raw total balance of the current user without any formatting.

[mycred_total_balance raw=1]

Displaying the accumulated total balance of the current user.

[mycred_total_balance total=1]

Displaying the total balance of a specific user in multiple point types. Here, the user id is 123 and the point type keys are ‘gold’ and ‘silver’.

[mycred_total_balance user_id=123 types=gold,silver]

PHP Function Code

In case you have difficulties debugging what causing issues with [MYCRED_SLUG_total_balance] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_total_balance', 'mycred_render_shortcode_total' );

Shortcode PHP function:

function mycred_render_shortcode_total( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'user_id' => 'current',
			'types'   => MYCRED_DEFAULT_TYPE_KEY,
			'raw'     => 0,
			'total'   => 0
		), $atts, MYCRED_SLUG . '_total_balance' ) );

		// If user ID is not set, get the current users ID
		if ( ! is_user_logged_in() && $user_id == 'current' )
			return $content;

		$user_id     = mycred_get_user_id( $user_id );

		// Get the users myCRED account object
		$account     = mycred_get_account( $user_id );
		if ( $account === false ) return;

		// Check for exclusion
		if ( empty( $account->balance ) ) return;

		// Assume we want all balances added up
		$point_types = $account->point_types;

		// If we set types="" to either one or a comma separared list of type keys
		if ( ! empty( $types ) && $types != 'all' ) {

			$types_to_addup = array();
			foreach ( explode( ',', $types ) as $type_key ) {

				$type_key = sanitize_text_field( $type_key );
				if ( ! array_key_exists( $type_key, $account->balance ) ) continue;

				if ( ! in_array( $type_key, $types_to_addup ) )
					$types_to_addup[] = $type_key;

			}
			$point_types   = $types_to_addup;

		}

		// Lets add up
		$balance_sum = 0;
		if ( ! empty( $point_types ) ) {
			foreach ( $point_types as $type_key ) {

				$balance = $account->balance[ $type_key ];
				if ( $balance === false ) continue;

				if ( $total == 1 )
					$balance_sum += $balance->accumulated;
				else
					$balance_sum += $balance->current;

			}
		}

		// If we only added up one, we can format (if set)
		if ( count( $point_types ) == 1 ) {

			$point_type = $account->balance[ $types_to_addup[0] ]->point_type;

			// Format requested
			if ( ! $raw && ! empty( $point_type ) )
				$balance_sum = $point_type->format( $balance_sum );

		}

		return apply_filters( 'mycred_total_balances_output', $balance_sum, $atts );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_total_balance.php

Mycred [myCRED_total_points] Shortcode

The myCRED_total_points shortcode calculates the total points of a user. It extracts attributes like type, ref, ref_id, user_id, and formatted. It checks if the point type exists and gets the user ID. It adds up all balances if there are no ref and ref_id.

Shortcode: [myCRED_total_points]

Parameters

Here is a list of all possible myCRED_total_points shortcode parameters and attributes:

  • type – Defines the type of points to be displayed.
  • ref – Specifies the reference for the points calculation.
  • ref_id – Assigns a specific reference ID for the points.
  • user_id – Determines the user whose points are to be displayed.
  • formatted – Decides the format of the point display (1 for formatted, 0 for raw).

Examples and Usage

Basic example – The shortcode displays the total points of the current user. No additional parameters are needed since the user_id is set to ‘current’ by default.

[mycred_total_points]

Advanced examples

Display the total points of a specific user by passing the user_id as a parameter. In this case, the user_id is 5.

[mycred_total_points user_id=5]

Display the total points earned from a specific reference. The reference here is ‘ref_example’.

[mycred_total_points ref='ref_example']

Show the total points earned from a specific reference ID. The reference ID in this example is 10.

[mycred_total_points ref_id=10]

Display the total points of a specific user earned from a specific reference. The user_id is 5 and the reference is ‘ref_example’.

[mycred_total_points user_id=5 ref='ref_example']

Show the total points of a specific user earned from a specific reference ID. The user_id is 5 and the reference ID is 10.

[mycred_total_points user_id=5 ref_id=10]

Display the total points without formatting. The formatted parameter is set to 0 to achieve this.

[mycred_total_points formatted=0]

Display the total points of a specific user without formatting. The user_id is 5 and the formatted parameter is set to 0.

[mycred_total_points user_id=5 formatted=0]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_total_points] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_total_points', 'mycred_render_shortcode_total_points' );

Shortcode PHP function:

function mycred_render_shortcode_total_points( $atts ) {

		extract( shortcode_atts( array(
			'type'      => MYCRED_DEFAULT_TYPE_KEY,
			'ref'       => '',
			'ref_id'    => '',
			'user_id'   => 'current',
			'formatted' => 1
		), $atts, MYCRED_SLUG . '_total_points' ) );

		if ( ! mycred_point_type_exists( $type ) )
			$type = MYCRED_DEFAULT_TYPE_KEY;

		$user_id = mycred_get_user_id( $user_id );
		$mycred  = mycred( $type );

		global $wpdb, $mycred_log_table;

		// Simple
		if ( $ref == '' && $ref_id == '' && $user_id == '' ) {

			// Add up all balances
			$total = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s", mycred_get_meta_key( $type ) ) );

		}

		// Complex
		else {

			$wheres   = array();
			$wheres[] = $wpdb->prepare( "ctype = %s", mycred_get_meta_key( $type ) );

			if ( strlen( $ref ) > 0 ) {

				// Either we have just one reference
				$multiple = explode( ',', $ref );
				if ( count( $multiple ) == 1 )
					$wheres[] = $wpdb->prepare( "ref = %s", $ref );

				// Or a comma seperated list of references
				else {

					$_clean = array();
					foreach ( $multiple as $ref ) {
						$ref = sanitize_key( $ref );
						if ( strlen( $ref ) > 0 )
							$_clean[] = $ref;
					}

					if ( ! empty( $_clean ) )
						$wheres[] = "ref IN ( '" . implode( "', '", $_clean ) . "' )";

				}

			}

			$ref_id  = absint( $ref_id );
			if ( $ref_id > 0 )
				$wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );

			$user_id = absint( $user_id );
			if ( $user_id != '' && $user_id != 0 )
				$wheres[] = $wpdb->prepare( "user_id = %d", $user_id );

			$wheres  = implode( " AND ", $wheres );
			$total   = $wpdb->get_var( "SELECT SUM( creds ) FROM {$mycred_log_table} WHERE {$wheres};" );

		}

		if ( $total === NULL )
			$total = 0;

		if ( $formatted == 1 )
			return $mycred->format_creds( $total );

		return $total;

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_total_points.php

Mycred [myCRED_total_since] Shortcode

The myCRED_total_since shortcode displays the total points a user has earned within a specified timeframe. It customizes the ‘from’ and ‘until’ parameters, the type of points, and user ID.

Shortcode: [myCRED_total_since]

Parameters

Here is a list of all possible myCRED_total_since shortcode parameters and attributes:

  • from – Specifies the start date for points calculation
  • until – Specifies the end date for points calculation
  • type – Defines the type of myCRED points to consider
  • ref – Filters the points based on specific references
  • user_id – Determines the user whose points are being calculated
  • formatted – Decides whether to display points in formatted style

Examples and Usage

Basic example – Displays the total points a user has earned since a specific date.

[mycred_total_since from="2022-01-01" user_id="10" /]

Advanced examples

Displays the total points a user has earned between two specific dates, with the points formatted.

[mycred_total_since from="2022-01-01" until="2022-02-01" user_id="10" formatted="1" /]

Displays the total points a user has earned since a specific date, for a specific point type, with the reference set to a specific value.

[mycred_total_since from="2022-01-01" type="gold" ref="quiz" user_id="10" /]

Displays the total points the current user has earned since a specific date, with the points formatted.

[mycred_total_since from="2022-01-01" user_id="current" formatted="1" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_total_since] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_total_since', 'mycred_render_shortcode_total_since' );

Shortcode PHP function:

function mycred_render_shortcode_total_since( $atts, $content = '' ) {

		extract( shortcode_atts( array(
			'from'      => 'today',
			'until'     => 'now',
			'type'      => MYCRED_DEFAULT_TYPE_KEY,
			'ref'       => '',
			'user_id'   => 'current',
			'formatted' => 1
		), $atts, MYCRED_SLUG . '_total_since' ) );

		if ( ! mycred_point_type_exists( $type ) )
			$type = MYCRED_DEFAULT_TYPE_KEY;

		if ( $ref == '' ) $ref = NULL;

		$user_id = mycred_get_user_id( $user_id );
		$mycred  = mycred( $type );
		$total   = mycred_get_total_by_time( $from, $until, $ref, $user_id, $type );

		if ( substr( $total, 0, 7 ) != 'Invalid' && $formatted == 1 )
			$total = $mycred->format_creds( $total );

		return $total;

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_total_since.php

Mycred [myCRED_video] Shortcode

The myCRED_video shortcode is a powerful tool from myCRED plugin. It allows you to embed YouTube videos in your WordPress content and assigns points to users based on video interactions. It uses various attributes like ‘id’, ‘width’, ‘height’, ‘amount’, ‘logic’, ‘interval’, ‘streaming’, ‘duration’, and ‘ctype’. The shortcode checks if the user is logged in, constructs the YouTube query, and generates the video output.

Shortcode: [myCRED_video]

Parameters

Here is a list of all possible myCRED_video shortcode parameters and attributes:

  • id – The unique ID of the video to be displayed.
  • width – The width of the video in pixels.
  • height – The height of the video in pixels.
  • amount – The amount of points to be awarded.
  • logic – The logic to use in awarding points.
  • interval – The interval between points being awarded.
  • streaming – If streaming is enabled or not.
  • duration – The duration of the video in seconds.
  • ctype – The type of points to be awarded.

Examples and Usage

Basic example – The following shortcode displays a video with the specified ID, width, and height. The video ID is mandatory, while the width and height are optional and default to 560 and 315 pixels, respectively.

[mycred_video id="videoID" width="560" height="315" /]

Advanced examples

Displaying a video with specific reward amount, logic and interval for reward distribution. The ‘amount’ parameter specifies the reward amount, ‘logic’ parameter defines the reward logic, and ‘interval’ parameter sets the interval for reward distribution.

[mycred_video id="videoID" amount="10" logic="play" interval="30" /]

Using the shortcode to display a streaming video with a specified duration and a custom point type. The ‘streaming’ parameter is set to ‘on’ for streaming videos, ‘duration’ parameter sets the video duration, and ‘ctype’ parameter specifies the custom point type.

[mycred_video id="videoID" streaming="on" duration="300" ctype="custom" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [myCRED_video] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( MYCRED_SLUG . '_video', 'mycred_render_shortcode_video' );

Shortcode PHP function:

function mycred_render_shortcode_video( $atts ) {

		global $mycred_video_points;

		extract( shortcode_atts( array(
			'id'       	=> NULL,
			'width'    	=> 560,
			'height'  	=> 315,
			'amount'   	=> '',
			'logic'    	=> '',
			'interval' 	=> '',
			'streaming'	=> '',
			'duration'	=> '',
			'ctype'    	=> MYCRED_DEFAULT_TYPE_KEY
		), $atts, MYCRED_SLUG . '_video' ) );

		$prf_hook = apply_filters( 'mycred_option_id', 'mycred_pref_hooks' );
		$hooks    = mycred_get_option( $prf_hook, false );
		if ( $ctype != MYCRED_DEFAULT_TYPE_KEY )
			$hooks = mycred_get_option( 'mycred_pref_hooks_' . sanitize_key( $ctype ), false );

		if ( $hooks === false || ! is_array( $hooks ) || ! array_key_exists( 'video_view', $hooks['hook_prefs'] ) ) return;
		$prefs    = $hooks['hook_prefs']['video_view'];

		if ( $amount == '' )
			$amount = $prefs['creds'];

		if ( $logic == '' )
			$logic = $prefs['logic'];

		if ( $interval == '' )
			$interval = $prefs['interval'];

		if ( $streaming == '' )
			$streaming = 'off';

		if ( $duration == '' )
			$duration = 300;

		// ID is required
		if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );

		// Interval
		if ( $interval ) {
		   $interval = (float) $interval;
           $interval = abs( $interval * 1000 );
        }

		// Video ID
		$video_id = str_replace( '-', '__', $id );

		// Create key
		$key      = mycred_create_token( array( 'youtube', $video_id, $amount, $logic, $interval, $ctype ) );

		if ( ! isset( $mycred_video_points ) || ! is_array( $mycred_video_points ) )
			$mycred_video_points = array();

		// Construct YouTube Query
		$query    = apply_filters( 'mycred_video_query_youtube', array(
			'enablejsapi' => 1,
			'version'     => 3,
			'playerapiid' => 'mycred_vvideo_v' . $video_id,
			'rel'         => 0,
			'controls'    => 1,
			'showinfo'    => 0
		), $atts, $video_id );

		if ( ! is_user_logged_in() )
			unset( $query['playerapiid'] );

		// Construct Youtube Query Address
		$url      = 'https://www.youtube.com/embed/' . $id;
		$url      = add_query_arg( $query, $url );

		$mycred_video_points[] = 'youtube';

		// Make sure video source ids are unique
		$mycred_video_points   = array_unique( $mycred_video_points );

		ob_start();

?>
<div class="row mycred-video-wrapper youtube-video">
	<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		<iframe id="mycred_vvideo_v<?php echo esc_attr( $video_id ); ?>" class="mycred-video mycred-youtube-video" data-vid="<?php echo esc_attr( $video_id ); ?>" src="<?php echo esc_url( $url ); ?>" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
	</div>
</div>
<?php

		if ( is_user_logged_in() ) :

?>
<script type="text/javascript">function mycred_vvideo_v<?php echo esc_attr( $video_id ); ?>( state ) { duration[ "<?php echo esc_attr( $video_id ); ?>" ] = state.target.getDuration(); mycred_view_video( "<?php echo esc_attr( $video_id ); ?>", state.data, "<?php echo esc_attr( $logic ); ?>", "<?php echo esc_attr( $interval ); ?>", "<?php echo esc_attr( $key ); ?>", "<?php echo esc_attr( $ctype ); ?>" , "<?php echo esc_attr( mycred_encode_values( $streaming ) ); ?>" , "<?php echo esc_attr( mycred_encode_values( $duration ) ); ?>" );  }</script>
<?php

		endif;

		$output = ob_get_contents();
		ob_end_clean();

		// Return the shortcode output
		return apply_filters( 'mycred_video_output', $output, $atts );

	}

Code file location:

mycred/mycred/includes/shortcodes/mycred_video.php

Conclusion

Now that you’ve learned how to embed the MyCRED Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *